From 5ecd4f9437b1832c88e1faf536903356c4b7ccbb Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 9 Nov 2016 12:01:34 +0100 Subject: [PATCH] Hold hooking lock for a shorter time to avoid deadlocks * In particular, we don't want to hold this lock while potentially calling FreeLibrary as that could try to acquire the loader lock that another thread might be holding while waiting on our lock. --- renderdoc/os/win32/win32_hook.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/renderdoc/os/win32/win32_hook.cpp b/renderdoc/os/win32/win32_hook.cpp index 9592707b6..220b5e925 100644 --- a/renderdoc/os/win32/win32_hook.cpp +++ b/renderdoc/os/win32/win32_hook.cpp @@ -296,9 +296,12 @@ struct CachedHookData if(found != hookset->FunctionHooks.end() && !strcmp(found->function.c_str(), importName) && found->excludeModule != module) { - SCOPED_LOCK(lock); bool already = false; - bool applied = found->ApplyHook(IATentry, already); + bool applied; + { + SCOPED_LOCK(lock); + applied = found->ApplyHook(IATentry, already); + } // if we failed, or if it's already set and we're not doing a missedOrdinals // second pass, then just bail out immediately as we've already hooked this @@ -344,9 +347,12 @@ struct CachedHookData if(found != hookset->FunctionHooks.end() && !strcmp(found->function.c_str(), importName) && found->excludeModule != module) { - SCOPED_LOCK(lock); bool already = false; - bool applied = found->ApplyHook(IATentry, already); + bool applied; + { + SCOPED_LOCK(lock); + applied = found->ApplyHook(IATentry, already); + } // if we failed, or if it's already set and we're not doing a missedOrdinals // second pass, then just bail out immediately as we've already hooked this