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