]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - arch/arm/kernel/signal.c
2 * linux/arch/arm/kernel/signal.c
4 * Copyright (C) 1995-2002 Russell King
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.
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>
16 #include <asm/cacheflush.h>
17 #include <asm/ucontext.h>
18 #include <asm/uaccess.h>
19 #include <asm/unistd.h>
24 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
27 * For ARM syscalls, we encode the syscall number into the instruction.
29 #define SWI_SYS_SIGRETURN (0xef000000|(__NR_sigreturn))
30 #define SWI_SYS_RT_SIGRETURN (0xef000000|(__NR_rt_sigreturn))
33 * With EABI, the syscall number has to be loaded into r7.
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))
39 * For Thumb syscalls, we pass the syscall number via r7. We therefore
40 * need two 16-bit instructions.
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))
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
,
50 static int do_signal(sigset_t
*oldset
, struct pt_regs
* regs
, int syscall
);
53 * atomically swap in the new signal mask, and wait for a signal.
55 asmlinkage
int sys_sigsuspend(int restart
, unsigned long oldmask
, old_sigset_t mask
, struct pt_regs
*regs
)
60 spin_lock_irq(¤t
->sighand
->siglock
);
61 saveset
= current
->blocked
;
62 siginitset(¤t
->blocked
, mask
);
64 spin_unlock_irq(¤t
->sighand
->siglock
);
65 regs
->ARM_r0
= -EINTR
;
68 current
->state
= TASK_INTERRUPTIBLE
;
70 if (do_signal(&saveset
, regs
, 0))
76 sys_rt_sigsuspend(sigset_t __user
*unewset
, size_t sigsetsize
, struct pt_regs
*regs
)
78 sigset_t saveset
, newset
;
80 /* XXX: Don't preclude handling different sized sigset_t's. */
81 if (sigsetsize
!= sizeof(sigset_t
))
84 if (copy_from_user(&newset
, unewset
, sizeof(newset
)))
86 sigdelsetmask(&newset
, ~_BLOCKABLE
);
88 spin_lock_irq(¤t
->sighand
->siglock
);
89 saveset
= current
->blocked
;
90 current
->blocked
= newset
;
92 spin_unlock_irq(¤t
->sighand
->siglock
);
93 regs
->ARM_r0
= -EINTR
;
96 current
->state
= TASK_INTERRUPTIBLE
;
98 if (do_signal(&saveset
, regs
, 0))
104 sys_sigaction(int sig
, const struct old_sigaction __user
*act
,
105 struct old_sigaction __user
*oact
)
107 struct k_sigaction new_ka
, old_ka
;
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
))
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
);
121 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
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
))
128 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
);
129 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
);
137 static int preserve_iwmmxt_context(struct iwmmxt_sigframe
*frame
)
139 char kbuf
[sizeof(*frame
) + 8];
140 struct iwmmxt_sigframe
*kframe
;
142 /* the iWMMXt context must be 64 bit aligned */
143 kframe
= (struct iwmmxt_sigframe
*)((unsigned long)(kbuf
+ 8) & ~7);
144 kframe
->magic
= IWMMXT_MAGIC
;
145 kframe
->size
= IWMMXT_STORAGE_SIZE
;
146 iwmmxt_task_copy(current_thread_info(), &kframe
->storage
);
147 return __copy_to_user(frame
, kframe
, sizeof(*frame
));
150 static int restore_iwmmxt_context(struct iwmmxt_sigframe
*frame
)
152 char kbuf
[sizeof(*frame
) + 8];
153 struct iwmmxt_sigframe
*kframe
;
155 /* the iWMMXt context must be 64 bit aligned */
156 kframe
= (struct iwmmxt_sigframe
*)((unsigned long)(kbuf
+ 8) & ~7);
157 if (__copy_from_user(kframe
, frame
, sizeof(*frame
)))
159 if (kframe
->magic
!= IWMMXT_MAGIC
||
160 kframe
->size
!= IWMMXT_STORAGE_SIZE
)
162 iwmmxt_task_restore(current_thread_info(), &kframe
->storage
);
169 * Do a signal return; undo the signal stack. These are aligned to 64-bit.
173 unsigned long retcode
[2];
181 static int restore_sigframe(struct pt_regs
*regs
, struct sigframe __user
*sf
)
183 struct aux_sigframe __user
*aux
;
187 err
= __copy_from_user(&set
, &sf
->uc
.uc_sigmask
, sizeof(set
));
189 sigdelsetmask(&set
, ~_BLOCKABLE
);
190 spin_lock_irq(¤t
->sighand
->siglock
);
191 current
->blocked
= set
;
193 spin_unlock_irq(¤t
->sighand
->siglock
);
196 __get_user_error(regs
->ARM_r0
, &sf
->uc
.uc_mcontext
.arm_r0
, err
);
197 __get_user_error(regs
->ARM_r1
, &sf
->uc
.uc_mcontext
.arm_r1
, err
);
198 __get_user_error(regs
->ARM_r2
, &sf
->uc
.uc_mcontext
.arm_r2
, err
);
199 __get_user_error(regs
->ARM_r3
, &sf
->uc
.uc_mcontext
.arm_r3
, err
);
200 __get_user_error(regs
->ARM_r4
, &sf
->uc
.uc_mcontext
.arm_r4
, err
);
201 __get_user_error(regs
->ARM_r5
, &sf
->uc
.uc_mcontext
.arm_r5
, err
);
202 __get_user_error(regs
->ARM_r6
, &sf
->uc
.uc_mcontext
.arm_r6
, err
);
203 __get_user_error(regs
->ARM_r7
, &sf
->uc
.uc_mcontext
.arm_r7
, err
);
204 __get_user_error(regs
->ARM_r8
, &sf
->uc
.uc_mcontext
.arm_r8
, err
);
205 __get_user_error(regs
->ARM_r9
, &sf
->uc
.uc_mcontext
.arm_r9
, err
);
206 __get_user_error(regs
->ARM_r10
, &sf
->uc
.uc_mcontext
.arm_r10
, err
);
207 __get_user_error(regs
->ARM_fp
, &sf
->uc
.uc_mcontext
.arm_fp
, err
);
208 __get_user_error(regs
->ARM_ip
, &sf
->uc
.uc_mcontext
.arm_ip
, err
);
209 __get_user_error(regs
->ARM_sp
, &sf
->uc
.uc_mcontext
.arm_sp
, err
);
210 __get_user_error(regs
->ARM_lr
, &sf
->uc
.uc_mcontext
.arm_lr
, err
);
211 __get_user_error(regs
->ARM_pc
, &sf
->uc
.uc_mcontext
.arm_pc
, err
);
212 __get_user_error(regs
->ARM_cpsr
, &sf
->uc
.uc_mcontext
.arm_cpsr
, err
);
214 err
|= !valid_user_regs(regs
);
216 aux
= (struct aux_sigframe __user
*) sf
->uc
.uc_regspace
;
218 if (err
== 0 && test_thread_flag(TIF_USING_IWMMXT
))
219 err
|= restore_iwmmxt_context(&aux
->iwmmxt
);
223 // err |= vfp_restore_state(&sf->aux.vfp);
229 asmlinkage
int sys_sigreturn(struct pt_regs
*regs
)
231 struct sigframe __user
*frame
;
233 /* Always make any pending restarted system calls return -EINTR */
234 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
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.
241 if (regs
->ARM_sp
& 7)
244 frame
= (struct sigframe __user
*)regs
->ARM_sp
;
246 if (!access_ok(VERIFY_READ
, frame
, sizeof (*frame
)))
249 if (restore_sigframe(regs
, frame
))
252 /* Send SIGTRAP if we're single-stepping */
253 if (current
->ptrace
& PT_SINGLESTEP
) {
254 ptrace_cancel_bpt(current
);
255 send_sig(SIGTRAP
, current
, 1);
261 force_sig(SIGSEGV
, current
);
265 asmlinkage
int sys_rt_sigreturn(struct pt_regs
*regs
)
267 struct rt_sigframe __user
*frame
;
269 /* Always make any pending restarted system calls return -EINTR */
270 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
273 * Since we stacked the signal on a 64-bit boundary,
274 * then 'sp' should be word aligned here. If it's
275 * not, then the user is trying to mess with us.
277 if (regs
->ARM_sp
& 7)
280 frame
= (struct rt_sigframe __user
*)regs
->ARM_sp
;
282 if (!access_ok(VERIFY_READ
, frame
, sizeof (*frame
)))
285 if (restore_sigframe(regs
, &frame
->sig
))
288 if (do_sigaltstack(&frame
->sig
.uc
.uc_stack
, NULL
, regs
->ARM_sp
) == -EFAULT
)
291 /* Send SIGTRAP if we're single-stepping */
292 if (current
->ptrace
& PT_SINGLESTEP
) {
293 ptrace_cancel_bpt(current
);
294 send_sig(SIGTRAP
, current
, 1);
300 force_sig(SIGSEGV
, current
);
305 setup_sigframe(struct sigframe __user
*sf
, struct pt_regs
*regs
, sigset_t
*set
)
307 struct aux_sigframe __user
*aux
;
310 __put_user_error(regs
->ARM_r0
, &sf
->uc
.uc_mcontext
.arm_r0
, err
);
311 __put_user_error(regs
->ARM_r1
, &sf
->uc
.uc_mcontext
.arm_r1
, err
);
312 __put_user_error(regs
->ARM_r2
, &sf
->uc
.uc_mcontext
.arm_r2
, err
);
313 __put_user_error(regs
->ARM_r3
, &sf
->uc
.uc_mcontext
.arm_r3
, err
);
314 __put_user_error(regs
->ARM_r4
, &sf
->uc
.uc_mcontext
.arm_r4
, err
);
315 __put_user_error(regs
->ARM_r5
, &sf
->uc
.uc_mcontext
.arm_r5
, err
);
316 __put_user_error(regs
->ARM_r6
, &sf
->uc
.uc_mcontext
.arm_r6
, err
);
317 __put_user_error(regs
->ARM_r7
, &sf
->uc
.uc_mcontext
.arm_r7
, err
);
318 __put_user_error(regs
->ARM_r8
, &sf
->uc
.uc_mcontext
.arm_r8
, err
);
319 __put_user_error(regs
->ARM_r9
, &sf
->uc
.uc_mcontext
.arm_r9
, err
);
320 __put_user_error(regs
->ARM_r10
, &sf
->uc
.uc_mcontext
.arm_r10
, err
);
321 __put_user_error(regs
->ARM_fp
, &sf
->uc
.uc_mcontext
.arm_fp
, err
);
322 __put_user_error(regs
->ARM_ip
, &sf
->uc
.uc_mcontext
.arm_ip
, err
);
323 __put_user_error(regs
->ARM_sp
, &sf
->uc
.uc_mcontext
.arm_sp
, err
);
324 __put_user_error(regs
->ARM_lr
, &sf
->uc
.uc_mcontext
.arm_lr
, err
);
325 __put_user_error(regs
->ARM_pc
, &sf
->uc
.uc_mcontext
.arm_pc
, err
);
326 __put_user_error(regs
->ARM_cpsr
, &sf
->uc
.uc_mcontext
.arm_cpsr
, err
);
328 __put_user_error(current
->thread
.trap_no
, &sf
->uc
.uc_mcontext
.trap_no
, err
);
329 __put_user_error(current
->thread
.error_code
, &sf
->uc
.uc_mcontext
.error_code
, err
);
330 __put_user_error(current
->thread
.address
, &sf
->uc
.uc_mcontext
.fault_address
, err
);
331 __put_user_error(set
->sig
[0], &sf
->uc
.uc_mcontext
.oldmask
, err
);
333 err
|= __copy_to_user(&sf
->uc
.uc_sigmask
, set
, sizeof(*set
));
335 aux
= (struct aux_sigframe __user
*) sf
->uc
.uc_regspace
;
337 if (err
== 0 && test_thread_flag(TIF_USING_IWMMXT
))
338 err
|= preserve_iwmmxt_context(&aux
->iwmmxt
);
342 // err |= vfp_save_state(&sf->aux.vfp);
344 __put_user_error(0, &aux
->end_magic
, err
);
349 static inline void __user
*
350 get_sigframe(struct k_sigaction
*ka
, struct pt_regs
*regs
, int framesize
)
352 unsigned long sp
= regs
->ARM_sp
;
356 * This is the X/Open sanctioned signal stack switching.
358 if ((ka
->sa
.sa_flags
& SA_ONSTACK
) && !sas_ss_flags(sp
))
359 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
362 * ATPCS B01 mandates 8-byte alignment
364 frame
= (void __user
*)((sp
- framesize
) & ~7);
367 * Check that we can actually write to the signal frame.
369 if (!access_ok(VERIFY_WRITE
, frame
, framesize
))
376 setup_return(struct pt_regs
*regs
, struct k_sigaction
*ka
,
377 unsigned long __user
*rc
, void __user
*frame
, int usig
)
379 unsigned long handler
= (unsigned long)ka
->sa
.sa_handler
;
380 unsigned long retcode
;
382 unsigned long cpsr
= regs
->ARM_cpsr
& ~PSR_f
;
385 * Maybe we need to deliver a 32-bit signal to a 26-bit task.
387 if (ka
->sa
.sa_flags
& SA_THIRTYTWO
)
388 cpsr
= (cpsr
& ~MODE_MASK
) | USR_MODE
;
390 #ifdef CONFIG_ARM_THUMB
391 if (elf_hwcap
& HWCAP_THUMB
) {
393 * The LSB of the handler determines if we're going to
394 * be using THUMB or ARM mode for this signal handler.
405 if (ka
->sa
.sa_flags
& SA_RESTORER
) {
406 retcode
= (unsigned long)ka
->sa
.sa_restorer
;
408 unsigned int idx
= thumb
<< 1;
410 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
413 if (__put_user(sigreturn_codes
[idx
], rc
) ||
414 __put_user(sigreturn_codes
[idx
+1], rc
+1))
417 if (cpsr
& MODE32_BIT
) {
419 * 32-bit code can use the new high-page
420 * signal return code support.
422 retcode
= KERN_SIGRETURN_CODE
+ (idx
<< 2) + thumb
;
425 * Ensure that the instruction cache sees
426 * the return code written onto the stack.
428 flush_icache_range((unsigned long)rc
,
429 (unsigned long)(rc
+ 2));
431 retcode
= ((unsigned long)rc
) + thumb
;
436 regs
->ARM_sp
= (unsigned long)frame
;
437 regs
->ARM_lr
= retcode
;
438 regs
->ARM_pc
= handler
;
439 regs
->ARM_cpsr
= cpsr
;
445 setup_frame(int usig
, struct k_sigaction
*ka
, sigset_t
*set
, struct pt_regs
*regs
)
447 struct sigframe __user
*frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
454 * Set uc.uc_flags to a value which sc.trap_no would never have.
456 __put_user_error(0x5ac3c35a, &frame
->uc
.uc_flags
, err
);
458 err
|= setup_sigframe(frame
, regs
, set
);
460 err
= setup_return(regs
, ka
, frame
->retcode
, frame
, usig
);
466 setup_rt_frame(int usig
, struct k_sigaction
*ka
, siginfo_t
*info
,
467 sigset_t
*set
, struct pt_regs
*regs
)
469 struct rt_sigframe __user
*frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
476 err
|= copy_siginfo_to_user(&frame
->info
, info
);
478 __put_user_error(0, &frame
->sig
.uc
.uc_flags
, err
);
479 __put_user_error(NULL
, &frame
->sig
.uc
.uc_link
, err
);
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
));
487 err
|= setup_sigframe(&frame
->sig
, regs
, set
);
489 err
= setup_return(regs
, ka
, frame
->sig
.retcode
, frame
, usig
);
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
497 regs
->ARM_r1
= (unsigned long)&frame
->info
;
498 regs
->ARM_r2
= (unsigned long)&frame
->sig
.uc
;
504 static inline void restart_syscall(struct pt_regs
*regs
)
506 regs
->ARM_r0
= regs
->ARM_ORIG_r0
;
507 regs
->ARM_pc
-= thumb_mode(regs
) ? 2 : 4;
511 * OK, we're invoking a handler
514 handle_signal(unsigned long sig
, struct k_sigaction
*ka
,
515 siginfo_t
*info
, sigset_t
*oldset
,
516 struct pt_regs
* regs
, int syscall
)
518 struct thread_info
*thread
= current_thread_info();
519 struct task_struct
*tsk
= current
;
524 * If we were from a system call, check for system call restarting...
527 switch (regs
->ARM_r0
) {
528 case -ERESTART_RESTARTBLOCK
:
529 case -ERESTARTNOHAND
:
530 regs
->ARM_r0
= -EINTR
;
533 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
534 regs
->ARM_r0
= -EINTR
;
538 case -ERESTARTNOINTR
:
539 restart_syscall(regs
);
544 * translate the signal
546 if (usig
< 32 && thread
->exec_domain
&& thread
->exec_domain
->signal_invmap
)
547 usig
= thread
->exec_domain
->signal_invmap
[usig
];
550 * Set up the stack frame
552 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
553 ret
= setup_rt_frame(usig
, ka
, info
, oldset
, regs
);
555 ret
= setup_frame(usig
, ka
, oldset
, regs
);
558 * Check that the resulting registers are actually sane.
560 ret
|= !valid_user_regs(regs
);
563 force_sigsegv(sig
, tsk
);
568 * Block the signal if we were successful.
570 spin_lock_irq(&tsk
->sighand
->siglock
);
571 sigorsets(&tsk
->blocked
, &tsk
->blocked
,
573 if (!(ka
->sa
.sa_flags
& SA_NODEFER
))
574 sigaddset(&tsk
->blocked
, sig
);
576 spin_unlock_irq(&tsk
->sighand
->siglock
);
581 * Note that 'init' is a special process: it doesn't get signals it doesn't
582 * want to handle. Thus you cannot kill init even with a SIGKILL even by
585 * Note that we go through the signals twice: once to check the signals that
586 * the kernel can handle, and then we build all the user-level signal handling
587 * stack-frames in one go after that.
589 static int do_signal(sigset_t
*oldset
, struct pt_regs
*regs
, int syscall
)
591 struct k_sigaction ka
;
596 * We want the common case to go fast, which
597 * is why we may in certain cases get here from
598 * kernel mode. Just return without doing anything
601 if (!user_mode(regs
))
607 if (current
->ptrace
& PT_SINGLESTEP
)
608 ptrace_cancel_bpt(current
);
610 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
612 handle_signal(signr
, &ka
, &info
, oldset
, regs
, syscall
);
613 if (current
->ptrace
& PT_SINGLESTEP
)
614 ptrace_set_bpt(current
);
620 * No signal to deliver to the process - restart the syscall.
623 if (regs
->ARM_r0
== -ERESTART_RESTARTBLOCK
) {
624 if (thumb_mode(regs
)) {
625 regs
->ARM_r7
= __NR_restart_syscall
- __NR_SYSCALL_BASE
;
628 #if defined(CONFIG_AEABI) && !defined(CONFIG_OABI_COMPAT)
629 regs
->ARM_r7
= __NR_restart_syscall
;
633 u32 swival
= __NR_restart_syscall
;
636 usp
= (u32 __user
*)regs
->ARM_sp
;
639 * Either we supports OABI only, or we have
640 * EABI with the OABI compat layer enabled.
641 * In the later case we don't know if user
642 * space is EABI or not, and if not we must
643 * not clobber r7. Always using the OABI
644 * syscall solves that issue and works for
647 swival
= swival
- __NR_SYSCALL_BASE
+ __NR_OABI_SYSCALL_BASE
;
649 put_user(regs
->ARM_pc
, &usp
[0]);
650 /* swi __NR_restart_syscall */
651 put_user(0xef000000 | swival
, &usp
[1]);
652 /* ldr pc, [sp], #12 */
653 put_user(0xe49df00c, &usp
[2]);
655 flush_icache_range((unsigned long)usp
,
656 (unsigned long)(usp
+ 3));
658 regs
->ARM_pc
= regs
->ARM_sp
+ 4;
662 if (regs
->ARM_r0
== -ERESTARTNOHAND
||
663 regs
->ARM_r0
== -ERESTARTSYS
||
664 regs
->ARM_r0
== -ERESTARTNOINTR
) {
665 restart_syscall(regs
);
668 if (current
->ptrace
& PT_SINGLESTEP
)
669 ptrace_set_bpt(current
);
674 do_notify_resume(struct pt_regs
*regs
, unsigned int thread_flags
, int syscall
)
676 if (thread_flags
& _TIF_SIGPENDING
)
677 do_signal(¤t
->blocked
, regs
, syscall
);