mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 17:12:57 +00:00
- Implement KdpSysGetVersion, KdpGetVersion, KdpReadVirtualMemory.
- Fix bugs in KdInitSystem; some 64-bit pointers must be sign-extneded, not zero-extended (thanks Myria!) - Properly read kernel base instead of kernel stack. - Fix compile issue due to incorrect KiBugCheckData definition. - WinDBG reports: "Connected to Windows Vista 16199 x86 compatible target, ptr64 FALSE. Kernel Debugger connection established. (Initial Breakpoint requested)" svn path=/branches/alex-kd-branch/; revision=25846
This commit is contained in:
parent
b9cd3f2d9d
commit
1654674e55
4 changed files with 89 additions and 17 deletions
|
@ -151,7 +151,7 @@ extern UCHAR KiDebugRegisterTrapOffsets[9];
|
||||||
extern UCHAR KiDebugRegisterContextOffsets[9];
|
extern UCHAR KiDebugRegisterContextOffsets[9];
|
||||||
extern ULONG KiFreezeFlag;
|
extern ULONG KiFreezeFlag;
|
||||||
extern ULONG KeTimeIncrement;
|
extern ULONG KeTimeIncrement;
|
||||||
extern PVOID KiBugCheckData;
|
extern ULONG_PTR KiBugCheckData[5];
|
||||||
|
|
||||||
/* MACROS *************************************************************************/
|
/* MACROS *************************************************************************/
|
||||||
|
|
||||||
|
|
|
@ -89,12 +89,82 @@ KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOLEAN
|
VOID
|
||||||
|
NTAPI
|
||||||
|
KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)
|
||||||
|
{
|
||||||
|
/* Copy the version block */
|
||||||
|
RtlCopyMemory(Version, &KdVersionBlock, sizeof(DBGKD_GET_VERSION64));
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID
|
||||||
|
NTAPI
|
||||||
|
KdpGetVersion(IN PDBGKD_MANIPULATE_STATE64 State)
|
||||||
|
{
|
||||||
|
STRING Header;
|
||||||
|
|
||||||
|
/* Fill out the header */
|
||||||
|
Header.Length = sizeof(DBGKD_GET_VERSION64);
|
||||||
|
Header.Buffer = (PCHAR)State;
|
||||||
|
|
||||||
|
/* Get the version block */
|
||||||
|
KdpSysGetVersion(&State->u.GetVersion64);
|
||||||
|
|
||||||
|
/* Fill out the state */
|
||||||
|
State->ApiNumber = DbgKdGetVersionApi;
|
||||||
|
State->ReturnStatus = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
/* Send the packet */
|
||||||
|
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
|
||||||
|
&Header,
|
||||||
|
NULL,
|
||||||
|
&KdpContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID
|
||||||
|
NTAPI
|
||||||
|
KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State,
|
||||||
|
IN PSTRING Data,
|
||||||
|
IN PCONTEXT Context)
|
||||||
|
{
|
||||||
|
STRING Header;
|
||||||
|
ULONG Length = State->u.ReadMemory.TransferCount;
|
||||||
|
|
||||||
|
/* Validate length */
|
||||||
|
if (Length > (PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64)))
|
||||||
|
{
|
||||||
|
/* Overflow, set it to maximum possible */
|
||||||
|
Length = PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy data */
|
||||||
|
RtlCopyMemory(Data->Buffer,
|
||||||
|
(PVOID)(ULONG_PTR)State->u.ReadMemory.TargetBaseAddress,
|
||||||
|
Length);
|
||||||
|
Data->Length = Length;
|
||||||
|
|
||||||
|
/* Fill out the header */
|
||||||
|
Header.Length = sizeof(DBGKD_GET_VERSION64);
|
||||||
|
Header.Buffer = (PCHAR)State;
|
||||||
|
|
||||||
|
/* Fill out the state */
|
||||||
|
State->ReturnStatus = STATUS_SUCCESS;
|
||||||
|
State->u.ReadMemory.ActualBytesRead = Length;
|
||||||
|
|
||||||
|
/* Send the packet */
|
||||||
|
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
|
||||||
|
&Header,
|
||||||
|
Data,
|
||||||
|
&KdpContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KCONTINUE_STATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
KdpSendWaitContinue(IN ULONG PacketType,
|
KdpSendWaitContinue(IN ULONG PacketType,
|
||||||
IN PSTRING SendHeader,
|
IN PSTRING SendHeader,
|
||||||
IN PSTRING SendData OPTIONAL,
|
IN PSTRING SendData OPTIONAL,
|
||||||
IN OUT PCONTEXT ContextRecord)
|
IN OUT PCONTEXT Context)
|
||||||
{
|
{
|
||||||
STRING Data, Header;
|
STRING Data, Header;
|
||||||
DBGKD_MANIPULATE_STATE64 ManipulateState;
|
DBGKD_MANIPULATE_STATE64 ManipulateState;
|
||||||
|
@ -113,7 +183,7 @@ SendPacket:
|
||||||
KdSendPacket(PacketType, SendHeader, SendData, &KdpContext);
|
KdSendPacket(PacketType, SendHeader, SendData, &KdpContext);
|
||||||
|
|
||||||
/* If the debugger isn't present anymore, just return success */
|
/* If the debugger isn't present anymore, just return success */
|
||||||
if (KdDebuggerNotPresent) return TRUE;
|
if (KdDebuggerNotPresent) return ContinueSuccess;
|
||||||
|
|
||||||
/* Main processing Loop */
|
/* Main processing Loop */
|
||||||
for (;;)
|
for (;;)
|
||||||
|
@ -122,7 +192,6 @@ SendPacket:
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Wait to get a reply to our packet */
|
/* Wait to get a reply to our packet */
|
||||||
ManipulateState.ApiNumber = 0xFFFFFFFF;
|
|
||||||
RecvCode = KdReceivePacket(PACKET_TYPE_KD_STATE_MANIPULATE,
|
RecvCode = KdReceivePacket(PACKET_TYPE_KD_STATE_MANIPULATE,
|
||||||
&Header,
|
&Header,
|
||||||
&Data,
|
&Data,
|
||||||
|
@ -138,9 +207,8 @@ SendPacket:
|
||||||
{
|
{
|
||||||
case DbgKdReadVirtualMemoryApi:
|
case DbgKdReadVirtualMemoryApi:
|
||||||
|
|
||||||
/* FIXME: TODO */
|
/* Read virtual memory */
|
||||||
Ke386SetCr2(DbgKdReadVirtualMemoryApi);
|
KdpReadVirtualMemory(&ManipulateState, &Data, Context);
|
||||||
while (TRUE);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DbgKdWriteVirtualMemoryApi:
|
case DbgKdWriteVirtualMemoryApi:
|
||||||
|
@ -292,9 +360,8 @@ SendPacket:
|
||||||
|
|
||||||
case DbgKdGetVersionApi:
|
case DbgKdGetVersionApi:
|
||||||
|
|
||||||
/* FIXME: TODO */
|
/* Get version data */
|
||||||
Ke386SetCr2(DbgKdGetVersionApi);
|
KdpGetVersion(&ManipulateState);
|
||||||
while (TRUE);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DbgKdWriteBreakPointExApi:
|
case DbgKdWriteBreakPointExApi:
|
||||||
|
|
|
@ -340,7 +340,7 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
|
||||||
{0}, // ExpNumberOfPagedPools
|
{0}, // ExpNumberOfPagedPools
|
||||||
{PtrToUlong(&KeTimeIncrement)},
|
{PtrToUlong(&KeTimeIncrement)},
|
||||||
{PtrToUlong(&KeBugcheckCallbackListHead)},
|
{PtrToUlong(&KeBugcheckCallbackListHead)},
|
||||||
{PtrToUlong(&KiBugCheckData)},
|
{PtrToUlong(KiBugCheckData)},
|
||||||
{PtrToUlong(&IopErrorLogListHead)},
|
{PtrToUlong(&IopErrorLogListHead)},
|
||||||
{PtrToUlong(&ObpRootDirectoryObject)},
|
{PtrToUlong(&ObpRootDirectoryObject)},
|
||||||
{PtrToUlong(&ObpTypeObjectType)},
|
{PtrToUlong(&ObpTypeObjectType)},
|
||||||
|
|
|
@ -109,8 +109,8 @@ KdInitSystem(IN ULONG BootPhase,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Save Pointers to Loaded Module List and Debugger Data */
|
/* Save Pointers to Loaded Module List and Debugger Data */
|
||||||
KdVersionBlock.PsLoadedModuleList = (ULONG64)&PsLoadedModuleList;
|
KdVersionBlock.PsLoadedModuleList = (ULONGLONG)(LONG_PTR)&PsLoadedModuleList;
|
||||||
KdVersionBlock.DebuggerDataList = (ULONG64)&KdpDebuggerDataListHead;
|
KdVersionBlock.DebuggerDataList = (ULONGLONG)(LONG_PTR)&KdpDebuggerDataListHead;
|
||||||
|
|
||||||
/* Set protocol limits */
|
/* Set protocol limits */
|
||||||
KdVersionBlock.MaxStateChange = DbgKdMaximumStateChange -
|
KdVersionBlock.MaxStateChange = DbgKdMaximumStateChange -
|
||||||
|
@ -126,8 +126,13 @@ KdInitSystem(IN ULONG BootPhase,
|
||||||
/* Check if we have a loader block */
|
/* Check if we have a loader block */
|
||||||
if (LoaderBlock)
|
if (LoaderBlock)
|
||||||
{
|
{
|
||||||
|
/* Get the image entry */
|
||||||
|
LdrEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink,
|
||||||
|
LDR_DATA_TABLE_ENTRY,
|
||||||
|
InLoadOrderLinks);
|
||||||
|
|
||||||
/* Save the Kernel Base */
|
/* Save the Kernel Base */
|
||||||
KdVersionBlock.KernBase = (ULONG64)LoaderBlock->KernelStack;
|
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;
|
||||||
|
@ -167,14 +172,14 @@ KdInitSystem(IN ULONG BootPhase,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Called from a bugcheck...Save the Kernel Base */
|
/* Called from a bugcheck...Save the Kernel Base */
|
||||||
KdVersionBlock.KernBase = PsNtosImageBase;
|
KdVersionBlock.KernBase = (ULONGLONG)(LONG_PTR)PsNtosImageBase;
|
||||||
|
|
||||||
/* Unconditionally enable KD */
|
/* Unconditionally enable KD */
|
||||||
EnableKd = TRUE;
|
EnableKd = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the Kernel Base in the Data Block */
|
/* Set the Kernel Base in the Data Block */
|
||||||
KdDebuggerDataBlock.KernBase = KdVersionBlock.KernBase;
|
KdDebuggerDataBlock.KernBase = (ULONG_PTR)PsNtosImageBase;
|
||||||
|
|
||||||
/* 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