blob: 47509df3b893acfb365ec503cbe00f2dabeea2ac [file] [log] [blame]
Adrian Bunkb00dc832008-05-19 16:52:27 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * arch/sparc64/kernel/signal.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
David S. Miller0a4949c42008-07-31 20:40:46 -07005 * Copyright (C) 1995, 2008 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
7 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
8 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
9 */
10
David S. Miller09337f52008-04-26 03:17:12 -070011#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/compat.h> /* for compat_old_sigset_t */
13#endif
14#include <linux/sched.h>
15#include <linux/kernel.h>
16#include <linux/signal.h>
17#include <linux/errno.h>
18#include <linux/wait.h>
19#include <linux/ptrace.h>
Roland McGrathe35a8922008-04-20 15:06:49 -070020#include <linux/tracehook.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/unistd.h>
22#include <linux/mm.h>
23#include <linux/tty.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/binfmts.h>
25#include <linux/bitops.h>
26
27#include <asm/uaccess.h>
28#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/pgtable.h>
30#include <asm/fpumacro.h>
31#include <asm/uctx.h>
32#include <asm/siginfo.h>
33#include <asm/visasm.h>
34
David S. Miller062ea6d2008-03-26 01:52:18 -070035#include "entry.h"
36#include "systbls.h"
David S. Miller55984732011-08-20 17:14:54 -070037#include "sigutil.h"
David S. Miller062ea6d2008-03-26 01:52:18 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041/* {set, get}context() needed for 64-bit SparcLinux userland. */
42asmlinkage void sparc64_set_context(struct pt_regs *regs)
43{
44 struct ucontext __user *ucp = (struct ucontext __user *)
45 regs->u_regs[UREG_I0];
46 mc_gregset_t __user *grp;
47 unsigned long pc, npc, tstate;
48 unsigned long fp, i7;
49 unsigned char fenab;
50 int err;
51
52 flush_user_windows();
53 if (get_thread_wsaved() ||
54 (((unsigned long)ucp) & (sizeof(unsigned long)-1)) ||
55 (!__access_ok(ucp, sizeof(*ucp))))
56 goto do_sigsegv;
57 grp = &ucp->uc_mcontext.mc_gregs;
58 err = __get_user(pc, &((*grp)[MC_PC]));
59 err |= __get_user(npc, &((*grp)[MC_NPC]));
60 if (err || ((pc | npc) & 3))
61 goto do_sigsegv;
62 if (regs->u_regs[UREG_I1]) {
63 sigset_t set;
64
65 if (_NSIG_WORDS == 1) {
66 if (__get_user(set.sig[0], &ucp->uc_sigmask.sig[0]))
67 goto do_sigsegv;
68 } else {
69 if (__copy_from_user(&set, &ucp->uc_sigmask, sizeof(sigset_t)))
70 goto do_sigsegv;
71 }
72 sigdelsetmask(&set, ~_BLOCKABLE);
73 spin_lock_irq(&current->sighand->siglock);
74 current->blocked = set;
75 recalc_sigpending();
76 spin_unlock_irq(&current->sighand->siglock);
77 }
78 if (test_thread_flag(TIF_32BIT)) {
79 pc &= 0xffffffff;
80 npc &= 0xffffffff;
81 }
82 regs->tpc = pc;
83 regs->tnpc = npc;
84 err |= __get_user(regs->y, &((*grp)[MC_Y]));
85 err |= __get_user(tstate, &((*grp)[MC_TSTATE]));
86 regs->tstate &= ~(TSTATE_ASI | TSTATE_ICC | TSTATE_XCC);
87 regs->tstate |= (tstate & (TSTATE_ASI | TSTATE_ICC | TSTATE_XCC));
88 err |= __get_user(regs->u_regs[UREG_G1], (&(*grp)[MC_G1]));
89 err |= __get_user(regs->u_regs[UREG_G2], (&(*grp)[MC_G2]));
90 err |= __get_user(regs->u_regs[UREG_G3], (&(*grp)[MC_G3]));
91 err |= __get_user(regs->u_regs[UREG_G4], (&(*grp)[MC_G4]));
92 err |= __get_user(regs->u_regs[UREG_G5], (&(*grp)[MC_G5]));
93 err |= __get_user(regs->u_regs[UREG_G6], (&(*grp)[MC_G6]));
David S. Miller0a4949c42008-07-31 20:40:46 -070094
95 /* Skip %g7 as that's the thread register in userspace. */
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 err |= __get_user(regs->u_regs[UREG_I0], (&(*grp)[MC_O0]));
98 err |= __get_user(regs->u_regs[UREG_I1], (&(*grp)[MC_O1]));
99 err |= __get_user(regs->u_regs[UREG_I2], (&(*grp)[MC_O2]));
100 err |= __get_user(regs->u_regs[UREG_I3], (&(*grp)[MC_O3]));
101 err |= __get_user(regs->u_regs[UREG_I4], (&(*grp)[MC_O4]));
102 err |= __get_user(regs->u_regs[UREG_I5], (&(*grp)[MC_O5]));
103 err |= __get_user(regs->u_regs[UREG_I6], (&(*grp)[MC_O6]));
104 err |= __get_user(regs->u_regs[UREG_I7], (&(*grp)[MC_O7]));
105
106 err |= __get_user(fp, &(ucp->uc_mcontext.mc_fp));
107 err |= __get_user(i7, &(ucp->uc_mcontext.mc_i7));
108 err |= __put_user(fp,
109 (&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[6])));
110 err |= __put_user(i7,
111 (&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[7])));
112
113 err |= __get_user(fenab, &(ucp->uc_mcontext.mc_fpregs.mcfpu_enab));
114 if (fenab) {
115 unsigned long *fpregs = current_thread_info()->fpregs;
116 unsigned long fprs;
117
118 fprs_write(0);
119 err |= __get_user(fprs, &(ucp->uc_mcontext.mc_fpregs.mcfpu_fprs));
120 if (fprs & FPRS_DL)
121 err |= copy_from_user(fpregs,
122 &(ucp->uc_mcontext.mc_fpregs.mcfpu_fregs),
123 (sizeof(unsigned int) * 32));
124 if (fprs & FPRS_DU)
125 err |= copy_from_user(fpregs+16,
126 ((unsigned long __user *)&(ucp->uc_mcontext.mc_fpregs.mcfpu_fregs))+16,
127 (sizeof(unsigned int) * 32));
128 err |= __get_user(current_thread_info()->xfsr[0],
129 &(ucp->uc_mcontext.mc_fpregs.mcfpu_fsr));
130 err |= __get_user(current_thread_info()->gsr[0],
131 &(ucp->uc_mcontext.mc_fpregs.mcfpu_gsr));
132 regs->tstate &= ~TSTATE_PEF;
133 }
134 if (err)
135 goto do_sigsegv;
136
137 return;
138do_sigsegv:
139 force_sig(SIGSEGV, current);
140}
141
142asmlinkage void sparc64_get_context(struct pt_regs *regs)
143{
144 struct ucontext __user *ucp = (struct ucontext __user *)
145 regs->u_regs[UREG_I0];
146 mc_gregset_t __user *grp;
147 mcontext_t __user *mcp;
148 unsigned long fp, i7;
149 unsigned char fenab;
150 int err;
151
152 synchronize_user_stack();
153 if (get_thread_wsaved() || clear_user(ucp, sizeof(*ucp)))
154 goto do_sigsegv;
155
156#if 1
157 fenab = 0; /* IMO get_context is like any other system call, thus modifies FPU state -jj */
158#else
159 fenab = (current_thread_info()->fpsaved[0] & FPRS_FEF);
160#endif
161
162 mcp = &ucp->uc_mcontext;
163 grp = &mcp->mc_gregs;
164
165 /* Skip over the trap instruction, first. */
166 if (test_thread_flag(TIF_32BIT)) {
167 regs->tpc = (regs->tnpc & 0xffffffff);
168 regs->tnpc = (regs->tnpc + 4) & 0xffffffff;
169 } else {
170 regs->tpc = regs->tnpc;
171 regs->tnpc += 4;
172 }
173 err = 0;
174 if (_NSIG_WORDS == 1)
175 err |= __put_user(current->blocked.sig[0],
176 (unsigned long __user *)&ucp->uc_sigmask);
177 else
178 err |= __copy_to_user(&ucp->uc_sigmask, &current->blocked,
179 sizeof(sigset_t));
180
181 err |= __put_user(regs->tstate, &((*grp)[MC_TSTATE]));
182 err |= __put_user(regs->tpc, &((*grp)[MC_PC]));
183 err |= __put_user(regs->tnpc, &((*grp)[MC_NPC]));
184 err |= __put_user(regs->y, &((*grp)[MC_Y]));
185 err |= __put_user(regs->u_regs[UREG_G1], &((*grp)[MC_G1]));
186 err |= __put_user(regs->u_regs[UREG_G2], &((*grp)[MC_G2]));
187 err |= __put_user(regs->u_regs[UREG_G3], &((*grp)[MC_G3]));
188 err |= __put_user(regs->u_regs[UREG_G4], &((*grp)[MC_G4]));
189 err |= __put_user(regs->u_regs[UREG_G5], &((*grp)[MC_G5]));
190 err |= __put_user(regs->u_regs[UREG_G6], &((*grp)[MC_G6]));
191 err |= __put_user(regs->u_regs[UREG_G7], &((*grp)[MC_G7]));
192 err |= __put_user(regs->u_regs[UREG_I0], &((*grp)[MC_O0]));
193 err |= __put_user(regs->u_regs[UREG_I1], &((*grp)[MC_O1]));
194 err |= __put_user(regs->u_regs[UREG_I2], &((*grp)[MC_O2]));
195 err |= __put_user(regs->u_regs[UREG_I3], &((*grp)[MC_O3]));
196 err |= __put_user(regs->u_regs[UREG_I4], &((*grp)[MC_O4]));
197 err |= __put_user(regs->u_regs[UREG_I5], &((*grp)[MC_O5]));
198 err |= __put_user(regs->u_regs[UREG_I6], &((*grp)[MC_O6]));
199 err |= __put_user(regs->u_regs[UREG_I7], &((*grp)[MC_O7]));
200
201 err |= __get_user(fp,
202 (&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[6])));
203 err |= __get_user(i7,
204 (&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[7])));
205 err |= __put_user(fp, &(mcp->mc_fp));
206 err |= __put_user(i7, &(mcp->mc_i7));
207
208 err |= __put_user(fenab, &(mcp->mc_fpregs.mcfpu_enab));
209 if (fenab) {
210 unsigned long *fpregs = current_thread_info()->fpregs;
211 unsigned long fprs;
212
213 fprs = current_thread_info()->fpsaved[0];
214 if (fprs & FPRS_DL)
215 err |= copy_to_user(&(mcp->mc_fpregs.mcfpu_fregs), fpregs,
216 (sizeof(unsigned int) * 32));
217 if (fprs & FPRS_DU)
218 err |= copy_to_user(
219 ((unsigned long __user *)&(mcp->mc_fpregs.mcfpu_fregs))+16, fpregs+16,
220 (sizeof(unsigned int) * 32));
221 err |= __put_user(current_thread_info()->xfsr[0], &(mcp->mc_fpregs.mcfpu_fsr));
222 err |= __put_user(current_thread_info()->gsr[0], &(mcp->mc_fpregs.mcfpu_gsr));
223 err |= __put_user(fprs, &(mcp->mc_fpregs.mcfpu_fprs));
224 }
225 if (err)
226 goto do_sigsegv;
227
228 return;
229do_sigsegv:
230 force_sig(SIGSEGV, current);
231}
232
233struct rt_signal_frame {
234 struct sparc_stackf ss;
235 siginfo_t info;
236 struct pt_regs regs;
237 __siginfo_fpu_t __user *fpu_save;
238 stack_t stack;
239 sigset_t mask;
David S. Miller55984732011-08-20 17:14:54 -0700240 __siginfo_rwin_t *rwin_save;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241};
242
David S. Miller2d7d5f02006-01-19 02:42:49 -0800243static long _sigpause_common(old_sigset_t set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 set &= _BLOCKABLE;
246 spin_lock_irq(&current->sighand->siglock);
David S. Miller2d7d5f02006-01-19 02:42:49 -0800247 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 siginitset(&current->blocked, set);
249 recalc_sigpending();
250 spin_unlock_irq(&current->sighand->siglock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
David S. Miller2d7d5f02006-01-19 02:42:49 -0800252 current->state = TASK_INTERRUPTIBLE;
253 schedule();
David S. Miller9a28dbf2008-05-12 22:45:15 -0700254
255 set_restore_sigmask();
256
David S. Miller2d7d5f02006-01-19 02:42:49 -0800257 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258}
259
David S. Miller2d7d5f02006-01-19 02:42:49 -0800260asmlinkage long sys_sigpause(unsigned int set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
David S. Miller2d7d5f02006-01-19 02:42:49 -0800262 return _sigpause_common(set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
David S. Miller2d7d5f02006-01-19 02:42:49 -0800265asmlinkage long sys_sigsuspend(old_sigset_t set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
David S. Miller2d7d5f02006-01-19 02:42:49 -0800267 return _sigpause_common(set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268}
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270void do_rt_sigreturn(struct pt_regs *regs)
271{
272 struct rt_signal_frame __user *sf;
273 unsigned long tpc, tnpc, tstate;
274 __siginfo_fpu_t __user *fpu_save;
David S. Miller55984732011-08-20 17:14:54 -0700275 __siginfo_rwin_t __user *rwin_save;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 sigset_t set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 int err;
278
279 /* Always make any pending restarted system calls return -EINTR */
280 current_thread_info()->restart_block.fn = do_no_restart_syscall;
281
282 synchronize_user_stack ();
283 sf = (struct rt_signal_frame __user *)
284 (regs->u_regs [UREG_FP] + STACK_BIAS);
285
286 /* 1. Make sure we are not getting garbage from the user */
287 if (((unsigned long) sf) & 3)
288 goto segv;
289
290 err = get_user(tpc, &sf->regs.tpc);
291 err |= __get_user(tnpc, &sf->regs.tnpc);
292 if (test_thread_flag(TIF_32BIT)) {
293 tpc &= 0xffffffff;
294 tnpc &= 0xffffffff;
295 }
296 err |= ((tpc | tnpc) & 3);
297
298 /* 2. Restore the state */
299 err |= __get_user(regs->y, &sf->regs.y);
300 err |= __get_user(tstate, &sf->regs.tstate);
301 err |= copy_from_user(regs->u_regs, sf->regs.u_regs, sizeof(regs->u_regs));
302
303 /* User can only change condition codes and %asi in %tstate. */
304 regs->tstate &= ~(TSTATE_ASI | TSTATE_ICC | TSTATE_XCC);
305 regs->tstate |= (tstate & (TSTATE_ASI | TSTATE_ICC | TSTATE_XCC));
306
307 err |= __get_user(fpu_save, &sf->fpu_save);
David S. Miller55984732011-08-20 17:14:54 -0700308 if (!err && fpu_save)
309 err |= restore_fpu_state(regs, fpu_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
Oleg Nesterov62715ec2007-07-17 14:37:54 -0700312 err |= do_sigaltstack(&sf->stack, NULL, (unsigned long)sf);
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 if (err)
315 goto segv;
Oleg Nesterov62715ec2007-07-17 14:37:54 -0700316
David S. Miller55984732011-08-20 17:14:54 -0700317 err |= __get_user(rwin_save, &sf->rwin_save);
318 if (!err && rwin_save) {
319 if (restore_rwin_state(rwin_save))
320 goto segv;
321 }
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 regs->tpc = tpc;
324 regs->tnpc = tnpc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
David S. Miller2678fef2008-05-01 03:30:22 -0700326 /* Prevent syscall restart. */
David S. Miller28e61032008-05-11 02:07:19 -0700327 pt_regs_clear_syscall(regs);
David S. Miller2678fef2008-05-01 03:30:22 -0700328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 sigdelsetmask(&set, ~_BLOCKABLE);
330 spin_lock_irq(&current->sighand->siglock);
331 current->blocked = set;
332 recalc_sigpending();
333 spin_unlock_irq(&current->sighand->siglock);
334 return;
335segv:
336 force_sig(SIGSEGV, current);
337}
338
339/* Checks if the fp is valid */
David S. Miller55984732011-08-20 17:14:54 -0700340static int invalid_frame_pointer(void __user *fp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
David S. Millerf036d9f2010-02-09 16:18:40 -0800342 if (((unsigned long) fp) & 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 return 1;
344 return 0;
345}
346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347static inline void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, unsigned long framesize)
348{
David S. Millerdc5dc7e2008-05-07 18:54:05 -0700349 unsigned long sp = regs->u_regs[UREG_FP] + STACK_BIAS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
David S. Millerdc5dc7e2008-05-07 18:54:05 -0700351 /*
352 * If we are on the alternate signal stack and would overflow it, don't.
353 * Return an always-bogus address instead so we will die with SIGSEGV.
354 */
355 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
356 return (void __user *) -1L;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 /* This is the X/Open sanctioned signal stack switching. */
359 if (ka->sa.sa_flags & SA_ONSTACK) {
David S. Millerdc5dc7e2008-05-07 18:54:05 -0700360 if (sas_ss_flags(sp) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 sp = current->sas_ss_sp + current->sas_ss_size;
362 }
David S. Millerdc5dc7e2008-05-07 18:54:05 -0700363
David S. Millerf036d9f2010-02-09 16:18:40 -0800364 sp -= framesize;
365
David S. Millerdc5dc7e2008-05-07 18:54:05 -0700366 /* Always align the stack frame. This handles two cases. First,
367 * sigaltstack need not be mindful of platform specific stack
368 * alignment. Second, if we took this signal because the stack
369 * is not aligned properly, we'd like to take the signal cleanly
370 * and report that.
371 */
David S. Millerf036d9f2010-02-09 16:18:40 -0800372 sp &= ~15UL;
David S. Millerdc5dc7e2008-05-07 18:54:05 -0700373
David S. Millerf036d9f2010-02-09 16:18:40 -0800374 return (void __user *) sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375}
376
David S. Miller392c2182010-09-21 21:41:12 -0700377static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
379 int signo, sigset_t *oldset, siginfo_t *info)
380{
381 struct rt_signal_frame __user *sf;
David S. Miller55984732011-08-20 17:14:54 -0700382 int wsaved, err, sf_size;
383 void __user *tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 /* 1. Make sure everything is clean */
386 synchronize_user_stack();
387 save_and_clear_fpu();
388
David S. Miller55984732011-08-20 17:14:54 -0700389 wsaved = get_thread_wsaved();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
David S. Miller55984732011-08-20 17:14:54 -0700391 sf_size = sizeof(struct rt_signal_frame);
392 if (current_thread_info()->fpsaved[0] & FPRS_FEF)
393 sf_size += sizeof(__siginfo_fpu_t);
394 if (wsaved)
395 sf_size += sizeof(__siginfo_rwin_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 sf = (struct rt_signal_frame __user *)
David S. Miller55984732011-08-20 17:14:54 -0700397 get_sigframe(ka, regs, sf_size);
398
399 if (invalid_frame_pointer (sf))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 goto sigill;
401
David S. Miller55984732011-08-20 17:14:54 -0700402 tail = (sf + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 /* 2. Save the current process state */
405 err = copy_to_user(&sf->regs, regs, sizeof (*regs));
406
407 if (current_thread_info()->fpsaved[0] & FPRS_FEF) {
David S. Miller55984732011-08-20 17:14:54 -0700408 __siginfo_fpu_t __user *fpu_save = tail;
409 tail += sizeof(__siginfo_fpu_t);
410 err |= save_fpu_state(regs, fpu_save);
411 err |= __put_user((u64)fpu_save, &sf->fpu_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 } else {
413 err |= __put_user(0, &sf->fpu_save);
414 }
David S. Miller55984732011-08-20 17:14:54 -0700415 if (wsaved) {
416 __siginfo_rwin_t __user *rwin_save = tail;
417 tail += sizeof(__siginfo_rwin_t);
418 err |= save_rwin_state(wsaved, rwin_save);
419 err |= __put_user((u64)rwin_save, &sf->rwin_save);
420 set_thread_wsaved(0);
421 } else {
422 err |= __put_user(0, &sf->rwin_save);
423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 /* Setup sigaltstack */
426 err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
427 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
428 err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
429
430 err |= copy_to_user(&sf->mask, oldset, sizeof(sigset_t));
431
David S. Miller55984732011-08-20 17:14:54 -0700432 if (!wsaved) {
433 err |= copy_in_user((u64 __user *)sf,
434 (u64 __user *)(regs->u_regs[UREG_FP] +
435 STACK_BIAS),
436 sizeof(struct reg_window));
437 } else {
438 struct reg_window *rp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
David S. Miller55984732011-08-20 17:14:54 -0700440 rp = &current_thread_info()->reg_window[wsaved - 1];
441 err |= copy_to_user(sf, rp, sizeof(struct reg_window));
442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 if (info)
444 err |= copy_siginfo_to_user(&sf->info, info);
445 else {
446 err |= __put_user(signo, &sf->info.si_signo);
447 err |= __put_user(SI_NOINFO, &sf->info.si_code);
448 }
449 if (err)
450 goto sigsegv;
451
452 /* 3. signal handler back-trampoline and parameters */
453 regs->u_regs[UREG_FP] = ((unsigned long) sf) - STACK_BIAS;
454 regs->u_regs[UREG_I0] = signo;
455 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
456
457 /* The sigcontext is passed in this way because of how it
458 * is defined in GLIBC's /usr/include/bits/sigcontext.h
459 * for sparc64. It includes the 128 bytes of siginfo_t.
460 */
461 regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
462
463 /* 5. signal handler */
464 regs->tpc = (unsigned long) ka->sa.sa_handler;
465 regs->tnpc = (regs->tpc + 4);
466 if (test_thread_flag(TIF_32BIT)) {
467 regs->tpc &= 0xffffffff;
468 regs->tnpc &= 0xffffffff;
469 }
470 /* 4. return to kernel instructions */
471 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
David S. Miller392c2182010-09-21 21:41:12 -0700472 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474sigill:
475 do_exit(SIGILL);
David S. Miller392c2182010-09-21 21:41:12 -0700476 return -EINVAL;
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478sigsegv:
479 force_sigsegv(signo, current);
David S. Miller392c2182010-09-21 21:41:12 -0700480 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481}
482
David S. Miller392c2182010-09-21 21:41:12 -0700483static inline int handle_signal(unsigned long signr, struct k_sigaction *ka,
484 siginfo_t *info,
485 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
David S. Miller392c2182010-09-21 21:41:12 -0700487 int err;
488
489 err = setup_rt_frame(ka, regs, signr, oldset,
490 (ka->sa.sa_flags & SA_SIGINFO) ? info : NULL);
491 if (err)
492 return err;
Steven Rostedt69be8f12005-08-29 11:44:09 -0400493 spin_lock_irq(&current->sighand->siglock);
494 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
495 if (!(ka->sa.sa_flags & SA_NOMASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 sigaddset(&current->blocked,signr);
Steven Rostedt69be8f12005-08-29 11:44:09 -0400497 recalc_sigpending();
498 spin_unlock_irq(&current->sighand->siglock);
David S. Miller392c2182010-09-21 21:41:12 -0700499
500 tracehook_signal_handler(signr, info, ka, regs, 0);
501
502 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
505static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
David S. Miller28e61032008-05-11 02:07:19 -0700506 struct sigaction *sa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
508 switch (regs->u_regs[UREG_I0]) {
509 case ERESTART_RESTARTBLOCK:
510 case ERESTARTNOHAND:
511 no_system_call_restart:
512 regs->u_regs[UREG_I0] = EINTR;
513 regs->tstate |= (TSTATE_ICARRY|TSTATE_XCARRY);
514 break;
515 case ERESTARTSYS:
516 if (!(sa->sa_flags & SA_RESTART))
517 goto no_system_call_restart;
518 /* fallthrough */
519 case ERESTARTNOINTR:
520 regs->u_regs[UREG_I0] = orig_i0;
521 regs->tpc -= 4;
522 regs->tnpc -= 4;
523 }
524}
525
526/* Note that 'init' is a special process: it doesn't get signals it doesn't
527 * want to handle. Thus you cannot kill init even with a SIGKILL even by
528 * mistake.
529 */
David S. Miller238468b2008-04-24 03:01:48 -0700530static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 struct k_sigaction ka;
David S. Miller28e61032008-05-11 02:07:19 -0700533 int restart_syscall;
David S. Miller2d7d5f02006-01-19 02:42:49 -0800534 sigset_t *oldset;
David S. Miller238468b2008-04-24 03:01:48 -0700535 siginfo_t info;
David S. Miller90888812008-04-27 14:52:51 -0700536 int signr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
David S. Miller2678fef2008-05-01 03:30:22 -0700538 if (pt_regs_is_syscall(regs) &&
539 (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) {
David S. Miller28e61032008-05-11 02:07:19 -0700540 restart_syscall = 1;
David S. Miller238468b2008-04-24 03:01:48 -0700541 } else
David S. Miller28e61032008-05-11 02:07:19 -0700542 restart_syscall = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
David S. Miller9a28dbf2008-05-12 22:45:15 -0700544 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David S. Miller2d7d5f02006-01-19 02:42:49 -0800545 oldset = &current->saved_sigmask;
546 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 oldset = &current->blocked;
548
David S. Miller09337f52008-04-26 03:17:12 -0700549#ifdef CONFIG_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (test_thread_flag(TIF_32BIT)) {
David S. Miller2d7d5f02006-01-19 02:42:49 -0800551 extern void do_signal32(sigset_t *, struct pt_regs *,
David S. Miller28e61032008-05-11 02:07:19 -0700552 int restart_syscall,
553 unsigned long orig_i0);
554 do_signal32(oldset, regs, restart_syscall, orig_i0);
David S. Miller2d7d5f02006-01-19 02:42:49 -0800555 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
557#endif
558
David S. Miller28e61032008-05-11 02:07:19 -0700559 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
560
561 /* If the debugger messes with the program counter, it clears
562 * the software "in syscall" bit, directing us to not perform
563 * a syscall restart.
564 */
565 if (restart_syscall && !pt_regs_is_syscall(regs))
566 restart_syscall = 0;
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 if (signr > 0) {
David S. Miller28e61032008-05-11 02:07:19 -0700569 if (restart_syscall)
570 syscall_restart(orig_i0, regs, &ka.sa);
David S. Miller392c2182010-09-21 21:41:12 -0700571 if (handle_signal(signr, &ka, &info, oldset, regs) == 0) {
572 /* A signal was successfully delivered; the saved
573 * sigmask will have been stored in the signal frame,
574 * and will be restored by sigreturn, so we can simply
575 * clear the TS_RESTORE_SIGMASK flag.
576 */
577 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
578 }
David S. Miller2d7d5f02006-01-19 02:42:49 -0800579 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 }
David S. Miller28e61032008-05-11 02:07:19 -0700581 if (restart_syscall &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
583 regs->u_regs[UREG_I0] == ERESTARTSYS ||
584 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
585 /* replay the system call when we are done */
David S. Miller28e61032008-05-11 02:07:19 -0700586 regs->u_regs[UREG_I0] = orig_i0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 regs->tpc -= 4;
588 regs->tnpc -= 4;
David S. Millerc2785252010-09-21 22:30:13 -0700589 pt_regs_clear_syscall(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
David S. Miller28e61032008-05-11 02:07:19 -0700591 if (restart_syscall &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
593 regs->u_regs[UREG_G1] = __NR_restart_syscall;
594 regs->tpc -= 4;
595 regs->tnpc -= 4;
David S. Millerc2785252010-09-21 22:30:13 -0700596 pt_regs_clear_syscall(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
David S. Miller2d7d5f02006-01-19 02:42:49 -0800598
David S. Miller9a28dbf2008-05-12 22:45:15 -0700599 /* If there's no signal to deliver, we just put the saved sigmask
David S. Miller2d7d5f02006-01-19 02:42:49 -0800600 * back
601 */
David S. Miller9a28dbf2008-05-12 22:45:15 -0700602 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
603 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David S. Miller2d7d5f02006-01-19 02:42:49 -0800604 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
605 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606}
607
David S. Miller7697daa2008-04-24 03:15:22 -0700608void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
David S. Miller9a28dbf2008-05-12 22:45:15 -0700610 if (thread_info_flags & _TIF_SIGPENDING)
David S. Miller238468b2008-04-24 03:01:48 -0700611 do_signal(regs, orig_i0);
Roland McGrathe35a8922008-04-20 15:06:49 -0700612 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
613 clear_thread_flag(TIF_NOTIFY_RESUME);
614 tracehook_notify_resume(regs);
David Howellsee18d642009-09-02 09:14:21 +0100615 if (current->replacement_session_keyring)
616 key_replace_session_keyring();
Roland McGrathe35a8922008-04-20 15:06:49 -0700617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618}
David Howellsee18d642009-09-02 09:14:21 +0100619