]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/ia64/__sigstack_longjmp.c
1 /* Copyright (C) 2004-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 /* The public __longjmp() implementation is limited to jumping within
19 the same stack. That is, in general it is not possible to use this
20 __longjmp() implementation to cross from one stack to another.
21 In contrast, the __sigstack_longjmp() implemented here allows
22 crossing from the alternate signal stack to the normal stack
37 struct rbs_flush_values
44 extern struct rbs_flush_values
__ia64_flush_rbs (void);
45 extern void __ia64_longjmp (__jmp_buf buf
, int val
, long rnat
, long rsc
)
46 __attribute__ ((__noreturn__
));
49 copy_rbs (unsigned long *dst
, unsigned long *dst_end
, unsigned long dst_rnat
,
50 unsigned long *src
, unsigned long *src_end
,
51 unsigned long current_rnat
)
53 unsigned long dst_slot
, src_rnat
= 0, src_slot
, *src_rnat_addr
, nat_bit
;
58 dst_slot
= ia64_rse_slot_num (dst
);
66 /* read source value, including NaT bit: */
67 src_slot
= ia64_rse_slot_num (src
);
70 /* skip src RNaT slot */
74 if (first_time
|| src_slot
== 0)
77 src_rnat_addr
= ia64_rse_rnat_addr (src
);
78 if (src_rnat_addr
< src_end
)
79 src_rnat
= *src_rnat_addr
;
81 src_rnat
= current_rnat
;
83 nat_bit
= (src_rnat
>> src_slot
) & 1;
85 assert (src
< src_end
);
89 dst_rnat
|= (1UL << dst_slot
);
91 dst_rnat
&= ~(1UL << dst_slot
);
94 dst_slot
= ia64_rse_slot_num (dst
);
96 *ia64_rse_rnat_addr (dst
) = dst_rnat
;
100 __sigstack_longjmp (__jmp_buf buf
, int val
)
102 unsigned long *rbs_base
, *bsp
, *bspstore
, *jb_bsp
, jb_sp
, ss_sp
;
103 unsigned long ndirty
, rnat
, load_rnat
, *jb_rnat_addr
;
104 struct sigcontext
*sc
;
106 struct rbs_flush_values c
;
108 /* put RSE into enforced-lazy mode and return current bsp/rsc/rnat: */
109 c
= __ia64_flush_rbs ();
111 jb_sp
= ((unsigned long *) buf
)[JB_SP
];
112 jb_bsp
= ((unsigned long **) buf
)[JB_BSP
];
114 INTERNAL_SYSCALL_CALL (sigaltstack
, NULL
, &stk
);
116 ss_sp
= (unsigned long) stk
.ss_sp
;
117 jb_rnat_addr
= ia64_rse_rnat_addr (jb_bsp
);
119 if ((stk
.ss_flags
& SS_ONSTACK
) == 0 || jb_sp
- ss_sp
< stk
.ss_size
)
120 /* Normal non-stack-crossing longjmp; if the RNaT slot for the bsp
121 saved in the jump-buffer is the same as the one for the current
122 BSP, use the current AR.RNAT value, otherwise, load it from the
123 jump-buffer's RNaT-slot. */
124 load_rnat
= (ia64_rse_rnat_addr ((unsigned long *) c
.bsp
) != jb_rnat_addr
);
127 /* If we are on the alternate signal-stack and the jump-buffer
128 lies outside the signal-stack, we may need to copy back the
129 dirty partition which was torn off and saved on the
130 signal-stack when the signal was delivered.
132 Caveat: we assume that the top of the alternate signal-stack
133 stores the sigcontext structure of the signal that
134 caused the switch to the signal-stack. This should
135 be a fairly safe assumption but the kernel _could_
136 do things differently.. */
137 sc
= ((struct sigcontext
*) ((ss_sp
+ stk
.ss_size
) & -16) - 1);
139 /* As a sanity-check, verify that the register-backing-store base
140 of the alternate signal-stack is where we expect it. */
141 rbs_base
= (unsigned long *)
142 ((ss_sp
+ sizeof (long) - 1) & -sizeof (long));
144 assert ((unsigned long) rbs_base
== sc
->sc_rbs_base
);
146 ndirty
= ia64_rse_num_regs (rbs_base
, rbs_base
+ (sc
->sc_loadrs
>> 19));
147 bsp
= (unsigned long *) sc
->sc_ar_bsp
;
148 bspstore
= ia64_rse_skip_regs (bsp
, -ndirty
);
150 if (bspstore
< jb_bsp
)
151 /* AR.BSPSTORE at the time of the signal was below the value
152 of AR.BSP saved in the jump-buffer => copy the missing
153 portion from the torn off dirty partition which got saved
154 on the alternate signal-stack. */
155 copy_rbs (bspstore
, jb_bsp
, sc
->sc_ar_rnat
,
156 rbs_base
, (unsigned long *) c
.bsp
, c
.rnat
);
161 rnat
= *jb_rnat_addr
;
164 __ia64_longjmp (buf
, val
, rnat
, c
.rsc
);