📄 mdsched.c
字号:
er.ExceptionInformation[0] = *(ULONG *)pctx->Fir;
er.ExceptionCode = STATUS_BREAKPOINT;
if (er.ExceptionInformation[0] == MIPS32_BREAK (DIVIDE_BY_ZERO_BREAKPOINT))
er.ExceptionCode = STATUS_INTEGER_DIVIDE_BY_ZERO;
else if (er.ExceptionInformation[0] == MIPS32_BREAK (MULTIPLY_OVERFLOW_BREAKPOINT) ||
er.ExceptionInformation[0] == MIPS32_BREAK (DIVIDE_OVERFLOW_BREAKPOINT))
er.ExceptionCode = STATUS_INTEGER_OVERFLOW;
else if (er.ExceptionInformation[0] == MIPS32_BREAK (BREAKIN_BREAKPOINT))
pctx->Fir += 4;
}
break;
case 10: // Reserved instruction
er.ExceptionCode = STATUS_ILLEGAL_INSTRUCTION;
break;
case 12: // arithmetic overflow
er.ExceptionCode = STATUS_INTEGER_OVERFLOW;
break;
#ifdef MIPS_HAS_FPU
case 11:
KCall((PKFN)SwitchFPUOwner,pctx);
pth->pcstkTop = (PCALLSTACK)(pexi->linkage & ~1);
goto continueExecution;
case 15: {
DWORD code;
code = GetAndClearFloatCode();
DEBUGMSG(ZONE_SEH,(L"FPU Exception register: %8.8lx\r\n",code));
if (code & 0x10000)
er.ExceptionCode = STATUS_FLOAT_INVALID_OPERATION;
else if (code & 0x08000)
er.ExceptionCode = STATUS_FLOAT_DIVIDE_BY_ZERO;
else if (code & 0x04000)
er.ExceptionCode = STATUS_FLOAT_OVERFLOW;
else if (code & 0x02000)
er.ExceptionCode = STATUS_FLOAT_UNDERFLOW;
else if (code & 0x01000)
er.ExceptionCode = STATUS_FLOAT_INEXACT_RESULT;
else
er.ExceptionCode = STATUS_FLOAT_DENORMAL_OPERAND;
FPUFlushContext();
memcpy(&pctx->FltF0,&pth->ctx.FltF0,sizeof(FREG_TYPE)*32);
pctx->Fsr = pth->ctx.Fsr;
#if !defined(_M_MRX000) || (_M_MRX000 < 5000)
// shouldn't get Psr from pth->ctx, since we have correct Psr in pctx already
//pctx->Psr = pth->ctx.Psr;
#endif
if (HandleHWFloatException(&er,pctx,cause)) {
// flush FPU context and set FPU owner to zero in case exception handler use any float-point operation.
FPUFlushContext();
memcpy(&pth->ctx.FltF0,&pctx->FltF0,sizeof(FREG_TYPE)*32);
pth->ctx.Fsr = pctx->Fsr;
pth->pcstkTop = (PCALLSTACK)(pexi->linkage & ~1);
goto continueExecution;
}
break;
}
#else
case 11:
er.ExceptionCode = STATUS_PRIVILEGED_INSTRUCTION;
break;
#endif
case 23: // watch breakpoint
er.ExceptionCode = STATUS_BREAKPOINT;
if (IsMIPS16Supported && (pctx->Fir & 1)) { // MIPS16
er.ExceptionInformation[0] = MIPS16_BREAK (BREAKIN_BREAKPOINT);
pctx->Fir -= 2;
} else {
er.ExceptionInformation[0] = MIPS32_BREAK (BREAKIN_BREAKPOINT);
}
pctx->Fir -= 4;
// If you are using the SetCPUHardware watch function you will probably
// want to uncomment the following line so that it will clear the register
// automatically on exception
// SetCPUHardwareWatch(0,0);
break;
case 30: // Stack overflow
er.ExceptionCode = STATUS_STACK_OVERFLOW;
er.ExceptionFlags = EXCEPTION_NONCONTINUABLE;
break;
}
}
if ((xcode != 9) && !IsNoFaultMsgSet ()) {
// if we faulted in DllMain doing PROCESS_ATTACH, the process name will
// be pointing to other process's (the creator) address space. Make sure
// we don't fault on displaying process name.
LPWSTR pProcName = pCurProc->lpszProcName? pCurProc->lpszProcName : L"";
LPCWSTR pszNamePC, pszNameRA;
DWORD dwOfstPC = (DWORD) pctx->Fir, dwOfstRA = (DWORD) pctx->IntRa;
DWORD ulOldKey;
SWITCHKEY(ulOldKey,0xffffffff);
pszNamePC = FindModuleNameAndOffset (dwOfstPC, &dwOfstPC);
pszNameRA = FindModuleNameAndOffset (dwOfstRA, &dwOfstRA);
if (!((DWORD) pProcName & 0x80000000)
&& (((DWORD) pProcName >> VA_SECTION) != (DWORD) (pCurProc->procnum+1)))
pProcName = L"";
NKDbgPrintfW(L"Exception %03x Thread=%8.8lx Proc=%8.8lx '%s'\r\n",
cause.XCODE, pth, hCurProc, pProcName);
NKDbgPrintfW(L"AKY=%8.8lx PC=%8.8lx(%s+0x%8.8lx) RA=%8.8lx(%s+0x%8.8lx) BVA=%8.8lx\r\n",
ulOldKey, pctx->Fir, pszNamePC, dwOfstPC, pctx->IntRa, pszNameRA, dwOfstRA, badVAddr);
SETCURKEY (ulOldKey);
if (IsNoFaultSet ()) {
NKDbgPrintfW(L"TLSKERN_NOFAULT set... bypassing kernel debugger.\r\n");
}
}
// Invoke the kernel debugger to attempt to debug the exception before
// letting the program resolve the condition via SEH.
pth->pcstkTop = (PCALLSTACK)(pexi->linkage & ~1);
if (!(pexi->linkage & 1) && IsValidKPtr (pexi)) {
// from RaiseException, free the callstack structure
FreeMem (pexi, HEAP_CALLSTACK);
}
if (!UserDbgTrap(&er,pctx,FALSE) && (IsNoFaultSet () || !HDException(&er, pctx, FALSE))) {
BOOL bHandled = FALSE;
// don't pass a break point exception to NKDispatchException
if (er.ExceptionCode != STATUS_BREAKPOINT) {
// to prevent recursive exception due to user messed-up TLS
KTHRDINFO (pth) &= ~UTLS_INKMODE;
bHandled = NKDispatchException(pth, &er, pctx);
}
if (!bHandled && !UserDbgTrap(&er, pctx, TRUE) && !HDException(&er, pctx, TRUE)) {
if (er.ExceptionCode == STATUS_BREAKPOINT) {
if (!pvHDNotifyExdi || pctx->Fir < (DWORD)pvHDNotifyExdi || pctx->Fir > ((DWORD)pvHDNotifyExdi + HD_NOTIFY_MARGIN))
RETAILMSG(1, (TEXT("DEBUG_BREAK @%8.8lx Ignored.\r\n"), pctx->Fir));
pctx->Fir += (pctx->Fir & 1)? 2 : 4; // skip over the BREAK instruction
} else {
// Terminate the process.
RETAILMSG(1, (TEXT("\r\nUnhandled exception %8.8lx:\r\n"),
er.ExceptionCode));
pctx->IntZero = badVAddr;
if (InSysCall()) {
DumpFrame(pth, (PICONTEXT)&pctx->IntZero, cause, badVAddr, 0);
lpNKHaltSystem ();
FakeNKHaltSystem ();
} else {
if (!GET_DEAD(pth)) {
PCALLSTACK pcstk = pth->pcstkTop;
while (pcstk && !pcstk->akyLast) {
pth->pcstkTop = (PCALLSTACK) ((DWORD) pcstk->pcstkNext & ~1);
if (IsValidKPtr (pcstk)) {
FreeMem (pcstk, HEAP_CALLSTACK);
}
pcstk = pth->pcstkTop;
}
DEBUGCHK (!pcstk); // should this happen, we have a fault in callback that wasn't handled
// by PSL
// clean up all the temporary callstack
if (er.ExceptionCode == STATUS_STACK_OVERFLOW) {
// stack overflow, not much we can do. Make sure we have enough room to run
// pExcpExitThread
// randomly picked a valid SP
pctx->IntSp = (DWORD) pth->tlsPtr - SECURESTK_RESERVE - (PAGE_SIZE >> 1);
}
SET_DEAD(pth);
//pth->tlsSecure[TLSSLOT_KERNEL] |= TLSKERN_TRYINGTODIE;
pctx->Fir = (ULONG)pExcpExitThread;
pctx->IntA0 = er.ExceptionCode; // argument: exception code
pctx->IntA1 = (ULONG)er.ExceptionAddress; // argument: exception address
RETAILMSG(1, (TEXT("Terminating thread %8.8lx\r\n"), pth));
} else {
DumpFrame(pth, (PICONTEXT)&pctx->IntZero, cause, badVAddr, 0);
RETAILMSG(1, (TEXT("Can't terminate thread %8.8lx, sleeping forever\r\n"), pth));
SurrenderCritSecs();
Sleep(INFINITE);
DEBUGCHK(0); // should never get here
}
}
}
}
}
if ((xcode == 2) || (xcode == 3))
GuardCommit(badVAddr);
continueExecution:
// restore ThrdInfo
KTHRDINFO (pth) = dwThrdInfo;
// If returning from handling a stack overflow, reset the thread's stack overflow
// flag. It would be good to free the tail of the stack at this time
// so that the thread will stack fault again if the stack gets too big. But we
// are currently using that stack page.
if (xcode == 30)
CLEAR_STACKFAULT(pth);
if (GET_DYING(pth) && !GET_DEAD(pth) && (pCurProc == pth->pOwnerProc)) {
SET_DEAD(pth);
CLEAR_USERBLOCK(pth);
CLEAR_DEBUGWAIT(pth);
pctx->Fir = (ULONG)pExcpExitThread;
pctx->IntA0 = er.ExceptionCode; // argument: exception code
pctx->IntA1 = (ULONG)er.ExceptionAddress; // argument: exception address
}
}
LONG __C_ExecuteExceptionFilter (
PEXCEPTION_POINTERS ExceptionPointers,
EXCEPTION_FILTER ExceptionFilter,
ULONG EstablisherFrame
);
VOID __C_ExecuteTerminationHandler (
BOOLEAN AbnormalTermination,
TERMINATION_HANDLER TerminationHandler,
ULONG EstablisherFrame
);
/*++
Routine Description:
This function scans the scope tables associated with the specified
procedure and calls exception and termination handlers as necessary.
Arguments:
ExceptionRecord - Supplies a pointer to an exception record.
EstablisherFrame - Supplies a pointer to frame of the establisher function.
ContextRecord - Supplies a pointer to a context record.
DispatcherContext - Supplies a pointer to the exception dispatcher or
unwind dispatcher context.
Return Value:
If the exception is handled by one of the exception filter routines, then
there is no return from this routine and RtlUnwind is called. Otherwise,
an exception disposition value of continue execution or continue search is
returned.
--*/
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
EXCEPTION_DISPOSITION
__C_specific_handler(
IN PEXCEPTION_RECORD ExceptionRecord,
IN PVOID EstablisherFrame,
IN OUT PCONTEXT ContextRecord,
IN OUT PDISPATCHER_CONTEXT DispatcherContext
) {
ULONG ControlPc;
EXCEPTION_FILTER ExceptionFilter;
EXCEPTION_POINTERS ExceptionPointers;
PRUNTIME_FUNCTION FunctionEntry;
ULONG Index;
PSCOPE_TABLE ScopeTable;
ULONG TargetPc;
TERMINATION_HANDLER TerminationHandler;
LONG Value;
// Get address of where control left the establisher, the address of the
// function table entry that describes the function, and the address of
// the scope table.
ControlPc = DispatcherContext->ControlPc;
FunctionEntry = DispatcherContext->FunctionEntry;
ScopeTable = (PSCOPE_TABLE)(FunctionEntry->HandlerData);
// If an unwind is not in progress, then scan the scope table and call
// the appropriate exception filter routines. Otherwise, scan the scope
// table and call the appropriate termination handlers using the target
// PC obtained from the context record.
// are called.
if (IS_DISPATCHING(ExceptionRecord->ExceptionFlags)) {
// Scan the scope table and call the appropriate exception filter
// routines.
ExceptionPointers.ExceptionRecord = ExceptionRecord;
ExceptionPointers.ContextRecord = ContextRecord;
for (Index = 0; Index < ScopeTable->Count; Index += 1) {
if ((ControlPc >= ScopeTable->ScopeRecord[Index].BeginAddress) &&
(ControlPc < ScopeTable->ScopeRecord[Index].EndAddress) &&
ScopeTable->ScopeRecord[Index].JumpTarget) {
// Call the exception filter routine.
ExceptionFilter = (EXCEPTION_FILTER)ScopeTable->ScopeRecord[Index].HandlerAddress;
Value = __C_ExecuteExceptionFilter(&ExceptionPointers, ExceptionFilter, (ULONG)EstablisherFrame);
// If the return value is less than zero, then dismiss the
// exception. Otherwise, if the value is greater than zero,
// then unwind to the target exception handler. Otherwise,
// continue the search for an exception filter.
if (Value < 0)
return ExceptionContinueExecution;
if (Value > 0) {
DispatcherContext->ControlPc = ScopeTable->ScopeRecord[Index].JumpTarget;
return ExceptionExecuteHandler;
}
}
}
} else {
// Scan the scope table and call the appropriate termination handler
// routines.
TargetPc = ContextRecord->Fir;
for (Index = 0; Index < ScopeTable->Count; Index += 1) {
if ((ControlPc >= ScopeTable->ScopeRecord[Index].BeginAddress) &&
(ControlPc < ScopeTable->ScopeRecord[Index].EndAddress)) {
// If the target PC is within the same scope the control PC
// is within, then this is an uplevel goto out of an inner try
// scope or a long jump back into a try scope. Terminate the
// scan termination handlers.
//
// N.B. The target PC can be just beyond the end of the scope,
// in which case it is a leave from the scope.
if ((TargetPc >= ScopeTable->ScopeRecord[Index].BeginAddress) &&
(TargetPc < ScopeTable->ScopeRecord[Index].EndAddress))
break;
// If the scope table entry describes an exception filter
// and the associated exception handler is the target of
// the unwind, then terminate the scan for termination
// handlers. Otherwise, if the scope table entry describes
// a termination handler, then record the address of the
// end of the scope as the new control PC address and call
// the termination handler.
if (ScopeTable->ScopeRecord[Index].JumpTarget) {
if (TargetPc == ScopeTable->ScopeRecord[Index].JumpTarget)
break;
} else {
DispatcherContext->ControlPc =
ScopeTable->ScopeRecord[Index].EndAddress + 4;
TerminationHandler = (TERMINATION_HANDLER)ScopeTable->ScopeRecord[Index].HandlerAddress;
__C_ExecuteTerminationHandler(TRUE, TerminationHandler, (ULONG)EstablisherFrame);
}
}
}
}
// Continue search for exception or termination handlers.
return ExceptionContinueSearch;
}
#ifdef MIPS_HAS_FPU
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
FPUFlushContext(void)
{
if (!InSysCall ())
KCall ((FARPROC) FPUFlushContext);
else if (g_CurFPUOwner) {
SaveFloatContext(g_CurFPUOwner);
g_CurFPUOwner = 0;
}
}
#endif
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL
DoThreadGetContext(
HANDLE hTh,
LPCONTEXT lpContext
)
{
PTHREAD pth;
if (!(pth = HandleToThread(hTh))) {
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
if (lpContext->ContextFlags & ~CONTEXT_FULL) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (pth->pThrdDbg && pth->pThrdDbg->psavedctx) {
ACCESSKEY ulOldKey;
SWITCHKEY(ulOldKey,0xffffffff);
if (lpContext->ContextFlags & CONTEXT_FLOATING_POINT) {
#ifdef MIPS_HAS_FPU
FPUFlushContext();
lpContext->Fsr = pth->ctx.Fsr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -