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> |
Vilas Bhat | 8420cf0 | 2024-08-20 01:56:53 +0000 | [diff] [blame] | 4 | #include <unistd.h> |
Peter Collingbourne | b39cb3c | 2019-03-01 13:12:49 -0800 | [diff] [blame] | 5 | |
Stephen Hines | 15027e0 | 2020-07-23 19:35:49 -0700 | [diff] [blame] | 6 | extern "C" void __attribute__((section(".custom_text"))) text_before_start_of_gap() {} |
| 7 | char __attribute__((section(".custom_bss"))) end_of_gap[0x1000]; |
Peter Collingbourne | b39cb3c | 2019-03-01 13:12:49 -0800 | [diff] [blame] | 8 | |
| 9 | extern "C" void* get_inner() { |
| 10 | android_dlextinfo info = {}; |
| 11 | info.flags = ANDROID_DLEXT_RESERVED_ADDRESS; |
| 12 | |
| 13 | char* start_of_gap = |
Vilas Bhat | 8420cf0 | 2024-08-20 01:56:53 +0000 | [diff] [blame] | 14 | reinterpret_cast<char*>( |
| 15 | (reinterpret_cast<uintptr_t>(text_before_start_of_gap) & |
| 16 | ~(sysconf(_SC_PAGESIZE) - 1)) + sysconf(_SC_PAGESIZE)); |
Peter Collingbourne | b39cb3c | 2019-03-01 13:12:49 -0800 | [diff] [blame] | 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 | } |