]> granicus.if.org Git - llvm/commit
[Support] Add error handling to sys::Process::getPageSize().
authorLang Hames <lhames@gmail.com>
Wed, 8 May 2019 02:11:07 +0000 (02:11 +0000)
committerLang Hames <lhames@gmail.com>
Wed, 8 May 2019 02:11:07 +0000 (02:11 +0000)
commit90dd07f5c5946a3d9d6861effe3291620c88c06f
tree76f37332bd47c5c9580ef589a2712958e315a091
parentd57f520be85544bbda97b7f27d16674fe168d827
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360221 91177308-0d34-0410-b5e6-96231b3b80d8
12 files changed:
include/llvm/ExecutionEngine/Orc/IndirectionUtils.h
include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h
include/llvm/Support/Process.h
lib/ExecutionEngine/JITLink/JITLink.cpp
lib/ExecutionEngine/Orc/OrcABISupport.cpp
lib/ExecutionEngine/SectionMemoryManager.cpp
lib/Support/MemoryBuffer.cpp
lib/Support/Unix/Memory.inc
lib/Support/Unix/Path.inc
lib/Support/Unix/Process.inc
lib/Support/Windows/Process.inc
unittests/Support/MemoryTest.cpp