@@ -30,15 +30,17 @@ SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do
30
30
#include " pal/signal.hpp"
31
31
32
32
#include " pal/palinternal.h"
33
+
34
+ #include < errno.h>
35
+ #include < signal.h>
36
+
33
37
#if !HAVE_MACH_EXCEPTIONS
34
38
#include " pal/init.h"
35
39
#include " pal/process.h"
36
40
#include " pal/debug.h"
37
41
#include " pal/virtual.h"
38
42
#include " pal/utils.h"
39
43
40
- #include < signal.h>
41
- #include < errno.h>
42
44
#include < string.h>
43
45
#include < sys/ucontext.h>
44
46
#include < sys/utsname.h>
@@ -47,15 +49,16 @@ SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do
47
49
48
50
#include " pal/context.h"
49
51
50
- using namespace CorUnix ;
51
-
52
52
#ifdef SIGRTMIN
53
53
#define INJECT_ACTIVATION_SIGNAL SIGRTMIN
54
54
#endif
55
55
56
56
#if !defined(INJECT_ACTIVATION_SIGNAL) && defined(FEATURE_HIJACK)
57
57
#error FEATURE_HIJACK requires INJECT_ACTIVATION_SIGNAL to be defined
58
58
#endif
59
+ #endif // !HAVE_MACH_EXCEPTIONS
60
+
61
+ using namespace CorUnix ;
59
62
60
63
/* local type definitions *****************************************************/
61
64
@@ -67,45 +70,50 @@ typedef void *siginfo_t;
67
70
#endif /* !HAVE_SIGINFO_T */
68
71
typedef void (*SIGFUNC)(int , siginfo_t *, void *);
69
72
73
+ #if !HAVE_MACH_EXCEPTIONS
70
74
// Return context and status for the signal_handler_worker.
71
75
struct SignalHandlerWorkerReturnPoint
72
76
{
73
77
bool returnFromHandler;
74
78
CONTEXT context;
75
79
};
80
+ #endif // !HAVE_MACH_EXCEPTIONS
76
81
77
82
/* internal function declarations *********************************************/
78
83
84
+ static void sigterm_handler (int code, siginfo_t *siginfo, void *context);
85
+ #if !HAVE_MACH_EXCEPTIONS
79
86
static void sigill_handler (int code, siginfo_t *siginfo, void *context);
80
87
static void sigfpe_handler (int code, siginfo_t *siginfo, void *context);
81
88
static void sigsegv_handler (int code, siginfo_t *siginfo, void *context);
82
89
static void sigtrap_handler (int code, siginfo_t *siginfo, void *context);
83
90
static void sigbus_handler (int code, siginfo_t *siginfo, void *context);
84
91
static void sigint_handler (int code, siginfo_t *siginfo, void *context);
85
92
static void sigquit_handler (int code, siginfo_t *siginfo, void *context);
86
- static void sigterm_handler (int code, siginfo_t *siginfo, void *context);
87
93
88
94
static bool common_signal_handler (int code, siginfo_t *siginfo, void *sigcontext, int numParams, ...);
89
95
90
96
#ifdef INJECT_ACTIVATION_SIGNAL
91
97
static void inject_activation_handler (int code, siginfo_t *siginfo, void *context);
92
98
#endif
99
+ #endif // !HAVE_MACH_EXCEPTIONS
93
100
94
101
static void handle_signal (int signal_id, SIGFUNC sigfunc, struct sigaction *previousAction, int additionalFlags = 0 );
95
102
static void restore_signal (int signal_id, struct sigaction *previousAction);
96
103
97
104
/* internal data declarations *********************************************/
98
105
106
+ static bool registered_sigterm_handler = false ;
107
+
108
+ struct sigaction g_previous_sigterm;
109
+ #if !HAVE_MACH_EXCEPTIONS
99
110
struct sigaction g_previous_sigill;
100
111
struct sigaction g_previous_sigtrap;
101
112
struct sigaction g_previous_sigfpe;
102
113
struct sigaction g_previous_sigbus;
103
114
struct sigaction g_previous_sigsegv;
104
115
struct sigaction g_previous_sigint;
105
116
struct sigaction g_previous_sigquit;
106
- struct sigaction g_previous_sigterm;
107
-
108
- static bool registered_sigterm_handler = false ;
109
117
110
118
#ifdef INJECT_ACTIVATION_SIGNAL
111
119
struct sigaction g_previous_activation;
@@ -114,9 +122,11 @@ struct sigaction g_previous_activation;
114
122
// Offset of the local variable containing native context in the common_signal_handler function.
115
123
// This offset is relative to the frame pointer.
116
124
int g_common_signal_handler_context_locvar_offset = 0 ;
125
+ #endif // !HAVE_MACH_EXCEPTIONS
117
126
118
127
/* public function definitions ************************************************/
119
128
129
+ #if !HAVE_MACH_EXCEPTIONS
120
130
/* ++
121
131
Function :
122
132
EnsureSignalAlternateStack
@@ -198,6 +208,7 @@ void FreeSignalAlternateStack()
198
208
free (oss.ss_sp );
199
209
}
200
210
}
211
+ #endif // !HAVE_MACH_EXCEPTIONS
201
212
202
213
/* ++
203
214
Function :
@@ -215,6 +226,7 @@ BOOL SEHInitializeSignals(DWORD flags)
215
226
{
216
227
TRACE (" Initializing signal handlers\n " );
217
228
229
+ #if !HAVE_MACH_EXCEPTIONS
218
230
/* we call handle_signal for every possible signal, even
219
231
if we don't provide a signal handler.
220
232
@@ -241,13 +253,15 @@ BOOL SEHInitializeSignals(DWORD flags)
241
253
{
242
254
return FALSE ;
243
255
}
256
+ #endif // !HAVE_MACH_EXCEPTIONS
244
257
245
258
if (flags & PAL_INITIALIZE_REGISTER_SIGTERM_HANDLER)
246
259
{
247
260
handle_signal (SIGTERM, sigterm_handler, &g_previous_sigterm);
248
261
registered_sigterm_handler = true ;
249
262
}
250
263
264
+ #if !HAVE_MACH_EXCEPTIONS
251
265
#ifdef INJECT_ACTIVATION_SIGNAL
252
266
handle_signal (INJECT_ACTIVATION_SIGNAL, inject_activation_handler, &g_previous_activation);
253
267
#endif
@@ -261,6 +275,7 @@ BOOL SEHInitializeSignals(DWORD flags)
261
275
issued a SIGPIPE will, instead, report an error and set errno to EPIPE.
262
276
*/
263
277
signal (SIGPIPE, SIG_IGN);
278
+ #endif // !HAVE_MACH_EXCEPTIONS
264
279
265
280
return TRUE ;
266
281
}
@@ -285,26 +300,31 @@ void SEHCleanupSignals()
285
300
{
286
301
TRACE (" Restoring default signal handlers\n " );
287
302
303
+ #if !HAVE_MACH_EXCEPTIONS
288
304
restore_signal (SIGILL, &g_previous_sigill);
289
305
restore_signal (SIGTRAP, &g_previous_sigtrap);
290
306
restore_signal (SIGFPE, &g_previous_sigfpe);
291
307
restore_signal (SIGBUS, &g_previous_sigbus);
292
308
restore_signal (SIGSEGV, &g_previous_sigsegv);
293
309
restore_signal (SIGINT, &g_previous_sigint);
294
310
restore_signal (SIGQUIT, &g_previous_sigquit);
311
+ #endif // !HAVE_MACH_EXCEPTIONS
295
312
296
313
if (registered_sigterm_handler)
297
314
{
298
315
restore_signal (SIGTERM, &g_previous_sigterm);
299
316
}
300
317
318
+ #if !HAVE_MACH_EXCEPTIONS
301
319
#ifdef INJECT_ACTIVATION_SIGNAL
302
320
restore_signal (INJECT_ACTIVATION_SIGNAL, &g_previous_activation);
303
321
#endif
322
+ #endif // !HAVE_MACH_EXCEPTIONS
304
323
}
305
324
306
325
/* internal function definitions **********************************************/
307
326
327
+ #if !HAVE_MACH_EXCEPTIONS
308
328
/* ++
309
329
Function :
310
330
sigill_handler
@@ -571,6 +591,7 @@ static void sigquit_handler(int code, siginfo_t *siginfo, void *context)
571
591
restore_signal (code, &g_previous_sigquit);
572
592
kill (gPID , code);
573
593
}
594
+ #endif // !HAVE_MACH_EXCEPTIONS
574
595
575
596
/* ++
576
597
Function :
@@ -601,6 +622,7 @@ static void sigterm_handler(int code, siginfo_t *siginfo, void *context)
601
622
}
602
623
}
603
624
625
+ #if !HAVE_MACH_EXCEPTIONS
604
626
#ifdef INJECT_ACTIVATION_SIGNAL
605
627
/* ++
606
628
Function :
@@ -799,6 +821,7 @@ static bool common_signal_handler(int code, siginfo_t *siginfo, void *sigcontext
799
821
800
822
return false ;
801
823
}
824
+ #endif // !HAVE_MACH_EXCEPTIONS
802
825
803
826
/* ++
804
827
Function :
@@ -856,5 +879,3 @@ void restore_signal(int signal_id, struct sigaction *previousAction)
856
879
errno, strerror (errno));
857
880
}
858
881
}
859
-
860
- #endif // !HAVE_MACH_EXCEPTIONS
0 commit comments