BsWin32CrashHandler.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. #include "BsPrerequisitesUtil.h"
  2. #include "BsDebug.h"
  3. #include "BsDynLib.h"
  4. #include "BsFileSystem.h"
  5. #include "windows.h"
  6. #include "DbgHelp.h"
  7. #include <psapi.h>
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Returns the raw stack trace using the provided context. Raw stack trace contains only
  12. * function addresses.
  13. *
  14. * @param context Processor context from which to start the stack trace.
  15. * @param stackTrace Output parameter that will contain the function addresses. First address is the deepest
  16. * called function and following address is its caller and so on.
  17. *
  18. * @returns Number of functions in the call stack.
  19. */
  20. UINT32 win32_getRawStackTrace(CONTEXT context, UINT64 stackTrace[BS_MAX_STACKTRACE_DEPTH])
  21. {
  22. HANDLE hProcess = GetCurrentProcess();
  23. HANDLE hThread = GetCurrentThread();
  24. UINT32 machineType;
  25. STACKFRAME64 stackFrame;
  26. memset(&stackFrame, 0, sizeof(stackFrame));
  27. stackFrame.AddrPC.Mode = AddrModeFlat;
  28. stackFrame.AddrStack.Mode = AddrModeFlat;
  29. stackFrame.AddrFrame.Mode = AddrModeFlat;
  30. #if BS_ARCH_TYPE == BS_ARCHITECTURE_x86_64
  31. stackFrame.AddrPC.Offset = context.Rip;
  32. stackFrame.AddrStack.Offset = context.Rsp;
  33. stackFrame.AddrFrame.Offset = context.Rbp;
  34. machineType = IMAGE_FILE_MACHINE_AMD64;
  35. #else
  36. stackFrame.AddrPC.Offset = context.Eip;
  37. stackFrame.AddrStack.Offset = context.Esp;
  38. stackFrame.AddrFrame.Offset = context.Ebp;
  39. machineType = IMAGE_FILE_MACHINE_I386;
  40. #endif
  41. UINT32 numEntries = 0;
  42. while (true)
  43. {
  44. if (!StackWalk64(machineType, hProcess, hThread, &stackFrame, &context, nullptr,
  45. SymFunctionTableAccess64, SymGetModuleBase64, nullptr))
  46. {
  47. break;
  48. }
  49. if (numEntries < BS_MAX_STACKTRACE_DEPTH)
  50. stackTrace[numEntries] = stackFrame.AddrPC.Offset;
  51. numEntries++;
  52. if (stackFrame.AddrPC.Offset == 0 || stackFrame.AddrFrame.Offset == 0)
  53. break;
  54. }
  55. return numEntries;
  56. }
  57. /**
  58. * @brief Returns a string containing a stack trace using the provided context. If function can be found in the symbol
  59. * table its readable name will be present in the stack trace, otherwise just its address.
  60. *
  61. * @param context Processor context from which to start the stack trace.
  62. * @param skip Number of bottom-most call stack entries to skip.
  63. *
  64. * @returns String containing the call stack with each function on its own line.
  65. */
  66. String win32_getStackTrace(CONTEXT context, UINT32 skip = 0)
  67. {
  68. UINT64 rawStackTrace[BS_MAX_STACKTRACE_DEPTH];
  69. UINT32 numEntries = win32_getRawStackTrace(context, rawStackTrace);
  70. numEntries = std::min((UINT32)BS_MAX_STACKTRACE_DEPTH, numEntries);
  71. UINT32 bufferSize = sizeof(PIMAGEHLP_SYMBOL64) + BS_MAX_STACKTRACE_NAME_BYTES;
  72. UINT8* buffer = (UINT8*)bs_alloc(bufferSize);
  73. PIMAGEHLP_SYMBOL64 symbol = (PIMAGEHLP_SYMBOL64)buffer;
  74. symbol->SizeOfStruct = bufferSize;
  75. symbol->MaxNameLength = BS_MAX_STACKTRACE_NAME_BYTES;
  76. HANDLE hProcess = GetCurrentProcess();
  77. StringStream outputStream;
  78. for (UINT32 i = skip; i < numEntries; i++)
  79. {
  80. if (i > skip)
  81. outputStream << std::endl;
  82. DWORD64 funcAddress = rawStackTrace[i];
  83. // Output function name
  84. DWORD64 dummy;
  85. if (SymGetSymFromAddr64(hProcess, funcAddress, &dummy, symbol))
  86. outputStream << StringUtil::format("{0}() - ", symbol->Name);
  87. // Output file name and line
  88. IMAGEHLP_LINE64 lineData;
  89. lineData.SizeOfStruct = sizeof(lineData);
  90. String addressString = toString(funcAddress, 0, ' ', std::ios::hex);
  91. DWORD column;
  92. if (SymGetLineFromAddr64(hProcess, funcAddress, &column, &lineData))
  93. {
  94. Path filePath = lineData.FileName;
  95. outputStream << StringUtil::format("0x{0} File[{1}:{2} ({3})]", addressString,
  96. filePath.getFilename(), lineData.LineNumber, column);
  97. }
  98. else
  99. {
  100. outputStream << StringUtil::format("0x{0}", addressString);
  101. }
  102. // Output module name
  103. IMAGEHLP_MODULE64 moduleData;
  104. moduleData.SizeOfStruct = sizeof(moduleData);
  105. if (SymGetModuleInfo64(hProcess, funcAddress, &moduleData))
  106. {
  107. Path filePath = moduleData.ImageName;
  108. outputStream << StringUtil::format(" Module[{0}]", filePath.getFilename());
  109. }
  110. }
  111. bs_free(buffer);
  112. return outputStream.str();
  113. }
  114. typedef bool(WINAPI *EnumProcessModulesType)(HANDLE hProcess, HMODULE* lphModule, DWORD cb, LPDWORD lpcbNeeded);
  115. typedef DWORD(WINAPI *GetModuleBaseNameType)(HANDLE hProcess, HMODULE hModule, LPSTR lpBaseName, DWORD nSize);
  116. typedef DWORD(WINAPI *GetModuleFileNameExType)(HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize);
  117. typedef bool(WINAPI *GetModuleInformationType)(HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb);
  118. static DynLib* gPSAPILib = nullptr;
  119. static EnumProcessModulesType gEnumProcessModules;
  120. static GetModuleBaseNameType gGetModuleBaseName;
  121. static GetModuleFileNameExType gGetModuleFileNameEx;
  122. static GetModuleInformationType gGetModuleInformation;
  123. /**
  124. * @brief Dynamically load the PSAPI.dll and the required symbols, if not already loaded.
  125. */
  126. void win32_initPSAPI()
  127. {
  128. if (gPSAPILib != nullptr)
  129. return;
  130. gPSAPILib = bs_new<DynLib>("PSAPI.dll");
  131. gEnumProcessModules = (EnumProcessModulesType)gPSAPILib->getSymbol("EnumProcessModules");
  132. gGetModuleBaseName = (GetModuleBaseNameType)gPSAPILib->getSymbol("GetModuleFileNameExA");
  133. gGetModuleFileNameEx = (GetModuleFileNameExType)gPSAPILib->getSymbol("GetModuleBaseNameA");
  134. gGetModuleInformation = (GetModuleInformationType)gPSAPILib->getSymbol("GetModuleInformation");
  135. }
  136. /**
  137. * @brief Unloads the PSAPI.dll if is loaded.
  138. */
  139. void win32_unloadPSAPI()
  140. {
  141. if (gPSAPILib == nullptr)
  142. return;
  143. gPSAPILib->unload();
  144. bs_delete(gPSAPILib);
  145. gPSAPILib = nullptr;
  146. }
  147. static bool gSymbolsLoaded = false;
  148. /**
  149. * @brief Loads symbols for all modules in the current process. Loaded symbols allow the stack walker to retrieve
  150. * human readable method, file, module names and other information.
  151. */
  152. void win32_loadSymbols()
  153. {
  154. if (gSymbolsLoaded)
  155. return;
  156. HANDLE hProcess = GetCurrentProcess();
  157. UINT32 options = SymGetOptions();
  158. options |= SYMOPT_LOAD_LINES;
  159. options |= SYMOPT_EXACT_SYMBOLS;
  160. options |= SYMOPT_UNDNAME;
  161. options |= SYMOPT_FAIL_CRITICAL_ERRORS;
  162. options |= SYMOPT_NO_PROMPTS;
  163. SymSetOptions(options);
  164. if(!SymInitialize(hProcess, nullptr, false))
  165. {
  166. LOGERR("SymInitialize failed. Error code: " + toString((UINT32)GetLastError()));
  167. return;
  168. }
  169. DWORD bufferSize;
  170. gEnumProcessModules(hProcess, nullptr, 0, &bufferSize);
  171. HMODULE* modules = (HMODULE*)bs_alloc(bufferSize);
  172. gEnumProcessModules(hProcess, modules, bufferSize, &bufferSize);
  173. UINT32 numModules = bufferSize / sizeof(HMODULE);
  174. for (UINT32 i = 0; i < numModules; i++)
  175. {
  176. MODULEINFO moduleInfo;
  177. char moduleName[BS_MAX_STACKTRACE_NAME_BYTES];
  178. char imageName[BS_MAX_STACKTRACE_NAME_BYTES];
  179. gGetModuleInformation(hProcess, modules[i], &moduleInfo, sizeof(moduleInfo));
  180. gGetModuleFileNameEx(hProcess, modules[i], imageName, BS_MAX_STACKTRACE_NAME_BYTES);
  181. gGetModuleBaseName(hProcess, modules[i], moduleName, BS_MAX_STACKTRACE_NAME_BYTES);
  182. char pdbSearchPath[BS_MAX_STACKTRACE_NAME_BYTES];
  183. char* fileName = nullptr;
  184. GetFullPathNameA(moduleName, BS_MAX_STACKTRACE_NAME_BYTES, pdbSearchPath, &fileName);
  185. *fileName = '\0';
  186. SymSetSearchPath(GetCurrentProcess(), pdbSearchPath);
  187. DWORD64 moduleAddress = SymLoadModule64(hProcess, modules[i], imageName, moduleName, (DWORD64)moduleInfo.lpBaseOfDll,
  188. (DWORD)moduleInfo.SizeOfImage);
  189. if (moduleAddress != 0)
  190. {
  191. IMAGEHLP_MODULE64 imageInfo;
  192. memset(&imageInfo, 0, sizeof(imageInfo));
  193. imageInfo.SizeOfStruct = sizeof(imageInfo);
  194. if(!SymGetModuleInfo64(GetCurrentProcess(), moduleAddress, &imageInfo))
  195. {
  196. LOGWRN("Failed retrieving module info for module: " + String(moduleName) + ". Error code: " + toString((UINT32)GetLastError()));
  197. }
  198. else
  199. {
  200. // Disabled because too much spam in the log, enable as needed
  201. #if 0
  202. if (imageInfo.SymType == SymNone)
  203. LOGWRN("Failed loading symbols for module: " + String(moduleName));
  204. #endif
  205. }
  206. }
  207. else
  208. {
  209. LOGWRN("Failed loading module " + String(moduleName) + ".Error code: " + toString((UINT32)GetLastError()) +
  210. ". Search path: " + String(pdbSearchPath) + ". Image name: " + String(imageName));
  211. }
  212. }
  213. bs_free(modules);
  214. gSymbolsLoaded = true;
  215. }
  216. /**
  217. * @brief Converts an exception record into a human readable error message.
  218. */
  219. String win32_getExceptionMessage(EXCEPTION_RECORD* record)
  220. {
  221. String exceptionAddress = toString((UINT64)record->ExceptionAddress, 0, ' ', std::ios::hex);
  222. String format;
  223. switch (record->ExceptionCode)
  224. {
  225. case EXCEPTION_ACCESS_VIOLATION:
  226. {
  227. DWORD_PTR violatedAddress = 0;
  228. if (record->NumberParameters == 2)
  229. {
  230. if (record->ExceptionInformation[0] == 0)
  231. format = "Unhandled exception at 0x{0}. Access violation reading 0x{1}.";
  232. else if (record->ExceptionInformation[0] == 8)
  233. format = "Unhandled exception at 0x{0}. Access violation DEP 0x{1}.";
  234. else
  235. format = "Unhandled exception at 0x{0}. Access violation writing 0x{1}.";
  236. violatedAddress = record->ExceptionInformation[1];
  237. }
  238. else
  239. format = "Unhandled exception at 0x{0}. Access violation.";
  240. String violatedAddressStr = toString(violatedAddress, 0, ' ', std::ios::hex);
  241. return StringUtil::format(format, exceptionAddress, violatedAddressStr);
  242. }
  243. case EXCEPTION_IN_PAGE_ERROR:
  244. {
  245. DWORD_PTR violatedAddress = 0;
  246. DWORD_PTR code = 0;
  247. if (record->NumberParameters == 3)
  248. {
  249. if (record->ExceptionInformation[0] == 0)
  250. format = "Unhandled exception at 0x{0}. Page fault reading 0x{1} with code 0x{2}.";
  251. else if (record->ExceptionInformation[0] == 8)
  252. format = "Unhandled exception at 0x{0}. Page fault DEP 0x{1} with code 0x{2}.";
  253. else
  254. format = "Unhandled exception at 0x{0}. Page fault writing 0x{1} with code 0x{2}.";
  255. violatedAddress = record->ExceptionInformation[1];
  256. code = record->ExceptionInformation[3];
  257. }
  258. else
  259. format = "Unhandled exception at 0x{0}. Page fault.";
  260. String violatedAddressStr = toString(violatedAddress, 0, ' ', std::ios::hex);
  261. String codeStr = toString(code, 0, ' ', std::ios::hex);
  262. return StringUtil::format(format, exceptionAddress, violatedAddressStr, codeStr);
  263. }
  264. case STATUS_ARRAY_BOUNDS_EXCEEDED:
  265. {
  266. format = "Unhandled exception at 0x{0}. Attempting to access an out of range array element.";
  267. return StringUtil::format(format, exceptionAddress);
  268. }
  269. case EXCEPTION_DATATYPE_MISALIGNMENT:
  270. {
  271. format = "Unhandled exception at 0x{0}. Attempting to access missaligned data.";
  272. return StringUtil::format(format, exceptionAddress);
  273. }
  274. case EXCEPTION_FLT_DENORMAL_OPERAND:
  275. {
  276. format = "Unhandled exception at 0x{0}. Floating point operand too small.";
  277. return StringUtil::format(format, exceptionAddress);
  278. }
  279. case EXCEPTION_FLT_DIVIDE_BY_ZERO:
  280. {
  281. format = "Unhandled exception at 0x{0}. Floating point operation attempted to divide by zero.";
  282. return StringUtil::format(format, exceptionAddress);
  283. }
  284. case EXCEPTION_FLT_INVALID_OPERATION:
  285. {
  286. format = "Unhandled exception at 0x{0}. Floating point invalid operation.";
  287. return StringUtil::format(format, exceptionAddress);
  288. }
  289. case EXCEPTION_FLT_OVERFLOW:
  290. {
  291. format = "Unhandled exception at 0x{0}. Floating point overflow.";
  292. return StringUtil::format(format, exceptionAddress);
  293. }
  294. case EXCEPTION_FLT_UNDERFLOW:
  295. {
  296. format = "Unhandled exception at 0x{0}. Floating point underflow.";
  297. return StringUtil::format(format, exceptionAddress);
  298. }
  299. case EXCEPTION_FLT_STACK_CHECK:
  300. {
  301. format = "Unhandled exception at 0x{0}. Floating point stack overflow/underflow.";
  302. return StringUtil::format(format, exceptionAddress);
  303. }
  304. case EXCEPTION_ILLEGAL_INSTRUCTION:
  305. {
  306. format = "Unhandled exception at 0x{0}. Attempting to execute an illegal instruction.";
  307. return StringUtil::format(format, exceptionAddress);
  308. }
  309. case EXCEPTION_PRIV_INSTRUCTION:
  310. {
  311. format = "Unhandled exception at 0x{0}. Attempting to execute a private instruction.";
  312. return StringUtil::format(format, exceptionAddress);
  313. }
  314. case EXCEPTION_INT_DIVIDE_BY_ZERO:
  315. {
  316. format = "Unhandled exception at 0x{0}. Integer operation attempted to divide by zero.";
  317. return StringUtil::format(format, exceptionAddress);
  318. }
  319. case EXCEPTION_INT_OVERFLOW:
  320. {
  321. format = "Unhandled exception at 0x{0}. Integer operation result has overflown.";
  322. return StringUtil::format(format, exceptionAddress);
  323. }
  324. case EXCEPTION_STACK_OVERFLOW:
  325. {
  326. format = "Unhandled exception at 0x{0}. Stack overflow.";
  327. return StringUtil::format(format, exceptionAddress);
  328. }
  329. default:
  330. {
  331. format = "Unhandled exception at 0x{0}. Code 0x{1}.";
  332. String exceptionCode = toString((UINT32)record->ExceptionCode, 0, ' ', std::ios::hex);
  333. return StringUtil::format(format, exceptionAddress, exceptionCode);
  334. }
  335. }
  336. }
  337. struct MiniDumpParams
  338. {
  339. Path filePath;
  340. EXCEPTION_POINTERS* exceptionData;
  341. };
  342. DWORD CALLBACK win32_writeMiniDumpWorker(void* data)
  343. {
  344. MiniDumpParams* params = (MiniDumpParams*)data;
  345. HANDLE hFile = CreateFileW(params->filePath.toWString().c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS,
  346. FILE_ATTRIBUTE_NORMAL, nullptr);
  347. if (hFile != INVALID_HANDLE_VALUE)
  348. {
  349. MINIDUMP_EXCEPTION_INFORMATION DumpExceptionInfo;
  350. DumpExceptionInfo.ThreadId = GetCurrentThreadId();
  351. DumpExceptionInfo.ExceptionPointers = params->exceptionData;
  352. DumpExceptionInfo.ClientPointers = false;
  353. MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal,
  354. &DumpExceptionInfo, nullptr, nullptr);
  355. CloseHandle(hFile);
  356. }
  357. return 0;
  358. }
  359. void win32_writeMiniDump(const Path& filePath, EXCEPTION_POINTERS* exceptionData)
  360. {
  361. MiniDumpParams param = { filePath, exceptionData };
  362. // Write minidump on a second thread in order to preserve the current thread's call stack
  363. DWORD threadId = 0;
  364. HANDLE hThread = CreateThread(nullptr, 0, &win32_writeMiniDumpWorker, &param, 0, &threadId);
  365. WaitForSingleObject(hThread, INFINITE);
  366. CloseHandle(hThread);
  367. }
  368. static const wchar_t* gMiniDumpName = L"minidump.dmp";
  369. const wchar_t* CrashHandler::CrashReportFolder = L"CrashReports/{0}/";
  370. const wchar_t* CrashHandler::CrashLogName = L"log.html";
  371. struct CrashHandler::Data
  372. {
  373. Mutex mutex;
  374. };
  375. CrashHandler::CrashHandler()
  376. {
  377. m = bs_new<Data>();
  378. }
  379. CrashHandler::~CrashHandler()
  380. {
  381. win32_unloadPSAPI();
  382. bs_delete(m);
  383. }
  384. void CrashHandler::reportCrash(const String& type, const String& description, const String& function,
  385. const String& file, UINT32 line)
  386. {
  387. // Win32 debug methods are not thread safe
  388. Lock<>(m->mutex);
  389. String stackTrace = getStackTrace();
  390. StringStream errorMessageStream;
  391. errorMessageStream << "Fatal error occurred and the program has to terminate!" << std::endl;
  392. errorMessageStream << "\t\t" << type << " - " << description << std::endl;
  393. errorMessageStream << "\t\t in " << function << " [" << file << ":" << line << "]" << std::endl;
  394. errorMessageStream << std::endl;
  395. errorMessageStream << "Stack trace: " << std::endl;
  396. errorMessageStream << stackTrace;
  397. String errorMessage = errorMessageStream.str();
  398. gDebug().logError(errorMessage);
  399. Path crashFolder = getCrashFolder();
  400. FileSystem::createDir(crashFolder);
  401. gDebug().saveLog(crashFolder + WString(CrashLogName));
  402. win32_writeMiniDump(crashFolder + WString(gMiniDumpName), nullptr);
  403. WString simpleErrorMessage = L"Fatal error occurred and the program has to terminate! " \
  404. L"\n\nFor more information check the crash report located at:\n " + crashFolder.toWString();
  405. MessageBoxW(nullptr, simpleErrorMessage.c_str(), L"Banshee fatal error!", MB_OK);
  406. // Note: Potentially also log Windows Error Report and/or send crash data to server
  407. }
  408. int CrashHandler::reportCrash(void* exceptionDataPtr)
  409. {
  410. EXCEPTION_POINTERS* exceptionData = (EXCEPTION_POINTERS*)exceptionDataPtr;
  411. // Win32 debug methods are not thread safe
  412. Lock<>(m->mutex);
  413. win32_initPSAPI();
  414. win32_loadSymbols();
  415. String stackTrace = win32_getStackTrace(*exceptionData->ContextRecord, 0);
  416. StringStream errorMessageStream;
  417. errorMessageStream << "Fatal error occurred and the program has to terminate!" << std::endl;
  418. errorMessageStream << "\t\t" << win32_getExceptionMessage(exceptionData->ExceptionRecord) << std::endl;;
  419. errorMessageStream << std::endl;
  420. errorMessageStream << "Stack trace: " << std::endl;
  421. errorMessageStream << stackTrace;
  422. String errorMessage = errorMessageStream.str();
  423. gDebug().logError(errorMessage);
  424. Path crashFolder = getCrashFolder();
  425. FileSystem::createDir(crashFolder);
  426. gDebug().saveLog(crashFolder + WString(CrashLogName));
  427. win32_writeMiniDump(crashFolder + WString(gMiniDumpName), exceptionData);
  428. WString simpleErrorMessage = L"Fatal error occurred and the program has to terminate! " \
  429. L"\n\nFor more information check the crash report located at:\n" + crashFolder.toWString();
  430. MessageBoxW(nullptr, simpleErrorMessage.c_str(), L"Banshee fatal error!", MB_OK);
  431. // Note: Potentially also log Windows Error Report and/or send crash data to server
  432. return EXCEPTION_EXECUTE_HANDLER;
  433. }
  434. Path CrashHandler::getCrashFolder()
  435. {
  436. SYSTEMTIME systemTime;
  437. GetLocalTime(&systemTime);
  438. WString timeStamp = L"{0}{1}{2}_{3}{4}";
  439. WString strYear = toWString(systemTime.wYear, 4, '0');
  440. WString strMonth = toWString(systemTime.wMonth, 2, '0');
  441. WString strDay = toWString(systemTime.wDay, 2, '0');
  442. WString strHour = toWString(systemTime.wHour, 2, '0');
  443. WString strMinute = toWString(systemTime.wMinute, 2, '0');
  444. timeStamp = StringUtil::format(timeStamp, strYear, strMonth, strDay, strHour, strMinute);
  445. WString folderName = StringUtil::format(CrashReportFolder, timeStamp);
  446. return FileSystem::getWorkingDirectoryPath() + folderName;
  447. }
  448. String CrashHandler::getStackTrace()
  449. {
  450. CONTEXT context;
  451. RtlCaptureContext(&context);
  452. win32_initPSAPI();
  453. win32_loadSymbols();
  454. return win32_getStackTrace(context, 2);
  455. }
  456. CrashHandler& gCrashHandler()
  457. {
  458. return CrashHandler::instance();
  459. }
  460. }