]> err.no Git - linux-2.6/blob - arch/arm/kernel/signal.c
[ARM] Remove rt_sigframe puc and pinfo pointers
[linux-2.6] / 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/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"
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))
30 #define SWI_SYS_RT_SIGRETURN    (0xef000000|(__NR_rt_sigreturn))
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 static 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  */
55 asmlinkage 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
75 asmlinkage int
76 sys_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
103 asmlinkage int 
104 sys_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
142 struct iwmmxt_sigframe {
143         unsigned long   magic0;
144         unsigned long   magic1;
145         unsigned long   storage[0x98/4];
146 };
147
148 static int preserve_iwmmxt_context(struct iwmmxt_sigframe *frame)
149 {
150         char kbuf[sizeof(*frame) + 8];
151         struct iwmmxt_sigframe *kframe;
152
153         /* the iWMMXt context must be 64 bit aligned */
154         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));
159 }
160
161 static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame)
162 {
163         char kbuf[sizeof(*frame) + 8];
164         struct iwmmxt_sigframe *kframe;
165
166         /* 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;
175 }
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  */
183 struct 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  */
195 struct sigframe {
196         struct sigcontext sc;
197         unsigned long extramask[_NSIG_WORDS-1];
198         unsigned long retcode[2];
199         struct aux_sigframe aux __attribute__((aligned(8)));
200 };
201
202 struct rt_sigframe {
203         struct siginfo info;
204         struct ucontext uc;
205         unsigned long retcode[2];
206         struct aux_sigframe aux __attribute__((aligned(8)));
207 };
208
209 static int
210 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
211                    struct aux_sigframe __user *aux)
212 {
213         int err = 0;
214
215         __get_user_error(regs->ARM_r0, &sc->arm_r0, err);
216         __get_user_error(regs->ARM_r1, &sc->arm_r1, err);
217         __get_user_error(regs->ARM_r2, &sc->arm_r2, err);
218         __get_user_error(regs->ARM_r3, &sc->arm_r3, err);
219         __get_user_error(regs->ARM_r4, &sc->arm_r4, err);
220         __get_user_error(regs->ARM_r5, &sc->arm_r5, err);
221         __get_user_error(regs->ARM_r6, &sc->arm_r6, err);
222         __get_user_error(regs->ARM_r7, &sc->arm_r7, err);
223         __get_user_error(regs->ARM_r8, &sc->arm_r8, err);
224         __get_user_error(regs->ARM_r9, &sc->arm_r9, err);
225         __get_user_error(regs->ARM_r10, &sc->arm_r10, err);
226         __get_user_error(regs->ARM_fp, &sc->arm_fp, err);
227         __get_user_error(regs->ARM_ip, &sc->arm_ip, err);
228         __get_user_error(regs->ARM_sp, &sc->arm_sp, err);
229         __get_user_error(regs->ARM_lr, &sc->arm_lr, err);
230         __get_user_error(regs->ARM_pc, &sc->arm_pc, err);
231         __get_user_error(regs->ARM_cpsr, &sc->arm_cpsr, err);
232
233         err |= !valid_user_regs(regs);
234
235 #ifdef CONFIG_IWMMXT
236         if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
237                 err |= restore_iwmmxt_context(&aux->iwmmxt);
238 #endif
239 #ifdef CONFIG_VFP
240 //      if (err == 0)
241 //              err |= vfp_restore_state(&aux->vfp);
242 #endif
243
244         return err;
245 }
246
247 asmlinkage int sys_sigreturn(struct pt_regs *regs)
248 {
249         struct sigframe __user *frame;
250         sigset_t set;
251
252         /* Always make any pending restarted system calls return -EINTR */
253         current_thread_info()->restart_block.fn = do_no_restart_syscall;
254
255         /*
256          * Since we stacked the signal on a 64-bit boundary,
257          * then 'sp' should be word aligned here.  If it's
258          * not, then the user is trying to mess with us.
259          */
260         if (regs->ARM_sp & 7)
261                 goto badframe;
262
263         frame = (struct sigframe __user *)regs->ARM_sp;
264
265         if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
266                 goto badframe;
267         if (__get_user(set.sig[0], &frame->sc.oldmask)
268             || (_NSIG_WORDS > 1
269                 && __copy_from_user(&set.sig[1], &frame->extramask,
270                                     sizeof(frame->extramask))))
271                 goto badframe;
272
273         sigdelsetmask(&set, ~_BLOCKABLE);
274         spin_lock_irq(&current->sighand->siglock);
275         current->blocked = set;
276         recalc_sigpending();
277         spin_unlock_irq(&current->sighand->siglock);
278
279         if (restore_sigcontext(regs, &frame->sc, &frame->aux))
280                 goto badframe;
281
282         /* Send SIGTRAP if we're single-stepping */
283         if (current->ptrace & PT_SINGLESTEP) {
284                 ptrace_cancel_bpt(current);
285                 send_sig(SIGTRAP, current, 1);
286         }
287
288         return regs->ARM_r0;
289
290 badframe:
291         force_sig(SIGSEGV, current);
292         return 0;
293 }
294
295 asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
296 {
297         struct rt_sigframe __user *frame;
298         sigset_t set;
299
300         /* Always make any pending restarted system calls return -EINTR */
301         current_thread_info()->restart_block.fn = do_no_restart_syscall;
302
303         /*
304          * Since we stacked the signal on a 64-bit boundary,
305          * then 'sp' should be word aligned here.  If it's
306          * not, then the user is trying to mess with us.
307          */
308         if (regs->ARM_sp & 7)
309                 goto badframe;
310
311         frame = (struct rt_sigframe __user *)regs->ARM_sp;
312
313         if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
314                 goto badframe;
315         if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
316                 goto badframe;
317
318         sigdelsetmask(&set, ~_BLOCKABLE);
319         spin_lock_irq(&current->sighand->siglock);
320         current->blocked = set;
321         recalc_sigpending();
322         spin_unlock_irq(&current->sighand->siglock);
323
324         if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &frame->aux))
325                 goto badframe;
326
327         if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->ARM_sp) == -EFAULT)
328                 goto badframe;
329
330         /* Send SIGTRAP if we're single-stepping */
331         if (current->ptrace & PT_SINGLESTEP) {
332                 ptrace_cancel_bpt(current);
333                 send_sig(SIGTRAP, current, 1);
334         }
335
336         return regs->ARM_r0;
337
338 badframe:
339         force_sig(SIGSEGV, current);
340         return 0;
341 }
342
343 static int
344 setup_sigcontext(struct sigcontext __user *sc, struct aux_sigframe __user *aux,
345                  struct pt_regs *regs, unsigned long mask)
346 {
347         int err = 0;
348
349         __put_user_error(regs->ARM_r0, &sc->arm_r0, err);
350         __put_user_error(regs->ARM_r1, &sc->arm_r1, err);
351         __put_user_error(regs->ARM_r2, &sc->arm_r2, err);
352         __put_user_error(regs->ARM_r3, &sc->arm_r3, err);
353         __put_user_error(regs->ARM_r4, &sc->arm_r4, err);
354         __put_user_error(regs->ARM_r5, &sc->arm_r5, err);
355         __put_user_error(regs->ARM_r6, &sc->arm_r6, err);
356         __put_user_error(regs->ARM_r7, &sc->arm_r7, err);
357         __put_user_error(regs->ARM_r8, &sc->arm_r8, err);
358         __put_user_error(regs->ARM_r9, &sc->arm_r9, err);
359         __put_user_error(regs->ARM_r10, &sc->arm_r10, err);
360         __put_user_error(regs->ARM_fp, &sc->arm_fp, err);
361         __put_user_error(regs->ARM_ip, &sc->arm_ip, err);
362         __put_user_error(regs->ARM_sp, &sc->arm_sp, err);
363         __put_user_error(regs->ARM_lr, &sc->arm_lr, err);
364         __put_user_error(regs->ARM_pc, &sc->arm_pc, err);
365         __put_user_error(regs->ARM_cpsr, &sc->arm_cpsr, err);
366
367         __put_user_error(current->thread.trap_no, &sc->trap_no, err);
368         __put_user_error(current->thread.error_code, &sc->error_code, err);
369         __put_user_error(current->thread.address, &sc->fault_address, err);
370         __put_user_error(mask, &sc->oldmask, err);
371
372 #ifdef CONFIG_IWMMXT
373         if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
374                 err |= preserve_iwmmxt_context(&aux->iwmmxt);
375 #endif
376 #ifdef CONFIG_VFP
377 //      if (err == 0)
378 //              err |= vfp_save_state(&aux->vfp);
379 #endif
380
381         return err;
382 }
383
384 static inline void __user *
385 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, int framesize)
386 {
387         unsigned long sp = regs->ARM_sp;
388         void __user *frame;
389
390         /*
391          * This is the X/Open sanctioned signal stack switching.
392          */
393         if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
394                 sp = current->sas_ss_sp + current->sas_ss_size;
395
396         /*
397          * ATPCS B01 mandates 8-byte alignment
398          */
399         frame = (void __user *)((sp - framesize) & ~7);
400
401         /*
402          * Check that we can actually write to the signal frame.
403          */
404         if (!access_ok(VERIFY_WRITE, frame, framesize))
405                 frame = NULL;
406
407         return frame;
408 }
409
410 static int
411 setup_return(struct pt_regs *regs, struct k_sigaction *ka,
412              unsigned long __user *rc, void __user *frame, int usig)
413 {
414         unsigned long handler = (unsigned long)ka->sa.sa_handler;
415         unsigned long retcode;
416         int thumb = 0;
417         unsigned long cpsr = regs->ARM_cpsr & ~PSR_f;
418
419         /*
420          * Maybe we need to deliver a 32-bit signal to a 26-bit task.
421          */
422         if (ka->sa.sa_flags & SA_THIRTYTWO)
423                 cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
424
425 #ifdef CONFIG_ARM_THUMB
426         if (elf_hwcap & HWCAP_THUMB) {
427                 /*
428                  * The LSB of the handler determines if we're going to
429                  * be using THUMB or ARM mode for this signal handler.
430                  */
431                 thumb = handler & 1;
432
433                 if (thumb)
434                         cpsr |= PSR_T_BIT;
435                 else
436                         cpsr &= ~PSR_T_BIT;
437         }
438 #endif
439
440         if (ka->sa.sa_flags & SA_RESTORER) {
441                 retcode = (unsigned long)ka->sa.sa_restorer;
442         } else {
443                 unsigned int idx = thumb << 1;
444
445                 if (ka->sa.sa_flags & SA_SIGINFO)
446                         idx += 3;
447
448                 if (__put_user(sigreturn_codes[idx],   rc) ||
449                     __put_user(sigreturn_codes[idx+1], rc+1))
450                         return 1;
451
452                 if (cpsr & MODE32_BIT) {
453                         /*
454                          * 32-bit code can use the new high-page
455                          * signal return code support.
456                          */
457                         retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
458                 } else {
459                         /*
460                          * Ensure that the instruction cache sees
461                          * the return code written onto the stack.
462                          */
463                         flush_icache_range((unsigned long)rc,
464                                            (unsigned long)(rc + 2));
465
466                         retcode = ((unsigned long)rc) + thumb;
467                 }
468         }
469
470         regs->ARM_r0 = usig;
471         regs->ARM_sp = (unsigned long)frame;
472         regs->ARM_lr = retcode;
473         regs->ARM_pc = handler;
474         regs->ARM_cpsr = cpsr;
475
476         return 0;
477 }
478
479 static int
480 setup_frame(int usig, struct k_sigaction *ka, sigset_t *set, struct pt_regs *regs)
481 {
482         struct sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
483         int err = 0;
484
485         if (!frame)
486                 return 1;
487
488         err |= setup_sigcontext(&frame->sc, &frame->aux, regs, set->sig[0]);
489
490         if (_NSIG_WORDS > 1) {
491                 err |= __copy_to_user(frame->extramask, &set->sig[1],
492                                       sizeof(frame->extramask));
493         }
494
495         if (err == 0)
496                 err = setup_return(regs, ka, frame->retcode, frame, usig);
497
498         return err;
499 }
500
501 static int
502 setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
503                sigset_t *set, struct pt_regs *regs)
504 {
505         struct rt_sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
506         stack_t stack;
507         int err = 0;
508
509         if (!frame)
510                 return 1;
511
512         err |= copy_siginfo_to_user(&frame->info, info);
513
514         __put_user_error(0, &frame->uc.uc_flags, err);
515         __put_user_error(NULL, &frame->uc.uc_link, err);
516
517         memset(&stack, 0, sizeof(stack));
518         stack.ss_sp = (void __user *)current->sas_ss_sp;
519         stack.ss_flags = sas_ss_flags(regs->ARM_sp);
520         stack.ss_size = current->sas_ss_size;
521         err |= __copy_to_user(&frame->uc.uc_stack, &stack, sizeof(stack));
522
523         err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->aux,
524                                 regs, set->sig[0]);
525         err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
526
527         if (err == 0)
528                 err = setup_return(regs, ka, frame->retcode, frame, usig);
529
530         if (err == 0) {
531                 /*
532                  * For realtime signals we must also set the second and third
533                  * arguments for the signal handler.
534                  *   -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
535                  */
536                 regs->ARM_r1 = (unsigned long)&frame->info;
537                 regs->ARM_r2 = (unsigned long)&frame->uc;
538         }
539
540         return err;
541 }
542
543 static inline void restart_syscall(struct pt_regs *regs)
544 {
545         regs->ARM_r0 = regs->ARM_ORIG_r0;
546         regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;
547 }
548
549 /*
550  * OK, we're invoking a handler
551  */     
552 static void
553 handle_signal(unsigned long sig, struct k_sigaction *ka,
554               siginfo_t *info, sigset_t *oldset,
555               struct pt_regs * regs, int syscall)
556 {
557         struct thread_info *thread = current_thread_info();
558         struct task_struct *tsk = current;
559         int usig = sig;
560         int ret;
561
562         /*
563          * If we were from a system call, check for system call restarting...
564          */
565         if (syscall) {
566                 switch (regs->ARM_r0) {
567                 case -ERESTART_RESTARTBLOCK:
568                 case -ERESTARTNOHAND:
569                         regs->ARM_r0 = -EINTR;
570                         break;
571                 case -ERESTARTSYS:
572                         if (!(ka->sa.sa_flags & SA_RESTART)) {
573                                 regs->ARM_r0 = -EINTR;
574                                 break;
575                         }
576                         /* fallthrough */
577                 case -ERESTARTNOINTR:
578                         restart_syscall(regs);
579                 }
580         }
581
582         /*
583          * translate the signal
584          */
585         if (usig < 32 && thread->exec_domain && thread->exec_domain->signal_invmap)
586                 usig = thread->exec_domain->signal_invmap[usig];
587
588         /*
589          * Set up the stack frame
590          */
591         if (ka->sa.sa_flags & SA_SIGINFO)
592                 ret = setup_rt_frame(usig, ka, info, oldset, regs);
593         else
594                 ret = setup_frame(usig, ka, oldset, regs);
595
596         /*
597          * Check that the resulting registers are actually sane.
598          */
599         ret |= !valid_user_regs(regs);
600
601         if (ret != 0) {
602                 force_sigsegv(sig, tsk);
603                 return;
604         }
605
606         /*
607          * Block the signal if we were successful.
608          */
609         spin_lock_irq(&tsk->sighand->siglock);
610         sigorsets(&tsk->blocked, &tsk->blocked,
611                   &ka->sa.sa_mask);
612         if (!(ka->sa.sa_flags & SA_NODEFER))
613                 sigaddset(&tsk->blocked, sig);
614         recalc_sigpending();
615         spin_unlock_irq(&tsk->sighand->siglock);
616
617 }
618
619 /*
620  * Note that 'init' is a special process: it doesn't get signals it doesn't
621  * want to handle. Thus you cannot kill init even with a SIGKILL even by
622  * mistake.
623  *
624  * Note that we go through the signals twice: once to check the signals that
625  * the kernel can handle, and then we build all the user-level signal handling
626  * stack-frames in one go after that.
627  */
628 static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
629 {
630         struct k_sigaction ka;
631         siginfo_t info;
632         int signr;
633
634         /*
635          * We want the common case to go fast, which
636          * is why we may in certain cases get here from
637          * kernel mode. Just return without doing anything
638          * if so.
639          */
640         if (!user_mode(regs))
641                 return 0;
642
643         if (try_to_freeze())
644                 goto no_signal;
645
646         if (current->ptrace & PT_SINGLESTEP)
647                 ptrace_cancel_bpt(current);
648
649         signr = get_signal_to_deliver(&info, &ka, regs, NULL);
650         if (signr > 0) {
651                 handle_signal(signr, &ka, &info, oldset, regs, syscall);
652                 if (current->ptrace & PT_SINGLESTEP)
653                         ptrace_set_bpt(current);
654                 return 1;
655         }
656
657  no_signal:
658         /*
659          * No signal to deliver to the process - restart the syscall.
660          */
661         if (syscall) {
662                 if (regs->ARM_r0 == -ERESTART_RESTARTBLOCK) {
663                         if (thumb_mode(regs)) {
664                                 regs->ARM_r7 = __NR_restart_syscall;
665                                 regs->ARM_pc -= 2;
666                         } else {
667                                 u32 __user *usp;
668
669                                 regs->ARM_sp -= 12;
670                                 usp = (u32 __user *)regs->ARM_sp;
671
672                                 put_user(regs->ARM_pc, &usp[0]);
673                                 /* swi __NR_restart_syscall */
674                                 put_user(0xef000000 | __NR_restart_syscall, &usp[1]);
675                                 /* ldr  pc, [sp], #12 */
676                                 put_user(0xe49df00c, &usp[2]);
677
678                                 flush_icache_range((unsigned long)usp,
679                                                    (unsigned long)(usp + 3));
680
681                                 regs->ARM_pc = regs->ARM_sp + 4;
682                         }
683                 }
684                 if (regs->ARM_r0 == -ERESTARTNOHAND ||
685                     regs->ARM_r0 == -ERESTARTSYS ||
686                     regs->ARM_r0 == -ERESTARTNOINTR) {
687                         restart_syscall(regs);
688                 }
689         }
690         if (current->ptrace & PT_SINGLESTEP)
691                 ptrace_set_bpt(current);
692         return 0;
693 }
694
695 asmlinkage void
696 do_notify_resume(struct pt_regs *regs, unsigned int thread_flags, int syscall)
697 {
698         if (thread_flags & _TIF_SIGPENDING)
699                 do_signal(&current->blocked, regs, syscall);
700 }