Path: blob/v3_openjdk/app_pojavlauncher/src/main/jni/driver_helper/hook.c
2128 views
//1// Created by maks on 05.06.2023.2//3#include <android/dlext.h>4#include <string.h>5#include <stdio.h>6// Silence the warnings about using reserved identifiers (we need to link to these to not pollute the global symtab)7//NOLINTBEGIN8static void* (*android_dlopen_ext_p)(const char* filename,9int flags,10const android_dlextinfo* extinfo,11const void* caller_addr);12static struct android_namespace_t* (*android_get_exported_namespace_p)(const char* name);13//NOLINTEND14static void* ready_handle;1516static const char *sphal_namespaces[3] = {17"sphal", "vendor", "default"18};192021__attribute__((visibility("default"), used)) void app__pojav_linkerhook_pass_handles(void* data, void* android_dlopen_ext,22void* android_get_exported_namespace) {23ready_handle = data;24android_dlopen_ext_p = android_dlopen_ext;25android_get_exported_namespace_p = android_get_exported_namespace;26}2728__attribute__((visibility("default"), used)) void *android_dlopen_ext(const char *filename, int flags, const android_dlextinfo *extinfo) {29if(!strstr(filename, "vulkan."))30return android_dlopen_ext_p(filename, flags, extinfo, &android_dlopen_ext);31return ready_handle;32}3334__attribute__((visibility("default"), used)) void *android_load_sphal_library(const char *filename, int flags) {35if(strstr(filename, "vulkan.")) {36return ready_handle;37}38//printf("__loader_android_get_exported_namespace = %p\n__loader_android_dlopen_ext = %p\n", __loader_android_get_exported_namespace,39// __loader_android_dlopen_ext);40struct android_namespace_t* androidNamespace;41for(int i = 0; i < 3; i++) {42androidNamespace = android_get_exported_namespace_p(sphal_namespaces[i]);43if(androidNamespace != NULL) break;44}45android_dlextinfo info;46info.flags = ANDROID_DLEXT_USE_NAMESPACE;47info.library_namespace = androidNamespace;48return android_dlopen_ext_p(filename, flags, &info, &android_dlopen_ext);49}5051// This is done for older android versions which don't52// export this function. Technically this is wrong53// but for our usage it's fine enough54__attribute__((visibility("default"), used)) uint64_t atrace_get_enabled_tags() {55return 0;56}5758