diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-09-13 22:38:11 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-09-13 22:38:11 +0000 |
commit | f7948483d2dccb64f0d7afa820273946429e3304 (patch) | |
tree | eccee279ddbcf7b5c58936b53cecc2ebc3d18f39 /llvm/lib/System | |
parent | 07369430c4be24444d55a48ca31d01538a680263 (diff) | |
download | bcm5719-llvm-f7948483d2dccb64f0d7afa820273946429e3304.tar.gz bcm5719-llvm-f7948483d2dccb64f0d7afa820273946429e3304.zip |
Simplify the sys::Memory interface per Chris' request.
llvm-svn: 16318
Diffstat (limited to 'llvm/lib/System')
-rw-r--r-- | llvm/lib/System/AIX/Memory.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/System/Cygwin/Memory.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/System/Darwin/Memory.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/System/FreeBSD/Memory.cpp | 16 | ||||
-rw-r--r-- | llvm/lib/System/Interix/Memory.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/System/Linux/Memory.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/System/SunOS/Memory.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/System/Win32/Memory.cpp | 17 |
8 files changed, 71 insertions, 62 deletions
diff --git a/llvm/lib/System/AIX/Memory.cpp b/llvm/lib/System/AIX/Memory.cpp index 6ba57de40a6..dc8f2d1c475 100644 --- a/llvm/lib/System/AIX/Memory.cpp +++ b/llvm/lib/System/AIX/Memory.cpp @@ -26,8 +26,8 @@ using namespace sys; //=== and must not be generic UNIX code (see ../Unix/Memory.cpp) //===----------------------------------------------------------------------===// -void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { - if (NumBytes == 0) return 0; +MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { + if (NumBytes == 0) return MemoryBlock(); static const long pageSize = Process::GetPageSize(); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; @@ -37,14 +37,15 @@ void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { if (pa == (void*)-1) { throw std::string("Can't allocate RWX Memory: ") + strerror(errno); } - M.Address = pa; - M.AllocSize = NumPages*pageSize; - return pa; + MemoryBlock result; + result.Address = pa; + result.Size = NumPages*pageSize; + return result; } -void Memory::ReleaseRWX(Memory& M) { - if (M.Address == 0 || M.AllocSize == 0) return; - if (0 != munmap(M.Address, M.AllocSize)) { +void Memory::ReleaseRWX(MemoryBlock& M) { + if (M.Address == 0 || M.Size == 0) return; + if (0 != munmap(M.Address, M.Size)) { throw std::string("Can't release RWX Memory: ") + strerror(errno); } } diff --git a/llvm/lib/System/Cygwin/Memory.cpp b/llvm/lib/System/Cygwin/Memory.cpp index 58e660c2083..2392e71e0db 100644 --- a/llvm/lib/System/Cygwin/Memory.cpp +++ b/llvm/lib/System/Cygwin/Memory.cpp @@ -26,8 +26,8 @@ using namespace sys; //=== and must not be generic UNIX code (see ../Unix/Memory.cpp) //===----------------------------------------------------------------------===// -void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { - if (NumBytes == 0) return 0; +MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { + if (NumBytes == 0) return MemoryBlock(); static const long pageSize = Process::GetPageSize(); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; @@ -37,14 +37,15 @@ void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { if (pa == (void*)-1) { throw std::string("Can't allocate RWX Memory: ") + strerror(errno); } - M.Address = pa; - M.AllocSize = NumPages*pageSize; - return pa; + MemoryBlock result; + result.Address = pa; + result.Size = NumPages*pageSize; + return result; } void Memory::ReleaseRWX(Memory& M) { - if (M.Address == 0 || M.AllocSize == 0) return; - if (0 != munmap(M.Address, M.AllocSize)) { + if (M.Address == 0 || M.Size == 0) return; + if (0 != munmap(M.Address, M.Size)) { throw std::string("Can't release RWX Memory: ") + strerror(errno); } } diff --git a/llvm/lib/System/Darwin/Memory.cpp b/llvm/lib/System/Darwin/Memory.cpp index a6a88835ad9..974d1dbe104 100644 --- a/llvm/lib/System/Darwin/Memory.cpp +++ b/llvm/lib/System/Darwin/Memory.cpp @@ -30,8 +30,8 @@ using namespace sys; /// to emit code to the memory then jump to it. Getting this type of memory /// is very OS specific. /// -void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { - if (NumBytes == 0) return 0; +MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { + if (NumBytes == 0) return MemoryBlock(); static const long pageSize = Process::GetPageSize(); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; @@ -43,14 +43,15 @@ void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { strerror_r(errno, msg, MAXPATHLEN-1); throw std::string("Can't allocate RWX Memory: ") + msg; } - M.Address = pa; - M.AllocSize = NumPages*pageSize; - return pa; + MemoryBlock result; + result.Address = pa; + result.Size = NumPages*pageSize; + return result; } -void Memory::ReleaseRWX(Memory& M) { - if (M.Address == 0 || M.AllocSize == 0) return; - if (0 != munmap(M.Address, M.AllocSize)) { +void Memory::ReleaseRWX(MemoryBlock& M) { + if (M.Address == 0 || M.Size == 0) return; + if (0 != munmap(M.Address, M.Size)) { char msg[MAXPATHLEN]; strerror_r(errno, msg, MAXPATHLEN-1); throw std::string("Can't release RWX Memory: ") + msg; diff --git a/llvm/lib/System/FreeBSD/Memory.cpp b/llvm/lib/System/FreeBSD/Memory.cpp index eeb22e910bf..4ab1a5dcc15 100644 --- a/llvm/lib/System/FreeBSD/Memory.cpp +++ b/llvm/lib/System/FreeBSD/Memory.cpp @@ -25,8 +25,8 @@ using namespace sys; //=== and must not be generic UNIX code (see ../Unix/Memory.cpp) //===----------------------------------------------------------------------===// -void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { - if (NumBytes == 0) return 0; +MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { + if (NumBytes == 0) return MemoryBlock(); static const long pageSize = Process::GetPageSize(); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; @@ -36,14 +36,16 @@ void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { if (pa == (void*)-1) { throw std::string("Can't allocate RWX Memory: ") + strerror(errno); } - M.Address = pa; - M.AllocSize = NumPages*pageSize; - return pa; + + MemoryBlock result; + result.Address = pa; + result.Size = NumPages*pageSize; + return result; } void Memory::ReleaseRWX(Memory& M) { - if (M.Address == 0 || M.AllocSize == 0) return; - if (0 != munmap(M.Address, M.AllocSize)) { + if (M.Address == 0 || M.Size == 0) return; + if (0 != munmap(M.Address, M.Size)) { throw std::string("Can't release RWX Memory: ") + strerror(errno); } } diff --git a/llvm/lib/System/Interix/Memory.cpp b/llvm/lib/System/Interix/Memory.cpp index b79f8b62680..94e58939328 100644 --- a/llvm/lib/System/Interix/Memory.cpp +++ b/llvm/lib/System/Interix/Memory.cpp @@ -25,8 +25,8 @@ using namespace sys; //=== and must not be generic UNIX code (see ../Unix/Memory.cpp) //===----------------------------------------------------------------------===// -void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { - if (NumBytes == 0) return 0; +MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { + if (NumBytes == 0) return MemoryBlock(); static const long pageSize = Process::GetPageSize(); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; @@ -36,14 +36,15 @@ void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { if (pa == (void*)-1) { throw std::string("Can't allocate RWX Memory: ") + strerror(errno); } - M.Address = pa; - M.AllocSize = NumPages*pageSize; - return pa; + MemoryBlock result; + result.Address = pa; + result.Size = NumPages*pageSize; + return result; } -void Memory::ReleaseRWX(Memory& M) { - if (M.Address == 0 || M.AllocSize == 0) return; - if (0 != munmap(M.Address, M.AllocSize)) { +void Memory::ReleaseRWX(MemoryBlock& M) { + if (M.Address == 0 || M.Size == 0) return; + if (0 != munmap(M.Address, M.Size)) { throw std::string("Can't release RWX Memory: ") + strerror(errno); } } diff --git a/llvm/lib/System/Linux/Memory.cpp b/llvm/lib/System/Linux/Memory.cpp index 1bc6fd98bb4..1a55ad8a196 100644 --- a/llvm/lib/System/Linux/Memory.cpp +++ b/llvm/lib/System/Linux/Memory.cpp @@ -30,8 +30,8 @@ using namespace sys; /// to emit code to the memory then jump to it. Getting this type of memory /// is very OS specific. /// -void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { - if (NumBytes == 0) return 0; +MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { + if (NumBytes == 0) return MemoryBlock(); static const long pageSize = Process::GetPageSize(); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; @@ -43,14 +43,15 @@ void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { strerror_r(errno, msg, MAXPATHLEN-1); throw std::string("Can't allocate RWX Memory: ") + msg; } - M.Address = pa; - M.AllocSize = NumPages*pageSize; - return pa; + MemoryBlock result; + result.Address = pa; + result.Size = NumPages*pageSize; + return result; } -void Memory::ReleaseRWX(Memory& M) { - if (M.Address == 0 || M.AllocSize == 0) return; - if (0 != munmap(M.Address, M.AllocSize)) { +void Memory::ReleaseRWX(MemoryBlock& M) { + if (M.Address == 0 || M.Size == 0) return; + if (0 != munmap(M.Address, M.Size)) { char msg[MAXPATHLEN]; strerror_r(errno, msg, MAXPATHLEN-1); throw std::string("Can't release RWX Memory: ") + msg; diff --git a/llvm/lib/System/SunOS/Memory.cpp b/llvm/lib/System/SunOS/Memory.cpp index d6d871aa715..8c6a44d2773 100644 --- a/llvm/lib/System/SunOS/Memory.cpp +++ b/llvm/lib/System/SunOS/Memory.cpp @@ -26,8 +26,8 @@ using namespace sys; //=== and must not be generic UNIX code (see ../Unix/Memory.cpp) //===----------------------------------------------------------------------===// -void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { - if (NumBytes == 0) return 0; +MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { + if (NumBytes == 0) return MemoryBlock(); static const long pageSize = Process::GetPageSize(); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; @@ -37,14 +37,15 @@ void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { if (pa == (void*)-1) { throw std::string("Can't allocate RWX Memory: ") + strerror(errno); } - M.Address = pa; - M.AllocSize = NumPages*pageSize; - return pa; + MemoryBlock result; + result.Address = pa; + result.AllocSize = NumPages*pageSize; + return result; } -void Memory::ReleaseRWX(Memory& M) { - if (M.Address == 0 || M.AllocSize == 0) return; - if (0 != munmap(M.Address, M.AllocSize)) { +void Memory::ReleaseRWX(MemoryBlock& M) { + if (M.Address == 0 || M.Size == 0) return; + if (0 != munmap(M.Address, M.Size)) { throw std::string("Can't release RWX Memory: ") + strerror(errno); } } diff --git a/llvm/lib/System/Win32/Memory.cpp b/llvm/lib/System/Win32/Memory.cpp index 8a9ae05f374..946e50cd6fc 100644 --- a/llvm/lib/System/Win32/Memory.cpp +++ b/llvm/lib/System/Win32/Memory.cpp @@ -22,8 +22,8 @@ using namespace sys; //=== WARNING: Implementation here must contain only Win32 specific code. //===----------------------------------------------------------------------===// -void* Memory::AllocateRWX(Memory&M, unsigned NumBytes) { - if (NumBytes == 0) return 0; +MemoryBlock Memory::AllocateRWX(unsigned NumBytes) { + if (NumBytes == 0) return MemoryBlock(); unsigned pageSize = Process::GetPageSize(); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; @@ -33,12 +33,13 @@ void* Memory::AllocateRWX(Memory&M, unsigned NumBytes) { throw std::string("Couldn't allocate ") + utostr(NumBytes) + " bytes of executable memory!"; } - M.Address = P; - M.AllocSize = NumBytes; - return P; + MemoryBlock result; + result.Address = P; + result.Size = NumBytes; + return result; } -void Memory::ReleaseRWX(Memory& M) { - if (M.Address == 0 ) return; - VirtualFree(M.Address, M.AllocSize, MEM_DECOMMIT, PAGE_NOACCESS); +void Memory::ReleaseRWX(MemoryBlock& M) { + if (M.Address == 0 || M.Size == 0) return; + VirtualFree(M.Address, M.Size, MEM_DECOMMIT, PAGE_NOACCESS); } |