Skip to content

Commit eae6521

Browse files
author
Stefan Ginsberg
committed
- DBGKD_WAIT_STATE_CHANGE64 is used in KD protocol 5, not number 6 that we use. Protocol 6 uses the DBGKD_ANY_WAIT_STATE_CHANGE structure which is sized according to the largest control-report structure (AMD64_DBGKD_CONTROL_REPORT currently), and is larger than DBGKD_WAIT_STATE_CHANGE64 on x86. This worked because our DBGKD_WAIT_STATE_CHANGE32/64 structures contained incorrect DBGKD_CONTROL_REPORT (used) and CONTEXT (unused) members that sized up the wait-state structure to pass WinDbg's length verification! It actually becomes larger than DBGKD_ANY_WAIT_STATE_CHANGE, but WinDbg only seems bail out only if the structure is too small. Remove the incorrect members from the protocol 5 structures and change to DBGKD_ANY_WAIT_STATE_CHANGE everywhere.
- 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
1 parent 5225641 commit eae6521

File tree

23 files changed

+175
-171
lines changed

23 files changed

+175
-171
lines changed

reactos/include/ddk/winddk.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10359,23 +10359,23 @@ NTAPI
1035910359
vDbgPrintEx(
1036010360
IN ULONG ComponentId,
1036110361
IN ULONG Level,
10362-
IN LPCSTR Format,
10362+
IN PCCH Format,
1036310363
IN va_list ap);
1036410364

1036510365
ULONG
1036610366
NTAPI
1036710367
vDbgPrintExWithPrefix(
10368-
IN LPCSTR Prefix,
10368+
IN PCCH Prefix,
1036910369
IN ULONG ComponentId,
1037010370
IN ULONG Level,
10371-
IN LPCSTR Format,
10371+
IN PCCH Format,
1037210372
IN va_list ap);
1037310373

1037410374
NTKERNELAPI
1037510375
ULONG
1037610376
DDKCDECLAPI
1037710377
DbgPrintReturnControlC(
10378-
IN PCH Format,
10378+
IN PCCH Format,
1037910379
IN ...);
1038010380

1038110381
ULONG

reactos/include/ndk/i386/ketypes.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ Header Name:
131131
(USHORT)(sizeof(KTSS)) : \
132132
(USHORT)(FIELD_OFFSET(KTSS, IoMaps[MapNumber-1].IoMap))
133133

134+
//
135+
// Size of the XMM register save area in the FXSAVE format
136+
//
137+
#define SIZE_OF_FX_REGISTERS 128
138+
134139
//
135140
// Static Kernel-Mode Address start (use MM_KSEG0_BASE for actual)
136141
//
@@ -333,7 +338,7 @@ typedef struct _FXSAVE_FORMAT
333338
ULONG DataSelector;
334339
ULONG MXCsr;
335340
ULONG MXCsrMask;
336-
UCHAR RegisterArea[128];
341+
UCHAR RegisterArea[SIZE_OF_FX_REGISTERS];
337342
UCHAR Reserved3[128];
338343
UCHAR Reserved4[224];
339344
UCHAR Align16Byte[8];

reactos/include/ndk/rtlfuncs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,15 +2669,15 @@ DbgBreakPoint(
26692669
VOID
26702670
NTAPI
26712671
DbgLoadImageSymbols(
2672-
IN PANSI_STRING Name,
2672+
IN PSTRING Name,
26732673
IN PVOID Base,
26742674
IN ULONG_PTR ProcessId
26752675
);
26762676

26772677
VOID
26782678
NTAPI
26792679
DbgUnLoadImageSymbols(
2680-
IN PANSI_STRING Name,
2680+
IN PSTRING Name,
26812681
IN PVOID Base,
26822682
IN ULONG_PTR ProcessId
26832683
);

reactos/include/reactos/windbgkd.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,6 @@ typedef struct _DBGKD_WAIT_STATE_CHANGE32
446446
DBGKM_EXCEPTION32 Exception;
447447
DBGKD_LOAD_SYMBOLS32 LoadSymbols;
448448
} u;
449-
DBGKD_CONTROL_REPORT ControlReport;
450-
CONTEXT Context;
451449
} DBGKD_WAIT_STATE_CHANGE32, *PDBGKD_WAIT_STATE_CHANGE32;
452450

453451
typedef struct _DBGKD_WAIT_STATE_CHANGE64
@@ -463,8 +461,6 @@ typedef struct _DBGKD_WAIT_STATE_CHANGE64
463461
DBGKM_EXCEPTION64 Exception;
464462
DBGKD_LOAD_SYMBOLS64 LoadSymbols;
465463
} u;
466-
DBGKD_CONTROL_REPORT ControlReport;
467-
CONTEXT Context;
468464
} DBGKD_WAIT_STATE_CHANGE64, *PDBGKD_WAIT_STATE_CHANGE64;
469465

470466
typedef struct _DBGKD_ANY_WAIT_STATE_CHANGE
@@ -864,15 +860,10 @@ typedef struct _DBGKD_TRACE_IO
864860
} u;
865861
} DBGKD_TRACE_IO, *PDBGKD_TRACE_IO;
866862

867-
#if defined(_M_AMD64)
868-
869-
#define CopyExceptionRecord(Ex64From, Ex64To) \
870-
RtlCopyMemory(Ex64To, Ex64From, sizeof(EXCEPTION_RECORD64))
871-
872-
#else
873-
874-
FORCEINLINE
863+
static
864+
__inline
875865
VOID
866+
NTAPI
876867
ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
877868
OUT PEXCEPTION_RECORD64 Ex64)
878869
{
@@ -890,9 +881,4 @@ ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
890881
}
891882
}
892883

893-
#define CopyExceptionRecord(Ex32From, Ex64To) \
894-
ExceptionRecord32To64((PEXCEPTION_RECORD32)Ex32From, Ex64To)
895-
896-
#endif
897-
898884
#endif

reactos/lib/drivers/ip/network/routines.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ VOID DisplayTCPPacket(
9494
UINT Length;
9595
PCHAR Buffer;
9696

97-
if (!(DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_PBUFFER | DPFLTR_MASK)) ||
98-
!(DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_TCP | DPFLTR_MASK))) {
97+
if ((DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_PBUFFER | DPFLTR_MASK) != TRUE) ||
98+
(DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_TCP | DPFLTR_MASK) != TRUE)) {
9999
return;
100100
}
101101

@@ -139,8 +139,8 @@ VOID DisplayIPPacket(
139139
PNDIS_BUFFER NextBuffer;
140140
PCHAR CharBuffer;
141141

142-
if (!(DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_PBUFFER | DPFLTR_MASK)) ||
143-
!(DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_IP | DPFLTR_MASK))) {
142+
if ((DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_PBUFFER | DPFLTR_MASK) != TRUE) ||
143+
(DbgQueryDebugFilterState(DPFLTR_TCPIP_ID, DEBUG_IP | DPFLTR_MASK) != TRUE)) {
144144
return;
145145
}
146146

reactos/lib/rtl/debug.c

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@
1616

1717
/* PRIVATE FUNCTIONS ********************************************************/
1818

19-
NTSTATUS
19+
ULONG
2020
NTAPI
21-
DebugPrint(IN PANSI_STRING DebugString,
21+
DebugPrint(IN PSTRING DebugString,
2222
IN ULONG ComponentId,
2323
IN ULONG Level)
2424
{
2525
/* Call the Debug Service */
2626
return DebugService(BREAKPOINT_PRINT,
2727
DebugString->Buffer,
28-
DebugString->Length,
28+
UlongToPtr(DebugString->Length),
2929
UlongToPtr(ComponentId),
3030
UlongToPtr(Level));
3131
}
3232

33-
NTSTATUS
33+
ULONG
3434
NTAPI
35-
DebugPrompt(IN PCSTRING Output,
35+
DebugPrompt(IN PSTRING Output,
3636
IN PSTRING Input)
3737
{
3838
/* Call the Debug Service */
3939
return DebugService(BREAKPOINT_PROMPT,
4040
Output->Buffer,
41-
Output->Length,
41+
UlongToPtr(Output->Length),
4242
Input->Buffer,
4343
UlongToPtr(Input->MaximumLength));
4444
}
@@ -47,22 +47,22 @@ DebugPrompt(IN PCSTRING Output,
4747

4848
ULONG
4949
NTAPI
50-
vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
50+
vDbgPrintExWithPrefixInternal(IN PCCH Prefix,
5151
IN ULONG ComponentId,
5252
IN ULONG Level,
53-
IN LPCSTR Format,
53+
IN PCCH Format,
5454
IN va_list ap,
5555
IN BOOLEAN HandleBreakpoint)
5656
{
5757
NTSTATUS Status;
58-
ANSI_STRING DebugString;
58+
STRING DebugString;
5959
CHAR Buffer[512];
6060
ULONG Length, PrefixLength;
6161
EXCEPTION_RECORD ExceptionRecord;
6262

6363
/* Check if we should print it or not */
6464
if ((ComponentId != MAXULONG) &&
65-
!(NtQueryDebugFilterState(ComponentId, Level)))
65+
(NtQueryDebugFilterState(ComponentId, Level)) != TRUE)
6666
{
6767
/* This message is masked */
6868
return STATUS_SUCCESS;
@@ -90,7 +90,6 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
9090
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
9191
{
9292
/* Fail */
93-
Length = PrefixLength = 0;
9493
_SEH2_YIELD(return _SEH2_GetExceptionCode());
9594
}
9695
_SEH2_END;
@@ -160,10 +159,10 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
160159
*/
161160
ULONG
162161
NTAPI
163-
vDbgPrintExWithPrefix(IN LPCSTR Prefix,
162+
vDbgPrintExWithPrefix(IN PCCH Prefix,
164163
IN ULONG ComponentId,
165164
IN ULONG Level,
166-
IN LPCSTR Format,
165+
IN PCCH Format,
167166
IN va_list ap)
168167
{
169168
/* Call the internal routine that also handles ControlC */
@@ -182,7 +181,7 @@ ULONG
182181
NTAPI
183182
vDbgPrintEx(IN ULONG ComponentId,
184183
IN ULONG Level,
185-
IN LPCSTR Format,
184+
IN PCCH Format,
186185
IN va_list ap)
187186
{
188187
/* Call the internal routine that also handles ControlC */
@@ -202,19 +201,19 @@ __cdecl
202201
DbgPrint(PCCH Format,
203202
...)
204203
{
205-
ULONG n;
204+
ULONG Status;
206205
va_list ap;
207206

208207
/* Call the internal routine that also handles ControlC */
209208
va_start(ap, Format);
210-
n = vDbgPrintExWithPrefixInternal("",
211-
-1,
212-
DPFLTR_ERROR_LEVEL,
213-
Format,
214-
ap,
215-
TRUE);
209+
Status = vDbgPrintExWithPrefixInternal("",
210+
-1,
211+
DPFLTR_ERROR_LEVEL,
212+
Format,
213+
ap,
214+
TRUE);
216215
va_end(ap);
217-
return n;
216+
return Status;
218217
}
219218

220219
/*
@@ -227,42 +226,42 @@ DbgPrintEx(IN ULONG ComponentId,
227226
IN PCCH Format,
228227
...)
229228
{
230-
ULONG n;
229+
ULONG Status;
231230
va_list ap;
232231

233232
/* Call the internal routine that also handles ControlC */
234233
va_start(ap, Format);
235-
n = vDbgPrintExWithPrefixInternal("",
236-
ComponentId,
237-
Level,
238-
Format,
239-
ap,
240-
TRUE);
234+
Status = vDbgPrintExWithPrefixInternal("",
235+
ComponentId,
236+
Level,
237+
Format,
238+
ap,
239+
TRUE);
241240
va_end(ap);
242-
return n;
241+
return Status;
243242
}
244243

245244
/*
246245
* @implemented
247246
*/
248247
ULONG
249248
__cdecl
250-
DbgPrintReturnControlC(PCH Format,
249+
DbgPrintReturnControlC(PCCH Format,
251250
...)
252251
{
253-
ULONG n;
252+
ULONG Status;
254253
va_list ap;
255254

256255
/* Call the internal routine that also handles ControlC */
257256
va_start(ap, Format);
258-
n = vDbgPrintExWithPrefixInternal("",
259-
-1,
260-
DPFLTR_ERROR_LEVEL,
261-
Format,
262-
ap,
263-
FALSE);
257+
Status = vDbgPrintExWithPrefixInternal("",
258+
-1,
259+
DPFLTR_ERROR_LEVEL,
260+
Format,
261+
ap,
262+
FALSE);
264263
va_end(ap);
265-
return n;
264+
return Status;
266265
}
267266

268267
/*
@@ -274,7 +273,7 @@ DbgPrompt(IN PCCH Prompt,
274273
OUT PCH Response,
275274
IN ULONG MaximumResponseLength)
276275
{
277-
CSTRING Output;
276+
STRING Output;
278277
STRING Input;
279278

280279
/* Setup the input string */
@@ -283,7 +282,7 @@ DbgPrompt(IN PCCH Prompt,
283282

284283
/* Setup the output string */
285284
Output.Length = strlen(Prompt);
286-
Output.Buffer = Prompt;
285+
Output.Buffer = (PCH)Prompt;
287286

288287
/* Call the system service */
289288
return DebugPrompt(&Output, &Input);
@@ -319,7 +318,7 @@ DbgSetDebugFilterState(IN ULONG ComponentId,
319318
*/
320319
VOID
321320
NTAPI
322-
DbgLoadImageSymbols(IN PANSI_STRING Name,
321+
DbgLoadImageSymbols(IN PSTRING Name,
323322
IN PVOID Base,
324323
IN ULONG_PTR ProcessId)
325324
{
@@ -328,7 +327,7 @@ DbgLoadImageSymbols(IN PANSI_STRING Name,
328327

329328
/* Setup the symbol data */
330329
SymbolInfo.BaseOfDll = Base;
331-
SymbolInfo.ProcessId = (ULONG)ProcessId;
330+
SymbolInfo.ProcessId = ProcessId;
332331

333332
/* Get NT Headers */
334333
NtHeader = RtlImageNtHeader(Base);
@@ -353,15 +352,15 @@ DbgLoadImageSymbols(IN PANSI_STRING Name,
353352
*/
354353
VOID
355354
NTAPI
356-
DbgUnLoadImageSymbols(IN PANSI_STRING Name,
355+
DbgUnLoadImageSymbols(IN PSTRING Name,
357356
IN PVOID Base,
358357
IN ULONG_PTR ProcessId)
359358
{
360359
KD_SYMBOLS_INFO SymbolInfo;
361360

362361
/* Setup the symbol data */
363362
SymbolInfo.BaseOfDll = Base;
364-
SymbolInfo.ProcessId = (ULONG)ProcessId;
363+
SymbolInfo.ProcessId = ProcessId;
365364
SymbolInfo.CheckSum = SymbolInfo.SizeOfImage = 0;
366365

367366
/* Load the symbols */

0 commit comments

Comments
 (0)