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