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
15#include <asm/elf.h>
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
45const 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
50static int do_signal(sigset_t *oldset, struct pt_regs * regs, int syscall);
51
52/*
53 * atomically swap in the new signal mask, and wait for a signal.
54 */
55asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, old_sigset_t mask, struct pt_regs *regs)
56{
57	sigset_t saveset;
58
59	mask &= _BLOCKABLE;
60	spin_lock_irq(&current->sighand->siglock);
61	saveset = current->blocked;
62	siginitset(&current->blocked, mask);
63	recalc_sigpending();
64	spin_unlock_irq(&current->sighand->siglock);
65	regs->ARM_r0 = -EINTR;
66
67	while (1) {
68		current->state = TASK_INTERRUPTIBLE;
69		schedule();
70		if (do_signal(&saveset, regs, 0))
71			return regs->ARM_r0;
72	}
73}
74
75asmlinkage int
76sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize, struct pt_regs *regs)
77{
78	sigset_t saveset, newset;
79
80	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
102asmlinkage int
103sys_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
135static 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
148static 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
167static 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
180static 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 */
201struct sigframe {
202	struct ucontext uc;
203	unsigned long retcode[2];
204};
205
206struct rt_sigframe {
207	struct siginfo info;
208	struct sigframe sig;
209};
210
211static 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
263asmlinkage 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	single_step_trap(current);
287
288	return regs->ARM_r0;
289
290badframe:
291	force_sig(SIGSEGV, current);
292	return 0;
293}
294
295asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
296{
297	struct rt_sigframe __user *frame;
298
299	/* Always make any pending restarted system calls return -EINTR */
300	current_thread_info()->restart_block.fn = do_no_restart_syscall;
301
302	/*
303	 * Since we stacked the signal on a 64-bit boundary,
304	 * then 'sp' should be word aligned here.  If it's
305	 * not, then the user is trying to mess with us.
306	 */
307	if (regs->ARM_sp & 7)
308		goto badframe;
309
310	frame = (struct rt_sigframe __user *)regs->ARM_sp;
311
312	if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
313		goto badframe;
314
315	if (restore_sigframe(regs, &frame->sig))
316		goto badframe;
317
318	if (do_sigaltstack(&frame->sig.uc.uc_stack, NULL, regs->ARM_sp) == -EFAULT)
319		goto badframe;
320
321	single_step_trap(current);
322
323	return regs->ARM_r0;
324
325badframe:
326	force_sig(SIGSEGV, current);
327	return 0;
328}
329
330static int
331setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set)
332{
333	struct aux_sigframe __user *aux;
334	int err = 0;
335
336	__put_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
337	__put_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
338	__put_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err);
339	__put_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err);
340	__put_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err);
341	__put_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err);
342	__put_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err);
343	__put_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err);
344	__put_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err);
345	__put_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err);
346	__put_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err);
347	__put_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err);
348	__put_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err);
349	__put_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err);
350	__put_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err);
351	__put_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err);
352	__put_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err);
353
354	__put_user_error(current->thread.trap_no, &sf->uc.uc_mcontext.trap_no, err);
355	__put_user_error(current->thread.error_code, &sf->uc.uc_mcontext.error_code, err);
356	__put_user_error(current->thread.address, &sf->uc.uc_mcontext.fault_address, err);
357	__put_user_error(set->sig[0], &sf->uc.uc_mcontext.oldmask, err);
358
359	err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set));
360
361	aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
362#ifdef CONFIG_CRUNCH
363	if (err == 0)
364		err |= preserve_crunch_context(&aux->crunch);
365#endif
366#ifdef CONFIG_IWMMXT
367	if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
368		err |= preserve_iwmmxt_context(&aux->iwmmxt);
369#endif
370#ifdef CONFIG_VFP
371//	if (err == 0)
372//		err |= vfp_save_state(&sf->aux.vfp);
373#endif
374	__put_user_error(0, &aux->end_magic, err);
375
376	return err;
377}
378
379static inline void __user *
380get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, int framesize)
381{
382	unsigned long sp = regs->ARM_sp;
383	void __user *frame;
384
385	/*
386	 * This is the X/Open sanctioned signal stack switching.
387	 */
388	if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
389		sp = current->sas_ss_sp + current->sas_ss_size;
390
391	/*
392	 * ATPCS B01 mandates 8-byte alignment
393	 */
394	frame = (void __user *)((sp - framesize) & ~7);
395
396	/*
397	 * Check that we can actually write to the signal frame.
398	 */
399	if (!access_ok(VERIFY_WRITE, frame, framesize))
400		frame = NULL;
401
402	return frame;
403}
404
405static int
406setup_return(struct pt_regs *regs, struct k_sigaction *ka,
407	     unsigned long __user *rc, void __user *frame, int usig)
408{
409	unsigned long handler = (unsigned long)ka->sa.sa_handler;
410	unsigned long retcode;
411	int thumb = 0;
412	unsigned long cpsr = regs->ARM_cpsr & ~PSR_f;
413
414	/*
415	 * Maybe we need to deliver a 32-bit signal to a 26-bit task.
416	 */
417	if (ka->sa.sa_flags & SA_THIRTYTWO)
418		cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
419
420#ifdef CONFIG_ARM_THUMB
421	if (elf_hwcap & HWCAP_THUMB) {
422		/*
423		 * The LSB of the handler determines if we're going to
424		 * be using THUMB or ARM mode for this signal handler.
425		 */
426		thumb = handler & 1;
427
428		if (thumb)
429			cpsr |= PSR_T_BIT;
430		else
431			cpsr &= ~PSR_T_BIT;
432	}
433#endif
434
435	if (ka->sa.sa_flags & SA_RESTORER) {
436		retcode = (unsigned long)ka->sa.sa_restorer;
437	} else {
438		unsigned int idx = thumb << 1;
439
440		if (ka->sa.sa_flags & SA_SIGINFO)
441			idx += 3;
442
443		if (__put_user(sigreturn_codes[idx],   rc) ||
444		    __put_user(sigreturn_codes[idx+1], rc+1))
445			return 1;
446
447		if (cpsr & MODE32_BIT) {
448			/*
449			 * 32-bit code can use the new high-page
450			 * signal return code support.
451			 */
452			retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
453		} else {
454			/*
455			 * Ensure that the instruction cache sees
456			 * the return code written onto the stack.
457			 */
458			flush_icache_range((unsigned long)rc,
459					   (unsigned long)(rc + 2));
460
461			retcode = ((unsigned long)rc) + thumb;
462		}
463	}
464
465	regs->ARM_r0 = usig;
466	regs->ARM_sp = (unsigned long)frame;
467	regs->ARM_lr = retcode;
468	regs->ARM_pc = handler;
469	regs->ARM_cpsr = cpsr;
470
471	return 0;
472}
473
474static int
475setup_frame(int usig, struct k_sigaction *ka, sigset_t *set, struct pt_regs *regs)
476{
477	struct sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
478	int err = 0;
479
480	if (!frame)
481		return 1;
482
483	/*
484	 * Set uc.uc_flags to a value which sc.trap_no would never have.
485	 */
486	__put_user_error(0x5ac3c35a, &frame->uc.uc_flags, err);
487
488	err |= setup_sigframe(frame, regs, set);
489	if (err == 0)
490		err = setup_return(regs, ka, frame->retcode, frame, usig);
491
492	return err;
493}
494
495static int
496setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
497	       sigset_t *set, struct pt_regs *regs)
498{
499	struct rt_sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
500	stack_t stack;
501	int err = 0;
502
503	if (!frame)
504		return 1;
505
506	err |= copy_siginfo_to_user(&frame->info, info);
507
508	__put_user_error(0, &frame->sig.uc.uc_flags, err);
509	__put_user_error(NULL, &frame->sig.uc.uc_link, err);
510
511	memset(&stack, 0, sizeof(stack));
512	stack.ss_sp = (void __user *)current->sas_ss_sp;
513	stack.ss_flags = sas_ss_flags(regs->ARM_sp);
514	stack.ss_size = current->sas_ss_size;
515	err |= __copy_to_user(&frame->sig.uc.uc_stack, &stack, sizeof(stack));
516
517	err |= setup_sigframe(&frame->sig, regs, set);
518	if (err == 0)
519		err = setup_return(regs, ka, frame->sig.retcode, frame, usig);
520
521	if (err == 0) {
522		/*
523		 * For realtime signals we must also set the second and third
524		 * arguments for the signal handler.
525		 *   -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
526		 */
527		regs->ARM_r1 = (unsigned long)&frame->info;
528		regs->ARM_r2 = (unsigned long)&frame->sig.uc;
529	}
530
531	return err;
532}
533
534static inline void restart_syscall(struct pt_regs *regs)
535{
536	regs->ARM_r0 = regs->ARM_ORIG_r0;
537	regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;
538}
539
540/*
541 * OK, we're invoking a handler
542 */
543static void
544handle_signal(unsigned long sig, struct k_sigaction *ka,
545	      siginfo_t *info, sigset_t *oldset,
546	      struct pt_regs * regs, int syscall)
547{
548	struct thread_info *thread = current_thread_info();
549	struct task_struct *tsk = current;
550	int usig = sig;
551	int ret;
552
553	/*
554	 * If we were from a system call, check for system call restarting...
555	 */
556	if (syscall) {
557		switch (regs->ARM_r0) {
558		case -ERESTART_RESTARTBLOCK:
559		case -ERESTARTNOHAND:
560			regs->ARM_r0 = -EINTR;
561			break;
562		case -ERESTARTSYS:
563			if (!(ka->sa.sa_flags & SA_RESTART)) {
564				regs->ARM_r0 = -EINTR;
565				break;
566			}
567			/* fallthrough */
568		case -ERESTARTNOINTR:
569			restart_syscall(regs);
570		}
571	}
572
573	/*
574	 * translate the signal
575	 */
576	if (usig < 32 && thread->exec_domain && thread->exec_domain->signal_invmap)
577		usig = thread->exec_domain->signal_invmap[usig];
578
579	/*
580	 * Set up the stack frame
581	 */
582	if (ka->sa.sa_flags & SA_SIGINFO)
583		ret = setup_rt_frame(usig, ka, info, oldset, regs);
584	else
585		ret = setup_frame(usig, ka, oldset, regs);
586
587	/*
588	 * Check that the resulting registers are actually sane.
589	 */
590	ret |= !valid_user_regs(regs);
591
592	if (ret != 0) {
593		force_sigsegv(sig, tsk);
594		return;
595	}
596
597	/*
598	 * Block the signal if we were successful.
599	 */
600	spin_lock_irq(&tsk->sighand->siglock);
601	sigorsets(&tsk->blocked, &tsk->blocked,
602		  &ka->sa.sa_mask);
603	if (!(ka->sa.sa_flags & SA_NODEFER))
604		sigaddset(&tsk->blocked, sig);
605	recalc_sigpending();
606	spin_unlock_irq(&tsk->sighand->siglock);
607
608}
609
610/*
611 * Note that 'init' is a special process: it doesn't get signals it doesn't
612 * want to handle. Thus you cannot kill init even with a SIGKILL even by
613 * mistake.
614 *
615 * Note that we go through the signals twice: once to check the signals that
616 * the kernel can handle, and then we build all the user-level signal handling
617 * stack-frames in one go after that.
618 */
619static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
620{
621	struct k_sigaction ka;
622	siginfo_t info;
623	int signr;
624
625	/*
626	 * We want the common case to go fast, which
627	 * is why we may in certain cases get here from
628	 * kernel mode. Just return without doing anything
629	 * if so.
630	 */
631	if (!user_mode(regs))
632		return 0;
633
634	if (try_to_freeze())
635		goto no_signal;
636
637	single_step_clear(current);
638
639	signr = get_signal_to_deliver(&info, &ka, regs, NULL);
640	if (signr > 0) {
641		handle_signal(signr, &ka, &info, oldset, regs, syscall);
642		single_step_set(current);
643		return 1;
644	}
645
646 no_signal:
647	/*
648	 * No signal to deliver to the process - restart the syscall.
649	 */
650	if (syscall) {
651		if (regs->ARM_r0 == -ERESTART_RESTARTBLOCK) {
652			if (thumb_mode(regs)) {
653				regs->ARM_r7 = __NR_restart_syscall - __NR_SYSCALL_BASE;
654				regs->ARM_pc -= 2;
655			} else {
656#if defined(CONFIG_AEABI) && !defined(CONFIG_OABI_COMPAT)
657				regs->ARM_r7 = __NR_restart_syscall;
658				regs->ARM_pc -= 4;
659#else
660				u32 __user *usp;
661				u32 swival = __NR_restart_syscall;
662
663				regs->ARM_sp -= 12;
664				usp = (u32 __user *)regs->ARM_sp;
665
666				/*
667				 * Either we supports OABI only, or we have
668				 * EABI with the OABI compat layer enabled.
669				 * In the later case we don't know if user
670				 * space is EABI or not, and if not we must
671				 * not clobber r7.  Always using the OABI
672				 * syscall solves that issue and works for
673				 * all those cases.
674				 */
675				swival = swival - __NR_SYSCALL_BASE + __NR_OABI_SYSCALL_BASE;
676
677				put_user(regs->ARM_pc, &usp[0]);
678				/* swi __NR_restart_syscall */
679				put_user(0xef000000 | swival, &usp[1]);
680				/* ldr	pc, [sp], #12 */
681				put_user(0xe49df00c, &usp[2]);
682
683				flush_icache_range((unsigned long)usp,
684						   (unsigned long)(usp + 3));
685
686				regs->ARM_pc = regs->ARM_sp + 4;
687#endif
688			}
689		}
690		if (regs->ARM_r0 == -ERESTARTNOHAND ||
691		    regs->ARM_r0 == -ERESTARTSYS ||
692		    regs->ARM_r0 == -ERESTARTNOINTR) {
693			restart_syscall(regs);
694		}
695	}
696	single_step_set(current);
697	return 0;
698}
699
700asmlinkage void
701do_notify_resume(struct pt_regs *regs, unsigned int thread_flags, int syscall)
702{
703	if (thread_flags & _TIF_SIGPENDING)
704		do_signal(&current->blocked, regs, syscall);
705}
706