diff options
author | hp.com!davidm <hp.com!davidm> | 2004-08-31 13:59:10 +0000 |
---|---|---|
committer | hp.com!davidm <hp.com!davidm> | 2004-08-31 13:59:10 +0000 |
commit | e29611e7d343a6f84dd9c5fd94415615ef49a4b0 (patch) | |
tree | 2a488fe1f557bbc42c02e1e4579dd9f186e640df | |
parent | 9c01662f1d7cd4ddf1d5bb109eaaef4db428102e (diff) | |
download | libunwind-e29611e7d343a6f84dd9c5fd94415615ef49a4b0.tar.gz |
(Logical change 1.259)
-rw-r--r-- | include/ia64/jmpbuf.h | 32 | ||||
-rw-r--r-- | include/x86/jmpbuf.h | 31 | ||||
-rw-r--r-- | include/x86_64/jmpbuf.h | 31 | ||||
-rw-r--r-- | src/ia64/longjmp.S | 38 | ||||
-rw-r--r-- | tests/ia64-test-setjmp.c | 123 |
5 files changed, 255 insertions, 0 deletions
diff --git a/include/ia64/jmpbuf.h b/include/ia64/jmpbuf.h new file mode 100644 index 00000000..faa1f344 --- /dev/null +++ b/include/ia64/jmpbuf.h @@ -0,0 +1,32 @@ +/* libunwind - a platform-independent unwind library + Copyright (C) 2004 Hewlett-Packard Co + Contributed by David Mosberger-Tang <davidm@hpl.hp.com> + +This file is part of libunwind. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +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. */ + +/* Use glibc's jump-buffer indices; NPTL peeks at SP and BSP: */ + +#define JB_SP 0 +#define JB_RP 8 +#define JB_BSP 17 +#define JB_MASK_SAVED 70 +#define JB_MASK 71 diff --git a/include/x86/jmpbuf.h b/include/x86/jmpbuf.h new file mode 100644 index 00000000..a0eb072e --- /dev/null +++ b/include/x86/jmpbuf.h @@ -0,0 +1,31 @@ +/* libunwind - a platform-independent unwind library + Copyright (C) 2004 Hewlett-Packard Co + Contributed by David Mosberger-Tang <davidm@hpl.hp.com> + +This file is part of libunwind. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +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. */ + +/* Use glibc's jump-buffer indices; NPTL peeks at SP: */ + +#define JB_SP 4 +#define JB_RP 5 +#define JB_MASK_SAVED 6 +#define JB_MASK 7 diff --git a/include/x86_64/jmpbuf.h b/include/x86_64/jmpbuf.h new file mode 100644 index 00000000..92200689 --- /dev/null +++ b/include/x86_64/jmpbuf.h @@ -0,0 +1,31 @@ +/* libunwind - a platform-independent unwind library + Copyright (C) 2004 Hewlett-Packard Co + Contributed by David Mosberger-Tang <davidm@hpl.hp.com> + +This file is part of libunwind. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +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. */ + +/* Use glibc's jump-buffer indices; NPTL peeks at SP: */ + +#define JB_SP 6 +#define JB_RP 7 +#define JB_MASK_SAVED 8 +#define JB_MASK 9 diff --git a/src/ia64/longjmp.S b/src/ia64/longjmp.S new file mode 100644 index 00000000..7590522f --- /dev/null +++ b/src/ia64/longjmp.S @@ -0,0 +1,38 @@ +/* libunwind - a platform-independent unwind library + Copyright (C) 2004 Hewlett-Packard Co + Contributed by David Mosberger-Tang <davidm@hpl.hp.com> + +This file is part of libunwind. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +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. */ + + .global _UI_longjmp_cont + + .align 32 + .proc longjmp_continuation +longjmp_continuation: +_UI_longjmp_cont: // non-function label for {sig,}longjmp.c + .prologue + .save rp, r15 + .body + mov rp = r15 + mov r8 = r16 + br.sptk.many rp + .endp longjmp_continuation diff --git a/tests/ia64-test-setjmp.c b/tests/ia64-test-setjmp.c new file mode 100644 index 00000000..defbbe9a --- /dev/null +++ b/tests/ia64-test-setjmp.c @@ -0,0 +1,123 @@ +/* libunwind - a platform-independent unwind library + Copyright (C) 2004 Hewlett-Packard Co + Contributed by David Mosberger-Tang <davidm@hpl.hp.com> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +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. */ + +/* Test to verify that we can siglongjmp() into a frame whose register + window is not backed by valid memory. */ + +#include <stdio.h> +#include <stdint.h> +#include <setjmp.h> +#include <signal.h> +#include <stdlib.h> +#include <unistd.h> + +#include <sys/mman.h> + +static sigjmp_buf env; +static int return_level; +static uintptr_t return_bsp; +static int verbose; + +static void +sighandler (int signal, void *siginfo, void *sigcontext) +{ + ucontext_t *uc = sigcontext; + int local = 0; + + if (verbose) + printf ("got signal, stack at %p, saved bsp=0x%lx\n", + &local, uc->uc_mcontext.sc_ar_bsp); + siglongjmp (env, 1); +} + +static void +doit (int n) +{ + uintptr_t guard_page_addr, bsp = (uintptr_t) __builtin_ia64_bsp (); + + if (n == 0) + { + size_t page_size = getpagesize (); + + guard_page_addr = (bsp + page_size - 1) & -page_size; + if (verbose) + printf ("guard_page_addr = 0x%lx\n", (unsigned long) guard_page_addr); + if (mmap ((void *) guard_page_addr, page_size, PROT_NONE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0) != (void *) guard_page_addr) + { + perror ("mmap"); + exit (EXIT_FAILURE); + } + } + + if (sigsetjmp (env, 1)) + { + return_level = n; + return_bsp = bsp; + } + else + doit (n + 1); +} + +int +main (int argc, char **argv) +{ + struct sigaction sa; + stack_t ss; + + if (argc > 1) + verbose = 1; + + ss.ss_sp = malloc (2 * SIGSTKSZ); + if (ss.ss_sp == NULL) + { + puts ("failed to allocate alternate stack"); + return EXIT_FAILURE; + } + ss.ss_flags = 0; + ss.ss_size = 2 * SIGSTKSZ; + if (sigaltstack (&ss, NULL) < 0) + { + printf ("sigaltstack failed %m\n"); + return EXIT_FAILURE; + } + + sa.sa_handler = (void (*) (int)) sighandler; + sigemptyset (&sa.sa_mask); + sa.sa_flags = SA_SIGINFO | SA_ONSTACK; + if (sigaction (SIGSEGV, &sa, NULL) < 0) + { + printf ("sigaction failed: %m\n"); + exit (1); + } + + doit (0); + + if (verbose) + { + printf ("sigsetjmp returned at level %d bsp=0x%lx\n", + return_level, return_bsp); + puts ("Test succeeded!"); + } + return EXIT_SUCCESS; +} |