1 | /* Tests of signal delivery on an alternate stack (_Exit). |
2 | Copyright (C) 2019-2022 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <support/xsignal.h> |
20 | #include <support/support.h> |
21 | #include <support/check.h> |
22 | #include <stdlib.h> |
23 | |
24 | /* C2011 7.4.1.1p5 specifies that only the following operations are |
25 | guaranteed to be well-defined inside an asynchronous signal handler: |
26 | * any operation on a lock-free atomic object |
27 | * assigning a value to an object declared as volatile sig_atomic_t |
28 | * calling abort, _Exit, quick_exit, or signal |
29 | * signal may only be called with its first argument equal to the |
30 | number of the signal that caused the handler to be called |
31 | |
32 | We use this list as a guideline for the set of operations that ought |
33 | also to be safe in a _synchronous_ signal delivered on an alternate |
34 | signal stack with only MINSIGSTKSZ bytes of space. |
35 | |
36 | This test program tests calls to _Exit. */ |
37 | |
38 | #define EXPECTED_STATUS 3 |
39 | |
40 | static void |
41 | handler (int unused) |
42 | { |
43 | _Exit (EXPECTED_STATUS); |
44 | } |
45 | |
46 | int |
47 | do_test (void) |
48 | { |
49 | void *sstk = xalloc_sigstack (size: 0); |
50 | struct sigaction sa; |
51 | |
52 | sa.sa_handler = handler; |
53 | sa.sa_flags = SA_RESTART | SA_ONSTACK; |
54 | sigfillset (&sa.sa_mask); |
55 | if (sigaction (SIGUSR1, act: &sa, oact: 0)) |
56 | FAIL_RET ("sigaction (SIGUSR1, handler): %m\n" ); |
57 | |
58 | raise (SIGUSR1); |
59 | |
60 | xfree_sigstack (stack: sstk); |
61 | FAIL_RET ("test process was not terminated by _Exit in signal handler" ); |
62 | } |
63 | |
64 | #include <support/test-driver.c> |
65 | |