Skip to content

Commit 6575154

Browse files
authored
[compiler-rt] Fixed Android 8.1 getauxval(AT_PAGESZ) crashes if called from .preinit_array. (#113427) (#116121)
Signed-off-by: funsafe-ptr <[email protected]>
1 parent efd0a7f commit 6575154

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
# include <sys/personality.h>
8383
# endif
8484

85+
# if SANITIZER_ANDROID && __ANDROID_API__ < 35
86+
// The weak `strerrorname_np` (introduced in API level 35) definition,
87+
// allows for checking the API level at runtime.
88+
extern "C" SANITIZER_WEAK_ATTRIBUTE const char *strerrorname_np(int);
89+
# endif
90+
8591
# if SANITIZER_LINUX && defined(__loongarch__)
8692
# include <sys/sysmacros.h>
8793
# endif
@@ -1240,6 +1246,16 @@ uptr GetPageSize() {
12401246
CHECK_EQ(rv, 0);
12411247
return (uptr)pz;
12421248
# elif SANITIZER_USE_GETAUXVAL
1249+
# if SANITIZER_ANDROID && __ANDROID_API__ < 35
1250+
// The 16 KB page size was introduced in Android 15 (API level 35), while
1251+
// earlier versions of Android always used a 4 KB page size.
1252+
// We are checking the weak definition of `strerrorname_np` (introduced in API
1253+
// level 35) because some earlier API levels crashed when
1254+
// `getauxval(AT_PAGESZ)` was called from the `.preinit_array`.
1255+
if (!strerrorname_np)
1256+
return 4096;
1257+
# endif
1258+
12431259
return getauxval(AT_PAGESZ);
12441260
# else
12451261
return sysconf(_SC_PAGESIZE); // EXEC_PAGESIZE may not be trustworthy.

0 commit comments

Comments
 (0)