Peter Collingbourne | b39cb3c | 2019-03-01 13:12:49 -0800 | [diff] [blame] | 1 | #include <android/dlext.h> |
| 2 | #include <dlfcn.h> |
Peter Collingbourne | b39cb3c | 2019-03-01 13:12:49 -0800 | [diff] [blame] | 3 | #include <stdlib.h> |
| 4 | |
Stephen Hines | 15027e0 | 2020-07-23 19:35:49 -0700 | [diff] [blame] | 5 | extern "C" void __attribute__((section(".custom_text"))) text_before_start_of_gap() {} |
| 6 | char __attribute__((section(".custom_bss"))) end_of_gap[0x1000]; |
Peter Collingbourne | b39cb3c | 2019-03-01 13:12:49 -0800 | [diff] [blame] | 7 | |
| 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 | } |