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 | //===----------------------------------------------------------------------===// |
Rafael Espindola | 9aa3d5d | 2013-06-14 13:59:21 +0000 | [diff] [blame] | 13 | #include "llvm/Support/FileSystem.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 14 | #include <algorithm> |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 15 | #include <signal.h> |
Reid Spencer | 70b6835 | 2004-09-28 23:58:03 +0000 | [diff] [blame] | 16 | #include <stdio.h> |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 17 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Format.h" |
| 19 | #include "llvm/Support/raw_ostream.h" |
| 20 | |
Chandler Carruth | 10b0915 | 2014-01-07 12:37:13 +0000 | [diff] [blame] | 21 | // The Windows.h header must be after LLVM and standard headers. |
Reid Kleckner | d59e2fa | 2014-02-12 21:26:20 +0000 | [diff] [blame] | 22 | #include "WindowsSupport.h" |
Chandler Carruth | 10b0915 | 2014-01-07 12:37:13 +0000 | [diff] [blame] | 23 | |
Jeff Cohen | 07e22ba | 2005-02-19 03:01:13 +0000 | [diff] [blame] | 24 | #ifdef __MINGW32__ |
Reid Spencer | 187b4ad | 2006-06-01 19:03:21 +0000 | [diff] [blame] | 25 | #include <imagehlp.h> |
Reid Spencer | 9904928 | 2004-09-23 14:47:10 +0000 | [diff] [blame] | 26 | #else |
Reid Spencer | 187b4ad | 2006-06-01 19:03:21 +0000 | [diff] [blame] | 27 | #include <dbghelp.h> |
Reid Spencer | 9904928 | 2004-09-23 14:47:10 +0000 | [diff] [blame] | 28 | #endif |
| 29 | #include <psapi.h> |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 30 | |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 31 | #ifdef _MSC_VER |
| 32 | #pragma comment(lib, "psapi.lib") |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 33 | #elif __MINGW32__ |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 34 | #if (HAVE_LIBPSAPI != 1) |
| 35 | #error "libpsapi.a should be present" |
Reid Spencer | 187b4ad | 2006-06-01 19:03:21 +0000 | [diff] [blame] | 36 | #endif |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 37 | // The version of g++ that comes with MinGW does *not* properly understand |
| 38 | // the ll format specifier for printf. However, MinGW passes the format |
| 39 | // specifiers on to the MSVCRT entirely, and the CRT understands the ll |
| 40 | // specifier. So these warnings are spurious in this case. Since we compile |
| 41 | // with -Wall, this will generate these warnings which should be ignored. So |
| 42 | // we will turn off the warnings for this just file. However, MinGW also does |
| 43 | // not support push and pop for diagnostics, so we have to manually turn it |
| 44 | // back on at the end of the file. |
| 45 | #pragma GCC diagnostic ignored "-Wformat" |
| 46 | #pragma GCC diagnostic ignored "-Wformat-extra-args" |
| 47 | |
Anton Korobeynikov | b27f11e | 2011-10-21 09:38:50 +0000 | [diff] [blame] | 48 | #if !defined(__MINGW64_VERSION_MAJOR) |
| 49 | // MinGW.org does not have updated support for the 64-bit versions of the |
| 50 | // DebugHlp APIs. So we will have to load them manually. The structures and |
| 51 | // method signatures were pulled from DbgHelp.h in the Windows Platform SDK, |
| 52 | // and adjusted for brevity. |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 53 | typedef struct _IMAGEHLP_LINE64 { |
| 54 | DWORD SizeOfStruct; |
| 55 | PVOID Key; |
| 56 | DWORD LineNumber; |
| 57 | PCHAR FileName; |
| 58 | DWORD64 Address; |
| 59 | } IMAGEHLP_LINE64, *PIMAGEHLP_LINE64; |
| 60 | |
| 61 | typedef struct _IMAGEHLP_SYMBOL64 { |
| 62 | DWORD SizeOfStruct; |
| 63 | DWORD64 Address; |
| 64 | DWORD Size; |
| 65 | DWORD Flags; |
| 66 | DWORD MaxNameLength; |
| 67 | CHAR Name[1]; |
| 68 | } IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64; |
| 69 | |
| 70 | typedef struct _tagADDRESS64 { |
| 71 | DWORD64 Offset; |
| 72 | WORD Segment; |
| 73 | ADDRESS_MODE Mode; |
| 74 | } ADDRESS64, *LPADDRESS64; |
| 75 | |
| 76 | typedef struct _KDHELP64 { |
| 77 | DWORD64 Thread; |
| 78 | DWORD ThCallbackStack; |
| 79 | DWORD ThCallbackBStore; |
| 80 | DWORD NextCallback; |
| 81 | DWORD FramePointer; |
| 82 | DWORD64 KiCallUserMode; |
| 83 | DWORD64 KeUserCallbackDispatcher; |
| 84 | DWORD64 SystemRangeStart; |
| 85 | DWORD64 KiUserExceptionDispatcher; |
| 86 | DWORD64 StackBase; |
| 87 | DWORD64 StackLimit; |
| 88 | DWORD64 Reserved[5]; |
| 89 | } KDHELP64, *PKDHELP64; |
| 90 | |
| 91 | typedef struct _tagSTACKFRAME64 { |
| 92 | ADDRESS64 AddrPC; |
| 93 | ADDRESS64 AddrReturn; |
| 94 | ADDRESS64 AddrFrame; |
| 95 | ADDRESS64 AddrStack; |
| 96 | ADDRESS64 AddrBStore; |
| 97 | PVOID FuncTableEntry; |
| 98 | DWORD64 Params[4]; |
| 99 | BOOL Far; |
| 100 | BOOL Virtual; |
| 101 | DWORD64 Reserved[3]; |
| 102 | KDHELP64 KdHelp; |
| 103 | } STACKFRAME64, *LPSTACKFRAME64; |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 104 | #endif // !defined(__MINGW64_VERSION_MAJOR) |
| 105 | #endif // __MINGW32__ |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 106 | |
| 107 | typedef BOOL (__stdcall *PREAD_PROCESS_MEMORY_ROUTINE64)(HANDLE hProcess, |
| 108 | DWORD64 qwBaseAddress, PVOID lpBuffer, DWORD nSize, |
| 109 | LPDWORD lpNumberOfBytesRead); |
| 110 | |
| 111 | typedef PVOID (__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE64)( HANDLE ahProcess, |
| 112 | DWORD64 AddrBase); |
| 113 | |
| 114 | typedef DWORD64 (__stdcall *PGET_MODULE_BASE_ROUTINE64)(HANDLE hProcess, |
| 115 | DWORD64 Address); |
| 116 | |
| 117 | typedef DWORD64 (__stdcall *PTRANSLATE_ADDRESS_ROUTINE64)(HANDLE hProcess, |
| 118 | HANDLE hThread, LPADDRESS64 lpaddr); |
| 119 | |
| 120 | typedef BOOL (WINAPI *fpStackWalk64)(DWORD, HANDLE, HANDLE, LPSTACKFRAME64, |
| 121 | PVOID, PREAD_PROCESS_MEMORY_ROUTINE64, |
| 122 | PFUNCTION_TABLE_ACCESS_ROUTINE64, |
| 123 | PGET_MODULE_BASE_ROUTINE64, |
| 124 | PTRANSLATE_ADDRESS_ROUTINE64); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 125 | static fpStackWalk64 fStackWalk64; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 126 | |
| 127 | typedef DWORD64 (WINAPI *fpSymGetModuleBase64)(HANDLE, DWORD64); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 128 | static fpSymGetModuleBase64 fSymGetModuleBase64; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 129 | |
| 130 | typedef BOOL (WINAPI *fpSymGetSymFromAddr64)(HANDLE, DWORD64, |
| 131 | PDWORD64, PIMAGEHLP_SYMBOL64); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 132 | static fpSymGetSymFromAddr64 fSymGetSymFromAddr64; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 133 | |
| 134 | typedef BOOL (WINAPI *fpSymGetLineFromAddr64)(HANDLE, DWORD64, |
| 135 | PDWORD, PIMAGEHLP_LINE64); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 136 | static fpSymGetLineFromAddr64 fSymGetLineFromAddr64; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 137 | |
| 138 | typedef PVOID (WINAPI *fpSymFunctionTableAccess64)(HANDLE, DWORD64); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 139 | static fpSymFunctionTableAccess64 fSymFunctionTableAccess64; |
| 140 | |
| 141 | typedef DWORD (WINAPI *fpSymSetOptions)(DWORD); |
| 142 | static fpSymSetOptions fSymSetOptions; |
| 143 | |
| 144 | typedef BOOL (WINAPI *fpSymInitialize)(HANDLE, PCSTR, BOOL); |
| 145 | static fpSymInitialize fSymInitialize; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 146 | |
| 147 | static bool load64BitDebugHelp(void) { |
David Majnemer | 17a4496 | 2013-10-07 09:52:36 +0000 | [diff] [blame] | 148 | HMODULE hLib = ::LoadLibraryW(L"Dbghelp.dll"); |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 149 | if (hLib) { |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 150 | fStackWalk64 = (fpStackWalk64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 151 | ::GetProcAddress(hLib, "StackWalk64"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 152 | fSymGetModuleBase64 = (fpSymGetModuleBase64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 153 | ::GetProcAddress(hLib, "SymGetModuleBase64"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 154 | fSymGetSymFromAddr64 = (fpSymGetSymFromAddr64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 155 | ::GetProcAddress(hLib, "SymGetSymFromAddr64"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 156 | fSymGetLineFromAddr64 = (fpSymGetLineFromAddr64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 157 | ::GetProcAddress(hLib, "SymGetLineFromAddr64"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 158 | fSymFunctionTableAccess64 = (fpSymFunctionTableAccess64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 159 | ::GetProcAddress(hLib, "SymFunctionTableAccess64"); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 160 | fSymSetOptions = (fpSymSetOptions)::GetProcAddress(hLib, "SymSetOptions"); |
| 161 | fSymInitialize = (fpSymInitialize)::GetProcAddress(hLib, "SymInitialize"); |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 162 | } |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 163 | return fStackWalk64 && fSymInitialize && fSymSetOptions; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 164 | } |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 165 | |
Yaron Keren | 240bd9c | 2015-07-22 19:01:14 +0000 | [diff] [blame] | 166 | using namespace llvm; |
| 167 | |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 168 | // Forward declare. |
| 169 | static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep); |
| 170 | static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType); |
| 171 | |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 172 | // InterruptFunction - The function to call if ctrl-c is pressed. |
| 173 | static void (*InterruptFunction)() = 0; |
| 174 | |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 175 | static std::vector<std::string> *FilesToRemove = NULL; |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 176 | static bool RegisteredUnhandledExceptionFilter = false; |
Reid Spencer | 1bdd0f0 | 2004-09-19 05:37:39 +0000 | [diff] [blame] | 177 | static bool CleanupExecuted = false; |
| 178 | static PTOP_LEVEL_EXCEPTION_FILTER OldFilter = NULL; |
Reid Spencer | 90debc5 | 2004-09-17 03:02:27 +0000 | [diff] [blame] | 179 | |
| 180 | // Windows creates a new thread to execute the console handler when an event |
| 181 | // (such as CTRL/C) occurs. This causes concurrency issues with the above |
| 182 | // globals which this critical section addresses. |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 183 | static CRITICAL_SECTION CriticalSection; |
Aaron Ballman | 50af8d4 | 2015-03-26 16:24:38 +0000 | [diff] [blame] | 184 | static bool CriticalSectionInitialized = false; |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 185 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 186 | static void PrintStackTraceForThread(llvm::raw_ostream &OS, HANDLE hProcess, |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 187 | HANDLE hThread, STACKFRAME64 &StackFrame, |
| 188 | CONTEXT *Context) { |
| 189 | DWORD machineType; |
| 190 | #if defined(_M_X64) |
| 191 | machineType = IMAGE_FILE_MACHINE_AMD64; |
| 192 | #else |
| 193 | machineType = IMAGE_FILE_MACHINE_I386; |
| 194 | #endif |
| 195 | |
| 196 | // Initialize the symbol handler. |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 197 | fSymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES); |
| 198 | fSymInitialize(hProcess, NULL, TRUE); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 199 | |
| 200 | while (true) { |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 201 | if (!fStackWalk64(machineType, hProcess, hThread, &StackFrame, Context, 0, |
| 202 | fSymFunctionTableAccess64, fSymGetModuleBase64, 0)) { |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 203 | break; |
| 204 | } |
| 205 | |
| 206 | if (StackFrame.AddrFrame.Offset == 0) |
| 207 | break; |
| 208 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 209 | using namespace llvm; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 210 | // Print the PC in hexadecimal. |
| 211 | DWORD64 PC = StackFrame.AddrPC.Offset; |
| 212 | #if defined(_M_X64) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 213 | OS << format("0x%016llX", PC); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 214 | #elif defined(_M_IX86) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 215 | OS << format("0x%08lX", static_cast<DWORD>(PC)); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 216 | #endif |
| 217 | |
| 218 | // Print the parameters. Assume there are four. |
| 219 | #if defined(_M_X64) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 220 | OS << format(" (0x%016llX 0x%016llX 0x%016llX 0x%016llX)", |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 221 | StackFrame.Params[0], StackFrame.Params[1], StackFrame.Params[2], |
| 222 | StackFrame.Params[3]); |
| 223 | #elif defined(_M_IX86) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 224 | OS << format(" (0x%08lX 0x%08lX 0x%08lX 0x%08lX)", |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 225 | static_cast<DWORD>(StackFrame.Params[0]), |
| 226 | static_cast<DWORD>(StackFrame.Params[1]), |
| 227 | static_cast<DWORD>(StackFrame.Params[2]), |
| 228 | static_cast<DWORD>(StackFrame.Params[3])); |
| 229 | #endif |
| 230 | // Verify the PC belongs to a module in this process. |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 231 | if (!fSymGetModuleBase64(hProcess, PC)) { |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 232 | OS << " <unknown module>\n"; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 233 | continue; |
| 234 | } |
| 235 | |
| 236 | // Print the symbol name. |
| 237 | char buffer[512]; |
| 238 | IMAGEHLP_SYMBOL64 *symbol = reinterpret_cast<IMAGEHLP_SYMBOL64 *>(buffer); |
| 239 | memset(symbol, 0, sizeof(IMAGEHLP_SYMBOL64)); |
| 240 | symbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); |
| 241 | symbol->MaxNameLength = 512 - sizeof(IMAGEHLP_SYMBOL64); |
| 242 | |
| 243 | DWORD64 dwDisp; |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 244 | if (!fSymGetSymFromAddr64(hProcess, PC, &dwDisp, symbol)) { |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 245 | OS << '\n'; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 246 | continue; |
| 247 | } |
| 248 | |
| 249 | buffer[511] = 0; |
| 250 | if (dwDisp > 0) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 251 | OS << format(", %s() + 0x%llX bytes(s)", (const char*)symbol->Name, |
| 252 | dwDisp); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 253 | else |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 254 | OS << format(", %s", (const char*)symbol->Name); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 255 | |
| 256 | // Print the source file and line number information. |
Yaron Keren | 24a86df | 2015-04-24 15:39:47 +0000 | [diff] [blame] | 257 | IMAGEHLP_LINE64 line = {}; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 258 | DWORD dwLineDisp; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 259 | line.SizeOfStruct = sizeof(line); |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 260 | if (fSymGetLineFromAddr64(hProcess, PC, &dwLineDisp, &line)) { |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 261 | OS << format(", %s, line %lu", line.FileName, line.LineNumber); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 262 | if (dwLineDisp > 0) |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 263 | OS << format(" + 0x%lX byte(s)", dwLineDisp); |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 266 | OS << '\n'; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 270 | namespace llvm { |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 271 | |
| 272 | //===----------------------------------------------------------------------===// |
Mikhail Glushenkov | f64d93d | 2010-10-21 20:40:39 +0000 | [diff] [blame] | 273 | //=== WARNING: Implementation here must contain only Win32 specific code |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 274 | //=== and must not be UNIX code |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 275 | //===----------------------------------------------------------------------===// |
| 276 | |
Daniel Dunbar | 1bdedd3 | 2009-09-22 15:58:35 +0000 | [diff] [blame] | 277 | #ifdef _MSC_VER |
Reid Kleckner | bd39f21 | 2013-04-05 16:18:03 +0000 | [diff] [blame] | 278 | /// AvoidMessageBoxHook - Emulates hitting "retry" from an "abort, retry, |
| 279 | /// ignore" CRT debug report dialog. "retry" raises an exception which |
| 280 | /// ultimately triggers our stack dumper. |
Reid Kleckner | 542a454 | 2015-02-26 21:08:21 +0000 | [diff] [blame] | 281 | static LLVM_ATTRIBUTE_UNUSED int |
| 282 | AvoidMessageBoxHook(int ReportType, char *Message, int *Return) { |
Reid Kleckner | bd39f21 | 2013-04-05 16:18:03 +0000 | [diff] [blame] | 283 | // Set *Return to the retry code for the return value of _CrtDbgReport: |
| 284 | // http://msdn.microsoft.com/en-us/library/8hyw4sy7(v=vs.71).aspx |
| 285 | // This may also trigger just-in-time debugging via DebugBreak(). |
| 286 | if (Return) |
| 287 | *Return = 1; |
| 288 | // Don't call _CrtDbgReport. |
| 289 | return TRUE; |
| 290 | } |
| 291 | |
Daniel Dunbar | 1bdedd3 | 2009-09-22 15:58:35 +0000 | [diff] [blame] | 292 | #endif |
Daniel Dunbar | 4c7b0ca | 2009-09-22 09:50:28 +0000 | [diff] [blame] | 293 | |
Aaron Ballman | 03b968e | 2015-01-29 20:48:34 +0000 | [diff] [blame] | 294 | extern "C" void HandleAbort(int Sig) { |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 295 | if (Sig == SIGABRT) { |
| 296 | LLVM_BUILTIN_TRAP; |
| 297 | } |
| 298 | } |
| 299 | |
Aaron Ballman | 50af8d4 | 2015-03-26 16:24:38 +0000 | [diff] [blame] | 300 | static void InitializeThreading() { |
| 301 | if (CriticalSectionInitialized) |
| 302 | return; |
| 303 | |
| 304 | // Now's the time to create the critical section. This is the first time |
| 305 | // through here, and there's only one thread. |
| 306 | InitializeCriticalSection(&CriticalSection); |
| 307 | CriticalSectionInitialized = true; |
| 308 | } |
| 309 | |
Daniel Dunbar | 4c7b0ca | 2009-09-22 09:50:28 +0000 | [diff] [blame] | 310 | static void RegisterHandler() { |
Leny Kholodov | bebb27b | 2015-07-02 14:34:57 +0000 | [diff] [blame] | 311 | // If we cannot load up the APIs (which would be unexpected as they should |
| 312 | // exist on every version of Windows we support), we will bail out since |
| 313 | // there would be nothing to report. |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 314 | if (!load64BitDebugHelp()) { |
| 315 | assert(false && "These APIs should always be available"); |
| 316 | return; |
| 317 | } |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 318 | |
Reid Spencer | 1bdd0f0 | 2004-09-19 05:37:39 +0000 | [diff] [blame] | 319 | if (RegisteredUnhandledExceptionFilter) { |
Reid Spencer | 90debc5 | 2004-09-17 03:02:27 +0000 | [diff] [blame] | 320 | EnterCriticalSection(&CriticalSection); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 321 | return; |
Reid Spencer | 90debc5 | 2004-09-17 03:02:27 +0000 | [diff] [blame] | 322 | } |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 323 | |
Aaron Ballman | 50af8d4 | 2015-03-26 16:24:38 +0000 | [diff] [blame] | 324 | InitializeThreading(); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 325 | |
| 326 | // Enter it immediately. Now if someone hits CTRL/C, the console handler |
| 327 | // can't proceed until the globals are updated. |
| 328 | EnterCriticalSection(&CriticalSection); |
| 329 | |
| 330 | RegisteredUnhandledExceptionFilter = true; |
Reid Spencer | 1bdd0f0 | 2004-09-19 05:37:39 +0000 | [diff] [blame] | 331 | OldFilter = SetUnhandledExceptionFilter(LLVMUnhandledExceptionFilter); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 332 | SetConsoleCtrlHandler(LLVMConsoleCtrlHandler, TRUE); |
| 333 | |
| 334 | // IMPORTANT NOTE: Caller must call LeaveCriticalSection(&CriticalSection) or |
| 335 | // else multi-threading problems will ensue. |
| 336 | } |
| 337 | |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 338 | // RemoveFileOnSignal - The public API |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 339 | bool sys::RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg) { |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 340 | RegisterHandler(); |
| 341 | |
Reid Spencer | 50eac3b | 2006-08-25 21:37:17 +0000 | [diff] [blame] | 342 | if (CleanupExecuted) { |
| 343 | if (ErrMsg) |
| 344 | *ErrMsg = "Process terminating -- cannot register for removal"; |
| 345 | return true; |
| 346 | } |
Reid Spencer | 1bdd0f0 | 2004-09-19 05:37:39 +0000 | [diff] [blame] | 347 | |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 348 | if (FilesToRemove == NULL) |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 349 | FilesToRemove = new std::vector<std::string>; |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 350 | |
Reid Spencer | f070b6c | 2004-11-16 06:59:53 +0000 | [diff] [blame] | 351 | FilesToRemove->push_back(Filename); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 352 | |
| 353 | LeaveCriticalSection(&CriticalSection); |
Reid Spencer | 50eac3b | 2006-08-25 21:37:17 +0000 | [diff] [blame] | 354 | return false; |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Dan Gohman | e201c07 | 2010-09-01 14:17:34 +0000 | [diff] [blame] | 357 | // DontRemoveFileOnSignal - The public API |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 358 | void sys::DontRemoveFileOnSignal(StringRef Filename) { |
Dan Gohman | e201c07 | 2010-09-01 14:17:34 +0000 | [diff] [blame] | 359 | if (FilesToRemove == NULL) |
| 360 | return; |
| 361 | |
NAKAMURA Takumi | 3f688b9 | 2010-10-22 01:23:50 +0000 | [diff] [blame] | 362 | RegisterHandler(); |
| 363 | |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 364 | std::vector<std::string>::reverse_iterator I = |
Dan Gohman | e201c07 | 2010-09-01 14:17:34 +0000 | [diff] [blame] | 365 | std::find(FilesToRemove->rbegin(), FilesToRemove->rend(), Filename); |
| 366 | if (I != FilesToRemove->rend()) |
| 367 | FilesToRemove->erase(I.base()-1); |
| 368 | |
| 369 | LeaveCriticalSection(&CriticalSection); |
| 370 | } |
| 371 | |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 372 | void sys::DisableSystemDialogsOnCrash() { |
| 373 | // Crash to stack trace handler on abort. |
| 374 | signal(SIGABRT, HandleAbort); |
| 375 | |
| 376 | // The following functions are not reliably accessible on MinGW. |
| 377 | #ifdef _MSC_VER |
| 378 | // We're already handling writing a "something went wrong" message. |
| 379 | _set_abort_behavior(0, _WRITE_ABORT_MSG); |
| 380 | // Disable Dr. Watson. |
| 381 | _set_abort_behavior(0, _CALL_REPORTFAULT); |
| 382 | _CrtSetReportHook(AvoidMessageBoxHook); |
| 383 | #endif |
| 384 | |
| 385 | // Disable standard error dialog box. |
| 386 | SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | |
| 387 | SEM_NOOPENFILEERRORBOX); |
| 388 | _set_error_mode(_OUT_TO_STDERR); |
| 389 | } |
| 390 | |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 391 | /// PrintStackTraceOnErrorSignal - When an error signal (such as SIBABRT or |
| 392 | /// SIGSEGV) is delivered to the process, print a stack trace and then exit. |
Pete Cooper | 6bea2f4 | 2015-04-07 20:43:23 +0000 | [diff] [blame] | 393 | void sys::PrintStackTraceOnErrorSignal(bool DisableCrashReporting) { |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 394 | DisableSystemDialogsOnCrash(); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 395 | RegisterHandler(); |
| 396 | LeaveCriticalSection(&CriticalSection); |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 397 | } |
Benjamin Kramer | f97eff6 | 2015-03-11 15:41:15 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Yaron Keren | bdae8d6 | 2015-03-14 19:20:56 +0000 | [diff] [blame] | 400 | #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) |
| 401 | // Provide a prototype for RtlCaptureContext, mingw32 from mingw.org is |
| 402 | // missing it but mingw-w64 has it. |
Benjamin Kramer | f97eff6 | 2015-03-11 15:41:15 +0000 | [diff] [blame] | 403 | extern "C" VOID WINAPI RtlCaptureContext(PCONTEXT ContextRecord); |
Benjamin Kramer | b47d549 | 2015-03-11 16:09:02 +0000 | [diff] [blame] | 404 | #endif |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 405 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 406 | void llvm::sys::PrintStackTrace(raw_ostream &OS) { |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 407 | |
Reid Kleckner | e658058 | 2015-03-05 18:26:58 +0000 | [diff] [blame] | 408 | STACKFRAME64 StackFrame = {}; |
Yaron Keren | 24a86df | 2015-04-24 15:39:47 +0000 | [diff] [blame] | 409 | CONTEXT Context = {}; |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 410 | ::RtlCaptureContext(&Context); |
| 411 | #if defined(_M_X64) |
| 412 | StackFrame.AddrPC.Offset = Context.Rip; |
| 413 | StackFrame.AddrStack.Offset = Context.Rsp; |
| 414 | StackFrame.AddrFrame.Offset = Context.Rbp; |
| 415 | #else |
| 416 | StackFrame.AddrPC.Offset = Context.Eip; |
| 417 | StackFrame.AddrStack.Offset = Context.Esp; |
| 418 | StackFrame.AddrFrame.Offset = Context.Ebp; |
| 419 | #endif |
| 420 | StackFrame.AddrPC.Mode = AddrModeFlat; |
| 421 | StackFrame.AddrStack.Mode = AddrModeFlat; |
| 422 | StackFrame.AddrFrame.Mode = AddrModeFlat; |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 423 | PrintStackTraceForThread(OS, GetCurrentProcess(), GetCurrentThread(), |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 424 | StackFrame, &Context); |
Argyrios Kyrtzidis | eb9ae76 | 2013-01-09 19:42:40 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Chris Lattner | 6a5d6ec | 2005-08-02 02:14:22 +0000 | [diff] [blame] | 427 | |
Benjamin Kramer | 90c2db2 | 2015-03-11 15:53:24 +0000 | [diff] [blame] | 428 | void llvm::sys::SetInterruptFunction(void (*IF)()) { |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 429 | RegisterHandler(); |
Jeff Cohen | 9aafa06 | 2005-08-02 03:26:32 +0000 | [diff] [blame] | 430 | InterruptFunction = IF; |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 431 | LeaveCriticalSection(&CriticalSection); |
Chris Lattner | 6a5d6ec | 2005-08-02 02:14:22 +0000 | [diff] [blame] | 432 | } |
Sebastian Redl | 8d5baa0 | 2009-03-19 23:26:52 +0000 | [diff] [blame] | 433 | |
| 434 | |
| 435 | /// AddSignalHandler - Add a function to be called when a signal is delivered |
| 436 | /// to the process. The handler can have a cookie passed to it to identify |
| 437 | /// what instance of the handler it is. |
Benjamin Kramer | b47d549 | 2015-03-11 16:09:02 +0000 | [diff] [blame] | 438 | void llvm::sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) { |
Sebastian Redl | 8d5baa0 | 2009-03-19 23:26:52 +0000 | [diff] [blame] | 439 | CallBacksToRun->push_back(std::make_pair(FnPtr, Cookie)); |
| 440 | RegisterHandler(); |
Torok Edwin | 6fb0956 | 2010-03-31 12:07:16 +0000 | [diff] [blame] | 441 | LeaveCriticalSection(&CriticalSection); |
Sebastian Redl | 8d5baa0 | 2009-03-19 23:26:52 +0000 | [diff] [blame] | 442 | } |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 443 | |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 444 | static void Cleanup() { |
Yaron Keren | 356aa46 | 2015-05-19 13:31:25 +0000 | [diff] [blame] | 445 | if (CleanupExecuted) |
| 446 | return; |
| 447 | |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 448 | EnterCriticalSection(&CriticalSection); |
| 449 | |
Reid Spencer | 1bdd0f0 | 2004-09-19 05:37:39 +0000 | [diff] [blame] | 450 | // Prevent other thread from registering new files and directories for |
| 451 | // removal, should we be executing because of the console handler callback. |
| 452 | CleanupExecuted = true; |
| 453 | |
| 454 | // FIXME: open files cannot be deleted. |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 455 | if (FilesToRemove != NULL) |
| 456 | while (!FilesToRemove->empty()) { |
Rafael Espindola | d724c28 | 2014-02-23 13:37:37 +0000 | [diff] [blame] | 457 | llvm::sys::fs::remove(FilesToRemove->back()); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 458 | FilesToRemove->pop_back(); |
| 459 | } |
Yaron Keren | 2873810 | 2015-07-22 21:11:17 +0000 | [diff] [blame^] | 460 | llvm::sys::RunSignalHandlers(); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 461 | LeaveCriticalSection(&CriticalSection); |
| 462 | } |
| 463 | |
Daniel Dunbar | 6827256 | 2010-05-08 02:10:34 +0000 | [diff] [blame] | 464 | void llvm::sys::RunInterruptHandlers() { |
Aaron Ballman | 50af8d4 | 2015-03-26 16:24:38 +0000 | [diff] [blame] | 465 | // The interrupt handler may be called from an interrupt, but it may also be |
| 466 | // called manually (such as the case of report_fatal_error with no registered |
| 467 | // error handler). We must ensure that the critical section is properly |
| 468 | // initialized. |
| 469 | InitializeThreading(); |
Daniel Dunbar | 6827256 | 2010-05-08 02:10:34 +0000 | [diff] [blame] | 470 | Cleanup(); |
| 471 | } |
| 472 | |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 473 | static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { |
Mikhail Glushenkov | 32acd74 | 2010-10-27 09:09:04 +0000 | [diff] [blame] | 474 | Cleanup(); |
Mikhail Glushenkov | f64d93d | 2010-10-21 20:40:39 +0000 | [diff] [blame] | 475 | |
Mikhail Glushenkov | 080d86f | 2010-10-28 08:25:44 +0000 | [diff] [blame] | 476 | // Initialize the STACKFRAME structure. |
Yaron Keren | 24a86df | 2015-04-24 15:39:47 +0000 | [diff] [blame] | 477 | STACKFRAME64 StackFrame = {}; |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 478 | |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 479 | #if defined(_M_X64) |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 480 | StackFrame.AddrPC.Offset = ep->ContextRecord->Rip; |
| 481 | StackFrame.AddrPC.Mode = AddrModeFlat; |
| 482 | StackFrame.AddrStack.Offset = ep->ContextRecord->Rsp; |
| 483 | StackFrame.AddrStack.Mode = AddrModeFlat; |
| 484 | StackFrame.AddrFrame.Offset = ep->ContextRecord->Rbp; |
| 485 | StackFrame.AddrFrame.Mode = AddrModeFlat; |
| 486 | #elif defined(_M_IX86) |
Mikhail Glushenkov | 080d86f | 2010-10-28 08:25:44 +0000 | [diff] [blame] | 487 | StackFrame.AddrPC.Offset = ep->ContextRecord->Eip; |
| 488 | StackFrame.AddrPC.Mode = AddrModeFlat; |
| 489 | StackFrame.AddrStack.Offset = ep->ContextRecord->Esp; |
| 490 | StackFrame.AddrStack.Mode = AddrModeFlat; |
| 491 | StackFrame.AddrFrame.Offset = ep->ContextRecord->Ebp; |
| 492 | StackFrame.AddrFrame.Mode = AddrModeFlat; |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 493 | #endif |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 494 | |
Mikhail Glushenkov | 080d86f | 2010-10-28 08:25:44 +0000 | [diff] [blame] | 495 | HANDLE hProcess = GetCurrentProcess(); |
| 496 | HANDLE hThread = GetCurrentThread(); |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 497 | PrintStackTraceForThread(llvm::errs(), hProcess, hThread, StackFrame, |
Zachary Turner | 62b7b61 | 2015-03-05 17:47:52 +0000 | [diff] [blame] | 498 | ep->ContextRecord); |
Mikhail Glushenkov | 080d86f | 2010-10-28 08:25:44 +0000 | [diff] [blame] | 499 | |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 500 | _exit(ep->ExceptionRecord->ExceptionCode); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) { |
Jeff Cohen | 9aafa06 | 2005-08-02 03:26:32 +0000 | [diff] [blame] | 504 | // We are running in our very own thread, courtesy of Windows. |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 505 | EnterCriticalSection(&CriticalSection); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 506 | Cleanup(); |
| 507 | |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 508 | // If an interrupt function has been set, go and run one it; otherwise, |
| 509 | // the process dies. |
| 510 | void (*IF)() = InterruptFunction; |
| 511 | InterruptFunction = 0; // Don't run it on another CTRL-C. |
| 512 | |
| 513 | if (IF) { |
Jeff Cohen | 9aafa06 | 2005-08-02 03:26:32 +0000 | [diff] [blame] | 514 | // Note: if the interrupt function throws an exception, there is nothing |
| 515 | // to catch it in this thread so it will kill the process. |
| 516 | IF(); // Run it now. |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 517 | LeaveCriticalSection(&CriticalSection); |
| 518 | return TRUE; // Don't kill the process. |
| 519 | } |
| 520 | |
Reid Spencer | 90debc5 | 2004-09-17 03:02:27 +0000 | [diff] [blame] | 521 | // Allow normal processing to take place; i.e., the process dies. |
Jeff Cohen | ba7cc68 | 2005-08-02 03:04:47 +0000 | [diff] [blame] | 522 | LeaveCriticalSection(&CriticalSection); |
Reid Spencer | 4aff78a | 2004-09-16 15:53:16 +0000 | [diff] [blame] | 523 | return FALSE; |
| 524 | } |
Michael J. Spencer | 44a36c8 | 2011-10-01 00:05:20 +0000 | [diff] [blame] | 525 | |
| 526 | #if __MINGW32__ |
| 527 | // We turned these warnings off for this file so that MinGW-g++ doesn't |
| 528 | // complain about the ll format specifiers used. Now we are turning the |
| 529 | // warnings back on. If MinGW starts to support diagnostic stacks, we can |
| 530 | // replace this with a pop. |
| 531 | #pragma GCC diagnostic warning "-Wformat" |
| 532 | #pragma GCC diagnostic warning "-Wformat-extra-args" |
| 533 | #endif |