summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix/Memory.inc
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2019-05-08 02:11:07 +0000
committerLang Hames <lhames@gmail.com>2019-05-08 02:11:07 +0000
commite4b4ab6d26f885f4b12624e5d375521070d8ba3d (patch)
tree96ade27def86606cec98d22008bebdcf22eafb90 /llvm/lib/Support/Unix/Memory.inc
parent83eb9c5b588c4848a7ed08b10ad6c6fb1945eae6 (diff)
downloadbcm5719-llvm-e4b4ab6d26f885f4b12624e5d375521070d8ba3d.tar.gz
bcm5719-llvm-e4b4ab6d26f885f4b12624e5d375521070d8ba3d.zip
[Support] Add error handling to sys::Process::getPageSize().
This patch changes the return type of sys::Process::getPageSize to Expected<unsigned> to account for the fact that the underlying syscalls used to obtain the page size may fail (see below). For clients who use the page size as an optimization only this patch adds a new method, getPageSizeEstimate, which calls through to getPageSize but discards any error returned and substitues a "reasonable" page size estimate estimate instead. All existing LLVM clients are updated to call getPageSizeEstimate rather than getPageSize. On Unix, sys::Process::getPageSize is implemented in terms of getpagesize or sysconf, depending on which macros are set. The sysconf call is documented to return -1 on failure. On Darwin getpagesize is implemented in terms of sysconf and may also fail (though the manpage documentation does not mention this). These failures have been observed in practice when highly restrictive sandbox permissions have been applied. Without this patch, the result is that getPageSize returns -1, which wreaks havoc on any subsequent code that was assuming a sane page size value. <rdar://problem/41654857> Reviewers: dblaikie, echristo Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59107 llvm-svn: 360221
Diffstat (limited to 'llvm/lib/Support/Unix/Memory.inc')
-rw-r--r--llvm/lib/Support/Unix/Memory.inc4
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc
index b8f5df5f72e..affdb7e70d9 100644
--- a/llvm/lib/Support/Unix/Memory.inc
+++ b/llvm/lib/Support/Unix/Memory.inc
@@ -103,7 +103,7 @@ Memory::allocateMappedMemory(size_t NumBytes,
// Use any near hint and the page size to set a page-aligned starting address
uintptr_t Start = NearBlock ? reinterpret_cast<uintptr_t>(NearBlock->base()) +
NearBlock->size() : 0;
- static const size_t PageSize = Process::getPageSize();
+ static const size_t PageSize = Process::getPageSizeEstimate();
if (Start && Start % PageSize)
Start += PageSize - Start % PageSize;
@@ -149,7 +149,7 @@ Memory::releaseMappedMemory(MemoryBlock &M) {
std::error_code
Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) {
- static const size_t PageSize = Process::getPageSize();
+ static const size_t PageSize = Process::getPageSizeEstimate();
if (M.Address == nullptr || M.Size == 0)
return std::error_code();
OpenPOWER on IntegriCloud