2008-04-29 00:22:51 +04:00
|
|
|
/* $NetBSD: linux_signal.c,v 1.62 2008/04/28 20:23:44 martin Exp $ */
|
2007-02-10 00:55:00 +03:00
|
|
|
|
1998-10-04 04:02:23 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
|
1995-03-01 02:24:35 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-10-04 04:02:23 +04:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Frank van der Linden and Eric Haszlakiewicz.
|
|
|
|
*
|
1995-03-01 02:24:35 +03:00
|
|
|
* 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.
|
|
|
|
*
|
1998-10-04 04:02:23 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
/*
|
1995-03-01 02:24:35 +03:00
|
|
|
* heavily from: svr4_signal.c,v 1.7 1995/01/09 01:04:21 christos Exp
|
|
|
|
*/
|
|
|
|
|
1998-10-01 06:27:33 +04:00
|
|
|
/*
|
|
|
|
* Functions in multiarch:
|
|
|
|
* linux_sys_signal : linux_sig_notalpha.c
|
|
|
|
* linux_sys_siggetmask : linux_sig_notalpha.c
|
|
|
|
* linux_sys_sigsetmask : linux_sig_notalpha.c
|
|
|
|
* linux_sys_pause : linux_sig_notalpha.c
|
|
|
|
* linux_sys_sigaction : linux_sigaction.c
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unimplemented:
|
|
|
|
* linux_sys_rt_sigtimedwait : sigsuspend w/timeout.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 05:07:52 +03:00
|
|
|
#include <sys/cdefs.h>
|
2008-04-29 00:22:51 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.62 2008/04/28 20:23:44 martin Exp $");
|
2001-11-13 05:07:52 +03:00
|
|
|
|
1998-12-19 19:27:09 +03:00
|
|
|
#define COMPAT_LINUX 1
|
|
|
|
|
1995-03-01 02:24:35 +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>
|
|
|
|
|
1998-10-04 00:17:36 +04:00
|
|
|
#include <compat/linux/common/linux_types.h>
|
|
|
|
#include <compat/linux/common/linux_signal.h>
|
2005-11-23 19:14:57 +03:00
|
|
|
#include <compat/linux/common/linux_exec.h> /* For emul_linux */
|
|
|
|
#include <compat/linux/common/linux_machdep.h> /* For LINUX_NPTL */
|
|
|
|
#include <compat/linux/common/linux_emuldata.h> /* for linux_emuldata */
|
1998-10-08 02:12:48 +04:00
|
|
|
#include <compat/linux/common/linux_siginfo.h>
|
2005-05-16 20:00:31 +04:00
|
|
|
#include <compat/linux/common/linux_sigevent.h>
|
1998-10-04 00:17:36 +04:00
|
|
|
#include <compat/linux/common/linux_util.h>
|
2007-10-19 22:52:09 +04:00
|
|
|
#include <compat/linux/common/linux_ipc.h>
|
|
|
|
#include <compat/linux/common/linux_sem.h>
|
1998-10-04 00:17:36 +04:00
|
|
|
|
1995-03-01 02:24:35 +03:00
|
|
|
#include <compat/linux/linux_syscallargs.h>
|
|
|
|
|
1998-10-01 06:27:33 +04:00
|
|
|
/* Locally used defines (in bsd<->linux conversion functions): */
|
1998-08-10 00:36:58 +04:00
|
|
|
#define linux_sigemptyset(s) memset((s), 0, sizeof(*(s)))
|
1998-12-15 22:31:30 +03:00
|
|
|
#define linux_sigismember(s, n) ((s)->sig[((n) - 1) / LINUX__NSIG_BPW] \
|
|
|
|
& (1 << ((n) - 1) % LINUX__NSIG_BPW))
|
|
|
|
#define linux_sigaddset(s, n) ((s)->sig[((n) - 1) / LINUX__NSIG_BPW] \
|
|
|
|
|= (1 << ((n) - 1) % LINUX__NSIG_BPW))
|
1995-08-14 02:55:28 +04:00
|
|
|
|
2002-03-22 20:14:18 +03:00
|
|
|
#ifdef DEBUG_LINUX
|
|
|
|
#define DPRINTF(a) uprintf a
|
|
|
|
#else
|
|
|
|
#define DPRINTF(a)
|
|
|
|
#endif
|
|
|
|
|
2002-04-01 02:22:43 +04:00
|
|
|
extern const int native_to_linux_signo[];
|
|
|
|
extern const int linux_to_native_signo[];
|
1995-08-14 02:55:28 +04:00
|
|
|
|
1998-10-01 06:27:33 +04:00
|
|
|
/*
|
1998-12-15 22:31:30 +03:00
|
|
|
* Convert between Linux and BSD signal sets.
|
1998-10-01 06:27:33 +04:00
|
|
|
*/
|
1998-12-15 22:31:30 +03:00
|
|
|
#if LINUX__NSIG_WORDS > 1
|
1995-08-14 02:55:28 +04:00
|
|
|
void
|
2007-12-08 21:35:53 +03:00
|
|
|
linux_old_extra_to_native_sigset(sigset_t *bss, const linux_old_sigset_t *lss, const unsigned long *extra)
|
1998-12-15 22:31:30 +03:00
|
|
|
{
|
|
|
|
linux_sigset_t lsnew;
|
|
|
|
|
|
|
|
/* convert old sigset to new sigset */
|
|
|
|
linux_sigemptyset(&lsnew);
|
|
|
|
lsnew.sig[0] = *lss;
|
|
|
|
if (extra)
|
2002-02-15 19:47:58 +03:00
|
|
|
memcpy(&lsnew.sig[1], extra,
|
|
|
|
sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
|
1998-12-15 22:31:30 +03:00
|
|
|
|
2002-02-15 19:47:58 +03:00
|
|
|
linux_to_native_sigset(bss, &lsnew);
|
1998-12-15 22:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-08 21:35:53 +03:00
|
|
|
native_to_linux_old_extra_sigset(linux_old_sigset_t *lss, unsigned long *extra, const sigset_t *bss)
|
1998-12-15 22:31:30 +03:00
|
|
|
{
|
|
|
|
linux_sigset_t lsnew;
|
|
|
|
|
2002-02-15 19:47:58 +03:00
|
|
|
native_to_linux_sigset(&lsnew, bss);
|
1998-12-15 22:31:30 +03:00
|
|
|
|
|
|
|
/* convert new sigset to old sigset */
|
|
|
|
*lss = lsnew.sig[0];
|
|
|
|
if (extra)
|
2002-02-15 19:47:58 +03:00
|
|
|
memcpy(extra, &lsnew.sig[1],
|
|
|
|
sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
|
1998-12-15 22:31:30 +03:00
|
|
|
}
|
2005-05-03 20:26:27 +04:00
|
|
|
#endif /* LINUX__NSIG_WORDS > 1 */
|
1998-12-15 22:31:30 +03:00
|
|
|
|
|
|
|
void
|
2007-12-08 21:35:53 +03:00
|
|
|
linux_to_native_sigset(sigset_t *bss, const linux_sigset_t *lss)
|
1995-03-01 02:24:35 +03:00
|
|
|
{
|
|
|
|
int i, newsig;
|
|
|
|
|
1995-08-14 02:55:28 +04:00
|
|
|
sigemptyset(bss);
|
1998-12-15 22:31:30 +03:00
|
|
|
for (i = 1; i < LINUX__NSIG; i++) {
|
1995-08-14 02:55:28 +04:00
|
|
|
if (linux_sigismember(lss, i)) {
|
2002-04-01 02:22:43 +04:00
|
|
|
newsig = linux_to_native_signo[i];
|
1995-03-01 02:24:35 +03:00
|
|
|
if (newsig)
|
1995-08-14 02:55:28 +04:00
|
|
|
sigaddset(bss, newsig);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-08 21:35:53 +03:00
|
|
|
native_to_linux_sigset(linux_sigset_t *lss, const sigset_t *bss)
|
1995-03-01 02:24:35 +03:00
|
|
|
{
|
|
|
|
int i, newsig;
|
1998-12-15 22:31:30 +03:00
|
|
|
|
1995-08-14 02:55:28 +04:00
|
|
|
linux_sigemptyset(lss);
|
|
|
|
for (i = 1; i < NSIG; i++) {
|
|
|
|
if (sigismember(bss, i)) {
|
2002-04-01 02:22:43 +04:00
|
|
|
newsig = native_to_linux_signo[i];
|
1995-03-01 02:24:35 +03:00
|
|
|
if (newsig)
|
1995-08-14 02:55:28 +04:00
|
|
|
linux_sigaddset(lss, newsig);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-19 01:24:17 +03:00
|
|
|
unsigned int
|
2007-12-08 21:35:53 +03:00
|
|
|
native_to_linux_sigflags(const int bsf)
|
2002-02-15 19:47:58 +03:00
|
|
|
{
|
2002-02-19 01:24:17 +03:00
|
|
|
unsigned int lsf = 0;
|
|
|
|
if ((bsf & SA_NOCLDSTOP) != 0)
|
|
|
|
lsf |= LINUX_SA_NOCLDSTOP;
|
|
|
|
if ((bsf & SA_NOCLDWAIT) != 0)
|
|
|
|
lsf |= LINUX_SA_NOCLDWAIT;
|
|
|
|
if ((bsf & SA_ONSTACK) != 0)
|
|
|
|
lsf |= LINUX_SA_ONSTACK;
|
|
|
|
if ((bsf & SA_RESTART) != 0)
|
|
|
|
lsf |= LINUX_SA_RESTART;
|
|
|
|
if ((bsf & SA_NODEFER) != 0)
|
|
|
|
lsf |= LINUX_SA_NOMASK;
|
|
|
|
if ((bsf & SA_RESETHAND) != 0)
|
|
|
|
lsf |= LINUX_SA_ONESHOT;
|
|
|
|
if ((bsf & SA_SIGINFO) != 0)
|
|
|
|
lsf |= LINUX_SA_SIGINFO;
|
|
|
|
return lsf;
|
2002-02-15 19:47:58 +03:00
|
|
|
}
|
|
|
|
|
2002-02-19 01:24:17 +03:00
|
|
|
int
|
2007-12-08 21:35:53 +03:00
|
|
|
linux_to_native_sigflags(const unsigned long lsf)
|
2002-02-15 19:47:58 +03:00
|
|
|
{
|
2002-02-19 01:24:17 +03:00
|
|
|
int bsf = 0;
|
|
|
|
if ((lsf & LINUX_SA_NOCLDSTOP) != 0)
|
|
|
|
bsf |= SA_NOCLDSTOP;
|
|
|
|
if ((lsf & LINUX_SA_NOCLDWAIT) != 0)
|
|
|
|
bsf |= SA_NOCLDWAIT;
|
|
|
|
if ((lsf & LINUX_SA_ONSTACK) != 0)
|
|
|
|
bsf |= SA_ONSTACK;
|
|
|
|
if ((lsf & LINUX_SA_RESTART) != 0)
|
|
|
|
bsf |= SA_RESTART;
|
|
|
|
if ((lsf & LINUX_SA_ONESHOT) != 0)
|
|
|
|
bsf |= SA_RESETHAND;
|
|
|
|
if ((lsf & LINUX_SA_NOMASK) != 0)
|
|
|
|
bsf |= SA_NODEFER;
|
|
|
|
if ((lsf & LINUX_SA_SIGINFO) != 0)
|
|
|
|
bsf |= SA_SIGINFO;
|
2006-09-13 04:52:07 +04:00
|
|
|
if ((lsf & ~LINUX_SA_ALLBITS) != 0) {
|
2002-03-22 20:14:18 +03:00
|
|
|
DPRINTF(("linux_old_to_native_sigflags: "
|
|
|
|
"%lx extra bits ignored\n", lsf));
|
2006-09-13 04:52:07 +04:00
|
|
|
}
|
2002-02-19 01:24:17 +03:00
|
|
|
return bsf;
|
2002-02-15 19:47:58 +03:00
|
|
|
}
|
|
|
|
|
1995-03-01 02:24:35 +03:00
|
|
|
/*
|
2005-05-20 01:16:29 +04:00
|
|
|
* Convert between Linux and BSD sigaction structures.
|
1995-03-01 02:24:35 +03:00
|
|
|
*/
|
|
|
|
void
|
2007-12-08 21:35:53 +03:00
|
|
|
linux_old_to_native_sigaction(struct sigaction *bsa, const struct linux_old_sigaction *lsa)
|
1998-10-01 06:27:33 +04:00
|
|
|
{
|
2002-11-26 21:43:20 +03:00
|
|
|
bsa->sa_handler = lsa->linux_sa_handler;
|
|
|
|
linux_old_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
|
|
|
|
bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
|
1998-10-01 06:27:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-08 21:35:53 +03:00
|
|
|
native_to_linux_old_sigaction(struct linux_old_sigaction *lsa, const struct sigaction *bsa)
|
1998-10-01 06:27:33 +04:00
|
|
|
{
|
2002-11-26 21:43:20 +03:00
|
|
|
lsa->linux_sa_handler = bsa->sa_handler;
|
|
|
|
native_to_linux_old_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
|
|
|
|
lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
|
2002-02-19 01:24:17 +03:00
|
|
|
#ifndef __alpha__
|
2002-11-26 21:43:20 +03:00
|
|
|
lsa->linux_sa_restorer = NULL;
|
2002-02-19 01:24:17 +03:00
|
|
|
#endif
|
1998-10-01 06:27:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ...and the new sigaction conversion funcs. */
|
|
|
|
void
|
2007-12-08 21:35:53 +03:00
|
|
|
linux_to_native_sigaction(struct sigaction *bsa, const struct linux_sigaction *lsa)
|
1995-03-01 02:24:35 +03:00
|
|
|
{
|
2002-11-26 21:43:20 +03:00
|
|
|
bsa->sa_handler = lsa->linux_sa_handler;
|
|
|
|
linux_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
|
|
|
|
bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-08 21:35:53 +03:00
|
|
|
native_to_linux_sigaction(struct linux_sigaction *lsa, const struct sigaction *bsa)
|
1995-03-01 02:24:35 +03:00
|
|
|
{
|
2002-11-26 21:43:20 +03:00
|
|
|
lsa->linux_sa_handler = bsa->sa_handler;
|
|
|
|
native_to_linux_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
|
|
|
|
lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
|
2002-02-19 01:24:17 +03:00
|
|
|
#ifndef __alpha__
|
2002-11-26 21:43:20 +03:00
|
|
|
lsa->linux_sa_restorer = NULL;
|
2002-02-19 01:24:17 +03:00
|
|
|
#endif
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
1998-10-01 06:27:33 +04:00
|
|
|
/* ----------------------------------------------------------------------- */
|
1995-03-01 02:24:35 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The Linux sigaction() system call. Do the usual conversions,
|
|
|
|
* and just call sigaction(). Some flags and values are silently
|
|
|
|
* ignored (see above).
|
|
|
|
*/
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_rt_sigaction(struct lwp *l, const struct linux_sys_rt_sigaction_args *uap, register_t *retval)
|
1995-09-20 02:37:27 +04:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
1995-03-01 02:24:35 +03:00
|
|
|
syscallarg(int) signum;
|
1998-09-11 16:50:05 +04:00
|
|
|
syscallarg(const struct linux_sigaction *) nsa;
|
1995-03-01 02:24:35 +03:00
|
|
|
syscallarg(struct linux_sigaction *) osa;
|
1998-10-01 06:27:33 +04:00
|
|
|
syscallarg(size_t) sigsetsize;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
1998-09-11 16:50:05 +04:00
|
|
|
struct linux_sigaction nlsa, olsa;
|
|
|
|
struct sigaction nbsa, obsa;
|
1999-12-05 01:26:52 +03:00
|
|
|
int error, sig;
|
2005-05-20 01:16:29 +04:00
|
|
|
void *tramp = NULL;
|
|
|
|
int vers = 0;
|
2005-05-20 05:06:50 +04:00
|
|
|
#if defined __amd64__
|
2007-02-10 00:55:00 +03:00
|
|
|
struct sigacts *ps = l->l_proc->p_sigacts;
|
2005-05-20 01:16:29 +04:00
|
|
|
#endif
|
1995-03-01 02:24:35 +03:00
|
|
|
|
1998-10-01 06:27:33 +04:00
|
|
|
if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
|
|
|
|
return (EINVAL);
|
|
|
|
|
1998-09-11 16:50:05 +04:00
|
|
|
if (SCARG(uap, nsa)) {
|
|
|
|
error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-02-15 19:47:58 +03:00
|
|
|
linux_to_native_sigaction(&nbsa, &nlsa);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
2005-05-20 01:16:29 +04:00
|
|
|
|
1999-12-05 01:26:52 +03:00
|
|
|
sig = SCARG(uap, signum);
|
|
|
|
if (sig < 0 || sig >= LINUX__NSIG)
|
|
|
|
return (EINVAL);
|
2002-04-01 02:22:43 +04:00
|
|
|
if (sig > 0 && !linux_to_native_signo[sig]) {
|
2000-08-10 00:20:49 +04:00
|
|
|
/* Pretend that we did something useful for unknown signals. */
|
|
|
|
obsa.sa_handler = SIG_IGN;
|
|
|
|
sigemptyset(&obsa.sa_mask);
|
|
|
|
obsa.sa_flags = 0;
|
|
|
|
} else {
|
2005-05-20 01:16:29 +04:00
|
|
|
#if defined __amd64__
|
|
|
|
if (nlsa.linux_sa_flags & LINUX_SA_RESTORER) {
|
|
|
|
if ((tramp = nlsa.linux_sa_restorer) != NULL)
|
|
|
|
vers = 2; /* XXX arch dependant */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
error = sigaction1(l, linux_to_native_signo[sig],
|
2002-07-05 03:32:02 +04:00
|
|
|
SCARG(uap, nsa) ? &nbsa : NULL,
|
|
|
|
SCARG(uap, osa) ? &obsa : NULL,
|
2005-05-20 01:16:29 +04:00
|
|
|
tramp, vers);
|
2000-08-10 00:20:49 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
1998-09-11 16:50:05 +04:00
|
|
|
if (SCARG(uap, osa)) {
|
2002-02-15 19:47:58 +03:00
|
|
|
native_to_linux_sigaction(&olsa, &obsa);
|
2005-05-20 01:16:29 +04:00
|
|
|
|
|
|
|
#if defined __amd64__
|
|
|
|
if (ps->sa_sigdesc[sig].sd_vers != 0) {
|
|
|
|
olsa.linux_sa_restorer = ps->sa_sigdesc[sig].sd_tramp;
|
|
|
|
olsa.linux_sa_flags |= LINUX_SA_RESTORER;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-09-11 16:50:05 +04:00
|
|
|
error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
return (0);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-12-08 21:35:53 +03:00
|
|
|
linux_sigprocmask1(struct lwp *l, int how, const linux_old_sigset_t *set, linux_old_sigset_t *oset)
|
1995-09-20 02:37:27 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
1998-10-01 06:27:33 +04:00
|
|
|
linux_old_sigset_t nlss, olss;
|
1998-09-11 16:50:05 +04:00
|
|
|
sigset_t nbss, obss;
|
|
|
|
int error;
|
1995-03-01 02:24:35 +03:00
|
|
|
|
1998-10-08 02:12:48 +04:00
|
|
|
switch (how) {
|
1995-03-01 02:24:35 +03:00
|
|
|
case LINUX_SIG_BLOCK:
|
1998-09-11 16:50:05 +04:00
|
|
|
how = SIG_BLOCK;
|
1995-03-01 02:24:35 +03:00
|
|
|
break;
|
|
|
|
case LINUX_SIG_UNBLOCK:
|
1998-09-11 16:50:05 +04:00
|
|
|
how = SIG_UNBLOCK;
|
1995-03-01 02:24:35 +03:00
|
|
|
break;
|
|
|
|
case LINUX_SIG_SETMASK:
|
1998-09-11 16:50:05 +04:00
|
|
|
how = SIG_SETMASK;
|
1995-03-01 02:24:35 +03:00
|
|
|
break;
|
|
|
|
default:
|
1998-09-11 16:50:05 +04:00
|
|
|
return (EINVAL);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
1998-10-08 02:12:48 +04:00
|
|
|
if (set) {
|
|
|
|
error = copyin(set, &nlss, sizeof(nlss));
|
1998-09-11 16:50:05 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-02-15 19:47:58 +03:00
|
|
|
linux_old_to_native_sigset(&nbss, &nlss);
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
error = sigprocmask1(l, how,
|
2000-07-29 01:38:44 +04:00
|
|
|
set ? &nbss : NULL, oset ? &obss : NULL);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
1998-09-11 16:50:05 +04:00
|
|
|
if (error)
|
2005-02-27 01:58:54 +03:00
|
|
|
return (error);
|
1998-10-08 02:12:48 +04:00
|
|
|
if (oset) {
|
2002-02-15 19:47:58 +03:00
|
|
|
native_to_linux_old_sigset(&olss, &obss);
|
1998-10-08 02:12:48 +04:00
|
|
|
error = copyout(&olss, oset, sizeof(olss));
|
1998-09-11 16:50:05 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2005-02-27 01:58:54 +03:00
|
|
|
}
|
1998-09-11 16:50:05 +04:00
|
|
|
return (error);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
1998-10-08 02:12:48 +04:00
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_rt_sigprocmask(struct lwp *l, const struct linux_sys_rt_sigprocmask_args *uap, register_t *retval)
|
1998-10-08 02:12:48 +04:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
1998-10-08 02:12:48 +04:00
|
|
|
syscallarg(int) how;
|
|
|
|
syscallarg(const linux_sigset_t *) set;
|
|
|
|
syscallarg(linux_sigset_t *) oset;
|
|
|
|
syscallarg(size_t) sigsetsize;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
1999-10-04 21:46:37 +04:00
|
|
|
linux_sigset_t nlss, olss, *oset;
|
|
|
|
const linux_sigset_t *set;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
1999-10-04 21:46:37 +04:00
|
|
|
sigset_t nbss, obss;
|
|
|
|
int error, how;
|
|
|
|
|
|
|
|
if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
switch (SCARG(uap, how)) {
|
|
|
|
case LINUX_SIG_BLOCK:
|
|
|
|
how = SIG_BLOCK;
|
|
|
|
break;
|
|
|
|
case LINUX_SIG_UNBLOCK:
|
|
|
|
how = SIG_UNBLOCK;
|
|
|
|
break;
|
|
|
|
case LINUX_SIG_SETMASK:
|
|
|
|
how = SIG_SETMASK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
1998-10-08 02:12:48 +04:00
|
|
|
}
|
|
|
|
|
1999-10-04 21:46:37 +04:00
|
|
|
set = SCARG(uap, set);
|
|
|
|
oset = SCARG(uap, oset);
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
error = copyin(set, &nlss, sizeof(nlss));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2002-02-15 19:47:58 +03:00
|
|
|
linux_to_native_sigset(&nbss, &nlss);
|
1999-10-04 21:46:37 +04:00
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
error = sigprocmask1(l, how,
|
2000-07-29 01:38:44 +04:00
|
|
|
set ? &nbss : NULL, oset ? &obss : NULL);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2000-07-29 01:49:09 +04:00
|
|
|
if (!error && oset) {
|
2002-02-15 19:47:58 +03:00
|
|
|
native_to_linux_sigset(&olss, &obss);
|
1999-10-04 21:46:37 +04:00
|
|
|
error = copyout(&olss, oset, sizeof(olss));
|
2005-02-27 01:58:54 +03:00
|
|
|
}
|
1999-10-04 21:46:37 +04:00
|
|
|
return (error);
|
1998-10-08 02:12:48 +04:00
|
|
|
}
|
|
|
|
|
1995-03-01 02:24:35 +03:00
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_rt_sigpending(struct lwp *l, const struct linux_sys_rt_sigpending_args *uap, register_t *retval)
|
1995-03-01 02:24:35 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
1998-10-01 06:27:33 +04:00
|
|
|
syscallarg(linux_sigset_t *) set;
|
|
|
|
syscallarg(size_t) sigsetsize;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
1998-09-11 16:50:05 +04:00
|
|
|
sigset_t bss;
|
|
|
|
linux_sigset_t lss;
|
1995-03-01 02:24:35 +03:00
|
|
|
|
1998-10-01 06:27:33 +04:00
|
|
|
if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
|
|
|
|
return (EINVAL);
|
1995-03-01 02:24:35 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
sigpending1(l, &bss);
|
2002-02-15 19:47:58 +03:00
|
|
|
native_to_linux_sigset(&lss, &bss);
|
1998-10-01 06:27:33 +04:00
|
|
|
return copyout(&lss, SCARG(uap, set), sizeof(lss));
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
1999-10-04 21:46:37 +04:00
|
|
|
|
2005-05-03 20:26:27 +04:00
|
|
|
#ifndef __amd64__
|
1995-03-01 02:24:35 +03:00
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_sigpending(struct lwp *l, const struct linux_sys_sigpending_args *uap, register_t *retval)
|
1995-03-01 02:24:35 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
1998-10-01 06:27:33 +04:00
|
|
|
syscallarg(linux_old_sigset_t *) mask;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
1998-09-11 16:50:05 +04:00
|
|
|
sigset_t bss;
|
1998-10-01 06:27:33 +04:00
|
|
|
linux_old_sigset_t lss;
|
1995-03-01 02:24:35 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
sigpending1(l, &bss);
|
2002-02-15 19:47:58 +03:00
|
|
|
native_to_linux_old_sigset(&lss, &bss);
|
1998-09-11 16:50:05 +04:00
|
|
|
return copyout(&lss, SCARG(uap, set), sizeof(lss));
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_sigsuspend(struct lwp *l, const struct linux_sys_sigsuspend_args *uap, register_t *retval)
|
1995-09-20 02:37:27 +04:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-03-04 08:59:00 +03:00
|
|
|
syscallarg(void *) restart;
|
1995-03-11 01:55:04 +03:00
|
|
|
syscallarg(int) oldmask;
|
1995-03-01 02:24:35 +03:00
|
|
|
syscallarg(int) mask;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
1998-10-01 06:27:33 +04:00
|
|
|
linux_old_sigset_t lss;
|
1998-09-11 16:50:05 +04:00
|
|
|
sigset_t bss;
|
1998-10-01 06:27:33 +04:00
|
|
|
|
1998-09-11 16:50:05 +04:00
|
|
|
lss = SCARG(uap, mask);
|
2002-02-15 19:47:58 +03:00
|
|
|
linux_old_to_native_sigset(&bss, &lss);
|
2007-02-10 00:55:00 +03:00
|
|
|
return (sigsuspend1(l, &bss));
|
1998-10-01 06:27:33 +04:00
|
|
|
}
|
2005-05-03 20:26:27 +04:00
|
|
|
#endif /* __amd64__ */
|
|
|
|
|
1998-10-01 06:27:33 +04:00
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_rt_sigsuspend(struct lwp *l, const struct linux_sys_rt_sigsuspend_args *uap, register_t *retval)
|
1998-10-01 06:27:33 +04:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
1998-10-01 06:27:33 +04:00
|
|
|
syscallarg(linux_sigset_t *) unewset;
|
|
|
|
syscallarg(size_t) sigsetsize;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
1998-10-01 06:27:33 +04:00
|
|
|
linux_sigset_t lss;
|
|
|
|
sigset_t bss;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2002-02-15 19:47:58 +03:00
|
|
|
linux_to_native_sigset(&bss, &lss);
|
1998-10-01 06:27:33 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
return (sigsuspend1(l, &bss));
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
1995-03-11 01:55:04 +03:00
|
|
|
/*
|
1998-10-01 06:27:33 +04:00
|
|
|
* Once more: only a signal conversion is needed.
|
|
|
|
* Note: also used as sys_rt_queueinfo. The info field is ignored.
|
1995-03-11 01:55:04 +03:00
|
|
|
*/
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_rt_queueinfo(struct lwp *l, const struct linux_sys_rt_queueinfo_args *uap, register_t *retval)
|
1998-10-01 06:27:33 +04:00
|
|
|
{
|
|
|
|
/* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
|
|
|
|
#if 0
|
|
|
|
struct linux_sys_rt_queueinfo_args /* {
|
|
|
|
syscallarg(int) pid;
|
|
|
|
syscallarg(int) signum;
|
|
|
|
syscallarg(siginfo_t *) uinfo;
|
|
|
|
} */ *uap = v;
|
|
|
|
#endif
|
1995-03-11 01:55:04 +03:00
|
|
|
|
1998-10-01 06:27:33 +04:00
|
|
|
/* XXX To really implement this we need to */
|
|
|
|
/* XXX keep a list of queued signals somewhere. */
|
2007-12-21 02:02:38 +03:00
|
|
|
return (linux_sys_kill(l, (const void *)uap, retval));
|
1995-03-11 01:55:04 +03:00
|
|
|
}
|
|
|
|
|
1995-03-01 02:24:35 +03:00
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_kill(struct lwp *l, const struct linux_sys_kill_args *uap, register_t *retval)
|
1995-09-20 02:37:27 +04:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
1995-03-01 02:24:35 +03:00
|
|
|
syscallarg(int) pid;
|
|
|
|
syscallarg(int) signum;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2003-01-19 00:21:28 +03:00
|
|
|
|
1995-10-07 09:25:19 +03:00
|
|
|
struct sys_kill_args ka;
|
1999-12-05 01:26:52 +03:00
|
|
|
int sig;
|
1995-08-14 02:55:28 +04:00
|
|
|
|
|
|
|
SCARG(&ka, pid) = SCARG(uap, pid);
|
1999-12-05 01:26:52 +03:00
|
|
|
sig = SCARG(uap, signum);
|
|
|
|
if (sig < 0 || sig >= LINUX__NSIG)
|
|
|
|
return (EINVAL);
|
2002-04-01 02:22:43 +04:00
|
|
|
SCARG(&ka, signum) = linux_to_native_signo[sig];
|
2003-01-19 00:21:28 +03:00
|
|
|
return sys_kill(l, &ka, retval);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
2000-08-23 21:02:18 +04:00
|
|
|
|
|
|
|
#ifdef LINUX_SS_ONSTACK
|
2007-12-04 21:40:07 +03:00
|
|
|
static void linux_to_native_sigaltstack(struct sigaltstack *,
|
|
|
|
const struct linux_sigaltstack *);
|
2000-08-23 21:02:18 +04:00
|
|
|
|
|
|
|
static void
|
2007-12-08 21:35:53 +03:00
|
|
|
linux_to_native_sigaltstack(struct sigaltstack *bss, const struct linux_sigaltstack *lss)
|
2000-08-23 21:02:18 +04:00
|
|
|
{
|
|
|
|
bss->ss_sp = lss->ss_sp;
|
|
|
|
bss->ss_size = lss->ss_size;
|
|
|
|
if (lss->ss_flags & LINUX_SS_ONSTACK)
|
|
|
|
bss->ss_flags = SS_ONSTACK;
|
|
|
|
else if (lss->ss_flags & LINUX_SS_DISABLE)
|
|
|
|
bss->ss_flags = SS_DISABLE;
|
|
|
|
else
|
|
|
|
bss->ss_flags = 0;
|
|
|
|
}
|
|
|
|
|
2003-07-04 01:22:32 +04:00
|
|
|
void
|
2007-12-08 21:35:53 +03:00
|
|
|
native_to_linux_sigaltstack(struct linux_sigaltstack *lss, const struct sigaltstack *bss)
|
2000-08-23 21:02:18 +04:00
|
|
|
{
|
|
|
|
lss->ss_sp = bss->ss_sp;
|
|
|
|
lss->ss_size = bss->ss_size;
|
|
|
|
if (bss->ss_flags & SS_ONSTACK)
|
|
|
|
lss->ss_flags = LINUX_SS_ONSTACK;
|
|
|
|
else if (bss->ss_flags & SS_DISABLE)
|
|
|
|
lss->ss_flags = LINUX_SS_DISABLE;
|
|
|
|
else
|
|
|
|
lss->ss_flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_sigaltstack(struct lwp *l, const struct linux_sys_sigaltstack_args *uap, register_t *retval)
|
2000-08-23 21:02:18 +04:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2000-08-23 21:02:18 +04:00
|
|
|
syscallarg(const struct linux_sigaltstack *) ss;
|
|
|
|
syscallarg(struct linux_sigaltstack *) oss;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2000-08-23 21:02:18 +04:00
|
|
|
struct linux_sigaltstack ss;
|
2005-09-19 06:46:49 +04:00
|
|
|
struct sigaltstack nss;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
int error = 0;
|
2000-08-23 21:02:18 +04:00
|
|
|
|
2005-09-19 06:46:49 +04:00
|
|
|
if (SCARG(uap, oss)) {
|
2007-02-10 00:55:00 +03:00
|
|
|
native_to_linux_sigaltstack(&ss, &l->l_sigstk);
|
2005-09-19 06:46:49 +04:00
|
|
|
if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-08-23 21:02:18 +04:00
|
|
|
if (SCARG(uap, ss) != NULL) {
|
|
|
|
if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
|
|
|
|
return error;
|
|
|
|
linux_to_native_sigaltstack(&nss, &ss);
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2005-09-19 06:46:49 +04:00
|
|
|
if (nss.ss_flags & ~SS_ALLBITS)
|
2007-02-10 00:55:00 +03:00
|
|
|
error = EINVAL;
|
|
|
|
else if (nss.ss_flags & SS_DISABLE) {
|
|
|
|
if (l->l_sigstk.ss_flags & SS_ONSTACK)
|
|
|
|
error = EINVAL;
|
|
|
|
} else if (nss.ss_size < LINUX_MINSIGSTKSZ)
|
|
|
|
error = ENOMEM;
|
|
|
|
|
|
|
|
if (error == 0)
|
|
|
|
l->l_sigstk = nss;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2000-08-23 21:02:18 +04:00
|
|
|
}
|
2005-09-19 06:46:49 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
return error;
|
2000-08-23 21:02:18 +04:00
|
|
|
}
|
2005-05-09 23:04:50 +04:00
|
|
|
#endif /* LINUX_SS_ONSTACK */
|
2005-11-23 19:14:57 +03:00
|
|
|
|
|
|
|
#ifdef LINUX_NPTL
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_tkill(struct lwp *l, const struct linux_sys_tkill_args *uap, register_t *retval)
|
2005-11-23 19:14:57 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2005-11-23 19:14:57 +03:00
|
|
|
syscallarg(int) tid;
|
|
|
|
syscallarg(int) sig;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2005-11-23 19:14:57 +03:00
|
|
|
struct linux_sys_kill_args cup;
|
|
|
|
|
|
|
|
/* We use the PID as the TID ... */
|
|
|
|
SCARG(&cup, pid) = SCARG(uap, tid);
|
|
|
|
SCARG(&cup, signum) = SCARG(uap, sig);
|
|
|
|
|
|
|
|
return linux_sys_kill(l, &cup, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
linux_sys_tgkill(struct lwp *l, const struct linux_sys_tgkill_args *uap, register_t *retval)
|
2005-11-23 19:14:57 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2005-11-23 19:14:57 +03:00
|
|
|
syscallarg(int) tgid;
|
|
|
|
syscallarg(int) tid;
|
|
|
|
syscallarg(int) sig;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2005-11-23 19:14:57 +03:00
|
|
|
struct linux_sys_kill_args cup;
|
|
|
|
struct linux_emuldata *led;
|
|
|
|
struct proc *p;
|
|
|
|
|
|
|
|
SCARG(&cup, pid) = SCARG(uap, tid);
|
|
|
|
SCARG(&cup, signum) = SCARG(uap, sig);
|
|
|
|
|
|
|
|
if (SCARG(uap, tgid) == -1)
|
|
|
|
return linux_sys_kill(l, &cup, retval);
|
|
|
|
|
|
|
|
/* We use the PID as the TID, but make sure the group ID is right */
|
2008-04-23 17:11:42 +04:00
|
|
|
/* XXX racy */
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
2008-04-23 17:11:42 +04:00
|
|
|
if ((p = p_find(SCARG(uap, tid), PFIND_LOCKED)) == NULL ||
|
|
|
|
p->p_emul != &emul_linux) {
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2005-11-23 19:14:57 +03:00
|
|
|
return ESRCH;
|
2008-04-23 17:11:42 +04:00
|
|
|
}
|
2005-11-23 19:14:57 +03:00
|
|
|
led = p->p_emuldata;
|
2008-04-23 17:11:42 +04:00
|
|
|
if (led->s->group_pid != SCARG(uap, tgid)) {
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2005-11-23 19:14:57 +03:00
|
|
|
return ESRCH;
|
2008-04-23 17:11:42 +04:00
|
|
|
}
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2005-11-23 19:14:57 +03:00
|
|
|
|
|
|
|
return linux_sys_kill(l, &cup, retval);
|
|
|
|
}
|
|
|
|
#endif /* LINUX_NPTL */
|