diff options
Diffstat (limited to 'contrib/llvm/lib/Support/Unix/Memory.inc')
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Memory.inc | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/contrib/llvm/lib/Support/Unix/Memory.inc b/contrib/llvm/lib/Support/Unix/Memory.inc index f3463e581735..edbc7938f0cb 100644 --- a/contrib/llvm/lib/Support/Unix/Memory.inc +++ b/contrib/llvm/lib/Support/Unix/Memory.inc @@ -91,17 +91,9 @@ Memory::allocateMappedMemory(size_t NumBytes, const size_t NumPages = (NumBytes+PageSize-1)/PageSize; int fd = -1; -#ifdef NEED_DEV_ZERO_FOR_MMAP - static int zero_fd = open("/dev/zero", O_RDWR); - if (zero_fd == -1) { - EC = std::error_code(errno, std::generic_category()); - return MemoryBlock(); - } - fd = zero_fd; -#endif int MMFlags = MAP_PRIVATE | -#ifdef HAVE_MMAP_ANONYMOUS +#ifdef MAP_ANONYMOUS MAP_ANONYMOUS #else MAP_ANON @@ -161,7 +153,10 @@ Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) { int Protect = getPosixProtectionFlags(Flags); - int Result = ::mprotect((void*)((uintptr_t)M.Address & ~(PageSize-1)), PageSize*((M.Size+PageSize-1)/PageSize), Protect); + uintptr_t Start = alignAddr((uint8_t *)M.Address - PageSize + 1, PageSize); + uintptr_t End = alignAddr((uint8_t *)M.Address + M.Size, PageSize); + int Result = ::mprotect((void *)Start, End - Start, Protect); + if (Result != 0) return std::error_code(errno, std::generic_category()); @@ -185,17 +180,9 @@ Memory::AllocateRWX(size_t NumBytes, const MemoryBlock* NearBlock, size_t NumPages = (NumBytes+PageSize-1)/PageSize; int fd = -1; -#ifdef NEED_DEV_ZERO_FOR_MMAP - static int zero_fd = open("/dev/zero", O_RDWR); - if (zero_fd == -1) { - MakeErrMsg(ErrMsg, "Can't open /dev/zero device"); - return MemoryBlock(); - } - fd = zero_fd; -#endif int flags = MAP_PRIVATE | -#ifdef HAVE_MMAP_ANONYMOUS +#ifdef MAP_ANONYMOUS MAP_ANONYMOUS #else MAP_ANON |