blob: 9d87e927189b1caa7263fabcca803d4ceee10f35 [file] [log] [blame]
mostang.com!davidm824d6612003-02-08 10:10:59 +00001/* libunwind - a platform-independent unwind library
2 Copyright (C) 2003 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5This file is part of libunwind.
6
7Permission is hereby granted, free of charge, to any person obtaining
8a copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense, and/or sell copies of the Software, and to
12permit persons to whom the Software is furnished to do so, subject to
13the following conditions:
14
15The above copyright notice and this permission notice shall be
16included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
25
26#define UNW_LOCAL_ONLY
27
mostang.com!davidmeeffb602003-03-06 06:14:36 +000028#include <assert.h>
mostang.com!davidm824d6612003-02-08 10:10:59 +000029#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
38void
39siglongjmp (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, &current_mask) < 0)
83 abort ();
84 mp = (unw_word_t *) &current_mask;
85 }
86
mostang.com!davidmeeffb602003-03-06 06:14:36 +000087 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!davidm824d6612003-02-08 10:10:59 +000092 || 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!davidmeeffb602003-03-06 06:14:36 +0000100 if (unw_set_reg (&c, UNW_REG_EH + 3, mp[1]) < 0)
mostang.com!davidm824d6612003-02-08 10:10:59 +0000101 abort ();
102 }
103
104 unw_resume (&c);
105
106 abort ();
107 }
108 while (unw_step (&c) >= 0);
109
110 abort ();
111}