blob: df957c7ba387727067952f9c7c922fda518ecb9f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* signal.c: FRV specific bits of signal handling
2 *
3 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from arch/m68k/kernel/signal.c
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13#include <linux/sched.h>
14#include <linux/mm.h>
15#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/kernel.h>
17#include <linux/signal.h>
18#include <linux/errno.h>
19#include <linux/wait.h>
20#include <linux/ptrace.h>
21#include <linux/unistd.h>
22#include <linux/personality.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080023#include <linux/freezer.h>
David Howells4a3b9892009-06-11 13:05:24 +010024#include <linux/tracehook.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/ucontext.h>
26#include <asm/uaccess.h>
27#include <asm/cacheflush.h>
28
29#define DEBUG_SIG 0
30
31#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
32
33struct fdpic_func_descriptor {
34 unsigned long text;
35 unsigned long GOT;
36};
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
39 * Atomically swap in the new signal mask, and wait for a signal.
40 */
41asmlinkage int sys_sigsuspend(int history0, int history1, old_sigset_t mask)
42{
Al Viro68f3f162012-05-21 21:42:32 -040043 sigset_t blocked;
44 siginitset(&blocked, mask);
45 return sigsuspend(&blocked);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
48asmlinkage int sys_sigaction(int sig,
49 const struct old_sigaction __user *act,
50 struct old_sigaction __user *oact)
51{
52 struct k_sigaction new_ka, old_ka;
53 int ret;
54
55 if (act) {
56 old_sigset_t mask;
57 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
58 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
59 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
60 return -EFAULT;
61 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
62 __get_user(mask, &act->sa_mask);
63 siginitset(&new_ka.sa.sa_mask, mask);
64 }
65
66 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
67
68 if (!ret && oact) {
69 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
70 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
71 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
72 return -EFAULT;
73 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
74 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
75 }
76
77 return ret;
78}
79
80asmlinkage
81int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
82{
83 return do_sigaltstack(uss, uoss, __frame->sp);
84}
85
86
87/*
88 * Do a signal return; undo the signal stack.
89 */
90
91struct sigframe
92{
Al Viro9e4d11f2006-06-23 02:04:04 -070093 __sigrestore_t pretcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 int sig;
95 struct sigcontext sc;
96 unsigned long extramask[_NSIG_WORDS-1];
97 uint32_t retcode[2];
98};
99
100struct rt_sigframe
101{
Al Viro9e4d11f2006-06-23 02:04:04 -0700102 __sigrestore_t pretcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 int sig;
Al Viro9e4d11f2006-06-23 02:04:04 -0700104 struct siginfo __user *pinfo;
105 void __user *puc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 struct siginfo info;
107 struct ucontext uc;
108 uint32_t retcode[2];
109};
110
111static int restore_sigcontext(struct sigcontext __user *sc, int *_gr8)
112{
113 struct user_context *user = current->thread.user;
114 unsigned long tbr, psr;
115
Al Viro20cd5142010-09-20 15:13:04 +0100116 /* Always make any pending restarted system calls return -EINTR */
117 current_thread_info()->restart_block.fn = do_no_restart_syscall;
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 tbr = user->i.tbr;
120 psr = user->i.psr;
121 if (copy_from_user(user, &sc->sc_context, sizeof(sc->sc_context)))
122 goto badframe;
123 user->i.tbr = tbr;
124 user->i.psr = psr;
125
126 restore_user_regs(user);
127
128 user->i.syscallno = -1; /* disable syscall checks */
129
130 *_gr8 = user->i.gr[8];
131 return 0;
132
133 badframe:
134 return 1;
135}
136
137asmlinkage int sys_sigreturn(void)
138{
139 struct sigframe __user *frame = (struct sigframe __user *) __frame->sp;
140 sigset_t set;
141 int gr8;
142
143 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
144 goto badframe;
145 if (__get_user(set.sig[0], &frame->sc.sc_oldmask))
146 goto badframe;
147
148 if (_NSIG_WORDS > 1 &&
149 __copy_from_user(&set.sig[1], &frame->extramask, sizeof(frame->extramask)))
150 goto badframe;
151
152 sigdelsetmask(&set, ~_BLOCKABLE);
153 spin_lock_irq(&current->sighand->siglock);
154 current->blocked = set;
155 recalc_sigpending();
156 spin_unlock_irq(&current->sighand->siglock);
157
158 if (restore_sigcontext(&frame->sc, &gr8))
159 goto badframe;
160 return gr8;
161
162 badframe:
163 force_sig(SIGSEGV, current);
164 return 0;
165}
166
167asmlinkage int sys_rt_sigreturn(void)
168{
169 struct rt_sigframe __user *frame = (struct rt_sigframe __user *) __frame->sp;
170 sigset_t set;
171 int gr8;
172
173 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
174 goto badframe;
175 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
176 goto badframe;
177
178 sigdelsetmask(&set, ~_BLOCKABLE);
179 spin_lock_irq(&current->sighand->siglock);
180 current->blocked = set;
181 recalc_sigpending();
182 spin_unlock_irq(&current->sighand->siglock);
183
184 if (restore_sigcontext(&frame->uc.uc_mcontext, &gr8))
185 goto badframe;
186
187 if (do_sigaltstack(&frame->uc.uc_stack, NULL, __frame->sp) == -EFAULT)
188 goto badframe;
189
190 return gr8;
191
192badframe:
193 force_sig(SIGSEGV, current);
194 return 0;
195}
196
197/*
198 * Set up a signal frame
199 */
200static int setup_sigcontext(struct sigcontext __user *sc, unsigned long mask)
201{
202 save_user_regs(current->thread.user);
203
204 if (copy_to_user(&sc->sc_context, current->thread.user, sizeof(sc->sc_context)) != 0)
205 goto badframe;
206
207 /* non-iBCS2 extensions.. */
208 if (__put_user(mask, &sc->sc_oldmask) < 0)
209 goto badframe;
210
211 return 0;
212
213 badframe:
214 return 1;
215}
216
217/*****************************************************************************/
218/*
219 * Determine which stack to use..
220 */
221static inline void __user *get_sigframe(struct k_sigaction *ka,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 size_t frame_size)
223{
224 unsigned long sp;
225
226 /* Default to using normal stack */
David Howellsfef2b582006-01-06 00:11:45 -0800227 sp = __frame->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 /* This is the X/Open sanctioned signal stack switching. */
230 if (ka->sa.sa_flags & SA_ONSTACK) {
Laurent MEYERd09042d2006-06-23 02:05:36 -0700231 if (! sas_ss_flags(sp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 sp = current->sas_ss_sp + current->sas_ss_size;
233 }
234
235 return (void __user *) ((sp - frame_size) & ~7UL);
David Howellsfef2b582006-01-06 00:11:45 -0800236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237} /* end get_sigframe() */
238
239/*****************************************************************************/
240/*
241 *
242 */
David Howellsfef2b582006-01-06 00:11:45 -0800243static int setup_frame(int sig, struct k_sigaction *ka, sigset_t *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 struct sigframe __user *frame;
246 int rsig;
247
Al Viro5f4ad042010-09-20 15:13:09 +0100248 set_fs(USER_DS);
249
David Howellsfef2b582006-01-06 00:11:45 -0800250 frame = get_sigframe(ka, sizeof(*frame));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
253 goto give_sigsegv;
254
255 rsig = sig;
256 if (sig < 32 &&
257 __current_thread_info->exec_domain &&
258 __current_thread_info->exec_domain->signal_invmap)
259 rsig = __current_thread_info->exec_domain->signal_invmap[sig];
260
261 if (__put_user(rsig, &frame->sig) < 0)
262 goto give_sigsegv;
263
264 if (setup_sigcontext(&frame->sc, set->sig[0]))
265 goto give_sigsegv;
266
267 if (_NSIG_WORDS > 1) {
268 if (__copy_to_user(frame->extramask, &set->sig[1],
269 sizeof(frame->extramask)))
270 goto give_sigsegv;
271 }
272
273 /* Set up to return from userspace. If provided, use a stub
274 * already in userspace. */
275 if (ka->sa.sa_flags & SA_RESTORER) {
276 if (__put_user(ka->sa.sa_restorer, &frame->pretcode) < 0)
277 goto give_sigsegv;
278 }
279 else {
280 /* Set up the following code on the stack:
281 * setlos #__NR_sigreturn,gr7
282 * tira gr0,0
283 */
Al Viro9e4d11f2006-06-23 02:04:04 -0700284 if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 __put_user(0x8efc0000|__NR_sigreturn, &frame->retcode[0]) ||
286 __put_user(0xc0700000, &frame->retcode[1]))
287 goto give_sigsegv;
288
289 flush_icache_range((unsigned long) frame->retcode,
290 (unsigned long) (frame->retcode + 2));
291 }
292
Al Viro5f4ad042010-09-20 15:13:09 +0100293 /* Set up registers for the signal handler */
WANG Congecd0fa92008-04-29 00:59:15 -0700294 if (current->personality & FDPIC_FUNCPTRS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 struct fdpic_func_descriptor __user *funcptr =
Al Viro9e4d11f2006-06-23 02:04:04 -0700296 (struct fdpic_func_descriptor __user *) ka->sa.sa_handler;
Al Viro5f4ad042010-09-20 15:13:09 +0100297 struct fdpic_func_descriptor desc;
298 if (copy_from_user(&desc, funcptr, sizeof(desc)))
299 goto give_sigsegv;
300 __frame->pc = desc.text;
301 __frame->gr15 = desc.GOT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 } else {
David Howellsfef2b582006-01-06 00:11:45 -0800303 __frame->pc = (unsigned long) ka->sa.sa_handler;
304 __frame->gr15 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
306
Al Viro5f4ad042010-09-20 15:13:09 +0100307 __frame->sp = (unsigned long) frame;
308 __frame->lr = (unsigned long) &frame->retcode;
309 __frame->gr8 = sig;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
David Howells8efc0ab2006-01-06 00:11:44 -0800311 /* the tracer may want to single-step inside the handler */
312 if (test_thread_flag(TIF_SINGLESTEP))
313 ptrace_notify(SIGTRAP);
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#if DEBUG_SIG
316 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
David Howellsfef2b582006-01-06 00:11:45 -0800317 sig, current->comm, current->pid, frame, __frame->pc,
David Howells8efc0ab2006-01-06 00:11:44 -0800318 frame->pretcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#endif
320
David Howellsa411aee2006-01-18 17:43:59 -0800321 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323give_sigsegv:
Al Viroad0acab2010-09-20 15:13:14 +0100324 force_sigsegv(sig, current);
David Howellsa411aee2006-01-18 17:43:59 -0800325 return -EFAULT;
David Howells8efc0ab2006-01-06 00:11:44 -0800326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327} /* end setup_frame() */
328
329/*****************************************************************************/
330/*
331 *
332 */
David Howells8efc0ab2006-01-06 00:11:44 -0800333static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
David Howellsfef2b582006-01-06 00:11:45 -0800334 sigset_t *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
336 struct rt_sigframe __user *frame;
337 int rsig;
338
Al Viro5f4ad042010-09-20 15:13:09 +0100339 set_fs(USER_DS);
340
David Howellsfef2b582006-01-06 00:11:45 -0800341 frame = get_sigframe(ka, sizeof(*frame));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
344 goto give_sigsegv;
345
346 rsig = sig;
347 if (sig < 32 &&
348 __current_thread_info->exec_domain &&
349 __current_thread_info->exec_domain->signal_invmap)
350 rsig = __current_thread_info->exec_domain->signal_invmap[sig];
351
352 if (__put_user(rsig, &frame->sig) ||
353 __put_user(&frame->info, &frame->pinfo) ||
354 __put_user(&frame->uc, &frame->puc))
355 goto give_sigsegv;
356
357 if (copy_siginfo_to_user(&frame->info, info))
358 goto give_sigsegv;
359
360 /* Create the ucontext. */
361 if (__put_user(0, &frame->uc.uc_flags) ||
Al Viro9e4d11f2006-06-23 02:04:04 -0700362 __put_user(NULL, &frame->uc.uc_link) ||
363 __put_user((void __user *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp) ||
David Howellsfef2b582006-01-06 00:11:45 -0800364 __put_user(sas_ss_flags(__frame->sp), &frame->uc.uc_stack.ss_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size))
366 goto give_sigsegv;
367
368 if (setup_sigcontext(&frame->uc.uc_mcontext, set->sig[0]))
369 goto give_sigsegv;
370
371 if (__copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)))
372 goto give_sigsegv;
373
374 /* Set up to return from userspace. If provided, use a stub
375 * already in userspace. */
376 if (ka->sa.sa_flags & SA_RESTORER) {
377 if (__put_user(ka->sa.sa_restorer, &frame->pretcode))
378 goto give_sigsegv;
379 }
380 else {
381 /* Set up the following code on the stack:
382 * setlos #__NR_sigreturn,gr7
383 * tira gr0,0
384 */
Al Viro9e4d11f2006-06-23 02:04:04 -0700385 if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 __put_user(0x8efc0000|__NR_rt_sigreturn, &frame->retcode[0]) ||
387 __put_user(0xc0700000, &frame->retcode[1]))
388 goto give_sigsegv;
389
390 flush_icache_range((unsigned long) frame->retcode,
391 (unsigned long) (frame->retcode + 2));
392 }
393
394 /* Set up registers for signal handler */
WANG Congecd0fa92008-04-29 00:59:15 -0700395 if (current->personality & FDPIC_FUNCPTRS) {
Al Viro9e4d11f2006-06-23 02:04:04 -0700396 struct fdpic_func_descriptor __user *funcptr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 (struct fdpic_func_descriptor __user *) ka->sa.sa_handler;
Al Viro5f4ad042010-09-20 15:13:09 +0100398 struct fdpic_func_descriptor desc;
399 if (copy_from_user(&desc, funcptr, sizeof(desc)))
400 goto give_sigsegv;
401 __frame->pc = desc.text;
402 __frame->gr15 = desc.GOT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 } else {
David Howellsfef2b582006-01-06 00:11:45 -0800404 __frame->pc = (unsigned long) ka->sa.sa_handler;
405 __frame->gr15 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
407
Al Viro5f4ad042010-09-20 15:13:09 +0100408 __frame->sp = (unsigned long) frame;
409 __frame->lr = (unsigned long) &frame->retcode;
410 __frame->gr8 = sig;
411 __frame->gr9 = (unsigned long) &frame->info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
David Howells8efc0ab2006-01-06 00:11:44 -0800413 /* the tracer may want to single-step inside the handler */
414 if (test_thread_flag(TIF_SINGLESTEP))
415 ptrace_notify(SIGTRAP);
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#if DEBUG_SIG
418 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
David Howellsfef2b582006-01-06 00:11:45 -0800419 sig, current->comm, current->pid, frame, __frame->pc,
David Howells8efc0ab2006-01-06 00:11:44 -0800420 frame->pretcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#endif
422
David Howellsa411aee2006-01-18 17:43:59 -0800423 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425give_sigsegv:
Al Viroad0acab2010-09-20 15:13:14 +0100426 force_sigsegv(sig, current);
David Howellsa411aee2006-01-18 17:43:59 -0800427 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429} /* end setup_rt_frame() */
430
431/*****************************************************************************/
432/*
433 * OK, we're invoking a handler
434 */
David Howells8efc0ab2006-01-06 00:11:44 -0800435static int handle_signal(unsigned long sig, siginfo_t *info,
David Howellsfef2b582006-01-06 00:11:45 -0800436 struct k_sigaction *ka, sigset_t *oldset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
David Howells8efc0ab2006-01-06 00:11:44 -0800438 int ret;
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 /* Are we from a system call? */
Al Viroed1cde62010-09-20 15:13:25 +0100441 if (__frame->syscallno != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 /* If so, check system call restarting.. */
David Howellsfef2b582006-01-06 00:11:45 -0800443 switch (__frame->gr8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 case -ERESTART_RESTARTBLOCK:
445 case -ERESTARTNOHAND:
David Howellsfef2b582006-01-06 00:11:45 -0800446 __frame->gr8 = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 break;
448
449 case -ERESTARTSYS:
450 if (!(ka->sa.sa_flags & SA_RESTART)) {
David Howellsfef2b582006-01-06 00:11:45 -0800451 __frame->gr8 = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 break;
453 }
David Howells8efc0ab2006-01-06 00:11:44 -0800454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 /* fallthrough */
456 case -ERESTARTNOINTR:
David Howellsfef2b582006-01-06 00:11:45 -0800457 __frame->gr8 = __frame->orig_gr8;
458 __frame->pc -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
Al Viroed1cde62010-09-20 15:13:25 +0100460 __frame->syscallno = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462
463 /* Set up the stack frame */
464 if (ka->sa.sa_flags & SA_SIGINFO)
David Howellsfef2b582006-01-06 00:11:45 -0800465 ret = setup_rt_frame(sig, ka, info, oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 else
David Howellsfef2b582006-01-06 00:11:45 -0800467 ret = setup_frame(sig, ka, oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
David Howellsa411aee2006-01-18 17:43:59 -0800469 if (ret == 0) {
David Howells8efc0ab2006-01-06 00:11:44 -0800470 spin_lock_irq(&current->sighand->siglock);
471 sigorsets(&current->blocked, &current->blocked,
472 &ka->sa.sa_mask);
473 if (!(ka->sa.sa_flags & SA_NODEFER))
474 sigaddset(&current->blocked, sig);
475 recalc_sigpending();
476 spin_unlock_irq(&current->sighand->siglock);
477 }
478
479 return ret;
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481} /* end handle_signal() */
482
483/*****************************************************************************/
484/*
485 * Note that 'init' is a special process: it doesn't get signals it doesn't
486 * want to handle. Thus you cannot kill init even with a SIGKILL even by
487 * mistake.
488 */
David Howellsa411aee2006-01-18 17:43:59 -0800489static void do_signal(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
491 struct k_sigaction ka;
492 siginfo_t info;
David Howellsa411aee2006-01-18 17:43:59 -0800493 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 int signr;
495
496 /*
497 * We want the common case to go fast, which
498 * is why we may in certain cases get here from
499 * kernel mode. Just return without doing anything
500 * if so.
501 */
David Howellsfef2b582006-01-06 00:11:45 -0800502 if (!user_mode(__frame))
David Howellsa411aee2006-01-18 17:43:59 -0800503 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Christoph Lameter3e1d1d22005-06-24 23:13:50 -0700505 if (try_to_freeze())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 goto no_signal;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
David Howellsa411aee2006-01-18 17:43:59 -0800508 if (test_thread_flag(TIF_RESTORE_SIGMASK))
509 oldset = &current->saved_sigmask;
510 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 oldset = &current->blocked;
512
David Howellsfef2b582006-01-06 00:11:45 -0800513 signr = get_signal_to_deliver(&info, &ka, __frame, NULL);
David Howellsa411aee2006-01-18 17:43:59 -0800514 if (signr > 0) {
515 if (handle_signal(signr, &info, &ka, oldset) == 0) {
516 /* a signal was successfully delivered; the saved
517 * sigmask will have been stored in the signal frame,
518 * and will be restored by sigreturn, so we can simply
519 * clear the TIF_RESTORE_SIGMASK flag */
520 if (test_thread_flag(TIF_RESTORE_SIGMASK))
521 clear_thread_flag(TIF_RESTORE_SIGMASK);
David Howells4a3b9892009-06-11 13:05:24 +0100522
523 tracehook_signal_handler(signr, &info, &ka, __frame,
524 test_thread_flag(TIF_SINGLESTEP));
David Howellsa411aee2006-01-18 17:43:59 -0800525 }
526
527 return;
528 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
David Howells8efc0ab2006-01-06 00:11:44 -0800530no_signal:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /* Did we come from a system call? */
Roel Kluinc896a2e2009-10-26 16:50:23 -0700532 if (__frame->syscallno != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 /* Restart the system call - no handlers present */
David Howellsa411aee2006-01-18 17:43:59 -0800534 switch (__frame->gr8) {
535 case -ERESTARTNOHAND:
536 case -ERESTARTSYS:
537 case -ERESTARTNOINTR:
David Howellsfef2b582006-01-06 00:11:45 -0800538 __frame->gr8 = __frame->orig_gr8;
539 __frame->pc -= 4;
David Howellsa411aee2006-01-18 17:43:59 -0800540 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
David Howellsa411aee2006-01-18 17:43:59 -0800542 case -ERESTART_RESTARTBLOCK:
Al Viro44c7aff2010-09-20 15:13:19 +0100543 __frame->gr7 = __NR_restart_syscall;
David Howellsfef2b582006-01-06 00:11:45 -0800544 __frame->pc -= 4;
David Howellsa411aee2006-01-18 17:43:59 -0800545 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 }
Al Viroed1cde62010-09-20 15:13:25 +0100547 __frame->syscallno = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549
David Howellsa411aee2006-01-18 17:43:59 -0800550 /* if there's no signal to deliver, we just put the saved sigmask
551 * back */
552 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
553 clear_thread_flag(TIF_RESTORE_SIGMASK);
554 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
555 }
David Howells8efc0ab2006-01-06 00:11:44 -0800556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557} /* end do_signal() */
558
559/*****************************************************************************/
560/*
561 * notification of userspace execution resumption
David Howellsa411aee2006-01-18 17:43:59 -0800562 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 */
564asmlinkage void do_notify_resume(__u32 thread_info_flags)
565{
566 /* pending single-step? */
567 if (thread_info_flags & _TIF_SINGLESTEP)
568 clear_thread_flag(TIF_SINGLESTEP);
569
570 /* deal with pending signal delivery */
David Howellsa411aee2006-01-18 17:43:59 -0800571 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
572 do_signal();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
David Howellsb7bab882009-06-11 13:05:14 +0100574 /* deal with notification on about to resume userspace execution */
575 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
576 clear_thread_flag(TIF_NOTIFY_RESUME);
David Howells4a3b9892009-06-11 13:05:24 +0100577 tracehook_notify_resume(__frame);
David Howellsee18d642009-09-02 09:14:21 +0100578 if (current->replacement_session_keyring)
579 key_replace_session_keyring();
David Howellsb7bab882009-06-11 13:05:14 +0100580 }
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582} /* end do_notify_resume() */