[PATCH] D59107: [Support] Add error handling to sys::Process::getPageSize().

Lang Hames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 12:52:32 PST 2019


lhames created this revision.
lhames added reviewers: dblaikie, echristo.
Herald added a subscriber: kristina.
Herald added a project: LLVM.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D59107

Files:
  include/llvm/ExecutionEngine/Orc/IndirectionUtils.h
  include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h
  include/llvm/Support/Process.h
  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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59107.189771.patch
Type: text/x-patch
Size: 10313 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190307/ca4cb4fa/attachment.bin>


More information about the llvm-commits mailing list