[NTOSKRNL] In addition to the hard-error port, reference also the process that handles the hard errors so that it doesn't disappear behind our back. On shutdown both the hard-error port and process are dereferenced.

This commit is contained in:
Hermès Bélusca-Maïto 2018-03-31 22:12:44 +02:00
parent 7ca90b50de
commit ed06b843fb
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 36 additions and 3 deletions

View file

@ -707,7 +707,7 @@ NtSetDefaultHardErrorPort(IN HANDLE PortHandle)
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
NTSTATUS Status = STATUS_UNSUCCESSFUL; NTSTATUS Status = STATUS_UNSUCCESSFUL;
/* Check if we have the Privilege */ /* Check if we have the privileges */
if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode)) if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode))
{ {
DPRINT1("NtSetDefaultHardErrorPort: Caller requires " DPRINT1("NtSetDefaultHardErrorPort: Caller requires "
@ -718,7 +718,7 @@ NtSetDefaultHardErrorPort(IN HANDLE PortHandle)
/* Only called once during bootup, make sure we weren't called yet */ /* Only called once during bootup, make sure we weren't called yet */
if (!ExReadyForErrors) if (!ExReadyForErrors)
{ {
/* Reference the port */ /* Reference the hard-error port */
Status = ObReferenceObjectByHandle(PortHandle, Status = ObReferenceObjectByHandle(PortHandle,
0, 0,
LpcPortObjectType, LpcPortObjectType,
@ -727,9 +727,11 @@ NtSetDefaultHardErrorPort(IN HANDLE PortHandle)
NULL); NULL);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* Save the data */ /* Keep also a reference to the process handling the hard errors */
ExpDefaultErrorPortProcess = PsGetCurrentProcess(); ExpDefaultErrorPortProcess = PsGetCurrentProcess();
ObReferenceObject(ExpDefaultErrorPortProcess);
ExReadyForErrors = TRUE; ExReadyForErrors = TRUE;
Status = STATUS_SUCCESS;
} }
} }

View file

@ -14,6 +14,25 @@
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
/* PRIVATE FUNCTIONS *********************************************************/
VOID
NTAPI
ExShutdownSystem(VOID)
{
/* Dereference the hard-error port and process objects */
if (ExpDefaultErrorPort)
{
ObDereferenceObject(ExpDefaultErrorPort);
ExpDefaultErrorPort = NULL;
}
if (ExpDefaultErrorPortProcess)
{
ObDereferenceObject(ExpDefaultErrorPortProcess);
ExpDefaultErrorPortProcess = NULL;
}
}
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
/* /*

View file

@ -31,6 +31,9 @@ extern KSPIN_LOCK ExpPagedLookasideListLock;
extern ULONG ExCriticalWorkerThreads; extern ULONG ExCriticalWorkerThreads;
extern ULONG ExDelayedWorkerThreads; extern ULONG ExDelayedWorkerThreads;
extern PVOID ExpDefaultErrorPort;
extern PEPROCESS ExpDefaultErrorPortProcess;
/* /*
* NT/Cm Version Info variables * NT/Cm Version Info variables
*/ */
@ -60,6 +63,7 @@ extern WINKD_WORKER_STATE ExpDebuggerWork;
extern PEPROCESS ExpDebuggerProcessAttach; extern PEPROCESS ExpDebuggerProcessAttach;
extern PEPROCESS ExpDebuggerProcessKill; extern PEPROCESS ExpDebuggerProcessKill;
extern ULONG_PTR ExpDebuggerPageIn; extern ULONG_PTR ExpDebuggerPageIn;
VOID NTAPI ExpDebuggerWorker(IN PVOID Context); VOID NTAPI ExpDebuggerWorker(IN PVOID Context);
// #endif /* _WINKD_ */ // #endif /* _WINKD_ */
@ -227,6 +231,10 @@ ExpInitializeExecutive(
IN PLOADER_PARAMETER_BLOCK LoaderBlock IN PLOADER_PARAMETER_BLOCK LoaderBlock
); );
VOID
NTAPI
ExShutdownSystem(VOID);
BOOLEAN BOOLEAN
NTAPI NTAPI
ExpInitializeEventImplementation(VOID); ExpInitializeEventImplementation(VOID);

View file

@ -278,6 +278,10 @@ PopGracefulShutdown(IN PVOID Context)
DPRINT("Configuration Manager shutting down\n"); DPRINT("Configuration Manager shutting down\n");
CmShutdownSystem(); CmShutdownSystem();
/* Shut down the Executive */
DPRINT("Executive shutting down\n");
ExShutdownSystem();
/* Note that modified pages should be written here (MiShutdownSystem) */ /* Note that modified pages should be written here (MiShutdownSystem) */
/* Flush all user files before we start shutting down IO */ /* Flush all user files before we start shutting down IO */