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