bionic: Adapt segment gap test for various page sizes
This makes the segment gap test compatible with systems having different
page sizes.
- The linker script now uses `ALIGN(CONSTANT (MAXPAGESIZE))`.
- The C++ code now uses `sysconf(_SC_PAGESIZE)` to get the actual page
size ensuring correct memory alignment of 'start_of_gap' at runtime.
Bug: 315509500
Test: (16k testing)
lunch aosp_cf_x86_64_phone_pgagnostic-trunk_staging-userdebug
m && launch_cvd
atest dlfcn#segment_gap
(4k testing)
lunch aosp_cf_x86_64_phone-trunk_staging-userdebug
m && launch_cvd
atest dlfcn#segment_gap
Change-Id: I31d45d1d22a237ef7d5ea487a64ef20e5e984ec0
diff --git a/tests/libs/segment_gap_outer.cpp b/tests/libs/segment_gap_outer.cpp
index 3ba90d0..0328a99 100644
--- a/tests/libs/segment_gap_outer.cpp
+++ b/tests/libs/segment_gap_outer.cpp
@@ -1,6 +1,7 @@
#include <android/dlext.h>
#include <dlfcn.h>
#include <stdlib.h>
+#include <unistd.h>
extern "C" void __attribute__((section(".custom_text"))) text_before_start_of_gap() {}
char __attribute__((section(".custom_bss"))) end_of_gap[0x1000];
@@ -10,8 +11,9 @@
info.flags = ANDROID_DLEXT_RESERVED_ADDRESS;
char* start_of_gap =
- reinterpret_cast<char*>(reinterpret_cast<uintptr_t>(text_before_start_of_gap) & ~0xfffull) +
- 0x1000;
+ reinterpret_cast<char*>(
+ (reinterpret_cast<uintptr_t>(text_before_start_of_gap) &
+ ~(sysconf(_SC_PAGESIZE) - 1)) + sysconf(_SC_PAGESIZE));
info.reserved_addr = start_of_gap;
info.reserved_size = end_of_gap - start_of_gap;