blob: 22efe8d250389a27b9ed3d01a4a92cd18689a0dc [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) ||
Al Virof0c22cd2012-04-22 17:20:02 -040059 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
60 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
61 __get_user(mask, &act->sa_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 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) ||
Al Virof0c22cd2012-04-22 17:20:02 -040071 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
72 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
73 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
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);
Matt Fleming7ebe0c52012-05-11 10:58:52 +1000153 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 if (restore_sigcontext(&frame->sc, &gr8))
156 goto badframe;
157 return gr8;
158
159 badframe:
160 force_sig(SIGSEGV, current);
161 return 0;
162}
163
164asmlinkage int sys_rt_sigreturn(void)
165{
166 struct rt_sigframe __user *frame = (struct rt_sigframe __user *) __frame->sp;
167 sigset_t set;
168 int gr8;
169
170 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
171 goto badframe;
172 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
173 goto badframe;
174
175 sigdelsetmask(&set, ~_BLOCKABLE);
Matt Fleming7ebe0c52012-05-11 10:58:52 +1000176 set_current_blocked(&set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 if (restore_sigcontext(&frame->uc.uc_mcontext, &gr8))
179 goto badframe;
180
181 if (do_sigaltstack(&frame->uc.uc_stack, NULL, __frame->sp) == -EFAULT)
182 goto badframe;
183
184 return gr8;
185
186badframe:
187 force_sig(SIGSEGV, current);
188 return 0;
189}
190
191/*
192 * Set up a signal frame
193 */
194static int setup_sigcontext(struct sigcontext __user *sc, unsigned long mask)
195{
196 save_user_regs(current->thread.user);
197
198 if (copy_to_user(&sc->sc_context, current->thread.user, sizeof(sc->sc_context)) != 0)
199 goto badframe;
200
201 /* non-iBCS2 extensions.. */
202 if (__put_user(mask, &sc->sc_oldmask) < 0)
203 goto badframe;
204
205 return 0;
206
207 badframe:
208 return 1;
209}
210
211/*****************************************************************************/
212/*
213 * Determine which stack to use..
214 */
215static inline void __user *get_sigframe(struct k_sigaction *ka,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 size_t frame_size)
217{
218 unsigned long sp;
219
220 /* Default to using normal stack */
David Howellsfef2b582006-01-06 00:11:45 -0800221 sp = __frame->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* This is the X/Open sanctioned signal stack switching. */
224 if (ka->sa.sa_flags & SA_ONSTACK) {
Laurent MEYERd09042d2006-06-23 02:05:36 -0700225 if (! sas_ss_flags(sp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 sp = current->sas_ss_sp + current->sas_ss_size;
227 }
228
229 return (void __user *) ((sp - frame_size) & ~7UL);
David Howellsfef2b582006-01-06 00:11:45 -0800230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231} /* end get_sigframe() */
232
233/*****************************************************************************/
234/*
235 *
236 */
David Howellsfef2b582006-01-06 00:11:45 -0800237static int setup_frame(int sig, struct k_sigaction *ka, sigset_t *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
239 struct sigframe __user *frame;
240 int rsig;
241
Al Viro5f4ad042010-09-20 15:13:09 +0100242 set_fs(USER_DS);
243
David Howellsfef2b582006-01-06 00:11:45 -0800244 frame = get_sigframe(ka, sizeof(*frame));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
247 goto give_sigsegv;
248
249 rsig = sig;
250 if (sig < 32 &&
251 __current_thread_info->exec_domain &&
252 __current_thread_info->exec_domain->signal_invmap)
253 rsig = __current_thread_info->exec_domain->signal_invmap[sig];
254
255 if (__put_user(rsig, &frame->sig) < 0)
256 goto give_sigsegv;
257
258 if (setup_sigcontext(&frame->sc, set->sig[0]))
259 goto give_sigsegv;
260
261 if (_NSIG_WORDS > 1) {
262 if (__copy_to_user(frame->extramask, &set->sig[1],
263 sizeof(frame->extramask)))
264 goto give_sigsegv;
265 }
266
267 /* Set up to return from userspace. If provided, use a stub
268 * already in userspace. */
269 if (ka->sa.sa_flags & SA_RESTORER) {
270 if (__put_user(ka->sa.sa_restorer, &frame->pretcode) < 0)
271 goto give_sigsegv;
272 }
273 else {
274 /* Set up the following code on the stack:
275 * setlos #__NR_sigreturn,gr7
276 * tira gr0,0
277 */
Al Viro9e4d11f2006-06-23 02:04:04 -0700278 if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 __put_user(0x8efc0000|__NR_sigreturn, &frame->retcode[0]) ||
280 __put_user(0xc0700000, &frame->retcode[1]))
281 goto give_sigsegv;
282
283 flush_icache_range((unsigned long) frame->retcode,
284 (unsigned long) (frame->retcode + 2));
285 }
286
Al Viro5f4ad042010-09-20 15:13:09 +0100287 /* Set up registers for the signal handler */
WANG Congecd0fa92008-04-29 00:59:15 -0700288 if (current->personality & FDPIC_FUNCPTRS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 struct fdpic_func_descriptor __user *funcptr =
Al Viro9e4d11f2006-06-23 02:04:04 -0700290 (struct fdpic_func_descriptor __user *) ka->sa.sa_handler;
Al Viro5f4ad042010-09-20 15:13:09 +0100291 struct fdpic_func_descriptor desc;
292 if (copy_from_user(&desc, funcptr, sizeof(desc)))
293 goto give_sigsegv;
294 __frame->pc = desc.text;
295 __frame->gr15 = desc.GOT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 } else {
David Howellsfef2b582006-01-06 00:11:45 -0800297 __frame->pc = (unsigned long) ka->sa.sa_handler;
298 __frame->gr15 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 }
300
Al Viro5f4ad042010-09-20 15:13:09 +0100301 __frame->sp = (unsigned long) frame;
302 __frame->lr = (unsigned long) &frame->retcode;
303 __frame->gr8 = sig;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
David Howells8efc0ab2006-01-06 00:11:44 -0800305 /* the tracer may want to single-step inside the handler */
306 if (test_thread_flag(TIF_SINGLESTEP))
307 ptrace_notify(SIGTRAP);
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309#if DEBUG_SIG
310 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
David Howellsfef2b582006-01-06 00:11:45 -0800311 sig, current->comm, current->pid, frame, __frame->pc,
David Howells8efc0ab2006-01-06 00:11:44 -0800312 frame->pretcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#endif
314
David Howellsa411aee2006-01-18 17:43:59 -0800315 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317give_sigsegv:
Al Viroad0acab2010-09-20 15:13:14 +0100318 force_sigsegv(sig, current);
David Howellsa411aee2006-01-18 17:43:59 -0800319 return -EFAULT;
David Howells8efc0ab2006-01-06 00:11:44 -0800320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321} /* end setup_frame() */
322
323/*****************************************************************************/
324/*
325 *
326 */
David Howells8efc0ab2006-01-06 00:11:44 -0800327static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
David Howellsfef2b582006-01-06 00:11:45 -0800328 sigset_t *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
330 struct rt_sigframe __user *frame;
331 int rsig;
332
Al Viro5f4ad042010-09-20 15:13:09 +0100333 set_fs(USER_DS);
334
David Howellsfef2b582006-01-06 00:11:45 -0800335 frame = get_sigframe(ka, sizeof(*frame));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
338 goto give_sigsegv;
339
340 rsig = sig;
341 if (sig < 32 &&
342 __current_thread_info->exec_domain &&
343 __current_thread_info->exec_domain->signal_invmap)
344 rsig = __current_thread_info->exec_domain->signal_invmap[sig];
345
346 if (__put_user(rsig, &frame->sig) ||
347 __put_user(&frame->info, &frame->pinfo) ||
348 __put_user(&frame->uc, &frame->puc))
349 goto give_sigsegv;
350
351 if (copy_siginfo_to_user(&frame->info, info))
352 goto give_sigsegv;
353
354 /* Create the ucontext. */
355 if (__put_user(0, &frame->uc.uc_flags) ||
Al Viro9e4d11f2006-06-23 02:04:04 -0700356 __put_user(NULL, &frame->uc.uc_link) ||
357 __put_user((void __user *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp) ||
David Howellsfef2b582006-01-06 00:11:45 -0800358 __put_user(sas_ss_flags(__frame->sp), &frame->uc.uc_stack.ss_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size))
360 goto give_sigsegv;
361
362 if (setup_sigcontext(&frame->uc.uc_mcontext, set->sig[0]))
363 goto give_sigsegv;
364
365 if (__copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)))
366 goto give_sigsegv;
367
368 /* Set up to return from userspace. If provided, use a stub
369 * already in userspace. */
370 if (ka->sa.sa_flags & SA_RESTORER) {
371 if (__put_user(ka->sa.sa_restorer, &frame->pretcode))
372 goto give_sigsegv;
373 }
374 else {
375 /* Set up the following code on the stack:
376 * setlos #__NR_sigreturn,gr7
377 * tira gr0,0
378 */
Al Viro9e4d11f2006-06-23 02:04:04 -0700379 if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 __put_user(0x8efc0000|__NR_rt_sigreturn, &frame->retcode[0]) ||
381 __put_user(0xc0700000, &frame->retcode[1]))
382 goto give_sigsegv;
383
384 flush_icache_range((unsigned long) frame->retcode,
385 (unsigned long) (frame->retcode + 2));
386 }
387
388 /* Set up registers for signal handler */
WANG Congecd0fa92008-04-29 00:59:15 -0700389 if (current->personality & FDPIC_FUNCPTRS) {
Al Viro9e4d11f2006-06-23 02:04:04 -0700390 struct fdpic_func_descriptor __user *funcptr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 (struct fdpic_func_descriptor __user *) ka->sa.sa_handler;
Al Viro5f4ad042010-09-20 15:13:09 +0100392 struct fdpic_func_descriptor desc;
393 if (copy_from_user(&desc, funcptr, sizeof(desc)))
394 goto give_sigsegv;
395 __frame->pc = desc.text;
396 __frame->gr15 = desc.GOT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 } else {
David Howellsfef2b582006-01-06 00:11:45 -0800398 __frame->pc = (unsigned long) ka->sa.sa_handler;
399 __frame->gr15 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 }
401
Al Viro5f4ad042010-09-20 15:13:09 +0100402 __frame->sp = (unsigned long) frame;
403 __frame->lr = (unsigned long) &frame->retcode;
404 __frame->gr8 = sig;
405 __frame->gr9 = (unsigned long) &frame->info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
David Howells8efc0ab2006-01-06 00:11:44 -0800407 /* the tracer may want to single-step inside the handler */
408 if (test_thread_flag(TIF_SINGLESTEP))
409 ptrace_notify(SIGTRAP);
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#if DEBUG_SIG
412 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
David Howellsfef2b582006-01-06 00:11:45 -0800413 sig, current->comm, current->pid, frame, __frame->pc,
David Howells8efc0ab2006-01-06 00:11:44 -0800414 frame->pretcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#endif
416
David Howellsa411aee2006-01-18 17:43:59 -0800417 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419give_sigsegv:
Al Viroad0acab2010-09-20 15:13:14 +0100420 force_sigsegv(sig, current);
David Howellsa411aee2006-01-18 17:43:59 -0800421 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423} /* end setup_rt_frame() */
424
425/*****************************************************************************/
426/*
427 * OK, we're invoking a handler
428 */
David Howells8efc0ab2006-01-06 00:11:44 -0800429static int handle_signal(unsigned long sig, siginfo_t *info,
Al Virob7f9a112012-05-02 09:59:21 -0400430 struct k_sigaction *ka)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
Al Virob7f9a112012-05-02 09:59:21 -0400432 sigset_t *oldset = sigmask_to_save();
David Howells8efc0ab2006-01-06 00:11:44 -0800433 int ret;
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 /* Are we from a system call? */
Al Viroed1cde62010-09-20 15:13:25 +0100436 if (__frame->syscallno != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 /* If so, check system call restarting.. */
David Howellsfef2b582006-01-06 00:11:45 -0800438 switch (__frame->gr8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 case -ERESTART_RESTARTBLOCK:
440 case -ERESTARTNOHAND:
David Howellsfef2b582006-01-06 00:11:45 -0800441 __frame->gr8 = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 break;
443
444 case -ERESTARTSYS:
445 if (!(ka->sa.sa_flags & SA_RESTART)) {
David Howellsfef2b582006-01-06 00:11:45 -0800446 __frame->gr8 = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 break;
448 }
David Howells8efc0ab2006-01-06 00:11:44 -0800449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 /* fallthrough */
451 case -ERESTARTNOINTR:
David Howellsfef2b582006-01-06 00:11:45 -0800452 __frame->gr8 = __frame->orig_gr8;
453 __frame->pc -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
Al Viroed1cde62010-09-20 15:13:25 +0100455 __frame->syscallno = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
457
458 /* Set up the stack frame */
459 if (ka->sa.sa_flags & SA_SIGINFO)
David Howellsfef2b582006-01-06 00:11:45 -0800460 ret = setup_rt_frame(sig, ka, info, oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 else
David Howellsfef2b582006-01-06 00:11:45 -0800462 ret = setup_frame(sig, ka, oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Matt Fleming7ebe0c52012-05-11 10:58:52 +1000464 if (ret == 0)
465 block_sigmask(ka, sig);
David Howells8efc0ab2006-01-06 00:11:44 -0800466
467 return ret;
468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469} /* end handle_signal() */
470
471/*****************************************************************************/
472/*
473 * Note that 'init' is a special process: it doesn't get signals it doesn't
474 * want to handle. Thus you cannot kill init even with a SIGKILL even by
475 * mistake.
476 */
David Howellsa411aee2006-01-18 17:43:59 -0800477static void do_signal(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
479 struct k_sigaction ka;
480 siginfo_t info;
David Howellsa411aee2006-01-18 17:43:59 -0800481 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 int signr;
483
484 /*
485 * We want the common case to go fast, which
486 * is why we may in certain cases get here from
487 * kernel mode. Just return without doing anything
488 * if so.
489 */
David Howellsfef2b582006-01-06 00:11:45 -0800490 if (!user_mode(__frame))
David Howellsa411aee2006-01-18 17:43:59 -0800491 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Christoph Lameter3e1d1d22005-06-24 23:13:50 -0700493 if (try_to_freeze())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 goto no_signal;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
David Howellsfef2b582006-01-06 00:11:45 -0800496 signr = get_signal_to_deliver(&info, &ka, __frame, NULL);
David Howellsa411aee2006-01-18 17:43:59 -0800497 if (signr > 0) {
Al Virob7f9a112012-05-02 09:59:21 -0400498 if (handle_signal(signr, &info, &ka) == 0) {
David Howellsa411aee2006-01-18 17:43:59 -0800499 /* a signal was successfully delivered; the saved
500 * sigmask will have been stored in the signal frame,
501 * and will be restored by sigreturn, so we can simply
502 * clear the TIF_RESTORE_SIGMASK flag */
503 if (test_thread_flag(TIF_RESTORE_SIGMASK))
504 clear_thread_flag(TIF_RESTORE_SIGMASK);
David Howells4a3b9892009-06-11 13:05:24 +0100505
506 tracehook_signal_handler(signr, &info, &ka, __frame,
507 test_thread_flag(TIF_SINGLESTEP));
David Howellsa411aee2006-01-18 17:43:59 -0800508 }
509
510 return;
511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
David Howells8efc0ab2006-01-06 00:11:44 -0800513no_signal:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 /* Did we come from a system call? */
Roel Kluinc896a2e2009-10-26 16:50:23 -0700515 if (__frame->syscallno != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 /* Restart the system call - no handlers present */
David Howellsa411aee2006-01-18 17:43:59 -0800517 switch (__frame->gr8) {
518 case -ERESTARTNOHAND:
519 case -ERESTARTSYS:
520 case -ERESTARTNOINTR:
David Howellsfef2b582006-01-06 00:11:45 -0800521 __frame->gr8 = __frame->orig_gr8;
522 __frame->pc -= 4;
David Howellsa411aee2006-01-18 17:43:59 -0800523 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
David Howellsa411aee2006-01-18 17:43:59 -0800525 case -ERESTART_RESTARTBLOCK:
Al Viro44c7aff2010-09-20 15:13:19 +0100526 __frame->gr7 = __NR_restart_syscall;
David Howellsfef2b582006-01-06 00:11:45 -0800527 __frame->pc -= 4;
David Howellsa411aee2006-01-18 17:43:59 -0800528 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 }
Al Viroed1cde62010-09-20 15:13:25 +0100530 __frame->syscallno = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 }
532
David Howellsa411aee2006-01-18 17:43:59 -0800533 /* if there's no signal to deliver, we just put the saved sigmask
534 * back */
Al Viro51a7b442012-05-21 23:33:55 -0400535 restore_saved_sigmask();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536} /* end do_signal() */
537
538/*****************************************************************************/
539/*
540 * notification of userspace execution resumption
David Howellsa411aee2006-01-18 17:43:59 -0800541 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 */
543asmlinkage void do_notify_resume(__u32 thread_info_flags)
544{
545 /* pending single-step? */
546 if (thread_info_flags & _TIF_SINGLESTEP)
547 clear_thread_flag(TIF_SINGLESTEP);
548
549 /* deal with pending signal delivery */
David Howellsa411aee2006-01-18 17:43:59 -0800550 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
551 do_signal();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
David Howellsb7bab882009-06-11 13:05:14 +0100553 /* deal with notification on about to resume userspace execution */
554 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
555 clear_thread_flag(TIF_NOTIFY_RESUME);
David Howells4a3b9892009-06-11 13:05:24 +0100556 tracehook_notify_resume(__frame);
David Howellsb7bab882009-06-11 13:05:14 +0100557 }
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559} /* end do_notify_resume() */