blob: c13a2a37ef007b2634a508b7053b0c3cc12e30b2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02002 * Copyright IBM Corp. 1999, 2006
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
4 *
5 * Based on Intel version
6 *
7 * Copyright (C) 1991, 1992 Linus Torvalds
8 *
9 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/sched.h>
13#include <linux/mm.h>
14#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/kernel.h>
16#include <linux/signal.h>
17#include <linux/errno.h>
18#include <linux/wait.h>
19#include <linux/ptrace.h>
20#include <linux/unistd.h>
21#include <linux/stddef.h>
22#include <linux/tty.h>
23#include <linux/personality.h>
24#include <linux/binfmts.h>
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +020025#include <linux/tracehook.h>
Heiko Carstens26689452009-01-14 14:14:36 +010026#include <linux/syscalls.h>
Heiko Carstens77575912009-06-12 10:26:25 +020027#include <linux/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/ucontext.h>
29#include <asm/uaccess.h>
30#include <asm/lowcore.h>
David Howellsa0616cd2012-03-28 18:30:02 +010031#include <asm/switch_to.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020032#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034typedef struct
35{
36 __u8 callee_used_stack[__SIGNAL_FRAMESIZE];
37 struct sigcontext sc;
38 _sigregs sregs;
39 int signo;
40 __u8 retcode[S390_SYSCALL_SIZE];
41} sigframe;
42
43typedef struct
44{
45 __u8 callee_used_stack[__SIGNAL_FRAMESIZE];
46 __u8 retcode[S390_SYSCALL_SIZE];
47 struct siginfo info;
48 struct ucontext uc;
49} rt_sigframe;
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/*
52 * Atomically swap in the new signal mask, and wait for a signal.
53 */
Heiko Carstens26689452009-01-14 14:14:36 +010054SYSCALL_DEFINE3(sigsuspend, int, history0, int, history1, old_sigset_t, mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Heiko Carstens391c62f2011-08-03 16:44:26 +020056 sigset_t blocked;
Heiko Carstens391c62f2011-08-03 16:44:26 +020057 siginitset(&blocked, mask);
Al Viro68f3f162012-05-21 21:42:32 -040058 return sigsuspend(&blocked);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
Heiko Carstens26689452009-01-14 14:14:36 +010061SYSCALL_DEFINE3(sigaction, int, sig, const struct old_sigaction __user *, act,
62 struct old_sigaction __user *, oact)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 struct k_sigaction new_ka, old_ka;
65 int ret;
66
67 if (act) {
68 old_sigset_t mask;
69 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
70 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
Heiko Carstens12bae232006-10-27 12:39:22 +020071 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
72 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
73 __get_user(mask, &act->sa_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 siginitset(&new_ka.sa.sa_mask, mask);
76 }
77
78 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
79
80 if (!ret && oact) {
81 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
82 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
Heiko Carstens12bae232006-10-27 12:39:22 +020083 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
84 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
85 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88
89 return ret;
90}
91
Heiko Carstens26689452009-01-14 14:14:36 +010092SYSCALL_DEFINE2(sigaltstack, const stack_t __user *, uss,
93 stack_t __user *, uoss)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +020095 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return do_sigaltstack(uss, uoss, regs->gprs[15]);
97}
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* Returns non-zero on fault. */
100static int save_sigregs(struct pt_regs *regs, _sigregs __user *sregs)
101{
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200102 _sigregs user_sregs;
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 save_access_regs(current->thread.acrs);
105
106 /* Copy a 'clean' PSW mask to the user to avoid leaking
107 information about whether PER is currently on. */
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100108 user_sregs.regs.psw.mask = psw_user_bits |
109 (regs->psw.mask & PSW_MASK_USER);
Martin Schwidefskyb05e3702006-10-04 20:01:58 +0200110 user_sregs.regs.psw.addr = regs->psw.addr;
111 memcpy(&user_sregs.regs.gprs, &regs->gprs, sizeof(sregs->regs.gprs));
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200112 memcpy(&user_sregs.regs.acrs, current->thread.acrs,
113 sizeof(sregs->regs.acrs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 /*
115 * We have to store the fp registers to current->thread.fp_regs
116 * to merge them with the emulated registers.
117 */
118 save_fp_regs(&current->thread.fp_regs);
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200119 memcpy(&user_sregs.fpregs, &current->thread.fp_regs,
120 sizeof(s390_fp_regs));
121 return __copy_to_user(sregs, &user_sregs, sizeof(_sigregs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
124/* Returns positive number on error */
125static int restore_sigregs(struct pt_regs *regs, _sigregs __user *sregs)
126{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 int err;
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200128 _sigregs user_sregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 /* Alwys make any pending restarted system call return -EINTR */
131 current_thread_info()->restart_block.fn = do_no_restart_syscall;
132
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200133 err = __copy_from_user(&user_sregs, sregs, sizeof(_sigregs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 if (err)
135 return err;
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100136 /* Use regs->psw.mask instead of psw_user_bits to preserve PER bit. */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100137 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100138 (user_sregs.regs.psw.mask & PSW_MASK_USER);
139 /* Check for invalid amode */
140 if (regs->psw.mask & PSW_MASK_EA)
141 regs->psw.mask |= PSW_MASK_BA;
142 regs->psw.addr = user_sregs.regs.psw.addr;
Martin Schwidefskyb05e3702006-10-04 20:01:58 +0200143 memcpy(&regs->gprs, &user_sregs.regs.gprs, sizeof(sregs->regs.gprs));
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200144 memcpy(&current->thread.acrs, &user_sregs.regs.acrs,
145 sizeof(sregs->regs.acrs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 restore_access_regs(current->thread.acrs);
147
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200148 memcpy(&current->thread.fp_regs, &user_sregs.fpregs,
149 sizeof(s390_fp_regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 current->thread.fp_regs.fpc &= FPC_VALID_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 restore_fp_regs(&current->thread.fp_regs);
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100153 clear_thread_flag(TIF_SYSCALL); /* No longer in a system call */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return 0;
155}
156
Heiko Carstens26689452009-01-14 14:14:36 +0100157SYSCALL_DEFINE0(sigreturn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200159 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 sigframe __user *frame = (sigframe __user *)regs->gprs[15];
161 sigset_t set;
162
163 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
164 goto badframe;
165 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE))
166 goto badframe;
Heiko Carstens391c62f2011-08-03 16:44:26 +0200167 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 if (restore_sigregs(regs, &frame->sregs))
169 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return regs->gprs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171badframe:
172 force_sig(SIGSEGV, current);
173 return 0;
174}
175
Heiko Carstens26689452009-01-14 14:14:36 +0100176SYSCALL_DEFINE0(rt_sigreturn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200178 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 rt_sigframe __user *frame = (rt_sigframe __user *)regs->gprs[15];
180 sigset_t set;
181
182 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
183 goto badframe;
184 if (__copy_from_user(&set.sig, &frame->uc.uc_sigmask, sizeof(set)))
185 goto badframe;
Heiko Carstens391c62f2011-08-03 16:44:26 +0200186 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 if (restore_sigregs(regs, &frame->uc.uc_mcontext))
188 goto badframe;
Cedric Le Goater4e3df372006-01-06 00:19:10 -0800189 if (do_sigaltstack(&frame->uc.uc_stack, NULL,
190 regs->gprs[15]) == -EFAULT)
191 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return regs->gprs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193badframe:
194 force_sig(SIGSEGV, current);
195 return 0;
196}
197
198/*
199 * Set up a signal frame.
200 */
201
202
203/*
204 * Determine which stack to use..
205 */
206static inline void __user *
207get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
208{
209 unsigned long sp;
210
211 /* Default to using normal stack */
212 sp = regs->gprs[15];
213
Heiko Carstensde553432008-04-17 07:45:57 +0200214 /* Overflow on alternate signal stack gives SIGSEGV. */
215 if (on_sig_stack(sp) && !on_sig_stack((sp - frame_size) & -8UL))
216 return (void __user *) -1UL;
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 /* This is the X/Open sanctioned signal stack switching. */
219 if (ka->sa.sa_flags & SA_ONSTACK) {
220 if (! sas_ss_flags(sp))
221 sp = current->sas_ss_sp + current->sas_ss_size;
222 }
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 return (void __user *)((sp - frame_size) & -8ul);
225}
226
227static inline int map_signal(int sig)
228{
229 if (current_thread_info()->exec_domain
230 && current_thread_info()->exec_domain->signal_invmap
231 && sig < 32)
232 return current_thread_info()->exec_domain->signal_invmap[sig];
233 else
234 return sig;
235}
236
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800237static int setup_frame(int sig, struct k_sigaction *ka,
238 sigset_t *set, struct pt_regs * regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
240 sigframe __user *frame;
241
242 frame = get_sigframe(ka, regs, sizeof(sigframe));
243 if (!access_ok(VERIFY_WRITE, frame, sizeof(sigframe)))
244 goto give_sigsegv;
245
Heiko Carstensde553432008-04-17 07:45:57 +0200246 if (frame == (void __user *) -1UL)
247 goto give_sigsegv;
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (__copy_to_user(&frame->sc.oldmask, &set->sig, _SIGMASK_COPY_SIZE))
250 goto give_sigsegv;
251
252 if (save_sigregs(regs, &frame->sregs))
253 goto give_sigsegv;
254 if (__put_user(&frame->sregs, &frame->sc.sregs))
255 goto give_sigsegv;
256
257 /* Set up to return from userspace. If provided, use a stub
258 already in userspace. */
259 if (ka->sa.sa_flags & SA_RESTORER) {
260 regs->gprs[14] = (unsigned long)
261 ka->sa.sa_restorer | PSW_ADDR_AMODE;
262 } else {
263 regs->gprs[14] = (unsigned long)
264 frame->retcode | PSW_ADDR_AMODE;
265 if (__put_user(S390_SYSCALL_OPCODE | __NR_sigreturn,
266 (u16 __user *)(frame->retcode)))
267 goto give_sigsegv;
268 }
269
270 /* Set up backchain. */
271 if (__put_user(regs->gprs[15], (addr_t __user *) frame))
272 goto give_sigsegv;
273
274 /* Set up registers for signal handler */
275 regs->gprs[15] = (unsigned long) frame;
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100276 regs->psw.mask |= PSW_MASK_EA | PSW_MASK_BA; /* 64 bit amode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 regs->psw.addr = (unsigned long) ka->sa.sa_handler | PSW_ADDR_AMODE;
278
279 regs->gprs[2] = map_signal(sig);
280 regs->gprs[3] = (unsigned long) &frame->sc;
281
282 /* We forgot to include these in the sigcontext.
283 To avoid breaking binary compatibility, they are passed as args. */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100284 if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL ||
285 sig == SIGTRAP || sig == SIGFPE) {
286 /* set extra registers only for synchronous signals */
287 regs->gprs[4] = regs->int_code & 127;
288 regs->gprs[5] = regs->int_parm_long;
289 regs->gprs[6] = task_thread_info(current)->last_break;
290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 /* Place signal number on stack to allow backtrace from handler. */
293 if (__put_user(regs->gprs[2], (int __user *) &frame->signo))
294 goto give_sigsegv;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800295 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297give_sigsegv:
298 force_sigsegv(sig, current);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800299 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300}
301
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800302static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 sigset_t *set, struct pt_regs * regs)
304{
305 int err = 0;
306 rt_sigframe __user *frame;
307
308 frame = get_sigframe(ka, regs, sizeof(rt_sigframe));
309 if (!access_ok(VERIFY_WRITE, frame, sizeof(rt_sigframe)))
310 goto give_sigsegv;
311
Heiko Carstensde553432008-04-17 07:45:57 +0200312 if (frame == (void __user *) -1UL)
313 goto give_sigsegv;
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 if (copy_siginfo_to_user(&frame->info, info))
316 goto give_sigsegv;
317
318 /* Create the ucontext. */
319 err |= __put_user(0, &frame->uc.uc_flags);
Al Viroc2814472005-09-29 00:16:02 +0100320 err |= __put_user(NULL, &frame->uc.uc_link);
321 err |= __put_user((void __user *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 err |= __put_user(sas_ss_flags(regs->gprs[15]),
323 &frame->uc.uc_stack.ss_flags);
324 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
325 err |= save_sigregs(regs, &frame->uc.uc_mcontext);
326 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
327 if (err)
328 goto give_sigsegv;
329
330 /* Set up to return from userspace. If provided, use a stub
331 already in userspace. */
332 if (ka->sa.sa_flags & SA_RESTORER) {
333 regs->gprs[14] = (unsigned long)
334 ka->sa.sa_restorer | PSW_ADDR_AMODE;
335 } else {
336 regs->gprs[14] = (unsigned long)
337 frame->retcode | PSW_ADDR_AMODE;
Heiko Carstensb44df3342006-05-01 12:16:15 -0700338 if (__put_user(S390_SYSCALL_OPCODE | __NR_rt_sigreturn,
339 (u16 __user *)(frame->retcode)))
340 goto give_sigsegv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342
343 /* Set up backchain. */
344 if (__put_user(regs->gprs[15], (addr_t __user *) frame))
345 goto give_sigsegv;
346
347 /* Set up registers for signal handler */
348 regs->gprs[15] = (unsigned long) frame;
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100349 regs->psw.mask |= PSW_MASK_EA | PSW_MASK_BA; /* 64 bit amode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 regs->psw.addr = (unsigned long) ka->sa.sa_handler | PSW_ADDR_AMODE;
351
352 regs->gprs[2] = map_signal(sig);
353 regs->gprs[3] = (unsigned long) &frame->info;
354 regs->gprs[4] = (unsigned long) &frame->uc;
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200355 regs->gprs[5] = task_thread_info(current)->last_break;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800356 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358give_sigsegv:
359 force_sigsegv(sig, current);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800360 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361}
362
Al Viroa610d6e2012-05-21 23:42:15 -0400363static void handle_signal(unsigned long sig, struct k_sigaction *ka,
Heiko Carstens391c62f2011-08-03 16:44:26 +0200364 siginfo_t *info, sigset_t *oldset,
365 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800367 int ret;
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 /* Set up the stack frame */
370 if (ka->sa.sa_flags & SA_SIGINFO)
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800371 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 else
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800373 ret = setup_frame(sig, ka, oldset, regs);
Heiko Carstens391c62f2011-08-03 16:44:26 +0200374 if (ret)
Al Viroa610d6e2012-05-21 23:42:15 -0400375 return;
Al Viroefee9842012-04-28 02:04:15 -0400376 signal_delivered(sig, info, ka, regs,
Al Viroa610d6e2012-05-21 23:42:15 -0400377 test_thread_flag(TIF_SINGLE_STEP));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
380/*
381 * Note that 'init' is a special process: it doesn't get signals it doesn't
382 * want to handle. Thus you cannot kill init even with a SIGKILL even by
383 * mistake.
384 *
385 * Note that we go through the signals twice: once to check the signals that
386 * the kernel can handle, and then we build all the user-level signal handling
387 * stack-frames in one go after that.
388 */
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800389void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 siginfo_t info;
392 int signr;
393 struct k_sigaction ka;
Al Virob7f9a112012-05-02 09:59:21 -0400394 sigset_t *oldset = sigmask_to_save();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100396 /*
397 * Get signal to deliver. When running under ptrace, at this point
398 * the debugger may change all our registers, including the system
399 * call information.
400 */
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100401 current_thread_info()->system_call =
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100402 test_thread_flag(TIF_SYSCALL) ? regs->int_code : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 if (signr > 0) {
406 /* Whee! Actually deliver the signal. */
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100407 if (current_thread_info()->system_call) {
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100408 regs->int_code = current_thread_info()->system_call;
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100409 /* Check for system call restarting. */
410 switch (regs->gprs[2]) {
411 case -ERESTART_RESTARTBLOCK:
412 case -ERESTARTNOHAND:
413 regs->gprs[2] = -EINTR;
414 break;
415 case -ERESTARTSYS:
416 if (!(ka.sa.sa_flags & SA_RESTART)) {
417 regs->gprs[2] = -EINTR;
418 break;
419 }
420 /* fallthrough */
421 case -ERESTARTNOINTR:
422 regs->gprs[2] = regs->orig_gpr2;
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100423 regs->psw.addr =
424 __rewind_psw(regs->psw,
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100425 regs->int_code >> 16);
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100426 break;
427 }
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100428 }
Martin Schwidefskyd9ae6772011-12-01 13:32:15 +0100429 /* No longer in a system call */
430 clear_thread_flag(TIF_SYSCALL);
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100431
Al Viroa610d6e2012-05-21 23:42:15 -0400432 if (is_compat_task())
433 handle_signal32(signr, &ka, &info, oldset, regs);
434 else
435 handle_signal(signr, &ka, &info, oldset, regs);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800436 return;
437 }
438
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100439 /* No handlers present - check for system call restart */
Martin Schwidefskyd9ae6772011-12-01 13:32:15 +0100440 clear_thread_flag(TIF_SYSCALL);
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100441 if (current_thread_info()->system_call) {
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100442 regs->int_code = current_thread_info()->system_call;
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100443 switch (regs->gprs[2]) {
444 case -ERESTART_RESTARTBLOCK:
445 /* Restart with sys_restart_syscall */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100446 regs->int_code = __NR_restart_syscall;
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100447 /* fallthrough */
448 case -ERESTARTNOHAND:
449 case -ERESTARTSYS:
450 case -ERESTARTNOINTR:
451 /* Restart system call with magic TIF bit. */
452 regs->gprs[2] = regs->orig_gpr2;
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100453 set_thread_flag(TIF_SYSCALL);
454 break;
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100455 }
456 }
457
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800458 /*
459 * If there's no signal to deliver, we just put the saved sigmask back.
460 */
Al Viro51a7b442012-05-21 23:33:55 -0400461 restore_saved_sigmask();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200463
464void do_notify_resume(struct pt_regs *regs)
465{
466 clear_thread_flag(TIF_NOTIFY_RESUME);
467 tracehook_notify_resume(regs);
468}