1 /* Test that sigprocmask does not read from the unused part of jmpbuf.
2    Copyright (C) 2017-2021 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 <stdlib.h>
20 #include <signal.h>
21 #include <string.h>
22 #include <errno.h>
23 #include <setjmpP.h>
24 #include <support/next_to_fault.h>
25 
26 #define SIZEOF_SIGSET_T sizeof (__jmp_buf_sigset_t)
27 
28 static int
do_test(void)29 do_test (void)
30 {
31   sigjmp_buf sj;
32   struct support_next_to_fault sigset_t_buf
33     = support_next_to_fault_allocate (SIZEOF_SIGSET_T);
34   sigset_t *m_p = (sigset_t *) sigset_t_buf.buffer;
35   sigset_t m;
36 
37   sigemptyset (&m);
38   memcpy (m_p, &m, SIZEOF_SIGSET_T);
39   sigprocmask (SIG_SETMASK, m_p, NULL);
40   memcpy (&m, m_p, SIZEOF_SIGSET_T);
41   if (sigsetjmp (sj, 0) == 0)
42     {
43       sigaddset (&m, SIGUSR1);
44       memcpy (m_p, &m, SIZEOF_SIGSET_T);
45       sigprocmask (SIG_SETMASK, m_p, NULL);
46       memcpy (&m, m_p, SIZEOF_SIGSET_T);
47       siglongjmp (sj, 1);
48       return EXIT_FAILURE;
49     }
50   sigprocmask (SIG_SETMASK, NULL, m_p);
51   memcpy (&m, m_p, SIZEOF_SIGSET_T);
52   return sigismember (&m, SIGUSR1) ? EXIT_SUCCESS : EXIT_FAILURE;
53 }
54 
55 #include <support/test-driver.c>
56