- More sharing between ntdll/ntoskrnl: shared Dbg code.
authorAlex Ionescu <aionescu@gmail.com>
Mon, 26 Sep 2005 04:59:48 +0000 (04:59 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Mon, 26 Sep 2005 04:59:48 +0000 (04:59 +0000)
- Added NtCreateDebugObject, NtDebugContinue, NtQueryDebugFilterState, NtSetDebugFilterState, NtWaitForDebugEvent to system call list.
- Added some debug constants to headers
- Updated RtlpCheckForActiveDebugger in ntoskrnl to return whatever we're expecting as the "normal" case.
- Added RtlpSetInDbgPrint to rtl support library for special DbgPrint implementation difference in user-mode
- Removed all the deprecated debug APIs in ntdll.
- Implemented NtQueryDebugFilterState and NtSetDebugFilterState based on royce's implementation.
- Started modifications on KeDebugService, and implemented DebugService in rtl
- Implemented all the Dbg* APIs in RTL.
- Implemented DbgUiConnectToDbg, DbgUiContinue, DbgUiWaitStateChange, DbgUiRemoteBreakin, DbgUiIssueRemoteBreakin
- Changed KD Print callbacks to also receive the length of the string.

Right now, one call that should be shared still isn't (the final DebugPrint call) because calling KeDebugService from kernel-mode seems to cause a hang. Also, DebugService does not currently cause an exception like it should (instead it still calls the Kdp handler), because those changes would've made the patch even bigger and are still untested.

svn path=/trunk/; revision=18078

22 files changed:
reactos/lib/ntdll/dbg/debug.c [deleted file]
reactos/lib/ntdll/dbg/print.c [deleted file]
reactos/lib/ntdll/def/ntdll.def
reactos/lib/ntdll/ntdll.xml
reactos/lib/ntdll/rtl/libsupp.c
reactos/lib/rtl/exception.c
reactos/lib/rtl/i386/debug.S
reactos/lib/rtl/rtl.xml
reactos/lib/rtl/rtlp.h
reactos/ntoskrnl/include/internal/kd.h
reactos/ntoskrnl/kd/kdio.c
reactos/ntoskrnl/kd/kdmain.c
reactos/ntoskrnl/kd/wrappers/bochs.c
reactos/ntoskrnl/kd/wrappers/gdbstub.c
reactos/ntoskrnl/ke/i386/syscall.S
reactos/ntoskrnl/ntoskrnl.xml
reactos/ntoskrnl/rtl/debug.c
reactos/ntoskrnl/rtl/libsupp.c
reactos/ntoskrnl/rtl/misc.c
reactos/tools/nci/sysfuncs.lst
reactos/w32api/include/ddk/winddk.h
reactos/w32api/include/ntstatus.h

diff --git a/reactos/lib/ntdll/dbg/debug.c b/reactos/lib/ntdll/dbg/debug.c
deleted file mode 100644 (file)
index edf9e73..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-/* $Id$
- *
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS kernel
- * FILE:            lib/ntdll/dbg/debug.c
- * PURPOSE:         User mode debugger support functions
- * PROGRAMMER:      Eric Kohl
- * UPDATE HISTORY:
- *                  14/04/2000 Created
- */
-
-/* INCLUDES *****************************************************************/
-
-#include <ntdll.h>
-#define NDEBUG
-#include <debug.h>
-
-/* FUNCTIONS *****************************************************************/
-
-static HANDLE DbgSsApiPort = NULL;
-static HANDLE DbgSsReplyPort = NULL;
-static NTSTATUS (STDCALL * DbgSsCallback)(PVOID,PVOID) = NULL;
-
-
-typedef struct _LPC_DBGSS_MESSAGE
-{
-       PORT_MESSAGE Header;
-       ULONG Unknown1;
-       ULONG Unknown2;
-       ULONG Unknown3;
-       ULONG Unknown4;
-} LPC_DBGSS_MESSAGE, *PLPC_DBGSS_MESSAGE;
-
-
-/* FUNCTIONS *****************************************************************/
-
-VOID STDCALL
-DbgSsServerThread(PVOID Unused)
-{
-       LPC_DBGSS_MESSAGE Message;
-       NTSTATUS Status;
-
-       for (;;)
-       {
-               Status = NtReplyWaitReceivePort (DbgSsApiPort,
-                                                NULL,
-                                                NULL,
-                                                (PPORT_MESSAGE)&Message);
-               if (!NT_SUCCESS(Status))
-               {
-                       DbgPrint ("DbgSs: NtReplyWaitReceivePort failed - Status == %lx\n",
-                                 Status);
-
-                       DbgBreakPoint ();
-               }
-               else
-               {
-                       /* FIXME: missing code!! */
-
-               }
-       }
-}
-
-
-/*
- * @unimplemented
- */
-NTSTATUS STDCALL
-DbgSsHandleKmApiMsg(ULONG Unknown1,
-                   HANDLE EventHandle)
-{
-  return STATUS_NOT_IMPLEMENTED;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-DbgSsInitialize(HANDLE ReplyPort,
-               PVOID Callback,
-               ULONG Unknown2,
-               ULONG Unknown3)
-{
-       SECURITY_QUALITY_OF_SERVICE Qos;
-       UNICODE_STRING PortName = RTL_CONSTANT_STRING(L"\\DbgSsApiPort");
-       NTSTATUS Status;
-
-       Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
-       Qos.ImpersonationLevel = SecurityIdentification;
-       Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
-       Qos.EffectiveOnly = TRUE;
-
-       Status = NtConnectPort (&DbgSsApiPort,
-                               &PortName,
-                               &Qos,
-                               NULL,
-                               NULL,
-                               NULL,
-                               NULL,
-                               NULL);
-       if (!NT_SUCCESS(Status))
-               return Status;
-
-       DbgSsReplyPort = ReplyPort;
-       DbgSsCallback = Callback;
-//     UnknownData2 = Unknown2;
-//     UnknownData3 = Unknown3;
-
-       Status = RtlCreateUserThread (NtCurrentProcess (),
-                                     NULL,
-                                     FALSE,
-                                     0,
-                                     0,
-                                     0,
-                                     (PTHREAD_START_ROUTINE)DbgSsServerThread,
-                                     NULL,
-                                     NULL,
-                                     NULL);
-
-       return Status;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-DbgUiConnectToDbg(VOID)
-{
-       SECURITY_QUALITY_OF_SERVICE Qos;
-       UNICODE_STRING PortName = RTL_CONSTANT_STRING(L"\\DbgUiApiPort");
-       NTSTATUS Status;
-       PTEB Teb;
-       ULONG InfoSize;
-
-       Teb = NtCurrentTeb ();
-
-       Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
-       Qos.ImpersonationLevel = SecurityIdentification;
-       Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
-       Qos.EffectiveOnly = TRUE;
-
-       InfoSize = sizeof(ULONG);
-
-       Status = NtConnectPort (&Teb->DbgSsReserved[1],
-                               &PortName,
-                               &Qos,
-                               NULL,
-                               NULL,
-                               NULL,
-                               &Teb->DbgSsReserved[0],
-                               &InfoSize);
-       if (!NT_SUCCESS(Status))
-       {
-               Teb->DbgSsReserved[1] = NULL;
-               return Status;
-       }
-
-       NtRegisterThreadTerminatePort(Teb->DbgSsReserved[1]);
-
-       return Status;
-}
-
-
-/*
- * @unimplemented
- */
-NTSTATUS STDCALL
-DbgUiContinue(PCLIENT_ID ClientId,
-             ULONG ContinueStatus)
-{
-  return STATUS_NOT_IMPLEMENTED;
-}
-
-
-/*
- * @unimplemented
- */
-NTSTATUS STDCALL
-DbgUiWaitStateChange(PDBGUI_WAIT_STATE_CHANGE DbgUiWaitStateCange,
-                     PLARGE_INTEGER TimeOut)
-{
-  return STATUS_NOT_IMPLEMENTED;
-}
-
-VOID STDCALL DbgUiRemoteBreakin(VOID)
-{
- DbgBreakPoint();
-
- RtlExitUserThread(STATUS_SUCCESS);
-}
-
-NTSTATUS STDCALL DbgUiIssueRemoteBreakin(HANDLE Process)
-{
- HANDLE hThread;
- CLIENT_ID cidClientId;
- NTSTATUS nErrCode;
- ULONG nStackSize = PAGE_SIZE;
-
- nErrCode = RtlCreateUserThread
- (
-  Process,
-  NULL,
-  FALSE,
-  0,
-  nStackSize,
-  nStackSize,
-  (PTHREAD_START_ROUTINE)DbgUiRemoteBreakin,
-  NULL,
-  &hThread,
-  &cidClientId
- );
-
- if(!NT_SUCCESS(nErrCode)) return nErrCode;
-
- NtClose(hThread);
-
- return STATUS_SUCCESS;
-}
-
-/* EOF */
diff --git a/reactos/lib/ntdll/dbg/print.c b/reactos/lib/ntdll/dbg/print.c
deleted file mode 100644 (file)
index 5e4a281..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/* $Id$
- *
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS kernel
- * FILE:            lib/ntdll/dbg/print.c
- * PURPOSE:         Debug output
- * PROGRAMMER:      Eric Kohl
- * UPDATE HISTORY:
- *                  Created 28/12/1999
- */
-
-#include <ntdll.h>
-#define NDEBUG
-#include <debug.h>
-
-/* FUNCTIONS ***************************************************************/
-
-ULONG DbgService (ULONG Service, PVOID Context1, PVOID Context2);
-__asm__ ("\n\t.global _DbgService\n\t"
-         "_DbgService:\n\t"
-         "mov 4(%esp), %eax\n\t"
-         "mov 8(%esp), %ecx\n\t"
-         "mov 12(%esp), %edx\n\t"
-         "int $0x2D\n\t"
-         "ret\n\t");
-
-/*
- * @unimplemented
- */
-ULONG
-DbgPrintEx(
-    IN ULONG ComponentId,
-    IN ULONG Level,
-    IN PCH Format,
-    ...
-    )
-{
-   ANSI_STRING DebugString;
-   CHAR Buffer[4096];
-   va_list ap;
-
-   /* init ansi string */
-   DebugString.Buffer = Buffer;
-   DebugString.MaximumLength = sizeof(Buffer);
-
-   va_start (ap, Format);
-   DebugString.Length = _vsnprintf (Buffer, sizeof(Buffer), Format, ap);
-   va_end (ap);
-
-   DbgService (1, &DebugString, NULL);
-
-   return (ULONG)DebugString.Length;
-}
-
-
-/*
- * @implemented
- */
-ULONG
-DbgPrint(PCH Format, ...)
-{
-   ANSI_STRING DebugString;
-   CHAR Buffer[4096];
-   va_list ap;
-
-   /* init ansi string */
-   DebugString.Buffer = Buffer;
-   DebugString.MaximumLength = sizeof(Buffer);
-
-   va_start (ap, Format);
-   DebugString.Length = _vsnprintf (Buffer, sizeof(Buffer), Format, ap);
-   va_end (ap);
-
-
-   return DbgPrintEx (0, 0, DebugString.Buffer);
-}
-
-
-/*
- * @implemented
- */
-VOID
-STDCALL
-DbgPrompt (
-       PCH OutputString,
-       PCH InputString,
-       USHORT InputSize
-       )
-{
-       ANSI_STRING Output;
-       ANSI_STRING Input;
-
-       Input.Length = 0;
-       Input.MaximumLength = InputSize;
-       Input.Buffer = InputString;
-
-       Output.Length = strlen (OutputString);
-       Output.MaximumLength = Output.Length + 1;
-       Output.Buffer = OutputString;
-
-       DbgService (2,
-                   &Output,
-                   &Input);
-}
-
-/* EOF */
index 6de5ba6..7665999 100644 (file)
@@ -24,8 +24,6 @@ DbgBreakPoint@0
 DbgPrint
 DbgPrintEx
 DbgPrompt@12
-DbgSsHandleKmApiMsg@8
-DbgSsInitialize@16
 DbgUiConnectToDbg@0
 DbgUiContinue@8
 DbgUiIssueRemoteBreakin@4
@@ -161,6 +159,7 @@ NtPrivilegeObjectAuditAlarm@24
 NtProtectVirtualMemory@20
 NtPulseEvent@8
 NtQueryAttributesFile@8
+NtQueryDebugFilterState@8
 NtQueryDefaultLocale@8
 NtQueryDefaultUILanguage@4
 NtQueryDirectoryFile@44
@@ -218,6 +217,7 @@ NtResumeProcess@4
 NtResumeThread@8
 NtSaveKey@8
 NtSecureConnectPort@36
+NtSetDebugFilterState@12
 NtSetContextThread@8
 NtSetDefaultHardErrorPort@4
 NtSetDefaultLocale@8
@@ -265,6 +265,7 @@ NtUnlockFile@20
 NtUnlockVirtualMemory@16
 NtUnmapViewOfSection@8
 NtVdmControl@8
+NtWaitForDebugEvent@16
 NtWaitForMultipleObjects@20
 NtWaitForSingleObject@12
 NtWaitHighEventPair@4
@@ -716,6 +717,7 @@ ZwCloseObjectAuditAlarm@12
 ZwCompleteConnectPort@4
 ZwConnectPort@32
 ZwContinue@8
+ZwCreateDebugObject@16
 ZwCreateDirectoryObject@12
 ZwCreateEvent@20
 ZwCreateEventPair@12
@@ -735,6 +737,7 @@ ZwCreateSymbolicLinkObject@16
 ZwCreateThread@32
 ZwCreateTimer@16
 ZwCreateToken@52
+ZwDebugContinue@12
 ZwDelayExecution@8
 ZwDeleteAtom@4
 ZwDeleteFile@4
index 7f7339f..d100957 100644 (file)
@@ -20,8 +20,7 @@
                <file>connect.c</file>
        </directory>
        <directory name="dbg">
-               <file>debug.c</file>
-               <file>print.c</file>
+               <file>dbgui.c</file>
        </directory>
        <directory name="ldr">
                <file>res.c</file>
index 30b7121..8508c8d 100644 (file)
 
 BOOLEAN
 NTAPI
-RtlpCheckForActiveDebugger(VOID)
+RtlpCheckForActiveDebugger(BOOLEAN Type)
 {
     return (NtCurrentPeb()->BeingDebugged);
 }
 
+BOOLEAN
+NTAPI
+RtlpSetInDbgPrint(IN BOOLEAN NewValue)
+{
+    /* If we're setting it to false, do it and return */
+    if (NewValue == FALSE)
+    {
+        NtCurrentTeb()->InDbgPrint = FALSE;
+        return FALSE;
+    }
+
+    /* Setting to true; check if it's not already */
+    if (NtCurrentTeb()->InDbgPrint) return TRUE;
+
+    /* Set it and return */
+    NtCurrentTeb()->InDbgPrint = TRUE;
+    return FALSE;
+}
+
 KPROCESSOR_MODE
 STDCALL
 RtlpGetMode()
index 6e2d0f5..cd1230c 100644 (file)
@@ -39,7 +39,7 @@ RtlRaiseException(PEXCEPTION_RECORD ExceptionRecord)
     Context.ContextFlags = CONTEXT_FULL;
 
     /* Check if we're being debugged (user-mode only) */
-    if (!RtlpCheckForActiveDebugger())
+    if (!RtlpCheckForActiveDebugger(TRUE))
     {
         /* Raise an exception immediately */
         Status = ZwRaiseException(ExceptionRecord, &Context, TRUE);
@@ -91,7 +91,7 @@ RtlRaiseStatus(NTSTATUS Status)
     Context.ContextFlags = CONTEXT_FULL;
 
     /* Check if we're being debugged (user-mode only) */
-    if (!RtlpCheckForActiveDebugger())
+    if (!RtlpCheckForActiveDebugger(TRUE))
     {
         /* Raise an exception immediately */
         ZwRaiseException(&ExceptionRecord, &Context, TRUE);
index 76394cf..5ead28e 100644 (file)
@@ -1,10 +1,9 @@
 /*\r
  * COPYRIGHT:         See COPYING in the top level directory\r
- * PROJECT:           ReactOS kernel\r
- * PURPOSE:           Run-Time Library\r
+ * PROJECT:           ReactOS Run-Time Library\r
+ * PURPOSE:           Debug Routines\r
  * FILE:              lib/rtl/i386/debug.S\r
  * PROGRAMER:         Alex Ionescu (alex@relsoft.net)\r
- * REVISION HISTORY:  27/07/2005 Created\r
  */\r
 \r
 .intel_syntax noprefix\r
@@ -14,6 +13,7 @@
 .globl  _DbgBreakPoint@0\r
 .globl  _DbgBreakPointWithStatus@4\r
 .globl  _DbgUserBreakPoint@0\r
+.globl  _DebugService@20\r
 \r
 /* FUNCTIONS ***************************************************************/\r
 \r
@@ -26,3 +26,36 @@ _DbgBreakPointWithStatus@4:
     mov eax, [esp+4]\r
     int 3\r
     ret 4\r
+\r
+_DebugService@20:\r
+\r
+    /* Setup the stack */\r
+    push ebp\r
+    mov ebp, esp\r
+\r
+    /* Save the registers */\r
+    push ecx\r
+    push ebx\r
+    push edi\r
+    push edi\r
+    push ebx\r
+\r
+    /* Call the Interrupt */\r
+    mov eax, [ebp+8]\r
+    mov ecx, [ebp+12]\r
+    mov edx, [ebp+16]\r
+    mov ebx, [ebp+20]\r
+    mov edi, [ebp+24]\r
+    int 0x2D\r
+    //int 3\r
+\r
+    /* Restore registers */\r
+    pop ebx\r
+    pop edi\r
+    pop edi\r
+    pop ebx\r
+\r
+    /* Return */\r
+    leave\r
+    ret 20\r
+\r
index ff0f8f7..bd96383 100644 (file)
@@ -24,6 +24,7 @@
        <file>crc32.c</file>
        <file>critical.c</file>
        <file>dbgbuffer.c</file>
+       <file>debug.c</file>
        <file>dos8dot3.c</file>
        <file>encode.c</file>
        <file>env.c</file>
index 55d0742..25625e0 100644 (file)
@@ -51,7 +51,7 @@ RtlLeaveHeapLock(PRTL_CRITICAL_SECTION CriticalSection);
 \r
 BOOLEAN\r
 NTAPI\r
-RtlpCheckForActiveDebugger(VOID);\r
+RtlpCheckForActiveDebugger(BOOLEAN Type);\r
 \r
 BOOLEAN\r
 NTAPI\r
index 91e834c..3c7351d 100644 (file)
@@ -107,7 +107,10 @@ VOID
 
 typedef
 VOID
-(STDCALL*PKDP_PRINT_ROUTINE)(PCH String);
+(STDCALL*PKDP_PRINT_ROUTINE)(
+    LPSTR String,
+    ULONG Length
+);
 
 typedef
 VOID
@@ -172,7 +175,9 @@ KdpEnterDebuggerException(
 
 ULONG
 STDCALL
-KdpPrintString(PANSI_STRING String);
+KdpPrintString(
+    LPSTR String,
+    ULONG Length);
 
 BOOLEAN
 STDCALL
@@ -180,7 +185,10 @@ KdpDetectConflicts(PCM_RESOURCE_LIST DriverList);
 
 VOID
 STDCALL
-KdpBochsDebugPrint(IN PCH Message);
+KdpBochsDebugPrint(
+    IN PCH Message,
+    IN ULONG Length
+);
 
 /* KD GLOBALS  ***************************************************************/
 
index 22bc5bb..6702515 100644 (file)
@@ -55,10 +55,9 @@ KdpPrintToLogInternal(PVOID Context)
 
 VOID
 STDCALL
-KdpPrintToLog(PCH String)
+KdpPrintToLog(PCH String,
+              ULONG StringLength)
 {
-    ULONG StringLength = strlen(String);
-
     /* Don't overflow */
     if ((CurrentPosition + StringLength) > BufferSize) return;
 
@@ -142,7 +141,8 @@ KdpInitDebugLog(PKD_DISPATCH_TABLE DispatchTable,
 
 VOID
 STDCALL
-KdpSerialDebugPrint(LPSTR Message)
+KdpSerialDebugPrint(LPSTR Message,
+                    ULONG Length)
 {
     PCHAR pch = (PCHAR) Message;
 
@@ -184,6 +184,15 @@ KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable,
 
 /* SCREEN FUNCTIONS **********************************************************/
 
+VOID
+STDCALL
+KdpScreenPrint(LPSTR Message,
+               ULONG Length)
+{
+    /* Call HAL */
+    HalDisplayString(Message);
+}
+
 VOID
 STDCALL
 KdpScreenInit(PKD_DISPATCH_TABLE DispatchTable,
@@ -195,7 +204,7 @@ KdpScreenInit(PKD_DISPATCH_TABLE DispatchTable,
     {
         /* Write out the functions that we support for now */
         DispatchTable->KdpInitRoutine = KdpScreenInit;
-        DispatchTable->KdpPrintRoutine = HalDisplayString;
+        DispatchTable->KdpPrintRoutine = KdpScreenPrint;
 
         /* Register as a Provider */
         InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
@@ -247,10 +256,10 @@ KdpDetectConflicts(PCM_RESOURCE_LIST DriverList)
 
 ULONG
 STDCALL
-KdpPrintString(PANSI_STRING String)
+KdpPrintString(LPSTR String,
+               ULONG Length)
 {
     if (!KdpDebugMode.Value) return 0;
-    PCH pch = String->Buffer;
     PLIST_ENTRY CurrentEntry;
     PKD_DISPATCH_TABLE CurrentTable;
 
@@ -264,17 +273,17 @@ KdpPrintString(PANSI_STRING String)
                                          KdProvidersList);
 
         /* Call it */
-        CurrentTable->KdpPrintRoutine(pch);
+        CurrentTable->KdpPrintRoutine(String, Length);
 
         /* Next Table */
         CurrentEntry = CurrentEntry->Flink;
     }
 
     /* Call the Wrapper Routine */
-    if (WrapperInitRoutine) WrapperTable.KdpPrintRoutine(pch);
+    if (WrapperInitRoutine) WrapperTable.KdpPrintRoutine(String, Length);
 
     /* Return the Length */
-    return((ULONG)String->Length);
+    return Length;
 }
 
 /* EOF */
index 72d5b12..a08154c 100644 (file)
@@ -21,26 +21,35 @@ ULONG EXPORTED KiBugCheckData;
 BOOLEAN KdpBreakPending;
 VOID STDCALL PspDumpThreads(BOOLEAN SystemThreads);
 
+typedef struct
+{
+       ULONG ComponentId;
+       ULONG Level;
+} KD_COMPONENT_DATA;
+#define MAX_KD_COMPONENT_TABLE_ENTRIES 128
+KD_COMPONENT_DATA KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES];
+ULONG KdComponentTableEntries = 0;
+
 /* PRIVATE FUNCTIONS *********************************************************/
 
 ULONG
 STDCALL
 KdpServiceDispatcher(ULONG Service,
-                     PVOID Context1,
-                     PVOID Context2)
+                     PVOID Buffer1,
+                     ULONG Buffer1Length)
 {
     ULONG Result = 0;
 
     switch (Service)
     {
-        case 1: /* DbgPrint */
-            Result = KdpPrintString ((PANSI_STRING)Context1);
+        case BREAKPOINT_PRINT: /* DbgPrint */
+            Result = KdpPrintString(Buffer1, Buffer1Length);
             break;
 
 #ifdef DBG
         case TAG('R', 'o', 's', ' '): /* ROS-INTERNAL */
         {
-            switch ((ULONG)Context1)
+            switch ((ULONG)Buffer1)
             {
                 case DumpNonPagedPool:
                     MiDebugDumpNonPagedPool(FALSE);
@@ -203,4 +212,54 @@ KdPowerTransition(ULONG PowerState)
     return STATUS_NOT_IMPLEMENTED;
 }
 
+NTSTATUS
+STDCALL
+NtQueryDebugFilterState(IN ULONG ComponentId,
+                        IN ULONG Level)
+{
+       int i;
+
+       /* convert Level to mask if it isn't already one */
+       if ( Level < 32 )
+               Level = 1 << Level;
+
+       for ( i = 0; i < KdComponentTableEntries; i++ )
+       {
+               if ( ComponentId == KdComponentTable[i].ComponentId )
+               {
+                       if ( Level & KdComponentTable[i].Level )
+                               return TRUE;
+                       break;
+               }
+       }
+       return FALSE;
+}
+
+NTSTATUS
+STDCALL
+NtSetDebugFilterState(IN ULONG ComponentId,
+                      IN ULONG Level,
+                      IN BOOLEAN State)
+{
+       int i;
+       for ( i = 0; i < KdComponentTableEntries; i++ )
+       {
+               if ( ComponentId == KdComponentTable[i].ComponentId )
+                       break;
+       }
+       if ( i == KdComponentTableEntries )
+       {
+               if ( i == MAX_KD_COMPONENT_TABLE_ENTRIES )
+                       return STATUS_INVALID_PARAMETER_1;
+               ++KdComponentTableEntries;
+               KdComponentTable[i].ComponentId = ComponentId;
+               KdComponentTable[i].Level = 0;
+       }
+       if ( State )
+               KdComponentTable[i].Level |= Level;
+       else
+               KdComponentTable[i].Level &= ~Level;
+       return STATUS_SUCCESS;
+}
+
  /* EOF */
index d812c38..f0f5517 100644 (file)
@@ -18,7 +18,8 @@
 
 VOID
 STDCALL
-KdpBochsDebugPrint(IN PCH Message)
+KdpBochsDebugPrint(IN PCH Message,
+                   IN ULONG Length)
 {
     while (*Message != 0)
     {
@@ -41,8 +42,6 @@ KdpBochsDebugPrint(IN PCH Message)
     }
 }
 
-
-
 VOID
 STDCALL
 KdpBochsInit(PKD_DISPATCH_TABLE WrapperTable,
index e15c1a7..521b6c9 100644 (file)
@@ -1446,7 +1446,7 @@ extern ULONG KdpPortIrq;
 
 VOID
 STDCALL
-KdpGdbDebugPrint(PCH Message)
+KdpGdbDebugPrint(PCH Message, ULONG Length)
 {
 #if 0
   /* This can be quite annoying! */
index 13eb866..cb84667 100644 (file)
@@ -839,12 +839,49 @@ _KiDebugService:
     mov [ebp+KTRAP_FRAME_DEBUGEBP], ebx
     mov [ebp+KTRAP_FRAME_DEBUGEIP], edi
 
+    /* Increase EIP so we skip the INT3 */
+    //inc dword ptr [ebp+KTRAP_FRAME_EIP]
+
     /* Call debug service dispatcher */
-    push [ebp+KTRAP_FRAME_EDX]
-    push [ebp+KTRAP_FRAME_ECX]
-    push [ebp+KTRAP_FRAME_EAX]
+    mov eax, [ebp+KTRAP_FRAME_EAX]
+    mov ecx, [ebp+KTRAP_FRAME_ECX]
+    mov edx, [ebp+KTRAP_FRAME_EAX]
+
+    /* Check for V86 mode */
+    test dword ptr [ebp+KTRAP_FRAME_EFLAGS], X86_EFLAGS_VM
+    jnz NotUserMode
+
+    /* Check if this is kernel or user-mode */
+    test byte ptr [ebp+KTRAP_FRAME_CS], 1
+    jz CallDispatch
+    cmp word ptr [ebp+KTRAP_FRAME_CS], USER_CS
+    jnz NotUserMode
+
+    /* Re-enable interrupts */
+VdmProc:
+    sti
+
+    /* Call the debug routine */
+CallDispatch:
+    mov esi, ecx
+    mov edi, edx
+    mov edx, eax
+    mov ecx, 3
+    push edi
+    push esi
+    push edx
     call _KdpServiceDispatcher@12
 
+NotUserMode:
+
+    /* Get the current process */
+    mov ebx, [fs:KPCR_CURRENT_THREAD]
+    mov ebx, [ebx+KTHREAD_APCSTATE_PROCESS]
+
+    /* Check if this is a VDM Process */
+    //cmp dword ptr [ebx+KPROCESS_VDM_OBJECTS], 0
+    //jz VdmProc
+
     /* Exit through common routine */
     jmp Kei386EoiHelper@0
 
index 9f06e9e..0b450cf 100644 (file)
                        </directory>
                </if>
                <file>atom.c</file>
-               <file>debug.c</file>
                <file>libsupp.c</file>
                <file>misc.c</file>
                <file>nls.c</file>
index 0986ff4..e69de29 100644 (file)
@@ -1,299 +0,0 @@
-/*
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS kernel
- * FILE:            ntoskrnl/rtl/dbgprint.c
- * PURPOSE:         Debug output
- *
- * PROGRAMMERS:     Eric Kohl (ekohl@abo.rhein-zeitung.de)
- */
-
-/* INCLUDES *****************************************************************/
-
-#include <ntoskrnl.h>
-#include <internal/debug.h>
-
-/* DATA *********************************************************************/
-
-typedef struct
-{
-       ULONG ComponentId;
-       ULONG Level;
-} KD_COMPONENT_DATA;
-#define MAX_KD_COMPONENT_TABLE_ENTRIES 128
-KD_COMPONENT_DATA KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES];
-ULONG KdComponentTableEntries = 0;
-
-/* FUNCTIONS ****************************************************************/
-
-/*
- * Note: DON'T CHANGE THIS FUNCTION!!!
- *       DON'T CALL HalDisplayString OR SOMETING ELSE!!!
- *       You'll only break the serial/bochs debugging feature!!!
- */
-
-/*
- * @implemented
- */
-ULONG STDCALL
-vDbgPrintExWithPrefix(IN LPCSTR Prefix,
-                      IN ULONG ComponentId,
-                      IN ULONG Level,
-                      IN LPCSTR Format,
-                      IN va_list ap)
-{
-   ANSI_STRING DebugString;
-   CHAR Buffer[513];
-   PCHAR pBuffer;
-   ULONG pBufferSize;
-#ifdef SERIALIZE_DBGPRINT
-#  define MESSAGETABLE_SIZE  16
-   LONG MyTableIndex;
-   static LONG Lock = 0;
-   static LONG TableWriteIndex = 0, TableReadIndex = 0;
-   static CHAR MessageTable[MESSAGETABLE_SIZE][sizeof(Buffer)] = { { '\0' } };
-#endif /* SERIALIZE_DBGPRINT */
-
-   /* TODO FIXME - call NtQueryDebugFilterState() instead per Alex */
-   if ( !DbgQueryDebugFilterState ( ComponentId, Level ) )
-      return 0;
-
-   /* init ansi string */
-   DebugString.Buffer = Buffer;
-   DebugString.MaximumLength = sizeof(Buffer);
-
-   pBuffer = Buffer;
-   pBufferSize = sizeof(Buffer);
-   DebugString.Length = 0;
-   if ( Prefix && *Prefix )
-   {
-      DebugString.Length = strlen(Prefix);
-      if ( DebugString.Length >= sizeof(Buffer) )
-         DebugString.Length = sizeof(Buffer) - 1;
-      memmove ( Buffer, Prefix, DebugString.Length );
-      Buffer[DebugString.Length] = '\0';
-      pBuffer = &Buffer[DebugString.Length];
-      pBufferSize -= DebugString.Length;
-   }
-
-   DebugString.Length += _vsnprintf ( pBuffer, pBufferSize, Format, ap );
-   Buffer[sizeof(Buffer)-1] = '\0';
-
-#ifdef SERIALIZE_DBGPRINT
-   /* check if we are already running */
-   if (InterlockedCompareExchange(&Lock, 1, 0) == 1)
-     {
-        MyTableIndex = InterlockedIncrement(&TableWriteIndex) - 1;
-        InterlockedCompareExchange(&TableWriteIndex, 0, MESSAGETABLE_SIZE);
-        MyTableIndex %= MESSAGETABLE_SIZE;
-
-        if (MessageTable[MyTableIndex][0] != '\0') /* table is full */
-          {
-             DebugString.Buffer = "CRITICAL ERROR: DbgPrint Table is FULL!";
-             DebugString.Length = 39;
-             KdpPrintString(&DebugString);
-             for (;;);
-          }
-        else
-          {
-             memcpy(MessageTable[MyTableIndex], DebugString.Buffer, DebugString.Length);
-             MessageTable[MyTableIndex][DebugString.Length] = '\0';
-          }
-     }
-   else
-     {
-#endif /* SERIALIZE_DBGPRINT */
-        KdpPrintString (&DebugString);
-#ifdef SERIALIZE_DBGPRINT
-        MyTableIndex = TableReadIndex;
-        while (MessageTable[MyTableIndex][0] != '\0')
-          {
-             /*DebugString.Buffer = "$$$";
-             DebugString.Length = 3;
-             KdpPrintString(&DebugString);*/
-
-             DebugString.Buffer = MessageTable[MyTableIndex];
-             DebugString.Length = strlen(DebugString.Buffer);
-             DebugString.MaximumLength = DebugString.Length + 1;
-
-             KdpPrintString(&DebugString);
-             MessageTable[MyTableIndex][0] = '\0';
-
-             MyTableIndex = InterlockedIncrement(&TableReadIndex);
-             InterlockedCompareExchange(&TableReadIndex, 0, MESSAGETABLE_SIZE);
-             MyTableIndex %= MESSAGETABLE_SIZE;
-          }
-        InterlockedDecrement(&Lock);
-     }
-#  undef MESSAGETABLE_SIZE
-#endif /* SERIALIZE_DBGPRINT */
-
-   return (ULONG)DebugString.Length;
-}
-
-/*
- * @implemented
- */
-ULONG STDCALL
-vDbgPrintEx(IN ULONG ComponentId,
-            IN ULONG Level,
-            IN LPCSTR Format,
-            IN va_list ap)
-{
-       return vDbgPrintExWithPrefix ( NULL, ComponentId, Level, Format, ap );
-}
-
-/*
- * @implemented
- */
-ULONG
-DbgPrint(PCH Format, ...)
-{
-       va_list ap;
-       ULONG rc;
-
-       va_start (ap, Format);
-       /* TODO FIXME - use DPFLTR_DEFAULT_ID and DPFLTR_INFO_LEVEL
-        *
-        * https://www.osronline.com/article.cfm?article=295
-        *
-        * ( first need to add those items to default registry and write the code
-        *   to load those settings so we don't anger ros-devs when DbgPrint() suddenly
-        *   stops working )
-        *
-        * ( also when you do this, remove -1 hack from DbgQueryDebugFilterState() )
-        */
-       rc = vDbgPrintExWithPrefix ( NULL, (ULONG)-1, (ULONG)-1, Format, ap );
-       va_end (ap);
-
-       return rc;
-}
-
-/*
- * @implemented
- */
-ULONG
-__cdecl
-DbgPrintEx(IN ULONG ComponentId,
-           IN ULONG Level,
-           IN PCH Format,
-           ...)
-{
-       va_list ap;
-       ULONG rc;
-
-       va_start (ap, Format);
-       rc = vDbgPrintExWithPrefix ( NULL, ComponentId, Level, Format, ap );
-       va_end (ap);
-
-       return rc;
-}
-
-/*
- * @unimplemented
- */
-ULONG
-__cdecl
-DbgPrintReturnControlC(PCH Format,
-                       ...)
-{
-    UNIMPLEMENTED;
-    return 0;
-}
-
-/*
- * @unimplemented
- */
-VOID
-STDCALL
-DbgPrompt(PCH OutputString,
-          PCH InputString,
-          USHORT InputSize)
-{
-    ANSI_STRING Output;
-    ANSI_STRING Input;
-
-    Input.Length = 0;
-    Input.MaximumLength = InputSize;
-    Input.Buffer = InputString;
-
-    Output.Length = strlen (OutputString);
-    Output.MaximumLength = Output.Length + 1;
-    Output.Buffer = OutputString;
-
-    /* FIXME: Not implemented yet!
-    KdpPromptString (&Output, &Input); */
-}
-
-/*
- * @implemented
- */
-BOOLEAN
-STDCALL
-DbgQueryDebugFilterState(IN ULONG ComponentId,
-                         IN ULONG Level)
-{
-       int i;
-
-       /* HACK HACK HACK - see comments in DbgPrint() */
-       if ( ComponentId == -1 )
-               return TRUE;
-
-       /* convert Level to mask if it isn't already one */
-       if ( Level < 32 )
-               Level = 1 << Level;
-
-       for ( i = 0; i < KdComponentTableEntries; i++ )
-       {
-               if ( ComponentId == KdComponentTable[i].ComponentId )
-               {
-                       if ( Level & KdComponentTable[i].Level )
-                               return TRUE;
-                       break;
-               }
-       }
-       return FALSE;
-}
-
-/*
- * @implemented
- */
-NTSTATUS
-STDCALL
-DbgSetDebugFilterState(IN ULONG ComponentId,
-                       IN ULONG Level,
-                       IN BOOLEAN State)
-{
-       int i;
-       for ( i = 0; i < KdComponentTableEntries; i++ )
-       {
-               if ( ComponentId == KdComponentTable[i].ComponentId )
-                       break;
-       }
-       if ( i == KdComponentTableEntries )
-       {
-               if ( i == MAX_KD_COMPONENT_TABLE_ENTRIES )
-                       return STATUS_INVALID_PARAMETER_1;
-               ++KdComponentTableEntries;
-               KdComponentTable[i].ComponentId = ComponentId;
-               KdComponentTable[i].Level = 0;
-       }
-       if ( State )
-               KdComponentTable[i].Level |= Level;
-       else
-               KdComponentTable[i].Level &= ~Level;
-       return STATUS_SUCCESS;
-}
-
-/*
- * @unimplemented
- */
-NTSTATUS
-STDCALL
-DbgLoadImageSymbols(IN PUNICODE_STRING Name,
-                    IN ULONG Base,
-                    IN ULONG Unknown3)
-{
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
-}
-/* EOF */
index 48f3ac9..261ace0 100644 (file)
@@ -19,10 +19,18 @@ extern ULONG NtGlobalFlag;
 
 BOOLEAN
 NTAPI
-RtlpCheckForActiveDebugger(VOID)
+RtlpCheckForActiveDebugger(BOOLEAN Type)
 {
     /* This check is meaningless in kernel-mode */
-    return TRUE;
+    return Type;
+}
+
+BOOLEAN
+NTAPI
+RtlpSetInDbgPrint(IN BOOLEAN NewValue)
+{
+    /* This check is meaningless in kernel-mode */
+    return FALSE;
 }
 
 KPROCESSOR_MODE
index 8f2d30a..cb9e1f1 100644 (file)
@@ -23,6 +23,17 @@ extern ULONG NtOSCSDVersion;
 
 /* FUNCTIONS *****************************************************************/
 
+NTSTATUS
+NTAPI
+DebugPrint(IN PANSI_STRING DebugString,
+           IN ULONG ComponentId,
+           IN ULONG Level)
+{
+    /* Temporary hack */
+    KdpPrintString(DebugString->Buffer, DebugString->Length);
+    return STATUS_SUCCESS;
+}
+
 /*
 * @implemented
 */
index 3f2b592..0f83941 100644 (file)
@@ -20,6 +20,7 @@ NtCloseObjectAuditAlarm 3
 NtCompleteConnectPort 1
 NtConnectPort 8
 NtContinue 2
+NtCreateDebugObject 4
 NtCreateDirectoryObject 3
 NtCreateEvent 5
 NtCreateEventPair 3
@@ -41,6 +42,7 @@ NtCreateThread 8
 NtCreateTimer 4
 NtCreateToken 13
 NtCreateWaitablePort 5
+NtDebugContinue 3
 NtDelayExecution 2
 NtDeleteAtom 1
 NtDeleteBootEntry 2
@@ -113,6 +115,7 @@ NtQueryInformationAtom 5
 NtQueryAttributesFile 2
 NtQueryBootEntryOrder 2
 NtQueryBootOptions 2
+NtQueryDebugFilterState 2
 NtQueryDefaultLocale 2
 NtQueryDefaultUILanguage 1
 NtQueryDirectoryFile 11
@@ -173,6 +176,7 @@ NtSaveKeyEx 3
 NtSecureConnectPort 9
 NtSetBootEntryOrder 2
 NtSetBootOptions 2
+NtSetDebugFilterState 3
 NtSetIoCompletion 5
 NtSetContextThread 2
 NtSetDefaultHardErrorPort 1
@@ -223,6 +227,7 @@ NtUnlockFile 5
 NtUnlockVirtualMemory 4
 NtUnmapViewOfSection 2
 NtVdmControl 2
+NtWaitForDebugEvent 4
 NtWaitForMultipleObjects 5
 NtWaitForSingleObject 3
 NtWaitHighEventPair 1
index 9d0bde3..edd9339 100644 (file)
@@ -219,6 +219,12 @@ typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
 #define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )   
 #define ZwCurrentThread() NtCurrentThread()      
 
+#define DPFLTR_ERROR_LEVEL                  0
+#define DPFLTR_WARNING_LEVEL                1
+#define DPFLTR_TRACE_LEVEL                  2
+#define DPFLTR_INFO_LEVEL                   3
+#define DPFLTR_MASK                         0x80000000
+
 #define MAXIMUM_PROCESSORS                32
 
 #define MAXIMUM_WAIT_OBJECTS              64
index 3d5b01a..c04a6ec 100644 (file)
@@ -26,6 +26,7 @@
  * Debug codes
  */
 #define DBG_CONTROL_C                    ((NTSTATUS)0x40010005L)
+#define DBG_PRINTEXCEPTION_C             ((NTSTATUS)0x40010006L)
 #define DBG_CONTROL_BREAK                ((NTSTATUS)0x40010008L)
 
 /*