Commit 40c72f20e89300dfaea28300ee17aa56d230d63f
Committed by
Kyle McMartin
1 parent
eba917273e
Exists in
master
and in
7 other branches
[PARISC] Prevent signal loops if we have a problem setting up a frame
2.6.13-rc6-pa2 use force_sigsegv() if we have a problem setting up a frame. This is required to prevent SIGSEGV loops. Signed-off-by: Randolph Chung <tausq@parisc-linux.org> Signed-off-by: Kyle McMartin <kyle@parisc-linux.org>
Showing 1 changed file with 1 additions and 9 deletions Inline Diff
arch/parisc/kernel/signal.c
1 | /* | 1 | /* |
2 | * linux/arch/parisc/kernel/signal.c: Architecture-specific signal | 2 | * linux/arch/parisc/kernel/signal.c: Architecture-specific signal |
3 | * handling support. | 3 | * handling support. |
4 | * | 4 | * |
5 | * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org> | 5 | * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org> |
6 | * Copyright (C) 2000 Linuxcare, Inc. | 6 | * Copyright (C) 2000 Linuxcare, Inc. |
7 | * | 7 | * |
8 | * Based on the ia64, i386, and alpha versions. | 8 | * Based on the ia64, i386, and alpha versions. |
9 | * | 9 | * |
10 | * Like the IA-64, we are a recent enough port (we are *starting* | 10 | * Like the IA-64, we are a recent enough port (we are *starting* |
11 | * with glibc2.2) that we do not need to support the old non-realtime | 11 | * with glibc2.2) that we do not need to support the old non-realtime |
12 | * Linux signals. Therefore we don't. HP/UX signals will go in | 12 | * Linux signals. Therefore we don't. HP/UX signals will go in |
13 | * arch/parisc/hpux/signal.c when we figure out how to do them. | 13 | * arch/parisc/hpux/signal.c when we figure out how to do them. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/sched.h> | 16 | #include <linux/sched.h> |
17 | #include <linux/mm.h> | 17 | #include <linux/mm.h> |
18 | #include <linux/smp.h> | 18 | #include <linux/smp.h> |
19 | #include <linux/smp_lock.h> | 19 | #include <linux/smp_lock.h> |
20 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
21 | #include <linux/signal.h> | 21 | #include <linux/signal.h> |
22 | #include <linux/errno.h> | 22 | #include <linux/errno.h> |
23 | #include <linux/wait.h> | 23 | #include <linux/wait.h> |
24 | #include <linux/ptrace.h> | 24 | #include <linux/ptrace.h> |
25 | #include <linux/unistd.h> | 25 | #include <linux/unistd.h> |
26 | #include <linux/stddef.h> | 26 | #include <linux/stddef.h> |
27 | #include <linux/compat.h> | 27 | #include <linux/compat.h> |
28 | #include <linux/elf.h> | 28 | #include <linux/elf.h> |
29 | #include <linux/personality.h> | 29 | #include <linux/personality.h> |
30 | #include <asm/ucontext.h> | 30 | #include <asm/ucontext.h> |
31 | #include <asm/rt_sigframe.h> | 31 | #include <asm/rt_sigframe.h> |
32 | #include <asm/uaccess.h> | 32 | #include <asm/uaccess.h> |
33 | #include <asm/pgalloc.h> | 33 | #include <asm/pgalloc.h> |
34 | #include <asm/cacheflush.h> | 34 | #include <asm/cacheflush.h> |
35 | #include <asm/asm-offsets.h> | 35 | #include <asm/asm-offsets.h> |
36 | 36 | ||
37 | #ifdef CONFIG_COMPAT | 37 | #ifdef CONFIG_COMPAT |
38 | #include <linux/compat.h> | 38 | #include <linux/compat.h> |
39 | #include "signal32.h" | 39 | #include "signal32.h" |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #define DEBUG_SIG 0 | 42 | #define DEBUG_SIG 0 |
43 | #define DEBUG_SIG_LEVEL 2 | 43 | #define DEBUG_SIG_LEVEL 2 |
44 | 44 | ||
45 | #if DEBUG_SIG | 45 | #if DEBUG_SIG |
46 | #define DBG(LEVEL, ...) \ | 46 | #define DBG(LEVEL, ...) \ |
47 | ((DEBUG_SIG_LEVEL >= LEVEL) \ | 47 | ((DEBUG_SIG_LEVEL >= LEVEL) \ |
48 | ? printk(__VA_ARGS__) : (void) 0) | 48 | ? printk(__VA_ARGS__) : (void) 0) |
49 | #else | 49 | #else |
50 | #define DBG(LEVEL, ...) | 50 | #define DBG(LEVEL, ...) |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | 53 | ||
54 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) | 54 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) |
55 | 55 | ||
56 | /* gcc will complain if a pointer is cast to an integer of different | 56 | /* gcc will complain if a pointer is cast to an integer of different |
57 | * size. If you really need to do this (and we do for an ELF32 user | 57 | * size. If you really need to do this (and we do for an ELF32 user |
58 | * application in an ELF64 kernel) then you have to do a cast to an | 58 | * application in an ELF64 kernel) then you have to do a cast to an |
59 | * integer of the same size first. The A() macro accomplishes | 59 | * integer of the same size first. The A() macro accomplishes |
60 | * this. */ | 60 | * this. */ |
61 | #define A(__x) ((unsigned long)(__x)) | 61 | #define A(__x) ((unsigned long)(__x)) |
62 | 62 | ||
63 | int do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall); | 63 | int do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall); |
64 | 64 | ||
65 | /* | 65 | /* |
66 | * Atomically swap in the new signal mask, and wait for a signal. | 66 | * Atomically swap in the new signal mask, and wait for a signal. |
67 | */ | 67 | */ |
68 | #ifdef __LP64__ | 68 | #ifdef __LP64__ |
69 | #include "sys32.h" | 69 | #include "sys32.h" |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | asmlinkage int | 72 | asmlinkage int |
73 | sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize, struct pt_regs *regs) | 73 | sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize, struct pt_regs *regs) |
74 | { | 74 | { |
75 | sigset_t saveset, newset; | 75 | sigset_t saveset, newset; |
76 | #ifdef __LP64__ | 76 | #ifdef __LP64__ |
77 | compat_sigset_t newset32; | 77 | compat_sigset_t newset32; |
78 | 78 | ||
79 | if(personality(current->personality) == PER_LINUX32){ | 79 | if(personality(current->personality) == PER_LINUX32){ |
80 | /* XXX: Don't preclude handling different sized sigset_t's. */ | 80 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
81 | if (sigsetsize != sizeof(compat_sigset_t)) | 81 | if (sigsetsize != sizeof(compat_sigset_t)) |
82 | return -EINVAL; | 82 | return -EINVAL; |
83 | if (copy_from_user(&newset32, (compat_sigset_t __user *)unewset, sizeof(newset32))) | 83 | if (copy_from_user(&newset32, (compat_sigset_t __user *)unewset, sizeof(newset32))) |
84 | return -EFAULT; | 84 | return -EFAULT; |
85 | sigset_32to64(&newset,&newset32); | 85 | sigset_32to64(&newset,&newset32); |
86 | 86 | ||
87 | } else | 87 | } else |
88 | #endif | 88 | #endif |
89 | { | 89 | { |
90 | /* XXX: Don't preclude handling different sized sigset_t's. */ | 90 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
91 | if (sigsetsize != sizeof(sigset_t)) | 91 | if (sigsetsize != sizeof(sigset_t)) |
92 | return -EINVAL; | 92 | return -EINVAL; |
93 | 93 | ||
94 | if (copy_from_user(&newset, unewset, sizeof(newset))) | 94 | if (copy_from_user(&newset, unewset, sizeof(newset))) |
95 | return -EFAULT; | 95 | return -EFAULT; |
96 | } | 96 | } |
97 | 97 | ||
98 | sigdelsetmask(&newset, ~_BLOCKABLE); | 98 | sigdelsetmask(&newset, ~_BLOCKABLE); |
99 | 99 | ||
100 | spin_lock_irq(¤t->sighand->siglock); | 100 | spin_lock_irq(¤t->sighand->siglock); |
101 | saveset = current->blocked; | 101 | saveset = current->blocked; |
102 | current->blocked = newset; | 102 | current->blocked = newset; |
103 | recalc_sigpending(); | 103 | recalc_sigpending(); |
104 | spin_unlock_irq(¤t->sighand->siglock); | 104 | spin_unlock_irq(¤t->sighand->siglock); |
105 | 105 | ||
106 | regs->gr[28] = -EINTR; | 106 | regs->gr[28] = -EINTR; |
107 | while (1) { | 107 | while (1) { |
108 | current->state = TASK_INTERRUPTIBLE; | 108 | current->state = TASK_INTERRUPTIBLE; |
109 | schedule(); | 109 | schedule(); |
110 | if (do_signal(&saveset, regs, 1)) | 110 | if (do_signal(&saveset, regs, 1)) |
111 | return -EINTR; | 111 | return -EINTR; |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | /* | 115 | /* |
116 | * Do a signal return - restore sigcontext. | 116 | * Do a signal return - restore sigcontext. |
117 | */ | 117 | */ |
118 | 118 | ||
119 | /* Trampoline for calling rt_sigreturn() */ | 119 | /* Trampoline for calling rt_sigreturn() */ |
120 | #define INSN_LDI_R25_0 0x34190000 /* ldi 0,%r25 (in_syscall=0) */ | 120 | #define INSN_LDI_R25_0 0x34190000 /* ldi 0,%r25 (in_syscall=0) */ |
121 | #define INSN_LDI_R25_1 0x34190002 /* ldi 1,%r25 (in_syscall=1) */ | 121 | #define INSN_LDI_R25_1 0x34190002 /* ldi 1,%r25 (in_syscall=1) */ |
122 | #define INSN_LDI_R20 0x3414015a /* ldi __NR_rt_sigreturn,%r20 */ | 122 | #define INSN_LDI_R20 0x3414015a /* ldi __NR_rt_sigreturn,%r20 */ |
123 | #define INSN_BLE_SR2_R0 0xe4008200 /* be,l 0x100(%sr2,%r0),%sr0,%r31 */ | 123 | #define INSN_BLE_SR2_R0 0xe4008200 /* be,l 0x100(%sr2,%r0),%sr0,%r31 */ |
124 | #define INSN_NOP 0x08000240 /* nop */ | 124 | #define INSN_NOP 0x08000240 /* nop */ |
125 | /* For debugging */ | 125 | /* For debugging */ |
126 | #define INSN_DIE_HORRIBLY 0x68000ccc /* stw %r0,0x666(%sr0,%r0) */ | 126 | #define INSN_DIE_HORRIBLY 0x68000ccc /* stw %r0,0x666(%sr0,%r0) */ |
127 | 127 | ||
128 | static long | 128 | static long |
129 | restore_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs) | 129 | restore_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs) |
130 | { | 130 | { |
131 | long err = 0; | 131 | long err = 0; |
132 | 132 | ||
133 | err |= __copy_from_user(regs->gr, sc->sc_gr, sizeof(regs->gr)); | 133 | err |= __copy_from_user(regs->gr, sc->sc_gr, sizeof(regs->gr)); |
134 | err |= __copy_from_user(regs->fr, sc->sc_fr, sizeof(regs->fr)); | 134 | err |= __copy_from_user(regs->fr, sc->sc_fr, sizeof(regs->fr)); |
135 | err |= __copy_from_user(regs->iaoq, sc->sc_iaoq, sizeof(regs->iaoq)); | 135 | err |= __copy_from_user(regs->iaoq, sc->sc_iaoq, sizeof(regs->iaoq)); |
136 | err |= __copy_from_user(regs->iasq, sc->sc_iasq, sizeof(regs->iasq)); | 136 | err |= __copy_from_user(regs->iasq, sc->sc_iasq, sizeof(regs->iasq)); |
137 | err |= __get_user(regs->sar, &sc->sc_sar); | 137 | err |= __get_user(regs->sar, &sc->sc_sar); |
138 | DBG(2,"restore_sigcontext: iaoq is 0x%#lx / 0x%#lx\n", | 138 | DBG(2,"restore_sigcontext: iaoq is 0x%#lx / 0x%#lx\n", |
139 | regs->iaoq[0],regs->iaoq[1]); | 139 | regs->iaoq[0],regs->iaoq[1]); |
140 | DBG(2,"restore_sigcontext: r28 is %ld\n", regs->gr[28]); | 140 | DBG(2,"restore_sigcontext: r28 is %ld\n", regs->gr[28]); |
141 | return err; | 141 | return err; |
142 | } | 142 | } |
143 | 143 | ||
144 | void | 144 | void |
145 | sys_rt_sigreturn(struct pt_regs *regs, int in_syscall) | 145 | sys_rt_sigreturn(struct pt_regs *regs, int in_syscall) |
146 | { | 146 | { |
147 | struct rt_sigframe __user *frame; | 147 | struct rt_sigframe __user *frame; |
148 | struct siginfo si; | 148 | struct siginfo si; |
149 | sigset_t set; | 149 | sigset_t set; |
150 | unsigned long usp = (regs->gr[30] & ~(0x01UL)); | 150 | unsigned long usp = (regs->gr[30] & ~(0x01UL)); |
151 | unsigned long sigframe_size = PARISC_RT_SIGFRAME_SIZE; | 151 | unsigned long sigframe_size = PARISC_RT_SIGFRAME_SIZE; |
152 | #ifdef __LP64__ | 152 | #ifdef __LP64__ |
153 | compat_sigset_t compat_set; | 153 | compat_sigset_t compat_set; |
154 | struct compat_rt_sigframe __user * compat_frame; | 154 | struct compat_rt_sigframe __user * compat_frame; |
155 | 155 | ||
156 | if(personality(current->personality) == PER_LINUX32) | 156 | if(personality(current->personality) == PER_LINUX32) |
157 | sigframe_size = PARISC_RT_SIGFRAME_SIZE32; | 157 | sigframe_size = PARISC_RT_SIGFRAME_SIZE32; |
158 | #endif | 158 | #endif |
159 | 159 | ||
160 | 160 | ||
161 | /* Unwind the user stack to get the rt_sigframe structure. */ | 161 | /* Unwind the user stack to get the rt_sigframe structure. */ |
162 | frame = (struct rt_sigframe __user *) | 162 | frame = (struct rt_sigframe __user *) |
163 | (usp - sigframe_size); | 163 | (usp - sigframe_size); |
164 | DBG(2,"sys_rt_sigreturn: frame is %p\n", frame); | 164 | DBG(2,"sys_rt_sigreturn: frame is %p\n", frame); |
165 | 165 | ||
166 | #ifdef __LP64__ | 166 | #ifdef __LP64__ |
167 | compat_frame = (struct compat_rt_sigframe __user *)frame; | 167 | compat_frame = (struct compat_rt_sigframe __user *)frame; |
168 | 168 | ||
169 | if(personality(current->personality) == PER_LINUX32){ | 169 | if(personality(current->personality) == PER_LINUX32){ |
170 | DBG(2,"sys_rt_sigreturn: ELF32 process.\n"); | 170 | DBG(2,"sys_rt_sigreturn: ELF32 process.\n"); |
171 | if (__copy_from_user(&compat_set, &compat_frame->uc.uc_sigmask, sizeof(compat_set))) | 171 | if (__copy_from_user(&compat_set, &compat_frame->uc.uc_sigmask, sizeof(compat_set))) |
172 | goto give_sigsegv; | 172 | goto give_sigsegv; |
173 | sigset_32to64(&set,&compat_set); | 173 | sigset_32to64(&set,&compat_set); |
174 | } else | 174 | } else |
175 | #endif | 175 | #endif |
176 | { | 176 | { |
177 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) | 177 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
178 | goto give_sigsegv; | 178 | goto give_sigsegv; |
179 | } | 179 | } |
180 | 180 | ||
181 | sigdelsetmask(&set, ~_BLOCKABLE); | 181 | sigdelsetmask(&set, ~_BLOCKABLE); |
182 | spin_lock_irq(¤t->sighand->siglock); | 182 | spin_lock_irq(¤t->sighand->siglock); |
183 | current->blocked = set; | 183 | current->blocked = set; |
184 | recalc_sigpending(); | 184 | recalc_sigpending(); |
185 | spin_unlock_irq(¤t->sighand->siglock); | 185 | spin_unlock_irq(¤t->sighand->siglock); |
186 | 186 | ||
187 | /* Good thing we saved the old gr[30], eh? */ | 187 | /* Good thing we saved the old gr[30], eh? */ |
188 | #ifdef __LP64__ | 188 | #ifdef __LP64__ |
189 | if(personality(current->personality) == PER_LINUX32){ | 189 | if(personality(current->personality) == PER_LINUX32){ |
190 | DBG(1,"sys_rt_sigreturn: compat_frame->uc.uc_mcontext 0x%p\n", | 190 | DBG(1,"sys_rt_sigreturn: compat_frame->uc.uc_mcontext 0x%p\n", |
191 | &compat_frame->uc.uc_mcontext); | 191 | &compat_frame->uc.uc_mcontext); |
192 | // FIXME: Load upper half from register file | 192 | // FIXME: Load upper half from register file |
193 | if (restore_sigcontext32(&compat_frame->uc.uc_mcontext, | 193 | if (restore_sigcontext32(&compat_frame->uc.uc_mcontext, |
194 | &compat_frame->regs, regs)) | 194 | &compat_frame->regs, regs)) |
195 | goto give_sigsegv; | 195 | goto give_sigsegv; |
196 | DBG(1,"sys_rt_sigreturn: usp %#08lx stack 0x%p\n", | 196 | DBG(1,"sys_rt_sigreturn: usp %#08lx stack 0x%p\n", |
197 | usp, &compat_frame->uc.uc_stack); | 197 | usp, &compat_frame->uc.uc_stack); |
198 | if (do_sigaltstack32(&compat_frame->uc.uc_stack, NULL, usp) == -EFAULT) | 198 | if (do_sigaltstack32(&compat_frame->uc.uc_stack, NULL, usp) == -EFAULT) |
199 | goto give_sigsegv; | 199 | goto give_sigsegv; |
200 | } else | 200 | } else |
201 | #endif | 201 | #endif |
202 | { | 202 | { |
203 | DBG(1,"sys_rt_sigreturn: frame->uc.uc_mcontext 0x%p\n", | 203 | DBG(1,"sys_rt_sigreturn: frame->uc.uc_mcontext 0x%p\n", |
204 | &frame->uc.uc_mcontext); | 204 | &frame->uc.uc_mcontext); |
205 | if (restore_sigcontext(&frame->uc.uc_mcontext, regs)) | 205 | if (restore_sigcontext(&frame->uc.uc_mcontext, regs)) |
206 | goto give_sigsegv; | 206 | goto give_sigsegv; |
207 | DBG(1,"sys_rt_sigreturn: usp %#08lx stack 0x%p\n", | 207 | DBG(1,"sys_rt_sigreturn: usp %#08lx stack 0x%p\n", |
208 | usp, &frame->uc.uc_stack); | 208 | usp, &frame->uc.uc_stack); |
209 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, usp) == -EFAULT) | 209 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, usp) == -EFAULT) |
210 | goto give_sigsegv; | 210 | goto give_sigsegv; |
211 | } | 211 | } |
212 | 212 | ||
213 | 213 | ||
214 | 214 | ||
215 | /* If we are on the syscall path IAOQ will not be restored, and | 215 | /* If we are on the syscall path IAOQ will not be restored, and |
216 | * if we are on the interrupt path we must not corrupt gr31. | 216 | * if we are on the interrupt path we must not corrupt gr31. |
217 | */ | 217 | */ |
218 | if (in_syscall) | 218 | if (in_syscall) |
219 | regs->gr[31] = regs->iaoq[0]; | 219 | regs->gr[31] = regs->iaoq[0]; |
220 | #if DEBUG_SIG | 220 | #if DEBUG_SIG |
221 | DBG(1,"sys_rt_sigreturn: returning to %#lx, DUMPING REGS:\n", regs->iaoq[0]); | 221 | DBG(1,"sys_rt_sigreturn: returning to %#lx, DUMPING REGS:\n", regs->iaoq[0]); |
222 | show_regs(regs); | 222 | show_regs(regs); |
223 | #endif | 223 | #endif |
224 | return; | 224 | return; |
225 | 225 | ||
226 | give_sigsegv: | 226 | give_sigsegv: |
227 | DBG(1,"sys_rt_sigreturn: Sending SIGSEGV\n"); | 227 | DBG(1,"sys_rt_sigreturn: Sending SIGSEGV\n"); |
228 | si.si_signo = SIGSEGV; | 228 | si.si_signo = SIGSEGV; |
229 | si.si_errno = 0; | 229 | si.si_errno = 0; |
230 | si.si_code = SI_KERNEL; | 230 | si.si_code = SI_KERNEL; |
231 | si.si_pid = current->pid; | 231 | si.si_pid = current->pid; |
232 | si.si_uid = current->uid; | 232 | si.si_uid = current->uid; |
233 | si.si_addr = &frame->uc; | 233 | si.si_addr = &frame->uc; |
234 | force_sig_info(SIGSEGV, &si, current); | 234 | force_sig_info(SIGSEGV, &si, current); |
235 | return; | 235 | return; |
236 | } | 236 | } |
237 | 237 | ||
238 | /* | 238 | /* |
239 | * Set up a signal frame. | 239 | * Set up a signal frame. |
240 | */ | 240 | */ |
241 | 241 | ||
242 | static inline void __user * | 242 | static inline void __user * |
243 | get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size) | 243 | get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size) |
244 | { | 244 | { |
245 | /*FIXME: ELF32 vs. ELF64 has different frame_size, but since we | 245 | /*FIXME: ELF32 vs. ELF64 has different frame_size, but since we |
246 | don't use the parameter it doesn't matter */ | 246 | don't use the parameter it doesn't matter */ |
247 | 247 | ||
248 | DBG(1,"get_sigframe: ka = %#lx, sp = %#lx, frame_size = %#lx\n", | 248 | DBG(1,"get_sigframe: ka = %#lx, sp = %#lx, frame_size = %#lx\n", |
249 | (unsigned long)ka, sp, frame_size); | 249 | (unsigned long)ka, sp, frame_size); |
250 | 250 | ||
251 | if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! on_sig_stack(sp)) | 251 | if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! on_sig_stack(sp)) |
252 | sp = current->sas_ss_sp; /* Stacks grow up! */ | 252 | sp = current->sas_ss_sp; /* Stacks grow up! */ |
253 | 253 | ||
254 | DBG(1,"get_sigframe: Returning sp = %#lx\n", (unsigned long)sp); | 254 | DBG(1,"get_sigframe: Returning sp = %#lx\n", (unsigned long)sp); |
255 | return (void __user *) sp; /* Stacks grow up. Fun. */ | 255 | return (void __user *) sp; /* Stacks grow up. Fun. */ |
256 | } | 256 | } |
257 | 257 | ||
258 | static long | 258 | static long |
259 | setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, int in_syscall) | 259 | setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, int in_syscall) |
260 | 260 | ||
261 | { | 261 | { |
262 | unsigned long flags = 0; | 262 | unsigned long flags = 0; |
263 | long err = 0; | 263 | long err = 0; |
264 | 264 | ||
265 | if (on_sig_stack((unsigned long) sc)) | 265 | if (on_sig_stack((unsigned long) sc)) |
266 | flags |= PARISC_SC_FLAG_ONSTACK; | 266 | flags |= PARISC_SC_FLAG_ONSTACK; |
267 | if (in_syscall) { | 267 | if (in_syscall) { |
268 | flags |= PARISC_SC_FLAG_IN_SYSCALL; | 268 | flags |= PARISC_SC_FLAG_IN_SYSCALL; |
269 | /* regs->iaoq is undefined in the syscall return path */ | 269 | /* regs->iaoq is undefined in the syscall return path */ |
270 | err |= __put_user(regs->gr[31], &sc->sc_iaoq[0]); | 270 | err |= __put_user(regs->gr[31], &sc->sc_iaoq[0]); |
271 | err |= __put_user(regs->gr[31]+4, &sc->sc_iaoq[1]); | 271 | err |= __put_user(regs->gr[31]+4, &sc->sc_iaoq[1]); |
272 | err |= __put_user(regs->sr[3], &sc->sc_iasq[0]); | 272 | err |= __put_user(regs->sr[3], &sc->sc_iasq[0]); |
273 | err |= __put_user(regs->sr[3], &sc->sc_iasq[1]); | 273 | err |= __put_user(regs->sr[3], &sc->sc_iasq[1]); |
274 | DBG(1,"setup_sigcontext: iaoq %#lx / %#lx (in syscall)\n", | 274 | DBG(1,"setup_sigcontext: iaoq %#lx / %#lx (in syscall)\n", |
275 | regs->gr[31], regs->gr[31]+4); | 275 | regs->gr[31], regs->gr[31]+4); |
276 | } else { | 276 | } else { |
277 | err |= __copy_to_user(sc->sc_iaoq, regs->iaoq, sizeof(regs->iaoq)); | 277 | err |= __copy_to_user(sc->sc_iaoq, regs->iaoq, sizeof(regs->iaoq)); |
278 | err |= __copy_to_user(sc->sc_iasq, regs->iasq, sizeof(regs->iasq)); | 278 | err |= __copy_to_user(sc->sc_iasq, regs->iasq, sizeof(regs->iasq)); |
279 | DBG(1,"setup_sigcontext: iaoq %#lx / %#lx (not in syscall)\n", | 279 | DBG(1,"setup_sigcontext: iaoq %#lx / %#lx (not in syscall)\n", |
280 | regs->iaoq[0], regs->iaoq[1]); | 280 | regs->iaoq[0], regs->iaoq[1]); |
281 | } | 281 | } |
282 | 282 | ||
283 | err |= __put_user(flags, &sc->sc_flags); | 283 | err |= __put_user(flags, &sc->sc_flags); |
284 | err |= __copy_to_user(sc->sc_gr, regs->gr, sizeof(regs->gr)); | 284 | err |= __copy_to_user(sc->sc_gr, regs->gr, sizeof(regs->gr)); |
285 | err |= __copy_to_user(sc->sc_fr, regs->fr, sizeof(regs->fr)); | 285 | err |= __copy_to_user(sc->sc_fr, regs->fr, sizeof(regs->fr)); |
286 | err |= __put_user(regs->sar, &sc->sc_sar); | 286 | err |= __put_user(regs->sar, &sc->sc_sar); |
287 | DBG(1,"setup_sigcontext: r28 is %ld\n", regs->gr[28]); | 287 | DBG(1,"setup_sigcontext: r28 is %ld\n", regs->gr[28]); |
288 | 288 | ||
289 | return err; | 289 | return err; |
290 | } | 290 | } |
291 | 291 | ||
292 | static long | 292 | static long |
293 | setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | 293 | setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
294 | sigset_t *set, struct pt_regs *regs, int in_syscall) | 294 | sigset_t *set, struct pt_regs *regs, int in_syscall) |
295 | { | 295 | { |
296 | struct rt_sigframe __user *frame; | 296 | struct rt_sigframe __user *frame; |
297 | unsigned long rp, usp; | 297 | unsigned long rp, usp; |
298 | unsigned long haddr, sigframe_size; | 298 | unsigned long haddr, sigframe_size; |
299 | struct siginfo si; | 299 | struct siginfo si; |
300 | int err = 0; | 300 | int err = 0; |
301 | #ifdef __LP64__ | 301 | #ifdef __LP64__ |
302 | compat_int_t compat_val; | 302 | compat_int_t compat_val; |
303 | struct compat_rt_sigframe __user * compat_frame; | 303 | struct compat_rt_sigframe __user * compat_frame; |
304 | compat_sigset_t compat_set; | 304 | compat_sigset_t compat_set; |
305 | #endif | 305 | #endif |
306 | 306 | ||
307 | usp = (regs->gr[30] & ~(0x01UL)); | 307 | usp = (regs->gr[30] & ~(0x01UL)); |
308 | /*FIXME: frame_size parameter is unused, remove it. */ | 308 | /*FIXME: frame_size parameter is unused, remove it. */ |
309 | frame = get_sigframe(ka, usp, sizeof(*frame)); | 309 | frame = get_sigframe(ka, usp, sizeof(*frame)); |
310 | 310 | ||
311 | DBG(1,"SETUP_RT_FRAME: START\n"); | 311 | DBG(1,"SETUP_RT_FRAME: START\n"); |
312 | DBG(1,"setup_rt_frame: frame %p info %p\n", frame, info); | 312 | DBG(1,"setup_rt_frame: frame %p info %p\n", frame, info); |
313 | 313 | ||
314 | 314 | ||
315 | #ifdef __LP64__ | 315 | #ifdef __LP64__ |
316 | 316 | ||
317 | compat_frame = (struct compat_rt_sigframe __user *)frame; | 317 | compat_frame = (struct compat_rt_sigframe __user *)frame; |
318 | 318 | ||
319 | if(personality(current->personality) == PER_LINUX32) { | 319 | if(personality(current->personality) == PER_LINUX32) { |
320 | DBG(1,"setup_rt_frame: frame->info = 0x%p\n", &compat_frame->info); | 320 | DBG(1,"setup_rt_frame: frame->info = 0x%p\n", &compat_frame->info); |
321 | err |= compat_copy_siginfo_to_user(&compat_frame->info, info); | 321 | err |= compat_copy_siginfo_to_user(&compat_frame->info, info); |
322 | DBG(1,"SETUP_RT_FRAME: 1\n"); | 322 | DBG(1,"SETUP_RT_FRAME: 1\n"); |
323 | compat_val = (compat_int_t)current->sas_ss_sp; | 323 | compat_val = (compat_int_t)current->sas_ss_sp; |
324 | err |= __put_user(compat_val, &compat_frame->uc.uc_stack.ss_sp); | 324 | err |= __put_user(compat_val, &compat_frame->uc.uc_stack.ss_sp); |
325 | DBG(1,"SETUP_RT_FRAME: 2\n"); | 325 | DBG(1,"SETUP_RT_FRAME: 2\n"); |
326 | compat_val = (compat_int_t)current->sas_ss_size; | 326 | compat_val = (compat_int_t)current->sas_ss_size; |
327 | err |= __put_user(compat_val, &compat_frame->uc.uc_stack.ss_size); | 327 | err |= __put_user(compat_val, &compat_frame->uc.uc_stack.ss_size); |
328 | DBG(1,"SETUP_RT_FRAME: 3\n"); | 328 | DBG(1,"SETUP_RT_FRAME: 3\n"); |
329 | compat_val = sas_ss_flags(regs->gr[30]); | 329 | compat_val = sas_ss_flags(regs->gr[30]); |
330 | err |= __put_user(compat_val, &compat_frame->uc.uc_stack.ss_flags); | 330 | err |= __put_user(compat_val, &compat_frame->uc.uc_stack.ss_flags); |
331 | DBG(1,"setup_rt_frame: frame->uc = 0x%p\n", &compat_frame->uc); | 331 | DBG(1,"setup_rt_frame: frame->uc = 0x%p\n", &compat_frame->uc); |
332 | DBG(1,"setup_rt_frame: frame->uc.uc_mcontext = 0x%p\n", &compat_frame->uc.uc_mcontext); | 332 | DBG(1,"setup_rt_frame: frame->uc.uc_mcontext = 0x%p\n", &compat_frame->uc.uc_mcontext); |
333 | err |= setup_sigcontext32(&compat_frame->uc.uc_mcontext, | 333 | err |= setup_sigcontext32(&compat_frame->uc.uc_mcontext, |
334 | &compat_frame->regs, regs, in_syscall); | 334 | &compat_frame->regs, regs, in_syscall); |
335 | sigset_64to32(&compat_set,set); | 335 | sigset_64to32(&compat_set,set); |
336 | err |= __copy_to_user(&compat_frame->uc.uc_sigmask, &compat_set, sizeof(compat_set)); | 336 | err |= __copy_to_user(&compat_frame->uc.uc_sigmask, &compat_set, sizeof(compat_set)); |
337 | } else | 337 | } else |
338 | #endif | 338 | #endif |
339 | { | 339 | { |
340 | DBG(1,"setup_rt_frame: frame->info = 0x%p\n", &frame->info); | 340 | DBG(1,"setup_rt_frame: frame->info = 0x%p\n", &frame->info); |
341 | err |= copy_siginfo_to_user(&frame->info, info); | 341 | err |= copy_siginfo_to_user(&frame->info, info); |
342 | err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); | 342 | err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
343 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); | 343 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); |
344 | err |= __put_user(sas_ss_flags(regs->gr[30]), | 344 | err |= __put_user(sas_ss_flags(regs->gr[30]), |
345 | &frame->uc.uc_stack.ss_flags); | 345 | &frame->uc.uc_stack.ss_flags); |
346 | DBG(1,"setup_rt_frame: frame->uc = 0x%p\n", &frame->uc); | 346 | DBG(1,"setup_rt_frame: frame->uc = 0x%p\n", &frame->uc); |
347 | DBG(1,"setup_rt_frame: frame->uc.uc_mcontext = 0x%p\n", &frame->uc.uc_mcontext); | 347 | DBG(1,"setup_rt_frame: frame->uc.uc_mcontext = 0x%p\n", &frame->uc.uc_mcontext); |
348 | err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, in_syscall); | 348 | err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, in_syscall); |
349 | /* FIXME: Should probably be converted aswell for the compat case */ | 349 | /* FIXME: Should probably be converted aswell for the compat case */ |
350 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); | 350 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
351 | } | 351 | } |
352 | 352 | ||
353 | if (err) | 353 | if (err) |
354 | goto give_sigsegv; | 354 | goto give_sigsegv; |
355 | 355 | ||
356 | /* Set up to return from userspace. If provided, use a stub | 356 | /* Set up to return from userspace. If provided, use a stub |
357 | already in userspace. The first words of tramp are used to | 357 | already in userspace. The first words of tramp are used to |
358 | save the previous sigrestartblock trampoline that might be | 358 | save the previous sigrestartblock trampoline that might be |
359 | on the stack. We start the sigreturn trampoline at | 359 | on the stack. We start the sigreturn trampoline at |
360 | SIGRESTARTBLOCK_TRAMP+X. */ | 360 | SIGRESTARTBLOCK_TRAMP+X. */ |
361 | err |= __put_user(in_syscall ? INSN_LDI_R25_1 : INSN_LDI_R25_0, | 361 | err |= __put_user(in_syscall ? INSN_LDI_R25_1 : INSN_LDI_R25_0, |
362 | &frame->tramp[SIGRESTARTBLOCK_TRAMP+0]); | 362 | &frame->tramp[SIGRESTARTBLOCK_TRAMP+0]); |
363 | err |= __put_user(INSN_LDI_R20, | 363 | err |= __put_user(INSN_LDI_R20, |
364 | &frame->tramp[SIGRESTARTBLOCK_TRAMP+1]); | 364 | &frame->tramp[SIGRESTARTBLOCK_TRAMP+1]); |
365 | err |= __put_user(INSN_BLE_SR2_R0, | 365 | err |= __put_user(INSN_BLE_SR2_R0, |
366 | &frame->tramp[SIGRESTARTBLOCK_TRAMP+2]); | 366 | &frame->tramp[SIGRESTARTBLOCK_TRAMP+2]); |
367 | err |= __put_user(INSN_NOP, &frame->tramp[SIGRESTARTBLOCK_TRAMP+3]); | 367 | err |= __put_user(INSN_NOP, &frame->tramp[SIGRESTARTBLOCK_TRAMP+3]); |
368 | 368 | ||
369 | #if DEBUG_SIG | 369 | #if DEBUG_SIG |
370 | /* Assert that we're flushing in the correct space... */ | 370 | /* Assert that we're flushing in the correct space... */ |
371 | { | 371 | { |
372 | int sid; | 372 | int sid; |
373 | asm ("mfsp %%sr3,%0" : "=r" (sid)); | 373 | asm ("mfsp %%sr3,%0" : "=r" (sid)); |
374 | DBG(1,"setup_rt_frame: Flushing 64 bytes at space %#x offset %p\n", | 374 | DBG(1,"setup_rt_frame: Flushing 64 bytes at space %#x offset %p\n", |
375 | sid, frame->tramp); | 375 | sid, frame->tramp); |
376 | } | 376 | } |
377 | #endif | 377 | #endif |
378 | 378 | ||
379 | flush_user_dcache_range((unsigned long) &frame->tramp[0], | 379 | flush_user_dcache_range((unsigned long) &frame->tramp[0], |
380 | (unsigned long) &frame->tramp[TRAMP_SIZE]); | 380 | (unsigned long) &frame->tramp[TRAMP_SIZE]); |
381 | flush_user_icache_range((unsigned long) &frame->tramp[0], | 381 | flush_user_icache_range((unsigned long) &frame->tramp[0], |
382 | (unsigned long) &frame->tramp[TRAMP_SIZE]); | 382 | (unsigned long) &frame->tramp[TRAMP_SIZE]); |
383 | 383 | ||
384 | /* TRAMP Words 0-4, Lenght 5 = SIGRESTARTBLOCK_TRAMP | 384 | /* TRAMP Words 0-4, Lenght 5 = SIGRESTARTBLOCK_TRAMP |
385 | * TRAMP Words 5-9, Length 4 = SIGRETURN_TRAMP | 385 | * TRAMP Words 5-9, Length 4 = SIGRETURN_TRAMP |
386 | * So the SIGRETURN_TRAMP is at the end of SIGRESTARTBLOCK_TRAMP | 386 | * So the SIGRETURN_TRAMP is at the end of SIGRESTARTBLOCK_TRAMP |
387 | */ | 387 | */ |
388 | rp = (unsigned long) &frame->tramp[SIGRESTARTBLOCK_TRAMP]; | 388 | rp = (unsigned long) &frame->tramp[SIGRESTARTBLOCK_TRAMP]; |
389 | 389 | ||
390 | if (err) | 390 | if (err) |
391 | goto give_sigsegv; | 391 | goto give_sigsegv; |
392 | 392 | ||
393 | haddr = A(ka->sa.sa_handler); | 393 | haddr = A(ka->sa.sa_handler); |
394 | /* The sa_handler may be a pointer to a function descriptor */ | 394 | /* The sa_handler may be a pointer to a function descriptor */ |
395 | #ifdef __LP64__ | 395 | #ifdef __LP64__ |
396 | if(personality(current->personality) == PER_LINUX32) { | 396 | if(personality(current->personality) == PER_LINUX32) { |
397 | #endif | 397 | #endif |
398 | if (haddr & PA_PLABEL_FDESC) { | 398 | if (haddr & PA_PLABEL_FDESC) { |
399 | Elf32_Fdesc fdesc; | 399 | Elf32_Fdesc fdesc; |
400 | Elf32_Fdesc __user *ufdesc = (Elf32_Fdesc __user *)A(haddr & ~3); | 400 | Elf32_Fdesc __user *ufdesc = (Elf32_Fdesc __user *)A(haddr & ~3); |
401 | 401 | ||
402 | err = __copy_from_user(&fdesc, ufdesc, sizeof(fdesc)); | 402 | err = __copy_from_user(&fdesc, ufdesc, sizeof(fdesc)); |
403 | 403 | ||
404 | if (err) | 404 | if (err) |
405 | goto give_sigsegv; | 405 | goto give_sigsegv; |
406 | 406 | ||
407 | haddr = fdesc.addr; | 407 | haddr = fdesc.addr; |
408 | regs->gr[19] = fdesc.gp; | 408 | regs->gr[19] = fdesc.gp; |
409 | } | 409 | } |
410 | #ifdef __LP64__ | 410 | #ifdef __LP64__ |
411 | } else { | 411 | } else { |
412 | Elf64_Fdesc fdesc; | 412 | Elf64_Fdesc fdesc; |
413 | Elf64_Fdesc __user *ufdesc = (Elf64_Fdesc __user *)A(haddr & ~3); | 413 | Elf64_Fdesc __user *ufdesc = (Elf64_Fdesc __user *)A(haddr & ~3); |
414 | 414 | ||
415 | err = __copy_from_user(&fdesc, ufdesc, sizeof(fdesc)); | 415 | err = __copy_from_user(&fdesc, ufdesc, sizeof(fdesc)); |
416 | 416 | ||
417 | if (err) | 417 | if (err) |
418 | goto give_sigsegv; | 418 | goto give_sigsegv; |
419 | 419 | ||
420 | haddr = fdesc.addr; | 420 | haddr = fdesc.addr; |
421 | regs->gr[19] = fdesc.gp; | 421 | regs->gr[19] = fdesc.gp; |
422 | DBG(1,"setup_rt_frame: 64 bit signal, exe=%#lx, r19=%#lx, in_syscall=%d\n", | 422 | DBG(1,"setup_rt_frame: 64 bit signal, exe=%#lx, r19=%#lx, in_syscall=%d\n", |
423 | haddr, regs->gr[19], in_syscall); | 423 | haddr, regs->gr[19], in_syscall); |
424 | } | 424 | } |
425 | #endif | 425 | #endif |
426 | 426 | ||
427 | /* The syscall return path will create IAOQ values from r31. | 427 | /* The syscall return path will create IAOQ values from r31. |
428 | */ | 428 | */ |
429 | sigframe_size = PARISC_RT_SIGFRAME_SIZE; | 429 | sigframe_size = PARISC_RT_SIGFRAME_SIZE; |
430 | #ifdef __LP64__ | 430 | #ifdef __LP64__ |
431 | if(personality(current->personality) == PER_LINUX32) | 431 | if(personality(current->personality) == PER_LINUX32) |
432 | sigframe_size = PARISC_RT_SIGFRAME_SIZE32; | 432 | sigframe_size = PARISC_RT_SIGFRAME_SIZE32; |
433 | #endif | 433 | #endif |
434 | if (in_syscall) { | 434 | if (in_syscall) { |
435 | regs->gr[31] = haddr; | 435 | regs->gr[31] = haddr; |
436 | #ifdef __LP64__ | 436 | #ifdef __LP64__ |
437 | if(personality(current->personality) == PER_LINUX) | 437 | if(personality(current->personality) == PER_LINUX) |
438 | sigframe_size |= 1; | 438 | sigframe_size |= 1; |
439 | #endif | 439 | #endif |
440 | } else { | 440 | } else { |
441 | unsigned long psw = USER_PSW; | 441 | unsigned long psw = USER_PSW; |
442 | #ifdef __LP64__ | 442 | #ifdef __LP64__ |
443 | if(personality(current->personality) == PER_LINUX) | 443 | if(personality(current->personality) == PER_LINUX) |
444 | psw |= PSW_W; | 444 | psw |= PSW_W; |
445 | #endif | 445 | #endif |
446 | 446 | ||
447 | /* If we are singlestepping, arrange a trap to be delivered | 447 | /* If we are singlestepping, arrange a trap to be delivered |
448 | when we return to userspace. Note the semantics -- we | 448 | when we return to userspace. Note the semantics -- we |
449 | should trap before the first insn in the handler is | 449 | should trap before the first insn in the handler is |
450 | executed. Ref: | 450 | executed. Ref: |
451 | http://sources.redhat.com/ml/gdb/2004-11/msg00245.html | 451 | http://sources.redhat.com/ml/gdb/2004-11/msg00245.html |
452 | */ | 452 | */ |
453 | if (pa_psw(current)->r) { | 453 | if (pa_psw(current)->r) { |
454 | pa_psw(current)->r = 0; | 454 | pa_psw(current)->r = 0; |
455 | psw |= PSW_R; | 455 | psw |= PSW_R; |
456 | mtctl(-1, 0); | 456 | mtctl(-1, 0); |
457 | } | 457 | } |
458 | 458 | ||
459 | regs->gr[0] = psw; | 459 | regs->gr[0] = psw; |
460 | regs->iaoq[0] = haddr | 3; | 460 | regs->iaoq[0] = haddr | 3; |
461 | regs->iaoq[1] = regs->iaoq[0] + 4; | 461 | regs->iaoq[1] = regs->iaoq[0] + 4; |
462 | } | 462 | } |
463 | 463 | ||
464 | regs->gr[2] = rp; /* userland return pointer */ | 464 | regs->gr[2] = rp; /* userland return pointer */ |
465 | regs->gr[26] = sig; /* signal number */ | 465 | regs->gr[26] = sig; /* signal number */ |
466 | 466 | ||
467 | #ifdef __LP64__ | 467 | #ifdef __LP64__ |
468 | if(personality(current->personality) == PER_LINUX32){ | 468 | if(personality(current->personality) == PER_LINUX32){ |
469 | regs->gr[25] = A(&compat_frame->info); /* siginfo pointer */ | 469 | regs->gr[25] = A(&compat_frame->info); /* siginfo pointer */ |
470 | regs->gr[24] = A(&compat_frame->uc); /* ucontext pointer */ | 470 | regs->gr[24] = A(&compat_frame->uc); /* ucontext pointer */ |
471 | } else | 471 | } else |
472 | #endif | 472 | #endif |
473 | { | 473 | { |
474 | regs->gr[25] = A(&frame->info); /* siginfo pointer */ | 474 | regs->gr[25] = A(&frame->info); /* siginfo pointer */ |
475 | regs->gr[24] = A(&frame->uc); /* ucontext pointer */ | 475 | regs->gr[24] = A(&frame->uc); /* ucontext pointer */ |
476 | } | 476 | } |
477 | 477 | ||
478 | DBG(1,"setup_rt_frame: making sigreturn frame: %#lx + %#lx = %#lx\n", | 478 | DBG(1,"setup_rt_frame: making sigreturn frame: %#lx + %#lx = %#lx\n", |
479 | regs->gr[30], sigframe_size, | 479 | regs->gr[30], sigframe_size, |
480 | regs->gr[30] + sigframe_size); | 480 | regs->gr[30] + sigframe_size); |
481 | /* Raise the user stack pointer to make a proper call frame. */ | 481 | /* Raise the user stack pointer to make a proper call frame. */ |
482 | regs->gr[30] = (A(frame) + sigframe_size); | 482 | regs->gr[30] = (A(frame) + sigframe_size); |
483 | 483 | ||
484 | 484 | ||
485 | DBG(1,"setup_rt_frame: sig deliver (%s,%d) frame=0x%p sp=%#lx iaoq=%#lx/%#lx rp=%#lx\n", | 485 | DBG(1,"setup_rt_frame: sig deliver (%s,%d) frame=0x%p sp=%#lx iaoq=%#lx/%#lx rp=%#lx\n", |
486 | current->comm, current->pid, frame, regs->gr[30], | 486 | current->comm, current->pid, frame, regs->gr[30], |
487 | regs->iaoq[0], regs->iaoq[1], rp); | 487 | regs->iaoq[0], regs->iaoq[1], rp); |
488 | 488 | ||
489 | return 1; | 489 | return 1; |
490 | 490 | ||
491 | give_sigsegv: | 491 | give_sigsegv: |
492 | DBG(1,"setup_rt_frame: sending SIGSEGV\n"); | 492 | DBG(1,"setup_rt_frame: sending SIGSEGV\n"); |
493 | if (sig == SIGSEGV) | 493 | force_sigsegv(sig, current); |
494 | ka->sa.sa_handler = SIG_DFL; | ||
495 | si.si_signo = SIGSEGV; | ||
496 | si.si_errno = 0; | ||
497 | si.si_code = SI_KERNEL; | ||
498 | si.si_pid = current->pid; | ||
499 | si.si_uid = current->uid; | ||
500 | si.si_addr = frame; | ||
501 | force_sig_info(SIGSEGV, &si, current); | ||
502 | return 0; | 494 | return 0; |
503 | } | 495 | } |
504 | 496 | ||
505 | /* | 497 | /* |
506 | * OK, we're invoking a handler. | 498 | * OK, we're invoking a handler. |
507 | */ | 499 | */ |
508 | 500 | ||
509 | static long | 501 | static long |
510 | handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, | 502 | handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, |
511 | sigset_t *oldset, struct pt_regs *regs, int in_syscall) | 503 | sigset_t *oldset, struct pt_regs *regs, int in_syscall) |
512 | { | 504 | { |
513 | DBG(1,"handle_signal: sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p\n", | 505 | DBG(1,"handle_signal: sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p\n", |
514 | sig, ka, info, oldset, regs); | 506 | sig, ka, info, oldset, regs); |
515 | 507 | ||
516 | /* Set up the stack frame */ | 508 | /* Set up the stack frame */ |
517 | if (!setup_rt_frame(sig, ka, info, oldset, regs, in_syscall)) | 509 | if (!setup_rt_frame(sig, ka, info, oldset, regs, in_syscall)) |
518 | return 0; | 510 | return 0; |
519 | 511 | ||
520 | spin_lock_irq(¤t->sighand->siglock); | 512 | spin_lock_irq(¤t->sighand->siglock); |
521 | sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); | 513 | sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); |
522 | if (!(ka->sa.sa_flags & SA_NODEFER)) | 514 | if (!(ka->sa.sa_flags & SA_NODEFER)) |
523 | sigaddset(¤t->blocked,sig); | 515 | sigaddset(¤t->blocked,sig); |
524 | recalc_sigpending(); | 516 | recalc_sigpending(); |
525 | spin_unlock_irq(¤t->sighand->siglock); | 517 | spin_unlock_irq(¤t->sighand->siglock); |
526 | return 1; | 518 | return 1; |
527 | } | 519 | } |
528 | 520 | ||
529 | /* | 521 | /* |
530 | * Note that 'init' is a special process: it doesn't get signals it doesn't | 522 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
531 | * want to handle. Thus you cannot kill init even with a SIGKILL even by | 523 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
532 | * mistake. | 524 | * mistake. |
533 | * | 525 | * |
534 | * We need to be able to restore the syscall arguments (r21-r26) to | 526 | * We need to be able to restore the syscall arguments (r21-r26) to |
535 | * restart syscalls. Thus, the syscall path should save them in the | 527 | * restart syscalls. Thus, the syscall path should save them in the |
536 | * pt_regs structure (it's okay to do so since they are caller-save | 528 | * pt_regs structure (it's okay to do so since they are caller-save |
537 | * registers). As noted below, the syscall number gets restored for | 529 | * registers). As noted below, the syscall number gets restored for |
538 | * us due to the magic of delayed branching. | 530 | * us due to the magic of delayed branching. |
539 | */ | 531 | */ |
540 | 532 | ||
541 | asmlinkage int | 533 | asmlinkage int |
542 | do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall) | 534 | do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall) |
543 | { | 535 | { |
544 | siginfo_t info; | 536 | siginfo_t info; |
545 | struct k_sigaction ka; | 537 | struct k_sigaction ka; |
546 | int signr; | 538 | int signr; |
547 | 539 | ||
548 | DBG(1,"\ndo_signal: oldset=0x%p, regs=0x%p, sr7 %#lx, in_syscall=%d\n", | 540 | DBG(1,"\ndo_signal: oldset=0x%p, regs=0x%p, sr7 %#lx, in_syscall=%d\n", |
549 | oldset, regs, regs->sr[7], in_syscall); | 541 | oldset, regs, regs->sr[7], in_syscall); |
550 | 542 | ||
551 | /* Everyone else checks to see if they are in kernel mode at | 543 | /* Everyone else checks to see if they are in kernel mode at |
552 | this point and exits if that's the case. I'm not sure why | 544 | this point and exits if that's the case. I'm not sure why |
553 | we would be called in that case, but for some reason we | 545 | we would be called in that case, but for some reason we |
554 | are. */ | 546 | are. */ |
555 | 547 | ||
556 | if (!oldset) | 548 | if (!oldset) |
557 | oldset = ¤t->blocked; | 549 | oldset = ¤t->blocked; |
558 | 550 | ||
559 | DBG(1,"do_signal: oldset %08lx / %08lx\n", | 551 | DBG(1,"do_signal: oldset %08lx / %08lx\n", |
560 | oldset->sig[0], oldset->sig[1]); | 552 | oldset->sig[0], oldset->sig[1]); |
561 | 553 | ||
562 | 554 | ||
563 | /* May need to force signal if handle_signal failed to deliver */ | 555 | /* May need to force signal if handle_signal failed to deliver */ |
564 | while (1) { | 556 | while (1) { |
565 | 557 | ||
566 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | 558 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
567 | DBG(3,"do_signal: signr = %d, regs->gr[28] = %ld\n", signr, regs->gr[28]); | 559 | DBG(3,"do_signal: signr = %d, regs->gr[28] = %ld\n", signr, regs->gr[28]); |
568 | 560 | ||
569 | if (signr <= 0) | 561 | if (signr <= 0) |
570 | break; | 562 | break; |
571 | 563 | ||
572 | /* Restart a system call if necessary. */ | 564 | /* Restart a system call if necessary. */ |
573 | if (in_syscall) { | 565 | if (in_syscall) { |
574 | /* Check the return code */ | 566 | /* Check the return code */ |
575 | switch (regs->gr[28]) { | 567 | switch (regs->gr[28]) { |
576 | case -ERESTART_RESTARTBLOCK: | 568 | case -ERESTART_RESTARTBLOCK: |
577 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | 569 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
578 | case -ERESTARTNOHAND: | 570 | case -ERESTARTNOHAND: |
579 | DBG(1,"ERESTARTNOHAND: returning -EINTR\n"); | 571 | DBG(1,"ERESTARTNOHAND: returning -EINTR\n"); |
580 | regs->gr[28] = -EINTR; | 572 | regs->gr[28] = -EINTR; |
581 | break; | 573 | break; |
582 | 574 | ||
583 | case -ERESTARTSYS: | 575 | case -ERESTARTSYS: |
584 | if (!(ka.sa.sa_flags & SA_RESTART)) { | 576 | if (!(ka.sa.sa_flags & SA_RESTART)) { |
585 | DBG(1,"ERESTARTSYS: putting -EINTR\n"); | 577 | DBG(1,"ERESTARTSYS: putting -EINTR\n"); |
586 | regs->gr[28] = -EINTR; | 578 | regs->gr[28] = -EINTR; |
587 | break; | 579 | break; |
588 | } | 580 | } |
589 | /* fallthrough */ | 581 | /* fallthrough */ |
590 | case -ERESTARTNOINTR: | 582 | case -ERESTARTNOINTR: |
591 | /* A syscall is just a branch, so all | 583 | /* A syscall is just a branch, so all |
592 | we have to do is fiddle the return pointer. */ | 584 | we have to do is fiddle the return pointer. */ |
593 | regs->gr[31] -= 8; /* delayed branching */ | 585 | regs->gr[31] -= 8; /* delayed branching */ |
594 | /* Preserve original r28. */ | 586 | /* Preserve original r28. */ |
595 | regs->gr[28] = regs->orig_r28; | 587 | regs->gr[28] = regs->orig_r28; |
596 | break; | 588 | break; |
597 | } | 589 | } |
598 | } | 590 | } |
599 | /* Whee! Actually deliver the signal. If the | 591 | /* Whee! Actually deliver the signal. If the |
600 | delivery failed, we need to continue to iterate in | 592 | delivery failed, we need to continue to iterate in |
601 | this loop so we can deliver the SIGSEGV... */ | 593 | this loop so we can deliver the SIGSEGV... */ |
602 | if (handle_signal(signr, &info, &ka, oldset, regs, in_syscall)) { | 594 | if (handle_signal(signr, &info, &ka, oldset, regs, in_syscall)) { |
603 | DBG(1,KERN_DEBUG "do_signal: Exit (success), regs->gr[28] = %ld\n", | 595 | DBG(1,KERN_DEBUG "do_signal: Exit (success), regs->gr[28] = %ld\n", |
604 | regs->gr[28]); | 596 | regs->gr[28]); |
605 | return 1; | 597 | return 1; |
606 | } | 598 | } |
607 | } | 599 | } |
608 | /* end of while(1) looping forever if we can't force a signal */ | 600 | /* end of while(1) looping forever if we can't force a signal */ |
609 | 601 | ||
610 | /* Did we come from a system call? */ | 602 | /* Did we come from a system call? */ |
611 | if (in_syscall) { | 603 | if (in_syscall) { |
612 | /* Restart the system call - no handlers present */ | 604 | /* Restart the system call - no handlers present */ |
613 | if (regs->gr[28] == -ERESTART_RESTARTBLOCK) { | 605 | if (regs->gr[28] == -ERESTART_RESTARTBLOCK) { |
614 | unsigned int *usp = (unsigned int *)regs->gr[30]; | 606 | unsigned int *usp = (unsigned int *)regs->gr[30]; |
615 | 607 | ||
616 | /* Setup a trampoline to restart the syscall | 608 | /* Setup a trampoline to restart the syscall |
617 | * with __NR_restart_syscall | 609 | * with __NR_restart_syscall |
618 | * | 610 | * |
619 | * 0: <return address (orig r31)> | 611 | * 0: <return address (orig r31)> |
620 | * 4: <2nd half for 64-bit> | 612 | * 4: <2nd half for 64-bit> |
621 | * 8: ldw 0(%sp), %r31 | 613 | * 8: ldw 0(%sp), %r31 |
622 | * 12: be 0x100(%sr2, %r0) | 614 | * 12: be 0x100(%sr2, %r0) |
623 | * 16: ldi __NR_restart_syscall, %r20 | 615 | * 16: ldi __NR_restart_syscall, %r20 |
624 | */ | 616 | */ |
625 | #ifndef __LP64__ | 617 | #ifndef __LP64__ |
626 | put_user(regs->gr[31], &usp[0]); | 618 | put_user(regs->gr[31], &usp[0]); |
627 | put_user(0x0fc0109f, &usp[2]); | 619 | put_user(0x0fc0109f, &usp[2]); |
628 | #else | 620 | #else |
629 | put_user(regs->gr[31] >> 32, &usp[0]); | 621 | put_user(regs->gr[31] >> 32, &usp[0]); |
630 | put_user(regs->gr[31] & 0xffffffff, &usp[1]); | 622 | put_user(regs->gr[31] & 0xffffffff, &usp[1]); |
631 | put_user(0x0fc010df, &usp[2]); | 623 | put_user(0x0fc010df, &usp[2]); |
632 | #endif | 624 | #endif |
633 | put_user(0xe0008200, &usp[3]); | 625 | put_user(0xe0008200, &usp[3]); |
634 | put_user(0x34140000, &usp[4]); | 626 | put_user(0x34140000, &usp[4]); |
635 | 627 | ||
636 | /* Stack is 64-byte aligned, and we only | 628 | /* Stack is 64-byte aligned, and we only |
637 | * need to flush 1 cache line */ | 629 | * need to flush 1 cache line */ |
638 | asm("fdc 0(%%sr3, %0)\n" | 630 | asm("fdc 0(%%sr3, %0)\n" |
639 | "sync\n" | 631 | "sync\n" |
640 | "fic 0(%%sr3, %0)\n" | 632 | "fic 0(%%sr3, %0)\n" |
641 | "sync\n" | 633 | "sync\n" |
642 | : : "r"(regs->gr[30])); | 634 | : : "r"(regs->gr[30])); |
643 | 635 | ||
644 | regs->gr[31] = regs->gr[30] + 8; | 636 | regs->gr[31] = regs->gr[30] + 8; |
645 | /* Preserve original r28. */ | 637 | /* Preserve original r28. */ |
646 | regs->gr[28] = regs->orig_r28; | 638 | regs->gr[28] = regs->orig_r28; |
647 | } else if (regs->gr[28] == -ERESTARTNOHAND || | 639 | } else if (regs->gr[28] == -ERESTARTNOHAND || |
648 | regs->gr[28] == -ERESTARTSYS || | 640 | regs->gr[28] == -ERESTARTSYS || |
649 | regs->gr[28] == -ERESTARTNOINTR) { | 641 | regs->gr[28] == -ERESTARTNOINTR) { |
650 | /* Hooray for delayed branching. We don't | 642 | /* Hooray for delayed branching. We don't |
651 | have to restore %r20 (the system call | 643 | have to restore %r20 (the system call |
652 | number) because it gets loaded in the delay | 644 | number) because it gets loaded in the delay |
653 | slot of the branch external instruction. */ | 645 | slot of the branch external instruction. */ |
654 | regs->gr[31] -= 8; | 646 | regs->gr[31] -= 8; |
655 | /* Preserve original r28. */ | 647 | /* Preserve original r28. */ |
656 | regs->gr[28] = regs->orig_r28; | 648 | regs->gr[28] = regs->orig_r28; |
657 | } | 649 | } |
658 | } | 650 | } |
659 | 651 | ||
660 | DBG(1,"do_signal: Exit (not delivered), regs->gr[28] = %ld\n", | 652 | DBG(1,"do_signal: Exit (not delivered), regs->gr[28] = %ld\n", |
661 | regs->gr[28]); | 653 | regs->gr[28]); |
662 | 654 | ||
663 | return 0; | 655 | return 0; |
664 | } | 656 | } |
665 | 657 |