https://git.reactos.org/?p=reactos.git;a=commitdiff;h=55053f0099c0f29f5e7d7…
commit 55053f0099c0f29f5e7d7fba5c87b46599f0b3b7
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Sun Jul 29 17:13:42 2018 +0200
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Mon Aug 13 13:24:12 2018 +0200
[LDR] Add debug logging when we encountered an exception in dll/tls callbacks.
CORE-14532
---
dll/ntdll/include/ntdllp.h | 6 +++---
dll/ntdll/ldr/ldrapi.c | 3 ++-
dll/ntdll/ldr/ldrinit.c | 27 ++++++++++++++++-----------
dll/ntdll/ldr/ldrutils.c | 13 +++++++------
4 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/dll/ntdll/include/ntdllp.h b/dll/ntdll/include/ntdllp.h
index 29ade67b45..934a4b2205 100644
--- a/dll/ntdll/include/ntdllp.h
+++ b/dll/ntdll/include/ntdllp.h
@@ -62,9 +62,9 @@ VOID NTAPI LdrpInitializeThread(IN PCONTEXT Context);
NTSTATUS NTAPI LdrpInitializeTls(VOID);
NTSTATUS NTAPI LdrpAllocateTls(VOID);
VOID NTAPI LdrpFreeTls(VOID);
-VOID NTAPI LdrpCallTlsInitializers(PVOID BaseAddress, ULONG Reason);
-BOOLEAN NTAPI LdrpCallInitRoutine(PDLL_INIT_ROUTINE EntryPoint, PVOID BaseAddress, ULONG
Reason, PVOID Context);
-NTSTATUS NTAPI LdrpInitializeProcess(PCONTEXT Context, PVOID SystemArgument1);
+VOID NTAPI LdrpCallTlsInitializers(IN PLDR_DATA_TABLE_ENTRY LdrEntry, IN ULONG Reason);
+BOOLEAN NTAPI LdrpCallInitRoutine(IN PDLL_INIT_ROUTINE EntryPoint, IN PVOID BaseAddress,
IN ULONG Reason, IN PVOID Context);
+NTSTATUS NTAPI LdrpInitializeProcess(IN PCONTEXT Context, IN PVOID SystemArgument1);
VOID NTAPI LdrpInitFailure(NTSTATUS Status);
VOID NTAPI LdrpValidateImageForMp(IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry);
VOID NTAPI LdrpEnsureLoaderLockIsHeld(VOID);
diff --git a/dll/ntdll/ldr/ldrapi.c b/dll/ntdll/ldr/ldrapi.c
index d9da842374..15f36bb2be 100644
--- a/dll/ntdll/ldr/ldrapi.c
+++ b/dll/ntdll/ldr/ldrapi.c
@@ -1485,7 +1485,8 @@ LdrUnloadDll(IN PVOID BaseAddress)
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- /* Do nothing */
+ DPRINT1("WARNING: Exception 0x%x during
LdrpCallInitRoutine(DLL_PROCESS_DETACH) for %wZ\n",
+ _SEH2_GetExceptionCode(), &LdrEntry->BaseDllName);
}
_SEH2_END;
diff --git a/dll/ntdll/ldr/ldrinit.c b/dll/ntdll/ldr/ldrinit.c
index 96af326062..058a128bdf 100644
--- a/dll/ntdll/ldr/ldrinit.c
+++ b/dll/ntdll/ldr/ldrinit.c
@@ -561,7 +561,7 @@ LdrpInitializeThread(IN PCONTEXT Context)
if (!LdrpShutdownInProgress)
{
/* Call TLS */
- LdrpCallTlsInitializers(LdrEntry->DllBase,
DLL_THREAD_ATTACH);
+ LdrpCallTlsInitializers(LdrEntry, DLL_THREAD_ATTACH);
}
}
@@ -581,7 +581,8 @@ LdrpInitializeThread(IN PCONTEXT Context)
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- /* Do nothing */
+ DPRINT1("WARNING: Exception 0x%x during
LdrpCallInitRoutine(DLL_THREAD_ATTACH) for %wZ\n",
+ _SEH2_GetExceptionCode(),
&LdrEntry->BaseDllName);
}
_SEH2_END;
@@ -610,7 +611,7 @@ LdrpInitializeThread(IN PCONTEXT Context)
_SEH2_TRY
{
/* Do TLS callbacks */
- LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_THREAD_ATTACH);
+ LdrpCallTlsInitializers(LdrpImageEntry, DLL_THREAD_ATTACH);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@@ -818,7 +819,7 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
if (LdrEntry->TlsIndex && Context)
{
/* Call TLS */
- LdrpCallTlsInitializers(LdrEntry->DllBase, DLL_PROCESS_ATTACH);
+ LdrpCallTlsInitializers(LdrEntry, DLL_PROCESS_ATTACH);
}
/* Call the Entrypoint */
@@ -835,6 +836,8 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
DllStatus = FALSE;
+ DPRINT1("WARNING: Exception 0x%x during
LdrpCallInitRoutine(DLL_PROCESS_ATTACH) for %wZ\n",
+ _SEH2_GetExceptionCode(), &LdrEntry->BaseDllName);
}
_SEH2_END;
@@ -889,7 +892,7 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
_SEH2_TRY
{
/* Do TLS callbacks */
- LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_PROCESS_ATTACH);
+ LdrpCallTlsInitializers(LdrpImageEntry, DLL_PROCESS_ATTACH);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@@ -996,7 +999,7 @@ LdrShutdownProcess(VOID)
if (LdrEntry->TlsIndex)
{
/* Call TLS */
- LdrpCallTlsInitializers(LdrEntry->DllBase,
DLL_PROCESS_DETACH);
+ LdrpCallTlsInitializers(LdrEntry, DLL_PROCESS_DETACH);
}
/* Call the Entrypoint */
@@ -1009,7 +1012,8 @@ LdrShutdownProcess(VOID)
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- /* Do nothing */
+ DPRINT1("WARNING: Exception 0x%x during
LdrpCallInitRoutine(DLL_PROCESS_DETACH) for %wZ\n",
+ _SEH2_GetExceptionCode(), &LdrEntry->BaseDllName);
}
_SEH2_END;
@@ -1034,7 +1038,7 @@ LdrShutdownProcess(VOID)
_SEH2_TRY
{
/* Do TLS callbacks */
- LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_PROCESS_DETACH);
+ LdrpCallTlsInitializers(LdrpImageEntry, DLL_PROCESS_DETACH);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@@ -1123,7 +1127,7 @@ LdrShutdownThread(VOID)
if (!LdrpShutdownInProgress)
{
/* Call TLS */
- LdrpCallTlsInitializers(LdrEntry->DllBase,
DLL_THREAD_DETACH);
+ LdrpCallTlsInitializers(LdrEntry, DLL_THREAD_DETACH);
}
}
@@ -1141,7 +1145,8 @@ LdrShutdownThread(VOID)
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- /* Do nothing */
+ DPRINT1("WARNING: Exception 0x%x during
LdrpCallInitRoutine(DLL_THREAD_DETACH) for %wZ\n",
+ _SEH2_GetExceptionCode(),
&LdrEntry->BaseDllName);
}
_SEH2_END;
@@ -1167,7 +1172,7 @@ LdrShutdownThread(VOID)
_SEH2_TRY
{
/* Do TLS callbacks */
- LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_THREAD_DETACH);
+ LdrpCallTlsInitializers(LdrpImageEntry, DLL_THREAD_DETACH);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
diff --git a/dll/ntdll/ldr/ldrutils.c b/dll/ntdll/ldr/ldrutils.c
index 5459d4a5d2..5f55938d13 100644
--- a/dll/ntdll/ldr/ldrutils.c
+++ b/dll/ntdll/ldr/ldrutils.c
@@ -470,7 +470,7 @@ LdrpUpdateLoadCount2(IN PLDR_DATA_TABLE_ENTRY LdrEntry,
VOID
NTAPI
-LdrpCallTlsInitializers(IN PVOID BaseAddress,
+LdrpCallTlsInitializers(IN PLDR_DATA_TABLE_ENTRY LdrEntry,
IN ULONG Reason)
{
PIMAGE_TLS_DIRECTORY TlsDirectory;
@@ -478,7 +478,7 @@ LdrpCallTlsInitializers(IN PVOID BaseAddress,
ULONG Size;
/* Get the TLS Directory */
- TlsDirectory = RtlImageDirectoryEntryToData(BaseAddress,
+ TlsDirectory = RtlImageDirectoryEntryToData(LdrEntry->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_TLS,
&Size);
@@ -497,7 +497,7 @@ LdrpCallTlsInitializers(IN PVOID BaseAddress,
if (ShowSnaps)
{
DPRINT1("LDR: Tls Callbacks Found. Imagebase %p Tls %p CallBacks
%p\n",
- BaseAddress, TlsDirectory, Array);
+ LdrEntry->DllBase, TlsDirectory, Array);
}
/* Loop the array */
@@ -510,12 +510,12 @@ LdrpCallTlsInitializers(IN PVOID BaseAddress,
if (ShowSnaps)
{
DPRINT1("LDR: Calling Tls Callback Imagebase %p Function
%p\n",
- BaseAddress, Callback);
+ LdrEntry->DllBase, Callback);
}
/* Call it */
LdrpCallInitRoutine((PDLL_INIT_ROUTINE)Callback,
- BaseAddress,
+ LdrEntry->DllBase,
Reason,
NULL);
}
@@ -524,7 +524,8 @@ LdrpCallTlsInitializers(IN PVOID BaseAddress,
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- /* Do nothing */
+ DPRINT1("LDR: Exception 0x%x during Tls Callback(%u) for %wZ\n",
+ _SEH2_GetExceptionCode(), Reason, &LdrEntry->BaseDllName);
}
_SEH2_END;
}