| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*++ |
| 6 | |
| 7 | |
| 8 | |
| 9 | Module Name: |
| 10 | |
| 11 | include/pal/seh.hpp |
| 12 | |
| 13 | Abstract: |
| 14 | Header file for public Structured Exception Handling stuff |
| 15 | |
| 16 | |
| 17 | |
| 18 | --*/ |
| 19 | |
| 20 | #ifndef _PAL_SEH_HPP_ |
| 21 | #define _PAL_SEH_HPP_ |
| 22 | |
| 23 | #include "config.h" |
| 24 | #include "pal/palinternal.h" |
| 25 | #include "pal/corunix.hpp" |
| 26 | |
| 27 | // Uncomment this define to turn off the signal handling thread. |
| 28 | // #define DO_NOT_USE_SIGNAL_HANDLING_THREAD |
| 29 | |
| 30 | /*++ |
| 31 | Function : |
| 32 | SEHInitialize |
| 33 | |
| 34 | Initialize all SEH-related stuff (signals, etc) |
| 35 | |
| 36 | Parameters: |
| 37 | CPalThread * pthrCurrent : reference to the current thread. |
| 38 | flags : PAL initialize flags |
| 39 | |
| 40 | Return value: |
| 41 | TRUE if SEH support initialization succeeded, |
| 42 | FALSE otherwise |
| 43 | |
| 44 | --*/ |
| 45 | BOOL |
| 46 | SEHInitialize(CorUnix::CPalThread *pthrCurrent, DWORD flags); |
| 47 | |
| 48 | /*++ |
| 49 | Function : |
| 50 | SEHCleanup |
| 51 | |
| 52 | Clean up SEH-related stuff(signals, etc) |
| 53 | |
| 54 | Parameters: |
| 55 | None |
| 56 | |
| 57 | (no return value) |
| 58 | --*/ |
| 59 | VOID |
| 60 | SEHCleanup(); |
| 61 | |
| 62 | /*++ |
| 63 | Function: |
| 64 | SEHProcessException |
| 65 | |
| 66 | Send the PAL exception to any handler registered. |
| 67 | |
| 68 | Parameters: |
| 69 | PAL_SEHException* exception |
| 70 | |
| 71 | Return value: |
| 72 | Returns TRUE if the exception happened in managed code and the execution should |
| 73 | continue (with possibly modified context). |
| 74 | Returns FALSE if the exception happened in managed code and it was not handled. |
| 75 | In case the exception was handled by calling a catch handler, it doesn't return at all. |
| 76 | --*/ |
| 77 | BOOL |
| 78 | SEHProcessException(PAL_SEHException* exception); |
| 79 | |
| 80 | /*++ |
| 81 | Function: |
| 82 | AllocateExceptionRecords |
| 83 | |
| 84 | Parameters: |
| 85 | exceptionRecord - output pointer to the allocated Windows exception record |
| 86 | contextRecord - output pointer to the allocated Windows context record |
| 87 | --*/ |
| 88 | VOID |
| 89 | AllocateExceptionRecords(EXCEPTION_RECORD** exceptionRecord, CONTEXT** contextRecord); |
| 90 | |
| 91 | #if !HAVE_MACH_EXCEPTIONS |
| 92 | // TODO: Implement for Mach exceptions. Not in CoreCLR surface area. |
| 93 | /*++ |
| 94 | Function : |
| 95 | SEHHandleControlEvent |
| 96 | |
| 97 | handle Control-C and Control-Break events (call handler routines, |
| 98 | notify debugger) |
| 99 | |
| 100 | Parameters : |
| 101 | DWORD event : event that occurred |
| 102 | LPVOID eip : instruction pointer when exception occurred |
| 103 | |
| 104 | (no return value) |
| 105 | |
| 106 | Notes : |
| 107 | Handlers are called on a last-installed, first called basis, until a |
| 108 | handler returns TRUE. If no handler returns TRUE (or no hanlder is |
| 109 | installed), the default behavior is to call ExitProcess |
| 110 | --*/ |
| 111 | void SEHHandleControlEvent(DWORD event, LPVOID eip); |
| 112 | #endif // !HAVE_MACH_EXCEPTIONS |
| 113 | |
| 114 | #if !HAVE_MACH_EXCEPTIONS |
| 115 | /*++ |
| 116 | Function : |
| 117 | SEHSetSafeState |
| 118 | |
| 119 | specify whether the current thread is in a state where exception handling |
| 120 | of signals can be done safely |
| 121 | |
| 122 | Parameters: |
| 123 | CPalThread * pthrCurrent : reference to the current thread. |
| 124 | BOOL state : TRUE if the thread is safe, FALSE otherwise |
| 125 | |
| 126 | (no return value) |
| 127 | --*/ |
| 128 | void SEHSetSafeState(CorUnix::CPalThread *pthrCurrent, BOOL state); |
| 129 | |
| 130 | /*++ |
| 131 | Function : |
| 132 | SEHGetSafeState |
| 133 | |
| 134 | determine whether the current thread is in a state where exception handling |
| 135 | of signals can be done safely |
| 136 | |
| 137 | Parameters: |
| 138 | CPalThread * pthrCurrent : reference to the current thread. |
| 139 | |
| 140 | Return value : |
| 141 | TRUE if the thread is in a safe state, FALSE otherwise |
| 142 | --*/ |
| 143 | BOOL SEHGetSafeState(CorUnix::CPalThread *pthrCurrent); |
| 144 | #endif // !HAVE_MACH_EXCEPTIONS |
| 145 | |
| 146 | extern "C" |
| 147 | { |
| 148 | |
| 149 | #ifdef FEATURE_PAL_SXS |
| 150 | /*++ |
| 151 | Function : |
| 152 | SEHEnable |
| 153 | |
| 154 | Enable SEH-related stuff on this thread |
| 155 | |
| 156 | Parameters: |
| 157 | CPalThread * pthrCurrent : reference to the current thread. |
| 158 | |
| 159 | Return value : |
| 160 | ERROR_SUCCESS, if enabling succeeded |
| 161 | an error code, otherwise |
| 162 | --*/ |
| 163 | CorUnix::PAL_ERROR SEHEnable(CorUnix::CPalThread *pthrCurrent); |
| 164 | |
| 165 | /*++ |
| 166 | Function : |
| 167 | SEHDisable |
| 168 | |
| 169 | Disable SEH-related stuff on this thread |
| 170 | |
| 171 | Parameters: |
| 172 | CPalThread * pthrCurrent : reference to the current thread. |
| 173 | |
| 174 | Return value : |
| 175 | ERROR_SUCCESS, if enabling succeeded |
| 176 | an error code, otherwise |
| 177 | --*/ |
| 178 | CorUnix::PAL_ERROR SEHDisable(CorUnix::CPalThread *pthrCurrent); |
| 179 | |
| 180 | #endif // FEATURE_PAL_SXS |
| 181 | |
| 182 | } |
| 183 | |
| 184 | #endif /* _PAL_SEH_HPP_ */ |
| 185 | |
| 186 | |