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 of the License, or
8 (at your option) any later version.
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, see <https://www.gnu.org/licenses/>. */
24 #if HAVE_SIGSEGV_RECOVERY
26 /* Cygwin uses faults for internal purposes, i.e. even when the user passes
27 valid pointers to all system calls.
29 An example is pthread_attr_init. POSIX:2001 states pthread_attr_init may
30 fail with EBUSY if an object was previously initialized. Recognizing
31 whether an object was previously initialized can be done with a magic
32 cookie. If the type pthread_attr_t is defined as
33 struct { int magic; ... other_data; }
34 it is easy. But in Cygwin, pthread_attr_t is defined as a pointer type.
35 Cygwin implements the check by testing whether the pthread_attr_t contains
36 a pointer to a memory region that contains a particular magic cookie.
37 This indirection may fault. (Search for pthread_attr_init and
38 verifyable_object_isvalid in the Cygwin sources.) In this example we trick
39 Cygwin into dereferencing the address 0x01010101. */
46 handler (void *fault_address
, int serious
)
56 sigsegv_install_handler (handler
);
58 /* Set up a pthread_attr_t that contains a pointer to address 0x01010101. */
59 memset (&a
, 1, sizeof (a
));
61 /* Make a system call to initialize it. It should succeed and not invoke
63 pthread_attr_init (&a
);