Change AllocateRWX/DeallocateRWX to not throw an exception.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29058 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2006-07-07 17:32:37 +00:00
parent c1780d2a0a
commit bed22d8902
4 changed files with 85 additions and 45 deletions

View File

@@ -23,7 +23,9 @@ using namespace sys;
//=== and must not be UNIX code
//===----------------------------------------------------------------------===//
MemoryBlock Memory::AllocateRWX(unsigned NumBytes, const MemoryBlock* NearBlock) {
MemoryBlock Memory::AllocateRWX(unsigned NumBytes,
const MemoryBlock *NearBlock,
std::string *ErrMsg) {
if (NumBytes == 0) return MemoryBlock();
static const long pageSize = Process::GetPageSize();
@@ -34,7 +36,8 @@ MemoryBlock Memory::AllocateRWX(unsigned NumBytes, const MemoryBlock* NearBlock)
void *pa = VirtualAlloc(NULL, NumPages*pageSize, MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
if (pa == NULL) {
ThrowError("Can't allocate RWX Memory: ");
GetError("Can't allocate RWX Memory: ", ErrMsg);
return MemoryBlock();
}
MemoryBlock result;
@@ -43,11 +46,10 @@ MemoryBlock Memory::AllocateRWX(unsigned NumBytes, const MemoryBlock* NearBlock)
return result;
}
void Memory::ReleaseRWX(MemoryBlock& M) {
bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) {
if (M.Address == 0 || M.Size == 0) return;
if (!VirtualFree(M.Address, 0, MEM_RELEASE)) {
ThrowError("Can't release RWX Memory: ");
}
if (!VirtualFree(M.Address, 0, MEM_RELEASE))
return GetError("Can't release RWX Memory: ", ErrMsg);
}
}