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.
This commit is contained in:
baldurk
2016-11-09 12:01:34 +01:00
parent 7baf53c89b
commit 5ecd4f9437
+10 -4
View File
@@ -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