From 90ef8815e3985f2a07c1585b8ba7c2edbeeeca3a Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 29 Oct 2018 17:20:25 +0000 Subject: [PATCH] Remove RENDERDOC_ANDROID_LIBRARY as a 'hooked library'. Refs #1140 * We only need to check for it in intercept_dlopen to return a consistent handle to our own library regardless of how the library is opened, to prevent multiple copies of the library being loaded. --- renderdoc/os/posix/android/android_hook.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/renderdoc/os/posix/android/android_hook.cpp b/renderdoc/os/posix/android/android_hook.cpp index 03e280bc6..1defb50e3 100644 --- a/renderdoc/os/posix/android/android_hook.cpp +++ b/renderdoc/os/posix/android/android_hook.cpp @@ -215,8 +215,19 @@ HookingInfo &GetHookInfo() void *intercept_dlopen(const char *filename, int flag) { - if(filename && GetHookInfo().IsLibHook(std::string(filename))) - return dlopen(RENDERDOC_ANDROID_LIBRARY, flag); + if(filename) + { + // if this is a library we're hooking, or a request for our own library in any form, return our + // own library. + // We need to intercept requests for our own library, because the android loader makes the + // completely ridiculous decision to load multiple copies of the same library into a process if + // it's dlopen'd with different paths. This obviously breaks with our hook install. + if(strstr(filename, RENDERDOC_ANDROID_LIBRARY) || GetHookInfo().IsLibHook(std::string(filename))) + { + HOOK_DEBUG_PRINT("Intercepting dlopen for %s", filename); + return dlopen(RENDERDOC_ANDROID_LIBRARY, flag); + } + } return NULL; } @@ -520,8 +531,6 @@ static void InstallHooksCommon() GetHookInfo().SetHooked("libc.so"); GetHookInfo().SetHooked("libvndksupport.so"); - GetHookInfo().AddLibHook(RENDERDOC_ANDROID_LIBRARY); - real_android_dlopen_ext = &android_dlopen_ext; loader_dlopen = (pfn__loader_dlopen)dlsym(RTLD_NEXT, "__loader_dlopen");