[llvm-commits] [llvm] r142039 - /llvm/trunk/lib/Support/Windows/Memory.inc

NAKAMURA Takumi geek4civic at gmail.com
Fri Oct 14 18:58:17 PDT 2011


Author: chapuni
Date: Fri Oct 14 20:58:16 2011
New Revision: 142039

URL: http://llvm.org/viewvc/llvm-project?rev=142039&view=rev
Log:
Windows/Memory.inc: Support the ability to allocate memory "near" another block of memory on Win32. It has fixed FIXME.

Thanks to Aaron Ballman!

Modified:
    llvm/trunk/lib/Support/Windows/Memory.inc

Modified: llvm/trunk/lib/Support/Windows/Memory.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Memory.inc?rev=142039&r1=142038&r2=142039&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Memory.inc (original)
+++ llvm/trunk/lib/Support/Windows/Memory.inc Fri Oct 14 20:58:16 2011
@@ -32,11 +32,16 @@
   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();
   }





More information about the llvm-commits mailing list