Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/PojavLauncher
Path: blob/v3_openjdk/app_pojavlauncher/src/main/jni/driver_helper/hook.c
2128 views
1
//
2
// Created by maks on 05.06.2023.
3
//
4
#include <android/dlext.h>
5
#include <string.h>
6
#include <stdio.h>
7
// Silence the warnings about using reserved identifiers (we need to link to these to not pollute the global symtab)
8
//NOLINTBEGIN
9
static void* (*android_dlopen_ext_p)(const char* filename,
10
int flags,
11
const android_dlextinfo* extinfo,
12
const void* caller_addr);
13
static struct android_namespace_t* (*android_get_exported_namespace_p)(const char* name);
14
//NOLINTEND
15
static void* ready_handle;
16
17
static const char *sphal_namespaces[3] = {
18
"sphal", "vendor", "default"
19
};
20
21
22
__attribute__((visibility("default"), used)) void app__pojav_linkerhook_pass_handles(void* data, void* android_dlopen_ext,
23
void* android_get_exported_namespace) {
24
ready_handle = data;
25
android_dlopen_ext_p = android_dlopen_ext;
26
android_get_exported_namespace_p = android_get_exported_namespace;
27
}
28
29
__attribute__((visibility("default"), used)) void *android_dlopen_ext(const char *filename, int flags, const android_dlextinfo *extinfo) {
30
if(!strstr(filename, "vulkan."))
31
return android_dlopen_ext_p(filename, flags, extinfo, &android_dlopen_ext);
32
return ready_handle;
33
}
34
35
__attribute__((visibility("default"), used)) void *android_load_sphal_library(const char *filename, int flags) {
36
if(strstr(filename, "vulkan.")) {
37
return ready_handle;
38
}
39
//printf("__loader_android_get_exported_namespace = %p\n__loader_android_dlopen_ext = %p\n", __loader_android_get_exported_namespace,
40
// __loader_android_dlopen_ext);
41
struct android_namespace_t* androidNamespace;
42
for(int i = 0; i < 3; i++) {
43
androidNamespace = android_get_exported_namespace_p(sphal_namespaces[i]);
44
if(androidNamespace != NULL) break;
45
}
46
android_dlextinfo info;
47
info.flags = ANDROID_DLEXT_USE_NAMESPACE;
48
info.library_namespace = androidNamespace;
49
return android_dlopen_ext_p(filename, flags, &info, &android_dlopen_ext);
50
}
51
52
// This is done for older android versions which don't
53
// export this function. Technically this is wrong
54
// but for our usage it's fine enough
55
__attribute__((visibility("default"), used)) uint64_t atrace_get_enabled_tags() {
56
return 0;
57
}
58