Author: ion
Date: Tue Feb 20 04:13:22 2007
New Revision: 25849
URL:
http://svn.reactos.org/svn/reactos?rev=25849&view=rev
Log:
- Add a bunch of hacks to KdpReadVirtualMemory to make it work for now.
- Fix bugs in KdpGetVersion, KdpReadVirtualMemory.
- Implement KdpReadControlSpace.
- Fix setting kernel range address instead of kernel image load address.
- WinDBG is slowly trying to talk with us. Now it wants to restore breakpoints since it
thinks this is the same machine I was debugging last night.
Modified:
branches/alex-kd-branch/reactos/include/psdk/wdbgexts.h
branches/alex-kd-branch/reactos/ntoskrnl/kd64/kdapi.c
branches/alex-kd-branch/reactos/ntoskrnl/kd64/kddata.c
branches/alex-kd-branch/reactos/ntoskrnl/kd64/kdinit.c
Modified: branches/alex-kd-branch/reactos/include/psdk/wdbgexts.h
URL:
http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/include/…
==============================================================================
--- branches/alex-kd-branch/reactos/include/psdk/wdbgexts.h (original)
+++ branches/alex-kd-branch/reactos/include/psdk/wdbgexts.h Tue Feb 20 04:13:22 2007
@@ -20,7 +20,7 @@
#define DBGKD_VERS_FLAG_HSS 0x0010
#define DBGKD_VERS_FLAG_PARTITIONS 0x0020
-#define KDBG_TAG TAG('G', 'B',
'D', 'K')
+#define KDBG_TAG TAG('K', 'D',
'B', 'G')
typedef struct _DBGKD_GET_VERSION64
{
Modified: branches/alex-kd-branch/reactos/ntoskrnl/kd64/kdapi.c
URL:
http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/ntoskrnl…
==============================================================================
--- branches/alex-kd-branch/reactos/ntoskrnl/kd64/kdapi.c (original)
+++ branches/alex-kd-branch/reactos/ntoskrnl/kd64/kdapi.c Tue Feb 20 04:13:22 2007
@@ -104,7 +104,7 @@
STRING Header;
/* Fill out the header */
- Header.Length = sizeof(DBGKD_GET_VERSION64);
+ Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
/* Get the version block */
@@ -121,6 +121,9 @@
&KdpContext);
}
+
+BOOLEAN VirtCalled = FALSE;
+
VOID
NTAPI
KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State,
@@ -129,6 +132,7 @@
{
STRING Header;
ULONG Length = State->u.ReadMemory.TransferCount;
+ NTSTATUS Status = STATUS_SUCCESS;
/* Validate length */
if (Length > (PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64)))
@@ -137,18 +141,38 @@
Length = PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64);
}
- /* Copy data */
- RtlCopyMemory(Data->Buffer,
- (PVOID)(ULONG_PTR)State->u.ReadMemory.TargetBaseAddress,
- Length);
+#if 0
+ if (!MmIsAddressValid((PVOID)(ULONG_PTR)State->u.ReadMemory.TargetBaseAddress))
+ {
+ Ke386SetCr2(State->u.ReadMemory.TargetBaseAddress);
+ while (TRUE);
+ }
+#endif
+
+ if ((ULONG_PTR)State->u.ReadMemory.TargetBaseAddress < KSEG0_BASE)
+ {
+ Length = 0;
+ Status = STATUS_UNSUCCESSFUL;
+ }
+ else if ((ULONG_PTR)State->u.ReadMemory.TargetBaseAddress >=
(ULONG_PTR)SharedUserData)
+ {
+ Length = 0;
+ Status = STATUS_UNSUCCESSFUL;
+ }
+ else
+ {
+ RtlCopyMemory(Data->Buffer,
+ (PVOID)(ULONG_PTR)State->u.ReadMemory.TargetBaseAddress,
+ Length);
+ }
+
+ /* Fill out the header */
Data->Length = Length;
-
- /* Fill out the header */
- Header.Length = sizeof(DBGKD_GET_VERSION64);
+ Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
/* Fill out the state */
- State->ReturnStatus = STATUS_SUCCESS;
+ State->ReturnStatus = Status;
State->u.ReadMemory.ActualBytesRead = Length;
/* Send the packet */
@@ -158,6 +182,66 @@
&KdpContext);
}
+VOID
+NTAPI
+KdpReadControlSpace(IN PDBGKD_MANIPULATE_STATE64 State,
+ IN PSTRING Data,
+ IN PCONTEXT Context)
+{
+ PDBGKD_READ_MEMORY64 ReadMemory = &State->u.ReadMemory;
+ STRING Header;
+ ULONG Length, RealLength;
+ PVOID ControlStart;
+
+ /* Setup the header */
+ Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
+ Header.Buffer = (PCHAR)State;
+ ASSERT(Data->Length == 0);
+
+ /* Check the length requested */
+ Length = ReadMemory->TransferCount;
+ if (Length > (PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64)))
+ {
+ /* Use maximum allowed */
+ Length = PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64);
+ }
+
+ /* Make sure that this is a valid request */
+ if (((ULONG)ReadMemory->TargetBaseAddress < sizeof(KPROCESSOR_STATE))
&&
+ (State->Processor < KeNumberProcessors))
+ {
+ /* Get the actual length */
+ RealLength = sizeof(KPROCESSOR_STATE) -
+ (ULONG_PTR)ReadMemory->TargetBaseAddress;
+ if (RealLength < Length) Length = RealLength;
+
+ /* Set the proper address */
+ ControlStart = (PVOID)((ULONG_PTR)ReadMemory->TargetBaseAddress +
+
(ULONG_PTR)&KiProcessorBlock[State->Processor]->
+ ProcessorState);
+
+ /* Copy the memory */
+ RtlCopyMemory(Data->Buffer, ControlStart, Length);
+ Data->Length = Length;
+
+ /* Finish up */
+ State->ReturnStatus = STATUS_SUCCESS;
+ ReadMemory->ActualBytesRead = Data->Length;
+ }
+ else
+ {
+ /* Invalid request */
+ Data->Length = 0;
+ State->ReturnStatus = STATUS_UNSUCCESSFUL;
+ ReadMemory->ActualBytesRead = 0;
+ }
+
+ /* Send the reply */
+ KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
+ &Header,
+ Data,
+ &KdpContext);
+}
KCONTINUE_STATUS
NTAPI
@@ -209,6 +293,7 @@
/* Read virtual memory */
KdpReadVirtualMemory(&ManipulateState, &Data, Context);
+ VirtCalled = TRUE;
break;
case DbgKdWriteVirtualMemoryApi:
@@ -255,9 +340,8 @@
case DbgKdReadControlSpaceApi:
- /* FIXME: TODO */
- Ke386SetCr2(DbgKdReadControlSpaceApi);
- while (TRUE);
+ /* Read control space */
+ KdpReadControlSpace(&ManipulateState, &Data, Context);
break;
case DbgKdWriteControlSpaceApi:
Modified: branches/alex-kd-branch/reactos/ntoskrnl/kd64/kddata.c
URL:
http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/ntoskrnl…
==============================================================================
--- branches/alex-kd-branch/reactos/ntoskrnl/kd64/kddata.c (original)
+++ branches/alex-kd-branch/reactos/ntoskrnl/kd64/kddata.c Tue Feb 20 04:13:22 2007
@@ -15,27 +15,6 @@
VOID NTAPI RtlpBreakWithStatusInstruction(VOID);
/* GLOBALS *******************************************************************/
-
-//
-// Debugger Version Block
-//
-DBGKD_GET_VERSION64 KdVersionBlock =
-{
- 0,
- 0,
- DBGKD_64BIT_PROTOCOL_VERSION2,
- KD_SECONDARY_VERSION_DEFAULT,
- DBGKD_VERS_FLAG_DATA,
- IMAGE_FILE_MACHINE_I386,
- PACKET_TYPE_MAX,
- 0,
- 0,
- DBGKD_SIMULATION_NONE,
- {0},
- 0,
- 0,
- 0
-};
//
// Debugger State
@@ -320,6 +299,27 @@
//
LIST_ENTRY KdpDebuggerDataListHead;
KSPIN_LOCK KdpDataSpinLock;
+
+//
+// Debugger Version and Data Block
+//
+DBGKD_GET_VERSION64 KdVersionBlock =
+{
+ 0,
+ 0,
+ DBGKD_64BIT_PROTOCOL_VERSION2,
+ KD_SECONDARY_VERSION_DEFAULT,
+ DBGKD_VERS_FLAG_DATA,
+ IMAGE_FILE_MACHINE_I386,
+ PACKET_TYPE_MAX,
+ 0,
+ 0,
+ DBGKD_SIMULATION_NONE,
+ {0},
+ 0,
+ 0,
+ 0
+};
KDDEBUGGER_DATA64 KdDebuggerDataBlock =
{
{{0}},
Modified: branches/alex-kd-branch/reactos/ntoskrnl/kd64/kdinit.c
URL:
http://svn.reactos.org/svn/reactos/branches/alex-kd-branch/reactos/ntoskrnl…
==============================================================================
--- branches/alex-kd-branch/reactos/ntoskrnl/kd64/kdinit.c (original)
+++ branches/alex-kd-branch/reactos/ntoskrnl/kd64/kdinit.c Tue Feb 20 04:13:22 2007
@@ -132,7 +132,8 @@
InLoadOrderLinks);
/* Save the Kernel Base */
- KdVersionBlock.KernBase =(ULONGLONG)(LONG_PTR)LdrEntry->DllBase;
+ LdrEntry->DllBase = (PVOID)PsNtosImageBase;
+ KdVersionBlock.KernBase = (ULONGLONG)(LONG_PTR)LdrEntry->DllBase;
/* Check if we have a command line */
CommandLine = LoaderBlock->LoadOptions;
@@ -179,7 +180,7 @@
}
/* Set the Kernel Base in the Data Block */
- KdDebuggerDataBlock.KernBase = (ULONG_PTR)PsNtosImageBase;
+ KdDebuggerDataBlock.KernBase = (ULONGLONG)(LONG_PTR)KdVersionBlock.KernBase;
/* Initialize the debugger if requested */
if ((EnableKd) && (NT_SUCCESS(KdDebuggerInitialize0(LoaderBlock))))