- DBGKD_WAIT_STATE_CHANGE64 is used in KD protocol 5, not number 6 that we use. Proto...
authorStefan Ginsberg <stefanginsberg@gmail.com>
Sun, 25 Oct 2009 15:56:38 +0000 (15:56 +0000)
committerStefan Ginsberg <stefanginsberg@gmail.com>
Sun, 25 Oct 2009 15:56:38 +0000 (15:56 +0000)
- Correct the value of SIZE_OF_FX_REGISTERS -- it was 4 times too low which resulted in KeContextToTrapFrame not properly clearing out the XMM register area. Correct the define and move it out from ke.h to x86's ketypes.h and use it in the FXSAVE format structure. Also remove the IOPM definitions from ke.h as they have been in the NDK for a while.
- KD uses STRINGs, not ANSI_STRINGs -- they are the same thing, but let's be consistent.
- ExceptionRecord32To64 should be available for both 32 and 64 bit builds (and it shouldn't be a forceinline). Get rid of CopyExceptionRecord and determine if we need to convert or can just copy it directly instead.
- Use _WIN64 instead of _M_AMD64 when determining if we need to set the DBGKD_VERS_FLAG_PTR64 flag.
- Don't check Nt/DbgQueryDebugFilterState for zero or nonzero -- it actually returns TRUE, FALSE or STATUS_INVALID_PARAMETER_1! Check for != TRUE in preparation for proper implementation of NtSet/QueryDebugFilterState.
- Fix Format parameter of DbgPrintReturnControlC -- it is const like the other DbgPrint* routines.
- Be consistent with the types used in debug.c and don't set local variables to zero if we are going to return to caller -- this doesn't seem to be required anymore.
- Fix DebugService and DebugService2: DebugService should take a ULONG followed by 4 pointers and DebugService2 doesn't return anything.
- Use ZwCurrentProcess() instead of -1 or 0xFFFFFFFF (which is incorrect for 64-bit) for the ProcessId parameter of DbgLoad/UnloadImageSymbols to clarify what is being passed. Don't use ZwCurrentProcess() in KeBugCheckWithTf for the pointer parameter of DbgUnLoadImageSymbols either. Use MAXULONG_PTR casted to PVOID instead.
- Use better named and sized variables in KdpTrap for setting the "return register" in the caller's CONTEXT.
- Correct and clarify the comment documenting under what conditions we pass user mode exceptions to the kernel debugger.

svn path=/trunk/; revision=43741

23 files changed:
reactos/include/ddk/winddk.h
reactos/include/ndk/i386/ketypes.h
reactos/include/ndk/rtlfuncs.h
reactos/include/reactos/windbgkd.h
reactos/lib/drivers/ip/network/routines.c
reactos/lib/rtl/debug.c
reactos/lib/rtl/powerpc/debug.c
reactos/lib/rtl/rtlp.h
reactos/ntoskrnl/ex/init.c
reactos/ntoskrnl/include/internal/kd64.h
reactos/ntoskrnl/include/internal/ke.h
reactos/ntoskrnl/kd/kdmain.c
reactos/ntoskrnl/kd64/amd64/kdsup.c
reactos/ntoskrnl/kd64/arm/kdsup.c
reactos/ntoskrnl/kd64/i386/kdsup.c
reactos/ntoskrnl/kd64/kdapi.c
reactos/ntoskrnl/kd64/kddata.c
reactos/ntoskrnl/kd64/kdinit.c
reactos/ntoskrnl/kd64/kdprint.c
reactos/ntoskrnl/kd64/kdtrap.c
reactos/ntoskrnl/ke/bug.c
reactos/ntoskrnl/ke/i386/exp.c
reactos/ntoskrnl/mm/sysldr.c

index 491d2ba..6b957b0 100644 (file)
@@ -10359,23 +10359,23 @@ NTAPI
 vDbgPrintEx(
   IN ULONG ComponentId,
   IN ULONG Level,
-  IN LPCSTR Format,
+  IN PCCH Format,
   IN va_list ap);
 
 ULONG
 NTAPI
 vDbgPrintExWithPrefix(
-  IN LPCSTR Prefix,
+  IN PCCH Prefix,
   IN ULONG ComponentId,
   IN ULONG Level,
-  IN LPCSTR Format,
+  IN PCCH Format,
   IN va_list ap);
 
 NTKERNELAPI
 ULONG
 DDKCDECLAPI
 DbgPrintReturnControlC(
-  IN PCH  Format,
+  IN PCCH  Format,
   IN ...);
 
 ULONG
index e9c8d7f..e946587 100644 (file)
@@ -131,6 +131,11 @@ Author:
         (USHORT)(sizeof(KTSS)) :                    \
         (USHORT)(FIELD_OFFSET(KTSS, IoMaps[MapNumber-1].IoMap))
 
+//
+// Size of the XMM register save area in the FXSAVE format
+//
+#define SIZE_OF_FX_REGISTERS    128
+
 //
 // Static Kernel-Mode Address start (use MM_KSEG0_BASE for actual)
 //
@@ -333,7 +338,7 @@ typedef struct _FXSAVE_FORMAT
     ULONG DataSelector;
     ULONG MXCsr;
     ULONG MXCsrMask;
-    UCHAR RegisterArea[128];
+    UCHAR RegisterArea[SIZE_OF_FX_REGISTERS];
     UCHAR Reserved3[128];
     UCHAR Reserved4[224];
     UCHAR Align16Byte[8];
index fa2199c..7f33e80 100644 (file)
@@ -2669,7 +2669,7 @@ DbgBreakPoint(
 VOID
 NTAPI
 DbgLoadImageSymbols(
-    IN PANSI_STRING Name,
+    IN PSTRING Name,
     IN PVOID Base,
     IN ULONG_PTR ProcessId
 );
@@ -2677,7 +2677,7 @@ DbgLoadImageSymbols(
 VOID
 NTAPI
 DbgUnLoadImageSymbols(
-    IN PANSI_STRING Name,
+    IN PSTRING Name,
     IN PVOID Base,
     IN ULONG_PTR ProcessId
 );
index bc88bf5..9aafb2c 100644 (file)
@@ -446,8 +446,6 @@ typedef struct _DBGKD_WAIT_STATE_CHANGE32
         DBGKM_EXCEPTION32 Exception;
         DBGKD_LOAD_SYMBOLS32 LoadSymbols;
     } u;
-    DBGKD_CONTROL_REPORT ControlReport;
-    CONTEXT Context;
 } DBGKD_WAIT_STATE_CHANGE32, *PDBGKD_WAIT_STATE_CHANGE32;
 
 typedef struct _DBGKD_WAIT_STATE_CHANGE64
@@ -463,8 +461,6 @@ typedef struct _DBGKD_WAIT_STATE_CHANGE64
         DBGKM_EXCEPTION64 Exception;
         DBGKD_LOAD_SYMBOLS64 LoadSymbols;
     } u;
-    DBGKD_CONTROL_REPORT ControlReport;
-    CONTEXT Context;
 } DBGKD_WAIT_STATE_CHANGE64, *PDBGKD_WAIT_STATE_CHANGE64;
 
 typedef struct _DBGKD_ANY_WAIT_STATE_CHANGE
@@ -864,15 +860,10 @@ typedef struct _DBGKD_TRACE_IO
    } u;
 } DBGKD_TRACE_IO, *PDBGKD_TRACE_IO;
 
-#if defined(_M_AMD64)
-
-#define CopyExceptionRecord(Ex64From, Ex64To) \
-        RtlCopyMemory(Ex64To, Ex64From, sizeof(EXCEPTION_RECORD64))
-
-#else
-
-FORCEINLINE
+static
+__inline
 VOID
+NTAPI
 ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
                       OUT PEXCEPTION_RECORD64 Ex64)
 {
@@ -890,9 +881,4 @@ ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
     }
 }
 
-#define CopyExceptionRecord(Ex32From, Ex64To) \
-        ExceptionRecord32To64((PEXCEPTION_RECORD32)Ex32From, Ex64To)
-
-#endif
-
 #endif
index d25ecd6..6407ecb 100644 (file)
@@ -94,8 +94,8 @@ VOID DisplayTCPPacket(
     UINT Length;
     PCHAR Buffer;
 
-    if (!(DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_PBUFFER | DPFLTR_MASK)) ||
-        !(DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_TCP | DPFLTR_MASK))) {
+    if ((DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_PBUFFER | DPFLTR_MASK) != TRUE) ||
+        (DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_TCP | DPFLTR_MASK) != TRUE)) {
         return;
     }
 
@@ -139,8 +139,8 @@ VOID DisplayIPPacket(
     PNDIS_BUFFER NextBuffer;
     PCHAR CharBuffer;
 
-    if (!(DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_PBUFFER | DPFLTR_MASK)) ||
-        !(DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_IP | DPFLTR_MASK))) {
+    if ((DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_PBUFFER | DPFLTR_MASK) != TRUE) ||
+        (DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_IP | DPFLTR_MASK) != TRUE)) {
         return;
     }
 
index 1ba40c7..5ac10e7 100644 (file)
 
 /* PRIVATE FUNCTIONS ********************************************************/
 
-NTSTATUS
+ULONG
 NTAPI
-DebugPrint(IN PANSI_STRING DebugString,
+DebugPrint(IN PSTRING DebugString,
            IN ULONG ComponentId,
            IN ULONG Level)
 {
     /* Call the Debug Service */
     return DebugService(BREAKPOINT_PRINT,
                         DebugString->Buffer,
-                        DebugString->Length,
+                        UlongToPtr(DebugString->Length),
                         UlongToPtr(ComponentId),
                         UlongToPtr(Level));
 }
 
-NTSTATUS
+ULONG
 NTAPI
-DebugPrompt(IN PCSTRING Output,
+DebugPrompt(IN PSTRING Output,
             IN PSTRING Input)
 {
     /* Call the Debug Service */
     return DebugService(BREAKPOINT_PROMPT,
                         Output->Buffer,
-                        Output->Length,
+                        UlongToPtr(Output->Length),
                         Input->Buffer,
                         UlongToPtr(Input->MaximumLength));
 }
@@ -47,22 +47,22 @@ DebugPrompt(IN PCSTRING Output,
 
 ULONG
 NTAPI
-vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
+vDbgPrintExWithPrefixInternal(IN PCCH Prefix,
                               IN ULONG ComponentId,
                               IN ULONG Level,
-                              IN LPCSTR Format,
+                              IN PCCH Format,
                               IN va_list ap,
                               IN BOOLEAN HandleBreakpoint)
 {
     NTSTATUS Status;
-    ANSI_STRING DebugString;
+    STRING DebugString;
     CHAR Buffer[512];
     ULONG Length, PrefixLength;
     EXCEPTION_RECORD ExceptionRecord;
 
     /* Check if we should print it or not */
     if ((ComponentId != MAXULONG) &&
-        !(NtQueryDebugFilterState(ComponentId, Level)))
+        (NtQueryDebugFilterState(ComponentId, Level)) != TRUE)
     {
         /* This message is masked */
         return STATUS_SUCCESS;
@@ -90,7 +90,6 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
     {
         /* Fail */
-        Length = PrefixLength = 0;
         _SEH2_YIELD(return _SEH2_GetExceptionCode());
     }
     _SEH2_END;
@@ -160,10 +159,10 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
  */
 ULONG
 NTAPI
-vDbgPrintExWithPrefix(IN LPCSTR Prefix,
+vDbgPrintExWithPrefix(IN PCCH Prefix,
                       IN ULONG ComponentId,
                       IN ULONG Level,
-                      IN LPCSTR Format,
+                      IN PCCH Format,
                       IN va_list ap)
 {
     /* Call the internal routine that also handles ControlC */
@@ -182,7 +181,7 @@ ULONG
 NTAPI
 vDbgPrintEx(IN ULONG ComponentId,
             IN ULONG Level,
-            IN LPCSTR Format,
+            IN PCCH Format,
             IN va_list ap)
 {
     /* Call the internal routine that also handles ControlC */
@@ -202,19 +201,19 @@ __cdecl
 DbgPrint(PCCH Format,
          ...)
 {
-    ULONG n;
+    ULONG Status;
     va_list ap;
 
     /* Call the internal routine that also handles ControlC */
     va_start(ap, Format);
-    n = vDbgPrintExWithPrefixInternal("",
-                                      -1,
-                                      DPFLTR_ERROR_LEVEL,
-                                      Format,
-                                      ap,
-                                      TRUE);
+    Status = vDbgPrintExWithPrefixInternal("",
+                                           -1,
+                                           DPFLTR_ERROR_LEVEL,
+                                           Format,
+                                           ap,
+                                           TRUE);
     va_end(ap);
-    return n;
+    return Status;
 }
 
 /*
@@ -227,19 +226,19 @@ DbgPrintEx(IN ULONG ComponentId,
            IN PCCH Format,
            ...)
 {
-    ULONG n;
+    ULONG Status;
     va_list ap;
 
     /* Call the internal routine that also handles ControlC */
     va_start(ap, Format);
-    n = vDbgPrintExWithPrefixInternal("",
-                                      ComponentId,
-                                      Level,
-                                      Format,
-                                      ap,
-                                      TRUE);
+    Status = vDbgPrintExWithPrefixInternal("",
+                                           ComponentId,
+                                           Level,
+                                           Format,
+                                           ap,
+                                           TRUE);
     va_end(ap);
-    return n;
+    return Status;
 }
 
 /*
@@ -247,22 +246,22 @@ DbgPrintEx(IN ULONG ComponentId,
  */
 ULONG
 __cdecl
-DbgPrintReturnControlC(PCH Format,
+DbgPrintReturnControlC(PCCH Format,
                        ...)
 {
-    ULONG n;
+    ULONG Status;
     va_list ap;
 
     /* Call the internal routine that also handles ControlC */
     va_start(ap, Format);
-    n = vDbgPrintExWithPrefixInternal("",
-                                      -1,
-                                      DPFLTR_ERROR_LEVEL,
-                                      Format,
-                                      ap,
-                                      FALSE);
+    Status = vDbgPrintExWithPrefixInternal("",
+                                           -1,
+                                           DPFLTR_ERROR_LEVEL,
+                                           Format,
+                                           ap,
+                                           FALSE);
     va_end(ap);
-    return n;
+    return Status;
 }
 
 /*
@@ -274,7 +273,7 @@ DbgPrompt(IN PCCH Prompt,
           OUT PCH Response,
           IN ULONG MaximumResponseLength)
 {
-    CSTRING Output;
+    STRING Output;
     STRING Input;
 
     /* Setup the input string */
@@ -283,7 +282,7 @@ DbgPrompt(IN PCCH Prompt,
 
     /* Setup the output string */
     Output.Length = strlen(Prompt);
-    Output.Buffer = Prompt;
+    Output.Buffer = (PCH)Prompt;
 
     /* Call the system service */
     return DebugPrompt(&Output, &Input);
@@ -319,7 +318,7 @@ DbgSetDebugFilterState(IN ULONG ComponentId,
  */
 VOID
 NTAPI
-DbgLoadImageSymbols(IN PANSI_STRING Name,
+DbgLoadImageSymbols(IN PSTRING Name,
                     IN PVOID Base,
                     IN ULONG_PTR ProcessId)
 {
@@ -328,7 +327,7 @@ DbgLoadImageSymbols(IN PANSI_STRING Name,
 
     /* Setup the symbol data */
     SymbolInfo.BaseOfDll = Base;
-    SymbolInfo.ProcessId = (ULONG)ProcessId;
+    SymbolInfo.ProcessId = ProcessId;
 
     /* Get NT Headers */
     NtHeader = RtlImageNtHeader(Base);
@@ -353,7 +352,7 @@ DbgLoadImageSymbols(IN PANSI_STRING Name,
  */
 VOID
 NTAPI
-DbgUnLoadImageSymbols(IN PANSI_STRING Name,
+DbgUnLoadImageSymbols(IN PSTRING Name,
                       IN PVOID Base,
                       IN ULONG_PTR ProcessId)
 {
@@ -361,7 +360,7 @@ DbgUnLoadImageSymbols(IN PANSI_STRING Name,
 
     /* Setup the symbol data */
     SymbolInfo.BaseOfDll = Base;
-    SymbolInfo.ProcessId = (ULONG)ProcessId;
+    SymbolInfo.ProcessId = ProcessId;
     SymbolInfo.CheckSum = SymbolInfo.SizeOfImage = 0;
 
     /* Load the symbols */
index dfedd25..41f8f79 100644 (file)
@@ -9,12 +9,12 @@ NTKERNELAPI
 VOID
 DbgBreakPointWithStatus(ULONG Status) { __asm__("ti 31,0,0"); }
 
-NTSTATUS
+ULONG
 NTAPI
 DebugService
-(ULONG Service, const void *Buffer, ULONG Length, PVOID Arg1, PVOID Arg2)
+(ULONG Service, PVOID Argument1, PVOID Argument1, PVOID Argument3, PVOID Argument4)
 {
-    NTSTATUS Result;
+    ULONG Result;
     __asm__("mr 0,%1\n\t"
             "mr 3,%2\n\t"
            "mr 4,%3\n\t"
@@ -26,17 +26,16 @@ DebugService
            "=r" (Result) :
            "r" (0x10000),
            "r" (Service),
-           "r" (Buffer),
-           "r" (Length),
-           "r" (Arg1),
-           "r" (Arg2) );
+           "r" (Argument1),
+           "r" (Argument2),
+           "r" (Argument3),
+           "r" (Argument4) );
     return Result;
 }
 
-NTSTATUS
+VOID
 NTAPI
 DebugService2
 (PVOID Arg1, PVOID Arg2, ULONG Service)
 {
-    return STATUS_SUCCESS;
 }
index e0f2436..297b0bc 100644 (file)
@@ -145,20 +145,26 @@ VOID
 NTAPI
 RtlpCaptureContext(OUT PCONTEXT ContextRecord);
 
-/* i386/debug.S */
-NTSTATUS
-NTAPI
-DebugService(IN ULONG Service,
-             IN const void* Buffer,
-             IN ULONG Length,
-             IN PVOID Argument1,
-             IN PVOID Argument2);
+//
+// Debug Service calls
+//
+ULONG
+NTAPI
+DebugService(
+    IN ULONG Service,
+    IN PVOID Argument1,
+    IN PVOID Argument2,
+    IN PVOID Argument3,
+    IN PVOID Argument4
+);
 
-NTSTATUS
+VOID
 NTAPI
-DebugService2(IN PVOID Argument1,
-              IN PVOID Argument2,
-              IN ULONG Service);
+DebugService2(
+    IN PVOID Argument1,
+    IN PVOID Argument2,
+    IN ULONG Service
+);
 
 /* Tags for the String Allocators */
 #define TAG_USTR        'RTSU'
index d641541..012f9fa 100644 (file)
@@ -734,7 +734,7 @@ ExpLoadBootSymbols(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     PLDR_DATA_TABLE_ENTRY LdrEntry;
     BOOLEAN OverFlow = FALSE;
     CHAR NameBuffer[256];
-    ANSI_STRING SymbolString;
+    STRING SymbolString;
 
     /* Loop the driver list */
     NextEntry = LoaderBlock->LoadOrderListHead.Flink;
@@ -799,13 +799,13 @@ ExpLoadBootSymbols(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
             /* Check if the buffer was ok */
             if (!OverFlow)
             {
-                /* Initialize the ANSI_STRING for the debugger */
+                /* Initialize the STRING for the debugger */
                 RtlInitString(&SymbolString, NameBuffer);
 
                 /* Load the symbols */
                 DbgLoadImageSymbols(&SymbolString,
                                     LdrEntry->DllBase,
-                                    0xFFFFFFFF);
+                                    (ULONG_PTR)ZwCurrentProcess());
             }
         }
 
index fb193a4..a3e9d28 100644 (file)
@@ -217,7 +217,7 @@ VOID
 NTAPI
 KdpSymbol(
     IN PSTRING DllPath,
-    IN PKD_SYMBOLS_INFO DllBase,
+    IN PKD_SYMBOLS_INFO SymbolInfo,
     IN BOOLEAN Unload,
     IN KPROCESSOR_MODE PreviousMode,
     IN PCONTEXT ContextRecord,
@@ -322,7 +322,7 @@ KdpGetStateChange(
 VOID
 NTAPI
 KdpSetContextState(
-    IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
+    IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange,
     IN PCONTEXT Context
 );
 
index a85180e..4173a3a 100644 (file)
@@ -180,16 +180,6 @@ extern ULONG KiDPCTimeout;
 /* One of the Reserved Wait Blocks, this one is for the Thread's Timer */
 #define TIMER_WAIT_BLOCK 0x3L
 
-/* IOPM Definitions */
-#define IO_ACCESS_MAP_NONE 0
-#define IOPM_OFFSET FIELD_OFFSET(KTSS, IoMaps[0].IoMap)
-#define KiComputeIopmOffset(MapNumber)              \
-    (MapNumber == IO_ACCESS_MAP_NONE) ?             \
-        (USHORT)(sizeof(KTSS)) :                    \
-        (USHORT)(FIELD_OFFSET(KTSS, IoMaps[MapNumber-1].IoMap))
-
-#define SIZE_OF_FX_REGISTERS 32
-
 /* INTERNAL KERNEL FUNCTIONS ************************************************/
 
 VOID
index 791be4e..bc54173 100644 (file)
@@ -368,13 +368,13 @@ NtQueryDebugFilterState(IN ULONG ComponentId,
             if (ComponentId == KdComponentTable[i].ComponentId)
             {
                 /* Check if mask are matching */
-                return (Level & KdComponentTable[i].Level) != 0;
+                return (Level & KdComponentTable[i].Level) ? TRUE : FALSE;
             }
         }
     }
 
     /* Entry not found in the table, use default mask */
-    return (Level & Kd_DEFAULT_MASK) != 0;
+    return (Level & Kd_DEFAULT_MASK) ? TRUE : FALSE;
 }
 
 NTSTATUS
index f31a4e8..c8e83a1 100644 (file)
@@ -28,7 +28,7 @@ KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
 
 VOID
 NTAPI
-KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
+KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange,
                    IN PCONTEXT Context)
 {
     UNIMPLEMENTED;
index 9ba9045..c763b6f 100644 (file)
@@ -28,7 +28,7 @@ KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
 
 VOID
 NTAPI
-KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
+KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange,
                    IN PCONTEXT Context)
 {
     UNIMPLEMENTED;
index b232a02..db2dc8b 100644 (file)
@@ -69,7 +69,7 @@ KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
 
 VOID
 NTAPI
-KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
+KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange,
                    IN PCONTEXT Context)
 {
     PKPRCB Prcb = KeGetCurrentPrcb();
index 329fec5..6efa5f3 100644 (file)
@@ -267,7 +267,7 @@ VOID
 NTAPI
 KdpSetCommonState(IN ULONG NewState,
                   IN PCONTEXT Context,
-                  IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange)
+                  IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange)
 {
     USHORT InstructionCount;
     BOOLEAN HadBreakpoints;
@@ -280,9 +280,9 @@ KdpSetCommonState(IN ULONG NewState,
     WaitStateChange->Thread = (ULONG64)(LONG_PTR)KeGetCurrentThread();
     WaitStateChange->ProgramCounter = (ULONG64)(LONG_PTR)KeGetContextPc(Context);
 
-    /* Zero out the Control Report */
-    RtlZeroMemory(&WaitStateChange->ControlReport,
-                  sizeof(DBGKD_CONTROL_REPORT));
+    /* Zero out the entire Control Report */
+    RtlZeroMemory(&WaitStateChange->AnyControlReport,
+                  sizeof(DBGKD_ANY_CONTROL_REPORT));
 
     /* Now copy the instruction stream and set the count */
     RtlCopyMemory(&WaitStateChange->ControlReport.InstructionStream[0],
@@ -1296,7 +1296,7 @@ KdpReportLoadSymbolsStateChange(IN PSTRING PathName,
 {
     PSTRING ExtraData;
     STRING Data, Header;
-    DBGKD_WAIT_STATE_CHANGE64 WaitStateChange;
+    DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
     KCONTINUE_STATUS Status;
 
     /* Start wait loop */
@@ -1335,7 +1335,7 @@ KdpReportLoadSymbolsStateChange(IN PSTRING PathName,
         }
 
         /* Setup the header */
-        Header.Length = sizeof(DBGKD_WAIT_STATE_CHANGE64);
+        Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
         Header.Buffer = (PCHAR)&WaitStateChange;
 
         /* Send the packet */
@@ -1356,7 +1356,7 @@ KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
                               IN BOOLEAN SecondChanceException)
 {
     STRING Header, Data;
-    DBGKD_WAIT_STATE_CHANGE64 WaitStateChange;
+    DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
     KCONTINUE_STATUS Status;
 
     /* Start report loop */
@@ -1366,15 +1366,21 @@ KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
         KdpSetCommonState(DbgKdExceptionStateChange, Context, &WaitStateChange);
 
         /* Copy the Exception Record and set First Chance flag */
-        CopyExceptionRecord(ExceptionRecord,
-                            &WaitStateChange.u.Exception.ExceptionRecord);
+#if !defined(_WIN64)
+        ExceptionRecord32To64((PEXCEPTION_RECORD32)ExceptionRecord,
+                              &WaitStateChange.u.Exception.ExceptionRecord);
+#else
+        RtlCopyMemory(&WaitStateChange.u.Exception.ExceptionRecord,
+                      ExceptionRecord,
+                      sizeof(EXCEPTION_RECORD));
+#endif
         WaitStateChange.u.Exception.FirstChance = !SecondChanceException;
 
         /* Now finish creating the structure */
         KdpSetContextState(&WaitStateChange, Context);
 
         /* Setup the actual header to send to KD */
-        Header.Length = sizeof(DBGKD_WAIT_STATE_CHANGE64);
+        Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
         Header.Buffer = (PCHAR)&WaitStateChange;
 
         /* Setup the trace data */
@@ -1828,20 +1834,26 @@ KdRefreshDebuggerNotPresent(VOID)
     return KdDebuggerNotPresent;
 }
 
+/*
+ * @unimplemented
+ */
 NTSTATUS
 NTAPI
-NtQueryDebugFilterState(ULONG ComponentId,
-                        ULONG Level)
+NtQueryDebugFilterState(IN ULONG ComponentId,
+                        IN ULONG Level)
 {
     /* HACK */
     return STATUS_SUCCESS;
 }
 
+/*
+ * @unimplemented
+ */
 NTSTATUS
 NTAPI
-NtSetDebugFilterState(ULONG ComponentId,
-                      ULONG Level,
-                      BOOLEAN State)
+NtSetDebugFilterState(IN ULONG ComponentId,
+                      IN ULONG Level,
+                      IN BOOLEAN State)
 {
     /* HACK */
     return STATUS_SUCCESS;
index 9af857a..c911037 100644 (file)
@@ -360,7 +360,7 @@ DBGKD_GET_VERSION64 KdVersionBlock =
     0,
     DBGKD_64BIT_PROTOCOL_VERSION2,
     CURRENT_KD_SECONDARY_VERSION,
-#if defined(_M_AMD64)
+#if defined(_WIN64)
     DBGKD_VERS_FLAG_DATA | DBGKD_VERS_FLAG_PTR64,
 #else
     DBGKD_VERS_FLAG_DATA,
index 8139564..77c0b1a 100644 (file)
@@ -75,7 +75,7 @@ KdInitSystem(IN ULONG BootPhase,
 {
     BOOLEAN EnableKd, DisableKdAfterInit = FALSE, BlockEnable;
     LPSTR CommandLine, DebugLine, DebugOptionStart, DebugOptionEnd;
-    ANSI_STRING ImageName;
+    STRING ImageName;
     PLDR_DATA_TABLE_ENTRY LdrEntry;
     PLIST_ENTRY NextEntry;
     ULONG i, j, Length, DebugOptionLength;
@@ -350,8 +350,10 @@ KdInitSystem(IN ULONG BootPhase,
                 NameBuffer[j] = ANSI_NULL;
 
                 /* Load symbols for image */
-                RtlInitAnsiString(&ImageName, NameBuffer);
-                DbgLoadImageSymbols(&ImageName, LdrEntry->DllBase, -1);
+                RtlInitString(&ImageName, NameBuffer);
+                DbgLoadImageSymbols(&ImageName,
+                                    LdrEntry->DllBase,
+                                    (ULONG_PTR)ZwCurrentProcess());
 
                 /* Go to the next entry */
                 NextEntry = NextEntry->Flink;
index 135b1ed..11380c7 100644 (file)
@@ -138,7 +138,7 @@ KdpCommandString(IN ULONG Length,
 VOID
 NTAPI
 KdpSymbol(IN PSTRING DllPath,
-          IN PKD_SYMBOLS_INFO DllBase,
+          IN PKD_SYMBOLS_INFO SymbolInfo,
           IN BOOLEAN Unload,
           IN KPROCESSOR_MODE PreviousMode,
           IN PCONTEXT ContextRecord,
@@ -163,7 +163,7 @@ KdpSymbol(IN PSTRING DllPath,
 
     /* Report the new state */
     Status = KdpReportLoadSymbolsStateChange(DllPath,
-                                             DllBase,
+                                             SymbolInfo,
                                              Unload,
                                              &Prcb->ProcessorState.
                                              ContextFrame);
@@ -243,7 +243,7 @@ KdpPrint(IN ULONG ComponentId,
 {
     NTSTATUS ReturnStatus;
     BOOLEAN Entered;
-    ANSI_STRING AnsiString;
+    STRING OutputString;
 
     /* Assume failure */
     *Status = FALSE;
@@ -268,12 +268,12 @@ KdpPrint(IN ULONG ComponentId,
         /* FIXME: Support user-mode */
     }
 
-    /* Setup the ANSI string */
-    AnsiString.Buffer = String;
-    AnsiString.Length = Length;
+    /* Setup the output string */
+    OutputString.Buffer = String;
+    OutputString.Length = Length;
 
     /* Log the print */
-    //KdLogDbgPrint(&AnsiString);
+    //KdLogDbgPrint(&OutputString);
 
     /* Check for a debugger */
     if (KdDebuggerNotPresent)
@@ -287,7 +287,7 @@ KdpPrint(IN ULONG ComponentId,
     Entered = KdEnterDebugger(TrapFrame, ExceptionFrame);
 
     /* Print the string */
-    if (KdpPrintString(&AnsiString))
+    if (KdpPrintString(&OutputString))
     {
         /* User pressed CTRL-C, breakpoint on return */
         ReturnStatus = STATUS_BREAKPOINT;
index aed14be..28a72e8 100644 (file)
@@ -135,8 +135,10 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
         IN BOOLEAN SecondChanceException)
 {
     BOOLEAN Unload = FALSE;
-    ULONG_PTR ProgramCounter, ReturnValue;
+    ULONG_PTR ProgramCounter;
     BOOLEAN Status = FALSE;
+    NTSTATUS ReturnStatus;
+    USHORT ReturnLength;
 
     /*
      * Check if we got a STATUS_BREAKPOINT with a SubID for Print, Prompt or
@@ -156,38 +158,38 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
             case BREAKPOINT_PRINT:
 
                 /* Call the worker routine */
-                ReturnValue = KdpPrint((ULONG)KdpGetFirstParameter(ContextRecord),
-                                       (ULONG)KdpGetSecondParameter(ContextRecord),
-                                       (LPSTR)ExceptionRecord->
-                                       ExceptionInformation[1],
-                                       (USHORT)ExceptionRecord->
-                                       ExceptionInformation[2],
-                                       PreviousMode,
-                                       TrapFrame,
-                                       ExceptionFrame,
-                                       &Status);
+                ReturnStatus = KdpPrint((ULONG)KdpGetFirstParameter(ContextRecord),
+                                        (ULONG)KdpGetSecondParameter(ContextRecord),
+                                        (LPSTR)ExceptionRecord->
+                                        ExceptionInformation[1],
+                                        (USHORT)ExceptionRecord->
+                                        ExceptionInformation[2],
+                                        PreviousMode,
+                                        TrapFrame,
+                                        ExceptionFrame,
+                                        &Status);
 
                 /* Update the return value for the caller */
-                KeSetContextReturnRegister(ContextRecord, ReturnValue);
+                KeSetContextReturnRegister(ContextRecord, ReturnStatus);
                 break;
 
             /* DbgPrompt */
             case BREAKPOINT_PROMPT:
 
                 /* Call the worker routine */
-                ReturnValue = KdpPrompt((LPSTR)ExceptionRecord->
-                                        ExceptionInformation[1],
-                                        (USHORT)ExceptionRecord->
-                                        ExceptionInformation[2],
-                                        (LPSTR)KdpGetFirstParameter(ContextRecord),
-                                        (USHORT)KdpGetSecondParameter(ContextRecord),
-                                        PreviousMode,
-                                        TrapFrame,
-                                        ExceptionFrame);
+                ReturnLength = KdpPrompt((LPSTR)ExceptionRecord->
+                                         ExceptionInformation[1],
+                                         (USHORT)ExceptionRecord->
+                                         ExceptionInformation[2],
+                                         (LPSTR)KdpGetFirstParameter(ContextRecord),
+                                         (USHORT)KdpGetSecondParameter(ContextRecord),
+                                         PreviousMode,
+                                         TrapFrame,
+                                         ExceptionFrame);
                 Status = TRUE;
 
                 /* Update the return value for the caller */
-                KeSetContextReturnRegister(ContextRecord, ReturnValue);
+                KeSetContextReturnRegister(ContextRecord, ReturnLength);
                 break;
 
             /* DbgUnLoadImageSymbols */
index 056fb7b..499b134 100644 (file)
@@ -1197,7 +1197,7 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
     if (Reboot)
     {
         /* Unload symbols */
-        DbgUnLoadImageSymbols(NULL, NtCurrentProcess(), 0);
+        DbgUnLoadImageSymbols(NULL, (PVOID)MAXULONG_PTR, 0);
         HalReturnToFirmware(HalRebootRoutine);
     }
 
index bd0df7a..28fdeb8 100644 (file)
@@ -930,9 +930,8 @@ KiDispatchException(IN PEXCEPTION_RECORD ExceptionRecord,
         {
             /* 
              * Break into the kernel debugger unless a user mode debugger
-             * is present or user mode exceptions are ignored, unless this is
-             * a breakpoint or a debug service in which case we have to
-             * handle it.
+             * is present or user mode exceptions are ignored, except if this
+             * is a debug service which we must always pass to KD
              */
             if ((!(PsGetCurrentProcess()->DebugPort) &&
                  !(KdIgnoreUmExceptions)) ||
index f63a7ca..23cb5fe 100644 (file)
@@ -730,7 +730,7 @@ MmUnloadSystemImage(IN PVOID ImageHandle)
     PLDR_DATA_TABLE_ENTRY LdrEntry = ImageHandle;
     PVOID BaseAddress = LdrEntry->DllBase;
     NTSTATUS Status;
-    ANSI_STRING TempName;
+    STRING TempName;
     BOOLEAN HadEntry = FALSE;
 
     /* Acquire the loader lock */
@@ -761,7 +761,9 @@ MmUnloadSystemImage(IN PVOID ImageHandle)
         if (NT_SUCCESS(Status))
         {
             /* Unload the symbols */
-            DbgUnLoadImageSymbols(&TempName, BaseAddress, -1);
+            DbgUnLoadImageSymbols(&TempName,
+                                  BaseAddress,
+                                  (ULONG_PTR)ZwCurrentProcess());
             RtlFreeAnsiString(&TempName);
         }
     }
@@ -1528,7 +1530,7 @@ MmLoadSystemImage(IN PUNICODE_STRING FileName,
     BOOLEAN LockOwned = FALSE;
     PLIST_ENTRY NextEntry;
     IMAGE_INFO ImageInfo;
-    ANSI_STRING AnsiTemp;
+    STRING AnsiTemp;
     PAGED_CODE();
 
     /* Detect session-load */
@@ -1941,7 +1943,9 @@ LoaderScan:
         RtlInitString(&AnsiTemp, Buffer);
 
         /* Notify the debugger */
-        DbgLoadImageSymbols(&AnsiTemp, LdrEntry->DllBase, -1);
+        DbgLoadImageSymbols(&AnsiTemp,
+                            LdrEntry->DllBase,
+                            (ULONG_PTR)ZwCurrentProcess());
         LdrEntry->Flags |= LDRP_DEBUG_SYMBOLS_LOADED;
     }