mostang.com!davidm | 824d661 | 2003-02-08 10:10:59 +0000 | [diff] [blame] | 1 | /* libunwind - a platform-independent unwind library |
| 2 | Copyright (C) 2003 Hewlett-Packard Co |
| 3 | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
| 4 | |
| 5 | This file is part of libunwind. |
| 6 | |
| 7 | Permission is hereby granted, free of charge, to any person obtaining |
| 8 | a copy of this software and associated documentation files (the |
| 9 | "Software"), to deal in the Software without restriction, including |
| 10 | without limitation the rights to use, copy, modify, merge, publish, |
| 11 | distribute, sublicense, and/or sell copies of the Software, and to |
| 12 | permit persons to whom the Software is furnished to do so, subject to |
| 13 | the following conditions: |
| 14 | |
| 15 | The above copyright notice and this permission notice shall be |
| 16 | included in all copies or substantial portions of the Software. |
| 17 | |
| 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 22 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 24 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 25 | |
| 26 | #define UNW_LOCAL_ONLY |
| 27 | |
mostang.com!davidm | eeffb60 | 2003-03-06 06:14:36 +0000 | [diff] [blame] | 28 | #include <assert.h> |
mostang.com!davidm | 824d661 | 2003-02-08 10:10:59 +0000 | [diff] [blame] | 29 | #include <libunwind.h> |
| 30 | #include <setjmp.h> |
| 31 | #include <signal.h> |
| 32 | #include <stdlib.h> |
| 33 | |
| 34 | #if UNW_TARGET_IA64 |
| 35 | # include "ia64/rse.h" |
| 36 | #endif |
| 37 | |
| 38 | void |
| 39 | siglongjmp (sigjmp_buf env, int val) |
| 40 | { |
| 41 | unw_word_t *mp, *wp = (unw_word_t *) env; |
| 42 | extern int _UI_siglongjmp_cont; |
| 43 | sigset_t current_mask; |
| 44 | unw_context_t uc; |
| 45 | unw_cursor_t c; |
| 46 | unw_word_t sp; |
| 47 | |
| 48 | if (unw_getcontext (&uc) < 0 || unw_init_local (&c, &uc) < 0) |
| 49 | abort (); |
| 50 | |
| 51 | do |
| 52 | { |
| 53 | if (unw_get_reg (&c, UNW_REG_SP, &sp) < 0) |
| 54 | abort (); |
| 55 | if (sp != wp[0]) |
| 56 | continue; |
| 57 | |
| 58 | #if UNW_TARGET_IA64 |
| 59 | { |
| 60 | unw_word_t bsp, pfs, sol; |
| 61 | |
| 62 | if (unw_get_reg (&c, UNW_IA64_BSP, &bsp) < 0 |
| 63 | || unw_get_reg (&c, UNW_IA64_AR_PFS, &pfs) < 0) |
| 64 | abort (); |
| 65 | |
| 66 | /* simulate the effect of "br.call sigsetjmp" on ar.bsp: */ |
| 67 | sol = (pfs >> 7) & 0x7f; |
| 68 | bsp = ia64_rse_skip_regs (bsp, sol); |
| 69 | |
| 70 | if (bsp != wp[4]) |
| 71 | continue; |
| 72 | } |
| 73 | #endif |
| 74 | |
| 75 | /* found the right frame: */ |
| 76 | |
| 77 | if (wp[2]) |
| 78 | mp = wp + 3; |
| 79 | else |
| 80 | { |
| 81 | /* sigmask wasn't saved; get it now so we can leave it unchanged. */ |
| 82 | if (sigprocmask (SIG_BLOCK, NULL, ¤t_mask) < 0) |
| 83 | abort (); |
| 84 | mp = (unw_word_t *) ¤t_mask; |
| 85 | } |
| 86 | |
mostang.com!davidm | eeffb60 | 2003-03-06 06:14:36 +0000 | [diff] [blame] | 87 | assert (UNW_NUM_EH_REGS >= 4); |
| 88 | |
| 89 | if (unw_set_reg (&c, UNW_REG_EH + 0, wp[1]) < 0 |
| 90 | || unw_set_reg (&c, UNW_REG_EH + 1, val) < 0 |
| 91 | || unw_set_reg (&c, UNW_REG_EH + 2, mp[0]) < 0 |
mostang.com!davidm | 824d661 | 2003-02-08 10:10:59 +0000 | [diff] [blame] | 92 | || unw_set_reg (&c, UNW_REG_IP, |
| 93 | (unw_word_t) &_UI_siglongjmp_cont)) |
| 94 | abort (); |
| 95 | |
| 96 | if (_NSIG > 8 * sizeof (unw_word_t)) |
| 97 | { |
| 98 | if (_NSIG > 16 * sizeof (unw_word_t)) |
| 99 | abort (); |
mostang.com!davidm | eeffb60 | 2003-03-06 06:14:36 +0000 | [diff] [blame] | 100 | if (unw_set_reg (&c, UNW_REG_EH + 3, mp[1]) < 0) |
mostang.com!davidm | 824d661 | 2003-02-08 10:10:59 +0000 | [diff] [blame] | 101 | abort (); |
| 102 | } |
| 103 | |
| 104 | unw_resume (&c); |
| 105 | |
| 106 | abort (); |
| 107 | } |
| 108 | while (unw_step (&c) >= 0); |
| 109 | |
| 110 | abort (); |
| 111 | } |