1 /* Test that libsigsegv does not interfere with internal fault handling
3 Copyright (C) 2009 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_SIGSEGV_RECOVERY
27 /* Cygwin uses faults for internal purposes, i.e. even when the user passes
28 valid pointers to all system calls.
30 An example is pthread_attr_init. POSIX:2001 states pthread_attr_init may
31 fail with EBUSY if an object was previously initialized. Recognizing
32 whether an object was previously initialized can be done with a magic
33 cookie. If the type pthread_attr_t is defined as
34 struct { int magic; ... other_data; }
35 it is easy. But in Cygwin, pthread_attr_t is defined as a pointer type.
36 Cygwin implements the check by testing whether the pthread_attr_t contains
37 a pointer to a memory region that contains a particular magic cookie.
38 This indirection may fault. (Search for pthread_attr_init and
39 verifyable_object_isvalid in the Cygwin sources.) In this example we trick
40 Cygwin into dereferencing the address 0x01010101. */
47 handler (void *fault_address
, int serious
)
57 sigsegv_install_handler (handler
);
59 /* Set up a pthread_attr_t that contains a pointer to address 0x01010101. */
60 memset (&a
, 1, sizeof (a
));
62 /* Make a system call to initialize it. It should succeed and not invoke
64 pthread_attr_init (&a
);