NetBSD/sys/compat/common/kern_sig_13.c

184 lines
5.2 KiB
C
Raw Normal View History

/* $NetBSD: kern_sig_13.c,v 1.17 2007/12/20 23:02:44 dsl Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* 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 NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_sig_13.c,v 1.17 2007/12/20 23:02:44 dsl Exp $");
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/signal.h>
#include <sys/signalvar.h>
#include <sys/systm.h>
#include <sys/mount.h>
#include <sys/syscallargs.h>
#include <machine/limits.h>
2005-09-13 05:42:32 +04:00
#include <compat/sys/signal.h>
#include <compat/sys/signalvar.h>
#include <compat/common/compat_util.h>
#include <compat/common/compat_sigaltstack.h>
void
native_sigset13_to_sigset(const sigset13_t *oss, sigset_t *ss)
{
ss->__bits[0] = *oss;
ss->__bits[1] = 0;
ss->__bits[2] = 0;
ss->__bits[3] = 0;
}
void
native_sigset_to_sigset13(const sigset_t *ss, sigset13_t *oss)
{
*oss = ss->__bits[0];
}
void
native_sigaction13_to_sigaction(const struct sigaction13 *osa, struct sigaction *sa)
{
2002-11-26 21:43:20 +03:00
sa->sa_handler = osa->osa_handler;
native_sigset13_to_sigset(&osa->osa_mask, &sa->sa_mask);
sa->sa_flags = osa->osa_flags;
}
void
native_sigaction_to_sigaction13(const struct sigaction *sa, struct sigaction13 *osa)
{
2002-11-26 21:43:20 +03:00
osa->osa_handler = sa->sa_handler;
native_sigset_to_sigset13(&sa->sa_mask, &osa->osa_mask);
osa->osa_flags = sa->sa_flags;
}
int
compat_13_sys_sigaltstack(struct lwp *l, const struct compat_13_sys_sigaltstack_args *uap, register_t *retval)
{
/* {
syscallarg(const struct sigaltstack13 *) nss;
syscallarg(struct sigaltstack13 *) oss;
} */
compat_sigaltstack(uap, sigaltstack13, SS_ONSTACK, SS_DISABLE);
}
int
compat_13_sys_sigaction(struct lwp *l, const struct compat_13_sys_sigaction_args *uap, register_t *retval)
{
/* {
syscallarg(int) signum;
syscallarg(const struct sigaction13 *) nsa;
syscallarg(struct sigaction13 *) osa;
} */
struct sigaction13 nesa, oesa;
struct sigaction nbsa, obsa;
int error;
if (SCARG(uap, nsa)) {
error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
if (error)
return (error);
native_sigaction13_to_sigaction(&nesa, &nbsa);
}
2007-02-10 00:55:00 +03:00
error = sigaction1(l, SCARG(uap, signum),
SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
NULL, 0);
if (error)
return (error);
if (SCARG(uap, osa)) {
native_sigaction_to_sigaction13(&obsa, &oesa);
error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa));
if (error)
return (error);
}
return (0);
}
int
compat_13_sys_sigprocmask(struct lwp *l, const struct compat_13_sys_sigprocmask_args *uap, register_t *retval)
{
/* {
syscallarg(int) how;
syscallarg(int) mask;
} */
2003-01-18 10:28:34 +03:00
struct proc *p = l->l_proc;
sigset13_t ness, oess;
sigset_t nbss, obss;
int error;
ness = SCARG(uap, mask);
native_sigset13_to_sigset(&ness, &nbss);
2007-02-10 00:55:00 +03:00
mutex_enter(&p->p_smutex);
error = sigprocmask1(l, SCARG(uap, how), &nbss, &obss);
mutex_exit(&p->p_smutex);
if (error)
return (error);
native_sigset_to_sigset13(&obss, &oess);
*retval = oess;
return (0);
}
int
compat_13_sys_sigpending(struct lwp *l, const void *v, register_t *retval)
{
sigset13_t ess;
sigset_t bss;
2007-02-10 00:55:00 +03:00
sigpending1(l, &bss);
native_sigset_to_sigset13(&bss, &ess);
*retval = ess;
return (0);
}
int
compat_13_sys_sigsuspend(struct lwp *l, const struct compat_13_sys_sigsuspend_args *uap, register_t *retval)
{
/* {
syscallarg(sigset13_t) mask;
} */
sigset13_t ess;
sigset_t bss;
ess = SCARG(uap, mask);
native_sigset13_to_sigset(&ess, &bss);
2007-02-10 00:55:00 +03:00
return (sigsuspend1(l, &bss));
}