1 /* Test that libsigsegv does not interfere with fault handling inside
3 Copyright (C) 2009-2010 Eric Blake <ebb9@byu.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
25 #if HAVE_STACK_OVERFLOW_RECOVERY && HAVE_SIGSEGV_RECOVERY && HAVE_EFAULT_SUPPORT
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 sigsegv_handler (void *fault_address
, int serious
)
43 /* This test is only enabled when ENABLE_EFAULT is true. If we get here,
44 the ENABLE_EFAULT handling in libsigsegv is incomplete. */
49 stackoverflow_handler (int emergency
, stackoverflow_context_t scp
)
51 /* This test is only enabled when ENABLE_EFAULT is true. If we get here,
52 the ENABLE_EFAULT handling in libsigsegv is incomplete. */
59 /* Test whether the OS handles some faults by itself. */
60 if (open (null_pointer
, O_RDONLY
) != -1 || errno
!= EFAULT
)
62 fprintf (stderr
, "EFAULT not detected alone.\n");
66 /* Prepare the storage for the alternate stack. */
67 prepare_alternate_stack ();
69 /* Install the stack overflow handler. */
70 if (stackoverflow_install_handler (&stackoverflow_handler
,
75 /* Install the SIGSEGV handler. */
76 if (sigsegv_install_handler (&sigsegv_handler
) < 0)
79 /* Test that the library does not interfere with OS faults. */
80 if (open (null_pointer
, O_RDONLY
) != -1 || errno
!= EFAULT
)
82 fprintf (stderr
, "EFAULT not detected with handler.\n");
86 /* Validate that the alternate stack did not overflow. */
87 check_alternate_stack_no_overflow ();
90 printf ("Test passed.\n");