diff options
author | Thorsten Lockert <tholo@cvs.openbsd.org> | 2001-02-02 19:48:09 +0000 |
---|---|---|
committer | Thorsten Lockert <tholo@cvs.openbsd.org> | 2001-02-02 19:48:09 +0000 |
commit | d6c176cacaec61f6276521d9ed3c313feb1e6964 (patch) | |
tree | 663f0b101f2cda6b7d3fcc2483148522d9f7b778 /sys/compat | |
parent | 6df397adccd28bfcc8bf941a4ebaf0fdefb2b99a (diff) |
Emulate some FreeBSD 4.x signal syscalls -- makes more new binaries work
Diffstat (limited to 'sys/compat')
-rw-r--r-- | sys/compat/freebsd/files.freebsd | 3 | ||||
-rw-r--r-- | sys/compat/freebsd/freebsd_signal.c | 242 | ||||
-rw-r--r-- | sys/compat/freebsd/freebsd_signal.h | 90 |
3 files changed, 334 insertions, 1 deletions
diff --git a/sys/compat/freebsd/files.freebsd b/sys/compat/freebsd/files.freebsd index 4f8999b5814..1382efaddfa 100644 --- a/sys/compat/freebsd/files.freebsd +++ b/sys/compat/freebsd/files.freebsd @@ -1,4 +1,4 @@ -# $OpenBSD: files.freebsd,v 1.3 1999/11/10 15:55:20 mickey Exp $ +# $OpenBSD: files.freebsd,v 1.4 2001/02/02 19:48:07 tholo Exp $ # $NetBSD: files.freebsd,v 1.1 1995/10/10 01:19:26 mycroft Exp $ # # Config.new file description for machine-independent FreeBSD compat code. @@ -12,5 +12,6 @@ file compat/freebsd/freebsd_file.c compat_freebsd file compat/freebsd/freebsd_ioctl.c compat_freebsd file compat/freebsd/freebsd_misc.c compat_freebsd file compat/freebsd/freebsd_ptrace.c compat_freebsd +file compat/freebsd/freebsd_signal.c compat_freebsd file compat/freebsd/freebsd_sysent.c compat_freebsd file compat/freebsd/freebsd_syscalls.c compat_freebsd & syscall_debug diff --git a/sys/compat/freebsd/freebsd_signal.c b/sys/compat/freebsd/freebsd_signal.c new file mode 100644 index 00000000000..8b6a0afaa6d --- /dev/null +++ b/sys/compat/freebsd/freebsd_signal.c @@ -0,0 +1,242 @@ +/* $OpenBSD: freebsd_signal.c,v 1.1 2001/02/02 19:48:07 tholo Exp $ */ +/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */ + +/* + * Copyright (c) 1997 Theo de Raadt. All rights reserved. + * Copyright (c) 1982, 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94 + */ + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/signalvar.h> +#include <sys/signal.h> +#include <sys/systm.h> +#include <sys/mount.h> + +#include <compat/freebsd/freebsd_signal.h> +#include <compat/freebsd/freebsd_syscallargs.h> + +static void freebsd_to_openbsd_sigaction __P((struct freebsd_sigaction *, + struct sigaction *)); + +static void openbsd_to_freebsd_sigaction __P((struct sigaction *, + struct freebsd_sigaction *)); + +static void +openbsd_to_freebsd_sigaction(obsa, fbsa) + struct sigaction *obsa; + struct freebsd_sigaction *fbsa; +{ + bzero(fbsa, sizeof(struct freebsd_sigaction)); + fbsa->freebsd_sa_handler = obsa->sa_handler; + bcopy(&obsa->sa_mask, &fbsa->freebsd_sa_mask.__bits[0], + sizeof(sigset_t)); + fbsa->freebsd_sa_flags = obsa->sa_flags; +} + +static void +freebsd_to_openbsd_sigaction(fbsa, obsa) + struct freebsd_sigaction *fbsa; + struct sigaction *obsa; +{ + obsa->sa_handler = fbsa->freebsd_sa_handler; + bcopy(&fbsa->freebsd_sa_mask.__bits[0], &obsa->sa_mask, + sizeof(sigset_t)); + obsa->sa_flags = fbsa->freebsd_sa_flags; +} + +/* ARGSUSED */ +int +freebsd_sys_sigaction40(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct freebsd_sys_sigaction40_args /* { + syscallarg(int) sig; + syscallarg(struct freebsd_sigaction *) act; + syscallarg(struct freebsd_sigaction *) oact; + } */ *uap = v; + struct sigaction vec; + register struct sigaction *sa; + struct freebsd_sigaction fbsa; + register struct sigacts *ps = p->p_sigacts; + register int signum; + int bit, error; + + signum = SCARG(uap, sig); + if (signum <= 0 || signum >= NSIG || + (SCARG(uap, act) && (signum == SIGKILL || signum == SIGSTOP))) + return (EINVAL); + sa = &vec; + if (SCARG(uap, oact)) { + sa->sa_handler = ps->ps_sigact[signum]; + sa->sa_mask = ps->ps_catchmask[signum]; + bit = sigmask(signum); + sa->sa_flags = 0; + if ((ps->ps_sigonstack & bit) != 0) + sa->sa_flags |= SA_ONSTACK; + if ((ps->ps_sigintr & bit) == 0) + sa->sa_flags |= SA_RESTART; + if ((ps->ps_sigreset & bit) != 0) + sa->sa_flags |= SA_RESETHAND; + if ((ps->ps_siginfo & bit) != 0) + sa->sa_flags |= SA_SIGINFO; + if (signum == SIGCHLD) { + if ((p->p_flag & P_NOCLDSTOP) != 0) + sa->sa_flags |= SA_NOCLDSTOP; + if ((p->p_flag & P_NOCLDWAIT) != 0) + sa->sa_flags |= SA_NOCLDWAIT; + } + if ((sa->sa_mask & bit) == 0) + sa->sa_flags |= SA_NODEFER; + sa->sa_mask &= ~bit; + openbsd_to_freebsd_sigaction(sa, &fbsa); + error = copyout((caddr_t)&fbsa, (caddr_t)SCARG(uap, oact), + sizeof (struct freebsd_sigaction)); + if (error) + return (error); + } + if (SCARG(uap, act)) { + error = copyin((caddr_t)SCARG(uap, act), (caddr_t)&fbsa, + sizeof (struct freebsd_sigaction)); + if (error) + return (error); + freebsd_to_openbsd_sigaction(&fbsa, sa); + setsigvec(p, signum, sa); + } + return (0); +} + +/* ARGSUSED */ +int +freebsd_sys_sigpending40(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + register struct freebsd_sys_sigpending40_args /* { + freebsd_sigset_t *set; + } */ *uap = v; + freebsd_sigset_t fss; + + bcopy(&p->p_siglist, &fss.__bits[0], sizeof(sigset_t)); + return (copyout((caddr_t)&fss, (caddr_t)SCARG(uap, set), sizeof(fss))); +} + +int +freebsd_sys_sigprocmask40(p, v, retval) + register struct proc *p; + void *v; + register_t *retval; +{ + struct freebsd_sys_sigprocmask40_args /* { + syscallarg(int) how; + syscallarg(freebsd_sigset_t *) set; + syscallarg(freebsd_sigset_t *) oset; + } */ *uap = v; + freebsd_sigset_t nss, oss; + sigset_t obnss; + int error = 0; + + if (SCARG(uap, set)) { + error = copyin(SCARG(uap, set), &nss, sizeof(nss)); + if (error) + return (error); + } + if (SCARG(uap, oset)) { + bzero(&oss, sizeof(freebsd_sigset_t)); + bcopy(&p->p_sigmask, &oss.__bits[0], sizeof(sigset_t)); + error = copyout((caddr_t)&oss, (caddr_t)SCARG(uap, oset), + sizeof(freebsd_sigset_t)); + if (error) + return (error); + } + if (SCARG(uap, set)) { + bcopy(&nss.__bits[0], &obnss, sizeof(sigset_t)); + (void)splhigh(); + switch (SCARG(uap, how)) { + case SIG_BLOCK: + p->p_sigmask |= obnss &~ sigcantmask; + break; + case SIG_UNBLOCK: + p->p_sigmask &= ~obnss; + break; + case SIG_SETMASK: + p->p_sigmask = obnss &~ sigcantmask; + break; + default: + error = EINVAL; + break; + } + (void) spl0(); + } + return (error); +} + +int +freebsd_sys_sigsuspend40(p, v, retval) + register struct proc *p; + void *v; + register_t *retval; +{ + struct freebsd_sys_sigsuspend40_args /* { + syscallarg(freebsd_sigset_t *) sigmask; + } */ *uap = v; + register struct sigacts *ps = p->p_sigacts; + freebsd_sigset_t fbset; + sigset_t obset; + + copyin(SCARG(uap, sigmask), &fbset, sizeof(freebsd_sigset_t)); + bcopy(&fbset.__bits[0], &obset, sizeof(sigset_t)); + /* + * When returning from sigpause, we want + * the old mask to be restored after the + * signal handler has finished. Thus, we + * save it here and mark the sigacts structure + * to indicate this. + */ + ps->ps_oldmask = p->p_sigmask; + ps->ps_flags |= SAS_OLDMASK; + p->p_sigmask = obset &~ sigcantmask; + while (tsleep((caddr_t) ps, PPAUSE|PCATCH, "pause", 0) == 0) + /* void */; + /* always return EINTR rather than ERESTART... */ + return (EINTR); +} diff --git a/sys/compat/freebsd/freebsd_signal.h b/sys/compat/freebsd/freebsd_signal.h new file mode 100644 index 00000000000..bd4f21db3fe --- /dev/null +++ b/sys/compat/freebsd/freebsd_signal.h @@ -0,0 +1,90 @@ +/* $OpenBSD: freebsd_signal.h,v 1.1 2001/02/02 19:48:08 tholo Exp $ */ +/* $NetBSD: signal.h,v 1.42 1998/12/21 10:35:00 drochner Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)signal.h 8.4 (Berkeley) 5/4/95 + */ + +#ifndef _FREEBSD_SYS_SIGNAL_H_ +#define _FREEBSD_SYS_SIGNAL_H_ + +typedef struct { + u_int32_t __bits[4]; +} freebsd_sigset_t; + +union freebsd_sigval { + /* Members as suggested by Annex C of POSIX 1003.1b. */ + int freebsd_sigval_int; + void *freebsd_sigval_ptr; +}; + +typedef struct __freebsd_siginfo { + int freebsd_si_signo; /* signal number */ + int freebsd_si_errno; /* errno association */ + /* + * 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 freebsd_si_code; /* signal code */ + int freebsd_si_pid; /* sending process */ + unsigned int freebsd_si_uid; /* sender's ruid */ + int freebsd_si_status; /* exit value */ + void *freebsd_si_addr; /* faulting instruction */ + union freebsd_sigval freebsd_si_value; /* signal value */ + long freebsd_si_band; /* band event for SIGPOLL */ + int __spare__[7]; /* gimme some slack */ +} freebsd_siginfo_t; + +/* + * Signal vector "template" used in sigaction call. + */ +struct freebsd_sigaction { + union { + void (*__freebsd_sa_handler) __P((int)); + void (*__freebsd_sa_sigaction) __P((int, struct __freebsd_siginfo *, void *)); + } __freebsd_sigaction_u; /* signal handler */ + int freebsd_sa_flags; /* see signal options below */ + freebsd_sigset_t freebsd_sa_mask; /* signal mask to apply */ +}; +#define freebsd_sa_handler __freebsd_sigaction_u.__freebsd_sa_handler +#define freebsd_sa_sigaction __freebsd_sigaction_u.__freebsd_sa_sigaction + +#endif /* !_FREEBSD_SYS_SIGNAL_H_ */ |