bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | // ExceptionHandler can write a minidump file when an exception occurs, |
| 31 | // or when WriteMinidump() is called explicitly by your program. |
| 32 | // |
| 33 | // To have the exception handler write minidumps when an uncaught exception |
| 34 | // (crash) occurs, you should create an instance early in the execution |
| 35 | // of your program, and keep it around for the entire time you want to |
| 36 | // have crash handling active (typically, until shutdown). |
| 37 | // |
| 38 | // If you want to write minidumps without installing the exception handler, |
| 39 | // you can create an ExceptionHandler with install_handler set to false, |
| 40 | // then call WriteMinidump. You can also use this technique if you want to |
| 41 | // use different minidump callbacks for different call sites. |
| 42 | // |
| 43 | // In either case, a callback function is called when a minidump is written, |
| 44 | // which receives the unqiue id of the minidump. The caller can use this |
| 45 | // id to collect and write additional application state, and to launch an |
| 46 | // external crash-reporting application. |
| 47 | // |
| 48 | // It is important that creation and destruction of ExceptionHandler objects |
| 49 | // be nested cleanly, when using install_handler = true. |
| 50 | // Avoid the following pattern: |
| 51 | // ExceptionHandler *e = new ExceptionHandler(...); |
| 52 | // ExceptionHandler *f = new ExceptionHandler(...); |
| 53 | // delete e; |
| 54 | // This will put the exception filter stack into an inconsistent state. |
bryner | f140025 | 2006-09-28 19:35:08 +0000 | [diff] [blame] | 55 | // |
| 56 | // To use this library in your project, you will need to link against |
mmentovai | 29401d2 | 2006-10-26 18:06:43 +0000 | [diff] [blame] | 57 | // ole32.lib. |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 58 | |
| 59 | #ifndef CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__ |
| 60 | #define CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__ |
| 61 | |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 62 | #include <stdlib.h> |
mmentovai | 29401d2 | 2006-10-26 18:06:43 +0000 | [diff] [blame] | 63 | #include <Windows.h> |
| 64 | #include <DbgHelp.h> |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 65 | |
mmentovai | 12a5245 | 2006-10-27 19:47:21 +0000 | [diff] [blame] | 66 | #pragma warning( push ) |
| 67 | // Disable exception handler warnings. |
| 68 | #pragma warning( disable : 4530 ) |
| 69 | |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 70 | #include <string> |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 71 | #include <vector> |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 72 | |
mmentovai | e5dc608 | 2007-02-14 19:51:05 +0000 | [diff] [blame] | 73 | #include "google_breakpad/common/minidump_format.h" |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 74 | |
mmentovai | e5dc608 | 2007-02-14 19:51:05 +0000 | [diff] [blame] | 75 | namespace google_breakpad { |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 76 | |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 77 | using std::vector; |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 78 | using std::wstring; |
| 79 | |
| 80 | class ExceptionHandler { |
| 81 | public: |
mmentovai | e5dc608 | 2007-02-14 19:51:05 +0000 | [diff] [blame] | 82 | // A callback function to run before Breakpad performs any substantial |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 83 | // processing of an exception. A FilterCallback is called before writing |
| 84 | // a minidump. context is the parameter supplied by the user as |
mmentovai | f614cb9 | 2007-01-12 16:54:10 +0000 | [diff] [blame] | 85 | // callback_context when the handler was created. exinfo points to the |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 86 | // exception record, if any; assertion points to assertion information, |
| 87 | // if any. |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 88 | // |
mmentovai | e5dc608 | 2007-02-14 19:51:05 +0000 | [diff] [blame] | 89 | // If a FilterCallback returns true, Breakpad will continue processing, |
| 90 | // attempting to write a minidump. If a FilterCallback returns false, Breakpad |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 91 | // will immediately report the exception as unhandled without writing a |
| 92 | // minidump, allowing another handler the opportunity to handle it. |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 93 | typedef bool (*FilterCallback)(void *context, EXCEPTION_POINTERS *exinfo, |
| 94 | MDRawAssertionInfo *assertion); |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 95 | |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 96 | // A callback function to run after the minidump has been written. |
| 97 | // minidump_id is a unique id for the dump, so the minidump |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 98 | // file is <dump_path>\<minidump_id>.dmp. context is the parameter supplied |
mmentovai | f614cb9 | 2007-01-12 16:54:10 +0000 | [diff] [blame] | 99 | // by the user as callback_context when the handler was created. exinfo |
| 100 | // points to the exception record, or NULL if no exception occurred. |
| 101 | // succeeded indicates whether a minidump file was successfully written. |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 102 | // assertion points to information about an assertion if the handler was |
| 103 | // invoked by an assertion. |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 104 | // |
mmentovai | e5dc608 | 2007-02-14 19:51:05 +0000 | [diff] [blame] | 105 | // If an exception occurred and the callback returns true, Breakpad will treat |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 106 | // the exception as fully-handled, suppressing any other handlers from being |
mmentovai | e5dc608 | 2007-02-14 19:51:05 +0000 | [diff] [blame] | 107 | // notified of the exception. If the callback returns false, Breakpad will |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 108 | // treat the exception as unhandled, and allow another handler to handle it. |
mmentovai | e5dc608 | 2007-02-14 19:51:05 +0000 | [diff] [blame] | 109 | // If there are no other handlers, Breakpad will report the exception to the |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 110 | // system as unhandled, allowing a debugger or native crash dialog the |
| 111 | // opportunity to handle the exception. Most callback implementations |
| 112 | // should normally return the value of |succeeded|, or when they wish to |
| 113 | // not report an exception of handled, false. Callbacks will rarely want to |
| 114 | // return true directly (unless |succeeded| is true). |
| 115 | typedef bool (*MinidumpCallback)(const wchar_t *dump_path, |
| 116 | const wchar_t *minidump_id, |
| 117 | void *context, |
mmentovai | f614cb9 | 2007-01-12 16:54:10 +0000 | [diff] [blame] | 118 | EXCEPTION_POINTERS *exinfo, |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 119 | MDRawAssertionInfo *assertion, |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 120 | bool succeeded); |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 121 | |
mmentovai | 6a844b1 | 2007-07-02 19:41:05 +0000 | [diff] [blame] | 122 | // HandlerType specifies which types of handlers should be installed, if |
| 123 | // any. Use HANDLER_NONE for an ExceptionHandler that remains idle, |
| 124 | // without catching any failures on its own. This type of handler may |
| 125 | // still be triggered by calling WriteMinidump. Otherwise, use a |
| 126 | // combination of the other HANDLER_ values, or HANDLER_ALL to install |
| 127 | // all handlers. |
| 128 | enum HandlerType { |
| 129 | HANDLER_NONE = 0, |
| 130 | HANDLER_EXCEPTION = 1 << 0, // SetUnhandledExceptionFilter |
| 131 | HANDLER_INVALID_PARAMETER = 1 << 1, // _set_invalid_parameter_handler |
| 132 | HANDLER_PURECALL = 1 << 2, // _set_purecall_handler |
| 133 | HANDLER_ALL = HANDLER_EXCEPTION | |
| 134 | HANDLER_INVALID_PARAMETER | |
| 135 | HANDLER_PURECALL |
| 136 | }; |
| 137 | |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 138 | // Creates a new ExceptionHandler instance to handle writing minidumps. |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 139 | // Before writing a minidump, the optional filter callback will be called. |
mmentovai | 6a844b1 | 2007-07-02 19:41:05 +0000 | [diff] [blame] | 140 | // Its return value determines whether or not Breakpad should write a |
| 141 | // minidump. Minidump files will be written to dump_path, and the optional |
| 142 | // callback is called after writing the dump file, as described above. |
| 143 | // handler_types specifies the types of handlers that should be installed. |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 144 | ExceptionHandler(const wstring &dump_path, |
mmentovai | 6a844b1 | 2007-07-02 19:41:05 +0000 | [diff] [blame] | 145 | FilterCallback filter, |
| 146 | MinidumpCallback callback, |
| 147 | void *callback_context, |
mmentovai | 3c07b28 | 2007-07-02 20:41:30 +0000 | [diff] [blame] | 148 | int handler_types); |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 149 | ~ExceptionHandler(); |
| 150 | |
mmentovai | 1bff57e | 2006-10-27 16:10:55 +0000 | [diff] [blame] | 151 | // Get and set the minidump path. |
| 152 | wstring dump_path() const { return dump_path_; } |
mmentovai | ed61ae0 | 2006-11-28 19:47:44 +0000 | [diff] [blame] | 153 | void set_dump_path(const wstring &dump_path) { |
| 154 | dump_path_ = dump_path; |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 155 | dump_path_c_ = dump_path_.c_str(); |
mmentovai | ed61ae0 | 2006-11-28 19:47:44 +0000 | [diff] [blame] | 156 | UpdateNextID(); // Necessary to put dump_path_ in next_minidump_path_. |
| 157 | } |
mmentovai | 1bff57e | 2006-10-27 16:10:55 +0000 | [diff] [blame] | 158 | |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 159 | // Writes a minidump immediately. This can be used to capture the |
| 160 | // execution state independently of a crash. Returns true on success. |
| 161 | bool WriteMinidump(); |
| 162 | |
mmentovai | fb6be7c | 2007-07-02 15:36:56 +0000 | [diff] [blame] | 163 | // Writes a minidump immediately, with the user-supplied exception |
| 164 | // information. |
| 165 | bool WriteMinidumpForException(EXCEPTION_POINTERS *exinfo); |
| 166 | |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 167 | // Convenience form of WriteMinidump which does not require an |
| 168 | // ExceptionHandler instance. |
| 169 | static bool WriteMinidump(const wstring &dump_path, |
| 170 | MinidumpCallback callback, void *callback_context); |
| 171 | |
mmentovai | 6a3f879 | 2007-08-17 19:42:18 +0000 | [diff] [blame^] | 172 | // Get the thread ID of the thread requesting the dump (either the exception |
| 173 | // thread or any other thread that called WriteMinidump directly). This |
| 174 | // may be useful if you want to include additional thread state in your |
| 175 | // dumps. |
| 176 | DWORD get_requesting_thread_id() const { return requesting_thread_id_; } |
| 177 | |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 178 | private: |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 179 | friend class AutoExceptionHandler; |
| 180 | |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 181 | // Function pointer type for MiniDumpWriteDump, which is looked up |
| 182 | // dynamically. |
| 183 | typedef BOOL (WINAPI *MiniDumpWriteDump_type)( |
| 184 | HANDLE hProcess, |
| 185 | DWORD dwPid, |
| 186 | HANDLE hFile, |
| 187 | MINIDUMP_TYPE DumpType, |
| 188 | CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, |
| 189 | CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, |
| 190 | CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam); |
| 191 | |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 192 | // Runs the main loop for the exception handler thread. |
| 193 | static DWORD WINAPI ExceptionHandlerThreadMain(void *lpParameter); |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 194 | |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 195 | // Called on the exception thread when an unhandled exception occurs. |
| 196 | // Signals the exception handler thread to handle the exception. |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 197 | static LONG WINAPI HandleException(EXCEPTION_POINTERS *exinfo); |
| 198 | |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 199 | #if _MSC_VER >= 1400 // MSVC 2005/8 |
| 200 | // This function will be called by some CRT functions when they detect |
| 201 | // that they were passed an invalid parameter. Note that in _DEBUG builds, |
| 202 | // the CRT may display an assertion dialog before calling this function, |
| 203 | // and the function will not be called unless the assertion dialog is |
| 204 | // dismissed by clicking "Ignore." |
| 205 | static void HandleInvalidParameter(const wchar_t *expression, |
| 206 | const wchar_t *function, |
| 207 | const wchar_t *file, |
| 208 | unsigned int line, |
| 209 | uintptr_t reserved); |
| 210 | #endif // _MSC_VER >= 1400 |
| 211 | |
ted.mielczarek | b86e7ec | 2007-05-10 17:12:14 +0000 | [diff] [blame] | 212 | // This function will be called by the CRT when a pure virtual |
| 213 | // function is called. |
| 214 | static void HandlePureVirtualCall(); |
| 215 | |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 216 | // This is called on the exception thread or on another thread that |
| 217 | // the user wishes to produce a dump from. It calls |
| 218 | // WriteMinidumpWithException on the handler thread, avoiding stack |
| 219 | // overflows and inconsistent dumps due to writing the dump from |
| 220 | // the exception thread. If the dump is requested as a result of an |
| 221 | // exception, exinfo contains exception information, otherwise, it |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 222 | // is NULL. If the dump is requested as a result of an assertion |
| 223 | // (such as an invalid parameter being passed to a CRT function), |
| 224 | // assertion contains data about the assertion, otherwise, it is NULL. |
| 225 | bool WriteMinidumpOnHandlerThread(EXCEPTION_POINTERS *exinfo, |
| 226 | MDRawAssertionInfo *assertion); |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 227 | |
| 228 | // This function does the actual writing of a minidump. It is called |
| 229 | // on the handler thread. requesting_thread_id is the ID of the thread |
| 230 | // that requested the dump. If the dump is requested as a result of |
| 231 | // an exception, exinfo contains exception information, otherwise, |
| 232 | // it is NULL. |
| 233 | bool WriteMinidumpWithException(DWORD requesting_thread_id, |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 234 | EXCEPTION_POINTERS *exinfo, |
| 235 | MDRawAssertionInfo *assertion); |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 236 | |
mmentovai | ed61ae0 | 2006-11-28 19:47:44 +0000 | [diff] [blame] | 237 | // Generates a new ID and stores it in next_minidump_id_, and stores the |
| 238 | // path of the next minidump to be written in next_minidump_path_. |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 239 | void UpdateNextID(); |
| 240 | |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 241 | FilterCallback filter_; |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 242 | MinidumpCallback callback_; |
| 243 | void *callback_context_; |
| 244 | |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 245 | // The directory in which a minidump will be written, set by the dump_path |
| 246 | // argument to the constructor, or set_dump_path. |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 247 | wstring dump_path_; |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 248 | |
| 249 | // The basename of the next minidump to be written, without the extension. |
mmentovai | 29401d2 | 2006-10-26 18:06:43 +0000 | [diff] [blame] | 250 | wstring next_minidump_id_; |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 251 | |
| 252 | // The full pathname of the next minidump to be written, including the file |
| 253 | // extension. |
mmentovai | ed61ae0 | 2006-11-28 19:47:44 +0000 | [diff] [blame] | 254 | wstring next_minidump_path_; |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 255 | |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 256 | // Pointers to C-string representations of the above. These are set when |
| 257 | // the above wstring versions are set in order to avoid calling c_str during |
| 258 | // an exception, as c_str may attempt to allocate heap memory. These |
| 259 | // pointers are not owned by the ExceptionHandler object, but their lifetimes |
| 260 | // should be equivalent to the lifetimes of the associated wstring, provided |
| 261 | // that the wstrings are not altered. |
| 262 | const wchar_t *dump_path_c_; |
| 263 | const wchar_t *next_minidump_id_c_; |
| 264 | const wchar_t *next_minidump_path_c_; |
| 265 | |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 266 | HMODULE dbghelp_module_; |
| 267 | MiniDumpWriteDump_type minidump_write_dump_; |
| 268 | |
mmentovai | 6a844b1 | 2007-07-02 19:41:05 +0000 | [diff] [blame] | 269 | // Tracks the handler types that were installed according to the |
| 270 | // handler_types constructor argument. |
mmentovai | 3c07b28 | 2007-07-02 20:41:30 +0000 | [diff] [blame] | 271 | int handler_types_; |
mmentovai | 65dbfcc | 2006-12-08 22:49:07 +0000 | [diff] [blame] | 272 | |
| 273 | // When installed_handler_ is true, previous_filter_ is the unhandled |
| 274 | // exception filter that was set prior to installing ExceptionHandler as |
| 275 | // the unhandled exception filter and pointing it to |this|. NULL indicates |
| 276 | // that there is no previous unhandled exception filter. |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 277 | LPTOP_LEVEL_EXCEPTION_FILTER previous_filter_; |
mmentovai | 65dbfcc | 2006-12-08 22:49:07 +0000 | [diff] [blame] | 278 | |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 279 | #if _MSC_VER >= 1400 // MSVC 2005/8 |
| 280 | // Beginning in VC 8, the CRT provides an invalid parameter handler that will |
| 281 | // be called when some CRT functions are passed invalid parameters. In |
| 282 | // earlier CRTs, the same conditions would cause unexpected behavior or |
| 283 | // crashes. |
| 284 | _invalid_parameter_handler previous_iph_; |
| 285 | #endif // _MSC_VER >= 1400 |
| 286 | |
ted.mielczarek | b86e7ec | 2007-05-10 17:12:14 +0000 | [diff] [blame] | 287 | // The CRT allows you to override the default handler for pure |
| 288 | // virtual function calls. |
| 289 | _purecall_handler previous_pch_; |
| 290 | |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 291 | // The exception handler thread. |
| 292 | HANDLE handler_thread_; |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 293 | |
| 294 | // The critical section enforcing the requirement that only one exception be |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 295 | // handled by a handler at a time. |
| 296 | CRITICAL_SECTION handler_critical_section_; |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 297 | |
| 298 | // Semaphores used to move exception handling between the exception thread |
| 299 | // and the handler thread. handler_start_semaphore_ is signalled by the |
| 300 | // exception thread to wake up the handler thread when an exception occurs. |
| 301 | // handler_finish_semaphore_ is signalled by the handler thread to wake up |
| 302 | // the exception thread when handling is complete. |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 303 | HANDLE handler_start_semaphore_; |
| 304 | HANDLE handler_finish_semaphore_; |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 305 | |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 306 | // The next 2 fields contain data passed from the requesting thread to |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 307 | // the handler thread. |
| 308 | |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 309 | // The thread ID of the thread requesting the dump (either the exception |
| 310 | // thread or any other thread that called WriteMinidump directly). |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 311 | DWORD requesting_thread_id_; |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 312 | |
| 313 | // The exception info passed to the exception handler on the exception |
| 314 | // thread, if an exception occurred. NULL for user-requested dumps. |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 315 | EXCEPTION_POINTERS *exception_info_; |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 316 | |
mmentovai | baff938 | 2007-02-07 20:20:10 +0000 | [diff] [blame] | 317 | // If the handler is invoked due to an assertion, this will contain a |
| 318 | // pointer to the assertion information. It is NULL at other times. |
| 319 | MDRawAssertionInfo *assertion_; |
| 320 | |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 321 | // The return value of the handler, passed from the handler thread back to |
| 322 | // the requesting thread. |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 323 | bool handler_return_value_; |
| 324 | |
mmentovai | 65dbfcc | 2006-12-08 22:49:07 +0000 | [diff] [blame] | 325 | // A stack of ExceptionHandler objects that have installed unhandled |
| 326 | // exception filters. This vector is used by HandleException to determine |
| 327 | // which ExceptionHandler object to route an exception to. When an |
| 328 | // ExceptionHandler is created with install_handler true, it will append |
| 329 | // itself to this list. |
| 330 | static vector<ExceptionHandler *> *handler_stack_; |
| 331 | |
| 332 | // The index of the ExceptionHandler in handler_stack_ that will handle the |
| 333 | // next exception. Note that 0 means the last entry in handler_stack_, 1 |
| 334 | // means the next-to-last entry, and so on. This is used by HandleException |
mmentovai | e5dc608 | 2007-02-14 19:51:05 +0000 | [diff] [blame] | 335 | // to support multiple stacked Breakpad handlers. |
mmentovai | 65dbfcc | 2006-12-08 22:49:07 +0000 | [diff] [blame] | 336 | static LONG handler_stack_index_; |
| 337 | |
| 338 | // handler_stack_critical_section_ guards operations on handler_stack_ and |
| 339 | // handler_stack_index_. |
mmentovai | 283fd39 | 2006-12-07 20:46:54 +0000 | [diff] [blame] | 340 | static CRITICAL_SECTION handler_stack_critical_section_; |
| 341 | |
| 342 | // True when handler_stack_critical_section_ has been initialized. |
| 343 | static bool handler_stack_critical_section_initialized_; |
mmentovai | b261019 | 2006-10-31 16:49:38 +0000 | [diff] [blame] | 344 | |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 345 | // disallow copy ctor and operator= |
| 346 | explicit ExceptionHandler(const ExceptionHandler &); |
| 347 | void operator=(const ExceptionHandler &); |
| 348 | }; |
| 349 | |
mmentovai | e5dc608 | 2007-02-14 19:51:05 +0000 | [diff] [blame] | 350 | } // namespace google_breakpad |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 351 | |
mmentovai | 12a5245 | 2006-10-27 19:47:21 +0000 | [diff] [blame] | 352 | #pragma warning( pop ) |
| 353 | |
bryner | 1217c1f | 2006-09-27 01:00:32 +0000 | [diff] [blame] | 354 | #endif // CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__ |