From c15e04cf7a6e4f0a75f215149db4013aa0900c78 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Mon, 26 Sep 2005 04:59:48 +0000 Subject: [PATCH] - More sharing between ntdll/ntoskrnl: shared Dbg code. - 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 --- reactos/lib/ntdll/dbg/debug.c | 222 ------------------ reactos/lib/ntdll/dbg/print.c | 106 --------- reactos/lib/ntdll/def/ntdll.def | 7 +- reactos/lib/ntdll/ntdll.xml | 3 +- reactos/lib/ntdll/rtl/libsupp.c | 21 +- reactos/lib/rtl/exception.c | 4 +- reactos/lib/rtl/i386/debug.S | 39 +++- reactos/lib/rtl/rtl.xml | 1 + reactos/lib/rtl/rtlp.h | 2 +- reactos/ntoskrnl/include/internal/kd.h | 14 +- reactos/ntoskrnl/kd/kdio.c | 29 ++- reactos/ntoskrnl/kd/kdmain.c | 69 +++++- reactos/ntoskrnl/kd/wrappers/bochs.c | 5 +- reactos/ntoskrnl/kd/wrappers/gdbstub.c | 2 +- reactos/ntoskrnl/ke/i386/syscall.S | 43 +++- reactos/ntoskrnl/ntoskrnl.xml | 1 - reactos/ntoskrnl/rtl/debug.c | 299 ------------------------- reactos/ntoskrnl/rtl/libsupp.c | 12 +- reactos/ntoskrnl/rtl/misc.c | 11 + reactos/tools/nci/sysfuncs.lst | 5 + reactos/w32api/include/ddk/winddk.h | 6 + reactos/w32api/include/ntstatus.h | 1 + 22 files changed, 236 insertions(+), 666 deletions(-) delete mode 100644 reactos/lib/ntdll/dbg/debug.c delete mode 100644 reactos/lib/ntdll/dbg/print.c diff --git a/reactos/lib/ntdll/dbg/debug.c b/reactos/lib/ntdll/dbg/debug.c deleted file mode 100644 index edf9e733fee..00000000000 --- a/reactos/lib/ntdll/dbg/debug.c +++ /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 -#define NDEBUG -#include - -/* 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 index 5e4a281099b..00000000000 --- a/reactos/lib/ntdll/dbg/print.c +++ /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 -#define NDEBUG -#include - -/* 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 */ diff --git a/reactos/lib/ntdll/def/ntdll.def b/reactos/lib/ntdll/def/ntdll.def index 6de5ba6fac3..7665999573e 100644 --- a/reactos/lib/ntdll/def/ntdll.def +++ b/reactos/lib/ntdll/def/ntdll.def @@ -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 diff --git a/reactos/lib/ntdll/ntdll.xml b/reactos/lib/ntdll/ntdll.xml index 7f7339f8904..d100957e7c9 100644 --- a/reactos/lib/ntdll/ntdll.xml +++ b/reactos/lib/ntdll/ntdll.xml @@ -20,8 +20,7 @@ connect.c - debug.c - print.c + dbgui.c res.c diff --git a/reactos/lib/ntdll/rtl/libsupp.c b/reactos/lib/ntdll/rtl/libsupp.c index 30b71213634..8508c8d4efb 100644 --- a/reactos/lib/ntdll/rtl/libsupp.c +++ b/reactos/lib/ntdll/rtl/libsupp.c @@ -17,11 +17,30 @@ 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() diff --git a/reactos/lib/rtl/exception.c b/reactos/lib/rtl/exception.c index 6e2d0f53bdc..cd1230c90f4 100644 --- a/reactos/lib/rtl/exception.c +++ b/reactos/lib/rtl/exception.c @@ -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); diff --git a/reactos/lib/rtl/i386/debug.S b/reactos/lib/rtl/i386/debug.S index 76394cfab8c..5ead28eec01 100644 --- a/reactos/lib/rtl/i386/debug.S +++ b/reactos/lib/rtl/i386/debug.S @@ -1,10 +1,9 @@ /* * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * PURPOSE: Run-Time Library + * PROJECT: ReactOS Run-Time Library + * PURPOSE: Debug Routines * FILE: lib/rtl/i386/debug.S * PROGRAMER: Alex Ionescu (alex@relsoft.net) - * REVISION HISTORY: 27/07/2005 Created */ .intel_syntax noprefix @@ -14,6 +13,7 @@ .globl _DbgBreakPoint@0 .globl _DbgBreakPointWithStatus@4 .globl _DbgUserBreakPoint@0 +.globl _DebugService@20 /* FUNCTIONS ***************************************************************/ @@ -26,3 +26,36 @@ _DbgBreakPointWithStatus@4: mov eax, [esp+4] int 3 ret 4 + +_DebugService@20: + + /* Setup the stack */ + push ebp + mov ebp, esp + + /* Save the registers */ + push ecx + push ebx + push edi + push edi + push ebx + + /* Call the Interrupt */ + mov eax, [ebp+8] + mov ecx, [ebp+12] + mov edx, [ebp+16] + mov ebx, [ebp+20] + mov edi, [ebp+24] + int 0x2D + //int 3 + + /* Restore registers */ + pop ebx + pop edi + pop edi + pop ebx + + /* Return */ + leave + ret 20 + diff --git a/reactos/lib/rtl/rtl.xml b/reactos/lib/rtl/rtl.xml index ff0f8f72ce9..bd96383440e 100644 --- a/reactos/lib/rtl/rtl.xml +++ b/reactos/lib/rtl/rtl.xml @@ -24,6 +24,7 @@ crc32.c critical.c dbgbuffer.c + debug.c dos8dot3.c encode.c env.c diff --git a/reactos/lib/rtl/rtlp.h b/reactos/lib/rtl/rtlp.h index 55d0742a0d5..25625e012a9 100644 --- a/reactos/lib/rtl/rtlp.h +++ b/reactos/lib/rtl/rtlp.h @@ -51,7 +51,7 @@ RtlLeaveHeapLock(PRTL_CRITICAL_SECTION CriticalSection); BOOLEAN NTAPI -RtlpCheckForActiveDebugger(VOID); +RtlpCheckForActiveDebugger(BOOLEAN Type); BOOLEAN NTAPI diff --git a/reactos/ntoskrnl/include/internal/kd.h b/reactos/ntoskrnl/include/internal/kd.h index 91e834c9d37..3c7351d60ca 100644 --- a/reactos/ntoskrnl/include/internal/kd.h +++ b/reactos/ntoskrnl/include/internal/kd.h @@ -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 ***************************************************************/ diff --git a/reactos/ntoskrnl/kd/kdio.c b/reactos/ntoskrnl/kd/kdio.c index 22bc5bbf8c9..67025151ad1 100644 --- a/reactos/ntoskrnl/kd/kdio.c +++ b/reactos/ntoskrnl/kd/kdio.c @@ -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 */ diff --git a/reactos/ntoskrnl/kd/kdmain.c b/reactos/ntoskrnl/kd/kdmain.c index 72d5b12cac1..a08154c6845 100644 --- a/reactos/ntoskrnl/kd/kdmain.c +++ b/reactos/ntoskrnl/kd/kdmain.c @@ -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 */ diff --git a/reactos/ntoskrnl/kd/wrappers/bochs.c b/reactos/ntoskrnl/kd/wrappers/bochs.c index d812c385546..f0f5517d709 100644 --- a/reactos/ntoskrnl/kd/wrappers/bochs.c +++ b/reactos/ntoskrnl/kd/wrappers/bochs.c @@ -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, diff --git a/reactos/ntoskrnl/kd/wrappers/gdbstub.c b/reactos/ntoskrnl/kd/wrappers/gdbstub.c index e15c1a75571..521b6c95c5d 100644 --- a/reactos/ntoskrnl/kd/wrappers/gdbstub.c +++ b/reactos/ntoskrnl/kd/wrappers/gdbstub.c @@ -1446,7 +1446,7 @@ extern ULONG KdpPortIrq; VOID STDCALL -KdpGdbDebugPrint(PCH Message) +KdpGdbDebugPrint(PCH Message, ULONG Length) { #if 0 /* This can be quite annoying! */ diff --git a/reactos/ntoskrnl/ke/i386/syscall.S b/reactos/ntoskrnl/ke/i386/syscall.S index 13eb86612b3..cb846673205 100644 --- a/reactos/ntoskrnl/ke/i386/syscall.S +++ b/reactos/ntoskrnl/ke/i386/syscall.S @@ -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 diff --git a/reactos/ntoskrnl/ntoskrnl.xml b/reactos/ntoskrnl/ntoskrnl.xml index 9f06e9e3c4b..0b450cf44f2 100644 --- a/reactos/ntoskrnl/ntoskrnl.xml +++ b/reactos/ntoskrnl/ntoskrnl.xml @@ -306,7 +306,6 @@ atom.c - debug.c libsupp.c misc.c nls.c diff --git a/reactos/ntoskrnl/rtl/debug.c b/reactos/ntoskrnl/rtl/debug.c index 0986ff415cb..e69de29bb2d 100644 --- a/reactos/ntoskrnl/rtl/debug.c +++ b/reactos/ntoskrnl/rtl/debug.c @@ -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 -#include - -/* 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 */ diff --git a/reactos/ntoskrnl/rtl/libsupp.c b/reactos/ntoskrnl/rtl/libsupp.c index 48f3ac918ba..261ace0d93d 100644 --- a/reactos/ntoskrnl/rtl/libsupp.c +++ b/reactos/ntoskrnl/rtl/libsupp.c @@ -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 diff --git a/reactos/ntoskrnl/rtl/misc.c b/reactos/ntoskrnl/rtl/misc.c index 8f2d30a2054..cb9e1f11651 100644 --- a/reactos/ntoskrnl/rtl/misc.c +++ b/reactos/ntoskrnl/rtl/misc.c @@ -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 */ diff --git a/reactos/tools/nci/sysfuncs.lst b/reactos/tools/nci/sysfuncs.lst index 3f2b5925157..0f839414775 100644 --- a/reactos/tools/nci/sysfuncs.lst +++ b/reactos/tools/nci/sysfuncs.lst @@ -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 diff --git a/reactos/w32api/include/ddk/winddk.h b/reactos/w32api/include/ddk/winddk.h index 9d0bde3efff..edd9339b917 100644 --- a/reactos/w32api/include/ddk/winddk.h +++ b/reactos/w32api/include/ddk/winddk.h @@ -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 diff --git a/reactos/w32api/include/ntstatus.h b/reactos/w32api/include/ntstatus.h index 3d5b01a6d5f..c04a6ec1b53 100644 --- a/reactos/w32api/include/ntstatus.h +++ b/reactos/w32api/include/ntstatus.h @@ -26,6 +26,7 @@ * Debug codes */ #define DBG_CONTROL_C ((NTSTATUS)0x40010005L) +#define DBG_PRINTEXCEPTION_C ((NTSTATUS)0x40010006L) #define DBG_CONTROL_BREAK ((NTSTATUS)0x40010008L) /*