diff options
Diffstat (limited to 'src/util.h')
| -rw-r--r-- | src/util.h | 32 |
1 files changed, 32 insertions, 0 deletions
| @@ -3,6 +3,11 @@ | |||
| 3 | // file license.txt or http://www.opensource.org/licenses/mit-license.php. | 3 | // file license.txt or http://www.opensource.org/licenses/mit-license.php. |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | // For abi::__forced_unwind, which CATCH_PRINT_EXCEPTION below must let past. | ||
| 7 | #ifndef _WIN32 | ||
| 8 | #include <cxxabi.h> | ||
| 9 | #endif | ||
| 10 | |||
| 6 | #if defined(_MSC_VER) || defined(__BORLANDC__) | 11 | #if defined(_MSC_VER) || defined(__BORLANDC__) |
| 7 | typedef __int64 int64; | 12 | typedef __int64 int64; |
| 8 | typedef unsigned __int64 uint64; | 13 | typedef unsigned __int64 uint64; |
| @@ -419,7 +424,34 @@ inline void heapchk() | |||
| 419 | } \ | 424 | } \ |
| 420 | } | 425 | } |
| 421 | 426 | ||
| 427 | // The forced-unwind arm has to come first, and it has to rethrow. | ||
| 428 | // | ||
| 429 | // On POSIX, _endthread() is pthread_exit(), and glibc implements that by | ||
| 430 | // throwing abi::__forced_unwind through the stack. It is not a real exception | ||
| 431 | // and catching it without rethrowing is a fatal error by contract: glibc | ||
| 432 | // notices and calls abort(). | ||
| 433 | // | ||
| 434 | // The bare catch(...) below did exactly that. Every shutdown on Linux died with | ||
| 435 | // | ||
| 436 | // UNKNOWN EXCEPTION bitflash-node in ThreadSocketHandler() | ||
| 437 | // FATAL: exception not rethrown | ||
| 438 | // | ||
| 439 | // which looked like nothing worse than an ugly exit, and was not: the process | ||
| 440 | // aborted partway through shutting down, so nothing after StopNode() ran. See | ||
| 441 | // main_gui.cpp, where DBFlush(true) is now called -- it could never have | ||
| 442 | // worked while this abort stood in front of it. Windows is unaffected; there | ||
| 443 | // _endthread() is the CRT's and unwinds nothing. | ||
| 444 | #ifdef _WIN32 | ||
| 445 | #define CATCH_FORCED_UNWIND | ||
| 446 | #else | ||
| 447 | #define CATCH_FORCED_UNWIND \ | ||
| 448 | catch (abi::__forced_unwind&) { \ | ||
| 449 | throw; \ | ||
| 450 | } | ||
| 451 | #endif | ||
| 452 | |||
| 422 | #define CATCH_PRINT_EXCEPTION(pszFn) \ | 453 | #define CATCH_PRINT_EXCEPTION(pszFn) \ |
| 454 | CATCH_FORCED_UNWIND \ | ||
| 423 | catch (std::exception& e) { \ | 455 | catch (std::exception& e) { \ |
| 424 | PrintException(&e, (pszFn)); \ | 456 | PrintException(&e, (pszFn)); \ |
| 425 | } catch (...) { \ | 457 | } catch (...) { \ |