diff options
author | Bill Wendling <isanbard@gmail.com> | 2011-10-16 01:49:31 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2011-10-16 01:49:31 +0000 |
commit | 9a1c399e2960c61aa89c7e05b5d1bde2e652dd8e (patch) | |
tree | 16a9f16b3fe61cb1520b6da2cd8f35ee828218c8 | |
parent | c2bbf6907ed58104b61d7d41cae11042f99cdcba (diff) |
Merging r142039:
------------------------------------------------------------------------
r142039 | chapuni | 2011-10-14 18:58:16 -0700 (Fri, 14 Oct 2011) | 3 lines
Windows/Memory.inc: Support the ability to allocate memory "near" another block of memory on Win32. It has fixed FIXME.
Thanks to Aaron Ballman!
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_30@142095 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Support/Windows/Memory.inc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Support/Windows/Memory.inc b/lib/Support/Windows/Memory.inc index 8609d39dd6..fcc72837c4 100644 --- a/lib/Support/Windows/Memory.inc +++ b/lib/Support/Windows/Memory.inc @@ -32,11 +32,16 @@ MemoryBlock Memory::AllocateRWX(size_t NumBytes, static const size_t pageSize = Process::GetPageSize(); size_t NumPages = (NumBytes+pageSize-1)/pageSize; - //FIXME: support NearBlock if ever needed on Win64. + PVOID start = NearBlock ? static_cast<unsigned char *>(NearBlock->base()) + + NearBlock->size() : NULL; - void *pa = VirtualAlloc(NULL, NumPages*pageSize, MEM_COMMIT, + void *pa = VirtualAlloc(start, NumPages*pageSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (pa == NULL) { + if (NearBlock) { + // Try again without the NearBlock hint + return AllocateRWX(NumBytes, NULL, ErrMsg); + } MakeErrMsg(ErrMsg, "Can't allocate RWX Memory: "); return MemoryBlock(); } |