diff --git a/src/hook/gsl_alloc_hook.c b/src/hook/gsl_alloc_hook.c index 6e746c9..07f332d 100644 --- a/src/hook/gsl_alloc_hook.c +++ b/src/hook/gsl_alloc_hook.c @@ -1,9 +1,13 @@ #include "hook_impl.h" __attribute__((visibility("default"))) int gsl_memory_alloc_pure(uint32_t size, uint32_t flags, void *memDesc) { - return hook_gsl_memory_alloc_pure(size, flags, memDesc); + return hook_gsl_memory_alloc_pure_64((uint64_t)size, flags, memDesc); +} + +__attribute__((visibility("default"))) int gsl_memory_alloc_pure_64(uint64_t size, uint32_t flags, void *memDesc) { + return hook_gsl_memory_alloc_pure_64(size, flags, memDesc); } __attribute__((visibility("default"))) int gsl_memory_free_pure(void *memDesc) { return hook_gsl_memory_free_pure(memDesc); -} \ No newline at end of file +} diff --git a/src/hook/hook_impl.cpp b/src/hook/hook_impl.cpp index c28337a..bd3356d 100644 --- a/src/hook/hook_impl.cpp +++ b/src/hook/hook_impl.cpp @@ -17,18 +17,21 @@ const HookImplParams *hook_params; //!< Bunch of info needed to load/patch the driver int (*gsl_memory_alloc_pure_sym)(uint32_t, uint32_t, void *); +int (*gsl_memory_alloc_pure_64_sym)(uint64_t, uint32_t, void *); int (*gsl_memory_free_pure_sym)(void *); int kgsl_fd; using gsl_memory_alloc_pure_t = decltype(gsl_memory_alloc_pure_sym); +using gsl_memory_alloc_pure_64_t = decltype(gsl_memory_alloc_pure_64_sym); using gsl_memory_free_pure_t = decltype(gsl_memory_free_pure_sym); __attribute__((visibility("default"))) void init_hook_param(const void *param) { hook_params = reinterpret_cast(param); } -__attribute__((visibility("default"))) void init_gsl(void *alloc, void *free) { +__attribute__((visibility("default"))) void init_gsl(void *alloc, void *alloc64, void *free) { gsl_memory_alloc_pure_sym = reinterpret_cast(alloc); + gsl_memory_alloc_pure_64_sym = reinterpret_cast(alloc64); gsl_memory_free_pure_sym = reinterpret_cast(free); } @@ -102,19 +105,20 @@ __attribute__((visibility("default"))) void *hook_android_dlopen_ext(const char if (libgslHandle) { gsl_memory_alloc_pure_sym = reinterpret_cast(dlsym(libgslHandle, "gsl_memory_alloc_pure")); + gsl_memory_alloc_pure_64_sym = reinterpret_cast(dlsym(libgslHandle, "gsl_memory_alloc_pure_64")); gsl_memory_free_pure_sym = reinterpret_cast(dlsym(libgslHandle, "gsl_memory_free_pure")); - if (gsl_memory_alloc_pure_sym && gsl_memory_free_pure_sym) { - auto initGsl{reinterpret_cast(dlsym(hookImpl, "init_gsl"))}; + if ((gsl_memory_alloc_pure_sym || gsl_memory_alloc_pure_64_sym) && gsl_memory_free_pure_sym) { + auto initGsl{reinterpret_cast(dlsym(hookImpl, "init_gsl"))}; if (!initGsl) return fallback(); - initGsl(gsl_memory_alloc_pure_sym, gsl_memory_free_pure_sym); + initGsl(gsl_memory_alloc_pure_sym, gsl_memory_alloc_pure_64_sym, gsl_memory_free_pure_sym); LOGI("hook_android_dlopen_ext: applied libgsl_alloc_hook"); hook_params->nextGpuMapping->gpu_addr = ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC; } } - if (!gsl_memory_alloc_pure_sym || !gsl_memory_free_pure_sym) + if (!((gsl_memory_alloc_pure_sym || gsl_memory_alloc_pure_64_sym) && gsl_memory_free_pure_sym)) LOGI("hook_android_dlopen_ext: hook failed: failed to apply libgsl_alloc_hook!"); } @@ -174,7 +178,7 @@ struct GslMemDesc { uintptr_t priv; }; -__attribute__((visibility("default"))) int hook_gsl_memory_alloc_pure(uint32_t size, uint32_t flags, void *memDesc) { +__attribute__((visibility("default"))) int hook_gsl_memory_alloc_pure_64(uint64_t size, uint32_t flags, void *memDesc) { auto gslMemDesc{reinterpret_cast(memDesc)}; if (hook_params->nextGpuMapping && hook_params->nextGpuMapping->size == size && (hook_params->nextGpuMapping->flags & flags) == hook_params->nextGpuMapping->flags) { auto &nextMapping{*hook_params->nextGpuMapping}; @@ -188,7 +192,10 @@ __attribute__((visibility("default"))) int hook_gsl_memory_alloc_pure(uint32_t s hook_params->nextGpuMapping->gpu_addr = ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC; return 0; } else { - return gsl_memory_alloc_pure_sym(size, flags, gslMemDesc); + if (gsl_memory_alloc_pure_64_sym) + return gsl_memory_alloc_pure_64_sym(size, flags, gslMemDesc); + else + return gsl_memory_alloc_pure_sym((uint32_t)size, flags, gslMemDesc); } } diff --git a/src/hook/hook_impl.h b/src/hook/hook_impl.h index 9e067af..fd0e3ca 100644 --- a/src/hook/hook_impl.h +++ b/src/hook/hook_impl.h @@ -20,7 +20,7 @@ void *hook_android_load_sphal_library(const char *filename, int flags); FILE *hook_fopen(const char *filename, const char *mode); -int hook_gsl_memory_alloc_pure(uint32_t size, uint32_t flags, void *memDesc); +int hook_gsl_memory_alloc_pure_64(uint64_t size, uint32_t flags, void *memDesc); int hook_gsl_memory_free_pure(void *memDesc);