diff options
author | cracauer <cracauer@FreeBSD.org> | 1999-07-06 07:13:48 +0000 |
---|---|---|
committer | cracauer <cracauer@FreeBSD.org> | 1999-07-06 07:13:48 +0000 |
commit | 53573bf465904188986e8c982e8019835628d6b2 (patch) | |
tree | 3e7334c4226a10712d8c0459ab03a8d400a4eea7 /sys | |
parent | 0bb9e75fd21026c94438f2db514d21fd69b82377 (diff) | |
download | FreeBSD-src-53573bf465904188986e8c982e8019835628d6b2.zip FreeBSD-src-53573bf465904188986e8c982e8019835628d6b2.tar.gz |
Implement SA_SIGINFO for i386. Thanks to Bruce Evans for much more
than a review, this was a nice puzzle.
This is supposed to be binary and source compatible with older
applications that access the old FreeBSD-style three arguments to a
signal handler.
Except those applications that access hidden signal handler arguments
bejond the documented third one. If you have applications that do,
please let me know so that we take the opportunity to provide the
functionality they need in a documented manner.
Also except application that use 'struct sigframe' directly. You need
to recompile gdb and doscmd. `make world` is recommended.
Example program that demonstrates how SA_SIGINFO and old-style FreeBSD
handlers (with their three args) may be used in the same process is at
http://www3.cons.org/tmp/fbsd-siginfo.c
Programs that use the old FreeBSD-style three arguments are easy to
change to SA_SIGINFO (although they don't need to, since the old style
will still work):
Old args to signal handler:
void handler_sn(int sig, int code, struct sigcontext *scp)
New args:
void handler_si(int sig, siginfo_t *si, void *third)
where:
old:code == new:second->si_code
old:scp == &(new:si->si_scp) /* Passed by value! */
The latter is also pointed to by new:third, but accessing via
si->si_scp is preferred because it is type-save.
FreeBSD implementation notes:
- This is just the framework to make the interface POSIX compatible.
For now, no additional functionality is provided. This is supposed
to happen now, starting with floating point values.
- We don't use 'sigcontext_t.si_value' for now (POSIX meant it for
realtime-related values).
- Documentation will be updated when new functionality is added and
the exact arguments passed are determined. The comments in
sys/signal.h are meant to be useful.
Reviewed by: BDE
Diffstat (limited to 'sys')
-rw-r--r-- | sys/amd64/amd64/genassym.c | 9 | ||||
-rw-r--r-- | sys/amd64/amd64/machdep.c | 77 | ||||
-rw-r--r-- | sys/amd64/include/frame.h | 40 | ||||
-rw-r--r-- | sys/i386/i386/genassym.c | 9 | ||||
-rw-r--r-- | sys/i386/i386/machdep.c | 77 | ||||
-rw-r--r-- | sys/i386/include/frame.h | 40 | ||||
-rw-r--r-- | sys/kern/kern_sig.c | 30 | ||||
-rw-r--r-- | sys/sys/_sigset.h | 76 | ||||
-rw-r--r-- | sys/sys/signal.h | 76 | ||||
-rw-r--r-- | sys/sys/signalvar.h | 3 |
10 files changed, 306 insertions, 131 deletions
diff --git a/sys/amd64/amd64/genassym.c b/sys/amd64/amd64/genassym.c index abb81ec..3e92787 100644 --- a/sys/amd64/amd64/genassym.c +++ b/sys/amd64/amd64/genassym.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 - * $Id: genassym.c,v 1.70 1999/06/01 18:19:38 jlemon Exp $ + * $Id: genassym.c,v 1.71 1999/06/28 09:21:41 peter Exp $ */ #include "opt_user_ldt.h" @@ -167,11 +167,8 @@ main() printf("#define\tTF_ESP %#x\n", OS(trapframe, tf_esp)); printf("#define\tTF_SS %#x\n", OS(trapframe, tf_ss)); - printf("#define\tSIGF_SIGNUM %#x\n", OS(sigframe, sf_signum)); - printf("#define\tSIGF_CODE %#x\n", OS(sigframe, sf_code)); - printf("#define\tSIGF_SCP %#x\n", OS(sigframe, sf_scp)); - printf("#define\tSIGF_HANDLER %#x\n", OS(sigframe, sf_handler)); - printf("#define\tSIGF_SC %#x\n", OS(sigframe, sf_sc)); + printf("#define\tSIGF_HANDLER %#x\n", OS(sigframe, sf_ahu.sf_handler)); + printf("#define\tSIGF_SC %#x\n", OS(sigframe, sf_siginfo.si_sc)); printf("#define\tB_READ %#x\n", B_READ); printf("#define\tENOENT %d\n", ENOENT); diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 54c72fc..616e7e5 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.351 1999/07/04 02:26:23 jlemon Exp $ + * $Id: machdep.c,v 1.352 1999/07/05 08:52:49 msmith Exp $ */ #include "apm.h" @@ -509,6 +509,9 @@ sendsig(catcher, sig, mask, code) * Process has trashed its stack; give it an illegal * instruction to halt it in its tracks. */ +#ifdef DEBUG + printf("process %d has trashed its stack\n", p->p_pid); +#endif SIGACTION(p, SIGILL) = SIG_DFL; sig = sigmask(SIGILL); p->p_sigignore &= ~sig; @@ -528,36 +531,50 @@ sendsig(catcher, sig, mask, code) sig = p->p_sysent->sv_sigsize + 1; } sf.sf_signum = sig; - sf.sf_code = code; - sf.sf_scp = &fp->sf_sc; + sf.sf_scp = (register_t)&fp->sf_siginfo.si_sc; + if (p->p_sigacts->ps_siginfo & sigmask(sig)) { + /* + * Signal handler installed with SA_SIGINFO. + */ + sf.sf_arg2 = (register_t)&fp->sf_siginfo; + sf.sf_siginfo.si_signo = sig; + sf.sf_siginfo.si_code = code; + sf.sf_ahu.sf_action = (__siginfohandler_t *)catcher; + } else { + /* + * Old FreeBSD-style arguments. + */ + sf.sf_arg2 = code; + sf.sf_ahu.sf_handler = catcher; + } + sf.sf_addr = (char *) regs->tf_err; - sf.sf_handler = catcher; /* save scratch registers */ - sf.sf_sc.sc_eax = regs->tf_eax; - sf.sf_sc.sc_ebx = regs->tf_ebx; - sf.sf_sc.sc_ecx = regs->tf_ecx; - sf.sf_sc.sc_edx = regs->tf_edx; - sf.sf_sc.sc_esi = regs->tf_esi; - sf.sf_sc.sc_edi = regs->tf_edi; - sf.sf_sc.sc_cs = regs->tf_cs; - sf.sf_sc.sc_ds = regs->tf_ds; - sf.sf_sc.sc_ss = regs->tf_ss; - sf.sf_sc.sc_es = regs->tf_es; - sf.sf_sc.sc_fs = regs->tf_fs; - sf.sf_sc.sc_isp = regs->tf_isp; + sf.sf_siginfo.si_sc.sc_eax = regs->tf_eax; + sf.sf_siginfo.si_sc.sc_ebx = regs->tf_ebx; + sf.sf_siginfo.si_sc.sc_ecx = regs->tf_ecx; + sf.sf_siginfo.si_sc.sc_edx = regs->tf_edx; + sf.sf_siginfo.si_sc.sc_esi = regs->tf_esi; + sf.sf_siginfo.si_sc.sc_edi = regs->tf_edi; + sf.sf_siginfo.si_sc.sc_cs = regs->tf_cs; + sf.sf_siginfo.si_sc.sc_ds = regs->tf_ds; + sf.sf_siginfo.si_sc.sc_ss = regs->tf_ss; + sf.sf_siginfo.si_sc.sc_es = regs->tf_es; + sf.sf_siginfo.si_sc.sc_fs = regs->tf_fs; + sf.sf_siginfo.si_sc.sc_isp = regs->tf_isp; /* * Build the signal context to be used by sigreturn. */ - sf.sf_sc.sc_onstack = oonstack; - sf.sf_sc.sc_mask = mask; - sf.sf_sc.sc_sp = regs->tf_esp; - sf.sf_sc.sc_fp = regs->tf_ebp; - sf.sf_sc.sc_pc = regs->tf_eip; - sf.sf_sc.sc_ps = regs->tf_eflags; - sf.sf_sc.sc_trapno = regs->tf_trapno; - sf.sf_sc.sc_err = regs->tf_err; + sf.sf_siginfo.si_sc.sc_onstack = oonstack; + sf.sf_siginfo.si_sc.sc_mask = mask; + sf.sf_siginfo.si_sc.sc_sp = regs->tf_esp; + sf.sf_siginfo.si_sc.sc_fp = regs->tf_ebp; + sf.sf_siginfo.si_sc.sc_pc = regs->tf_eip; + sf.sf_siginfo.si_sc.sc_ps = regs->tf_eflags; + sf.sf_siginfo.si_sc.sc_trapno = regs->tf_trapno; + sf.sf_siginfo.si_sc.sc_err = regs->tf_err; /* * If we're a vm86 process, we want to save the segment registers. @@ -568,13 +585,13 @@ sendsig(catcher, sig, mask, code) struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs; struct vm86_kernel *vm86 = &p->p_addr->u_pcb.pcb_ext->ext_vm86; - sf.sf_sc.sc_gs = tf->tf_vm86_gs; - sf.sf_sc.sc_fs = tf->tf_vm86_fs; - sf.sf_sc.sc_es = tf->tf_vm86_es; - sf.sf_sc.sc_ds = tf->tf_vm86_ds; + sf.sf_siginfo.si_sc.sc_gs = tf->tf_vm86_gs; + sf.sf_siginfo.si_sc.sc_fs = tf->tf_vm86_fs; + sf.sf_siginfo.si_sc.sc_es = tf->tf_vm86_es; + sf.sf_siginfo.si_sc.sc_ds = tf->tf_vm86_ds; if (vm86->vm86_has_vme == 0) - sf.sf_sc.sc_ps = (tf->tf_eflags & ~(PSL_VIF | PSL_VIP)) + sf.sf_siginfo.si_sc.sc_ps = (tf->tf_eflags & ~(PSL_VIF | PSL_VIP)) | (vm86->vm86_eflags & (PSL_VIF | PSL_VIP)); /* @@ -640,7 +657,7 @@ sigreturn(p, uap) */ scp = uap->sigcntxp; fp = (struct sigframe *) - ((caddr_t)scp - offsetof(struct sigframe, sf_sc)); + ((caddr_t)scp - offsetof(struct sigframe, sf_siginfo.si_sc)); if (useracc((caddr_t)fp, sizeof (*fp), B_WRITE) == 0) return(EFAULT); diff --git a/sys/amd64/include/frame.h b/sys/amd64/include/frame.h index 5c0dcda..f339f01 100644 --- a/sys/amd64/include/frame.h +++ b/sys/amd64/include/frame.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)frame.h 5.2 (Berkeley) 1/18/91 - * $Id: frame.h,v 1.16 1999/04/28 01:03:59 luoqi Exp $ + * $Id: frame.h,v 1.17 1999/05/11 16:29:01 luoqi Exp $ */ #ifndef _MACHINE_FRAME_H_ @@ -158,15 +158,39 @@ struct clockframe { }; /* - * Signal frame + * Signal frame, arguments passed to application signal handlers. */ struct sigframe { - int sf_signum; - int sf_code; - struct sigcontext *sf_scp; - char *sf_addr; - sig_t sf_handler; - struct sigcontext sf_sc; + /* + * The first three members may be used by applications. + */ + + register_t sf_signum; + + /* + * Either 'int' for old-style FreeBSD handler or 'siginfo_t *' + * pointing to sf_siginfo for SA_SIGINFO handlers. + */ + register_t sf_arg2; + + /* Points to sf_siginfo.si_sc. */ + register_t sf_scp; + + /* + * The following arguments are not constrained by the + * function call protocol. + * Applications are not supposed to access these members, + * except using the pointers we provide in the first three + * arguments. + */ + char *sf_addr; + union { + __siginfohandler_t *sf_action; + __sighandler_t *sf_handler; + } sf_ahu; + + /* In the SA_SIGINFO case, sf_arg2 points here. */ + siginfo_t sf_siginfo; }; int kdb_trap __P((int, int, struct trapframe *)); diff --git a/sys/i386/i386/genassym.c b/sys/i386/i386/genassym.c index abb81ec..3e92787 100644 --- a/sys/i386/i386/genassym.c +++ b/sys/i386/i386/genassym.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 - * $Id: genassym.c,v 1.70 1999/06/01 18:19:38 jlemon Exp $ + * $Id: genassym.c,v 1.71 1999/06/28 09:21:41 peter Exp $ */ #include "opt_user_ldt.h" @@ -167,11 +167,8 @@ main() printf("#define\tTF_ESP %#x\n", OS(trapframe, tf_esp)); printf("#define\tTF_SS %#x\n", OS(trapframe, tf_ss)); - printf("#define\tSIGF_SIGNUM %#x\n", OS(sigframe, sf_signum)); - printf("#define\tSIGF_CODE %#x\n", OS(sigframe, sf_code)); - printf("#define\tSIGF_SCP %#x\n", OS(sigframe, sf_scp)); - printf("#define\tSIGF_HANDLER %#x\n", OS(sigframe, sf_handler)); - printf("#define\tSIGF_SC %#x\n", OS(sigframe, sf_sc)); + printf("#define\tSIGF_HANDLER %#x\n", OS(sigframe, sf_ahu.sf_handler)); + printf("#define\tSIGF_SC %#x\n", OS(sigframe, sf_siginfo.si_sc)); printf("#define\tB_READ %#x\n", B_READ); printf("#define\tENOENT %d\n", ENOENT); diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 54c72fc..616e7e5 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.351 1999/07/04 02:26:23 jlemon Exp $ + * $Id: machdep.c,v 1.352 1999/07/05 08:52:49 msmith Exp $ */ #include "apm.h" @@ -509,6 +509,9 @@ sendsig(catcher, sig, mask, code) * Process has trashed its stack; give it an illegal * instruction to halt it in its tracks. */ +#ifdef DEBUG + printf("process %d has trashed its stack\n", p->p_pid); +#endif SIGACTION(p, SIGILL) = SIG_DFL; sig = sigmask(SIGILL); p->p_sigignore &= ~sig; @@ -528,36 +531,50 @@ sendsig(catcher, sig, mask, code) sig = p->p_sysent->sv_sigsize + 1; } sf.sf_signum = sig; - sf.sf_code = code; - sf.sf_scp = &fp->sf_sc; + sf.sf_scp = (register_t)&fp->sf_siginfo.si_sc; + if (p->p_sigacts->ps_siginfo & sigmask(sig)) { + /* + * Signal handler installed with SA_SIGINFO. + */ + sf.sf_arg2 = (register_t)&fp->sf_siginfo; + sf.sf_siginfo.si_signo = sig; + sf.sf_siginfo.si_code = code; + sf.sf_ahu.sf_action = (__siginfohandler_t *)catcher; + } else { + /* + * Old FreeBSD-style arguments. + */ + sf.sf_arg2 = code; + sf.sf_ahu.sf_handler = catcher; + } + sf.sf_addr = (char *) regs->tf_err; - sf.sf_handler = catcher; /* save scratch registers */ - sf.sf_sc.sc_eax = regs->tf_eax; - sf.sf_sc.sc_ebx = regs->tf_ebx; - sf.sf_sc.sc_ecx = regs->tf_ecx; - sf.sf_sc.sc_edx = regs->tf_edx; - sf.sf_sc.sc_esi = regs->tf_esi; - sf.sf_sc.sc_edi = regs->tf_edi; - sf.sf_sc.sc_cs = regs->tf_cs; - sf.sf_sc.sc_ds = regs->tf_ds; - sf.sf_sc.sc_ss = regs->tf_ss; - sf.sf_sc.sc_es = regs->tf_es; - sf.sf_sc.sc_fs = regs->tf_fs; - sf.sf_sc.sc_isp = regs->tf_isp; + sf.sf_siginfo.si_sc.sc_eax = regs->tf_eax; + sf.sf_siginfo.si_sc.sc_ebx = regs->tf_ebx; + sf.sf_siginfo.si_sc.sc_ecx = regs->tf_ecx; + sf.sf_siginfo.si_sc.sc_edx = regs->tf_edx; + sf.sf_siginfo.si_sc.sc_esi = regs->tf_esi; + sf.sf_siginfo.si_sc.sc_edi = regs->tf_edi; + sf.sf_siginfo.si_sc.sc_cs = regs->tf_cs; + sf.sf_siginfo.si_sc.sc_ds = regs->tf_ds; + sf.sf_siginfo.si_sc.sc_ss = regs->tf_ss; + sf.sf_siginfo.si_sc.sc_es = regs->tf_es; + sf.sf_siginfo.si_sc.sc_fs = regs->tf_fs; + sf.sf_siginfo.si_sc.sc_isp = regs->tf_isp; /* * Build the signal context to be used by sigreturn. */ - sf.sf_sc.sc_onstack = oonstack; - sf.sf_sc.sc_mask = mask; - sf.sf_sc.sc_sp = regs->tf_esp; - sf.sf_sc.sc_fp = regs->tf_ebp; - sf.sf_sc.sc_pc = regs->tf_eip; - sf.sf_sc.sc_ps = regs->tf_eflags; - sf.sf_sc.sc_trapno = regs->tf_trapno; - sf.sf_sc.sc_err = regs->tf_err; + sf.sf_siginfo.si_sc.sc_onstack = oonstack; + sf.sf_siginfo.si_sc.sc_mask = mask; + sf.sf_siginfo.si_sc.sc_sp = regs->tf_esp; + sf.sf_siginfo.si_sc.sc_fp = regs->tf_ebp; + sf.sf_siginfo.si_sc.sc_pc = regs->tf_eip; + sf.sf_siginfo.si_sc.sc_ps = regs->tf_eflags; + sf.sf_siginfo.si_sc.sc_trapno = regs->tf_trapno; + sf.sf_siginfo.si_sc.sc_err = regs->tf_err; /* * If we're a vm86 process, we want to save the segment registers. @@ -568,13 +585,13 @@ sendsig(catcher, sig, mask, code) struct trapframe_vm86 *tf = (struct trapframe_vm86 *)regs; struct vm86_kernel *vm86 = &p->p_addr->u_pcb.pcb_ext->ext_vm86; - sf.sf_sc.sc_gs = tf->tf_vm86_gs; - sf.sf_sc.sc_fs = tf->tf_vm86_fs; - sf.sf_sc.sc_es = tf->tf_vm86_es; - sf.sf_sc.sc_ds = tf->tf_vm86_ds; + sf.sf_siginfo.si_sc.sc_gs = tf->tf_vm86_gs; + sf.sf_siginfo.si_sc.sc_fs = tf->tf_vm86_fs; + sf.sf_siginfo.si_sc.sc_es = tf->tf_vm86_es; + sf.sf_siginfo.si_sc.sc_ds = tf->tf_vm86_ds; if (vm86->vm86_has_vme == 0) - sf.sf_sc.sc_ps = (tf->tf_eflags & ~(PSL_VIF | PSL_VIP)) + sf.sf_siginfo.si_sc.sc_ps = (tf->tf_eflags & ~(PSL_VIF | PSL_VIP)) | (vm86->vm86_eflags & (PSL_VIF | PSL_VIP)); /* @@ -640,7 +657,7 @@ sigreturn(p, uap) */ scp = uap->sigcntxp; fp = (struct sigframe *) - ((caddr_t)scp - offsetof(struct sigframe, sf_sc)); + ((caddr_t)scp - offsetof(struct sigframe, sf_siginfo.si_sc)); if (useracc((caddr_t)fp, sizeof (*fp), B_WRITE) == 0) return(EFAULT); diff --git a/sys/i386/include/frame.h b/sys/i386/include/frame.h index 5c0dcda..f339f01 100644 --- a/sys/i386/include/frame.h +++ b/sys/i386/include/frame.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)frame.h 5.2 (Berkeley) 1/18/91 - * $Id: frame.h,v 1.16 1999/04/28 01:03:59 luoqi Exp $ + * $Id: frame.h,v 1.17 1999/05/11 16:29:01 luoqi Exp $ */ #ifndef _MACHINE_FRAME_H_ @@ -158,15 +158,39 @@ struct clockframe { }; /* - * Signal frame + * Signal frame, arguments passed to application signal handlers. */ struct sigframe { - int sf_signum; - int sf_code; - struct sigcontext *sf_scp; - char *sf_addr; - sig_t sf_handler; - struct sigcontext sf_sc; + /* + * The first three members may be used by applications. + */ + + register_t sf_signum; + + /* + * Either 'int' for old-style FreeBSD handler or 'siginfo_t *' + * pointing to sf_siginfo for SA_SIGINFO handlers. + */ + register_t sf_arg2; + + /* Points to sf_siginfo.si_sc. */ + register_t sf_scp; + + /* + * The following arguments are not constrained by the + * function call protocol. + * Applications are not supposed to access these members, + * except using the pointers we provide in the first three + * arguments. + */ + char *sf_addr; + union { + __siginfohandler_t *sf_action; + __sighandler_t *sf_handler; + } sf_ahu; + + /* In the SA_SIGINFO case, sf_arg2 points here. */ + siginfo_t sf_siginfo; }; int kdb_trap __P((int, int, struct trapframe *)); diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 78f5d50..2e63a0a 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94 - * $Id: kern_sig.c,v 1.55 1999/04/28 11:36:59 phk Exp $ + * $Id: kern_sig.c,v 1.56 1999/05/03 23:57:22 billf Exp $ */ #include "opt_compat.h" @@ -126,9 +126,13 @@ sigaction(p, uap) return (EINVAL); sa = &vec; if (uap->osa) { - sa->sa_handler = ps->ps_sigact[signum]; - sa->sa_mask = ps->ps_catchmask[signum]; bit = sigmask(signum); + if ((ps->ps_siginfo & bit) != 0) + sa->sa_sigaction = + (__siginfohandler_t *)ps->ps_sigact[signum]; + else + sa->sa_handler = ps->ps_sigact[signum]; + sa->sa_mask = ps->ps_catchmask[signum]; sa->sa_flags = 0; if ((ps->ps_sigonstack & bit) != 0) sa->sa_flags |= SA_ONSTACK; @@ -138,6 +142,8 @@ sigaction(p, uap) sa->sa_flags |= SA_RESETHAND; if ((ps->ps_signodefer & bit) != 0) sa->sa_flags |= SA_NODEFER; + if ((ps->ps_siginfo & bit) != 0) + sa->sa_flags |= SA_SIGINFO; if (signum == SIGCHLD && p->p_procsig->ps_flag & P_NOCLDSTOP) sa->sa_flags |= SA_NOCLDSTOP; if (signum == SIGCHLD && p->p_procsig->ps_flag & P_NOCLDWAIT) @@ -151,7 +157,7 @@ sigaction(p, uap) sizeof (vec)))) return (error); if ((signum == SIGKILL || signum == SIGSTOP) && - sa->sa_handler != SIG_DFL) + ps->ps_sigact[signum] != SIG_DFL) return (EINVAL); setsigvec(p, signum, sa); } @@ -172,8 +178,14 @@ setsigvec(p, signum, sa) * Change setting atomically. */ (void) splhigh(); - ps->ps_sigact[signum] = sa->sa_handler; ps->ps_catchmask[signum] = sa->sa_mask &~ sigcantmask; + if (sa->sa_flags & SA_SIGINFO) { + ps->ps_sigact[signum] = sa->sa_handler; + ps->ps_siginfo |= bit; + } else { + ps->ps_sigact[signum] = (__sighandler_t *)sa->sa_sigaction; + ps->ps_siginfo &= ~bit; + } if ((sa->sa_flags & SA_RESTART) == 0) ps->ps_sigintr |= bit; else @@ -221,15 +233,15 @@ setsigvec(p, signum, sa) * However, don't put SIGCONT in p_sigignore, * as we have to restart the process. */ - if (sa->sa_handler == SIG_IGN || - (sigprop[signum] & SA_IGNORE && sa->sa_handler == SIG_DFL)) { + if (ps->ps_sigact[signum] == SIG_IGN || + (sigprop[signum] & SA_IGNORE && ps->ps_sigact[signum] == SIG_DFL)) { p->p_siglist &= ~bit; /* never to be seen again */ if (signum != SIGCONT) p->p_sigignore |= bit; /* easier in psignal */ p->p_sigcatch &= ~bit; } else { p->p_sigignore &= ~bit; - if (sa->sa_handler == SIG_DFL) + if (ps->ps_sigact[signum] == SIG_DFL) p->p_sigcatch &= ~bit; else p->p_sigcatch |= bit; @@ -387,6 +399,8 @@ osigvec(p, uap) sv->sv_flags |= SV_RESETHAND; if ((ps->ps_signodefer & bit) != 0) sv->sv_flags |= SV_NODEFER; + if ((ps->ps_siginfo & bit) != 0) + sv->sv_flags |= SV_SIGINFO; #ifndef COMPAT_SUNOS if (signum == SIGCHLD && p->p_procsig->ps_flag & P_NOCLDSTOP) sv->sv_flags |= SV_NOCLDSTOP; diff --git a/sys/sys/_sigset.h b/sys/sys/_sigset.h index 39d554e..471baa9 100644 --- a/sys/sys/_sigset.h +++ b/sys/sys/_sigset.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)signal.h 8.4 (Berkeley) 5/4/95 - * $Id: signal.h,v 1.13 1998/03/28 11:50:43 dufault Exp $ + * $Id: signal.h,v 1.14 1998/08/05 09:04:36 dfr Exp $ */ #ifndef _SYS_SIGNAL_H_ @@ -113,6 +113,50 @@ */ typedef void __sighandler_t __P((int)); +#if defined(_P1003_1B_VISIBLE_HISTORICALLY) || \ + (!defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)) +union sigval { + /* Members as suggested by Annex C of POSIX 1003.1b. */ + int sigval_int; + void *sigval_ptr; +}; +#endif /* !_ANSI_SOURCE && _P1003_1B_VISIBLE_HISTORICALLY */ + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +/* POSIX 1003.1b required values. */ +#define SI_USER 0x10001 +#define SI_QUEUE 0x10002 +#define SI_TIMER 0x10003 +#define SI_ASYNCIO 0x10004 +#define SI_MESGQ 0x10005 + +/* Additional FreeBSD values. */ +#define SI_UNDEFINED 0 + +struct __siginfo { + struct sigcontext si_sc; + int si_signo; /* signal number */ + + /* + * Cause of signal, one of the SI_ macros or signal-specific + * values, i.e. one of the FPE_... values for SIGFPE. This + * value is equivalent to the second argument to an old-style + * FreeBSD signal handler. + */ + int si_code; + + union sigval si_value; +}; +#else /* ! _ANSI_SOURCE && ! _POSIX_SOURCE */ +struct __siginfo; +#endif /* ! _ANSI_SOURCE && ! _POSIX_SOURCE */ + +typedef struct __siginfo siginfo_t; + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +typedef void __siginfohandler_t __P((int, siginfo_t *, void *)); +#endif /* ! _ANSI_SOURCE && ! _POSIX_SOURCE */ + #define SIG_DFL ((__sighandler_t *)0) #define SIG_IGN ((__sighandler_t *)1) #define SIG_ERR ((__sighandler_t *)-1) @@ -124,16 +168,26 @@ typedef unsigned int sigset_t; * Signal vector "template" used in sigaction call. */ struct sigaction { - __sighandler_t *sa_handler; /* signal handler */ + union { + void (*__sa_handler) __P((int)); + void (*__sa_sigaction) __P((int, siginfo_t *, void *)); + } __sigaction_u; /* signal handler */ sigset_t sa_mask; /* signal mask to apply */ int sa_flags; /* see signal options below */ }; +/* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */ +#define sa_handler __sigaction_u.__sa_handler +#ifndef _POSIX_SOURCE +#define sa_sigaction __sigaction_u.__sa_sigaction +#endif + #ifndef _POSIX_SOURCE #define SA_ONSTACK 0x0001 /* take signal on signal stack */ #define SA_RESTART 0x0002 /* restart system call on signal return */ #define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */ #define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */ #define SA_NOCLDWAIT 0x0020 /* don't keep zombies around */ +#define SA_SIGINFO 0x0040 /* signal handler with SA_SIGINFO args */ #ifdef COMPAT_SUNOS #define SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtramp */ #endif @@ -183,6 +237,7 @@ struct sigvec { #define SV_RESETHAND SA_RESETHAND #define SV_NODEFER SA_NODEFER #define SV_NOCLDSTOP SA_NOCLDSTOP +#define SV_SIGINFO SA_SIGINFO #define sv_onstack sv_flags /* isn't compatibility wonderful! */ /* @@ -204,20 +259,7 @@ struct sigstack { #endif /* !_POSIX_SOURCE */ #endif /* !_ANSI_SOURCE */ -#ifdef _P1003_1B_VISIBLE_HISTORICALLY - -/* sys/aio.h unconditionally defined these */ - -union sigval { - int sival_int; /* Integer signal value */ - void *sival_ptr; /* Pointer signal value */ -}; - -typedef struct siginfo { - int si_signo; /* Signal number */ - int si_code; /* Cause of the signal */ - union sigval si_value; /* Signal value */ -} siginfo_t; +#if !defined(_ANSI_SOURCE) && defined(_P1003_1B_VISIBLE_HISTORICALLY) struct sigevent { int sigev_notify; /* Notification type */ @@ -228,7 +270,7 @@ struct sigevent { #define SIGEV_NONE 0 /* No async notification */ #define SIGEV_SIGNAL 1 /* Generate a queued signal */ -#endif +#endif /* ! _ANSI_SOURCE && _P1003_1B_VISIBLE_HISTORICALLY */ /* * For historical reasons; programs expect signal's return value to be diff --git a/sys/sys/signal.h b/sys/sys/signal.h index 39d554e..471baa9 100644 --- a/sys/sys/signal.h +++ b/sys/sys/signal.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)signal.h 8.4 (Berkeley) 5/4/95 - * $Id: signal.h,v 1.13 1998/03/28 11:50:43 dufault Exp $ + * $Id: signal.h,v 1.14 1998/08/05 09:04:36 dfr Exp $ */ #ifndef _SYS_SIGNAL_H_ @@ -113,6 +113,50 @@ */ typedef void __sighandler_t __P((int)); +#if defined(_P1003_1B_VISIBLE_HISTORICALLY) || \ + (!defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)) +union sigval { + /* Members as suggested by Annex C of POSIX 1003.1b. */ + int sigval_int; + void *sigval_ptr; +}; +#endif /* !_ANSI_SOURCE && _P1003_1B_VISIBLE_HISTORICALLY */ + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +/* POSIX 1003.1b required values. */ +#define SI_USER 0x10001 +#define SI_QUEUE 0x10002 +#define SI_TIMER 0x10003 +#define SI_ASYNCIO 0x10004 +#define SI_MESGQ 0x10005 + +/* Additional FreeBSD values. */ +#define SI_UNDEFINED 0 + +struct __siginfo { + struct sigcontext si_sc; + int si_signo; /* signal number */ + + /* + * Cause of signal, one of the SI_ macros or signal-specific + * values, i.e. one of the FPE_... values for SIGFPE. This + * value is equivalent to the second argument to an old-style + * FreeBSD signal handler. + */ + int si_code; + + union sigval si_value; +}; +#else /* ! _ANSI_SOURCE && ! _POSIX_SOURCE */ +struct __siginfo; +#endif /* ! _ANSI_SOURCE && ! _POSIX_SOURCE */ + +typedef struct __siginfo siginfo_t; + +#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) +typedef void __siginfohandler_t __P((int, siginfo_t *, void *)); +#endif /* ! _ANSI_SOURCE && ! _POSIX_SOURCE */ + #define SIG_DFL ((__sighandler_t *)0) #define SIG_IGN ((__sighandler_t *)1) #define SIG_ERR ((__sighandler_t *)-1) @@ -124,16 +168,26 @@ typedef unsigned int sigset_t; * Signal vector "template" used in sigaction call. */ struct sigaction { - __sighandler_t *sa_handler; /* signal handler */ + union { + void (*__sa_handler) __P((int)); + void (*__sa_sigaction) __P((int, siginfo_t *, void *)); + } __sigaction_u; /* signal handler */ sigset_t sa_mask; /* signal mask to apply */ int sa_flags; /* see signal options below */ }; +/* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */ +#define sa_handler __sigaction_u.__sa_handler +#ifndef _POSIX_SOURCE +#define sa_sigaction __sigaction_u.__sa_sigaction +#endif + #ifndef _POSIX_SOURCE #define SA_ONSTACK 0x0001 /* take signal on signal stack */ #define SA_RESTART 0x0002 /* restart system call on signal return */ #define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */ #define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */ #define SA_NOCLDWAIT 0x0020 /* don't keep zombies around */ +#define SA_SIGINFO 0x0040 /* signal handler with SA_SIGINFO args */ #ifdef COMPAT_SUNOS #define SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtramp */ #endif @@ -183,6 +237,7 @@ struct sigvec { #define SV_RESETHAND SA_RESETHAND #define SV_NODEFER SA_NODEFER #define SV_NOCLDSTOP SA_NOCLDSTOP +#define SV_SIGINFO SA_SIGINFO #define sv_onstack sv_flags /* isn't compatibility wonderful! */ /* @@ -204,20 +259,7 @@ struct sigstack { #endif /* !_POSIX_SOURCE */ #endif /* !_ANSI_SOURCE */ -#ifdef _P1003_1B_VISIBLE_HISTORICALLY - -/* sys/aio.h unconditionally defined these */ - -union sigval { - int sival_int; /* Integer signal value */ - void *sival_ptr; /* Pointer signal value */ -}; - -typedef struct siginfo { - int si_signo; /* Signal number */ - int si_code; /* Cause of the signal */ - union sigval si_value; /* Signal value */ -} siginfo_t; +#if !defined(_ANSI_SOURCE) && defined(_P1003_1B_VISIBLE_HISTORICALLY) struct sigevent { int sigev_notify; /* Notification type */ @@ -228,7 +270,7 @@ struct sigevent { #define SIGEV_NONE 0 /* No async notification */ #define SIGEV_SIGNAL 1 /* Generate a queued signal */ -#endif +#endif /* ! _ANSI_SOURCE && _P1003_1B_VISIBLE_HISTORICALLY */ /* * For historical reasons; programs expect signal's return value to be diff --git a/sys/sys/signalvar.h b/sys/sys/signalvar.h index a9f9c40..48d4b9e 100644 --- a/sys/sys/signalvar.h +++ b/sys/sys/signalvar.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)signalvar.h 8.6 (Berkeley) 2/19/95 - * $Id: signalvar.h,v 1.22 1999/01/07 21:23:46 julian Exp $ + * $Id: signalvar.h,v 1.23 1999/01/26 02:38:11 julian Exp $ */ #ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */ @@ -55,6 +55,7 @@ struct sigacts { sigset_t ps_sigintr; /* signals that interrupt syscalls */ sigset_t ps_sigreset; /* signals that reset when caught */ sigset_t ps_signodefer; /* signals not masked while handled */ + sigset_t ps_siginfo; /* signals that want SA_SIGINFO args */ int ps_flags; /* signal flags, below */ struct sigaltstack ps_sigstk; /* sp & on stack state variable */ sigset_t ps_usertramp; /* SunOS compat; libc sigtramp XXX */ |