blob: 9f1e1768e4a696cb65a425a1adf76aa222ae92b6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/kernel/signal.c
3 *
4 * Copyright (C) 1995-2002 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/config.h>
11#include <linux/errno.h>
12#include <linux/signal.h>
13#include <linux/ptrace.h>
14#include <linux/personality.h>
15
16#include <asm/cacheflush.h>
17#include <asm/ucontext.h>
18#include <asm/uaccess.h>
19#include <asm/unistd.h>
20
21#include "ptrace.h"
Russell Kinge00d3492005-06-22 20:26:05 +010022#include "signal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
25
26/*
27 * For ARM syscalls, we encode the syscall number into the instruction.
28 */
29#define SWI_SYS_SIGRETURN (0xef000000|(__NR_sigreturn))
30#define SWI_SYS_RT_SIGRETURN (0xef000000|(__NR_rt_sigreturn))
31
32/*
Nicolas Pitrefcca5382006-01-18 22:38:47 +000033 * With EABI, the syscall number has to be loaded into r7.
34 */
35#define MOV_R7_NR_SIGRETURN (0xe3a07000 | (__NR_sigreturn - __NR_SYSCALL_BASE))
36#define MOV_R7_NR_RT_SIGRETURN (0xe3a07000 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
37
38/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * For Thumb syscalls, we pass the syscall number via r7. We therefore
40 * need two 16-bit instructions.
41 */
42#define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (__NR_sigreturn - __NR_SYSCALL_BASE))
43#define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
44
Nicolas Pitrefcca5382006-01-18 22:38:47 +000045const unsigned long sigreturn_codes[7] = {
46 MOV_R7_NR_SIGRETURN, SWI_SYS_SIGRETURN, SWI_THUMB_SIGRETURN,
47 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
Linus Torvalds1da177e2005-04-16 15:20:36 -070048};
49
50static int do_signal(sigset_t *oldset, struct pt_regs * regs, int syscall);
51
52/*
53 * atomically swap in the new signal mask, and wait for a signal.
54 */
55asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, old_sigset_t mask, struct pt_regs *regs)
56{
57 sigset_t saveset;
58
59 mask &= _BLOCKABLE;
60 spin_lock_irq(&current->sighand->siglock);
61 saveset = current->blocked;
62 siginitset(&current->blocked, mask);
63 recalc_sigpending();
64 spin_unlock_irq(&current->sighand->siglock);
65 regs->ARM_r0 = -EINTR;
66
67 while (1) {
68 current->state = TASK_INTERRUPTIBLE;
69 schedule();
70 if (do_signal(&saveset, regs, 0))
71 return regs->ARM_r0;
72 }
73}
74
75asmlinkage int
76sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize, struct pt_regs *regs)
77{
78 sigset_t saveset, newset;
79
80 /* XXX: Don't preclude handling different sized sigset_t's. */
81 if (sigsetsize != sizeof(sigset_t))
82 return -EINVAL;
83
84 if (copy_from_user(&newset, unewset, sizeof(newset)))
85 return -EFAULT;
86 sigdelsetmask(&newset, ~_BLOCKABLE);
87
88 spin_lock_irq(&current->sighand->siglock);
89 saveset = current->blocked;
90 current->blocked = newset;
91 recalc_sigpending();
92 spin_unlock_irq(&current->sighand->siglock);
93 regs->ARM_r0 = -EINTR;
94
95 while (1) {
96 current->state = TASK_INTERRUPTIBLE;
97 schedule();
98 if (do_signal(&saveset, regs, 0))
99 return regs->ARM_r0;
100 }
101}
102
103asmlinkage int
104sys_sigaction(int sig, const struct old_sigaction __user *act,
105 struct old_sigaction __user *oact)
106{
107 struct k_sigaction new_ka, old_ka;
108 int ret;
109
110 if (act) {
111 old_sigset_t mask;
112 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
113 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
114 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
115 return -EFAULT;
116 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
117 __get_user(mask, &act->sa_mask);
118 siginitset(&new_ka.sa.sa_mask, mask);
119 }
120
121 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
122
123 if (!ret && oact) {
124 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
125 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
126 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
127 return -EFAULT;
128 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
129 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
130 }
131
132 return ret;
133}
134
135#ifdef CONFIG_IWMMXT
136
137/* iwmmxt_area is 0x98 bytes long, preceeded by 8 bytes of signature */
138#define IWMMXT_STORAGE_SIZE (0x98 + 8)
139#define IWMMXT_MAGIC0 0x12ef842a
140#define IWMMXT_MAGIC1 0x1c07ca71
141
142struct iwmmxt_sigframe {
143 unsigned long magic0;
144 unsigned long magic1;
145 unsigned long storage[0x98/4];
146};
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static int preserve_iwmmxt_context(struct iwmmxt_sigframe *frame)
149{
Hugh Dickins69b04752005-10-29 18:16:36 -0700150 char kbuf[sizeof(*frame) + 8];
151 struct iwmmxt_sigframe *kframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* the iWMMXt context must be 64 bit aligned */
Hugh Dickins69b04752005-10-29 18:16:36 -0700154 kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
155 kframe->magic0 = IWMMXT_MAGIC0;
156 kframe->magic1 = IWMMXT_MAGIC1;
157 iwmmxt_task_copy(current_thread_info(), &kframe->storage);
158 return __copy_to_user(frame, kframe, sizeof(*frame));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame)
162{
Hugh Dickins69b04752005-10-29 18:16:36 -0700163 char kbuf[sizeof(*frame) + 8];
164 struct iwmmxt_sigframe *kframe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Hugh Dickins69b04752005-10-29 18:16:36 -0700166 /* the iWMMXt context must be 64 bit aligned */
167 kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
168 if (__copy_from_user(kframe, frame, sizeof(*frame)))
169 return -1;
170 if (kframe->magic0 != IWMMXT_MAGIC0 ||
171 kframe->magic1 != IWMMXT_MAGIC1)
172 return -1;
173 iwmmxt_task_restore(current_thread_info(), &kframe->storage);
174 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
176
177#endif
178
179/*
180 * Auxiliary signal frame. This saves stuff like FP state.
181 * The layout of this structure is not part of the user ABI.
182 */
183struct aux_sigframe {
184#ifdef CONFIG_IWMMXT
185 struct iwmmxt_sigframe iwmmxt;
186#endif
187#ifdef CONFIG_VFP
188 union vfp_state vfp;
189#endif
190};
191
192/*
193 * Do a signal return; undo the signal stack. These are aligned to 64-bit.
194 */
195struct sigframe {
Russell King7d4fdc12006-06-15 20:13:25 +0100196 struct ucontext uc;
Nicolas Pitrefcca5382006-01-18 22:38:47 +0000197 unsigned long retcode[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 struct aux_sigframe aux __attribute__((aligned(8)));
199};
200
201struct rt_sigframe {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 struct siginfo info;
203 struct ucontext uc;
Nicolas Pitrefcca5382006-01-18 22:38:47 +0000204 unsigned long retcode[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 struct aux_sigframe aux __attribute__((aligned(8)));
206};
207
208static int
209restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
210 struct aux_sigframe __user *aux)
211{
212 int err = 0;
213
214 __get_user_error(regs->ARM_r0, &sc->arm_r0, err);
215 __get_user_error(regs->ARM_r1, &sc->arm_r1, err);
216 __get_user_error(regs->ARM_r2, &sc->arm_r2, err);
217 __get_user_error(regs->ARM_r3, &sc->arm_r3, err);
218 __get_user_error(regs->ARM_r4, &sc->arm_r4, err);
219 __get_user_error(regs->ARM_r5, &sc->arm_r5, err);
220 __get_user_error(regs->ARM_r6, &sc->arm_r6, err);
221 __get_user_error(regs->ARM_r7, &sc->arm_r7, err);
222 __get_user_error(regs->ARM_r8, &sc->arm_r8, err);
223 __get_user_error(regs->ARM_r9, &sc->arm_r9, err);
224 __get_user_error(regs->ARM_r10, &sc->arm_r10, err);
225 __get_user_error(regs->ARM_fp, &sc->arm_fp, err);
226 __get_user_error(regs->ARM_ip, &sc->arm_ip, err);
227 __get_user_error(regs->ARM_sp, &sc->arm_sp, err);
228 __get_user_error(regs->ARM_lr, &sc->arm_lr, err);
229 __get_user_error(regs->ARM_pc, &sc->arm_pc, err);
230 __get_user_error(regs->ARM_cpsr, &sc->arm_cpsr, err);
231
232 err |= !valid_user_regs(regs);
233
234#ifdef CONFIG_IWMMXT
235 if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
236 err |= restore_iwmmxt_context(&aux->iwmmxt);
237#endif
238#ifdef CONFIG_VFP
239// if (err == 0)
240// err |= vfp_restore_state(&aux->vfp);
241#endif
242
243 return err;
244}
245
246asmlinkage int sys_sigreturn(struct pt_regs *regs)
247{
248 struct sigframe __user *frame;
249 sigset_t set;
250
251 /* Always make any pending restarted system calls return -EINTR */
252 current_thread_info()->restart_block.fn = do_no_restart_syscall;
253
254 /*
255 * Since we stacked the signal on a 64-bit boundary,
256 * then 'sp' should be word aligned here. If it's
257 * not, then the user is trying to mess with us.
258 */
259 if (regs->ARM_sp & 7)
260 goto badframe;
261
262 frame = (struct sigframe __user *)regs->ARM_sp;
263
264 if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
265 goto badframe;
Russell King7d4fdc12006-06-15 20:13:25 +0100266 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 goto badframe;
268
269 sigdelsetmask(&set, ~_BLOCKABLE);
270 spin_lock_irq(&current->sighand->siglock);
271 current->blocked = set;
272 recalc_sigpending();
273 spin_unlock_irq(&current->sighand->siglock);
274
Russell King7d4fdc12006-06-15 20:13:25 +0100275 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &frame->aux))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 goto badframe;
277
278 /* Send SIGTRAP if we're single-stepping */
279 if (current->ptrace & PT_SINGLESTEP) {
280 ptrace_cancel_bpt(current);
281 send_sig(SIGTRAP, current, 1);
282 }
283
284 return regs->ARM_r0;
285
286badframe:
287 force_sig(SIGSEGV, current);
288 return 0;
289}
290
291asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
292{
293 struct rt_sigframe __user *frame;
294 sigset_t set;
295
296 /* Always make any pending restarted system calls return -EINTR */
297 current_thread_info()->restart_block.fn = do_no_restart_syscall;
298
299 /*
300 * Since we stacked the signal on a 64-bit boundary,
301 * then 'sp' should be word aligned here. If it's
302 * not, then the user is trying to mess with us.
303 */
304 if (regs->ARM_sp & 7)
305 goto badframe;
306
307 frame = (struct rt_sigframe __user *)regs->ARM_sp;
308
309 if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
310 goto badframe;
311 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
312 goto badframe;
313
314 sigdelsetmask(&set, ~_BLOCKABLE);
315 spin_lock_irq(&current->sighand->siglock);
316 current->blocked = set;
317 recalc_sigpending();
318 spin_unlock_irq(&current->sighand->siglock);
319
320 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &frame->aux))
321 goto badframe;
322
323 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->ARM_sp) == -EFAULT)
324 goto badframe;
325
326 /* Send SIGTRAP if we're single-stepping */
327 if (current->ptrace & PT_SINGLESTEP) {
328 ptrace_cancel_bpt(current);
329 send_sig(SIGTRAP, current, 1);
330 }
331
332 return regs->ARM_r0;
333
334badframe:
335 force_sig(SIGSEGV, current);
336 return 0;
337}
338
339static int
340setup_sigcontext(struct sigcontext __user *sc, struct aux_sigframe __user *aux,
341 struct pt_regs *regs, unsigned long mask)
342{
343 int err = 0;
344
345 __put_user_error(regs->ARM_r0, &sc->arm_r0, err);
346 __put_user_error(regs->ARM_r1, &sc->arm_r1, err);
347 __put_user_error(regs->ARM_r2, &sc->arm_r2, err);
348 __put_user_error(regs->ARM_r3, &sc->arm_r3, err);
349 __put_user_error(regs->ARM_r4, &sc->arm_r4, err);
350 __put_user_error(regs->ARM_r5, &sc->arm_r5, err);
351 __put_user_error(regs->ARM_r6, &sc->arm_r6, err);
352 __put_user_error(regs->ARM_r7, &sc->arm_r7, err);
353 __put_user_error(regs->ARM_r8, &sc->arm_r8, err);
354 __put_user_error(regs->ARM_r9, &sc->arm_r9, err);
355 __put_user_error(regs->ARM_r10, &sc->arm_r10, err);
356 __put_user_error(regs->ARM_fp, &sc->arm_fp, err);
357 __put_user_error(regs->ARM_ip, &sc->arm_ip, err);
358 __put_user_error(regs->ARM_sp, &sc->arm_sp, err);
359 __put_user_error(regs->ARM_lr, &sc->arm_lr, err);
360 __put_user_error(regs->ARM_pc, &sc->arm_pc, err);
361 __put_user_error(regs->ARM_cpsr, &sc->arm_cpsr, err);
362
363 __put_user_error(current->thread.trap_no, &sc->trap_no, err);
364 __put_user_error(current->thread.error_code, &sc->error_code, err);
365 __put_user_error(current->thread.address, &sc->fault_address, err);
366 __put_user_error(mask, &sc->oldmask, err);
367
368#ifdef CONFIG_IWMMXT
369 if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
370 err |= preserve_iwmmxt_context(&aux->iwmmxt);
371#endif
372#ifdef CONFIG_VFP
373// if (err == 0)
374// err |= vfp_save_state(&aux->vfp);
375#endif
376
377 return err;
378}
379
380static inline void __user *
381get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, int framesize)
382{
383 unsigned long sp = regs->ARM_sp;
384 void __user *frame;
385
386 /*
387 * This is the X/Open sanctioned signal stack switching.
388 */
389 if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
390 sp = current->sas_ss_sp + current->sas_ss_size;
391
392 /*
393 * ATPCS B01 mandates 8-byte alignment
394 */
395 frame = (void __user *)((sp - framesize) & ~7);
396
397 /*
398 * Check that we can actually write to the signal frame.
399 */
400 if (!access_ok(VERIFY_WRITE, frame, framesize))
401 frame = NULL;
402
403 return frame;
404}
405
406static int
407setup_return(struct pt_regs *regs, struct k_sigaction *ka,
408 unsigned long __user *rc, void __user *frame, int usig)
409{
410 unsigned long handler = (unsigned long)ka->sa.sa_handler;
411 unsigned long retcode;
412 int thumb = 0;
413 unsigned long cpsr = regs->ARM_cpsr & ~PSR_f;
414
415 /*
416 * Maybe we need to deliver a 32-bit signal to a 26-bit task.
417 */
418 if (ka->sa.sa_flags & SA_THIRTYTWO)
419 cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
420
421#ifdef CONFIG_ARM_THUMB
422 if (elf_hwcap & HWCAP_THUMB) {
423 /*
424 * The LSB of the handler determines if we're going to
425 * be using THUMB or ARM mode for this signal handler.
426 */
427 thumb = handler & 1;
428
429 if (thumb)
430 cpsr |= PSR_T_BIT;
431 else
432 cpsr &= ~PSR_T_BIT;
433 }
434#endif
435
436 if (ka->sa.sa_flags & SA_RESTORER) {
437 retcode = (unsigned long)ka->sa.sa_restorer;
438 } else {
Nicolas Pitrefcca5382006-01-18 22:38:47 +0000439 unsigned int idx = thumb << 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 if (ka->sa.sa_flags & SA_SIGINFO)
Nicolas Pitrefcca5382006-01-18 22:38:47 +0000442 idx += 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Nicolas Pitrefcca5382006-01-18 22:38:47 +0000444 if (__put_user(sigreturn_codes[idx], rc) ||
445 __put_user(sigreturn_codes[idx+1], rc+1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return 1;
447
Russell Kinge00d3492005-06-22 20:26:05 +0100448 if (cpsr & MODE32_BIT) {
449 /*
450 * 32-bit code can use the new high-page
451 * signal return code support.
452 */
453 retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
454 } else {
455 /*
456 * Ensure that the instruction cache sees
457 * the return code written onto the stack.
458 */
459 flush_icache_range((unsigned long)rc,
Nicolas Pitrefcca5382006-01-18 22:38:47 +0000460 (unsigned long)(rc + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Russell Kinge00d3492005-06-22 20:26:05 +0100462 retcode = ((unsigned long)rc) + thumb;
463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 }
465
466 regs->ARM_r0 = usig;
467 regs->ARM_sp = (unsigned long)frame;
468 regs->ARM_lr = retcode;
469 regs->ARM_pc = handler;
470 regs->ARM_cpsr = cpsr;
471
472 return 0;
473}
474
475static int
476setup_frame(int usig, struct k_sigaction *ka, sigset_t *set, struct pt_regs *regs)
477{
478 struct sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
479 int err = 0;
480
481 if (!frame)
482 return 1;
483
Russell King7d4fdc12006-06-15 20:13:25 +0100484 err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->aux, regs, set->sig[0]);
485 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 if (err == 0)
Nicolas Pitrefcca5382006-01-18 22:38:47 +0000488 err = setup_return(regs, ka, frame->retcode, frame, usig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 return err;
491}
492
493static int
494setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
495 sigset_t *set, struct pt_regs *regs)
496{
497 struct rt_sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
498 stack_t stack;
499 int err = 0;
500
501 if (!frame)
502 return 1;
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 err |= copy_siginfo_to_user(&frame->info, info);
505
506 __put_user_error(0, &frame->uc.uc_flags, err);
507 __put_user_error(NULL, &frame->uc.uc_link, err);
508
509 memset(&stack, 0, sizeof(stack));
510 stack.ss_sp = (void __user *)current->sas_ss_sp;
511 stack.ss_flags = sas_ss_flags(regs->ARM_sp);
512 stack.ss_size = current->sas_ss_size;
513 err |= __copy_to_user(&frame->uc.uc_stack, &stack, sizeof(stack));
514
515 err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->aux,
516 regs, set->sig[0]);
517 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
518
519 if (err == 0)
Nicolas Pitrefcca5382006-01-18 22:38:47 +0000520 err = setup_return(regs, ka, frame->retcode, frame, usig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 if (err == 0) {
523 /*
524 * For realtime signals we must also set the second and third
525 * arguments for the signal handler.
526 * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
527 */
528 regs->ARM_r1 = (unsigned long)&frame->info;
529 regs->ARM_r2 = (unsigned long)&frame->uc;
530 }
531
532 return err;
533}
534
535static inline void restart_syscall(struct pt_regs *regs)
536{
537 regs->ARM_r0 = regs->ARM_ORIG_r0;
538 regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;
539}
540
541/*
542 * OK, we're invoking a handler
543 */
544static void
545handle_signal(unsigned long sig, struct k_sigaction *ka,
546 siginfo_t *info, sigset_t *oldset,
547 struct pt_regs * regs, int syscall)
548{
549 struct thread_info *thread = current_thread_info();
550 struct task_struct *tsk = current;
551 int usig = sig;
552 int ret;
553
554 /*
555 * If we were from a system call, check for system call restarting...
556 */
557 if (syscall) {
558 switch (regs->ARM_r0) {
559 case -ERESTART_RESTARTBLOCK:
560 case -ERESTARTNOHAND:
561 regs->ARM_r0 = -EINTR;
562 break;
563 case -ERESTARTSYS:
564 if (!(ka->sa.sa_flags & SA_RESTART)) {
565 regs->ARM_r0 = -EINTR;
566 break;
567 }
568 /* fallthrough */
569 case -ERESTARTNOINTR:
570 restart_syscall(regs);
571 }
572 }
573
574 /*
575 * translate the signal
576 */
577 if (usig < 32 && thread->exec_domain && thread->exec_domain->signal_invmap)
578 usig = thread->exec_domain->signal_invmap[usig];
579
580 /*
581 * Set up the stack frame
582 */
583 if (ka->sa.sa_flags & SA_SIGINFO)
584 ret = setup_rt_frame(usig, ka, info, oldset, regs);
585 else
586 ret = setup_frame(usig, ka, oldset, regs);
587
588 /*
589 * Check that the resulting registers are actually sane.
590 */
591 ret |= !valid_user_regs(regs);
592
Steven Rostedt69be8f12005-08-29 11:44:09 -0400593 if (ret != 0) {
Daniel Jacobowitza6c61e92005-11-19 10:01:07 +0000594 force_sigsegv(sig, tsk);
595 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
597
Daniel Jacobowitza6c61e92005-11-19 10:01:07 +0000598 /*
599 * Block the signal if we were successful.
600 */
601 spin_lock_irq(&tsk->sighand->siglock);
602 sigorsets(&tsk->blocked, &tsk->blocked,
603 &ka->sa.sa_mask);
604 if (!(ka->sa.sa_flags & SA_NODEFER))
605 sigaddset(&tsk->blocked, sig);
606 recalc_sigpending();
607 spin_unlock_irq(&tsk->sighand->siglock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
610
611/*
612 * Note that 'init' is a special process: it doesn't get signals it doesn't
613 * want to handle. Thus you cannot kill init even with a SIGKILL even by
614 * mistake.
615 *
616 * Note that we go through the signals twice: once to check the signals that
617 * the kernel can handle, and then we build all the user-level signal handling
618 * stack-frames in one go after that.
619 */
620static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
621{
622 struct k_sigaction ka;
623 siginfo_t info;
624 int signr;
625
626 /*
627 * We want the common case to go fast, which
628 * is why we may in certain cases get here from
629 * kernel mode. Just return without doing anything
630 * if so.
631 */
632 if (!user_mode(regs))
633 return 0;
634
Andrew Mortonbdb94f32005-06-26 03:27:21 -0700635 if (try_to_freeze())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 goto no_signal;
637
638 if (current->ptrace & PT_SINGLESTEP)
639 ptrace_cancel_bpt(current);
640
641 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
642 if (signr > 0) {
643 handle_signal(signr, &ka, &info, oldset, regs, syscall);
644 if (current->ptrace & PT_SINGLESTEP)
645 ptrace_set_bpt(current);
646 return 1;
647 }
648
649 no_signal:
650 /*
651 * No signal to deliver to the process - restart the syscall.
652 */
653 if (syscall) {
654 if (regs->ARM_r0 == -ERESTART_RESTARTBLOCK) {
655 if (thumb_mode(regs)) {
656 regs->ARM_r7 = __NR_restart_syscall;
657 regs->ARM_pc -= 2;
658 } else {
659 u32 __user *usp;
660
661 regs->ARM_sp -= 12;
662 usp = (u32 __user *)regs->ARM_sp;
663
664 put_user(regs->ARM_pc, &usp[0]);
665 /* swi __NR_restart_syscall */
666 put_user(0xef000000 | __NR_restart_syscall, &usp[1]);
667 /* ldr pc, [sp], #12 */
668 put_user(0xe49df00c, &usp[2]);
669
670 flush_icache_range((unsigned long)usp,
671 (unsigned long)(usp + 3));
672
673 regs->ARM_pc = regs->ARM_sp + 4;
674 }
675 }
676 if (regs->ARM_r0 == -ERESTARTNOHAND ||
677 regs->ARM_r0 == -ERESTARTSYS ||
678 regs->ARM_r0 == -ERESTARTNOINTR) {
679 restart_syscall(regs);
680 }
681 }
682 if (current->ptrace & PT_SINGLESTEP)
683 ptrace_set_bpt(current);
684 return 0;
685}
686
687asmlinkage void
688do_notify_resume(struct pt_regs *regs, unsigned int thread_flags, int syscall)
689{
690 if (thread_flags & _TIF_SIGPENDING)
691 do_signal(&current->blocked, regs, syscall);
692}