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