* Sync up to trunk head (r65394).
[reactos.git] / ntoskrnl / dbgk / dbgkobj.c
index 347a96d..7fcf14c 100644 (file)
@@ -133,7 +133,7 @@ DbgkpQueueMessage(IN PEPROCESS Process,
         if (!DebugObject->DebuggerInactive)
         {
             /* Add the event into the object's list */
-            DBGKTRACE(DBGK_MESSAGE_DEBUG, "Inserting: %lx %p\n",
+            DBGKTRACE(DBGK_MESSAGE_DEBUG, "Inserting: %p %d\n",
                       DebugEvent, Message->ApiNumber);
             InsertTailList(&DebugObject->EventList, &DebugEvent->EventList);
 
@@ -192,7 +192,7 @@ DbgkpQueueMessage(IN PEPROCESS Process,
             ObDereferenceObject(Process);
 
             /* Free the debug event */
-            ExFreePool(DebugEvent);
+            ExFreePoolWithTag(DebugEvent, 'EgbD');
         }
     }
 
@@ -326,7 +326,7 @@ DbgkForwardException(IN PEXCEPTION_RECORD ExceptionRecord,
     BOOLEAN UseLpc = FALSE;
     PAGED_CODE();
     DBGKTRACE(DBGK_EXCEPTION_DEBUG,
-              "ExceptionRecord: %p Port: %p\n", ExceptionRecord, DebugPort);
+              "ExceptionRecord: %p Port: %u\n", ExceptionRecord, DebugPort);
 
     /* Setup the API Message */
     ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
@@ -418,7 +418,7 @@ DbgkpFreeDebugEvent(IN PDEBUG_EVENT DebugEvent)
     /* Dereference process and thread and free the event */
     ObDereferenceObject(DebugEvent->Process);
     ObDereferenceObject(DebugEvent->Thread);
-    ExFreePool(DebugEvent);
+    ExFreePoolWithTag(DebugEvent, 'EgbD');
 }
 
 VOID
@@ -1495,7 +1495,7 @@ DbgkInitialize(VOID)
     ObjectTypeInitializer.GenericMapping = DbgkDebugObjectMapping;
     ObjectTypeInitializer.PoolType = NonPagedPool;
     ObjectTypeInitializer.ValidAccessMask = DEBUG_OBJECT_ALL_ACCESS;
-    ObjectTypeInitializer.UseDefaultObject = TRUE;
+    ObjectTypeInitializer.SecurityRequired = TRUE;
     ObjectTypeInitializer.CloseProcedure = DbgkpCloseObject;
     ObjectTypeInitializer.DeleteProcedure = DbgkpDeleteObject;
     ObCreateObjectType(&Name,
@@ -1504,6 +1504,46 @@ DbgkInitialize(VOID)
                        &DbgkDebugObjectType);
 }
 
+NTSTATUS
+NTAPI
+DbgkOpenProcessDebugPort(IN PEPROCESS Process,
+                         IN KPROCESSOR_MODE PreviousMode,
+                         OUT HANDLE *DebugHandle)
+{
+    PDEBUG_OBJECT DebugObject;
+    NTSTATUS Status;
+    PAGED_CODE();
+
+    /* If there's no debug port, just exit */
+    if (!Process->DebugPort) return STATUS_PORT_NOT_SET;
+
+    /* Otherwise, acquire the lock while we grab the port */
+    ExAcquireFastMutex(&DbgkpProcessDebugPortMutex);
+
+    /* Grab it and reference it if it exists */
+    DebugObject = Process->DebugPort;
+    if (DebugObject) ObReferenceObject(DebugObject);
+
+    /* Release the lock now */
+    ExReleaseFastMutex(&DbgkpProcessDebugPortMutex);
+
+    /* Bail out if it doesn't exist */
+    if (!DebugObject) return STATUS_PORT_NOT_SET;
+
+    /* Now get a handle to it */
+    Status = ObOpenObjectByPointer(DebugObject,
+                                   0,
+                                   NULL,
+                                   MAXIMUM_ALLOWED,
+                                   DbgkDebugObjectType,
+                                   PreviousMode,
+                                   DebugHandle);
+    if (!NT_SUCCESS(Status)) ObDereferenceObject(DebugObject);
+
+    /* Return status */
+    return Status;
+}
+
 /* PUBLIC FUNCTIONS **********************************************************/
 
 /*
@@ -1617,7 +1657,7 @@ NtDebugContinue(IN HANDLE DebugHandle,
     BOOLEAN NeedsWake = FALSE;
     CLIENT_ID ClientId;
     PAGED_CODE();
-    DBGKTRACE(DBGK_OBJECT_DEBUG, "Handle: %p Status: %p\n",
+    DBGKTRACE(DBGK_OBJECT_DEBUG, "Handle: %p Status: %d\n",
               DebugHandle, ContinueStatus);
 
     /* Check if we were called from user mode*/