void __cdecl se_translator_function(unsigned int err, struct _EXCEPTION_POINTERS* ep) { char buf[128]; sprintf(buf,"%s(0x%08x) at 0x%08x",ExceptionName(err),err,ep->ExceptionRecord->ExceptionAddress); CrashHandler::ExceptionHandler(ep); throw std::exception(buf); }
void KernelCrashHandler(struct interrupt_context* intctx) { Scheduler::SaveInterruptedContext(intctx, &CurrentThread()->registers); // Panic the kernel with a diagnostic message. PanicF("Unhandled CPU Exception id %zu `%s' at ip=0x%zx (cr2=0x%zx, " "err_code=0x%zx)", intctx->int_no, ExceptionName(intctx), ExceptionLocation(intctx), intctx->cr2, intctx->err_code); }
/** Called by windows if an exception happens. */ static LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e) { // Prologue. logOutput.SetSubscribersEnabled(false); PRINT("Spring %s has crashed.", SpringVersion::GetFull().c_str()); #ifdef USE_GML PRINT("MT with %d threads.", gmlThreadCount); #endif initImageHlpDll(); // Record exception info. PRINT("Exception: %s (0x%08lx)", ExceptionName(e->ExceptionRecord->ExceptionCode), e->ExceptionRecord->ExceptionCode); PRINT("Exception Address: 0x%08lx", (unsigned long int) (PVOID) e->ExceptionRecord->ExceptionAddress); // Record list of loaded DLLs. PRINT("DLL information:"); SymEnumerateModules(GetCurrentProcess(), EnumModules, NULL); // Record stacktrace. PRINT("Stacktrace:"); Stacktrace(e); // Unintialize IMAGEHLP.DLL SymCleanup(GetCurrentProcess()); // Cleanup. SDL_Quit(); logOutput.End(); // Stop writing to log. // FIXME: update closing of demo to new netcode // Inform user. char dir[MAX_PATH], msg[MAX_PATH+200]; GetCurrentDirectory(sizeof(dir) - 1, dir); SNPRINTF(msg, sizeof(msg), "Spring has crashed.\n\n" "A stacktrace has been written to:\n" "%s\\infolog.txt", dir); MessageBox(NULL, msg, "Spring: Unhandled exception", 0); // this seems to silently close the application return EXCEPTION_EXECUTE_HANDLER; // this triggers the microsoft "application has crashed" error dialog //return EXCEPTION_CONTINUE_SEARCH; // in practice, 100% CPU usage but no continuation of execution // (tested segmentation fault and division by zero) //return EXCEPTION_CONTINUE_EXECUTION; }
/** Called by windows if an exception happens. */ static LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e) { // Prologue. Logger::warning("CaesarIA %d has crashed.", CAESARIA_BUILD_NUMBER ); // Initialize IMAGEHLP.DLL. SymInitialize(GetCurrentProcess(), ".", TRUE); // Record exception info. Logger::warning("Exception: %s (0x%08x)\n", ExceptionName(e->ExceptionRecord->ExceptionCode), e->ExceptionRecord->ExceptionCode); Logger::warning("Exception Address: 0x%08x\n", e->ExceptionRecord->ExceptionAddress); // Record list of loaded DLLs. //Logger::warning("DLL information:\n"); //SymEnumerateModules(GetCurrentProcess(), EnumModules, NULL); // Record stacktrace. Logger::warning("Stacktrace:\n"); Stacktrace(e); // Unintialize IMAGEHLP.DLL SymCleanup(GetCurrentProcess()); // Cleanup. // FIXME: update closing of demo to new netcode // Inform user. char dir[MAX_PATH]; GetCurrentDirectory(sizeof(dir) - 1, dir); std::string msg = utils::format( 0xff, "CaesarIA has crashed.\n\n" "A stacktrace has been written to:\n" "%s\\stdout.txt", dir); OSystem::error( "CaesarIA: Unhandled exception", msg ); // this seems to silently close the application return EXCEPTION_EXECUTE_HANDLER; // this triggers the microsoft "application has crashed" error dialog //return EXCEPTION_CONTINUE_SEARCH; // in practice, 100% CPU usage but no continuation of execution // (tested segmentation fault and division by zero) //return EXCEPTION_CONTINUE_EXECUTION; }
/** Called by windows if an exception happens. */ LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e) { // Prologue. logOutput.SetSubscribersEnabled(false); PRINT("Spring %s has crashed.", SpringVersion::GetFull().c_str()); #ifdef USE_GML PRINT("MT with %d threads.", gmlThreadCount); #endif PrepareStacktrace(); const std::string error(ExceptionName(e->ExceptionRecord->ExceptionCode)); // Print exception info. PRINT("Exception: %s (0x%08lx)", error.c_str(), e->ExceptionRecord->ExceptionCode); PRINT("Exception Address: 0x%08lx", (unsigned long int) (PVOID) e->ExceptionRecord->ExceptionAddress); // Print stacktrace. Stacktrace(NULL, e); CleanupStacktrace(); // Only the first crash is of any real interest CrashHandler::Remove(); // Inform user. std::ostringstream buf; buf << "Spring has crashed:\n" << " " << error << ".\n\n" << "A stacktrace has been written to:\n" << " " << logOutput.GetFilePath(); ErrorMessageBox(buf.str(), "Spring: Unhandled exception", MBF_OK | MBF_CRASH); //calls exit()! // this seems to silently close the application return EXCEPTION_EXECUTE_HANDLER; // this triggers the microsoft "application has crashed" error dialog //return EXCEPTION_CONTINUE_SEARCH; // in practice, 100% CPU usage but no continuation of execution // (tested segmentation fault and division by zero) //return EXCEPTION_CONTINUE_EXECUTION; }
void UserCrashHandler(struct interrupt_context* intctx) { Scheduler::SaveInterruptedContext(intctx, &CurrentThread()->registers); // Execute this crash handler with preemption on. Interrupt::Enable(); // TODO: Also send signals for other types of user-space crashes. if ( intctx->int_no == 14 /* Page fault */ ) { struct sigaction* act = &CurrentProcess()->signal_actions[SIGSEGV]; kthread_mutex_lock(&CurrentProcess()->signal_lock); bool handled = act->sa_handler != SIG_DFL && act->sa_handler != SIG_IGN; if ( handled ) CurrentThread()->DeliverSignalUnlocked(SIGSEGV); kthread_mutex_unlock(&CurrentProcess()->signal_lock); if ( handled ) { assert(Interrupt::IsEnabled()); return Signal::DispatchHandler(intctx, NULL); } } // Issue a diagnostic message to the kernel log concerning the crash. Log::PrintF("The current process (pid %ji `%s') crashed and was terminated:\n", (intmax_t) CurrentProcess()->pid, CurrentProcess()->program_image_path); Log::PrintF("%s exception at ip=0x%zx (cr2=0x%zx, err_code=0x%zx)\n", ExceptionName(intctx), ExceptionLocation(intctx), intctx->cr2, intctx->err_code); // Exit the process with the right error code. // TODO: Send a SIGINT, SIGBUS, or whatever instead. CurrentProcess()->ExitThroughSignal(SIGSEGV); // Deliver signals to this thread so it can exit correctly. assert(Interrupt::IsEnabled()); Signal::DispatchHandler(intctx, NULL); }