blob: fda41480b0bdeba4a943cc9de9fb74809c678b2f [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070092/* Returns non-zero on fault. */
93static int save_sigregs(struct pt_regs *regs, _sigregs __user *sregs)
94{
Gerald Schaefer6837a8c2006-09-20 15:59:39 +020095 _sigregs user_sregs;
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 save_access_regs(current->thread.acrs);
98
99 /* Copy a 'clean' PSW mask to the user to avoid leaking
100 information about whether PER is currently on. */
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100101 user_sregs.regs.psw.mask = psw_user_bits |
102 (regs->psw.mask & PSW_MASK_USER);
Martin Schwidefskyb05e3702006-10-04 20:01:58 +0200103 user_sregs.regs.psw.addr = regs->psw.addr;
104 memcpy(&user_sregs.regs.gprs, &regs->gprs, sizeof(sregs->regs.gprs));
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200105 memcpy(&user_sregs.regs.acrs, current->thread.acrs,
106 sizeof(sregs->regs.acrs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 /*
108 * We have to store the fp registers to current->thread.fp_regs
109 * to merge them with the emulated registers.
110 */
111 save_fp_regs(&current->thread.fp_regs);
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200112 memcpy(&user_sregs.fpregs, &current->thread.fp_regs,
113 sizeof(s390_fp_regs));
114 return __copy_to_user(sregs, &user_sregs, sizeof(_sigregs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115}
116
117/* Returns positive number on error */
118static int restore_sigregs(struct pt_regs *regs, _sigregs __user *sregs)
119{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 int err;
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200121 _sigregs user_sregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123 /* Alwys make any pending restarted system call return -EINTR */
124 current_thread_info()->restart_block.fn = do_no_restart_syscall;
125
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200126 err = __copy_from_user(&user_sregs, sregs, sizeof(_sigregs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 if (err)
128 return err;
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100129 /* Use regs->psw.mask instead of psw_user_bits to preserve PER bit. */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100130 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100131 (user_sregs.regs.psw.mask & PSW_MASK_USER);
Martin Schwidefskyfa968ee2012-11-07 10:44:08 +0100132 /* Check for invalid user address space control. */
133 if ((regs->psw.mask & PSW_MASK_ASC) >= (psw_kernel_bits & PSW_MASK_ASC))
134 regs->psw.mask = (psw_user_bits & PSW_MASK_ASC) |
135 (regs->psw.mask & ~PSW_MASK_ASC);
Martin Schwidefskyd4e81b32011-10-30 15:16:51 +0100136 /* Check for invalid amode */
137 if (regs->psw.mask & PSW_MASK_EA)
138 regs->psw.mask |= PSW_MASK_BA;
139 regs->psw.addr = user_sregs.regs.psw.addr;
Martin Schwidefskyb05e3702006-10-04 20:01:58 +0200140 memcpy(&regs->gprs, &user_sregs.regs.gprs, sizeof(sregs->regs.gprs));
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200141 memcpy(&current->thread.acrs, &user_sregs.regs.acrs,
142 sizeof(sregs->regs.acrs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 restore_access_regs(current->thread.acrs);
144
Gerald Schaefer6837a8c2006-09-20 15:59:39 +0200145 memcpy(&current->thread.fp_regs, &user_sregs.fpregs,
146 sizeof(s390_fp_regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 current->thread.fp_regs.fpc &= FPC_VALID_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 restore_fp_regs(&current->thread.fp_regs);
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100150 clear_thread_flag(TIF_SYSCALL); /* No longer in a system call */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 return 0;
152}
153
Heiko Carstens26689452009-01-14 14:14:36 +0100154SYSCALL_DEFINE0(sigreturn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200156 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 sigframe __user *frame = (sigframe __user *)regs->gprs[15];
158 sigset_t set;
159
160 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
161 goto badframe;
162 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE))
163 goto badframe;
Heiko Carstens391c62f2011-08-03 16:44:26 +0200164 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 if (restore_sigregs(regs, &frame->sregs))
166 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 return regs->gprs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168badframe:
169 force_sig(SIGSEGV, current);
170 return 0;
171}
172
Heiko Carstens26689452009-01-14 14:14:36 +0100173SYSCALL_DEFINE0(rt_sigreturn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Martin Schwidefsky03ff9a22007-04-27 16:01:40 +0200175 struct pt_regs *regs = task_pt_regs(current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 rt_sigframe __user *frame = (rt_sigframe __user *)regs->gprs[15];
177 sigset_t set;
178
179 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
180 goto badframe;
181 if (__copy_from_user(&set.sig, &frame->uc.uc_sigmask, sizeof(set)))
182 goto badframe;
Heiko Carstens391c62f2011-08-03 16:44:26 +0200183 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 if (restore_sigregs(regs, &frame->uc.uc_mcontext))
185 goto badframe;
Al Viroe2141252012-12-23 03:36:41 -0500186 if (restore_altstack(&frame->uc.uc_stack))
Cedric Le Goater4e3df372006-01-06 00:19:10 -0800187 goto badframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 return regs->gprs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189badframe:
190 force_sig(SIGSEGV, current);
191 return 0;
192}
193
194/*
195 * Set up a signal frame.
196 */
197
198
199/*
200 * Determine which stack to use..
201 */
202static inline void __user *
203get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
204{
205 unsigned long sp;
206
207 /* Default to using normal stack */
208 sp = regs->gprs[15];
209
Heiko Carstensde553432008-04-17 07:45:57 +0200210 /* Overflow on alternate signal stack gives SIGSEGV. */
211 if (on_sig_stack(sp) && !on_sig_stack((sp - frame_size) & -8UL))
212 return (void __user *) -1UL;
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 /* This is the X/Open sanctioned signal stack switching. */
215 if (ka->sa.sa_flags & SA_ONSTACK) {
216 if (! sas_ss_flags(sp))
217 sp = current->sas_ss_sp + current->sas_ss_size;
218 }
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return (void __user *)((sp - frame_size) & -8ul);
221}
222
223static inline int map_signal(int sig)
224{
225 if (current_thread_info()->exec_domain
226 && current_thread_info()->exec_domain->signal_invmap
227 && sig < 32)
228 return current_thread_info()->exec_domain->signal_invmap[sig];
229 else
230 return sig;
231}
232
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800233static int setup_frame(int sig, struct k_sigaction *ka,
234 sigset_t *set, struct pt_regs * regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
236 sigframe __user *frame;
237
238 frame = get_sigframe(ka, regs, sizeof(sigframe));
239 if (!access_ok(VERIFY_WRITE, frame, sizeof(sigframe)))
240 goto give_sigsegv;
241
Heiko Carstensde553432008-04-17 07:45:57 +0200242 if (frame == (void __user *) -1UL)
243 goto give_sigsegv;
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 if (__copy_to_user(&frame->sc.oldmask, &set->sig, _SIGMASK_COPY_SIZE))
246 goto give_sigsegv;
247
248 if (save_sigregs(regs, &frame->sregs))
249 goto give_sigsegv;
250 if (__put_user(&frame->sregs, &frame->sc.sregs))
251 goto give_sigsegv;
252
253 /* Set up to return from userspace. If provided, use a stub
254 already in userspace. */
255 if (ka->sa.sa_flags & SA_RESTORER) {
256 regs->gprs[14] = (unsigned long)
257 ka->sa.sa_restorer | PSW_ADDR_AMODE;
258 } else {
259 regs->gprs[14] = (unsigned long)
260 frame->retcode | PSW_ADDR_AMODE;
261 if (__put_user(S390_SYSCALL_OPCODE | __NR_sigreturn,
262 (u16 __user *)(frame->retcode)))
263 goto give_sigsegv;
264 }
265
266 /* Set up backchain. */
267 if (__put_user(regs->gprs[15], (addr_t __user *) frame))
268 goto give_sigsegv;
269
270 /* Set up registers for signal handler */
271 regs->gprs[15] = (unsigned long) frame;
Martin Schwidefskyfa968ee2012-11-07 10:44:08 +0100272 /* Force default amode and default user address space control. */
273 regs->psw.mask = PSW_MASK_EA | PSW_MASK_BA |
274 (psw_user_bits & PSW_MASK_ASC) |
275 (regs->psw.mask & ~PSW_MASK_ASC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 regs->psw.addr = (unsigned long) ka->sa.sa_handler | PSW_ADDR_AMODE;
277
278 regs->gprs[2] = map_signal(sig);
279 regs->gprs[3] = (unsigned long) &frame->sc;
280
281 /* We forgot to include these in the sigcontext.
282 To avoid breaking binary compatibility, they are passed as args. */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100283 if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL ||
284 sig == SIGTRAP || sig == SIGFPE) {
285 /* set extra registers only for synchronous signals */
286 regs->gprs[4] = regs->int_code & 127;
287 regs->gprs[5] = regs->int_parm_long;
288 regs->gprs[6] = task_thread_info(current)->last_break;
289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 /* Place signal number on stack to allow backtrace from handler. */
292 if (__put_user(regs->gprs[2], (int __user *) &frame->signo))
293 goto give_sigsegv;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800294 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296give_sigsegv:
297 force_sigsegv(sig, current);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800298 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800301static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 sigset_t *set, struct pt_regs * regs)
303{
304 int err = 0;
305 rt_sigframe __user *frame;
306
307 frame = get_sigframe(ka, regs, sizeof(rt_sigframe));
308 if (!access_ok(VERIFY_WRITE, frame, sizeof(rt_sigframe)))
309 goto give_sigsegv;
310
Heiko Carstensde553432008-04-17 07:45:57 +0200311 if (frame == (void __user *) -1UL)
312 goto give_sigsegv;
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 if (copy_siginfo_to_user(&frame->info, info))
315 goto give_sigsegv;
316
317 /* Create the ucontext. */
318 err |= __put_user(0, &frame->uc.uc_flags);
Al Viroc2814472005-09-29 00:16:02 +0100319 err |= __put_user(NULL, &frame->uc.uc_link);
Al Viroe2141252012-12-23 03:36:41 -0500320 err |= __save_altstack(&frame->uc.uc_stack, regs->gprs[15]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 err |= save_sigregs(regs, &frame->uc.uc_mcontext);
322 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
323 if (err)
324 goto give_sigsegv;
325
326 /* Set up to return from userspace. If provided, use a stub
327 already in userspace. */
328 if (ka->sa.sa_flags & SA_RESTORER) {
329 regs->gprs[14] = (unsigned long)
330 ka->sa.sa_restorer | PSW_ADDR_AMODE;
331 } else {
332 regs->gprs[14] = (unsigned long)
333 frame->retcode | PSW_ADDR_AMODE;
Heiko Carstensb44df3342006-05-01 12:16:15 -0700334 if (__put_user(S390_SYSCALL_OPCODE | __NR_rt_sigreturn,
335 (u16 __user *)(frame->retcode)))
336 goto give_sigsegv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 }
338
339 /* Set up backchain. */
340 if (__put_user(regs->gprs[15], (addr_t __user *) frame))
341 goto give_sigsegv;
342
343 /* Set up registers for signal handler */
344 regs->gprs[15] = (unsigned long) frame;
Martin Schwidefskyfa968ee2012-11-07 10:44:08 +0100345 /* Force default amode and default user address space control. */
346 regs->psw.mask = PSW_MASK_EA | PSW_MASK_BA |
347 (psw_user_bits & PSW_MASK_ASC) |
348 (regs->psw.mask & ~PSW_MASK_ASC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 regs->psw.addr = (unsigned long) ka->sa.sa_handler | PSW_ADDR_AMODE;
350
351 regs->gprs[2] = map_signal(sig);
352 regs->gprs[3] = (unsigned long) &frame->info;
353 regs->gprs[4] = (unsigned long) &frame->uc;
Martin Schwidefsky86f25522010-05-17 10:00:05 +0200354 regs->gprs[5] = task_thread_info(current)->last_break;
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800355 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357give_sigsegv:
358 force_sigsegv(sig, current);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800359 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
361
Al Viroa610d6e2012-05-21 23:42:15 -0400362static void handle_signal(unsigned long sig, struct k_sigaction *ka,
Heiko Carstens391c62f2011-08-03 16:44:26 +0200363 siginfo_t *info, sigset_t *oldset,
364 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800366 int ret;
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /* Set up the stack frame */
369 if (ka->sa.sa_flags & SA_SIGINFO)
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800370 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 else
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800372 ret = setup_frame(sig, ka, oldset, regs);
Heiko Carstens391c62f2011-08-03 16:44:26 +0200373 if (ret)
Al Viroa610d6e2012-05-21 23:42:15 -0400374 return;
Al Viroefee9842012-04-28 02:04:15 -0400375 signal_delivered(sig, info, ka, regs,
Al Viroa610d6e2012-05-21 23:42:15 -0400376 test_thread_flag(TIF_SINGLE_STEP));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377}
378
379/*
380 * Note that 'init' is a special process: it doesn't get signals it doesn't
381 * want to handle. Thus you cannot kill init even with a SIGKILL even by
382 * mistake.
383 *
384 * Note that we go through the signals twice: once to check the signals that
385 * the kernel can handle, and then we build all the user-level signal handling
386 * stack-frames in one go after that.
387 */
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800388void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 siginfo_t info;
391 int signr;
392 struct k_sigaction ka;
Al Virob7f9a112012-05-02 09:59:21 -0400393 sigset_t *oldset = sigmask_to_save();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100395 /*
396 * Get signal to deliver. When running under ptrace, at this point
397 * the debugger may change all our registers, including the system
398 * call information.
399 */
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100400 current_thread_info()->system_call =
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100401 test_thread_flag(TIF_SYSCALL) ? regs->int_code : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 if (signr > 0) {
405 /* Whee! Actually deliver the signal. */
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100406 if (current_thread_info()->system_call) {
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100407 regs->int_code = current_thread_info()->system_call;
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100408 /* Check for system call restarting. */
409 switch (regs->gprs[2]) {
410 case -ERESTART_RESTARTBLOCK:
411 case -ERESTARTNOHAND:
412 regs->gprs[2] = -EINTR;
413 break;
414 case -ERESTARTSYS:
415 if (!(ka.sa.sa_flags & SA_RESTART)) {
416 regs->gprs[2] = -EINTR;
417 break;
418 }
419 /* fallthrough */
420 case -ERESTARTNOINTR:
421 regs->gprs[2] = regs->orig_gpr2;
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100422 regs->psw.addr =
423 __rewind_psw(regs->psw,
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100424 regs->int_code >> 16);
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100425 break;
426 }
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100427 }
Martin Schwidefskyd9ae6772011-12-01 13:32:15 +0100428 /* No longer in a system call */
429 clear_thread_flag(TIF_SYSCALL);
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100430
Al Viroa610d6e2012-05-21 23:42:15 -0400431 if (is_compat_task())
432 handle_signal32(signr, &ka, &info, oldset, regs);
433 else
434 handle_signal(signr, &ka, &info, oldset, regs);
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800435 return;
436 }
437
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100438 /* No handlers present - check for system call restart */
Martin Schwidefskyd9ae6772011-12-01 13:32:15 +0100439 clear_thread_flag(TIF_SYSCALL);
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100440 if (current_thread_info()->system_call) {
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100441 regs->int_code = current_thread_info()->system_call;
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100442 switch (regs->gprs[2]) {
443 case -ERESTART_RESTARTBLOCK:
444 /* Restart with sys_restart_syscall */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100445 regs->int_code = __NR_restart_syscall;
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100446 /* fallthrough */
447 case -ERESTARTNOHAND:
448 case -ERESTARTSYS:
449 case -ERESTARTNOINTR:
450 /* Restart system call with magic TIF bit. */
451 regs->gprs[2] = regs->orig_gpr2;
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100452 set_thread_flag(TIF_SYSCALL);
Martin Schwidefsky39efd4e2012-11-21 16:36:27 +0100453 if (test_thread_flag(TIF_SINGLE_STEP))
454 set_thread_flag(TIF_PER_TRAP);
Martin Schwidefskyb6ef5bb2011-10-30 15:16:49 +0100455 break;
Martin Schwidefsky20b40a72011-10-30 15:16:47 +0100456 }
457 }
458
Heiko Carstens54dfe5d2006-02-01 03:06:38 -0800459 /*
460 * If there's no signal to deliver, we just put the saved sigmask back.
461 */
Al Viro51a7b442012-05-21 23:33:55 -0400462 restore_saved_sigmask();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463}
Martin Schwidefsky753c4dd2008-10-10 21:33:20 +0200464
465void do_notify_resume(struct pt_regs *regs)
466{
467 clear_thread_flag(TIF_NOTIFY_RESUME);
468 tracehook_notify_resume(regs);
469}