xref: /haiku/src/system/libroot/posix/arch/generic/setjmp_save_sigs.c (revision 830f67ef991407f287dbc1238aa5f5906d90c991)
1 /*
2  * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <setjmp.h>
8 
9 
10 /** This function is called by sigsetjmp() only */
11 
12 int __setjmp_save_sigs(jmp_buf buffer, int saveMask);
13 
14 int
15 __setjmp_save_sigs(jmp_buf buffer, int saveMask)
16 {
17 	// If the signal mask shall be saved, we save the inverted signal mask. The
18 	// reason for this is that due to unblockable signals the inverted signal
19 	// mask is never zero and thus we can use a zero value to indicate that the
20 	// mask has not been saved.
21 	sigset_t signalMask;
22 	if (saveMask != 0 && sigprocmask(SIG_BLOCK, NULL, &signalMask) == 0)
23 		buffer[0].inverted_signal_mask = ~signalMask;
24 	else
25 		buffer[0].inverted_signal_mask = 0;
26 
27 	return 0;
28 }
29