📄 kdapi.c
字号:
hr = Hdstub.pfnCallClientIoctl (OSAXST1_NAME, OSAXST1_IOCTL_SET_THREADCTX, (DWORD) pOsAxsCmd->u.Addr,
(DWORD) AdditionalData->Buffer, (DWORD)AdditionalData->Length, 0);
AdditionalData->Length = 0;
if (FAILED (hr))
{
DEBUGGERMSG(KDZONE_ALERT, (TEXT(" KdpCallOsAccess: Failed to set ThreadCtx info in OsAxsT1, hr = 0x%08X\r\n"),hr));
}
}
break;
case OSAXS_API_GET_MOD_O32_LITE:
{
DWORD dwSize = (DWORD) AdditionalData->MaximumLength;
hr = Hdstub.pfnCallClientIoctl (OSAXST1_NAME, OSAXST1_IOCTL_GET_MODULE_O32_DATA,
(DWORD) pOsAxsCmd->u.ModO32.in_hmod,
(DWORD) &pOsAxsCmd->u.ModO32.out_cO32Lite,
(DWORD) AdditionalData->Buffer,
(DWORD) &dwSize);
if (SUCCEEDED (hr))
{
AdditionalData->Length = (USHORT) dwSize;
}
else
{
DEBUGGERMSG (KDZONE_ALERT, (TEXT(" KdpCallOsAccess: Failed to call OsAxsT1\r\n")));
}
break;
}
#if defined(x86)
case OSAXS_API_GET_EXCEPTION_REGISTRATION:
{
DEBUGGERMSG(KDZONE_API, (L" KdpCallOsAccess: OSAXST1_IOCTL_GET_EXCEPTION_REGISTRATION\r\n"));
hr = Hdstub.pfnCallClientIoctl (OSAXST1_NAME, OSAXST1_IOCTL_GET_EXCEPTION_REGISTRATION, (DWORD) &pOsAxsCmd->u.ExReg, 0, 0, 0);
AdditionalData->Length = 0;
break;
}
#endif
default:
DEBUGGERMSG (KDZONE_API, (L" KdpCallOsAccess: Invalid API Number %d\r\n", pOsAxsCmd->dwApi));
hr = OSAXS_E_APINUMBER;
break;
}
}
else
{
DEBUGGERMSG(KDZONE_ALERT, (L" KdpCallOsAccess: Protocol mismatch\r\n"));
if (pOsAxsCmd->dwVersion < OSAXS_PROTOCOL_LATEST_VERSION)
{
g_dwOsAxsProtocolVersion = pOsAxsCmd->dwVersion;
goto HandleRequest;
}
else
{
pOsAxsCmd->dwVersion = OSAXS_PROTOCOL_LATEST_VERSION;
hr = OSAXS_E_PROTOCOLVERSION;
}
}
/* Manufacture response */
pOsAxsCmd->hr = hr;
KdpSendPacket(PACKET_TYPE_KD_CMD, GUID_KDDBGCLIENT_OSAXS, &ResponseHeader, AdditionalData);
DEBUGGERMSG (KDZONE_API, (L"--KdpCallOsAccess\r\n"));
}
VOID
KdpReadVirtualMemory(
IN DBGKD_COMMAND *pdbgkdCmdPacket,
IN PSTRING AdditionalData
)
/*++
Routine Description:
This function is called in response of a read virtual memory
command message. Its function is to read virtual memory
and return.
Arguments:
pdbgkdCmdPacket - Supplies the command message.
AdditionalData - Supplies any additional data for the message.
Return Value:
None.
--*/
{
DBGKD_READ_MEMORY *a = &pdbgkdCmdPacket->u.ReadMemory;
ULONG ulLengthAtempted;
STRING MessageHeader;
MessageHeader.Length = sizeof (*pdbgkdCmdPacket);
MessageHeader.Buffer = (PCHAR) pdbgkdCmdPacket;
// make sure that nothing but a read memory message was transmitted
KD_ASSERT (AdditionalData->Length == 0);
// Trim transfer count to fit in a single message
if (a->dwTransferCount > KDP_MESSAGE_BUFFER_SIZE)
{
ulLengthAtempted = KDP_MESSAGE_BUFFER_SIZE;
}
else
{
ulLengthAtempted = a->dwTransferCount;
}
// Perform the actual memory read, if some locations are not readable, the read will be truncated
AdditionalData->Length = (USHORT) KdpMoveMemory(
AdditionalData->Buffer,
(void *) a->qwTgtAddress,
ulLengthAtempted
);
if (ulLengthAtempted == AdditionalData->Length)
{
pdbgkdCmdPacket->dwReturnStatus = STATUS_SUCCESS;
}
else
{
DEBUGGERMSG( KDZONE_API, (L" KdpReadVirtualMemory: Only read %d of %d bytes starting at 0x%8.8x\r\n", AdditionalData->Length, ulLengthAtempted, a->qwTgtAddress));
pdbgkdCmdPacket->dwReturnStatus = STATUS_UNSUCCESSFUL;
}
// Sanitize (remove SW BP artefacts) the memory block data before sending it back
DEBUGGERMSG (KDZONE_VIRTMEM, (L" KdpReadVirtualMemory: Sanitizing %d bytes starting at 0x%8.8x\r\n", AdditionalData->Length, a->qwTgtAddress));
KdpSanitize (AdditionalData->Buffer, (void *) a->qwTgtAddress, AdditionalData->Length, TRUE);
a->dwActualBytesRead = AdditionalData->Length;
KdpSendKdApiCmdPacket (&MessageHeader, AdditionalData);
}
VOID
KdpWriteVirtualMemory(
IN DBGKD_COMMAND *pdbgkdCmdPacket,
IN PSTRING AdditionalData
)
/*++
Routine Description:
This function is called in response of a write virtual memory
command message. Its function is to write virtual memory
and return.
Arguments:
pdbgkdCmdPacket - Supplies the command message.
AdditionalData - Supplies any additional data for the message.
Return Value:
None.
--*/
{
DBGKD_WRITE_MEMORY *a = &pdbgkdCmdPacket->u.WriteMemory;
ULONG ulLengthWritten;
STRING MessageHeader;
MessageHeader.Length = sizeof (*pdbgkdCmdPacket);
MessageHeader.Buffer = (PCHAR) pdbgkdCmdPacket;
ulLengthWritten = KdpMoveMemory (
(void *) a->qwTgtAddress,
AdditionalData->Buffer,
AdditionalData->Length
);
if (ulLengthWritten == AdditionalData->Length)
{
pdbgkdCmdPacket->dwReturnStatus = STATUS_SUCCESS;
}
else
{
pdbgkdCmdPacket->dwReturnStatus = STATUS_UNSUCCESSFUL;
}
a->dwActualBytesWritten = ulLengthWritten;
KdpSendKdApiCmdPacket (&MessageHeader, NULL);
}
VOID
KdpSetContext(
IN DBGKD_COMMAND *pdbgkdCmdPacket,
IN PSTRING AdditionalData
)
/*++
Routine Description:
This function is called in response of a set context state
manipulation message. Its function is set the current
context.
Arguments:
pdbgkdCmdPacket - Supplies the command message.
AdditionalData - Supplies any additional data for the message.
Return Value:
None.
--*/
{
STRING MessageHeader;
BOOL fOwner = FALSE;
#ifdef ARM
CONCAN_REGS *pConcanRegs = (CONCAN_REGS *)(AdditionalData->Buffer + sizeof (CONTEXT));
#endif
MessageHeader.Length = sizeof(*pdbgkdCmdPacket);
MessageHeader.Buffer = (PCHAR)pdbgkdCmdPacket;
#if defined (ARM)
KD_ASSERT (AdditionalData->Length == (sizeof (CONTEXT) + sizeof (CONCAN_REGS)));
#else
KD_ASSERT(AdditionalData->Length == sizeof(CONTEXT));
#endif
pdbgkdCmdPacket->dwReturnStatus = STATUS_SUCCESS;
memcpy (g_pctxException, AdditionalData->Buffer, sizeof (CONTEXT));
// copy the DSP registers into the thread context
#if defined(SHx) && !defined(SH4) && !defined(SH3e)
// copy over the DSP registers from the thread context
fOwner = (pCurThread == g_CurDSPOwner);
DSPFlushContext();
// if DSPFlushContext updated pCurThread's PSR, keep exception context in sync
if (fOwner) g_pctxException->Psr &= ~SR_DSP_ENABLED;
memcpy (&(pCurThread->ctx.DSR), &(g_pctxException->DSR), sizeof (DWORD) * 13);
#endif
// copy the floating point registers into the thread context
#if defined(SH4)
fOwner = (pCurThread == g_CurFPUOwner);
FPUFlushContext();
// if FPUFlushContext updated pCurThread's PSR, keep exception context in sync
if (fOwner) g_pctxException->Psr |= SR_FPU_DISABLED;
memcpy (&(pCurThread->ctx.Fpscr), &(g_pctxException->Fpscr), sizeof (DWORD) * 34);
#elif defined(MIPS_HAS_FPU)
FPUFlushContext();
pCurThread->ctx.Fsr = g_pctxException->Fsr;
memcpy (&(pCurThread->ctx.FltF0), &(g_pctxException->FltF0), sizeof (FREG_TYPE) * 32);
#elif defined(ARM)
// ARM VFP10 Support
// FPUFlushContext might modify FpExc, but apparently it can't be restored, so we shouldn't bother
// trying update our context with it
FPUFlushContext ();
memcpy (&(pCurThread->ctx.Fpscr), &(g_pctxException->Fpscr), sizeof (DWORD) * 43);
if (DetectConcanCoprocessors ())
{
SetConcanRegisters (pConcanRegs);
}
#endif
KdpSendKdApiCmdPacket (&MessageHeader, NULL);
}
VOID
KdpSetNotifPacket (
IN DBGKD_NOTIF *pdbgNotifPacket,
IN EXCEPTION_RECORD *pExceptionRecord,
IN BOOLEAN SecondChance
)
/*++
Routine Description:
Fill in the Wait_State_Change message record.
Arguments:
pdbgNotifPacket - Supplies pointer to record to fill in
pExceptionRecord - Supplies a pointer to an exception record.
SecondChance - Supplies a boolean value that determines whether this is
the first or second chance for the exception.
Return Value:
None.
--*/
{
memset (pdbgNotifPacket, 0, sizeof (*pdbgNotifPacket)); // zero init
// Set up description of event, including exception record
pdbgNotifPacket->dwNewState = DbgKdExceptionNotif;
pdbgNotifPacket->NbBpAvail.dwNbHwCodeBpAvail = 0; // TODO: Get this from OAL
pdbgNotifPacket->NbBpAvail.dwNbSwCodeBpAvail = BREAKPOINT_TABLE_SIZE - g_nTotalNumDistinctSwCodeBps;
pdbgNotifPacket->NbBpAvail.dwNbHwDataBpAvail = 0; // TODO: Get this from OAL
pdbgNotifPacket->NbBpAvail.dwNbSwDataBpAvail = 0;
pdbgNotifPacket->TgtVerInfo.dwCpuFamily = TARGET_CODE_CPU;
pdbgNotifPacket->TgtVerInfo.dwBuildNumber = VER_PRODUCTBUILD; // TODO: Get the real build
pdbgNotifPacket->TgtVerInfo.wMajorOsVersion = 5;
pdbgNotifPacket->TgtVerInfo.wMinorOsVersion = 0;
pdbgNotifPacket->TgtVerInfo.dwNkCEProcessorType = NkCEProcessorType;
pdbgNotifPacket->TgtVerInfo.dwCpuCapablilityFlags = 0;
if (g_kdKernData.fDSPPresent)
{ // hardware DSP support used
pdbgNotifPacket->TgtVerInfo.dwCpuCapablilityFlags |= DBGKD_VERS_FLAG_DSP;
}
if (g_kdKernData.fFPUPresent)
{ // hardware FPU support used
pdbgNotifPacket->TgtVerInfo.dwCpuCapablilityFlags |= DBGKD_VERS_FLAG_FPU;
}
#if defined (ARM)
if (DetectConcanCoprocessors())
{ // Concan support
pdbgNotifPacket->TgtVerInfo.dwCpuCapablilityFlags |= DBGKD_VERS_FLAG_MULTIMEDIA;
}
#endif
pdbgNotifPacket->dwSubVersionId = KDAPI_PROTOCOL_VERSION;
pdbgNotifPacket->wNumberOfCpus = 1;
if (g_fForceReload)
{
pdbgNotifPacket->dwKdpFlags |= DBGKD_STATE_DID_RESET;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -