2002-04-08 18:51:29 +04:00
|
|
|
/* $NetBSD: osf1_signal.c,v 1.21 2002/04/08 14:51:29 christos Exp $ */
|
1999-04-26 09:35:08 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 Christopher G. Demetriou
|
|
|
|
* for the NetBSD Project.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
1998-01-05 20:51:27 +03:00
|
|
|
|
2001-11-13 05:07:52 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-04-08 18:51:29 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: osf1_signal.c,v 1.21 2002/04/08 14:51:29 christos Exp $");
|
2001-11-13 05:07:52 +03:00
|
|
|
|
1995-10-07 09:25:19 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
|
1999-04-26 05:21:43 +04:00
|
|
|
#include <compat/osf1/osf1.h>
|
1995-10-07 09:25:19 +03:00
|
|
|
#include <compat/osf1/osf1_signal.h>
|
|
|
|
#include <compat/osf1/osf1_syscallargs.h>
|
2000-12-01 15:28:30 +03:00
|
|
|
#include <compat/common/compat_util.h>
|
1999-05-01 06:57:08 +04:00
|
|
|
#include <compat/osf1/osf1_cvt.h>
|
1995-10-07 09:25:19 +03:00
|
|
|
|
1999-05-05 05:51:31 +04:00
|
|
|
#if 0
|
|
|
|
int
|
|
|
|
osf1_sys_kill(p, v, retval)
|
|
|
|
struct proc *p;
|
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct osf1_sys_kill_args *uap = v;
|
|
|
|
struct sys_kill_args ka;
|
|
|
|
|
|
|
|
SCARG(&ka, pid) = SCARG(uap, pid);
|
2002-04-08 18:51:29 +04:00
|
|
|
SCARG(&ka, signum) = osf1_to_native_signo[SCARG(uap, signum)];
|
1999-05-05 05:51:31 +04:00
|
|
|
return sys_kill(p, &ka, retval);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1995-10-07 09:25:19 +03:00
|
|
|
int
|
|
|
|
osf1_sys_sigaction(p, v, retval)
|
|
|
|
struct proc *p;
|
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
1999-04-24 11:13:23 +04:00
|
|
|
struct osf1_sys_sigaction_args *uap = v;
|
1995-10-07 09:25:19 +03:00
|
|
|
struct osf1_sigaction *nosa, *oosa, tmposa;
|
1999-04-23 09:56:28 +04:00
|
|
|
struct sigaction *nbsa, *obsa, tmpbsa;
|
|
|
|
struct sys___sigaction14_args sa;
|
1995-10-07 09:25:19 +03:00
|
|
|
caddr_t sg;
|
|
|
|
int error;
|
|
|
|
|
2002-03-16 23:43:48 +03:00
|
|
|
sg = stackgap_init(p, 0);
|
1995-10-07 09:25:19 +03:00
|
|
|
nosa = SCARG(uap, nsa);
|
|
|
|
oosa = SCARG(uap, osa);
|
|
|
|
|
|
|
|
if (oosa != NULL)
|
2002-03-16 23:43:48 +03:00
|
|
|
obsa = stackgap_alloc(p, &sg, sizeof(struct sigaction));
|
1995-10-07 09:25:19 +03:00
|
|
|
else
|
|
|
|
obsa = NULL;
|
|
|
|
|
|
|
|
if (nosa != NULL) {
|
2002-03-16 23:43:48 +03:00
|
|
|
nbsa = stackgap_alloc(p, &sg, sizeof(struct sigaction));
|
1995-10-07 09:25:19 +03:00
|
|
|
if ((error = copyin(nosa, &tmposa, sizeof(tmposa))) != 0)
|
|
|
|
return error;
|
1999-05-01 06:57:08 +04:00
|
|
|
osf1_cvt_sigaction_to_native(&tmposa, &tmpbsa);
|
1995-10-07 09:25:19 +03:00
|
|
|
if ((error = copyout(&tmpbsa, nbsa, sizeof(tmpbsa))) != 0)
|
|
|
|
return error;
|
|
|
|
} else
|
|
|
|
nbsa = NULL;
|
|
|
|
|
2002-04-08 18:51:29 +04:00
|
|
|
SCARG(&sa, signum) = osf1_to_native_signo[SCARG(uap, signum)];
|
1995-10-07 09:25:19 +03:00
|
|
|
SCARG(&sa, nsa) = nbsa;
|
|
|
|
SCARG(&sa, osa) = obsa;
|
|
|
|
|
1999-04-23 09:56:28 +04:00
|
|
|
if ((error = sys___sigaction14(p, &sa, retval)) != 0)
|
1995-10-07 09:25:19 +03:00
|
|
|
return error;
|
|
|
|
|
|
|
|
if (oosa != NULL) {
|
|
|
|
if ((error = copyin(obsa, &tmpbsa, sizeof(tmpbsa))) != 0)
|
|
|
|
return error;
|
1999-05-01 06:57:08 +04:00
|
|
|
osf1_cvt_sigaction_from_native(&tmpbsa, &tmposa);
|
1995-10-07 09:25:19 +03:00
|
|
|
if ((error = copyout(&tmposa, oosa, sizeof(tmposa))) != 0)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
osf1_sys_sigaltstack(p, v, retval)
|
1999-04-24 11:09:49 +04:00
|
|
|
struct proc *p;
|
1995-10-07 09:25:19 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
1999-04-24 11:13:23 +04:00
|
|
|
struct osf1_sys_sigaltstack_args *uap = v;
|
1995-10-07 09:25:19 +03:00
|
|
|
struct osf1_sigaltstack *noss, *ooss, tmposs;
|
|
|
|
struct sigaltstack *nbss, *obss, tmpbss;
|
1998-05-20 20:34:29 +04:00
|
|
|
struct sys___sigaltstack14_args sa;
|
1995-10-07 09:25:19 +03:00
|
|
|
caddr_t sg;
|
|
|
|
int error;
|
|
|
|
|
2002-03-16 23:43:48 +03:00
|
|
|
sg = stackgap_init(p, 0);
|
1995-10-07 09:25:19 +03:00
|
|
|
noss = SCARG(uap, nss);
|
|
|
|
ooss = SCARG(uap, oss);
|
|
|
|
|
|
|
|
if (ooss != NULL)
|
2002-03-16 23:43:48 +03:00
|
|
|
obss = stackgap_alloc(p, &sg, sizeof(struct sigaltstack));
|
1995-10-07 09:25:19 +03:00
|
|
|
else
|
|
|
|
obss = NULL;
|
|
|
|
|
|
|
|
if (noss != NULL) {
|
2002-03-16 23:43:48 +03:00
|
|
|
nbss = stackgap_alloc(p, &sg, sizeof(struct sigaltstack));
|
1995-10-07 09:25:19 +03:00
|
|
|
if ((error = copyin(noss, &tmposs, sizeof(tmposs))) != 0)
|
|
|
|
return error;
|
1999-05-01 06:57:08 +04:00
|
|
|
if ((error = osf1_cvt_sigaltstack_to_native(&tmposs, &tmpbss)) != 0)
|
1999-04-30 09:24:04 +04:00
|
|
|
return error;
|
1995-10-07 09:25:19 +03:00
|
|
|
if ((error = copyout(&tmpbss, nbss, sizeof(tmpbss))) != 0)
|
|
|
|
return error;
|
|
|
|
} else
|
|
|
|
nbss = NULL;
|
|
|
|
|
|
|
|
SCARG(&sa, nss) = nbss;
|
|
|
|
SCARG(&sa, oss) = obss;
|
|
|
|
|
1998-05-20 20:34:29 +04:00
|
|
|
if ((error = sys___sigaltstack14(p, &sa, retval)) != 0)
|
1995-10-07 09:25:19 +03:00
|
|
|
return error;
|
|
|
|
|
|
|
|
if (obss != NULL) {
|
|
|
|
if ((error = copyin(obss, &tmpbss, sizeof(tmpbss))) != 0)
|
|
|
|
return error;
|
1999-05-01 06:57:08 +04:00
|
|
|
osf1_cvt_sigaltstack_from_native(&tmpbss, &tmposs);
|
1995-10-07 09:25:19 +03:00
|
|
|
if ((error = copyout(&tmposs, ooss, sizeof(tmposs))) != 0)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
int
|
|
|
|
osf1_sys_signal(p, v, retval)
|
1999-04-24 11:09:49 +04:00
|
|
|
struct proc *p;
|
1995-10-07 09:25:19 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
1999-04-24 11:13:23 +04:00
|
|
|
struct osf1_sys_signal_args *uap = v;
|
2002-04-08 18:51:29 +04:00
|
|
|
int signum = osf1_to_native_signo[OSF1_SIGNO(SCARG(uap, signum))];
|
1995-10-07 09:25:19 +03:00
|
|
|
int error;
|
2002-03-16 23:43:48 +03:00
|
|
|
caddr_t sg = stackgap_init(p, 0);
|
1995-10-07 09:25:19 +03:00
|
|
|
|
|
|
|
if (signum <= 0 || signum >= OSF1_NSIG) {
|
|
|
|
if (OSF1_SIGCALL(SCARG(uap, signum)) == OSF1_SIGNAL_MASK ||
|
|
|
|
OSF1_SIGCALL(SCARG(uap, signum)) == OSF1_SIGDEFER_MASK)
|
|
|
|
*retval = (int)OSF1_SIG_ERR;
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (OSF1_SIGCALL(SCARG(uap, signum))) {
|
|
|
|
case OSF1_SIGDEFER_MASK:
|
|
|
|
/*
|
|
|
|
* sigset is identical to signal() except
|
|
|
|
* that SIG_HOLD is allowed as
|
|
|
|
* an action.
|
|
|
|
*/
|
|
|
|
if (SCARG(uap, handler) == OSF1_SIG_HOLD) {
|
|
|
|
struct sys_sigprocmask_args sa;
|
|
|
|
|
|
|
|
SCARG(&sa, how) = SIG_BLOCK;
|
|
|
|
SCARG(&sa, mask) = sigmask(signum);
|
|
|
|
return sys_sigprocmask(p, &sa, retval);
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case OSF1_SIGNAL_MASK:
|
|
|
|
{
|
|
|
|
struct sys_sigaction_args sa_args;
|
|
|
|
struct sigaction *nbsa, *obsa, sa;
|
|
|
|
|
2002-03-16 23:43:48 +03:00
|
|
|
nbsa = stackgap_alloc(p, &sg, sizeof(struct sigaction));
|
|
|
|
obsa = stackgap_alloc(p, &sg, sizeof(struct sigaction));
|
1995-10-07 09:25:19 +03:00
|
|
|
SCARG(&sa_args, signum) = signum;
|
|
|
|
SCARG(&sa_args, nsa) = nbsa;
|
|
|
|
SCARG(&sa_args, osa) = obsa;
|
|
|
|
|
|
|
|
sa.sa_handler = SCARG(uap, handler);
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
#if 0
|
|
|
|
if (signum != SIGALRM)
|
|
|
|
sa.sa_flags = SA_RESTART;
|
|
|
|
#endif
|
|
|
|
if ((error = copyout(&sa, nbsa, sizeof(sa))) != 0)
|
|
|
|
return error;
|
|
|
|
if ((error = sys_sigaction(p, &sa_args, retval)) != 0) {
|
|
|
|
DPRINTF(("signal: sigaction failed: %d\n",
|
|
|
|
error));
|
|
|
|
*retval = (int)OSF1_SIG_ERR;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if ((error = copyin(obsa, &sa, sizeof(sa))) != 0)
|
|
|
|
return error;
|
|
|
|
*retval = (int)sa.sa_handler;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OSF1_SIGHOLD_MASK:
|
|
|
|
{
|
|
|
|
struct sys_sigprocmask_args sa;
|
|
|
|
|
|
|
|
SCARG(&sa, how) = SIG_BLOCK;
|
|
|
|
SCARG(&sa, mask) = sigmask(signum);
|
|
|
|
return sys_sigprocmask(p, &sa, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
case OSF1_SIGRELSE_MASK:
|
|
|
|
{
|
|
|
|
struct sys_sigprocmask_args sa;
|
|
|
|
|
|
|
|
SCARG(&sa, how) = SIG_UNBLOCK;
|
|
|
|
SCARG(&sa, mask) = sigmask(signum);
|
|
|
|
return sys_sigprocmask(p, &sa, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
case OSF1_SIGIGNORE_MASK:
|
|
|
|
{
|
|
|
|
struct sys_sigaction_args sa_args;
|
|
|
|
struct sigaction *bsa, sa;
|
|
|
|
|
2002-03-16 23:43:48 +03:00
|
|
|
bsa = stackgap_alloc(p, &sg, sizeof(struct sigaction));
|
1995-10-07 09:25:19 +03:00
|
|
|
SCARG(&sa_args, signum) = signum;
|
|
|
|
SCARG(&sa_args, nsa) = bsa;
|
|
|
|
SCARG(&sa_args, osa) = NULL;
|
|
|
|
|
|
|
|
sa.sa_handler = SIG_IGN;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
if ((error = copyout(&sa, bsa, sizeof(sa))) != 0)
|
|
|
|
return error;
|
|
|
|
if ((error = sys_sigaction(p, &sa_args, retval)) != 0) {
|
|
|
|
DPRINTF(("sigignore: sigaction failed\n"));
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OSF1_SIGPAUSE_MASK:
|
|
|
|
{
|
|
|
|
struct sys_sigsuspend_args sa;
|
|
|
|
|
|
|
|
SCARG(&sa, mask) = p->p_sigmask & ~sigmask(signum);
|
|
|
|
return sys_sigsuspend(p, &sa, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-05 05:51:31 +04:00
|
|
|
int
|
|
|
|
osf1_sys_sigpending(p, v, retval)
|
|
|
|
struct proc *p;
|
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct osf1_sys_sigpending_args *uap = v;
|
|
|
|
sigset_t bss;
|
|
|
|
osf1_sigset_t oss;
|
|
|
|
|
|
|
|
bss = p->p_siglist & p->p_sigmask;
|
|
|
|
osf1_cvt_sigset_from_native(&bss, &oss);
|
|
|
|
|
|
|
|
return copyout(&oss, SCARG(uap, mask), sizeof(oss));
|
|
|
|
}
|
|
|
|
|
1995-10-07 09:25:19 +03:00
|
|
|
int
|
|
|
|
osf1_sys_sigprocmask(p, v, retval)
|
1999-04-24 11:09:49 +04:00
|
|
|
struct proc *p;
|
1995-10-07 09:25:19 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
1999-04-24 11:13:23 +04:00
|
|
|
struct osf1_sys_sigprocmask_args *uap = v;
|
1995-10-07 09:25:19 +03:00
|
|
|
osf1_sigset_t oss;
|
|
|
|
sigset_t bss;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if (SCARG(uap, oset) != NULL) {
|
|
|
|
/* Fix the return value first if needed */
|
1999-05-01 06:57:08 +04:00
|
|
|
osf1_cvt_sigset_from_native(&p->p_sigmask, &oss);
|
1995-10-07 09:25:19 +03:00
|
|
|
if ((error = copyout(&oss, SCARG(uap, oset), sizeof(oss))) != 0)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SCARG(uap, set) == NULL)
|
|
|
|
/* Just examine */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((error = copyin(SCARG(uap, set), &oss, sizeof(oss))) != 0)
|
|
|
|
return error;
|
|
|
|
|
1999-05-01 06:57:08 +04:00
|
|
|
osf1_cvt_sigset_to_native(&oss, &bss);
|
1995-10-07 09:25:19 +03:00
|
|
|
|
2000-08-21 06:33:04 +04:00
|
|
|
(void) splsched(); /* XXXSMP */
|
1995-10-07 09:25:19 +03:00
|
|
|
|
|
|
|
switch (SCARG(uap, how)) {
|
|
|
|
case OSF1_SIG_BLOCK:
|
|
|
|
p->p_sigmask |= bss & ~sigcantmask;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSF1_SIG_UNBLOCK:
|
|
|
|
p->p_sigmask &= ~bss;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSF1_SIG_SETMASK:
|
|
|
|
p->p_sigmask = bss & ~sigcantmask;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) spl0();
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
osf1_sys_sigsuspend(p, v, retval)
|
1999-04-24 11:09:49 +04:00
|
|
|
struct proc *p;
|
1995-10-07 09:25:19 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
1999-04-24 11:13:23 +04:00
|
|
|
struct osf1_sys_sigsuspend_args *uap = v;
|
1995-10-07 09:25:19 +03:00
|
|
|
osf1_sigset_t oss;
|
|
|
|
sigset_t bss;
|
|
|
|
struct sys_sigsuspend_args sa;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if ((error = copyin(SCARG(uap, ss), &oss, sizeof(oss))) != 0)
|
|
|
|
return error;
|
|
|
|
|
1999-05-01 06:57:08 +04:00
|
|
|
osf1_cvt_sigset_to_native(&oss, &bss);
|
1995-10-07 09:25:19 +03:00
|
|
|
|
|
|
|
SCARG(&sa, mask) = bss;
|
|
|
|
return sys_sigsuspend(p, &sa, retval);
|
|
|
|
}
|
|
|
|
#endif
|