1 /* Test that libsigsegv does not interfere with fault handling inside
3 Copyright (C) 2009-2010 Eric Blake <ebb9@byu.net>
4 Copyright (C) 2021 Bruno Haible <bruno@clisp.org>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
25 #if HAVE_STACK_OVERFLOW_RECOVERY && HAVE_EFAULT_SUPPORT
33 #include "altstack-util.h"
36 If we were to use a literal NULL, gcc would give a warning on glibc systems:
37 "warning: null argument where non-null required". */
38 const char *null_pointer
= NULL
;
41 handler (int emergency
, stackoverflow_context_t scp
)
43 /* This test is only enabled when ENABLE_EFAULT is true. If we get here,
44 the ENABLE_EFAULT handling in libsigsegv is incomplete. */
51 /* Test whether the OS handles some faults by itself. */
52 if (open (null_pointer
, O_RDONLY
) != -1 || errno
!= EFAULT
)
54 fprintf (stderr
, "EFAULT not detected alone.\n");
58 /* Prepare the storage for the alternate stack. */
59 prepare_alternate_stack ();
61 /* Install the stack overflow handler. */
62 if (stackoverflow_install_handler (&handler
, mystack
, SIGSTKSZ
) < 0)
65 /* Test that the library does not interfere with OS faults. */
66 if (open (null_pointer
, O_RDONLY
) != -1 || errno
!= EFAULT
)
68 fprintf (stderr
, "EFAULT not detected with handler.\n");
72 /* Validate that the alternate stack did not overflow. */
73 check_alternate_stack_no_overflow ();
76 printf ("Test passed.\n");