1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2004 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 /* Test to verify that we can siglongjmp() into a frame whose register
25 window is not backed by valid memory. */
42 #ifdef HAVE_IA64INTRIN_H
43 # include <ia64intrin.h>
46 static sigjmp_buf env;
47 static int return_level;
48 static uintptr_t return_bsp;
54 #ifdef __INTEL_COMPILER
55 return __getReg (_IA64_REG_AR_BSP);
57 return (uintptr_t) __builtin_ia64_bsp ();
62 sighandler (int signal, void *siginfo, void *sigcontext)
64 ucontext_t *uc = sigcontext;
68 printf ("got signal, stack at %p, saved bsp=0x%lx\n",
69 &local, uc->uc_mcontext.sc_ar_bsp);
73 /* Direct call of doit () at the end of doit () would get optimized by GCC to
75 static void doit (int n);
76 typedef void (*doit_type) (int);
77 static volatile doit_type doit_pointer = doit;
82 uintptr_t guard_page_addr, bsp = get_bsp ();
87 size_t page_size = getpagesize ();
89 guard_page_addr = (bsp + page_size - 1) & -page_size;
91 printf ("guard_page_addr = 0x%lx\n", (unsigned long) guard_page_addr);
92 ret = mmap ((void *) guard_page_addr, page_size, PROT_NONE,
93 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
94 if (ret != (void *) guard_page_addr)
96 if (ret == MAP_FAILED)
99 fprintf (stderr, "mmap() returned %p, expected 0x%lx\n",
100 ret, guard_page_addr);
105 if (sigsetjmp (env, 1))
111 (*doit_pointer) (n + 1);
115 main (int argc, char **argv)
123 ss.ss_sp = malloc (2 * SIGSTKSZ);
124 if (ss.ss_sp == NULL)
126 puts ("failed to allocate alternate stack");
130 ss.ss_size = 2 * SIGSTKSZ;
131 if (sigaltstack (&ss, NULL) < 0)
133 printf ("sigaltstack failed: %s\n", strerror (errno));
137 sa.sa_handler = (void (*) (int)) sighandler;
138 sigemptyset (&sa.sa_mask);
139 sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
140 if (sigaction (SIGSEGV, &sa, NULL) < 0)
142 printf ("sigaction failed: %s\n", strerror (errno));
150 printf ("sigsetjmp returned at level %d bsp=0x%lx\n",
151 return_level, return_bsp);
152 puts ("Test succeeded!");