mirror of
https://github.com/reactos/reactos.git
synced 2025-07-16 04:14:10 +00:00
[LDR] Protect calls from LdrpCallInitRoutine and LdrpCallTlsInitializers with SEH.
CORE-14532
This commit is contained in:
parent
1ea68d0510
commit
dfff8ed0d8
2 changed files with 140 additions and 68 deletions
|
@ -1476,10 +1476,18 @@ LdrUnloadDll(IN PVOID BaseAddress)
|
||||||
LdrEntry->EntryPointActivationContext);
|
LdrEntry->EntryPointActivationContext);
|
||||||
|
|
||||||
/* Call the entrypoint */
|
/* Call the entrypoint */
|
||||||
|
_SEH2_TRY
|
||||||
|
{
|
||||||
LdrpCallInitRoutine(LdrEntry->EntryPoint,
|
LdrpCallInitRoutine(LdrEntry->EntryPoint,
|
||||||
LdrEntry->DllBase,
|
LdrEntry->DllBase,
|
||||||
DLL_PROCESS_DETACH,
|
DLL_PROCESS_DETACH,
|
||||||
NULL);
|
NULL);
|
||||||
|
}
|
||||||
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
}
|
||||||
|
_SEH2_END;
|
||||||
|
|
||||||
/* Release the context */
|
/* Release the context */
|
||||||
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
||||||
|
|
|
@ -552,6 +552,8 @@ LdrpInitializeThread(IN PCONTEXT Context)
|
||||||
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
||||||
LdrEntry->EntryPointActivationContext);
|
LdrEntry->EntryPointActivationContext);
|
||||||
|
|
||||||
|
_SEH2_TRY
|
||||||
|
{
|
||||||
/* Check if it has TLS */
|
/* Check if it has TLS */
|
||||||
if (LdrEntry->TlsIndex)
|
if (LdrEntry->TlsIndex)
|
||||||
{
|
{
|
||||||
|
@ -576,6 +578,12 @@ LdrpInitializeThread(IN PCONTEXT Context)
|
||||||
DLL_THREAD_ATTACH,
|
DLL_THREAD_ATTACH,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
}
|
||||||
|
_SEH2_END;
|
||||||
|
|
||||||
/* Deactivate the ActCtx */
|
/* Deactivate the ActCtx */
|
||||||
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
||||||
|
@ -599,8 +607,16 @@ LdrpInitializeThread(IN PCONTEXT Context)
|
||||||
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
||||||
LdrpImageEntry->EntryPointActivationContext);
|
LdrpImageEntry->EntryPointActivationContext);
|
||||||
|
|
||||||
|
_SEH2_TRY
|
||||||
|
{
|
||||||
/* Do TLS callbacks */
|
/* Do TLS callbacks */
|
||||||
LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_THREAD_ATTACH);
|
LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_THREAD_ATTACH);
|
||||||
|
}
|
||||||
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
}
|
||||||
|
_SEH2_END;
|
||||||
|
|
||||||
/* Deactivate the ActCtx */
|
/* Deactivate the ActCtx */
|
||||||
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
||||||
|
@ -796,6 +812,8 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
|
||||||
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
||||||
LdrEntry->EntryPointActivationContext);
|
LdrEntry->EntryPointActivationContext);
|
||||||
|
|
||||||
|
_SEH2_TRY
|
||||||
|
{
|
||||||
/* Check if it has TLS */
|
/* Check if it has TLS */
|
||||||
if (LdrEntry->TlsIndex && Context)
|
if (LdrEntry->TlsIndex && Context)
|
||||||
{
|
{
|
||||||
|
@ -813,6 +831,12 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
|
||||||
LdrEntry->DllBase,
|
LdrEntry->DllBase,
|
||||||
DLL_PROCESS_ATTACH,
|
DLL_PROCESS_ATTACH,
|
||||||
Context);
|
Context);
|
||||||
|
}
|
||||||
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
DllStatus = FALSE;
|
||||||
|
}
|
||||||
|
_SEH2_END;
|
||||||
|
|
||||||
/* Deactivate the ActCtx */
|
/* Deactivate the ActCtx */
|
||||||
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
||||||
|
@ -862,8 +886,16 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
|
||||||
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
||||||
LdrpImageEntry->EntryPointActivationContext);
|
LdrpImageEntry->EntryPointActivationContext);
|
||||||
|
|
||||||
|
_SEH2_TRY
|
||||||
|
{
|
||||||
/* Do TLS callbacks */
|
/* Do TLS callbacks */
|
||||||
LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_PROCESS_ATTACH);
|
LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_PROCESS_ATTACH);
|
||||||
|
}
|
||||||
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
}
|
||||||
|
_SEH2_END;
|
||||||
|
|
||||||
/* Deactivate the ActCtx */
|
/* Deactivate the ActCtx */
|
||||||
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
||||||
|
@ -958,6 +990,8 @@ LdrShutdownProcess(VOID)
|
||||||
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
||||||
LdrEntry->EntryPointActivationContext);
|
LdrEntry->EntryPointActivationContext);
|
||||||
|
|
||||||
|
_SEH2_TRY
|
||||||
|
{
|
||||||
/* Check if it has TLS */
|
/* Check if it has TLS */
|
||||||
if (LdrEntry->TlsIndex)
|
if (LdrEntry->TlsIndex)
|
||||||
{
|
{
|
||||||
|
@ -972,6 +1006,12 @@ LdrShutdownProcess(VOID)
|
||||||
LdrEntry->DllBase,
|
LdrEntry->DllBase,
|
||||||
DLL_PROCESS_DETACH,
|
DLL_PROCESS_DETACH,
|
||||||
(PVOID)1);
|
(PVOID)1);
|
||||||
|
}
|
||||||
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
}
|
||||||
|
_SEH2_END;
|
||||||
|
|
||||||
/* Deactivate the ActCtx */
|
/* Deactivate the ActCtx */
|
||||||
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
||||||
|
@ -991,8 +1031,16 @@ LdrShutdownProcess(VOID)
|
||||||
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
||||||
LdrpImageEntry->EntryPointActivationContext);
|
LdrpImageEntry->EntryPointActivationContext);
|
||||||
|
|
||||||
|
_SEH2_TRY
|
||||||
|
{
|
||||||
/* Do TLS callbacks */
|
/* Do TLS callbacks */
|
||||||
LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_PROCESS_DETACH);
|
LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_PROCESS_DETACH);
|
||||||
|
}
|
||||||
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
}
|
||||||
|
_SEH2_END;
|
||||||
|
|
||||||
/* Deactivate the ActCtx */
|
/* Deactivate the ActCtx */
|
||||||
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
||||||
|
@ -1066,6 +1114,8 @@ LdrShutdownThread(VOID)
|
||||||
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
||||||
LdrEntry->EntryPointActivationContext);
|
LdrEntry->EntryPointActivationContext);
|
||||||
|
|
||||||
|
_SEH2_TRY
|
||||||
|
{
|
||||||
/* Check if it has TLS */
|
/* Check if it has TLS */
|
||||||
if (LdrEntry->TlsIndex)
|
if (LdrEntry->TlsIndex)
|
||||||
{
|
{
|
||||||
|
@ -1088,6 +1138,12 @@ LdrShutdownThread(VOID)
|
||||||
DLL_THREAD_DETACH,
|
DLL_THREAD_DETACH,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
}
|
||||||
|
_SEH2_END;
|
||||||
|
|
||||||
/* Deactivate the ActCtx */
|
/* Deactivate the ActCtx */
|
||||||
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
||||||
|
@ -1108,8 +1164,16 @@ LdrShutdownThread(VOID)
|
||||||
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
||||||
LdrpImageEntry->EntryPointActivationContext);
|
LdrpImageEntry->EntryPointActivationContext);
|
||||||
|
|
||||||
|
_SEH2_TRY
|
||||||
|
{
|
||||||
/* Do TLS callbacks */
|
/* Do TLS callbacks */
|
||||||
LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_THREAD_DETACH);
|
LdrpCallTlsInitializers(Peb->ImageBaseAddress, DLL_THREAD_DETACH);
|
||||||
|
}
|
||||||
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
/* Do nothing */
|
||||||
|
}
|
||||||
|
_SEH2_END;
|
||||||
|
|
||||||
/* Deactivate the ActCtx */
|
/* Deactivate the ActCtx */
|
||||||
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue