blob: c19755815e530c86544f6dfd55c143eb63d02f5f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/kernel/signal.c
3 *
Heiko Carstens54dfe5d2006-02-01 03:06:38 -08004 * Copyright (C) IBM Corp. 1999,2006
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
6 *
7 * Based on Intel version
8 *
9 * Copyright (C) 1991, 1992 Linus Torvalds
10 *
11 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
12 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/sched.h>
15#include <linux/mm.h>
16#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/kernel.h>
18#include <linux/signal.h>
19#include <linux/errno.h>
20#include <linux/wait.h>
21#include <linux/ptrace.h>
22#include <linux/unistd.h>
23#include <linux/stddef.h>
24#include <linux/tty.h>
25#include <linux/personality.h>
26#include <linux/binfmts.h>
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020027#include <linux/tracehook.h>
Heiko Carstens26689452009-01-14 14:14:36 +010028#include <linux/syscalls.h>
Heiko Carstens77575912009-06-12 10:26:25 +020029#include <linux/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/ucontext.h>
31#include <asm/uaccess.h>
32#include <asm/lowcore.h>
Martin Schwidefsky20b40a72011-10-30 15:16:47 +010033#include <asm/compat.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020034#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
37
38
39typedef struct
40{
41 __u8 callee_used_stack[__SIGNAL_FRAMESIZE];
42 struct sigcontext sc;
43 _sigregs sregs;
44 int signo;
45 __u8 retcode[S390_SYSCALL_SIZE];
46} sigframe;
47
48typedef struct
49{
50 __u8 callee_used_stack[__SIGNAL_FRAMESIZE];
51 __u8 retcode[S390_SYSCALL_SIZE];
52 struct siginfo info;
53 struct ucontext uc;
54} rt_sigframe;
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/*
57 * Atomically swap in the new signal mask, and wait for a signal.
58 */
Heiko Carstens26689452009-01-14 14:14:36 +010059SYSCALL_DEFINE3(sigsuspend, int, history0, int, history1, old_sigset_t, mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Heiko Carstens391c62f2011-08-03 16:44:26 +020061 sigset_t blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Heiko Carstens391c62f2011-08-03 16:44:26 +020063 current->saved_sigmask = current->blocked;
64 mask &= _BLOCKABLE;
65 siginitset(&blocked, mask);
66 set_current_blocked(&blocked);
Martin Schwidefsky0b4d7892010-01-27 10:12:37 +010067 set_current_state(TASK_INTERRUPTIBLE);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -080068 schedule();
Heiko Carstens9e8ed3a2011-08-03 16:44:32 +020069 set_restore_sigmask();
Heiko Carstens54dfe5d2006-02-01 03:06:38 -080070 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Heiko Carstens26689452009-01-14 14:14:36 +010073SYSCALL_DEFINE3(sigaction, int, sig, const struct old_sigaction __user *, act,
74 struct old_sigaction __user *, oact)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 struct k_sigaction new_ka, old_ka;
77 int ret;
78
79 if (act) {
80 old_sigset_t mask;
81 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
82 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
Heiko Carstens12bae232006-10-27 12:39:22 +020083 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
84 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
85 __get_user(mask, &act->sa_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 siginitset(&new_ka.sa.sa_mask, mask);
88 }
89
90 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
91
92 if (!ret && oact) {
93 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
94 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
Heiko Carstens12bae232006-10-27 12:39:22 +020095 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
96 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
97 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 }
100
101 return ret;
102}
103
Heiko Carstens26689452009-01-14 14:14:36 +0100104SYSCALL_DEFINE2(sigaltstack, const stack_t __user *, uss,
105 stack_t __user *, uoss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200107 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 return do_sigaltstack(uss, uoss, regs->gprs[15]);
109}
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111/* Returns non-zero on fault. */
112static int save_sigregs(struct pt_regs *regs, _sigregs __user *sregs)
113{
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200114 _sigregs user_sregs;
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 save_access_regs(current->thread.acrs);
117
118 /* Copy a 'clean' PSW mask to the user to avoid leaking
119 information about whether PER is currently on. */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100120 user_sregs.regs.psw.mask = psw_user_bits | PSW_MASK_EA | PSW_MASK_BA |
121 (regs->psw.mask & PSW_MASK_USER);
Martin Schwidefskyb05e3702006-10-04 20:01:58 +0200122 user_sregs.regs.psw.addr = regs->psw.addr;
123 memcpy(&user_sregs.regs.gprs, &regs->gprs, sizeof(sregs->regs.gprs));
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200124 memcpy(&user_sregs.regs.acrs, current->thread.acrs,
125 sizeof(sregs->regs.acrs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 /*
127 * We have to store the fp registers to current->thread.fp_regs
128 * to merge them with the emulated registers.
129 */
130 save_fp_regs(&current->thread.fp_regs);
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200131 memcpy(&user_sregs.fpregs, &current->thread.fp_regs,
132 sizeof(s390_fp_regs));
133 return __copy_to_user(sregs, &user_sregs, sizeof(_sigregs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
136/* Returns positive number on error */
137static int restore_sigregs(struct pt_regs *regs, _sigregs __user *sregs)
138{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 int err;
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200140 _sigregs user_sregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 /* Alwys make any pending restarted system call return -EINTR */
143 current_thread_info()->restart_block.fn = do_no_restart_syscall;
144
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200145 err = __copy_from_user(&user_sregs, sregs, sizeof(_sigregs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 if (err)
147 return err;
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100148 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
149 (user_sregs.regs.psw.mask & PSW_MASK_USER);
Martin Schwidefskyb05e3702006-10-04 20:01:58 +0200150 regs->psw.addr = PSW_ADDR_AMODE | user_sregs.regs.psw.addr;
151 memcpy(&regs->gprs, &user_sregs.regs.gprs, sizeof(sregs->regs.gprs));
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200152 memcpy(&current->thread.acrs, &user_sregs.regs.acrs,
153 sizeof(sregs->regs.acrs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 restore_access_regs(current->thread.acrs);
155
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200156 memcpy(&current->thread.fp_regs, &user_sregs.fpregs,
157 sizeof(s390_fp_regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 current->thread.fp_regs.fpc &= FPC_VALID_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160 restore_fp_regs(&current->thread.fp_regs);
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100161 clear_thread_flag(TIF_SYSCALL); /* No longer in a system call */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 return 0;
163}
164
Heiko Carstens26689452009-01-14 14:14:36 +0100165SYSCALL_DEFINE0(sigreturn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200167 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 sigframe __user *frame = (sigframe __user *)regs->gprs[15];
169 sigset_t set;
170
171 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
172 goto badframe;
173 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE))
174 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 sigdelsetmask(&set, ~_BLOCKABLE);
Heiko Carstens391c62f2011-08-03 16:44:26 +0200176 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 if (restore_sigregs(regs, &frame->sregs))
178 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 return regs->gprs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180badframe:
181 force_sig(SIGSEGV, current);
182 return 0;
183}
184
Heiko Carstens26689452009-01-14 14:14:36 +0100185SYSCALL_DEFINE0(rt_sigreturn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200187 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 rt_sigframe __user *frame = (rt_sigframe __user *)regs->gprs[15];
189 sigset_t set;
190
191 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
192 goto badframe;
193 if (__copy_from_user(&set.sig, &frame->uc.uc_sigmask, sizeof(set)))
194 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 sigdelsetmask(&set, ~_BLOCKABLE);
Heiko Carstens391c62f2011-08-03 16:44:26 +0200196 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 if (restore_sigregs(regs, &frame->uc.uc_mcontext))
198 goto badframe;
Cedric Le Goater4e3df372006-01-06 00:19:10 -0800199 if (do_sigaltstack(&frame->uc.uc_stack, NULL,
200 regs->gprs[15]) == -EFAULT)
201 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return regs->gprs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203badframe:
204 force_sig(SIGSEGV, current);
205 return 0;
206}
207
208/*
209 * Set up a signal frame.
210 */
211
212
213/*
214 * Determine which stack to use..
215 */
216static inline void __user *
217get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
218{
219 unsigned long sp;
220
221 /* Default to using normal stack */
222 sp = regs->gprs[15];
223
Heiko Carstensde553432008-04-17 07:45:57 +0200224 /* Overflow on alternate signal stack gives SIGSEGV. */
225 if (on_sig_stack(sp) && !on_sig_stack((sp - frame_size) & -8UL))
226 return (void __user *) -1UL;
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 /* This is the X/Open sanctioned signal stack switching. */
229 if (ka->sa.sa_flags & SA_ONSTACK) {
230 if (! sas_ss_flags(sp))
231 sp = current->sas_ss_sp + current->sas_ss_size;
232 }
233
234 /* This is the legacy signal stack switching. */
235 else if (!user_mode(regs) &&
236 !(ka->sa.sa_flags & SA_RESTORER) &&
237 ka->sa.sa_restorer) {
238 sp = (unsigned long) ka->sa.sa_restorer;
239 }
240
241 return (void __user *)((sp - frame_size) & -8ul);
242}
243
244static inline int map_signal(int sig)
245{
246 if (current_thread_info()->exec_domain
247 && current_thread_info()->exec_domain->signal_invmap
248 && sig < 32)
249 return current_thread_info()->exec_domain->signal_invmap[sig];
250 else
251 return sig;
252}
253
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800254static int setup_frame(int sig, struct k_sigaction *ka,
255 sigset_t *set, struct pt_regs * regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
257 sigframe __user *frame;
258
259 frame = get_sigframe(ka, regs, sizeof(sigframe));
260 if (!access_ok(VERIFY_WRITE, frame, sizeof(sigframe)))
261 goto give_sigsegv;
262
Heiko Carstensde553432008-04-17 07:45:57 +0200263 if (frame == (void __user *) -1UL)
264 goto give_sigsegv;
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 if (__copy_to_user(&frame->sc.oldmask, &set->sig, _SIGMASK_COPY_SIZE))
267 goto give_sigsegv;
268
269 if (save_sigregs(regs, &frame->sregs))
270 goto give_sigsegv;
271 if (__put_user(&frame->sregs, &frame->sc.sregs))
272 goto give_sigsegv;
273
274 /* Set up to return from userspace. If provided, use a stub
275 already in userspace. */
276 if (ka->sa.sa_flags & SA_RESTORER) {
277 regs->gprs[14] = (unsigned long)
278 ka->sa.sa_restorer | PSW_ADDR_AMODE;
279 } else {
280 regs->gprs[14] = (unsigned long)
281 frame->retcode | PSW_ADDR_AMODE;
282 if (__put_user(S390_SYSCALL_OPCODE | __NR_sigreturn,
283 (u16 __user *)(frame->retcode)))
284 goto give_sigsegv;
285 }
286
287 /* Set up backchain. */
288 if (__put_user(regs->gprs[15], (addr_t __user *) frame))
289 goto give_sigsegv;
290
291 /* Set up registers for signal handler */
292 regs->gprs[15] = (unsigned long) frame;
293 regs->psw.addr = (unsigned long) ka->sa.sa_handler | PSW_ADDR_AMODE;
294
295 regs->gprs[2] = map_signal(sig);
296 regs->gprs[3] = (unsigned long) &frame->sc;
297
298 /* We forgot to include these in the sigcontext.
299 To avoid breaking binary compatibility, they are passed as args. */
300 regs->gprs[4] = current->thread.trap_no;
301 regs->gprs[5] = current->thread.prot_addr;
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200302 regs->gprs[6] = task_thread_info(current)->last_break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 /* Place signal number on stack to allow backtrace from handler. */
305 if (__put_user(regs->gprs[2], (int __user *) &frame->signo))
306 goto give_sigsegv;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800307 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309give_sigsegv:
310 force_sigsegv(sig, current);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800311 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312}
313
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800314static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 sigset_t *set, struct pt_regs * regs)
316{
317 int err = 0;
318 rt_sigframe __user *frame;
319
320 frame = get_sigframe(ka, regs, sizeof(rt_sigframe));
321 if (!access_ok(VERIFY_WRITE, frame, sizeof(rt_sigframe)))
322 goto give_sigsegv;
323
Heiko Carstensde553432008-04-17 07:45:57 +0200324 if (frame == (void __user *) -1UL)
325 goto give_sigsegv;
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 if (copy_siginfo_to_user(&frame->info, info))
328 goto give_sigsegv;
329
330 /* Create the ucontext. */
331 err |= __put_user(0, &frame->uc.uc_flags);
Al Viroc2814472005-09-29 00:16:02 +0100332 err |= __put_user(NULL, &frame->uc.uc_link);
333 err |= __put_user((void __user *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 err |= __put_user(sas_ss_flags(regs->gprs[15]),
335 &frame->uc.uc_stack.ss_flags);
336 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
337 err |= save_sigregs(regs, &frame->uc.uc_mcontext);
338 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
339 if (err)
340 goto give_sigsegv;
341
342 /* Set up to return from userspace. If provided, use a stub
343 already in userspace. */
344 if (ka->sa.sa_flags & SA_RESTORER) {
345 regs->gprs[14] = (unsigned long)
346 ka->sa.sa_restorer | PSW_ADDR_AMODE;
347 } else {
348 regs->gprs[14] = (unsigned long)
349 frame->retcode | PSW_ADDR_AMODE;
Heiko Carstensb44df3342006-05-01 12:16:15 -0700350 if (__put_user(S390_SYSCALL_OPCODE | __NR_rt_sigreturn,
351 (u16 __user *)(frame->retcode)))
352 goto give_sigsegv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
354
355 /* Set up backchain. */
356 if (__put_user(regs->gprs[15], (addr_t __user *) frame))
357 goto give_sigsegv;
358
359 /* Set up registers for signal handler */
360 regs->gprs[15] = (unsigned long) frame;
361 regs->psw.addr = (unsigned long) ka->sa.sa_handler | PSW_ADDR_AMODE;
362
363 regs->gprs[2] = map_signal(sig);
364 regs->gprs[3] = (unsigned long) &frame->info;
365 regs->gprs[4] = (unsigned long) &frame->uc;
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200366 regs->gprs[5] = task_thread_info(current)->last_break;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800367 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369give_sigsegv:
370 force_sigsegv(sig, current);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800371 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
Heiko Carstens391c62f2011-08-03 16:44:26 +0200374static int handle_signal(unsigned long sig, struct k_sigaction *ka,
375 siginfo_t *info, sigset_t *oldset,
376 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Heiko Carstens391c62f2011-08-03 16:44:26 +0200378 sigset_t blocked;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800379 int ret;
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 /* Set up the stack frame */
382 if (ka->sa.sa_flags & SA_SIGINFO)
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800383 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 else
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800385 ret = setup_frame(sig, ka, oldset, regs);
Heiko Carstens391c62f2011-08-03 16:44:26 +0200386 if (ret)
387 return ret;
388 sigorsets(&blocked, &current->blocked, &ka->sa.sa_mask);
389 if (!(ka->sa.sa_flags & SA_NODEFER))
390 sigaddset(&blocked, sig);
391 set_current_blocked(&blocked);
392 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
394
395/*
396 * Note that 'init' is a special process: it doesn't get signals it doesn't
397 * want to handle. Thus you cannot kill init even with a SIGKILL even by
398 * mistake.
399 *
400 * Note that we go through the signals twice: once to check the signals that
401 * the kernel can handle, and then we build all the user-level signal handling
402 * stack-frames in one go after that.
403 */
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800404void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 siginfo_t info;
407 int signr;
408 struct k_sigaction ka;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800409 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 /*
412 * We want the common case to go fast, which
413 * is why we may in certain cases get here from
414 * kernel mode. Just return without doing anything
415 * if so.
416 */
417 if (!user_mode(regs))
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800418 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800420 if (test_thread_flag(TIF_RESTORE_SIGMASK))
421 oldset = &current->saved_sigmask;
422 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 oldset = &current->blocked;
424
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100425 /*
426 * Get signal to deliver. When running under ptrace, at this point
427 * the debugger may change all our registers, including the system
428 * call information.
429 */
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100430 current_thread_info()->system_call =
431 test_thread_flag(TIF_SYSCALL) ? regs->svc_code : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434 if (signr > 0) {
435 /* Whee! Actually deliver the signal. */
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100436 if (current_thread_info()->system_call) {
437 regs->svc_code = current_thread_info()->system_call;
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100438 /* Check for system call restarting. */
439 switch (regs->gprs[2]) {
440 case -ERESTART_RESTARTBLOCK:
441 case -ERESTARTNOHAND:
442 regs->gprs[2] = -EINTR;
443 break;
444 case -ERESTARTSYS:
445 if (!(ka.sa.sa_flags & SA_RESTART)) {
446 regs->gprs[2] = -EINTR;
447 break;
448 }
449 /* fallthrough */
450 case -ERESTARTNOINTR:
451 regs->gprs[2] = regs->orig_gpr2;
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100452 regs->psw.addr =
453 __rewind_psw(regs->psw,
454 regs->svc_code >> 16);
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100455 break;
456 }
457 /* No longer in a system call */
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100458 clear_thread_flag(TIF_SYSCALL);
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100459 }
460
461 if ((is_compat_task() ?
462 handle_signal32(signr, &ka, &info, oldset, regs) :
463 handle_signal(signr, &ka, &info, oldset, regs)) == 0) {
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800464 /*
465 * A signal was successfully delivered; the saved
466 * sigmask will have been stored in the signal frame,
467 * and will be restored by sigreturn, so we can simply
468 * clear the TIF_RESTORE_SIGMASK flag.
469 */
470 if (test_thread_flag(TIF_RESTORE_SIGMASK))
471 clear_thread_flag(TIF_RESTORE_SIGMASK);
Roland McGrath0ac30be2008-01-26 14:11:22 +0100472
473 /*
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200474 * Let tracing know that we've done the handler setup.
475 */
476 tracehook_signal_handler(signr, &info, &ka, regs,
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100477 test_thread_flag(TIF_SINGLE_STEP));
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800478 }
479 return;
480 }
481
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100482 /* No handlers present - check for system call restart */
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100483 if (current_thread_info()->system_call) {
484 regs->svc_code = current_thread_info()->system_call;
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100485 switch (regs->gprs[2]) {
486 case -ERESTART_RESTARTBLOCK:
487 /* Restart with sys_restart_syscall */
488 regs->svc_code = __NR_restart_syscall;
489 /* fallthrough */
490 case -ERESTARTNOHAND:
491 case -ERESTARTSYS:
492 case -ERESTARTNOINTR:
493 /* Restart system call with magic TIF bit. */
494 regs->gprs[2] = regs->orig_gpr2;
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100495 set_thread_flag(TIF_SYSCALL);
496 break;
497 default:
498 clear_thread_flag(TIF_SYSCALL);
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100499 break;
500 }
501 }
502
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800503 /*
504 * If there's no signal to deliver, we just put the saved sigmask back.
505 */
506 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
507 clear_thread_flag(TIF_RESTORE_SIGMASK);
508 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510}
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200511
512void do_notify_resume(struct pt_regs *regs)
513{
514 clear_thread_flag(TIF_NOTIFY_RESUME);
515 tracehook_notify_resume(regs);
David Howellsee18d642009-09-02 09:14:21 +0100516 if (current->replacement_session_keyring)
517 key_replace_session_keyring();
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200518}