From 51b47e4ecf182fcc76f257b909155b21af5f06df Mon Sep 17 00:00:00 2001 From: "mostang.com!davidm" Date: Tue, 21 Jan 2003 17:41:20 +0000 Subject: [PATCH] Test unwinding across signal delivered on alternate signal stack. (Logical change 1.40) --- tests/bt.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/bt.c b/tests/bt.c index 926e23d9..21d2692f 100644 --- a/tests/bt.c +++ b/tests/bt.c @@ -1,5 +1,5 @@ /* libunwind - a platform-independent unwind library - Copyright (C) 2001-2002 Hewlett-Packard Co + Copyright (C) 2001-2003 Hewlett-Packard Co Contributed by David Mosberger-Tang This file is part of libunwind. @@ -25,10 +25,12 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include #include #include #include #include +#include #include #include @@ -88,8 +90,10 @@ foo (void) void *buffer[20]; int i, n; + printf ("\texplicit backtrace:\n"); do_backtrace (); + printf ("\tvia backtrace():\n"); n = backtrace (buffer, 20); for (i = 0; i < n; ++i) printf ("[%d] ip=%p\n", i, buffer[i]); @@ -102,7 +106,9 @@ sighandler (int signal, struct sigcontext sc) sighandler (int signal, void *siginfo, struct sigcontext *sc) #endif { - printf ("sighandler: got signal %d", signal); + int sp; + + printf ("sighandler: got signal %d, sp=%p", signal, &sp); #if UNW_TARGET_IA64 printf (" @ %lx", sc->sc_ip); #elif UNW_TARGET_X86 @@ -116,9 +122,31 @@ sighandler (int signal, void *siginfo, struct sigcontext *sc) int main (int argc, char **argv) { + struct sigaction act; + stack_t stk; + + printf ("Normal backtrace:\n"); foo (); + printf ("\nBacktrace across signal handler:\n"); signal (SIGTERM, (sighandler_t) sighandler); kill (getpid (), SIGTERM); + + printf ("Backtrace across signal handler on alternate stack:\n"); + stk.ss_sp = malloc (SIGSTKSZ); + if (!stk.ss_sp) + panic ("failed to allocate SIGSTKSZ (%u) bytes\n", SIGSTKSZ); + stk.ss_size = SIGSTKSZ; + stk.ss_flags = 0; + if (sigaltstack (&stk, NULL) < 0) + panic ("sigaltstack: %s\n", strerror (errno)); + + memset (&act, 0, sizeof (act)); + act.sa_handler = (void (*)(int)) sighandler; + act.sa_flags = SA_ONSTACK; + if (sigaction (SIGTERM, &act, NULL) < 0) + panic ("sigaction: %s\n", strerror (errno)); + kill (getpid (), SIGTERM); + return 0; }