Bump version number.
[libsigsegv/ericb.git] / tests / cygwin1.c
bloba685df0a6dd119593e4fa455127bb64fd85be9c6
1 /* Test that libsigsegv does not interfere with internal fault handling
2 inside system calls.
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)
8 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, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 #ifndef _MSC_VER
20 # include <config.h>
21 #endif
23 #include "sigsegv.h"
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. */
42 #include <pthread.h>
43 #include <stdlib.h>
44 #include <string.h>
46 static int
47 handler (void *fault_address, int serious)
49 exit (2);
52 int
53 main ()
55 pthread_attr_t a;
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
63 the handler. */
64 pthread_attr_init (&a);
66 return 0;
69 #endif