This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Modify hard-coded page size for Android.
ClosedPublic

Authored by cferris on Aug 16 2023, 2:55 PM.

Details

Summary

On Android, if PAGE_SIZE is defined, use that as the hard-coded value.
Otherwise, fallback to using getting the page size.

Diff Detail

Event Timeline

cferris created this revision.Aug 16 2023, 2:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2023, 2:55 PM
cferris requested review of this revision.Aug 16 2023, 2:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2023, 2:55 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
Chia-hungDuan added inline comments.Aug 16 2023, 3:03 PM
compiler-rt/lib/scudo/standalone/common.h
136–137

How about simply return PAGE_SIZE if it's defined?

This may convey an information that PAGE_SIZE is a way to customize the page size value.

Chia-hungDuan added inline comments.Aug 16 2023, 3:09 PM
compiler-rt/lib/scudo/standalone/common.h
136–137

Or is it supposed to be

#if defined(SCUDO_ANDROID)
// Bionic uses a hardcoded value if PAGE_SIZE is defined.
#if defined(PAGE_SIZE)
  return PAGE_SIZE;
#endif
#endif // if defined(SCUDO_ANDROID)
enh added inline comments.Aug 16 2023, 3:21 PM
compiler-rt/lib/scudo/standalone/common.h
136–137

Or is it supposed to be

#if defined(SCUDO_ANDROID)
// Bionic uses a hardcoded value if PAGE_SIZE is defined.
#if defined(PAGE_SIZE)
  return PAGE_SIZE;
#endif
#endif // if defined(SCUDO_ANDROID)

well, it's the same thing, right?

the reason i didn't suggest dropping the SCUDO_ANDROID part and only checking PAGE_SIZE is that that would be a behavior change for other libcs. (basically: glibc/musl on x86/x86-64/alpha/s390.) which i _think_ is fine anyway (because afaik we're the only libc left that defines PAGE_SIZE for an architecture where the page size isn't actually a constant), but since that would strictly be a behavioral change...

but, yeah, i think there's a decent argument for just having

#if defined(PAGE_SIZE) 
  return PAGE_SIZE;
#endif

if you want.

Chia-hungDuan accepted this revision.Aug 16 2023, 5:55 PM
Chia-hungDuan added inline comments.
compiler-rt/lib/scudo/standalone/common.h
136–137

Yep, they are the same in the result and I agree with your concern on the behavioral change.

To me, the difference is the implication of the use of PAGE_SIZE. Nested under SCUDO_ANDROID will imply it's only used on Android. In contrast, it'll give me the impression that everyone can use it to define constant page size (however, it only works on Android).

That's why I think nesting PAGE_SIZE under SCUDO_ANDROID will be better. Not a strong opinion, feel free to keep the current structure!

This revision is now accepted and ready to land.Aug 16 2023, 5:55 PM
enh added inline comments.Aug 17 2023, 9:23 AM
compiler-rt/lib/scudo/standalone/common.h
136–137

yeah, i don't have a strong opinion either, but given that PAGE_SIZE is just a regular libc #define [at least traditionally], it seems weird using that as a general configuration option.

maybe a comment like // Most Android builds have a build-time constant page size. would have helped?

cferris updated this revision to Diff 551312.Aug 17 2023, 4:09 PM

Added include of unistd.h and modified the return given comments.

I modified the change and added an include because without unistd.h, PAGE_SIZE is not defined in many cases.

cferris marked 5 inline comments as done.Aug 17 2023, 4:11 PM
cferris added inline comments.
compiler-rt/lib/scudo/standalone/common.h
136–137

Changed this to a slightly different version, but the spirit of this suggestion.

Chia-hungDuan accepted this revision.Aug 17 2023, 4:44 PM
This revision was automatically updated to reflect the committed changes.