[ntoskrnl]
[reactos.git] / reactos / ntoskrnl / dbgk / dbgkutil.c
index 38d38d3..0d5d571 100644 (file)
@@ -12,8 +12,6 @@
 #define NDEBUG
 #include <debug.h>
 
-extern ULONG DbgkpTraceLevel;
-
 /* FUNCTIONS *****************************************************************/
 
 HANDLE
@@ -61,7 +59,7 @@ DbgkpSuspendProcess(VOID)
     PAGED_CODE();
 
     /* Make sure this isn't a deleted process */
-    if (PsGetCurrentProcess()->ProcessDelete)
+    if (!PsGetCurrentProcess()->ProcessDelete)
     {
         /* Freeze all the threads */
         KeFreezeAllThreads();
@@ -86,9 +84,9 @@ DbgkpResumeProcess(VOID)
 
 VOID
 NTAPI
-DbgkCreateThread(PVOID StartAddress)
+DbgkCreateThread(IN PETHREAD Thread,
+                 IN PVOID StartAddress)
 {
-    PETHREAD Thread = PsGetCurrentThread();
     PEPROCESS Process = PsGetCurrentProcess();
     ULONG ProcessFlags;
     IMAGE_INFO ImageInfo;
@@ -106,10 +104,13 @@ DbgkCreateThread(PVOID StartAddress)
     PTEB Teb;
     PAGED_CODE();
 
+    /* Sanity check */
+    ASSERT(Thread == PsGetCurrentThread());
+
     /* Try ORing in the create reported and image notify flags */
-    ProcessFlags = InterlockedOr((PLONG)&Process->Flags,
-                                 PSF_CREATE_REPORTED_BIT |
-                                 PSF_IMAGE_NOTIFY_DONE_BIT);
+    ProcessFlags = PspSetProcessFlag(Process,
+                                     PSF_CREATE_REPORTED_BIT |
+                                     PSF_IMAGE_NOTIFY_DONE_BIT);
 
     /* Check if we were the first to set them or if another thread raced us */
     if (!(ProcessFlags & PSF_IMAGE_NOTIFY_DONE_BIT) && (PsImageNotifyEnabled))
@@ -208,7 +209,8 @@ DbgkCreateThread(PVOID StartAddress)
         /* Setup the API Message */
         ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
                                  (8 + sizeof(DBGKM_CREATE_PROCESS));
-        ApiMessage.h.u2.ZeroInit = LPC_DEBUG_EVENT;
+        ApiMessage.h.u2.ZeroInit = 0;
+        ApiMessage.h.u2.s2.Type = LPC_DEBUG_EVENT;
         ApiMessage.ApiNumber = DbgKmCreateProcessApi;
 
         /* Send the message */
@@ -268,7 +270,8 @@ DbgkCreateThread(PVOID StartAddress)
             /* Setup the API Message */
             ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
                                      (8 + sizeof(DBGKM_LOAD_DLL));
-            ApiMessage.h.u2.ZeroInit = LPC_DEBUG_EVENT;
+            ApiMessage.h.u2.ZeroInit = 0;
+            ApiMessage.h.u2.s2.Type = LPC_DEBUG_EVENT;
             ApiMessage.ApiNumber = DbgKmLoadDllApi;
 
             /* Send the message */
@@ -282,12 +285,13 @@ DbgkCreateThread(PVOID StartAddress)
     {
         /* Otherwise, do it just for the thread */
         CreateThread->SubSystemKey = 0;
-        CreateThread->StartAddress = NULL;
+        CreateThread->StartAddress = StartAddress;
 
         /* Setup the API Message */
         ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
                                  (8 + sizeof(DBGKM_CREATE_THREAD));
-        ApiMessage.h.u2.ZeroInit = LPC_DEBUG_EVENT;
+        ApiMessage.h.u2.ZeroInit = 0;
+        ApiMessage.h.u2.s2.Type = LPC_DEBUG_EVENT;
         ApiMessage.ApiNumber = DbgKmCreateThreadApi;
 
         /* Send the message */
@@ -320,7 +324,8 @@ DbgkExitProcess(IN NTSTATUS ExitStatus)
     /* Setup the API Message */
     ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
                              (8 + sizeof(DBGKM_EXIT_PROCESS));
-    ApiMessage.h.u2.ZeroInit = LPC_DEBUG_EVENT;
+    ApiMessage.h.u2.ZeroInit = 0;
+    ApiMessage.h.u2.s2.Type = LPC_DEBUG_EVENT;
     ApiMessage.ApiNumber = DbgKmExitProcessApi;
 
     /* Set the current exit time */
@@ -356,7 +361,8 @@ DbgkExitThread(IN NTSTATUS ExitStatus)
     /* Setup the API Message */
     ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
                              (8 + sizeof(DBGKM_EXIT_THREAD));
-    ApiMessage.h.u2.ZeroInit = LPC_DEBUG_EVENT;
+    ApiMessage.h.u2.ZeroInit = 0;
+    ApiMessage.h.u2.s2.Type = LPC_DEBUG_EVENT;
     ApiMessage.ApiNumber = DbgKmExitThreadApi;
 
     /* Suspend the process */
@@ -385,11 +391,10 @@ DbgkMapViewOfSection(IN PVOID Section,
     DBGKTRACE(DBGK_PROCESS_DEBUG,
               "Section: %p. Base: %p\n", Section, BaseAddress);
 
-    /* Check if this thread is hidden, doesn't have a debug port, or died */
-    if ((Thread->HideFromDebugger) ||
-        !(Process->DebugPort) ||
-        (Thread->DeadThread) ||
-        (KeGetPreviousMode() == KernelMode))
+    /* Check if this thread is kernel, hidden or doesn't have a debug port */
+    if ((ExGetPreviousMode() == KernelMode) ||
+        (Thread->HideFromDebugger) ||
+        !(Process->DebugPort))
     {
         /* Don't notify the debugger */
         return;
@@ -414,7 +419,8 @@ DbgkMapViewOfSection(IN PVOID Section,
     /* Setup the API Message */
     ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
                              (8 + sizeof(DBGKM_LOAD_DLL));
-    ApiMessage.h.u2.ZeroInit = LPC_DEBUG_EVENT;
+    ApiMessage.h.u2.ZeroInit = 0;
+    ApiMessage.h.u2.s2.Type = LPC_DEBUG_EVENT;
     ApiMessage.ApiNumber = DbgKmLoadDllApi;
 
     /* Send the message */
@@ -434,11 +440,10 @@ DbgkUnMapViewOfSection(IN PVOID BaseAddress)
     PETHREAD Thread = PsGetCurrentThread();
     PAGED_CODE();
 
-    /* Check if this thread is hidden, doesn't have a debug port, or died */
-    if ((Thread->HideFromDebugger) ||
-        !(Process->DebugPort) ||
-        (Thread->DeadThread) ||
-        (KeGetPreviousMode() == KernelMode))
+    /* Check if this thread is kernel, hidden or doesn't have a debug port */
+    if ((ExGetPreviousMode() == KernelMode) ||
+        (Thread->HideFromDebugger) ||
+        !(Process->DebugPort))
     {
         /* Don't notify the debugger */
         return;
@@ -450,11 +455,10 @@ DbgkUnMapViewOfSection(IN PVOID BaseAddress)
     /* Setup the API Message */
     ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
                              (8 + sizeof(DBGKM_UNLOAD_DLL));
-    ApiMessage.h.u2.ZeroInit = LPC_DEBUG_EVENT;
+    ApiMessage.h.u2.ZeroInit = 0;
+    ApiMessage.h.u2.s2.Type = LPC_DEBUG_EVENT;
     ApiMessage.ApiNumber = DbgKmUnloadDllApi;
 
     /* Send the message */
     DbgkpSendApiMessage(&ApiMessage, TRUE);
 }
-
-/* EOF */