This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by lhames on Mar 7 2019, 12:49 PM.

Details

Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

lhames created this revision.Mar 7 2019, 12:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2019, 12:49 PM
Herald added a subscriber: kristina. · View Herald Transcript

Seems reasonable to me (but feel free to wait for someone with more context/domain awareness)

lib/ExecutionEngine/Orc/OrcABISupport.cpp
932 ↗(On Diff #189771)

Should this be 'const' too?

(similar for the other ones that have been made static)

lib/Support/Unix/Process.inc
78 ↗(On Diff #189771)

I suppose in theory we could turn this from compile-time to runtime failure & then systems that don't provide these ways to access the page size would be OK except for running stuff that /needs/ it like the JIT.

But I doubt that's important/worth doing.

lhames marked 2 inline comments as done.Mar 7 2019, 1:38 PM
lhames added inline comments.
lib/ExecutionEngine/Orc/OrcABISupport.cpp
932 ↗(On Diff #189771)

Good catch. Thanks!

lib/Support/Unix/Process.inc
78 ↗(On Diff #189771)

It's definitely worth thinking about. I'm going to leave it for now, but I think you might be right that this is better off as a #warn and a runtime failure.

lhames updated this revision to Diff 190168.Mar 11 2019, 3:31 PM
  • Address Dave's feedback.

Any further thoughts Dave? If not I'll commit before this gets stale. :)

  • Lang.
dblaikie accepted this revision.Apr 29 2019, 4:14 PM

Nah, that's all I've got.

This revision is now accepted and ready to land.Apr 29 2019, 4:14 PM
This revision was automatically updated to reflect the committed changes.
svenvh added a subscriber: svenvh.May 9 2019, 3:27 AM

fwiw, I have updated two more uses of getPageSize() to fix LLVM_USE_PERF builds in r360322.

Sorry I missed them, and thanks very much for the fix Sven!