This is an archive of the discontinued LLVM Phabricator instance.

[scudo] getauxval alternative for Android
ClosedPublic

Authored by cryptoad on Sep 5 2017, 12:27 PM.

Details

Summary

getauxval was introduced with API level 18. In order to get things to work
at lower API levels (for the toolchain itself which is built at 14 for 32-bit),
we introduce an alternative implementation reading directly from
/proc/self/auxv.

Event Timeline

cryptoad created this revision.Sep 5 2017, 12:27 PM
alekseyshl added inline comments.Sep 5 2017, 1:58 PM
lib/scudo/scudo_utils.cpp
149

Since you are emulating getauxval anyway, wouldn't it be more logical to do just that, define getauxval up there:

// getauxval() was introduced with API level 18 on Android.
# if SANITIZER_ANDROID && __ANDROID_API__ < 18
#  include <fcntl.h>
uptr getauxval(uptr type) {
   ...
}
# else
#  include <sys/auxv.h>
# endif

and then just use it?

uptr HWCap = getauxval(AT_HWCAP);
alekseyshl added inline comments.Sep 5 2017, 2:01 PM
lib/scudo/scudo_utils.cpp
140

If you agree with redefining getauxval, it should be moved next to the function definition too.

cryptoad updated this revision to Diff 113915.Sep 5 2017, 2:29 PM
cryptoad marked 2 inline comments as done.

Redefining getauxval instead of introducing a third party middleman as
suggested by @alekseyshl.

cryptoad updated this revision to Diff 113917.Sep 5 2017, 2:38 PM

Comment update.

alekseyshl accepted this revision.Sep 5 2017, 2:55 PM
alekseyshl added inline comments.
lib/scudo/scudo_utils.cpp
28

It should never be defined here, right? So, we can drop #ifndef.

This revision is now accepted and ready to land.Sep 5 2017, 2:55 PM
cryptoad marked an inline comment as done.Sep 5 2017, 3:02 PM
cryptoad added inline comments.
lib/scudo/scudo_utils.cpp
28

True, I was being more conservative than probably needed!

cryptoad updated this revision to Diff 113921.Sep 5 2017, 3:04 PM
cryptoad marked 2 inline comments as done.

Drop the #ifndef AT_HWCAP as it shouldn't be definedi there. If it is,
something is probably wrong somewhere.

cryptoad updated this revision to Diff 113923.Sep 5 2017, 3:19 PM

Adding missing space.

cryptoad closed this revision.Sep 6 2017, 10:52 AM