mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 17:52:56 +00:00
- 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. svn path=/branches/alex-kd-branch/; revision=25849
This commit is contained in:
parent
f42e752565
commit
24f9e136e6
4 changed files with 120 additions and 35 deletions
|
@ -20,7 +20,7 @@ enum
|
||||||
#define DBGKD_VERS_FLAG_HSS 0x0010
|
#define DBGKD_VERS_FLAG_HSS 0x0010
|
||||||
#define DBGKD_VERS_FLAG_PARTITIONS 0x0020
|
#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
|
typedef struct _DBGKD_GET_VERSION64
|
||||||
{
|
{
|
||||||
|
|
|
@ -104,7 +104,7 @@ KdpGetVersion(IN PDBGKD_MANIPULATE_STATE64 State)
|
||||||
STRING Header;
|
STRING Header;
|
||||||
|
|
||||||
/* Fill out the header */
|
/* Fill out the header */
|
||||||
Header.Length = sizeof(DBGKD_GET_VERSION64);
|
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
|
||||||
Header.Buffer = (PCHAR)State;
|
Header.Buffer = (PCHAR)State;
|
||||||
|
|
||||||
/* Get the version block */
|
/* Get the version block */
|
||||||
|
@ -121,6 +121,9 @@ KdpGetVersion(IN PDBGKD_MANIPULATE_STATE64 State)
|
||||||
&KdpContext);
|
&KdpContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOLEAN VirtCalled = FALSE;
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State,
|
KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State,
|
||||||
|
@ -129,6 +132,7 @@ KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State,
|
||||||
{
|
{
|
||||||
STRING Header;
|
STRING Header;
|
||||||
ULONG Length = State->u.ReadMemory.TransferCount;
|
ULONG Length = State->u.ReadMemory.TransferCount;
|
||||||
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
/* Validate length */
|
/* Validate length */
|
||||||
if (Length > (PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64)))
|
if (Length > (PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64)))
|
||||||
|
@ -137,18 +141,38 @@ KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State,
|
||||||
Length = PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64);
|
Length = PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy data */
|
#if 0
|
||||||
RtlCopyMemory(Data->Buffer,
|
if (!MmIsAddressValid((PVOID)(ULONG_PTR)State->u.ReadMemory.TargetBaseAddress))
|
||||||
(PVOID)(ULONG_PTR)State->u.ReadMemory.TargetBaseAddress,
|
{
|
||||||
Length);
|
Ke386SetCr2(State->u.ReadMemory.TargetBaseAddress);
|
||||||
Data->Length = Length;
|
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 */
|
/* Fill out the header */
|
||||||
Header.Length = sizeof(DBGKD_GET_VERSION64);
|
Data->Length = Length;
|
||||||
|
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
|
||||||
Header.Buffer = (PCHAR)State;
|
Header.Buffer = (PCHAR)State;
|
||||||
|
|
||||||
/* Fill out the state */
|
/* Fill out the state */
|
||||||
State->ReturnStatus = STATUS_SUCCESS;
|
State->ReturnStatus = Status;
|
||||||
State->u.ReadMemory.ActualBytesRead = Length;
|
State->u.ReadMemory.ActualBytesRead = Length;
|
||||||
|
|
||||||
/* Send the packet */
|
/* Send the packet */
|
||||||
|
@ -158,6 +182,66 @@ KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State,
|
||||||
&KdpContext);
|
&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
|
KCONTINUE_STATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
|
@ -209,6 +293,7 @@ SendPacket:
|
||||||
|
|
||||||
/* Read virtual memory */
|
/* Read virtual memory */
|
||||||
KdpReadVirtualMemory(&ManipulateState, &Data, Context);
|
KdpReadVirtualMemory(&ManipulateState, &Data, Context);
|
||||||
|
VirtCalled = TRUE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DbgKdWriteVirtualMemoryApi:
|
case DbgKdWriteVirtualMemoryApi:
|
||||||
|
@ -255,9 +340,8 @@ SendPacket:
|
||||||
|
|
||||||
case DbgKdReadControlSpaceApi:
|
case DbgKdReadControlSpaceApi:
|
||||||
|
|
||||||
/* FIXME: TODO */
|
/* Read control space */
|
||||||
Ke386SetCr2(DbgKdReadControlSpaceApi);
|
KdpReadControlSpace(&ManipulateState, &Data, Context);
|
||||||
while (TRUE);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DbgKdWriteControlSpaceApi:
|
case DbgKdWriteControlSpaceApi:
|
||||||
|
|
|
@ -16,27 +16,6 @@ VOID NTAPI RtlpBreakWithStatusInstruction(VOID);
|
||||||
|
|
||||||
/* GLOBALS *******************************************************************/
|
/* 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
|
// Debugger State
|
||||||
//
|
//
|
||||||
|
@ -320,6 +299,27 @@ ULONG KdComponentTableSize = sizeof(KdComponentTable);
|
||||||
//
|
//
|
||||||
LIST_ENTRY KdpDebuggerDataListHead;
|
LIST_ENTRY KdpDebuggerDataListHead;
|
||||||
KSPIN_LOCK KdpDataSpinLock;
|
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 =
|
KDDEBUGGER_DATA64 KdDebuggerDataBlock =
|
||||||
{
|
{
|
||||||
{{0}},
|
{{0}},
|
||||||
|
|
|
@ -132,7 +132,8 @@ KdInitSystem(IN ULONG BootPhase,
|
||||||
InLoadOrderLinks);
|
InLoadOrderLinks);
|
||||||
|
|
||||||
/* Save the Kernel Base */
|
/* 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 */
|
/* Check if we have a command line */
|
||||||
CommandLine = LoaderBlock->LoadOptions;
|
CommandLine = LoaderBlock->LoadOptions;
|
||||||
|
@ -179,7 +180,7 @@ KdInitSystem(IN ULONG BootPhase,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the Kernel Base in the Data Block */
|
/* 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 */
|
/* Initialize the debugger if requested */
|
||||||
if ((EnableKd) && (NT_SUCCESS(KdDebuggerInitialize0(LoaderBlock))))
|
if ((EnableKd) && (NT_SUCCESS(KdDebuggerInitialize0(LoaderBlock))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue