blob: fb448e778a623c6dbaf512ff564946c76ac7403f [file] [log] [blame]
Peter Collingbourneb39cb3c2019-03-01 13:12:49 -08001#include <android/dlext.h>
2#include <dlfcn.h>
3#include <jni.h>
4#include <stdlib.h>
5
6extern "C" void text_before_start_of_gap() {}
7char end_of_gap[0x1000];
8
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*>(reinterpret_cast<uintptr_t>(text_before_start_of_gap) & ~0xfffull) +
15 0x1000;
16 info.reserved_addr = start_of_gap;
17 info.reserved_size = end_of_gap - start_of_gap;
18
19 void *handle = android_dlopen_ext("libsegment_gap_inner.so", RTLD_NOW, &info);
20 if (!handle) {
21 __builtin_trap();
22 }
23
24 return dlsym(handle, "inner");
25}