Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 1 | //===- Win32/Signals.cpp - Win32 Signals Implementation ---------*- C++ -*-===// |
Mikhail Glushenkov | f64d93d | 2010-10-21 20:40:39 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Mikhail Glushenkov | f64d93d | 2010-10-21 20:40:39 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file provides the Win32 specific implementation of the Signals class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Zachary Turner | b44d7a0 | 2018-06-01 22:23:46 +0000 | [diff] [blame] | 13 | #include "llvm/Support/ConvertUTF.h" |
Rafael Espindola | 9aa3d5d | 2013-06-14 13:59:21 +0000 | [diff] [blame] | 14 | #include "llvm/Support/FileSystem.h" |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Path.h" |
| 16 | #include "llvm/Support/Process.h" |
| 17 | #include "llvm/Support/WindowsError.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include <algorithm> |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 19 | #include <io.h> |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 20 | #include <signal.h> |
Reid Spencer | 70b6835 | 2004-09-28 23:58:03 +0000 | [diff] [blame] | 21 | #include <stdio.h> |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 22 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Format.h" |
| 24 | #include "llvm/Support/raw_ostream.h" |
| 25 | |
Chandler Carruth | 10b0915 | 2014-01-07 12:37:13 +0000 | [diff] [blame] | 26 | // The Windows.h header must be after LLVM and standard headers. |
Reid Kleckner | d59e2fa | 2014-02-12 21:26:20 +0000 | [diff] [blame] | 27 | #include "WindowsSupport.h" |
Chandler Carruth | 10b0915 | 2014-01-07 12:37:13 +0000 | [diff] [blame] | 28 | |
Jeff Cohen | 07e22ba | 2005-02-19 03:01:13 +0000 | [diff] [blame] | 29 | #ifdef __MINGW32__ |
Reid Spencer | 187b4ad | 2006-06-01 19:03:21 +0000 | [diff] [blame] | 30 | #include <imagehlp.h> |
Reid Spencer | 9904928 | 2004-09-23 14:47:10 +0000 | [diff] [blame] | 31 | #else |
Zachary Turner | ab266cf | 2016-12-21 18:50:52 +0000 | [diff] [blame] | 32 | #include <crtdbg.h> |
Reid Spencer | 187b4ad | 2006-06-01 19:03:21 +0000 | [diff] [blame] | 33 | #include <dbghelp.h> |
Reid Spencer | 9904928 | 2004-09-23 14:47:10 +0000 | [diff] [blame] | 34 | #endif |
| 35 | #include <psapi.h> |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 36 | |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 37 | #ifdef _MSC_VER |
| 38 | #pragma comment(lib, "psapi.lib") |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 39 | #elif __MINGW32__ |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 40 | // The version of g++ that comes with MinGW does *not* properly understand |
| 41 | // the ll format specifier for printf. However, MinGW passes the format |
| 42 | // specifiers on to the MSVCRT entirely, and the CRT understands the ll |
| 43 | // specifier. So these warnings are spurious in this case. Since we compile |
| 44 | // with -Wall, this will generate these warnings which should be ignored. So |
| 45 | // we will turn off the warnings for this just file. However, MinGW also does |
| 46 | // not support push and pop for diagnostics, so we have to manually turn it |
| 47 | // back on at the end of the file. |
| 48 | #pragma GCC diagnostic ignored "-Wformat" |
| 49 | #pragma GCC diagnostic ignored "-Wformat-extra-args" |
| 50 | |
Anton Korobeynikov | b27f11e | 2011-10-21 09:38:50 +0000 | [diff] [blame] | 51 | #if !defined(__MINGW64_VERSION_MAJOR) |
| 52 | // MinGW.org does not have updated support for the 64-bit versions of the |
| 53 | // DebugHlp APIs. So we will have to load them manually. The structures and |
| 54 | // method signatures were pulled from DbgHelp.h in the Windows Platform SDK, |
| 55 | // and adjusted for brevity. |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 56 | typedef struct _IMAGEHLP_LINE64 { |
| 57 | DWORD SizeOfStruct; |
| 58 | PVOID Key; |
| 59 | DWORD LineNumber; |
| 60 | PCHAR FileName; |
| 61 | DWORD64 Address; |
| 62 | } IMAGEHLP_LINE64, *PIMAGEHLP_LINE64; |
| 63 | |
| 64 | typedef struct _IMAGEHLP_SYMBOL64 { |
| 65 | DWORD SizeOfStruct; |
| 66 | DWORD64 Address; |
| 67 | DWORD Size; |
| 68 | DWORD Flags; |
| 69 | DWORD MaxNameLength; |
| 70 | CHAR Name[1]; |
| 71 | } IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64; |
| 72 | |
| 73 | typedef struct _tagADDRESS64 { |
| 74 | DWORD64 Offset; |
| 75 | WORD Segment; |
| 76 | ADDRESS_MODE Mode; |
| 77 | } ADDRESS64, *LPADDRESS64; |
| 78 | |
| 79 | typedef struct _KDHELP64 { |
| 80 | DWORD64 Thread; |
| 81 | DWORD ThCallbackStack; |
| 82 | DWORD ThCallbackBStore; |
| 83 | DWORD NextCallback; |
| 84 | DWORD FramePointer; |
| 85 | DWORD64 KiCallUserMode; |
| 86 | DWORD64 KeUserCallbackDispatcher; |
| 87 | DWORD64 SystemRangeStart; |
| 88 | DWORD64 KiUserExceptionDispatcher; |
| 89 | DWORD64 StackBase; |
| 90 | DWORD64 StackLimit; |
| 91 | DWORD64 Reserved[5]; |
| 92 | } KDHELP64, *PKDHELP64; |
| 93 | |
| 94 | typedef struct _tagSTACKFRAME64 { |
| 95 | ADDRESS64 AddrPC; |
| 96 | ADDRESS64 AddrReturn; |
| 97 | ADDRESS64 AddrFrame; |
| 98 | ADDRESS64 AddrStack; |
| 99 | ADDRESS64 AddrBStore; |
| 100 | PVOID FuncTableEntry; |
| 101 | DWORD64 Params[4]; |
| 102 | BOOL Far; |
| 103 | BOOL Virtual; |
| 104 | DWORD64 Reserved[3]; |
| 105 | KDHELP64 KdHelp; |
| 106 | } STACKFRAME64, *LPSTACKFRAME64; |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 107 | #endif // !defined(__MINGW64_VERSION_MAJOR) |
| 108 | #endif // __MINGW32__ |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 109 | |
| 110 | typedef BOOL (__stdcall *PREAD_PROCESS_MEMORY_ROUTINE64)(HANDLE hProcess, |
| 111 | DWORD64 qwBaseAddress, PVOID lpBuffer, DWORD nSize, |
| 112 | LPDWORD lpNumberOfBytesRead); |
| 113 | |
| 114 | typedef PVOID (__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE64)( HANDLE ahProcess, |
| 115 | DWORD64 AddrBase); |
| 116 | |
| 117 | typedef DWORD64 (__stdcall *PGET_MODULE_BASE_ROUTINE64)(HANDLE hProcess, |
| 118 | DWORD64 Address); |
| 119 | |
| 120 | typedef DWORD64 (__stdcall *PTRANSLATE_ADDRESS_ROUTINE64)(HANDLE hProcess, |
| 121 | HANDLE hThread, LPADDRESS64 lpaddr); |
| 122 | |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 123 | typedef BOOL(WINAPI *fpMiniDumpWriteDump)(HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, |
| 124 | PMINIDUMP_EXCEPTION_INFORMATION, |
| 125 | PMINIDUMP_USER_STREAM_INFORMATION, |
| 126 | PMINIDUMP_CALLBACK_INFORMATION); |
| 127 | static fpMiniDumpWriteDump fMiniDumpWriteDump; |
| 128 | |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 129 | typedef BOOL (WINAPI *fpStackWalk64)(DWORD, HANDLE, HANDLE, LPSTACKFRAME64, |
| 130 | PVOID, PREAD_PROCESS_MEMORY_ROUTINE64, |
| 131 | PFUNCTION_TABLE_ACCESS_ROUTINE64, |
| 132 | PGET_MODULE_BASE_ROUTINE64, |
| 133 | PTRANSLATE_ADDRESS_ROUTINE64); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 134 | static fpStackWalk64 fStackWalk64; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 135 | |
| 136 | typedef DWORD64 (WINAPI *fpSymGetModuleBase64)(HANDLE, DWORD64); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 137 | static fpSymGetModuleBase64 fSymGetModuleBase64; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 138 | |
| 139 | typedef BOOL (WINAPI *fpSymGetSymFromAddr64)(HANDLE, DWORD64, |
| 140 | PDWORD64, PIMAGEHLP_SYMBOL64); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 141 | static fpSymGetSymFromAddr64 fSymGetSymFromAddr64; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 142 | |
| 143 | typedef BOOL (WINAPI *fpSymGetLineFromAddr64)(HANDLE, DWORD64, |
| 144 | PDWORD, PIMAGEHLP_LINE64); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 145 | static fpSymGetLineFromAddr64 fSymGetLineFromAddr64; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 146 | |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 147 | typedef BOOL(WINAPI *fpSymGetModuleInfo64)(HANDLE hProcess, DWORD64 dwAddr, |
| 148 | PIMAGEHLP_MODULE64 ModuleInfo); |
| 149 | static fpSymGetModuleInfo64 fSymGetModuleInfo64; |
| 150 | |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 151 | typedef PVOID (WINAPI *fpSymFunctionTableAccess64)(HANDLE, DWORD64); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 152 | static fpSymFunctionTableAccess64 fSymFunctionTableAccess64; |
| 153 | |
| 154 | typedef DWORD (WINAPI *fpSymSetOptions)(DWORD); |
| 155 | static fpSymSetOptions fSymSetOptions; |
| 156 | |
| 157 | typedef BOOL (WINAPI *fpSymInitialize)(HANDLE, PCSTR, BOOL); |
| 158 | static fpSymInitialize fSymInitialize; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 159 | |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 160 | typedef BOOL (WINAPI *fpEnumerateLoadedModules)(HANDLE,PENUMLOADED_MODULES_CALLBACK64,PVOID); |
| 161 | static fpEnumerateLoadedModules fEnumerateLoadedModules; |
| 162 | |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 163 | static bool load64BitDebugHelp(void) { |
David Majnemer | 17a4496 | 2013-10-07 09:52:36 +0000 | [diff] [blame] | 164 | HMODULE hLib = ::LoadLibraryW(L"Dbghelp.dll"); |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 165 | if (hLib) { |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 166 | fMiniDumpWriteDump = (fpMiniDumpWriteDump) |
| 167 | ::GetProcAddress(hLib, "MiniDumpWriteDump"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 168 | fStackWalk64 = (fpStackWalk64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 169 | ::GetProcAddress(hLib, "StackWalk64"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 170 | fSymGetModuleBase64 = (fpSymGetModuleBase64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 171 | ::GetProcAddress(hLib, "SymGetModuleBase64"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 172 | fSymGetSymFromAddr64 = (fpSymGetSymFromAddr64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 173 | ::GetProcAddress(hLib, "SymGetSymFromAddr64"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 174 | fSymGetLineFromAddr64 = (fpSymGetLineFromAddr64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 175 | ::GetProcAddress(hLib, "SymGetLineFromAddr64"); |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 176 | fSymGetModuleInfo64 = (fpSymGetModuleInfo64) |
| 177 | ::GetProcAddress(hLib, "SymGetModuleInfo64"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 178 | fSymFunctionTableAccess64 = (fpSymFunctionTableAccess64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 179 | ::GetProcAddress(hLib, "SymFunctionTableAccess64"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 180 | fSymSetOptions = (fpSymSetOptions)::GetProcAddress(hLib, "SymSetOptions"); |
| 181 | fSymInitialize = (fpSymInitialize)::GetProcAddress(hLib, "SymInitialize"); |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 182 | fEnumerateLoadedModules = (fpEnumerateLoadedModules) |
| 183 | ::GetProcAddress(hLib, "EnumerateLoadedModules64"); |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 184 | } |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 185 | return fStackWalk64 && fSymInitialize && fSymSetOptions && fMiniDumpWriteDump; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 186 | } |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 187 | |
Yaron Keren | 240bd9c | 2015-07-22 19:01:14 +0000 | [diff] [blame] | 188 | using namespace llvm; |
| 189 | |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 190 | // Forward declare. |
| 191 | static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep); |
| 192 | static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType); |
| 193 | |
JF Bastien | 93bce51 | 2018-05-15 04:06:28 +0000 | [diff] [blame] | 194 | // The function to call if ctrl-c is pressed. |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 195 | static void (*InterruptFunction)() = 0; |
| 196 | |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 197 | static std::vector<std::string> *FilesToRemove = NULL; |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 198 | static bool RegisteredUnhandledExceptionFilter = false; |
Reid Spencer | 1bdd0f0 | 2004-09-19 05:37:39 +0000 | [diff] [blame] | 199 | static bool CleanupExecuted = false; |
| 200 | static PTOP_LEVEL_EXCEPTION_FILTER OldFilter = NULL; |
Reid Spencer | 90debc5 | 2004-09-17 03:02:27 +0000 | [diff] [blame] | 201 | |
| 202 | // Windows creates a new thread to execute the console handler when an event |
| 203 | // (such as CTRL/C) occurs. This causes concurrency issues with the above |
| 204 | // globals which this critical section addresses. |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 205 | static CRITICAL_SECTION CriticalSection; |
Aaron Ballman | 50af8d4 | 2015-03-26 16:24:38 +0000 | [diff] [blame] | 206 | static bool CriticalSectionInitialized = false; |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 207 | |
Richard Smith | 2ad6d48 | 2016-06-09 00:53:21 +0000 | [diff] [blame] | 208 | static StringRef Argv0; |
| 209 | |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 210 | enum { |
| 211 | #if defined(_M_X64) |
| 212 | NativeMachineType = IMAGE_FILE_MACHINE_AMD64 |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 213 | #elif defined(_M_ARM64) |
| 214 | NativeMachineType = IMAGE_FILE_MACHINE_ARM64 |
| 215 | #elif defined(_M_IX86) |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 216 | NativeMachineType = IMAGE_FILE_MACHINE_I386 |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 217 | #elif defined(_M_ARM) |
| 218 | NativeMachineType = IMAGE_FILE_MACHINE_ARMNT |
| 219 | #else |
| 220 | NativeMachineType = IMAGE_FILE_MACHINE_UNKNOWN |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 221 | #endif |
| 222 | }; |
| 223 | |
| 224 | static bool printStackTraceWithLLVMSymbolizer(llvm::raw_ostream &OS, |
| 225 | HANDLE hProcess, HANDLE hThread, |
| 226 | STACKFRAME64 &StackFrameOrig, |
| 227 | CONTEXT *ContextOrig) { |
| 228 | // StackWalk64 modifies the incoming stack frame and context, so copy them. |
| 229 | STACKFRAME64 StackFrame = StackFrameOrig; |
| 230 | |
| 231 | // Copy the register context so that we don't modify it while we unwind. We |
| 232 | // could use InitializeContext + CopyContext, but that's only required to get |
| 233 | // at AVX registers, which typically aren't needed by StackWalk64. Reduce the |
| 234 | // flag set to indicate that there's less data. |
| 235 | CONTEXT Context = *ContextOrig; |
| 236 | Context.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER; |
| 237 | |
| 238 | static void *StackTrace[256]; |
Aaron Ballman | 3c44b42 | 2015-11-05 14:22:56 +0000 | [diff] [blame] | 239 | size_t Depth = 0; |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 240 | while (fStackWalk64(NativeMachineType, hProcess, hThread, &StackFrame, |
| 241 | &Context, 0, fSymFunctionTableAccess64, |
| 242 | fSymGetModuleBase64, 0)) { |
| 243 | if (StackFrame.AddrFrame.Offset == 0) |
| 244 | break; |
| 245 | StackTrace[Depth++] = (void *)(uintptr_t)StackFrame.AddrPC.Offset; |
| 246 | if (Depth >= array_lengthof(StackTrace)) |
| 247 | break; |
| 248 | } |
| 249 | |
Richard Smith | 2ad6d48 | 2016-06-09 00:53:21 +0000 | [diff] [blame] | 250 | return printSymbolizedStackTrace(Argv0, &StackTrace[0], Depth, OS); |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | namespace { |
| 254 | struct FindModuleData { |
| 255 | void **StackTrace; |
| 256 | int Depth; |
| 257 | const char **Modules; |
| 258 | intptr_t *Offsets; |
| 259 | StringSaver *StrPool; |
| 260 | }; |
| 261 | } |
| 262 | |
NAKAMURA Takumi | 2de1b32 | 2016-03-07 00:13:09 +0000 | [diff] [blame] | 263 | static BOOL CALLBACK findModuleCallback(PCSTR ModuleName, |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 264 | DWORD64 ModuleBase, ULONG ModuleSize, |
| 265 | void *VoidData) { |
| 266 | FindModuleData *Data = (FindModuleData*)VoidData; |
| 267 | intptr_t Beg = ModuleBase; |
| 268 | intptr_t End = Beg + ModuleSize; |
| 269 | for (int I = 0; I < Data->Depth; I++) { |
| 270 | if (Data->Modules[I]) |
| 271 | continue; |
| 272 | intptr_t Addr = (intptr_t)Data->StackTrace[I]; |
| 273 | if (Beg <= Addr && Addr < End) { |
Mehdi Amini | e4f0b75 | 2016-10-05 01:41:11 +0000 | [diff] [blame] | 274 | Data->Modules[I] = Data->StrPool->save(ModuleName).data(); |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 275 | Data->Offsets[I] = Addr - Beg; |
| 276 | } |
| 277 | } |
| 278 | return TRUE; |
| 279 | } |
| 280 | |
| 281 | static bool findModulesAndOffsets(void **StackTrace, int Depth, |
| 282 | const char **Modules, intptr_t *Offsets, |
| 283 | const char *MainExecutableName, |
| 284 | StringSaver &StrPool) { |
| 285 | if (!fEnumerateLoadedModules) |
| 286 | return false; |
| 287 | FindModuleData Data; |
| 288 | Data.StackTrace = StackTrace; |
| 289 | Data.Depth = Depth; |
| 290 | Data.Modules = Modules; |
| 291 | Data.Offsets = Offsets; |
| 292 | Data.StrPool = &StrPool; |
| 293 | fEnumerateLoadedModules(GetCurrentProcess(), findModuleCallback, &Data); |
| 294 | return true; |
| 295 | } |
| 296 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 297 | static void PrintStackTraceForThread(llvm::raw_ostream &OS, HANDLE hProcess, |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 298 | HANDLE hThread, STACKFRAME64 &StackFrame, |
| 299 | CONTEXT *Context) { |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 300 | // Initialize the symbol handler. |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 301 | fSymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES); |
| 302 | fSymInitialize(hProcess, NULL, TRUE); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 303 | |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 304 | // Try llvm-symbolizer first. llvm-symbolizer knows how to deal with both PDBs |
| 305 | // and DWARF, so it should do a good job regardless of what debug info or |
| 306 | // linker is in use. |
| 307 | if (printStackTraceWithLLVMSymbolizer(OS, hProcess, hThread, StackFrame, |
| 308 | Context)) { |
| 309 | return; |
| 310 | } |
| 311 | |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 312 | while (true) { |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 313 | if (!fStackWalk64(NativeMachineType, hProcess, hThread, &StackFrame, |
| 314 | Context, 0, fSymFunctionTableAccess64, |
| 315 | fSymGetModuleBase64, 0)) { |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 316 | break; |
| 317 | } |
| 318 | |
| 319 | if (StackFrame.AddrFrame.Offset == 0) |
| 320 | break; |
| 321 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 322 | using namespace llvm; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 323 | // Print the PC in hexadecimal. |
| 324 | DWORD64 PC = StackFrame.AddrPC.Offset; |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 325 | #if defined(_M_X64) || defined(_M_ARM64) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 326 | OS << format("0x%016llX", PC); |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 327 | #elif defined(_M_IX86) || defined(_M_ARM) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 328 | OS << format("0x%08lX", static_cast<DWORD>(PC)); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 329 | #endif |
| 330 | |
| 331 | // Print the parameters. Assume there are four. |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 332 | #if defined(_M_X64) || defined(_M_ARM64) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 333 | OS << format(" (0x%016llX 0x%016llX 0x%016llX 0x%016llX)", |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 334 | StackFrame.Params[0], StackFrame.Params[1], StackFrame.Params[2], |
| 335 | StackFrame.Params[3]); |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 336 | #elif defined(_M_IX86) || defined(_M_ARM) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 337 | OS << format(" (0x%08lX 0x%08lX 0x%08lX 0x%08lX)", |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 338 | static_cast<DWORD>(StackFrame.Params[0]), |
| 339 | static_cast<DWORD>(StackFrame.Params[1]), |
| 340 | static_cast<DWORD>(StackFrame.Params[2]), |
| 341 | static_cast<DWORD>(StackFrame.Params[3])); |
| 342 | #endif |
| 343 | // Verify the PC belongs to a module in this process. |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 344 | if (!fSymGetModuleBase64(hProcess, PC)) { |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 345 | OS << " <unknown module>\n"; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 346 | continue; |
| 347 | } |
| 348 | |
| 349 | // Print the symbol name. |
| 350 | char buffer[512]; |
| 351 | IMAGEHLP_SYMBOL64 *symbol = reinterpret_cast<IMAGEHLP_SYMBOL64 *>(buffer); |
| 352 | memset(symbol, 0, sizeof(IMAGEHLP_SYMBOL64)); |
| 353 | symbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); |
| 354 | symbol->MaxNameLength = 512 - sizeof(IMAGEHLP_SYMBOL64); |
| 355 | |
| 356 | DWORD64 dwDisp; |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 357 | if (!fSymGetSymFromAddr64(hProcess, PC, &dwDisp, symbol)) { |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 358 | OS << '\n'; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 359 | continue; |
| 360 | } |
| 361 | |
| 362 | buffer[511] = 0; |
| 363 | if (dwDisp > 0) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 364 | OS << format(", %s() + 0x%llX bytes(s)", (const char*)symbol->Name, |
| 365 | dwDisp); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 366 | else |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 367 | OS << format(", %s", (const char*)symbol->Name); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 368 | |
| 369 | // Print the source file and line number information. |
Yaron Keren | 24a86df | 2015-04-24 15:39:47 +0000 | [diff] [blame] | 370 | IMAGEHLP_LINE64 line = {}; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 371 | DWORD dwLineDisp; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 372 | line.SizeOfStruct = sizeof(line); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 373 | if (fSymGetLineFromAddr64(hProcess, PC, &dwLineDisp, &line)) { |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 374 | OS << format(", %s, line %lu", line.FileName, line.LineNumber); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 375 | if (dwLineDisp > 0) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 376 | OS << format(" + 0x%lX byte(s)", dwLineDisp); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 379 | OS << '\n'; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 383 | namespace llvm { |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 384 | |
| 385 | //===----------------------------------------------------------------------===// |
Mikhail Glushenkov | f64d93d | 2010-10-21 20:40:39 +0000 | [diff] [blame] | 386 | //=== WARNING: Implementation here must contain only Win32 specific code |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 387 | //=== and must not be UNIX code |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 388 | //===----------------------------------------------------------------------===// |
| 389 | |
Daniel Dunbar | 1bdedd3 | 2009-09-22 15:58:35 +0000 | [diff] [blame] | 390 | #ifdef _MSC_VER |
JF Bastien | 93bce51 | 2018-05-15 04:06:28 +0000 | [diff] [blame] | 391 | /// Emulates hitting "retry" from an "abort, retry, ignore" CRT debug report |
| 392 | /// dialog. "retry" raises an exception which ultimately triggers our stack |
| 393 | /// dumper. |
Reid Kleckner | 542a454 | 2015-02-26 21:08:21 +0000 | [diff] [blame] | 394 | static LLVM_ATTRIBUTE_UNUSED int |
| 395 | AvoidMessageBoxHook(int ReportType, char *Message, int *Return) { |
Reid Kleckner | bd39f21 | 2013-04-05 16:18:03 +0000 | [diff] [blame] | 396 | // Set *Return to the retry code for the return value of _CrtDbgReport: |
| 397 | // http://msdn.microsoft.com/en-us/library/8hyw4sy7(v=vs.71).aspx |
| 398 | // This may also trigger just-in-time debugging via DebugBreak(). |
| 399 | if (Return) |
| 400 | *Return = 1; |
| 401 | // Don't call _CrtDbgReport. |
| 402 | return TRUE; |
| 403 | } |
| 404 | |
Daniel Dunbar | 1bdedd3 | 2009-09-22 15:58:35 +0000 | [diff] [blame] | 405 | #endif |
Daniel Dunbar | 4c7b0ca | 2009-09-22 09:50:28 +0000 | [diff] [blame] | 406 | |
Aaron Ballman | 03b968e | 2015-01-29 20:48:34 +0000 | [diff] [blame] | 407 | extern "C" void HandleAbort(int Sig) { |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 408 | if (Sig == SIGABRT) { |
| 409 | LLVM_BUILTIN_TRAP; |
| 410 | } |
| 411 | } |
| 412 | |
Aaron Ballman | 50af8d4 | 2015-03-26 16:24:38 +0000 | [diff] [blame] | 413 | static void InitializeThreading() { |
| 414 | if (CriticalSectionInitialized) |
| 415 | return; |
| 416 | |
| 417 | // Now's the time to create the critical section. This is the first time |
| 418 | // through here, and there's only one thread. |
| 419 | InitializeCriticalSection(&CriticalSection); |
| 420 | CriticalSectionInitialized = true; |
| 421 | } |
| 422 | |
Daniel Dunbar | 4c7b0ca | 2009-09-22 09:50:28 +0000 | [diff] [blame] | 423 | static void RegisterHandler() { |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 424 | // If we cannot load up the APIs (which would be unexpected as they should |
| 425 | // exist on every version of Windows we support), we will bail out since |
| 426 | // there would be nothing to report. |
Reid Kleckner | 6cdf844 | 2016-01-11 21:07:48 +0000 | [diff] [blame] | 427 | if (!load64BitDebugHelp()) { |
| 428 | assert(false && "These APIs should always be available"); |
| 429 | return; |
| 430 | } |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 431 | |
Reid Spencer | 1bdd0f0 | 2004-09-19 05:37:39 +0000 | [diff] [blame] | 432 | if (RegisteredUnhandledExceptionFilter) { |
Reid Spencer | 90debc5 | 2004-09-17 03:02:27 +0000 | [diff] [blame] | 433 | EnterCriticalSection(&CriticalSection); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 434 | return; |
Reid Spencer | 90debc5 | 2004-09-17 03:02:27 +0000 | [diff] [blame] | 435 | } |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 436 | |
Aaron Ballman | 50af8d4 | 2015-03-26 16:24:38 +0000 | [diff] [blame] | 437 | InitializeThreading(); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 438 | |
| 439 | // Enter it immediately. Now if someone hits CTRL/C, the console handler |
| 440 | // can't proceed until the globals are updated. |
| 441 | EnterCriticalSection(&CriticalSection); |
| 442 | |
| 443 | RegisteredUnhandledExceptionFilter = true; |
Reid Spencer | 1bdd0f0 | 2004-09-19 05:37:39 +0000 | [diff] [blame] | 444 | OldFilter = SetUnhandledExceptionFilter(LLVMUnhandledExceptionFilter); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 445 | SetConsoleCtrlHandler(LLVMConsoleCtrlHandler, TRUE); |
| 446 | |
| 447 | // IMPORTANT NOTE: Caller must call LeaveCriticalSection(&CriticalSection) or |
| 448 | // else multi-threading problems will ensue. |
| 449 | } |
| 450 | |
JF Bastien | 93bce51 | 2018-05-15 04:06:28 +0000 | [diff] [blame] | 451 | // The public API |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 452 | bool sys::RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg) { |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 453 | RegisterHandler(); |
| 454 | |
Reid Spencer | 50eac3b | 2006-08-25 21:37:17 +0000 | [diff] [blame] | 455 | if (CleanupExecuted) { |
| 456 | if (ErrMsg) |
| 457 | *ErrMsg = "Process terminating -- cannot register for removal"; |
| 458 | return true; |
| 459 | } |
Reid Spencer | 1bdd0f0 | 2004-09-19 05:37:39 +0000 | [diff] [blame] | 460 | |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 461 | if (FilesToRemove == NULL) |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 462 | FilesToRemove = new std::vector<std::string>; |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 463 | |
Reid Spencer | f070b6c | 2004-11-16 06:59:53 +0000 | [diff] [blame] | 464 | FilesToRemove->push_back(Filename); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 465 | |
| 466 | LeaveCriticalSection(&CriticalSection); |
Reid Spencer | 50eac3b | 2006-08-25 21:37:17 +0000 | [diff] [blame] | 467 | return false; |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 468 | } |
| 469 | |
JF Bastien | 93bce51 | 2018-05-15 04:06:28 +0000 | [diff] [blame] | 470 | // The public API |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 471 | void sys::DontRemoveFileOnSignal(StringRef Filename) { |
Dan Gohman | e201c07 | 2010-09-01 14:17:34 +0000 | [diff] [blame] | 472 | if (FilesToRemove == NULL) |
| 473 | return; |
| 474 | |
NAKAMURA Takumi | 3f688b9 | 2010-10-22 01:23:50 +0000 | [diff] [blame] | 475 | RegisterHandler(); |
| 476 | |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 477 | std::vector<std::string>::reverse_iterator I = |
David Majnemer | 4253126 | 2016-08-12 03:55:06 +0000 | [diff] [blame] | 478 | find(reverse(*FilesToRemove), Filename); |
Dan Gohman | e201c07 | 2010-09-01 14:17:34 +0000 | [diff] [blame] | 479 | if (I != FilesToRemove->rend()) |
| 480 | FilesToRemove->erase(I.base()-1); |
| 481 | |
| 482 | LeaveCriticalSection(&CriticalSection); |
| 483 | } |
| 484 | |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 485 | void sys::DisableSystemDialogsOnCrash() { |
| 486 | // Crash to stack trace handler on abort. |
| 487 | signal(SIGABRT, HandleAbort); |
| 488 | |
| 489 | // The following functions are not reliably accessible on MinGW. |
| 490 | #ifdef _MSC_VER |
| 491 | // We're already handling writing a "something went wrong" message. |
| 492 | _set_abort_behavior(0, _WRITE_ABORT_MSG); |
| 493 | // Disable Dr. Watson. |
| 494 | _set_abort_behavior(0, _CALL_REPORTFAULT); |
| 495 | _CrtSetReportHook(AvoidMessageBoxHook); |
| 496 | #endif |
| 497 | |
| 498 | // Disable standard error dialog box. |
| 499 | SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | |
| 500 | SEM_NOOPENFILEERRORBOX); |
| 501 | _set_error_mode(_OUT_TO_STDERR); |
| 502 | } |
| 503 | |
JF Bastien | 93bce51 | 2018-05-15 04:06:28 +0000 | [diff] [blame] | 504 | /// When an error signal (such as SIGABRT or SIGSEGV) is delivered to the |
| 505 | /// process, print a stack trace and then exit. |
Richard Smith | 2ad6d48 | 2016-06-09 00:53:21 +0000 | [diff] [blame] | 506 | void sys::PrintStackTraceOnErrorSignal(StringRef Argv0, |
| 507 | bool DisableCrashReporting) { |
| 508 | ::Argv0 = Argv0; |
| 509 | |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 510 | if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT")) |
| 511 | Process::PreventCoreFiles(); |
| 512 | |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 513 | DisableSystemDialogsOnCrash(); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 514 | RegisterHandler(); |
| 515 | LeaveCriticalSection(&CriticalSection); |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 516 | } |
Benjamin Kramer | f97eff6 | 2015-03-11 15:41:15 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Yaron Keren | bdae8d6 | 2015-03-14 19:20:56 +0000 | [diff] [blame] | 519 | #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) |
| 520 | // Provide a prototype for RtlCaptureContext, mingw32 from mingw.org is |
| 521 | // missing it but mingw-w64 has it. |
Benjamin Kramer | f97eff6 | 2015-03-11 15:41:15 +0000 | [diff] [blame] | 522 | extern "C" VOID WINAPI RtlCaptureContext(PCONTEXT ContextRecord); |
Benjamin Kramer | b47d549 | 2015-03-11 16:09:02 +0000 | [diff] [blame] | 523 | #endif |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 524 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 525 | void llvm::sys::PrintStackTrace(raw_ostream &OS) { |
Reid Kleckner | e658058 | 2015-03-05 18:26:58 +0000 | [diff] [blame] | 526 | STACKFRAME64 StackFrame = {}; |
Yaron Keren | 24a86df | 2015-04-24 15:39:47 +0000 | [diff] [blame] | 527 | CONTEXT Context = {}; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 528 | ::RtlCaptureContext(&Context); |
| 529 | #if defined(_M_X64) |
| 530 | StackFrame.AddrPC.Offset = Context.Rip; |
| 531 | StackFrame.AddrStack.Offset = Context.Rsp; |
| 532 | StackFrame.AddrFrame.Offset = Context.Rbp; |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 533 | #elif defined(_M_IX86) |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 534 | StackFrame.AddrPC.Offset = Context.Eip; |
| 535 | StackFrame.AddrStack.Offset = Context.Esp; |
| 536 | StackFrame.AddrFrame.Offset = Context.Ebp; |
Martin Storsjo | 8293161 | 2018-04-13 06:38:02 +0000 | [diff] [blame] | 537 | #elif defined(_M_ARM64) |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 538 | StackFrame.AddrPC.Offset = Context.Pc; |
| 539 | StackFrame.AddrStack.Offset = Context.Sp; |
| 540 | StackFrame.AddrFrame.Offset = Context.Fp; |
Martin Storsjo | 8293161 | 2018-04-13 06:38:02 +0000 | [diff] [blame] | 541 | #elif defined(_M_ARM) |
| 542 | StackFrame.AddrPC.Offset = Context.Pc; |
| 543 | StackFrame.AddrStack.Offset = Context.Sp; |
| 544 | StackFrame.AddrFrame.Offset = Context.R11; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 545 | #endif |
| 546 | StackFrame.AddrPC.Mode = AddrModeFlat; |
| 547 | StackFrame.AddrStack.Mode = AddrModeFlat; |
| 548 | StackFrame.AddrFrame.Mode = AddrModeFlat; |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 549 | PrintStackTraceForThread(OS, GetCurrentProcess(), GetCurrentThread(), |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 550 | StackFrame, &Context); |
Argyrios Kyrtzidis | eb9ae76 | 2013-01-09 19:42:40 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Chris Lattner | 6a5d6ec | 2005-08-02 02:14:22 +0000 | [diff] [blame] | 553 | |
Benjamin Kramer | 90c2db2 | 2015-03-11 15:53:24 +0000 | [diff] [blame] | 554 | void llvm::sys::SetInterruptFunction(void (*IF)()) { |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 555 | RegisterHandler(); |
Jeff Cohen | 9aafa06 | 2005-08-02 03:26:32 +0000 | [diff] [blame] | 556 | InterruptFunction = IF; |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 557 | LeaveCriticalSection(&CriticalSection); |
Chris Lattner | 6a5d6ec | 2005-08-02 02:14:22 +0000 | [diff] [blame] | 558 | } |
Sebastian Redl | 8d5baa0 | 2009-03-19 23:26:52 +0000 | [diff] [blame] | 559 | |
| 560 | |
JF Bastien | 93bce51 | 2018-05-15 04:06:28 +0000 | [diff] [blame] | 561 | /// Add a function to be called when a signal is delivered to the process. The |
| 562 | /// handler can have a cookie passed to it to identify what instance of the |
| 563 | /// handler it is. |
JF Bastien | aa1333a | 2018-05-16 17:25:35 +0000 | [diff] [blame] | 564 | void llvm::sys::AddSignalHandler(sys::SignalHandlerCallback FnPtr, |
| 565 | void *Cookie) { |
| 566 | insertSignalHandler(FnPtr, Cookie); |
Sebastian Redl | 8d5baa0 | 2009-03-19 23:26:52 +0000 | [diff] [blame] | 567 | RegisterHandler(); |
Torok Edwin | 6fb0956 | 2010-03-31 12:07:16 +0000 | [diff] [blame] | 568 | LeaveCriticalSection(&CriticalSection); |
Sebastian Redl | 8d5baa0 | 2009-03-19 23:26:52 +0000 | [diff] [blame] | 569 | } |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 570 | |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 571 | static void Cleanup() { |
Yaron Keren | 356aa46 | 2015-05-19 13:31:25 +0000 | [diff] [blame] | 572 | if (CleanupExecuted) |
| 573 | return; |
| 574 | |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 575 | EnterCriticalSection(&CriticalSection); |
| 576 | |
Reid Spencer | 1bdd0f0 | 2004-09-19 05:37:39 +0000 | [diff] [blame] | 577 | // Prevent other thread from registering new files and directories for |
| 578 | // removal, should we be executing because of the console handler callback. |
| 579 | CleanupExecuted = true; |
| 580 | |
| 581 | // FIXME: open files cannot be deleted. |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 582 | if (FilesToRemove != NULL) |
| 583 | while (!FilesToRemove->empty()) { |
Rafael Espindola | d724c28 | 2014-02-23 13:37:37 +0000 | [diff] [blame] | 584 | llvm::sys::fs::remove(FilesToRemove->back()); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 585 | FilesToRemove->pop_back(); |
| 586 | } |
Yaron Keren | 2873810 | 2015-07-22 21:11:17 +0000 | [diff] [blame] | 587 | llvm::sys::RunSignalHandlers(); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 588 | LeaveCriticalSection(&CriticalSection); |
| 589 | } |
| 590 | |
Daniel Dunbar | 6827256 | 2010-05-08 02:10:34 +0000 | [diff] [blame] | 591 | void llvm::sys::RunInterruptHandlers() { |
Aaron Ballman | 50af8d4 | 2015-03-26 16:24:38 +0000 | [diff] [blame] | 592 | // The interrupt handler may be called from an interrupt, but it may also be |
| 593 | // called manually (such as the case of report_fatal_error with no registered |
| 594 | // error handler). We must ensure that the critical section is properly |
| 595 | // initialized. |
| 596 | InitializeThreading(); |
Daniel Dunbar | 6827256 | 2010-05-08 02:10:34 +0000 | [diff] [blame] | 597 | Cleanup(); |
| 598 | } |
| 599 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 600 | /// Find the Windows Registry Key for a given location. |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 601 | /// |
| 602 | /// \returns a valid HKEY if the location exists, else NULL. |
| 603 | static HKEY FindWERKey(const llvm::Twine &RegistryLocation) { |
| 604 | HKEY Key; |
Aaron Ballman | 0da8b2e | 2016-06-23 14:45:54 +0000 | [diff] [blame] | 605 | if (ERROR_SUCCESS != ::RegOpenKeyExA(HKEY_LOCAL_MACHINE, |
| 606 | RegistryLocation.str().c_str(), 0, |
| 607 | KEY_QUERY_VALUE | KEY_READ, &Key)) |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 608 | return NULL; |
| 609 | |
| 610 | return Key; |
| 611 | } |
| 612 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 613 | /// Populate ResultDirectory with the value for "DumpFolder" for a given |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 614 | /// Windows Registry key. |
| 615 | /// |
| 616 | /// \returns true if a valid value for DumpFolder exists, false otherwise. |
| 617 | static bool GetDumpFolder(HKEY Key, |
| 618 | llvm::SmallVectorImpl<char> &ResultDirectory) { |
| 619 | using llvm::sys::windows::UTF16ToUTF8; |
| 620 | |
| 621 | if (!Key) |
| 622 | return false; |
| 623 | |
| 624 | DWORD BufferLengthBytes = 0; |
| 625 | |
| 626 | if (ERROR_SUCCESS != ::RegGetValueW(Key, 0, L"DumpFolder", REG_EXPAND_SZ, |
| 627 | NULL, NULL, &BufferLengthBytes)) |
| 628 | return false; |
| 629 | |
| 630 | SmallVector<wchar_t, MAX_PATH> Buffer(BufferLengthBytes); |
| 631 | |
| 632 | if (ERROR_SUCCESS != ::RegGetValueW(Key, 0, L"DumpFolder", REG_EXPAND_SZ, |
| 633 | NULL, Buffer.data(), &BufferLengthBytes)) |
| 634 | return false; |
| 635 | |
| 636 | DWORD ExpandBufferSize = ::ExpandEnvironmentStringsW(Buffer.data(), NULL, 0); |
| 637 | |
| 638 | if (!ExpandBufferSize) |
| 639 | return false; |
| 640 | |
| 641 | SmallVector<wchar_t, MAX_PATH> ExpandBuffer(ExpandBufferSize); |
| 642 | |
| 643 | if (ExpandBufferSize != ::ExpandEnvironmentStringsW(Buffer.data(), |
| 644 | ExpandBuffer.data(), |
| 645 | ExpandBufferSize)) |
| 646 | return false; |
| 647 | |
| 648 | if (UTF16ToUTF8(ExpandBuffer.data(), ExpandBufferSize - 1, ResultDirectory)) |
| 649 | return false; |
| 650 | |
| 651 | return true; |
| 652 | } |
| 653 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 654 | /// Populate ResultType with a valid MINIDUMP_TYPE based on the value of |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 655 | /// "DumpType" for a given Windows Registry key. |
| 656 | /// |
| 657 | /// According to |
| 658 | /// https://msdn.microsoft.com/en-us/library/windows/desktop/bb787181(v=vs.85).aspx |
| 659 | /// valid values for DumpType are: |
| 660 | /// * 0: Custom dump |
| 661 | /// * 1: Mini dump |
| 662 | /// * 2: Full dump |
| 663 | /// If "Custom dump" is specified then the "CustomDumpFlags" field is read |
| 664 | /// containing a bitwise combination of MINIDUMP_TYPE values. |
| 665 | /// |
| 666 | /// \returns true if a valid value for ResultType can be set, false otherwise. |
| 667 | static bool GetDumpType(HKEY Key, MINIDUMP_TYPE &ResultType) { |
| 668 | if (!Key) |
| 669 | return false; |
| 670 | |
| 671 | DWORD DumpType; |
| 672 | DWORD TypeSize = sizeof(DumpType); |
| 673 | if (ERROR_SUCCESS != ::RegGetValueW(Key, NULL, L"DumpType", RRF_RT_REG_DWORD, |
| 674 | NULL, &DumpType, |
| 675 | &TypeSize)) |
| 676 | return false; |
| 677 | |
| 678 | switch (DumpType) { |
| 679 | case 0: { |
| 680 | DWORD Flags = 0; |
| 681 | if (ERROR_SUCCESS != ::RegGetValueW(Key, NULL, L"CustomDumpFlags", |
| 682 | RRF_RT_REG_DWORD, NULL, &Flags, |
| 683 | &TypeSize)) |
| 684 | return false; |
| 685 | |
| 686 | ResultType = static_cast<MINIDUMP_TYPE>(Flags); |
| 687 | break; |
| 688 | } |
| 689 | case 1: |
| 690 | ResultType = MiniDumpNormal; |
| 691 | break; |
| 692 | case 2: |
| 693 | ResultType = MiniDumpWithFullMemory; |
| 694 | break; |
| 695 | default: |
| 696 | return false; |
| 697 | } |
| 698 | return true; |
| 699 | } |
| 700 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 701 | /// Write a Windows dump file containing process information that can be |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 702 | /// used for post-mortem debugging. |
| 703 | /// |
| 704 | /// \returns zero error code if a mini dump created, actual error code |
| 705 | /// otherwise. |
| 706 | static std::error_code WINAPI |
| 707 | WriteWindowsDumpFile(PMINIDUMP_EXCEPTION_INFORMATION ExceptionInfo) { |
| 708 | using namespace llvm; |
| 709 | using namespace llvm::sys; |
| 710 | |
| 711 | std::string MainExecutableName = fs::getMainExecutable(nullptr, nullptr); |
| 712 | StringRef ProgramName; |
| 713 | |
| 714 | if (MainExecutableName.empty()) { |
| 715 | // If we can't get the executable filename, |
| 716 | // things are in worse shape than we realize |
| 717 | // and we should just bail out. |
| 718 | return mapWindowsError(::GetLastError()); |
| 719 | } |
| 720 | |
| 721 | ProgramName = path::filename(MainExecutableName.c_str()); |
| 722 | |
| 723 | // The Windows Registry location as specified at |
| 724 | // https://msdn.microsoft.com/en-us/library/windows/desktop/bb787181%28v=vs.85%29.aspx |
| 725 | // "Collecting User-Mode Dumps" that may optionally be set to collect crash |
| 726 | // dumps in a specified location. |
| 727 | StringRef LocalDumpsRegistryLocation = |
| 728 | "SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\LocalDumps"; |
| 729 | |
| 730 | // The key pointing to the Registry location that may contain global crash |
| 731 | // dump settings. This will be NULL if the location can not be found. |
| 732 | ScopedRegHandle DefaultLocalDumpsKey(FindWERKey(LocalDumpsRegistryLocation)); |
| 733 | |
| 734 | // The key pointing to the Registry location that may contain |
| 735 | // application-specific crash dump settings. This will be NULL if the |
| 736 | // location can not be found. |
| 737 | ScopedRegHandle AppSpecificKey( |
| 738 | FindWERKey(Twine(LocalDumpsRegistryLocation) + "\\" + ProgramName)); |
| 739 | |
| 740 | // Look to see if a dump type is specified in the registry; first with the |
| 741 | // app-specific key and failing that with the global key. If none are found |
| 742 | // default to a normal dump (GetDumpType will return false either if the key |
| 743 | // is NULL or if there is no valid DumpType value at its location). |
| 744 | MINIDUMP_TYPE DumpType; |
| 745 | if (!GetDumpType(AppSpecificKey, DumpType)) |
| 746 | if (!GetDumpType(DefaultLocalDumpsKey, DumpType)) |
| 747 | DumpType = MiniDumpNormal; |
| 748 | |
| 749 | // Look to see if a dump location is specified in the registry; first with the |
| 750 | // app-specific key and failing that with the global key. If none are found |
| 751 | // we'll just create the dump file in the default temporary file location |
| 752 | // (GetDumpFolder will return false either if the key is NULL or if there is |
| 753 | // no valid DumpFolder value at its location). |
| 754 | bool ExplicitDumpDirectorySet = true; |
| 755 | SmallString<MAX_PATH> DumpDirectory; |
| 756 | if (!GetDumpFolder(AppSpecificKey, DumpDirectory)) |
| 757 | if (!GetDumpFolder(DefaultLocalDumpsKey, DumpDirectory)) |
| 758 | ExplicitDumpDirectorySet = false; |
| 759 | |
| 760 | int FD; |
| 761 | SmallString<MAX_PATH> DumpPath; |
| 762 | |
| 763 | if (ExplicitDumpDirectorySet) { |
| 764 | if (std::error_code EC = fs::create_directories(DumpDirectory)) |
| 765 | return EC; |
| 766 | if (std::error_code EC = fs::createUniqueFile( |
| 767 | Twine(DumpDirectory) + "\\" + ProgramName + ".%%%%%%.dmp", FD, |
| 768 | DumpPath)) |
| 769 | return EC; |
| 770 | } else if (std::error_code EC = |
| 771 | fs::createTemporaryFile(ProgramName, "dmp", FD, DumpPath)) |
| 772 | return EC; |
| 773 | |
| 774 | // Our support functions return a file descriptor but Windows wants a handle. |
| 775 | ScopedCommonHandle FileHandle(reinterpret_cast<HANDLE>(_get_osfhandle(FD))); |
| 776 | |
| 777 | if (!fMiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), |
| 778 | FileHandle, DumpType, ExceptionInfo, NULL, NULL)) |
| 779 | return mapWindowsError(::GetLastError()); |
| 780 | |
| 781 | llvm::errs() << "Wrote crash dump file \"" << DumpPath << "\"\n"; |
| 782 | return std::error_code(); |
| 783 | } |
| 784 | |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 785 | static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { |
Mikhail Glushenkov | 32acd74 | 2010-10-27 09:09:04 +0000 | [diff] [blame] | 786 | Cleanup(); |
Mikhail Glushenkov | f64d93d | 2010-10-21 20:40:39 +0000 | [diff] [blame] | 787 | |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 788 | // We'll automatically write a Minidump file here to help diagnose |
| 789 | // the nasty sorts of crashes that aren't 100% reproducible from a set of |
| 790 | // inputs (or in the event that the user is unable or unwilling to provide a |
| 791 | // reproducible case). |
Kristof Beyls | 7adf8c5 | 2017-03-31 14:58:52 +0000 | [diff] [blame] | 792 | if (!llvm::sys::Process::AreCoreFilesPrevented()) { |
Leny Kholodov | 1b73e66 | 2016-05-04 16:56:51 +0000 | [diff] [blame] | 793 | MINIDUMP_EXCEPTION_INFORMATION ExceptionInfo; |
| 794 | ExceptionInfo.ThreadId = ::GetCurrentThreadId(); |
| 795 | ExceptionInfo.ExceptionPointers = ep; |
| 796 | ExceptionInfo.ClientPointers = FALSE; |
| 797 | |
| 798 | if (std::error_code EC = WriteWindowsDumpFile(&ExceptionInfo)) |
| 799 | llvm::errs() << "Could not write crash dump file: " << EC.message() |
| 800 | << "\n"; |
| 801 | } |
| 802 | |
Mikhail Glushenkov | 080d86f | 2010-10-28 08:25:44 +0000 | [diff] [blame] | 803 | // Initialize the STACKFRAME structure. |
Yaron Keren | 24a86df | 2015-04-24 15:39:47 +0000 | [diff] [blame] | 804 | STACKFRAME64 StackFrame = {}; |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 805 | |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 806 | #if defined(_M_X64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 807 | StackFrame.AddrPC.Offset = ep->ContextRecord->Rip; |
| 808 | StackFrame.AddrPC.Mode = AddrModeFlat; |
| 809 | StackFrame.AddrStack.Offset = ep->ContextRecord->Rsp; |
| 810 | StackFrame.AddrStack.Mode = AddrModeFlat; |
| 811 | StackFrame.AddrFrame.Offset = ep->ContextRecord->Rbp; |
| 812 | StackFrame.AddrFrame.Mode = AddrModeFlat; |
| 813 | #elif defined(_M_IX86) |
Mikhail Glushenkov | 080d86f | 2010-10-28 08:25:44 +0000 | [diff] [blame] | 814 | StackFrame.AddrPC.Offset = ep->ContextRecord->Eip; |
| 815 | StackFrame.AddrPC.Mode = AddrModeFlat; |
| 816 | StackFrame.AddrStack.Offset = ep->ContextRecord->Esp; |
| 817 | StackFrame.AddrStack.Mode = AddrModeFlat; |
| 818 | StackFrame.AddrFrame.Offset = ep->ContextRecord->Ebp; |
| 819 | StackFrame.AddrFrame.Mode = AddrModeFlat; |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 820 | #elif defined(_M_ARM64) || defined(_M_ARM) |
| 821 | StackFrame.AddrPC.Offset = ep->ContextRecord->Pc; |
| 822 | StackFrame.AddrPC.Mode = AddrModeFlat; |
| 823 | StackFrame.AddrStack.Offset = ep->ContextRecord->Sp; |
| 824 | StackFrame.AddrStack.Mode = AddrModeFlat; |
Martin Storsjo | 8293161 | 2018-04-13 06:38:02 +0000 | [diff] [blame] | 825 | #if defined(_M_ARM64) |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 826 | StackFrame.AddrFrame.Offset = ep->ContextRecord->Fp; |
Martin Storsjo | 8293161 | 2018-04-13 06:38:02 +0000 | [diff] [blame] | 827 | #else |
| 828 | StackFrame.AddrFrame.Offset = ep->ContextRecord->R11; |
| 829 | #endif |
Martell Malone | 346a5fd | 2017-08-03 23:12:33 +0000 | [diff] [blame] | 830 | StackFrame.AddrFrame.Mode = AddrModeFlat; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 831 | #endif |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 832 | |
Mikhail Glushenkov | 080d86f | 2010-10-28 08:25:44 +0000 | [diff] [blame] | 833 | HANDLE hProcess = GetCurrentProcess(); |
| 834 | HANDLE hThread = GetCurrentThread(); |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 835 | PrintStackTraceForThread(llvm::errs(), hProcess, hThread, StackFrame, |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 836 | ep->ContextRecord); |
Mikhail Glushenkov | 080d86f | 2010-10-28 08:25:44 +0000 | [diff] [blame] | 837 | |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 838 | _exit(ep->ExceptionRecord->ExceptionCode); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) { |
Jeff Cohen | 9aafa06 | 2005-08-02 03:26:32 +0000 | [diff] [blame] | 842 | // We are running in our very own thread, courtesy of Windows. |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 843 | EnterCriticalSection(&CriticalSection); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 844 | Cleanup(); |
| 845 | |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 846 | // If an interrupt function has been set, go and run one it; otherwise, |
| 847 | // the process dies. |
| 848 | void (*IF)() = InterruptFunction; |
| 849 | InterruptFunction = 0; // Don't run it on another CTRL-C. |
| 850 | |
| 851 | if (IF) { |
Jeff Cohen | 9aafa06 | 2005-08-02 03:26:32 +0000 | [diff] [blame] | 852 | // Note: if the interrupt function throws an exception, there is nothing |
| 853 | // to catch it in this thread so it will kill the process. |
| 854 | IF(); // Run it now. |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 855 | LeaveCriticalSection(&CriticalSection); |
| 856 | return TRUE; // Don't kill the process. |
| 857 | } |
| 858 | |
Reid Spencer | 90debc5 | 2004-09-17 03:02:27 +0000 | [diff] [blame] | 859 | // Allow normal processing to take place; i.e., the process dies. |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 860 | LeaveCriticalSection(&CriticalSection); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 861 | return FALSE; |
| 862 | } |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 863 | |
| 864 | #if __MINGW32__ |
| 865 | // We turned these warnings off for this file so that MinGW-g++ doesn't |
| 866 | // complain about the ll format specifiers used. Now we are turning the |
| 867 | // warnings back on. If MinGW starts to support diagnostic stacks, we can |
| 868 | // replace this with a pop. |
| 869 | #pragma GCC diagnostic warning "-Wformat" |
| 870 | #pragma GCC diagnostic warning "-Wformat-extra-args" |
| 871 | #endif |