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
9Module Name:
10
11 include/pal/seh.hpp
12
13Abstract:
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/*++
31Function :
32 SEHInitialize
33
34 Initialize all SEH-related stuff (signals, etc)
35
36Parameters:
37 CPalThread * pthrCurrent : reference to the current thread.
38 flags : PAL initialize flags
39
40Return value:
41 TRUE if SEH support initialization succeeded,
42 FALSE otherwise
43
44--*/
45BOOL
46SEHInitialize(CorUnix::CPalThread *pthrCurrent, DWORD flags);
47
48/*++
49Function :
50 SEHCleanup
51
52 Clean up SEH-related stuff(signals, etc)
53
54Parameters:
55 None
56
57 (no return value)
58--*/
59VOID
60SEHCleanup();
61
62/*++
63Function:
64 SEHProcessException
65
66 Send the PAL exception to any handler registered.
67
68Parameters:
69 PAL_SEHException* exception
70
71Return 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--*/
77BOOL
78SEHProcessException(PAL_SEHException* exception);
79
80/*++
81Function:
82 AllocateExceptionRecords
83
84Parameters:
85 exceptionRecord - output pointer to the allocated Windows exception record
86 contextRecord - output pointer to the allocated Windows context record
87--*/
88VOID
89AllocateExceptionRecords(EXCEPTION_RECORD** exceptionRecord, CONTEXT** contextRecord);
90
91#if !HAVE_MACH_EXCEPTIONS
92// TODO: Implement for Mach exceptions. Not in CoreCLR surface area.
93/*++
94Function :
95 SEHHandleControlEvent
96
97 handle Control-C and Control-Break events (call handler routines,
98 notify debugger)
99
100Parameters :
101 DWORD event : event that occurred
102 LPVOID eip : instruction pointer when exception occurred
103
104(no return value)
105
106Notes :
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--*/
111void SEHHandleControlEvent(DWORD event, LPVOID eip);
112#endif // !HAVE_MACH_EXCEPTIONS
113
114#if !HAVE_MACH_EXCEPTIONS
115/*++
116Function :
117 SEHSetSafeState
118
119 specify whether the current thread is in a state where exception handling
120 of signals can be done safely
121
122Parameters:
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--*/
128void SEHSetSafeState(CorUnix::CPalThread *pthrCurrent, BOOL state);
129
130/*++
131Function :
132 SEHGetSafeState
133
134 determine whether the current thread is in a state where exception handling
135 of signals can be done safely
136
137Parameters:
138 CPalThread * pthrCurrent : reference to the current thread.
139
140Return value :
141 TRUE if the thread is in a safe state, FALSE otherwise
142--*/
143BOOL SEHGetSafeState(CorUnix::CPalThread *pthrCurrent);
144#endif // !HAVE_MACH_EXCEPTIONS
145
146extern "C"
147{
148
149#ifdef FEATURE_PAL_SXS
150/*++
151Function :
152 SEHEnable
153
154 Enable SEH-related stuff on this thread
155
156Parameters:
157 CPalThread * pthrCurrent : reference to the current thread.
158
159Return value :
160 ERROR_SUCCESS, if enabling succeeded
161 an error code, otherwise
162--*/
163CorUnix::PAL_ERROR SEHEnable(CorUnix::CPalThread *pthrCurrent);
164
165/*++
166Function :
167 SEHDisable
168
169 Disable SEH-related stuff on this thread
170
171Parameters:
172 CPalThread * pthrCurrent : reference to the current thread.
173
174Return value :
175 ERROR_SUCCESS, if enabling succeeded
176 an error code, otherwise
177--*/
178CorUnix::PAL_ERROR SEHDisable(CorUnix::CPalThread *pthrCurrent);
179
180#endif // FEATURE_PAL_SXS
181
182}
183
184#endif /* _PAL_SEH_HPP_ */
185
186