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

View file

@ -14,6 +14,25 @@
#define NDEBUG
#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 *****************************************************************/
/*

View file

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

View file

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