aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-09-13 22:38:11 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-09-13 22:38:11 +0000
commit33189e787b98c79bd03be466ec19dfb2f65eb65f (patch)
tree5a89a9849c359508b329a3cdf9876b33eae45d5d /lib
parent2565943289cf53ff1b8dd1dfa13b6068e4d31681 (diff)
downloadexternal_llvm-33189e787b98c79bd03be466ec19dfb2f65eb65f.zip
external_llvm-33189e787b98c79bd03be466ec19dfb2f65eb65f.tar.gz
external_llvm-33189e787b98c79bd03be466ec19dfb2f65eb65f.tar.bz2
Simplify the sys::Memory interface per Chris' request.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16318 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/ExecutionEngine/JIT/JITEmitter.cpp4
-rw-r--r--lib/System/AIX/Memory.cpp17
-rw-r--r--lib/System/Cygwin/Memory.cpp15
-rw-r--r--lib/System/Darwin/Memory.cpp17
-rw-r--r--lib/System/FreeBSD/Memory.cpp16
-rw-r--r--lib/System/Interix/Memory.cpp17
-rw-r--r--lib/System/Linux/Memory.cpp17
-rw-r--r--lib/System/SunOS/Memory.cpp17
-rw-r--r--lib/System/Win32/Memory.cpp17
-rw-r--r--lib/System/Win32/Memory.inc17
10 files changed, 82 insertions, 72 deletions
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp
index 3ce5765..a0e7a94 100644
--- a/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -38,7 +38,7 @@ namespace {
/// are emitting is. This never bothers to release the memory, because when
/// we are ready to destroy the JIT, the program exits.
class JITMemoryManager {
- sys::Memory MemBlock; // Virtual memory block allocated RWX
+ sys::MemoryBlock MemBlock; // Virtual memory block allocated RWX
unsigned char *MemBase; // Base of block of memory, start of stub mem
unsigned char *FunctionBase; // Start of the function body area
unsigned char *CurStubPtr, *CurFunctionPtr;
@@ -53,7 +53,7 @@ namespace {
JITMemoryManager::JITMemoryManager() {
// Allocate a 16M block of memory...
- sys::Memory::AllocateRWX(MemBlock,(16 << 20));
+ MemBlock = sys::Memory::AllocateRWX((16 << 20));
MemBase = reinterpret_cast<unsigned char*>(MemBlock.base());
FunctionBase = MemBase + 512*1024; // Use 512k for stubs
diff --git a/lib/System/AIX/Memory.cpp b/lib/System/AIX/Memory.cpp
index 6ba57de..dc8f2d1 100644
--- a/lib/System/AIX/Memory.cpp
+++ b/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/lib/System/Cygwin/Memory.cpp b/lib/System/Cygwin/Memory.cpp
index 58e660c..2392e71 100644
--- a/lib/System/Cygwin/Memory.cpp
+++ b/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/lib/System/Darwin/Memory.cpp b/lib/System/Darwin/Memory.cpp
index a6a8883..974d1db 100644
--- a/lib/System/Darwin/Memory.cpp
+++ b/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/lib/System/FreeBSD/Memory.cpp b/lib/System/FreeBSD/Memory.cpp
index eeb22e9..4ab1a5d 100644
--- a/lib/System/FreeBSD/Memory.cpp
+++ b/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/lib/System/Interix/Memory.cpp b/lib/System/Interix/Memory.cpp
index b79f8b6..94e5893 100644
--- a/lib/System/Interix/Memory.cpp
+++ b/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/lib/System/Linux/Memory.cpp b/lib/System/Linux/Memory.cpp
index 1bc6fd9..1a55ad8 100644
--- a/lib/System/Linux/Memory.cpp
+++ b/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/lib/System/SunOS/Memory.cpp b/lib/System/SunOS/Memory.cpp
index d6d871a..8c6a44d 100644
--- a/lib/System/SunOS/Memory.cpp
+++ b/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/lib/System/Win32/Memory.cpp b/lib/System/Win32/Memory.cpp
index 8a9ae05..946e50c 100644
--- a/lib/System/Win32/Memory.cpp
+++ b/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);
}
diff --git a/lib/System/Win32/Memory.inc b/lib/System/Win32/Memory.inc
index 8a9ae05..946e50c 100644
--- a/lib/System/Win32/Memory.inc
+++ b/lib/System/Win32/Memory.inc
@@ -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);
}