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