1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00

Use the /dev/zero device as the device on which the pages are mapped.

Patch contributed by Henrik Bach. Thanks Henrik!

llvm-svn: 16397
This commit is contained in:
Reid Spencer 2004-09-18 19:34:09 +00:00
parent fb3c25ded9
commit b503c250a3

View File

@ -15,6 +15,7 @@
// Include the generic unix implementation // Include the generic unix implementation
#include "../Unix/Memory.cpp" #include "../Unix/Memory.cpp"
#include "llvm/System/Process.h" #include "llvm/System/Process.h"
#include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
namespace llvm { namespace llvm {
@ -30,9 +31,14 @@ MemoryBlock Memory::AllocateRWX(unsigned NumBytes) {
static const long pageSize = Process::GetPageSize(); static const long pageSize = Process::GetPageSize();
unsigned NumPages = (NumBytes+pageSize-1)/pageSize; unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
int fd = open("/dev/zero", O_RDWR);
if (fd == -1) {
throw std::string("Can't open /dev/zero device: ") + strerror(errno);
}
void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_ANON|MAP_NOCORE, -1, 0); MAP_SHARED, fd, 0);
if (pa == (void*)-1) { if (pa == (void*)-1) {
throw std::string("Can't allocate RWX Memory: ") + strerror(errno); throw std::string("Can't allocate RWX Memory: ") + strerror(errno);
} }