[MS] Add messages 2200-2249 and 3502-3507 to netmsg.dll.
[reactos.git] / ntoskrnl / dbgk / dbgkobj.c
index cdf081f..3f03e9b 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);
 
@@ -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 |
@@ -470,6 +470,7 @@ DbgkpPostFakeModuleMessages(IN PEPROCESS Process,
     OBJECT_ATTRIBUTES ObjectAttributes;
     IO_STATUS_BLOCK IoStatusBlock;
     NTSTATUS Status;
+    UNICODE_STRING FullDllName;
     PAGED_CODE();
     DBGKTRACE(DBGK_PROCESS_DEBUG, "Process: %p Thread: %p DebugObject: %p\n",
               Process, Thread, DebugObject);
@@ -477,96 +478,112 @@ DbgkpPostFakeModuleMessages(IN PEPROCESS Process,
     /* Quit if there's no PEB */
     if (!Peb) return STATUS_SUCCESS;
 
-    /* Get the Loader Data List */
-    LdrData = Peb->Ldr;
-    ListHead = &LdrData->InLoadOrderModuleList;
-    NextEntry = ListHead->Flink;
-
-    /* Loop the modules */
-    i = 0;
-    while ((NextEntry != ListHead) && (i < 500))
+    /* Accessing user memory, need SEH */
+    _SEH2_TRY
     {
-        /* Skip the first entry */
-        if (!i)
+        /* Get the Loader Data List */
+        ProbeForRead(Peb, sizeof(*Peb), 1);
+        LdrData = Peb->Ldr;
+        ProbeForRead(LdrData, sizeof(*LdrData), 1);
+        ListHead = &LdrData->InLoadOrderModuleList;
+        ProbeForRead(ListHead, sizeof(*ListHead), 1);
+        NextEntry = ListHead->Flink;
+
+        /* Loop the modules */
+        i = 0;
+        while ((NextEntry != ListHead) && (i < 500))
         {
-            /* Go to the next module */
-            NextEntry = NextEntry->Flink;
-            i++;
-            continue;
-        }
+            ProbeForRead(NextEntry, sizeof(*NextEntry), 1);
+            /* Skip the first entry */
+            if (!i)
+            {
+                /* Go to the next module */
+                NextEntry = NextEntry->Flink;
+                i++;
+                continue;
+            }
 
-        /* Get the entry */
-        LdrEntry = CONTAINING_RECORD(NextEntry,
-                                     LDR_DATA_TABLE_ENTRY,
-                                     InLoadOrderLinks);
+            /* Get the entry */
+            LdrEntry = CONTAINING_RECORD(NextEntry,
+                                         LDR_DATA_TABLE_ENTRY,
+                                         InLoadOrderLinks);
+            ProbeForRead(LdrEntry, sizeof(*LdrEntry), 1);
 
-        /* Setup the API Message */
-        RtlZeroMemory(&ApiMessage, sizeof(DBGKM_MSG));
-        ApiMessage.ApiNumber = DbgKmLoadDllApi;
+            /* Setup the API Message */
+            RtlZeroMemory(&ApiMessage, sizeof(DBGKM_MSG));
+            ApiMessage.ApiNumber = DbgKmLoadDllApi;
 
-        /* Set base and clear the name */
-        LoadDll->BaseOfDll = LdrEntry->DllBase;
-        LoadDll->NamePointer = NULL;
+            /* Set base and clear the name */
+            LoadDll->BaseOfDll = LdrEntry->DllBase;
+            LoadDll->NamePointer = NULL;
 
-        /* Get the NT Headers */
-        NtHeader = RtlImageNtHeader(LoadDll->BaseOfDll);
-        if (NtHeader)
-        {
-            /* Save debug data */
-            LoadDll->DebugInfoFileOffset = NtHeader->FileHeader.
-                                           PointerToSymbolTable;
-            LoadDll->DebugInfoSize = NtHeader->FileHeader.NumberOfSymbols;
-        }
+            /* Get the NT Headers */
+            NtHeader = RtlImageNtHeader(LoadDll->BaseOfDll);
+            if (NtHeader)
+            {
+                /* Save debug data */
+                LoadDll->DebugInfoFileOffset = NtHeader->FileHeader.
+                                               PointerToSymbolTable;
+                LoadDll->DebugInfoSize = NtHeader->FileHeader.NumberOfSymbols;
+            }
 
-        /* Trace */
-        DBGKTRACE(DBGK_PROCESS_DEBUG, "Name: %wZ. Base: %p\n",
-                  &LdrEntry->FullDllName, LdrEntry->DllBase);
+            /* Trace */
+            FullDllName = LdrEntry->FullDllName;
+            ProbeForRead(FullDllName.Buffer, FullDllName.MaximumLength, 1);
+            DBGKTRACE(DBGK_PROCESS_DEBUG, "Name: %wZ. Base: %p\n",
+                      &FullDllName, LdrEntry->DllBase);
 
-        /* Get the name of the DLL */
-        Status = MmGetFileNameForAddress(NtHeader, &ModuleName);
-        if (NT_SUCCESS(Status))
-        {
-            /* Setup the object attributes */
-            InitializeObjectAttributes(&ObjectAttributes,
-                                       &ModuleName,
-                                       OBJ_FORCE_ACCESS_CHECK |
-                                       OBJ_KERNEL_HANDLE |
-                                       OBJ_CASE_INSENSITIVE,
-                                       NULL,
-                                       NULL);
+            /* Get the name of the DLL */
+            Status = MmGetFileNameForAddress(NtHeader, &ModuleName);
+            if (NT_SUCCESS(Status))
+            {
+                /* Setup the object attributes */
+                InitializeObjectAttributes(&ObjectAttributes,
+                                           &ModuleName,
+                                           OBJ_FORCE_ACCESS_CHECK |
+                                           OBJ_KERNEL_HANDLE |
+                                           OBJ_CASE_INSENSITIVE,
+                                           NULL,
+                                           NULL);
 
-            /* Open the file to get a handle to it */
-            Status = ZwOpenFile(&LoadDll->FileHandle,
-                                GENERIC_READ | SYNCHRONIZE,
-                                &ObjectAttributes,
-                                &IoStatusBlock,
-                                FILE_SHARE_READ |
-                                FILE_SHARE_WRITE |
-                                FILE_SHARE_DELETE,
-                                FILE_SYNCHRONOUS_IO_NONALERT);
-            if (!NT_SUCCESS(Status)) LoadDll->FileHandle = NULL;
-
-            /* Free the name now */
-            ExFreePool(ModuleName.Buffer);
-        }
+                /* Open the file to get a handle to it */
+                Status = ZwOpenFile(&LoadDll->FileHandle,
+                                    GENERIC_READ | SYNCHRONIZE,
+                                    &ObjectAttributes,
+                                    &IoStatusBlock,
+                                    FILE_SHARE_READ |
+                                    FILE_SHARE_WRITE |
+                                    FILE_SHARE_DELETE,
+                                    FILE_SYNCHRONOUS_IO_NONALERT);
+                if (!NT_SUCCESS(Status)) LoadDll->FileHandle = NULL;
+
+                /* Free the name now */
+                ExFreePool(ModuleName.Buffer);
+            }
 
-        /* Send the fake module load message */
-        Status = DbgkpQueueMessage(Process,
-                                   Thread,
-                                   &ApiMessage,
-                                   DEBUG_EVENT_NOWAIT,
-                                   DebugObject);
-        if (!NT_SUCCESS(Status))
-        {
-            /* Message send failed, close the file handle if we had one */
-            if (LoadDll->FileHandle) ObCloseHandle(LoadDll->FileHandle,
-                                                   KernelMode);
-        }
+            /* Send the fake module load message */
+            Status = DbgkpQueueMessage(Process,
+                                       Thread,
+                                       &ApiMessage,
+                                       DEBUG_EVENT_NOWAIT,
+                                       DebugObject);
+            if (!NT_SUCCESS(Status))
+            {
+                /* Message send failed, close the file handle if we had one */
+                if (LoadDll->FileHandle) ObCloseHandle(LoadDll->FileHandle,
+                                                       KernelMode);
+            }
 
-        /* Go to the next module */
-        NextEntry = NextEntry->Flink;
-        i++;
+            /* Go to the next module */
+            NextEntry = NextEntry->Flink;
+            i++;
+        }
     }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+        NOTHING;
+    }
+    _SEH2_END;
 
     /* Return success */
     return STATUS_SUCCESS;
@@ -758,7 +775,7 @@ DbgkpPostFakeThreadMessages(IN PEPROCESS Process,
     {
         /* Dereference and fail */
         if (pFirstThread) ObDereferenceObject(pFirstThread);
-        if (pLastThread) ObDereferenceObject(pLastThread);
+        ObDereferenceObject(pLastThread);
         return Status;
     }
 
@@ -1657,7 +1674,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*/