1 #include <android/dlext.h> 2 #include <dlfcn.h> 3 #include <stdlib.h> 4 #include <unistd.h> 5 text_before_start_of_gap()6extern "C" void __attribute__((section(".custom_text"))) text_before_start_of_gap() {} 7 char __attribute__((section(".custom_bss"))) end_of_gap[0x1000]; 8 get_inner()9extern "C" void* get_inner() { 10 android_dlextinfo info = {}; 11 info.flags = ANDROID_DLEXT_RESERVED_ADDRESS; 12 13 char* start_of_gap = 14 reinterpret_cast<char*>( 15 (reinterpret_cast<uintptr_t>(text_before_start_of_gap) & 16 ~(sysconf(_SC_PAGESIZE) - 1)) + sysconf(_SC_PAGESIZE)); 17 info.reserved_addr = start_of_gap; 18 info.reserved_size = end_of_gap - start_of_gap; 19 20 void *handle = android_dlopen_ext("libsegment_gap_inner.so", RTLD_NOW, &info); 21 if (!handle) { 22 __builtin_trap(); 23 } 24 25 return dlsym(handle, "inner"); 26 } 27