1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2003-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 /* Verify that unw_resume() restores the signal mask at proper time. */
32 #include <libunwind.h>
40 #ifdef HAVE_IA64INTRIN_H
41 # include <ia64intrin.h>
44 #define panic(args...) \
45 do { fprintf (stderr, args); ++nerrors; } while (0)
49 int got_usr1, got_usr2;
56 # ifdef __INTEL_COMPILER
57 return __getReg (_IA64_REG_AR_BSP);
59 return (uintptr_t) __builtin_ia64_bsp ();
66 #ifdef TEST_WITH_SIGINFO
70 void *ucontext UNUSED)
77 sigset_t mask, oldmask;
85 printf ("bsp = %llx\n", (unsigned long long) get_bsp ());
89 printf ("got signal %d\n", sig);
97 sigaddset (&mask, SIGUSR2);
98 sigprocmask (SIG_BLOCK, &mask, &oldmask);
99 kill (getpid (), SIGUSR2); /* pend SIGUSR2 */
101 signal (SIGUSR1, SIG_IGN);
103 if ((ret = unw_getcontext (&uc)) < 0)
104 panic ("unw_getcontext() failed: ret=%d\n", ret);
105 #if UNW_TARGET_X86_64
106 /* unw_getcontext() doesn't save signal mask to avoid a syscall */
107 uc.uc_sigmask = oldmask;
109 if ((ret = unw_init_local (&c, &uc)) < 0)
110 panic ("unw_init_local() failed: ret=%d\n", ret);
112 if ((ret = unw_step (&c)) < 0) /* step to signal trampoline */
113 panic ("unw_step(1) failed: ret=%d\n", ret);
115 if ((ret = unw_step (&c)) < 0) /* step to kill() */
116 panic ("unw_step(2) failed: ret=%d\n", ret);
118 #if defined(UNW_TARGET_TILEGX)
119 if ((ret = unw_step (&c)) < 0) /* step to signal trampoline */
120 panic ("unw_step(2) failed: ret=%d\n", ret);
123 if ((ret = unw_get_reg (&c, UNW_REG_IP, &ip)) < 0)
124 panic ("unw_get_reg(IP) failed: ret=%d\n", ret);
126 printf ("resuming at 0x%lx, with SIGUSR2 pending\n",
130 else if (sig == SIGUSR2)
136 printf ("OK: stack still at %p\n", &foo);
138 signal (SIGUSR2, SIG_IGN);
141 panic ("Got unexpected signal %d\n", sig);
145 main (int argc, char **argv UNUSED)
154 memset (&sa, 0, sizeof(sa));
155 #ifdef TEST_WITH_SIGINFO
156 sa.sa_sigaction = handler;
157 sa.sa_flags = SA_SIGINFO;
159 sa.sa_handler = handler;
162 if (sigaction (SIGUSR1, &sa, NULL) != 0 ||
163 sigaction (SIGUSR2, &sa, NULL) != 0)
165 fprintf (stderr, "sigaction() failed: %s\n", strerror (errno));
169 /* Use the FPU a bit; otherwise we get spurious errors should the
170 signal handler need to use the FPU for any reason. This seems to
178 return -1; /* can't happen, but don't tell the compiler... */
181 printf ("sending SIGUSR1\n");
182 kill (getpid (), SIGUSR1);
185 panic ("failed to get SIGUSR2\n");
189 fprintf (stderr, "FAILURE: detected %d errors\n", nerrors);
194 printf ("SUCCESS\n");