blob: 7fc29615ef0132129c46d44fb4561ba084f4a1c2 [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{
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 mask &= _BLOCKABLE;
44 spin_lock_irq(&current->sighand->siglock);
David Howellsa411aee2006-01-18 17:43:59 -080045 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 siginitset(&current->blocked, mask);
47 recalc_sigpending();
48 spin_unlock_irq(&current->sighand->siglock);
49
David Howellsa411aee2006-01-18 17:43:59 -080050 current->state = TASK_INTERRUPTIBLE;
51 schedule();
52 set_thread_flag(TIF_RESTORE_SIGMASK);
53 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
56asmlinkage int sys_sigaction(int sig,
57 const struct old_sigaction __user *act,
58 struct old_sigaction __user *oact)
59{
60 struct k_sigaction new_ka, old_ka;
61 int ret;
62
63 if (act) {
64 old_sigset_t mask;
65 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
66 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
67 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
68 return -EFAULT;
69 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
70 __get_user(mask, &act->sa_mask);
71 siginitset(&new_ka.sa.sa_mask, mask);
72 }
73
74 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
75
76 if (!ret && oact) {
77 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
78 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
79 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
80 return -EFAULT;
81 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
82 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
83 }
84
85 return ret;
86}
87
88asmlinkage
89int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
90{
91 return do_sigaltstack(uss, uoss, __frame->sp);
92}
93
94
95/*
96 * Do a signal return; undo the signal stack.
97 */
98
99struct sigframe
100{
Al Viro9e4d11f2006-06-23 02:04:04 -0700101 __sigrestore_t pretcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 int sig;
103 struct sigcontext sc;
104 unsigned long extramask[_NSIG_WORDS-1];
105 uint32_t retcode[2];
106};
107
108struct rt_sigframe
109{
Al Viro9e4d11f2006-06-23 02:04:04 -0700110 __sigrestore_t pretcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 int sig;
Al Viro9e4d11f2006-06-23 02:04:04 -0700112 struct siginfo __user *pinfo;
113 void __user *puc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 struct siginfo info;
115 struct ucontext uc;
116 uint32_t retcode[2];
117};
118
119static int restore_sigcontext(struct sigcontext __user *sc, int *_gr8)
120{
121 struct user_context *user = current->thread.user;
122 unsigned long tbr, psr;
123
Al Viro20cd5142010-09-20 15:13:04 +0100124 /* Always make any pending restarted system calls return -EINTR */
125 current_thread_info()->restart_block.fn = do_no_restart_syscall;
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 tbr = user->i.tbr;
128 psr = user->i.psr;
129 if (copy_from_user(user, &sc->sc_context, sizeof(sc->sc_context)))
130 goto badframe;
131 user->i.tbr = tbr;
132 user->i.psr = psr;
133
134 restore_user_regs(user);
135
136 user->i.syscallno = -1; /* disable syscall checks */
137
138 *_gr8 = user->i.gr[8];
139 return 0;
140
141 badframe:
142 return 1;
143}
144
145asmlinkage int sys_sigreturn(void)
146{
147 struct sigframe __user *frame = (struct sigframe __user *) __frame->sp;
148 sigset_t set;
149 int gr8;
150
151 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
152 goto badframe;
153 if (__get_user(set.sig[0], &frame->sc.sc_oldmask))
154 goto badframe;
155
156 if (_NSIG_WORDS > 1 &&
157 __copy_from_user(&set.sig[1], &frame->extramask, sizeof(frame->extramask)))
158 goto badframe;
159
160 sigdelsetmask(&set, ~_BLOCKABLE);
161 spin_lock_irq(&current->sighand->siglock);
162 current->blocked = set;
163 recalc_sigpending();
164 spin_unlock_irq(&current->sighand->siglock);
165
166 if (restore_sigcontext(&frame->sc, &gr8))
167 goto badframe;
168 return gr8;
169
170 badframe:
171 force_sig(SIGSEGV, current);
172 return 0;
173}
174
175asmlinkage int sys_rt_sigreturn(void)
176{
177 struct rt_sigframe __user *frame = (struct rt_sigframe __user *) __frame->sp;
178 sigset_t set;
179 int gr8;
180
181 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
182 goto badframe;
183 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
184 goto badframe;
185
186 sigdelsetmask(&set, ~_BLOCKABLE);
187 spin_lock_irq(&current->sighand->siglock);
188 current->blocked = set;
189 recalc_sigpending();
190 spin_unlock_irq(&current->sighand->siglock);
191
192 if (restore_sigcontext(&frame->uc.uc_mcontext, &gr8))
193 goto badframe;
194
195 if (do_sigaltstack(&frame->uc.uc_stack, NULL, __frame->sp) == -EFAULT)
196 goto badframe;
197
198 return gr8;
199
200badframe:
201 force_sig(SIGSEGV, current);
202 return 0;
203}
204
205/*
206 * Set up a signal frame
207 */
208static int setup_sigcontext(struct sigcontext __user *sc, unsigned long mask)
209{
210 save_user_regs(current->thread.user);
211
212 if (copy_to_user(&sc->sc_context, current->thread.user, sizeof(sc->sc_context)) != 0)
213 goto badframe;
214
215 /* non-iBCS2 extensions.. */
216 if (__put_user(mask, &sc->sc_oldmask) < 0)
217 goto badframe;
218
219 return 0;
220
221 badframe:
222 return 1;
223}
224
225/*****************************************************************************/
226/*
227 * Determine which stack to use..
228 */
229static inline void __user *get_sigframe(struct k_sigaction *ka,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 size_t frame_size)
231{
232 unsigned long sp;
233
234 /* Default to using normal stack */
David Howellsfef2b582006-01-06 00:11:45 -0800235 sp = __frame->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 /* This is the X/Open sanctioned signal stack switching. */
238 if (ka->sa.sa_flags & SA_ONSTACK) {
Laurent MEYERd09042d2006-06-23 02:05:36 -0700239 if (! sas_ss_flags(sp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 sp = current->sas_ss_sp + current->sas_ss_size;
241 }
242
243 return (void __user *) ((sp - frame_size) & ~7UL);
David Howellsfef2b582006-01-06 00:11:45 -0800244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245} /* end get_sigframe() */
246
247/*****************************************************************************/
248/*
249 *
250 */
David Howellsfef2b582006-01-06 00:11:45 -0800251static int setup_frame(int sig, struct k_sigaction *ka, sigset_t *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 struct sigframe __user *frame;
254 int rsig;
255
David Howellsfef2b582006-01-06 00:11:45 -0800256 frame = get_sigframe(ka, sizeof(*frame));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
259 goto give_sigsegv;
260
261 rsig = sig;
262 if (sig < 32 &&
263 __current_thread_info->exec_domain &&
264 __current_thread_info->exec_domain->signal_invmap)
265 rsig = __current_thread_info->exec_domain->signal_invmap[sig];
266
267 if (__put_user(rsig, &frame->sig) < 0)
268 goto give_sigsegv;
269
270 if (setup_sigcontext(&frame->sc, set->sig[0]))
271 goto give_sigsegv;
272
273 if (_NSIG_WORDS > 1) {
274 if (__copy_to_user(frame->extramask, &set->sig[1],
275 sizeof(frame->extramask)))
276 goto give_sigsegv;
277 }
278
279 /* Set up to return from userspace. If provided, use a stub
280 * already in userspace. */
281 if (ka->sa.sa_flags & SA_RESTORER) {
282 if (__put_user(ka->sa.sa_restorer, &frame->pretcode) < 0)
283 goto give_sigsegv;
284 }
285 else {
286 /* Set up the following code on the stack:
287 * setlos #__NR_sigreturn,gr7
288 * tira gr0,0
289 */
Al Viro9e4d11f2006-06-23 02:04:04 -0700290 if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 __put_user(0x8efc0000|__NR_sigreturn, &frame->retcode[0]) ||
292 __put_user(0xc0700000, &frame->retcode[1]))
293 goto give_sigsegv;
294
295 flush_icache_range((unsigned long) frame->retcode,
296 (unsigned long) (frame->retcode + 2));
297 }
298
299 /* set up registers for signal handler */
David Howellsfef2b582006-01-06 00:11:45 -0800300 __frame->sp = (unsigned long) frame;
301 __frame->lr = (unsigned long) &frame->retcode;
302 __frame->gr8 = sig;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
WANG Congecd0fa92008-04-29 00:59:15 -0700304 if (current->personality & FDPIC_FUNCPTRS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 struct fdpic_func_descriptor __user *funcptr =
Al Viro9e4d11f2006-06-23 02:04:04 -0700306 (struct fdpic_func_descriptor __user *) ka->sa.sa_handler;
David Howellsfef2b582006-01-06 00:11:45 -0800307 __get_user(__frame->pc, &funcptr->text);
308 __get_user(__frame->gr15, &funcptr->GOT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 } else {
David Howellsfef2b582006-01-06 00:11:45 -0800310 __frame->pc = (unsigned long) ka->sa.sa_handler;
311 __frame->gr15 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 }
313
314 set_fs(USER_DS);
315
David Howells8efc0ab2006-01-06 00:11:44 -0800316 /* the tracer may want to single-step inside the handler */
317 if (test_thread_flag(TIF_SINGLESTEP))
318 ptrace_notify(SIGTRAP);
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#if DEBUG_SIG
321 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
David Howellsfef2b582006-01-06 00:11:45 -0800322 sig, current->comm, current->pid, frame, __frame->pc,
David Howells8efc0ab2006-01-06 00:11:44 -0800323 frame->pretcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#endif
325
David Howellsa411aee2006-01-18 17:43:59 -0800326 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328give_sigsegv:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 force_sig(SIGSEGV, current);
David Howellsa411aee2006-01-18 17:43:59 -0800330 return -EFAULT;
David Howells8efc0ab2006-01-06 00:11:44 -0800331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332} /* end setup_frame() */
333
334/*****************************************************************************/
335/*
336 *
337 */
David Howells8efc0ab2006-01-06 00:11:44 -0800338static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
David Howellsfef2b582006-01-06 00:11:45 -0800339 sigset_t *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
341 struct rt_sigframe __user *frame;
342 int rsig;
343
David Howellsfef2b582006-01-06 00:11:45 -0800344 frame = get_sigframe(ka, sizeof(*frame));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
347 goto give_sigsegv;
348
349 rsig = sig;
350 if (sig < 32 &&
351 __current_thread_info->exec_domain &&
352 __current_thread_info->exec_domain->signal_invmap)
353 rsig = __current_thread_info->exec_domain->signal_invmap[sig];
354
355 if (__put_user(rsig, &frame->sig) ||
356 __put_user(&frame->info, &frame->pinfo) ||
357 __put_user(&frame->uc, &frame->puc))
358 goto give_sigsegv;
359
360 if (copy_siginfo_to_user(&frame->info, info))
361 goto give_sigsegv;
362
363 /* Create the ucontext. */
364 if (__put_user(0, &frame->uc.uc_flags) ||
Al Viro9e4d11f2006-06-23 02:04:04 -0700365 __put_user(NULL, &frame->uc.uc_link) ||
366 __put_user((void __user *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp) ||
David Howellsfef2b582006-01-06 00:11:45 -0800367 __put_user(sas_ss_flags(__frame->sp), &frame->uc.uc_stack.ss_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size))
369 goto give_sigsegv;
370
371 if (setup_sigcontext(&frame->uc.uc_mcontext, set->sig[0]))
372 goto give_sigsegv;
373
374 if (__copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)))
375 goto give_sigsegv;
376
377 /* Set up to return from userspace. If provided, use a stub
378 * already in userspace. */
379 if (ka->sa.sa_flags & SA_RESTORER) {
380 if (__put_user(ka->sa.sa_restorer, &frame->pretcode))
381 goto give_sigsegv;
382 }
383 else {
384 /* Set up the following code on the stack:
385 * setlos #__NR_sigreturn,gr7
386 * tira gr0,0
387 */
Al Viro9e4d11f2006-06-23 02:04:04 -0700388 if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 __put_user(0x8efc0000|__NR_rt_sigreturn, &frame->retcode[0]) ||
390 __put_user(0xc0700000, &frame->retcode[1]))
391 goto give_sigsegv;
392
393 flush_icache_range((unsigned long) frame->retcode,
394 (unsigned long) (frame->retcode + 2));
395 }
396
397 /* Set up registers for signal handler */
David Howellsfef2b582006-01-06 00:11:45 -0800398 __frame->sp = (unsigned long) frame;
399 __frame->lr = (unsigned long) &frame->retcode;
400 __frame->gr8 = sig;
401 __frame->gr9 = (unsigned long) &frame->info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
WANG Congecd0fa92008-04-29 00:59:15 -0700403 if (current->personality & FDPIC_FUNCPTRS) {
Al Viro9e4d11f2006-06-23 02:04:04 -0700404 struct fdpic_func_descriptor __user *funcptr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 (struct fdpic_func_descriptor __user *) ka->sa.sa_handler;
David Howellsfef2b582006-01-06 00:11:45 -0800406 __get_user(__frame->pc, &funcptr->text);
407 __get_user(__frame->gr15, &funcptr->GOT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 } else {
David Howellsfef2b582006-01-06 00:11:45 -0800409 __frame->pc = (unsigned long) ka->sa.sa_handler;
410 __frame->gr15 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 }
412
413 set_fs(USER_DS);
414
David Howells8efc0ab2006-01-06 00:11:44 -0800415 /* the tracer may want to single-step inside the handler */
416 if (test_thread_flag(TIF_SINGLESTEP))
417 ptrace_notify(SIGTRAP);
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#if DEBUG_SIG
420 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
David Howellsfef2b582006-01-06 00:11:45 -0800421 sig, current->comm, current->pid, frame, __frame->pc,
David Howells8efc0ab2006-01-06 00:11:44 -0800422 frame->pretcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#endif
424
David Howellsa411aee2006-01-18 17:43:59 -0800425 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427give_sigsegv:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 force_sig(SIGSEGV, current);
David Howellsa411aee2006-01-18 17:43:59 -0800429 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431} /* end setup_rt_frame() */
432
433/*****************************************************************************/
434/*
435 * OK, we're invoking a handler
436 */
David Howells8efc0ab2006-01-06 00:11:44 -0800437static int handle_signal(unsigned long sig, siginfo_t *info,
David Howellsfef2b582006-01-06 00:11:45 -0800438 struct k_sigaction *ka, sigset_t *oldset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
David Howells8efc0ab2006-01-06 00:11:44 -0800440 int ret;
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 /* Are we from a system call? */
David Howellsfef2b582006-01-06 00:11:45 -0800443 if (in_syscall(__frame)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 /* If so, check system call restarting.. */
David Howellsfef2b582006-01-06 00:11:45 -0800445 switch (__frame->gr8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 case -ERESTART_RESTARTBLOCK:
447 case -ERESTARTNOHAND:
David Howellsfef2b582006-01-06 00:11:45 -0800448 __frame->gr8 = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 break;
450
451 case -ERESTARTSYS:
452 if (!(ka->sa.sa_flags & SA_RESTART)) {
David Howellsfef2b582006-01-06 00:11:45 -0800453 __frame->gr8 = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 break;
455 }
David Howells8efc0ab2006-01-06 00:11:44 -0800456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 /* fallthrough */
458 case -ERESTARTNOINTR:
David Howellsfef2b582006-01-06 00:11:45 -0800459 __frame->gr8 = __frame->orig_gr8;
460 __frame->pc -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462 }
463
464 /* Set up the stack frame */
465 if (ka->sa.sa_flags & SA_SIGINFO)
David Howellsfef2b582006-01-06 00:11:45 -0800466 ret = setup_rt_frame(sig, ka, info, oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 else
David Howellsfef2b582006-01-06 00:11:45 -0800468 ret = setup_frame(sig, ka, oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
David Howellsa411aee2006-01-18 17:43:59 -0800470 if (ret == 0) {
David Howells8efc0ab2006-01-06 00:11:44 -0800471 spin_lock_irq(&current->sighand->siglock);
472 sigorsets(&current->blocked, &current->blocked,
473 &ka->sa.sa_mask);
474 if (!(ka->sa.sa_flags & SA_NODEFER))
475 sigaddset(&current->blocked, sig);
476 recalc_sigpending();
477 spin_unlock_irq(&current->sighand->siglock);
478 }
479
480 return ret;
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482} /* end handle_signal() */
483
484/*****************************************************************************/
485/*
486 * Note that 'init' is a special process: it doesn't get signals it doesn't
487 * want to handle. Thus you cannot kill init even with a SIGKILL even by
488 * mistake.
489 */
David Howellsa411aee2006-01-18 17:43:59 -0800490static void do_signal(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 struct k_sigaction ka;
493 siginfo_t info;
David Howellsa411aee2006-01-18 17:43:59 -0800494 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 int signr;
496
497 /*
498 * We want the common case to go fast, which
499 * is why we may in certain cases get here from
500 * kernel mode. Just return without doing anything
501 * if so.
502 */
David Howellsfef2b582006-01-06 00:11:45 -0800503 if (!user_mode(__frame))
David Howellsa411aee2006-01-18 17:43:59 -0800504 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Christoph Lameter3e1d1d22005-06-24 23:13:50 -0700506 if (try_to_freeze())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 goto no_signal;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
David Howellsa411aee2006-01-18 17:43:59 -0800509 if (test_thread_flag(TIF_RESTORE_SIGMASK))
510 oldset = &current->saved_sigmask;
511 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 oldset = &current->blocked;
513
David Howellsfef2b582006-01-06 00:11:45 -0800514 signr = get_signal_to_deliver(&info, &ka, __frame, NULL);
David Howellsa411aee2006-01-18 17:43:59 -0800515 if (signr > 0) {
516 if (handle_signal(signr, &info, &ka, oldset) == 0) {
517 /* a signal was successfully delivered; the saved
518 * sigmask will have been stored in the signal frame,
519 * and will be restored by sigreturn, so we can simply
520 * clear the TIF_RESTORE_SIGMASK flag */
521 if (test_thread_flag(TIF_RESTORE_SIGMASK))
522 clear_thread_flag(TIF_RESTORE_SIGMASK);
David Howells4a3b9892009-06-11 13:05:24 +0100523
524 tracehook_signal_handler(signr, &info, &ka, __frame,
525 test_thread_flag(TIF_SINGLESTEP));
David Howellsa411aee2006-01-18 17:43:59 -0800526 }
527
528 return;
529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
David Howells8efc0ab2006-01-06 00:11:44 -0800531no_signal:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 /* Did we come from a system call? */
Roel Kluinc896a2e2009-10-26 16:50:23 -0700533 if (__frame->syscallno != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 /* Restart the system call - no handlers present */
David Howellsa411aee2006-01-18 17:43:59 -0800535 switch (__frame->gr8) {
536 case -ERESTARTNOHAND:
537 case -ERESTARTSYS:
538 case -ERESTARTNOINTR:
David Howellsfef2b582006-01-06 00:11:45 -0800539 __frame->gr8 = __frame->orig_gr8;
540 __frame->pc -= 4;
David Howellsa411aee2006-01-18 17:43:59 -0800541 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
David Howellsa411aee2006-01-18 17:43:59 -0800543 case -ERESTART_RESTARTBLOCK:
David Howellsfef2b582006-01-06 00:11:45 -0800544 __frame->gr8 = __NR_restart_syscall;
545 __frame->pc -= 4;
David Howellsa411aee2006-01-18 17:43:59 -0800546 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 }
548 }
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() */