// FIXME: it's not always right. Thread::stop might hang. void XDbgProxy::stop() { assert(false); _stopFlag = true; Thread::stop(-1); // stop xdbg thread typedef NTSTATUS (NTAPI *LdrUnregDllNotifFunc)(PVOID Cookie); LdrUnregDllNotifFunc LdrUnregisterDllNotification = (LdrUnregDllNotifFunc)GetProcAddress( GetModuleHandle("ntdll.dll"), "LdrUnregisterDllNotification"); if (LdrUnregisterDllNotification) { LdrUnregisterDllNotification(_dllNotifCooike); _dllNotifCooike = NULL; } RemoveVectoredExceptionHandler(_vehCookie); _vehCookie = NULL; UninitWin32ApiWrapper(); if (_hPipe != INVALID_HANDLE_VALUE) { CloseHandle(_hPipe); _hPipe = INVALID_HANDLE_VALUE; } if (_hApiPipe != INVALID_HANDLE_VALUE) { CloseHandle(_hApiPipe); _hApiPipe = INVALID_HANDLE_VALUE; } }
void c_to_factor_toplevel(CELL quot) { if(!AddVectoredExceptionHandler(0, (void*)exception_handler)) fatal_error("AddVectoredExceptionHandler failed", 0); c_to_factor(quot); RemoveVectoredExceptionHandler((void*)exception_handler); }
w_boolean_t w_remove_exception_handler(w_ptr_t handle) { if (RemoveVectoredExceptionHandler(handle) == 0) return FALSE; return TRUE; }
void CEeExecutor::RemoveExceptionHandler() { #if defined(_WIN32) RemoveVectoredExceptionHandler(m_handler); #endif g_eeExecutor = nullptr; }
void tt_crash_trace_component_exit_ntv() { #ifdef TT_PLATFORM_ENABLE_BACKTRACE if (__exception_handler != NULL) { RemoveVectoredExceptionHandler(__exception_handler); } #endif }
BOOL Interrupt_3() { PVOID Handle = AddVectoredExceptionHandler(1, VectoredHandler); SwallowedException = TRUE; __debugbreak(); RemoveVectoredExceptionHandler(Handle); return SwallowedException; }
void RemoveExceptionHandler(void) { if (exchndlrv) RemoveVectoredExceptionHandler(exchndlrv); SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)exchndlr); exchndlr = NULL; exchndlrv = NULL; }
void win32_seh_cleanup() { guint32 ret = 0; if (mono_old_win_toplevel_exception_filter) SetUnhandledExceptionFilter(mono_old_win_toplevel_exception_filter); ret = RemoveVectoredExceptionHandler (mono_win_vectored_exception_handle); g_assert (ret); }
void FatalConditionHandler::reset() { if (isSet) { // Unregister handler and restore the old guarantee RemoveVectoredExceptionHandler(exceptionHandlerHandle); SetThreadStackGuarantee(&guaranteeSize); exceptionHandlerHandle = nullptr; isSet = false; } }
void vboxVDbgVEHandlerUnregister() { ULONG uResult; if (g_VBoxWDbgVEHandler) { uResult = RemoveVectoredExceptionHandler(g_VBoxWDbgVEHandler); CRASSERT(uResult); g_VBoxWDbgVEHandler = NULL; } }
void MemoryProtectionExceptionHandler::uninstall() { if (sExceptionHandlerInstalled) { MOZ_ASSERT(!sHandlingException); // Restore the previous exception handler. MOZ_ALWAYS_TRUE(RemoveVectoredExceptionHandler(sVectoredExceptionHandler)); sExceptionHandlerInstalled = false; } }
void UnhookSound() { HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, Utility->GetProcessThread()->th32ThreadID); SuspendThread(hThread); SetThreadContext(hThread, &GameCTX); ResumeThread(hThread); CloseHandle(hThread); RemoveVectoredExceptionHandler(hExceptionHandler); }
void __unregister_hs_exception_handler( void ) { if (__hs_handle != NULL) { // Should the return value be checked? we're terminating anyway. RemoveVectoredExceptionHandler(__hs_handle); __hs_handle = NULL; } else { errorBelch("__unregister_hs_exception_handler() called without having called __register_hs_exception_handler() first."); } }
void UnregisterHandler(ExceptionHandler *h) { auto i = std::find_if(handlers_.begin(), handlers_.end(), [rhs=h](ExceptionHandler *h) { return rhs == h; }); if (i != handlers_.end()) handlers_.erase(i); if (handlers_.empty()) { RemoveVectoredExceptionHandler(h_); h_ = 0; } }
static void SetThreadName( DWORD dwThreadID,const char *threadName ) { THREADNAME_INFO info; info.dwType = 0x1000; info.szName = threadName; info.dwThreadID = dwThreadID; info.dwFlags = 0; PVOID veh = AddVectoredExceptionHandler( 1,ignoreNameException ); RaiseException( EXCEPTION_THREAD_NAME,0, sizeof(info)/sizeof(ULONG_PTR),(ULONG_PTR*)&info ); RemoveVectoredExceptionHandler( veh ); }
PVOID dyn_AddVectoredExceptionHandler (ULONG isFirst, PVECTORED_EXCEPTION_HANDLER handler) { PVOID handlerHandle; if (isFirst) { RemoveVectoredExceptionHandler(fake_AVEH_handle); handlerHandle = AddVectoredExceptionHandler(isFirst,handler); fake_AVEH_handle = AddVectoredExceptionHandler (isFirst,(PVECTORED_EXCEPTION_HANDLER)dyn_trapHandler); } else { handlerHandle = AddVectoredExceptionHandler(isFirst,handler); } return handlerHandle; }
void removePageGuardExceptionHandler() { vktrace_sem_wait(ref_amount_sem_id); if (OPTHandler) { if (OPTHandlerRefAmount) { OPTHandlerRefAmount--; } if (!OPTHandlerRefAmount) { RemoveVectoredExceptionHandler(OPTHandler); OPTHandler = nullptr; } } vktrace_sem_post(ref_amount_sem_id); }
/** * Clean up Windows environment */ void GNShutdownWinEnv () { plibc_shutdown (); #ifdef W32_VEH if (GNWinVEH_handle != NULL) { RemoveVectoredExceptionHandler (GNWinVEH_handle); GNWinVEH_handle = NULL; } #endif FreeLibrary (hNTDLL); FreeLibrary (hIphlpapi); FreeLibrary (hAdvapi); FreeLibrary (hNetapi); CoUninitialize (); }
KxStackTrace::~KxStackTrace() { #ifdef WIN32 if (!IsDebuggerPresent()) #endif { signal(SIGABRT, SIG_DFL); signal(SIGSEGV, SIG_DFL); signal(SIGILL, SIG_DFL); signal(SIGFPE, SIG_DFL); #ifdef GNUC signal(SIGBUS, SIG_DFL); #endif //std::set_terminate(old_term); std::set_unexpected(nullptr); #ifdef WIN32 SetUnhandledExceptionFilter(nullptr); RemoveVectoredExceptionHandler(VFilter); #endif } }
BOOL HwDetourDetach( DWORD dwLineAddress, DWORD dwType ) { HANDLE hThreadSnap; THREADENTRY32 te32; static BOOL bExceptionHandlerUnSet = FALSE; if (bExceptionHandlerUnSet == FALSE) { RemoveVectoredExceptionHandler(g_hVectorHandle); bExceptionHandlerUnSet = !bExceptionHandlerUnSet; } hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, NULL ); if( hThreadSnap == INVALID_HANDLE_VALUE ) return FALSE; te32.dwSize = sizeof( THREADENTRY32 ); if( Thread32First( hThreadSnap, &te32 ) ) { do { if( te32.th32OwnerProcessID != GetCurrentProcessId() || te32.th32ThreadID == GetCurrentThreadId() ) continue; UninstDbgBreakfromThrd( te32.th32ThreadID,dwLineAddress, dwType); } while( Thread32Next( hThreadSnap, &te32 ) ); } for(int i = 0; i < 4; i++) { if( dwLineAddress == g_ExceptionInfo[i].dwLineAddr) { g_ExceptionInfo[i].bIsFree = TRUE; break; } } return TRUE; }
/// <summary> /// Remove existing hook /// </summary> /// <param name="targetFunc">Target function ptr</param> /// <returns>true on success, false if not found</returns> bool TraceHook::RemoveHook( void* targetFunc ) { auto findfn = [targetFunc]( const mapContext::value_type& val ) { return val.second.hooks.count( (uintptr_t)targetFunc ); }; // Get context containing target function auto iter = std::find_if( _contexts.begin(), _contexts.end(), findfn ); if (iter != _contexts.end()) { auto& ctx = iter->second; // Remove function from list ctx.hooks.erase( (uintptr_t)targetFunc ); if (ctx.hooks.empty()) { // Remove hook itself *(uintptr_t*)ctx.targetPtr = ctx.origPtrVal; _contexts.erase( iter ); } // Before handler is removed we need to make sure no thread will // generate exception again Sleep( 10 ); // Remove exception handler if (_contexts.empty() && _pExptHandler != nullptr) { RemoveVectoredExceptionHandler( _pExptHandler ); _pExptHandler = nullptr; } return true; } return false; }
int shutdown_signals() { if (asserts_disabled) { restore_assert_dialogs(); asserts_disabled = false; } signal(SIGABRT, prev_sig); ULONG res = RemoveVectoredExceptionHandler(veh); if (!res) return -1; BOOL ok = SetConsoleCtrlHandler((PHANDLER_ROUTINE)ctrl_handler, FALSE); if (!ok) return -1; port_mutex_destroy(&g_mutex); return 0; } //shutdown_signals
TraceHook::~TraceHook() { if (_pExptHandler != nullptr) RemoveVectoredExceptionHandler( _pExptHandler ); }
LONG WINAPI VEHandler(PEXCEPTION_POINTERS exceptionPtrs) { if ( (exceptionPtrs->ExceptionRecord->ExceptionCode < 0x80000000) // non-critical || (exceptionPtrs->ExceptionRecord->ExceptionCode == 0xe06d7363)) { // cpp exception // don't report non-critical exceptions return EXCEPTION_CONTINUE_SEARCH; } /* if (((exceptionPtrs->ExceptionRecord->ExceptionFlags & EXCEPTION_NONCONTINUABLE) != 0) || (exceptionPtrs->ExceptionRecord->ExceptionCode == 0xe06d7363)) { // don't want to break on non-critical exceptions. 0xe06d7363 indicates a C++ exception. why are those marked non-continuable? return EXCEPTION_CONTINUE_SEARCH; } */ if (RemoveVectoredExceptionHandler(exceptionHandler) == 0) { ::MessageBoxA(nullptr, "Failed to properly report windows exception, not daring to continue", "Critical Error ^ 2", MB_OK); return EXCEPTION_CONTINUE_SEARCH; } auto logger = spdlog::get("usvfs"); // ensure that the barrier won't keep future hook functions from running in case the process lives ON_BLOCK_EXIT([] () { HookLib::TrampolinePool::instance().forceUnlockBarrier(); }); try { std::pair<uintptr_t, uintptr_t> range = winapi::ex::getSectionRange(dllModule); uintptr_t exceptionAddress = reinterpret_cast<uintptr_t>(exceptionPtrs->ExceptionRecord->ExceptionAddress); if ((exceptionAddress < range.first) || (exceptionAddress > range.second)) { // exception address outside this dll std::wstring modName = winapi::ex::wide::getSectionName(exceptionPtrs->ExceptionRecord->ExceptionAddress); if (logger.get() != nullptr) { logger->warn("windows exception {0:x} from {1}", exceptionPtrs->ExceptionRecord->ExceptionCode, ush::string_cast<std::string>(modName)); } // re-install exception handler // exceptionHandler = ::AddVectoredExceptionHandler(0, VEHandler); return EXCEPTION_CONTINUE_SEARCH; } else { if (logger.get() != nullptr) { logger->warn("windows exception {0:x}", exceptionPtrs->ExceptionRecord->ExceptionCode); } } } catch (const std::exception &e) { if (logger.get() != nullptr) { logger->error("windows exception from unkown module ({})", e.what()); } } // remove hooks delete manager; manager = nullptr; createMiniDump(exceptionPtrs); return EXCEPTION_CONTINUE_SEARCH; }
void win32_seh_cleanup() { if (mono_old_win_toplevel_exception_filter) SetUnhandledExceptionFilter(mono_old_win_toplevel_exception_filter); RemoveVectoredExceptionHandler (mono_win_vectored_exception_handle); }