Wrapper for platform-specific fatal error (signals/SEH) handlers Tries to be cooperative with other handlers, and not step over other handlers. This means that unknown structured exceptions are passed on, previous signal handlers are called, and so on. Can only be instantiated once, and assumes that once a signal is caught, the binary will end up terminating. Thus, there
| 8009 | // Can only be instantiated once, and assumes that once a signal |
| 8010 | // is caught, the binary will end up terminating. Thus, there |
| 8011 | class FatalConditionHandler { |
| 8012 | bool m_started = false; |
| 8013 | |
| 8014 | // Install/disengage implementation for specific platform. |
| 8015 | // Should be if-defed to work on current platform, can assume |
| 8016 | // engage-disengage 1:1 pairing. |
| 8017 | void engage_platform(); |
| 8018 | void disengage_platform(); |
| 8019 | public: |
| 8020 | // Should also have platform-specific implementations as needed |
| 8021 | FatalConditionHandler(); |
| 8022 | ~FatalConditionHandler(); |
| 8023 | |
| 8024 | void engage() { |
| 8025 | assert(!m_started && "Handler cannot be installed twice."); |
| 8026 | m_started = true; |
| 8027 | engage_platform(); |
| 8028 | } |
| 8029 | |
| 8030 | void disengage() { |
| 8031 | assert(m_started && "Handler cannot be uninstalled without being installed first"); |
| 8032 | m_started = false; |
| 8033 | disengage_platform(); |
| 8034 | } |
| 8035 | }; |
| 8036 | |
| 8037 | //! Simple RAII guard for (dis)engaging the FatalConditionHandler |
| 8038 | class FatalConditionHandlerGuard { |