17 USE_OLD_USER_SE_FIRST = 2
20DWORD TLSInd_FlagsSE = TLS_OUT_OF_INDEXES;
21DWORD TLSInd_UserSE = TLS_OUT_OF_INDEXES;
23#if defined(__BORLANDC__)
24void _USERENTRY TLSInd_Free()
25#elif defined(_MSC_VER)
26void __cdecl TLSInd_Free()
31 TlsFree(TLSInd_FlagsSE);
32 TlsFree(TLSInd_UserSE);
33 TLSInd_FlagsSE = TLS_OUT_OF_INDEXES;
34 TLSInd_UserSE = TLS_OUT_OF_INDEXES;
37LONG WINAPI usrSEH(_EXCEPTION_POINTERS *pInfo)
39 LONG ret = EXCEPTION_CONTINUE_SEARCH;
40 if (
size_t(TlsGetValue(TLSInd_FlagsSE)) &USE_OLD_USER_SE_FIRST)
42 if (
auto oldHook = LPTOP_LEVEL_EXCEPTION_FILTER(TlsGetValue(TLSInd_UserSE)))
46 if (EXCEPTION_CONTINUE_SEARCH == ret)
48 if (
const auto er =pInfo->ExceptionRecord)
49 RUNTIME_ERROR(
"code 0x{:x}, flags 0x{:x}, extra {}, ip {}, arg#{:x}",
52 static_cast<void*
>(er->ExceptionRecord),
53 static_cast<void*
>(er->ExceptionAddress),
54 er->NumberParameters);
56 return EXCEPTION_CONTINUE_SEARCH;
68void catchSE(
bool useOldHookFirst)
77 if (TLS_OUT_OF_INDEXES == TLSInd_FlagsSE)
79 static std::atomic_flag lock = ATOMIC_FLAG_INIT;
81 if (TLS_OUT_OF_INDEXES == TLSInd_FlagsSE)
83 TLSInd_UserSE = TlsAlloc();
84 TLSInd_FlagsSE = TlsAlloc();
89 if (!TlsGetValue(TLSInd_FlagsSE))
91 TlsSetValue(TLSInd_UserSE, LPVOID(SetUnhandledExceptionFilter(usrSEH)));
92 size_t flags = CATCH_SE_CALLED;
94 flags |= USE_OLD_USER_SE_FIRST;
96 TlsSetValue(TLSInd_FlagsSE, LPVOID(flags));
#define RUNTIME_ERROR(fmtStr,...)
Wrap FILE(DATE)#__LINE__ FUNCTION: msg into std::runtime_error.
THE common namespace of bux library.