diff options
author | Andrew Lenharth <andrewl@lenharth.org> | 2005-07-29 23:40:16 +0000 |
---|---|---|
committer | Andrew Lenharth <andrewl@lenharth.org> | 2005-07-29 23:40:16 +0000 |
commit | a00269bc3e97d4e53ed196325ef02e6d1f3d70dc (patch) | |
tree | 8ac8e30fc2eaea6abd4adb0eafbe4a47baf68dbe /lib/System | |
parent | 422f3d58a8a9d346e0bb34f77c30184b0dfc2838 (diff) | |
download | llvm-a00269bc3e97d4e53ed196325ef02e6d1f3d70dc.tar.gz llvm-a00269bc3e97d4e53ed196325ef02e6d1f3d70dc.tar.bz2 llvm-a00269bc3e97d4e53ed196325ef02e6d1f3d70dc.tar.xz |
support near allocations for the JIT
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r-- | lib/System/Unix/Memory.inc | 12 | ||||
-rw-r--r-- | lib/System/Win32/Memory.inc | 4 |
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/System/Unix/Memory.inc b/lib/System/Unix/Memory.inc index a89fd22d2e..4475960e11 100644 --- a/lib/System/Unix/Memory.inc +++ b/lib/System/Unix/Memory.inc @@ -25,7 +25,7 @@ namespace llvm { /// to emit code to the memory then jump to it. Getting this type of memory /// is very OS specific. /// -MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { +MemoryBlock Memory::AllocateRWX(unsigned NumBytes, const MemoryBlock* NearBlock) { if (NumBytes == 0) return MemoryBlock(); long pageSize = Process::GetPageSize(); @@ -47,10 +47,16 @@ MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { MAP_ANON #endif ; - void *pa = ::mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, + + void* start = NearBlock ? (unsigned char*) NearBlock->base() + NearBlock->size() : 0; + + void *pa = ::mmap(start, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, flags, fd, 0); if (pa == MAP_FAILED) { - ThrowErrno("Can't allocate RWX Memory"); + if (NearBlock) //Try again without a near hint + return AllocateRWX(NumBytes, 0); + else + ThrowErrno("Can't allocate RWX Memory"); } MemoryBlock result; result.Address = pa; diff --git a/lib/System/Win32/Memory.inc b/lib/System/Win32/Memory.inc index 9ebef6a71a..7e93dee24e 100644 --- a/lib/System/Win32/Memory.inc +++ b/lib/System/Win32/Memory.inc @@ -23,12 +23,14 @@ using namespace sys; //=== and must not be UNIX code //===----------------------------------------------------------------------===// -MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { +MemoryBlock Memory::AllocateRWX(unsigned NumBytes, const MemoryBlock* NearBlock) { if (NumBytes == 0) return MemoryBlock(); static const long pageSize = Process::GetPageSize(); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + //FIXME: support NearBlock if ever needed on Win64. + void *pa = VirtualAlloc(NULL, NumPages*pageSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (pa == NULL) { |