2 * linux/arch/parisc/kernel/signal.c: Architecture-specific signal
5 * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org>
6 * Copyright (C) 2000 Linuxcare, Inc.
8 * Based on the ia64, i386, and alpha versions.
10 * Like the IA-64, we are a recent enough port (we are *starting*
11 * with glibc2.2) that we do not need to support the old non-realtime
12 * Linux signals. Therefore we don't. HP/UX signals will go in
13 * arch/parisc/hpux/signal.c when we figure out how to do them.
16 #include <linux/config.h>
18 #include <linux/version.h>
19 #include <linux/sched.h>
21 #include <linux/smp.h>
22 #include <linux/smp_lock.h>
23 #include <linux/kernel.h>
24 #include <linux/signal.h>
25 #include <linux/errno.h>
26 #include <linux/wait.h>
27 #include <linux/ptrace.h>
28 #include <linux/unistd.h>
29 #include <linux/stddef.h>
30 #include <asm/ucontext.h>
31 #include <asm/uaccess.h>
32 #include <asm/pgalloc.h>
36 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
38 extern long sys_wait4 (int, int *, int, struct rusage
*);
39 int do_signal(sigset_t
*oldset
, struct pt_regs
*regs
, int in_syscall
);
41 int copy_siginfo_to_user(siginfo_t
*to
, siginfo_t
*from
)
43 if (!access_ok (VERIFY_WRITE
, to
, sizeof(siginfo_t
)))
45 if (from
->si_code
< 0)
46 return __copy_to_user(to
, from
, sizeof(siginfo_t
));
51 * If you change siginfo_t structure, please be sure
52 * this code is fixed accordingly. It should never
53 * copy any pad contained in the structure to avoid
54 * security leaks, but must copy the generic 3 ints
55 * plus the relevant union member.
57 err
= __put_user(from
->si_signo
, &to
->si_signo
);
58 err
|= __put_user(from
->si_errno
, &to
->si_errno
);
59 err
|= __put_user((short)from
->si_code
, &to
->si_code
);
60 switch (from
->si_code
>> 16) {
61 case __SI_FAULT
>> 16:
62 /* FIXME: should we put the interruption code here? */
64 err
|= __put_user(from
->si_addr
, &to
->si_addr
);
67 err
|= __put_user(from
->si_utime
, &to
->si_utime
);
68 err
|= __put_user(from
->si_stime
, &to
->si_stime
);
69 err
|= __put_user(from
->si_status
, &to
->si_status
);
71 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
72 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
74 /* case __SI_RT: This is not generated by the kernel as of now. */
81 * Atomically swap in the new signal mask, and wait for a signal.
88 sys_rt_sigsuspend(sigset_t
*unewset
, size_t sigsetsize
, struct pt_regs
*regs
)
90 sigset_t saveset
, newset
;
92 /* XXX FIXME -- assumes 32-bit user app! */
95 /* XXX: Don't preclude handling different sized sigset_t's. */
96 if (sigsetsize
!= sizeof(sigset_t32
))
99 if (copy_from_user(&newset32
, (sigset_t32
*)unewset
, sizeof(newset32
)))
102 newset
.sig
[0] = newset32
.sig
[0] | ((unsigned long)newset32
.sig
[1] << 32);
105 /* XXX: Don't preclude handling different sized sigset_t's. */
106 if (sigsetsize
!= sizeof(sigset_t
))
109 if (copy_from_user(&newset
, unewset
, sizeof(newset
)))
112 sigdelsetmask(&newset
, ~_BLOCKABLE
);
114 spin_lock_irq(¤t
->sigmask_lock
);
115 saveset
= current
->blocked
;
116 current
->blocked
= newset
;
117 recalc_sigpending(current
);
118 spin_unlock_irq(¤t
->sigmask_lock
);
120 regs
->gr
[28] = -EINTR
;
122 current
->state
= TASK_INTERRUPTIBLE
;
124 if (do_signal(&saveset
, regs
, 1))
130 * Do a signal return - restore sigcontext.
134 unsigned int tramp
[4];
139 /* Trampoline for calling rt_sigreturn() */
140 #define INSN_LDI_R25_0 0x34190000 /* ldi 0,%r25 (in_syscall=0) */
141 #define INSN_LDI_R25_1 0x34190002 /* ldi 1,%r25 (in_syscall=1) */
142 #define INSN_LDI_R20 0x3414015a /* ldi __NR_rt_sigreturn,%r20 */
143 #define INSN_BLE_SR2_R0 0xe4008200 /* be,l 0x100(%sr2,%r0),%sr0,%r31 */
144 #define INSN_NOP 0x80000240 /* nop */
146 #define INSN_DIE_HORRIBLY 0x68000ccc /* stw %r0,0x666(%sr0,%r0) */
149 * The 32-bit ABI wants at least 48 bytes for a function call frame:
150 * 16 bytes for arg0-arg3, and 32 bytes for magic (the only part of
151 * which Linux/parisc uses is sp-20 for the saved return pointer...)
152 * Then, the stack pointer must be rounded to a cache line (64 bytes).
154 #define PARISC_RT_SIGFRAME_SIZE \
155 (((sizeof(struct rt_sigframe) + 48) + 63) & -64)
158 restore_sigcontext(struct sigcontext
*sc
, struct pt_regs
*regs
)
162 err
|= __copy_from_user(regs
->gr
, sc
->sc_gr
, sizeof(regs
->gr
));
163 err
|= __copy_from_user(regs
->fr
, sc
->sc_fr
, sizeof(regs
->fr
));
164 err
|= __copy_from_user(regs
->iaoq
, sc
->sc_iaoq
, sizeof(regs
->iaoq
));
165 err
|= __copy_from_user(regs
->iasq
, sc
->sc_iasq
, sizeof(regs
->iasq
));
166 err
|= __get_user(regs
->sar
, &sc
->sc_sar
);
169 printk("restore_sigcontext: r28 is %ld\n", regs
->gr
[28]);
175 sys_rt_sigreturn(struct pt_regs
*regs
, int in_syscall
)
177 struct rt_sigframe
*frame
;
180 unsigned long usp
= regs
->gr
[30];
182 /* Unwind the user stack to get the rt_sigframe structure. */
183 frame
= (struct rt_sigframe
*)
184 (usp
- PARISC_RT_SIGFRAME_SIZE
);
186 printk("in sys_rt_sigreturn, frame is %p\n", frame
);
189 /* Verify that it's a good sigcontext before using it */
190 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
192 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
195 sigdelsetmask(&set
, ~_BLOCKABLE
);
196 spin_lock_irq(¤t
->sigmask_lock
);
197 current
->blocked
= set
;
198 recalc_sigpending(current
);
199 spin_unlock_irq(¤t
->sigmask_lock
);
201 /* Good thing we saved the old gr[30], eh? */
202 if (restore_sigcontext(&frame
->uc
.uc_mcontext
, regs
))
206 printk("usp: %#08lx stack %p",
207 usp
, &frame
->uc
.uc_stack
);
210 /* I don't know why everyone else assumes they can call this
211 with a pointer to a stack_t on the kernel stack. That
212 makes no sense. Anyway we'll do it like m68k, since we
213 also are using segmentation in the same way as them. */
214 if (do_sigaltstack(&frame
->uc
.uc_stack
, NULL
, usp
) == -EFAULT
)
217 /* If we are on the syscall path IAOQ will not be restored, and
218 * if we are on the interrupt path we must not corrupt gr31.
221 regs
->gr
[31] = regs
->iaoq
[0];
223 printk("returning to %#lx\n", regs
->iaoq
[0]);
224 printk("in sys_rt_sigreturn:\n");
231 printk("fuckup in sys_rt_sigreturn, sending SIGSEGV\n");
233 si
.si_signo
= SIGSEGV
;
235 si
.si_code
= SI_KERNEL
;
236 si
.si_pid
= current
->pid
;
237 si
.si_uid
= current
->uid
;
238 si
.si_addr
= &frame
->uc
;
239 force_sig_info(SIGSEGV
, &si
, current
);
244 * Set up a signal frame.
248 get_sigframe(struct k_sigaction
*ka
, unsigned long sp
, size_t frame_size
)
250 if ((ka
->sa
.sa_flags
& SA_ONSTACK
) != 0 && ! on_sig_stack(sp
))
251 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
253 return (void *) sp
; /* Stacks grow up. Fun. */
257 setup_sigcontext(struct sigcontext
*sc
, struct pt_regs
*regs
, int in_syscall
)
260 unsigned long flags
= 0;
263 if (on_sig_stack((unsigned long) sc
))
264 flags
|= PARISC_SC_FLAG_ONSTACK
;
266 flags
|= PARISC_SC_FLAG_IN_SYSCALL
;
267 /* regs->iaoq is undefined in the syscall return path */
268 err
|= __put_user(regs
->gr
[31], &sc
->sc_iaoq
[0]);
269 err
|= __put_user(regs
->gr
[31]+4, &sc
->sc_iaoq
[1]);
271 printk("setup_sigcontext: iaoq %#lx/%#lx\n", regs
->gr
[31], regs
->gr
[31]);
274 err
|= __copy_to_user(sc
->sc_iaoq
, regs
->iaoq
, sizeof(regs
->iaoq
));
275 err
|= __copy_to_user(sc
->sc_iasq
, regs
->iasq
, sizeof(regs
->iasq
));
277 printk("setup_sigcontext: iaoq %#lx/%#lx\n", regs
->iaoq
[0], regs
->iaoq
[1]);
281 err
|= __put_user(flags
, &sc
->sc_flags
);
282 err
|= __copy_to_user(sc
->sc_gr
, regs
->gr
, sizeof(regs
->gr
));
283 err
|= __copy_to_user(sc
->sc_fr
, regs
->fr
, sizeof(regs
->fr
));
284 err
|= __put_user(regs
->sar
, &sc
->sc_sar
);
286 printk("setup_sigcontext: r28 is %ld\n", regs
->gr
[28]);
293 setup_rt_frame(int sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
294 sigset_t
*set
, struct pt_regs
*regs
, int in_syscall
)
296 struct rt_sigframe
*frame
;
297 unsigned long rp
, usp
, haddr
;
302 /* access_ok is broken, so do a simplistic "are we stomping on
303 kernel space" assertion. */
304 if (usp
> PAGE_OFFSET
) {
305 printk("setup_rt_frame: called on kernel space (usp=%#lx), NOW YOU MUST DIE!!!\n",
311 frame
= get_sigframe(ka
, usp
, sizeof(*frame
));
312 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
316 printk("setup_rt_frame 1: frame %p info %p\n", frame
, info
);
319 err
|= __copy_to_user(&frame
->info
, info
, sizeof(siginfo_t
));
320 err
|= __put_user(current
->sas_ss_sp
, &frame
->uc
.uc_stack
.ss_sp
);
321 err
|= __put_user(current
->sas_ss_size
, &frame
->uc
.uc_stack
.ss_size
);
322 err
|= __put_user(sas_ss_flags(regs
->gr
[30]),
323 &frame
->uc
.uc_stack
.ss_flags
);
324 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, regs
, in_syscall
);
325 err
|= __copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
329 /* Set up to return from userspace. If provided, use a stub
330 already in userspace. */
331 err
|= __put_user(in_syscall
? INSN_LDI_R25_1
: INSN_LDI_R25_0
,
333 err
|= __put_user(INSN_LDI_R20
, &frame
->tramp
[1]);
334 err
|= __put_user(INSN_BLE_SR2_R0
, &frame
->tramp
[2]);
335 err
|= __put_user(INSN_NOP
, &frame
->tramp
[3]);
338 /* Assert that we're flushing in the correct space... */
341 asm ("mfsp %%sr3,%0" : "=r" (sid
));
342 printk("flushing 64 bytes at space %#x offset %p\n",
347 #if CACHE_FLUSHING_IS_NOT_BROKEN
348 flush_icache_range((unsigned long) &frame
->tramp
[0],
349 (unsigned long) &frame
->tramp
[4]);
351 /* It should *always* be cache line-aligned, but the compiler
352 sometimes screws up. */
353 asm volatile("fdc 0(%%sr3,%0)\n\t"
354 "fdc %1(%%sr3,%0)\n\t"
356 "fic 0(%%sr3,%0)\n\t"
357 "fic %1(%%sr3,%0)\n\t"
359 : : "r" (frame
->tramp
), "r" (L1_CACHE_BYTES
));
361 rp
= (unsigned long) frame
->tramp
;
367 /* Much more has to happen with signals than this -- but it'll at least */
368 /* provide a pointer to some places which definitely need a look. */
369 #define HACK unsigned int
371 #define HACK unsigned long
373 haddr
= (HACK
) ka
->sa
.sa_handler
;
374 /* ARGH! Fucking brain damage. You don't want to know. */
379 plabel
= (HACK
*) (haddr
& ~3);
380 err
|= __get_user(haddr
, plabel
);
381 err
|= __get_user(ltp
, plabel
+ 1);
387 /* The syscall return path will create IAOQ values from r31.
390 regs
->gr
[31] = (HACK
) haddr
;
392 regs
->iaoq
[0] = (HACK
) haddr
| 3;
393 regs
->iaoq
[1] = regs
->iaoq
[0] + 4;
396 regs
->gr
[2] = rp
; /* userland return pointer */
397 regs
->gr
[26] = sig
; /* signal number */
398 regs
->gr
[25] = (HACK
) &frame
->info
; /* siginfo pointer */
399 regs
->gr
[24] = (HACK
) &frame
->uc
; /* ucontext pointer */
401 printk("making sigreturn frame: %#lx + %#lx = %#lx\n",
402 regs
->gr
[30], PARISC_RT_SIGFRAME_SIZE
,
403 regs
->gr
[30] + PARISC_RT_SIGFRAME_SIZE
);
405 /* Raise the user stack pointer to make a proper call frame. */
406 regs
->gr
[30] = ((HACK
) frame
+ PARISC_RT_SIGFRAME_SIZE
);
409 printk("SIG deliver (%s:%d): frame=0x%p sp=%#lx iaoq=%#lx/%#lx rp=%#lx\n",
410 current
->comm
, current
->pid
, frame
, regs
->gr
[30],
411 regs
->iaoq
[0], regs
->iaoq
[1], rp
);
418 printk("fuckup in setup_rt_frame, sending SIGSEGV\n");
421 ka
->sa
.sa_handler
= SIG_DFL
;
422 si
.si_signo
= SIGSEGV
;
424 si
.si_code
= SI_KERNEL
;
425 si
.si_pid
= current
->pid
;
426 si
.si_uid
= current
->uid
;
428 force_sig_info(SIGSEGV
, &si
, current
);
433 * OK, we're invoking a handler.
437 handle_signal(unsigned long sig
, struct k_sigaction
*ka
,
438 siginfo_t
*info
, sigset_t
*oldset
,
439 struct pt_regs
*regs
, int in_syscall
)
442 printk("handle_signal(sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p)\n",
443 sig
, ka
, info
, oldset
, regs
);
445 /* Set up the stack frame */
446 if (!setup_rt_frame(sig
, ka
, info
, oldset
, regs
, in_syscall
))
449 if (ka
->sa
.sa_flags
& SA_ONESHOT
)
450 ka
->sa
.sa_handler
= SIG_DFL
;
452 if (!(ka
->sa
.sa_flags
& SA_NODEFER
)) {
453 spin_lock_irq(¤t
->sigmask_lock
);
454 sigorsets(¤t
->blocked
,¤t
->blocked
,&ka
->sa
.sa_mask
);
455 sigaddset(¤t
->blocked
,sig
);
456 recalc_sigpending(current
);
457 spin_unlock_irq(¤t
->sigmask_lock
);
463 * Note that 'init' is a special process: it doesn't get signals it doesn't
464 * want to handle. Thus you cannot kill init even with a SIGKILL even by
467 * We need to be able to restore the syscall arguments (r21-r26) to
468 * restart syscalls. Thus, the syscall path should save them in the
469 * pt_regs structure (it's okay to do so since they are caller-save
470 * registers). As noted below, the syscall number gets restored for
471 * us due to the magic of delayed branching.
474 do_signal(sigset_t
*oldset
, struct pt_regs
*regs
, int in_syscall
)
477 struct k_sigaction
*ka
;
480 printk("do_signal(oldset=0x%p, regs=0x%p, sr7 %#lx, pending %d, in_syscall=%d\n",
481 oldset
, regs
, regs
->sr
[7], current
->sigpending
, in_syscall
);
483 /* Everyone else checks to see if they are in kernel mode at
484 this point and exits if that's the case. I'm not sure why
485 we would be called in that case, but for some reason we
489 oldset
= ¤t
->blocked
;
492 printk("do_signal: oldset %08lx:%08lx\n", oldset
->sig
[0], oldset
->sig
[1]);
498 spin_lock_irq(¤t
->sigmask_lock
);
499 signr
= dequeue_signal(¤t
->blocked
, &info
);
500 spin_unlock_irq(¤t
->sigmask_lock
);
502 printk("do_signal: signr=%ld, pid=%d\n", signr
, current
->pid
);
508 if ((current
->ptrace
& PT_PTRACED
) && signr
!= SIGKILL
) {
509 /* Let the debugger run. */
510 current
->exit_code
= signr
;
511 set_current_state(TASK_STOPPED
);
512 notify_parent(current
, SIGCHLD
);
515 /* We're back. Did the debugger cancel the sig? */
516 if (!(signr
= current
->exit_code
))
518 current
->exit_code
= 0;
520 /* The debugger continued. Ignore SIGSTOP. */
521 if (signr
== SIGSTOP
)
524 /* Update the siginfo structure. Is this good? */
525 if (signr
!= info
.si_signo
) {
526 info
.si_signo
= signr
;
528 info
.si_code
= SI_USER
;
529 info
.si_pid
= current
->p_pptr
->pid
;
530 info
.si_uid
= current
->p_pptr
->uid
;
533 /* If the (new) signal is now blocked, requeue it. */
534 if (sigismember(¤t
->blocked
, signr
)) {
535 send_sig_info(signr
, &info
, current
);
540 ka
= ¤t
->sig
->action
[signr
-1];
542 printk("sa_handler is %lx\n", ka
->sa
.sa_handler
);
544 if ((unsigned long) ka
->sa
.sa_handler
== (unsigned long) SIG_IGN
) {
545 if (signr
!= SIGCHLD
)
547 while (sys_wait4(-1, NULL
, WNOHANG
, NULL
) > 0)
552 if ((unsigned long) ka
->sa
.sa_handler
== (unsigned long) SIG_DFL
) {
553 int exit_code
= signr
;
555 /* Init gets no signals it doesn't want. */
556 if (current
->pid
== 1)
560 case SIGCONT
: case SIGCHLD
: case SIGWINCH
:
563 case SIGTSTP
: case SIGTTIN
: case SIGTTOU
:
564 if (is_orphaned_pgrp(current
->pgrp
))
569 set_current_state(TASK_STOPPED
);
570 current
->exit_code
= signr
;
571 if (!(current
->p_pptr
->sig
->action
[SIGCHLD
-1].sa
.sa_flags
& SA_NOCLDSTOP
))
572 notify_parent(current
, SIGCHLD
);
576 case SIGQUIT
: case SIGILL
: case SIGTRAP
:
577 case SIGABRT
: case SIGFPE
: case SIGSEGV
:
578 case SIGBUS
: case SIGSYS
: case SIGXCPU
: case SIGXFSZ
:
579 if (signr
== SIGQUIT
) /* Userspace debugging */
581 if (do_coredump(signr
, regs
))
587 sigaddset(¤t
->pending
.signal
, signr
);
588 recalc_sigpending(current
);
589 current
->flags
|= PF_SIGNALED
;
595 /* Restart a system call if necessary. */
597 /* Check the return code */
598 switch (regs
->gr
[28]) {
599 case -ERESTARTNOHAND
:
601 printk("ERESTARTNOHAND: returning -EINTR\n");
603 regs
->gr
[28] = -EINTR
;
607 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
609 printk("ERESTARTSYS: putting -EINTR\n");
611 regs
->gr
[28] = -EINTR
;
615 case -ERESTARTNOINTR
:
616 /* A syscall is just a branch, so all
617 we have to do is fiddle the return
619 regs
->gr
[31] -= 8; /* delayed branching */
620 /* Preserve original r28. */
621 regs
->gr
[28] = regs
->orig_r28
;
625 /* Whee! Actually deliver the signal. If the
626 delivery failed, we need to continue to iterate in
627 this loop so we can deliver the SIGSEGV... */
628 if (handle_signal(signr
, ka
, &info
, oldset
, regs
, in_syscall
)) {
630 printk("Exiting do_signal (success), regs->gr[28] = %ld\n", regs
->gr
[28]);
636 /* Did we come from a system call? */
638 /* Restart the system call - no handlers present */
639 if (regs
->gr
[28] == -ERESTARTNOHAND
||
640 regs
->gr
[28] == -ERESTARTSYS
||
641 regs
->gr
[28] == -ERESTARTNOINTR
) {
642 /* Hooray for delayed branching. We don't
643 have to restore %r20 (the system call
644 number) because it gets loaded in the delay
645 slot of the branch external instruction. */
647 /* Preserve original r28. */
648 regs
->gr
[28] = regs
->orig_r28
;
652 printk("Exiting do_signal (not delivered), regs->gr[28] = %ld\n", regs
->gr
[28]);