[NTOSKRNL] In addition to the hard-error port, reference also the process that handle...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 31 Mar 2018 20:12:44 +0000 (22:12 +0200)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 1 Apr 2018 20:39:30 +0000 (22:39 +0200)
ntoskrnl/ex/harderr.c
ntoskrnl/ex/shutdown.c
ntoskrnl/include/internal/ex.h
ntoskrnl/po/poshtdwn.c

index c5073a3..84f409a 100644 (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;
         }
     }
 
index 6022f27..864f92c 100644 (file)
 #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 *****************************************************************/
 
 /*
index 053b8c8..091b907 100644 (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);
index 04618c9..719f8b8 100644 (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 */