[LDR] Guard some sections where we grab a lock.

CORE-14532
This commit is contained in:
Mark Jansen 2018-07-29 17:40:42 +02:00
parent 86fe412d5c
commit ad08c6631b
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B
2 changed files with 194 additions and 180 deletions

View file

@ -353,6 +353,9 @@ LdrLoadDll(IN PWSTR SearchPath OPTIONAL,
/* Check if there's a TLD DLL being loaded */ /* Check if there's a TLD DLL being loaded */
OldTldDll = LdrpTopLevelDllBeingLoaded; OldTldDll = LdrpTopLevelDllBeingLoaded;
_SEH2_TRY
{
if (OldTldDll) if (OldTldDll)
{ {
/* This is a recursive load, do something about it? */ /* This is a recursive load, do something about it? */
@ -414,12 +417,16 @@ LdrLoadDll(IN PWSTR SearchPath OPTIONAL,
DllName, DllName,
Status); Status);
} }
}
_SEH2_FINALLY
{
/* Restore the old TLD DLL */ /* Restore the old TLD DLL */
LdrpTopLevelDllBeingLoaded = OldTldDll; LdrpTopLevelDllBeingLoaded = OldTldDll;
/* Release the lock */ /* Release the lock */
LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, Cookie); LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, Cookie);
}
_SEH2_END;
/* Do we have a redirect string? */ /* Do we have a redirect string? */
if (DllString2.Buffer) RtlFreeUnicodeString(&DllString2); if (DllString2.Buffer) RtlFreeUnicodeString(&DllString2);

View file

@ -2488,6 +2488,8 @@ LdrpLoadDll(IN BOOLEAN Redirected,
/* Check for init flag and acquire lock */ /* Check for init flag and acquire lock */
if (!InInit) RtlEnterCriticalSection(&LdrpLoaderLock); if (!InInit) RtlEnterCriticalSection(&LdrpLoaderLock);
_SEH2_TRY
{
/* Show debug message */ /* Show debug message */
if (ShowSnaps) if (ShowSnaps)
{ {
@ -2511,7 +2513,8 @@ LdrpLoadDll(IN BOOLEAN Redirected,
FALSE, FALSE,
Redirected, Redirected,
&LdrEntry); &LdrEntry);
if (!NT_SUCCESS(Status)) goto Quickie; if (!NT_SUCCESS(Status))
_SEH2_LEAVE;
/* FIXME: Need to mark the DLL range for the stack DB */ /* FIXME: Need to mark the DLL range for the stack DB */
//RtlpStkMarkDllRange(LdrEntry); //RtlpStkMarkDllRange(LdrEntry);
@ -2561,7 +2564,7 @@ LdrpLoadDll(IN BOOLEAN Redirected,
LdrUnloadDll(LdrEntry->DllBase); LdrUnloadDll(LdrEntry->DllBase);
/* Return the error */ /* Return the error */
goto Quickie; _SEH2_LEAVE;
} }
} }
else if (LdrEntry->LoadCount != 0xFFFF) else if (LdrEntry->LoadCount != 0xFFFF)
@ -2625,9 +2628,13 @@ LdrpLoadDll(IN BOOLEAN Redirected,
} }
} }
Quickie: }
_SEH2_FINALLY
{
/* Release the lock */ /* Release the lock */
if (!InInit) RtlLeaveCriticalSection(&LdrpLoaderLock); if (!InInit) RtlLeaveCriticalSection(&LdrpLoaderLock);
}
_SEH2_END;
/* Check for success */ /* Check for success */
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))