📄 mdsched.c
字号:
break; case 5: // Address error (store) case 4: // Address error (load or instruction fetch) if (GetContextMode(pctx) != USER_MODE || !(badVAddr&0x80000000)) { er.ExceptionCode = STATUS_DATATYPE_MISALIGNMENT; break; } goto accessError; case 2: // TLB miss (load or instruction fetch) case 3: // TLB Miss (store) case 1: // TLB modification if (ProcessPageFault((xcode==3) || (xcode == 1), badVAddr)) { pth->pcstkTop = (PCALLSTACK)(pexi->linkage & ~1); goto continueExecution; } accessError: er.ExceptionInformation[0] = xcode & 1; er.ExceptionCode = STATUS_ACCESS_VIOLATION; er.ExceptionInformation[1] = badVAddr; er.NumberParameters = 2; break; case 6: // Bus error (instruction fetch) case 7: // Bus error (data reference) er.ExceptionInformation[0] = xcode & 1; er.ExceptionCode = STATUS_ACCESS_VIOLATION; er.ExceptionInformation[1] = badVAddr; er.NumberParameters = 2; break; case 9: // Breakpoint#ifdef MIPS16SUPPORT if (pctx->Fir & 1) { // MIPS16 mode er.ExceptionInformation[0] = *(USHORT *)(pctx->Fir & ~1); er.ExceptionCode = STATUS_BREAKPOINT; if (er.ExceptionInformation[0] == MIPS16_BREAK (DIVIDE_BY_ZERO_BREAKPOINT)) { er.ExceptionCode = STATUS_INTEGER_DIVIDE_BY_ZERO; } else if (er.ExceptionInformation[0] == MIPS16_BREAK (MULTIPLY_OVERFLOW_BREAKPOINT) || er.ExceptionInformation[0] == MIPS16_BREAK (DIVIDE_OVERFLOW_BREAKPOINT)) { er.ExceptionCode = STATUS_INTEGER_OVERFLOW; } else if (er.ExceptionInformation[0] == MIPS16_BREAK (BREAKIN_BREAKPOINT)) { pctx->Fir += 2; } } else#endif { // MIPS32 mode 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(1,(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(DWORD)*32); pctx->Fsr = pth->ctx.Fsr; if (HandleHWFloatException(&er,pctx,cause)) { memcpy(&pth->ctx.FltF0,&pctx->FltF0,sizeof(DWORD)*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;#ifdef MIPS16SUPPORT if (pctx->Fir & 1) { // MIPS16 er.ExceptionInformation[0] = MIPS16_BREAK (BREAKIN_BREAKPOINT); pctx->Fir -= 2; } else#endif { 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) { NKDbgPrintfW(L"Exception %03x Thread=%8.8lx Proc=%8.8lx\r\n", cause.XCODE, pth, hCurProc); NKDbgPrintfW(L"AKY=%8.8lx PC=%8.8lx RA=%8.8lx BVA=%8.8lx\r\n", pCurThread->aky, pctx->Fir, pctx->IntRa, badVAddr); NKDbgPrintfW(L"Process '%s'\r\n", pCurProc->lpszProcName ? pCurProc->lpszProcName : L""); if (UTlsPtr()[TLSSLOT_KERNEL] & TLSKERN_NOFAULT) { 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 (!UserDbgTrap(&er,pctx,FALSE) && ((UTlsPtr()[TLSSLOT_KERNEL] & TLSKERN_NOFAULT) || !KDTrap(&er, pctx, FALSE))) { if (er.ExceptionCode == STATUS_BREAKPOINT) { RETAILMSG(1, (TEXT("DEBUG_BREAK @%8.8lx Ignored.\r\n"), pctx->Fir)); pctx->Fir += 4; // skip over the BREAK instruction } else { bHandled = NKDispatchException(pth, &er, pctx); if (!bHandled) { if (!UserDbgTrap(&er, pctx, TRUE) && !KDTrap(&er, pctx, TRUE)) { // Terminate the process. RETAILMSG(1, (TEXT("\r\nUnhandled exception %8.8lx:\r\n"), er.ExceptionCode)); pctx->IntZero = badVAddr; DumpFrame(pth, (PICONTEXT)&pctx->IntZero, cause, badVAddr, 0); if (InSysCall()) { OutputDebugStringW(L"Halting system\r\n"); for (;;) ; } else { if (!GET_DEAD(pth)) { SET_DEAD(pth); pctx->Fir = (ULONG)pExitThread; pctx->IntA0 = 0; RETAILMSG(1, (TEXT("Terminating thread %8.8lx\r\n"), pth)); } else { 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: // 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)pExitThread; pctx->IntA0 = 0; } }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_FPUvoid FPUFlushContext(void) { if (g_CurFPUOwner) { SaveFloatContext(g_CurFPUOwner); g_CurFPUOwner = 0; }}#endifBOOL 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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -