Commit | Line | Data |
---|---|---|
8bfabb04 AC |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
7b6bb8da | 3 | Copyright 1996, 1999, 2003, 2004, 2007, 2008, 2009, 2010, 2011 |
0fb0cc75 | 4 | Free Software Foundation, Inc. |
8bfabb04 AC |
5 | |
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 | |
a9762ec7 | 8 | the Free Software Foundation; either version 3 of the License, or |
8bfabb04 AC |
9 | (at your option) any later version. |
10 | ||
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. | |
a9762ec7 | 15 | |
8bfabb04 | 16 | You should have received a copy of the GNU General Public License |
a9762ec7 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8bfabb04 AC |
18 | |
19 | #include <signal.h> | |
20 | #include <setjmp.h> | |
725603e1 | 21 | #include <stdlib.h> |
9d9030bc | 22 | #include <string.h> |
8bfabb04 AC |
23 | |
24 | enum tests { | |
9d9030bc | 25 | code_entry_point, code_descriptor, data_read, data_write |
8bfabb04 AC |
26 | }; |
27 | ||
28 | static volatile enum tests test; | |
29 | ||
30 | /* Some basic types and zero buffers. */ | |
31 | ||
32 | typedef long data_t; | |
33 | typedef long code_t (void); | |
9d9030bc AC |
34 | data_t *volatile data; |
35 | code_t *volatile code; | |
36 | /* "desc" is intentionally initialized to a data object. This is | |
37 | needed to test function descriptors on arches like ia64. */ | |
38 | data_t zero[10]; | |
39 | code_t *volatile desc = (code_t *) (void *) zero; | |
8bfabb04 | 40 | |
8f5a3103 | 41 | sigjmp_buf env; |
8bfabb04 AC |
42 | |
43 | extern void | |
44 | keeper (int sig) | |
45 | { | |
725603e1 | 46 | siglongjmp (env, 0); |
8bfabb04 AC |
47 | } |
48 | ||
49 | extern long | |
50 | bowler (void) | |
51 | { | |
52 | switch (test) | |
53 | { | |
9d9030bc AC |
54 | case data_read: |
55 | /* Try to read address zero. */ | |
56 | return (*data); | |
57 | case data_write: | |
58 | /* Try to write (the assignment) to address zero. */ | |
59 | return (*data) = 1; | |
8bfabb04 | 60 | case code_entry_point: |
9d9030bc AC |
61 | /* For typical architectures, call a function at address |
62 | zero. */ | |
63 | return (*code) (); | |
8bfabb04 | 64 | case code_descriptor: |
9d9030bc AC |
65 | /* For atypical architectures that use function descriptors, |
66 | call a function descriptor, the code field of which is zero | |
67 | (which has the effect of jumping to address zero). */ | |
68 | return (*desc) (); | |
8bfabb04 AC |
69 | } |
70 | } | |
71 | ||
72 | int | |
73 | main () | |
74 | { | |
75 | static volatile int i; | |
725603e1 UW |
76 | |
77 | struct sigaction act; | |
78 | memset (&act, 0, sizeof act); | |
79 | act.sa_handler = keeper; | |
80 | sigaction (SIGSEGV, &act, NULL); | |
aacd552b | 81 | sigaction (SIGBUS, &act, NULL); |
725603e1 | 82 | |
8bfabb04 AC |
83 | for (i = 0; i < 10; i++) |
84 | { | |
725603e1 | 85 | sigsetjmp (env, 1); |
8bfabb04 AC |
86 | bowler (); |
87 | } | |
88 | } |