2010-07-01 06:38:26 +04:00
|
|
|
/* $NetBSD: sys_sig.c,v 1.28 2010/07/01 02:38:31 rmind Exp $ */
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*-
|
2008-04-24 22:39:20 +04:00
|
|
|
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
2007-02-10 00:55:00 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Andrew Doran.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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. 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.14 (Berkeley) 5/14/95
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2010-07-01 06:38:26 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.28 2010/07/01 02:38:31 rmind Exp $");
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/pool.h>
|
2008-10-15 10:51:17 +04:00
|
|
|
#include <sys/sa.h>
|
|
|
|
#include <sys/savar.h>
|
2007-02-10 00:55:00 +03:00
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
#include <sys/kauth.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/kmem.h>
|
2008-11-19 21:35:57 +03:00
|
|
|
#include <sys/module.h>
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
int
|
2009-12-20 07:49:09 +03:00
|
|
|
sys___sigaction_sigtramp(struct lwp *l,
|
|
|
|
const struct sys___sigaction_sigtramp_args *uap, register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(int) signum;
|
|
|
|
syscallarg(const struct sigaction *) nsa;
|
|
|
|
syscallarg(struct sigaction *) osa;
|
|
|
|
syscallarg(void *) tramp;
|
|
|
|
syscallarg(int) vers;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct sigaction nsa, osa;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (SCARG(uap, nsa)) {
|
|
|
|
error = copyin(SCARG(uap, nsa), &nsa, sizeof(nsa));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
error = sigaction1(l, SCARG(uap, signum),
|
|
|
|
SCARG(uap, nsa) ? &nsa : 0, SCARG(uap, osa) ? &osa : 0,
|
|
|
|
SCARG(uap, tramp), SCARG(uap, vers));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
if (SCARG(uap, osa)) {
|
|
|
|
error = copyout(&osa, SCARG(uap, osa), sizeof(osa));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
2009-12-20 07:49:09 +03:00
|
|
|
return 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manipulate signal mask. Note that we receive new mask, not pointer, and
|
|
|
|
* return old mask as return value; the library stub does the rest.
|
|
|
|
*/
|
|
|
|
int
|
2009-12-20 07:49:09 +03:00
|
|
|
sys___sigprocmask14(struct lwp *l, const struct sys___sigprocmask14_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(int) how;
|
|
|
|
syscallarg(const sigset_t *) set;
|
|
|
|
syscallarg(sigset_t *) oset;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
sigset_t nss, oss;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (SCARG(uap, set)) {
|
|
|
|
error = copyin(SCARG(uap, set), &nss, sizeof(nss));
|
|
|
|
if (error)
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03: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, SCARG(uap, how),
|
|
|
|
SCARG(uap, set) ? &nss : 0, SCARG(uap, oset) ? &oss : 0);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (error)
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
if (SCARG(uap, oset)) {
|
|
|
|
error = copyout(&oss, SCARG(uap, oset), sizeof(oss));
|
|
|
|
if (error)
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2009-12-20 07:49:09 +03:00
|
|
|
return 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-12-20 07:49:09 +03:00
|
|
|
sys___sigpending14(struct lwp *l, const struct sys___sigpending14_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(sigset_t *) set;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
sigset_t ss;
|
|
|
|
|
|
|
|
sigpending1(l, &ss);
|
2009-12-20 07:49:09 +03:00
|
|
|
return copyout(&ss, SCARG(uap, set), sizeof(ss));
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Suspend process until signal, providing mask to be set in the meantime.
|
|
|
|
* Note nonstandard calling convention: libc stub passes mask, not pointer,
|
|
|
|
* to save a copyin.
|
|
|
|
*/
|
|
|
|
int
|
2009-12-20 07:49:09 +03:00
|
|
|
sys___sigsuspend14(struct lwp *l, const struct sys___sigsuspend14_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(const sigset_t *) set;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
sigset_t ss;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (SCARG(uap, set)) {
|
|
|
|
error = copyin(SCARG(uap, set), &ss, sizeof(ss));
|
|
|
|
if (error)
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2009-12-20 07:49:09 +03:00
|
|
|
return sigsuspend1(l, SCARG(uap, set) ? &ss : 0);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-12-20 07:49:09 +03:00
|
|
|
sys___sigaltstack14(struct lwp *l, const struct sys___sigaltstack14_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(const struct sigaltstack *) nss;
|
|
|
|
syscallarg(struct sigaltstack *) oss;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct sigaltstack nss, oss;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (SCARG(uap, nss)) {
|
|
|
|
error = copyin(SCARG(uap, nss), &nss, sizeof(nss));
|
|
|
|
if (error)
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
error = sigaltstack1(l,
|
|
|
|
SCARG(uap, nss) ? &nss : 0, SCARG(uap, oss) ? &oss : 0);
|
|
|
|
if (error)
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
if (SCARG(uap, oss)) {
|
|
|
|
error = copyout(&oss, SCARG(uap, oss), sizeof(oss));
|
|
|
|
if (error)
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2009-12-20 07:49:09 +03:00
|
|
|
return 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
sys_kill(struct lwp *l, const struct sys_kill_args *uap, register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(int) pid;
|
|
|
|
syscallarg(int) signum;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p;
|
|
|
|
ksiginfo_t ksi;
|
|
|
|
int signum = SCARG(uap, signum);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if ((u_int)signum >= NSIG)
|
2009-12-20 07:49:09 +03:00
|
|
|
return EINVAL;
|
2007-02-10 00:55:00 +03:00
|
|
|
KSI_INIT(&ksi);
|
|
|
|
ksi.ksi_signo = signum;
|
|
|
|
ksi.ksi_code = SI_USER;
|
|
|
|
ksi.ksi_pid = l->l_proc->p_pid;
|
|
|
|
ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
|
|
|
|
if (SCARG(uap, pid) > 0) {
|
|
|
|
/* kill single process */
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
2010-07-01 06:38:26 +04:00
|
|
|
p = proc_find(SCARG(uap, pid));
|
|
|
|
if (p == NULL) {
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2009-12-20 07:49:09 +03:00
|
|
|
return ESRCH;
|
2008-04-24 19:35:27 +04:00
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
error = kauth_authorize_process(l->l_cred,
|
2008-01-23 20:56:53 +03:00
|
|
|
KAUTH_PROCESS_SIGNAL, p, KAUTH_ARG(signum),
|
2007-02-10 00:55:00 +03:00
|
|
|
NULL, NULL);
|
|
|
|
if (!error && signum) {
|
|
|
|
kpsignal2(p, &ksi);
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
switch (SCARG(uap, pid)) {
|
|
|
|
case -1: /* broadcast signal */
|
2009-12-20 07:49:09 +03:00
|
|
|
return killpg1(l, &ksi, 0, 1);
|
2007-02-10 00:55:00 +03:00
|
|
|
case 0: /* signal own process group */
|
2009-12-20 07:49:09 +03:00
|
|
|
return killpg1(l, &ksi, 0, 0);
|
2007-02-10 00:55:00 +03:00
|
|
|
default: /* negative explicit process group */
|
2009-12-20 07:49:09 +03:00
|
|
|
return killpg1(l, &ksi, -SCARG(uap, pid), 0);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-12-20 07:49:09 +03:00
|
|
|
sys_getcontext(struct lwp *l, const struct sys_getcontext_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(struct __ucontext *) ucp;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
ucontext_t uc;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
getucontext(l, &uc);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
return copyout(&uc, SCARG(uap, ucp), sizeof (*SCARG(uap, ucp)));
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-12-20 07:49:09 +03:00
|
|
|
sys_setcontext(struct lwp *l, const struct sys_setcontext_args *uap,
|
|
|
|
register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(const ucontext_t *) ucp;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
ucontext_t uc;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = copyin(SCARG(uap, ucp), &uc, sizeof (uc));
|
|
|
|
if (error)
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
|
|
|
if ((uc.uc_flags & _UC_CPU) == 0)
|
|
|
|
return EINVAL;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
error = setucontext(l, &uc);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (error)
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
return EJUSTRETURN;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sigtimedwait(2) system call, used also for implementation
|
|
|
|
* of sigwaitinfo() and sigwait().
|
|
|
|
*
|
|
|
|
* This only handles single LWP in signal wait. libpthread provides
|
|
|
|
* it's own sigtimedwait() wrapper to DTRT WRT individual threads.
|
|
|
|
*/
|
|
|
|
int
|
2009-01-11 05:45:45 +03:00
|
|
|
sys_____sigtimedwait50(struct lwp *l,
|
|
|
|
const struct sys_____sigtimedwait50_args *uap, register_t *retval)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
|
2010-01-20 01:28:30 +03:00
|
|
|
return sigtimedwait1(l, uap, retval, copyout, copyin, copyout);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sigaction1(struct lwp *l, int signum, const struct sigaction *nsa,
|
|
|
|
struct sigaction *osa, const void *tramp, int vers)
|
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
struct sigacts *ps;
|
|
|
|
sigset_t tset;
|
|
|
|
int prop, error;
|
|
|
|
ksiginfoq_t kq;
|
2008-11-25 19:42:44 +03:00
|
|
|
static bool v0v1valid;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (signum <= 0 || signum >= NSIG)
|
2009-12-20 07:49:09 +03:00
|
|
|
return EINVAL;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
p = l->l_proc;
|
|
|
|
error = 0;
|
|
|
|
ksiginfo_queue_init(&kq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trampoline ABI version 0 is reserved for the legacy kernel
|
|
|
|
* provided on-stack trampoline. Conversely, if we are using a
|
|
|
|
* non-0 ABI version, we must have a trampoline. Only validate the
|
|
|
|
* vers if a new sigaction was supplied. Emulations use legacy
|
|
|
|
* kernel trampolines with version 0, alternatively check for that
|
|
|
|
* too.
|
2008-11-19 21:35:57 +03:00
|
|
|
*
|
|
|
|
* If version < 2, we try to autoload the compat module. Note
|
|
|
|
* that we interlock with the unload check in compat_modcmd()
|
|
|
|
* using module_lock. If the autoload fails, we don't try it
|
|
|
|
* again for this process.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2008-11-25 19:42:44 +03:00
|
|
|
if (nsa != NULL) {
|
|
|
|
if (__predict_false(vers < 2) &&
|
|
|
|
(p->p_lflag & PL_SIGCOMPAT) == 0) {
|
|
|
|
mutex_enter(&module_lock);
|
|
|
|
if (sendsig_sigcontext_vec == NULL) {
|
|
|
|
(void)module_autoload("compat",
|
|
|
|
MODULE_CLASS_ANY);
|
|
|
|
}
|
|
|
|
if (sendsig_sigcontext_vec != NULL) {
|
|
|
|
/*
|
|
|
|
* We need to remember if the
|
|
|
|
* sigcontext method may be useable,
|
|
|
|
* because libc may use it even
|
|
|
|
* if siginfo is available.
|
|
|
|
*/
|
|
|
|
v0v1valid = true;
|
|
|
|
}
|
|
|
|
mutex_enter(proc_lock);
|
|
|
|
/*
|
|
|
|
* Prevent unload of compat module while
|
|
|
|
* this process remains.
|
|
|
|
*/
|
|
|
|
p->p_lflag |= PL_SIGCOMPAT;
|
|
|
|
mutex_exit(proc_lock);
|
|
|
|
mutex_exit(&module_lock);
|
2008-11-19 21:35:57 +03:00
|
|
|
}
|
|
|
|
|
2008-11-25 19:42:44 +03:00
|
|
|
switch (vers) {
|
|
|
|
case 0:
|
|
|
|
/* sigcontext, kernel supplied trampoline. */
|
|
|
|
if (tramp != NULL || !v0v1valid) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* sigcontext, user supplied trampoline. */
|
|
|
|
if (tramp == NULL || !v0v1valid) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
/* siginfo, user supplied trampoline. */
|
|
|
|
if (tramp == NULL) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
ps = p->p_sigacts;
|
|
|
|
if (osa)
|
|
|
|
*osa = SIGACTION_PS(ps, signum);
|
|
|
|
if (!nsa)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
prop = sigprop[signum];
|
|
|
|
if ((nsa->sa_flags & ~SA_ALLBITS) || (prop & SA_CANTMASK)) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
SIGACTION_PS(ps, signum) = *nsa;
|
|
|
|
ps->sa_sigdesc[signum].sd_tramp = tramp;
|
|
|
|
ps->sa_sigdesc[signum].sd_vers = vers;
|
|
|
|
sigminusset(&sigcantmask, &SIGACTION_PS(ps, signum).sa_mask);
|
|
|
|
|
|
|
|
if ((prop & SA_NORESET) != 0)
|
|
|
|
SIGACTION_PS(ps, signum).sa_flags &= ~SA_RESETHAND;
|
|
|
|
|
|
|
|
if (signum == SIGCHLD) {
|
|
|
|
if (nsa->sa_flags & SA_NOCLDSTOP)
|
|
|
|
p->p_sflag |= PS_NOCLDSTOP;
|
|
|
|
else
|
|
|
|
p->p_sflag &= ~PS_NOCLDSTOP;
|
|
|
|
if (nsa->sa_flags & SA_NOCLDWAIT) {
|
|
|
|
/*
|
|
|
|
* Paranoia: since SA_NOCLDWAIT is implemented by
|
|
|
|
* reparenting the dying child to PID 1 (and trust
|
|
|
|
* it to reap the zombie), PID 1 itself is forbidden
|
|
|
|
* to set SA_NOCLDWAIT.
|
|
|
|
*/
|
|
|
|
if (p->p_pid == 1)
|
2007-02-18 01:31:36 +03:00
|
|
|
p->p_flag &= ~PK_NOCLDWAIT;
|
2007-02-10 00:55:00 +03:00
|
|
|
else
|
2007-02-18 01:31:36 +03:00
|
|
|
p->p_flag |= PK_NOCLDWAIT;
|
2007-02-10 00:55:00 +03:00
|
|
|
} else
|
2007-02-18 01:31:36 +03:00
|
|
|
p->p_flag &= ~PK_NOCLDWAIT;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (nsa->sa_handler == SIG_IGN) {
|
|
|
|
/*
|
|
|
|
* Paranoia: same as above.
|
|
|
|
*/
|
|
|
|
if (p->p_pid == 1)
|
2007-02-18 01:31:36 +03:00
|
|
|
p->p_flag &= ~PK_CLDSIGIGN;
|
2007-02-10 00:55:00 +03:00
|
|
|
else
|
2007-02-18 01:31:36 +03:00
|
|
|
p->p_flag |= PK_CLDSIGIGN;
|
2007-02-10 00:55:00 +03:00
|
|
|
} else
|
2007-02-18 01:31:36 +03:00
|
|
|
p->p_flag &= ~PK_CLDSIGIGN;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((nsa->sa_flags & SA_NODEFER) == 0)
|
|
|
|
sigaddset(&SIGACTION_PS(ps, signum).sa_mask, signum);
|
|
|
|
else
|
|
|
|
sigdelset(&SIGACTION_PS(ps, signum).sa_mask, signum);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set bit in p_sigctx.ps_sigignore for signals that are set to
|
|
|
|
* SIG_IGN, and for signals set to SIG_DFL where the default is to
|
|
|
|
* ignore. However, don't put SIGCONT in p_sigctx.ps_sigignore, as
|
|
|
|
* we have to restart the process.
|
|
|
|
*/
|
|
|
|
if (nsa->sa_handler == SIG_IGN ||
|
|
|
|
(nsa->sa_handler == SIG_DFL && (prop & SA_IGNORE) != 0)) {
|
|
|
|
/* Never to be seen again. */
|
|
|
|
sigemptyset(&tset);
|
|
|
|
sigaddset(&tset, signum);
|
|
|
|
sigclearall(p, &tset, &kq);
|
|
|
|
if (signum != SIGCONT) {
|
|
|
|
/* Easier in psignal */
|
|
|
|
sigaddset(&p->p_sigctx.ps_sigignore, signum);
|
|
|
|
}
|
|
|
|
sigdelset(&p->p_sigctx.ps_sigcatch, signum);
|
|
|
|
} else {
|
|
|
|
sigdelset(&p->p_sigctx.ps_sigignore, signum);
|
|
|
|
if (nsa->sa_handler == SIG_DFL)
|
|
|
|
sigdelset(&p->p_sigctx.ps_sigcatch, signum);
|
|
|
|
else
|
|
|
|
sigaddset(&p->p_sigctx.ps_sigcatch, signum);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Previously held signals may now have become visible. Ensure that
|
|
|
|
* we check for them before returning to userspace.
|
|
|
|
*/
|
2007-02-27 18:19:54 +03:00
|
|
|
if (sigispending(l, 0)) {
|
|
|
|
lwp_lock(l);
|
|
|
|
l->l_flag |= LW_PENDSIG;
|
|
|
|
lwp_unlock(l);
|
|
|
|
}
|
2009-12-20 07:49:09 +03:00
|
|
|
out:
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_queue_drain(&kq);
|
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sigprocmask1(struct lwp *l, int how, const sigset_t *nss, sigset_t *oss)
|
|
|
|
{
|
|
|
|
int more;
|
2008-10-15 10:51:17 +04:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
sigset_t *mask;
|
|
|
|
mask = (p->p_sa != NULL) ? &p->p_sa->sa_sigmask : &l->l_sigmask;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-10-15 10:51:17 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (oss)
|
2008-10-15 10:51:17 +04:00
|
|
|
*oss = *mask;
|
2007-02-10 00:55:00 +03:00
|
|
|
if (nss) {
|
|
|
|
switch (how) {
|
|
|
|
case SIG_BLOCK:
|
2008-10-15 10:51:17 +04:00
|
|
|
sigplusset(nss, mask);
|
2007-02-10 00:55:00 +03:00
|
|
|
more = 0;
|
|
|
|
break;
|
|
|
|
case SIG_UNBLOCK:
|
2008-10-15 10:51:17 +04:00
|
|
|
sigminusset(nss, mask);
|
2007-02-10 00:55:00 +03:00
|
|
|
more = 1;
|
|
|
|
break;
|
|
|
|
case SIG_SETMASK:
|
2008-10-15 10:51:17 +04:00
|
|
|
*mask = *nss;
|
2007-02-10 00:55:00 +03:00
|
|
|
more = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2008-10-15 10:51:17 +04:00
|
|
|
sigminusset(&sigcantmask, mask);
|
2007-02-27 18:19:54 +03:00
|
|
|
if (more && sigispending(l, 0)) {
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Check for pending signals on return to user.
|
|
|
|
*/
|
|
|
|
lwp_lock(l);
|
2007-02-18 01:31:36 +03:00
|
|
|
l->l_flag |= LW_PENDSIG;
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
return 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sigpending1(struct lwp *l, sigset_t *ss)
|
|
|
|
{
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
*ss = l->l_sigpend.sp_set;
|
|
|
|
sigplusset(&p->p_sigpend.sp_set, ss);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sigsuspend1(struct lwp *l, const sigset_t *ss)
|
|
|
|
{
|
2009-12-20 07:49:09 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (ss) {
|
|
|
|
/*
|
2008-02-19 15:20:02 +03:00
|
|
|
* When returning from sigsuspend, we want
|
2007-02-10 00:55:00 +03:00
|
|
|
* the old mask to be restored after the
|
|
|
|
* signal handler has finished. Thus, we
|
|
|
|
* save it here and mark the sigctx structure
|
|
|
|
* to indicate this.
|
|
|
|
*/
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
l->l_sigrestore = 1;
|
|
|
|
l->l_sigoldmask = l->l_sigmask;
|
|
|
|
l->l_sigmask = *ss;
|
|
|
|
sigminusset(&sigcantmask, &l->l_sigmask);
|
|
|
|
|
|
|
|
/* Check for pending signals when sleeping. */
|
2007-02-27 18:19:54 +03:00
|
|
|
if (sigispending(l, 0)) {
|
|
|
|
lwp_lock(l);
|
|
|
|
l->l_flag |= LW_PENDSIG;
|
|
|
|
lwp_unlock(l);
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
2007-02-22 09:34:42 +03:00
|
|
|
while (kpause("pause", true, 0, NULL) == 0)
|
2007-02-10 00:55:00 +03:00
|
|
|
;
|
|
|
|
|
|
|
|
/* always return EINTR rather than ERESTART... */
|
2009-12-20 07:49:09 +03:00
|
|
|
return EINTR;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sigaltstack1(struct lwp *l, const struct sigaltstack *nss,
|
2009-12-20 07:49:09 +03:00
|
|
|
struct sigaltstack *oss)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
int error = 0;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (oss)
|
|
|
|
*oss = l->l_sigstk;
|
|
|
|
|
|
|
|
if (nss) {
|
|
|
|
if (nss->ss_flags & ~SS_ALLBITS)
|
|
|
|
error = EINVAL;
|
|
|
|
else if (nss->ss_flags & SS_DISABLE) {
|
|
|
|
if (l->l_sigstk.ss_flags & SS_ONSTACK)
|
|
|
|
error = EINVAL;
|
|
|
|
} else if (nss->ss_size < MINSIGSTKSZ)
|
|
|
|
error = ENOMEM;
|
|
|
|
|
|
|
|
if (!error)
|
|
|
|
l->l_sigstk = *nss;
|
|
|
|
}
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-01-20 01:28:30 +03:00
|
|
|
sigtimedwait1(struct lwp *l, const struct sys_____sigtimedwait50_args *uap,
|
2009-12-20 07:49:09 +03:00
|
|
|
register_t *retval, copyout_t storeinf, copyin_t fetchts, copyout_t storets)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2007-02-10 00:55:00 +03:00
|
|
|
syscallarg(const sigset_t *) set;
|
|
|
|
syscallarg(siginfo_t *) info;
|
|
|
|
syscallarg(struct timespec *) timeout;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2009-12-20 07:49:09 +03:00
|
|
|
int error, signum, timo;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct timespec ts, tsstart, tsnow;
|
2009-12-19 21:25:54 +03:00
|
|
|
ksiginfo_t ksi;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate timeout, if it was specified.
|
|
|
|
*/
|
|
|
|
if (SCARG(uap, timeout)) {
|
2009-12-20 07:49:09 +03:00
|
|
|
error = (*fetchts)(SCARG(uap, timeout), &ts, sizeof(ts));
|
2009-03-29 21:54:12 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2009-03-29 21:54:12 +04:00
|
|
|
if ((error = itimespecfix(&ts)) != 0)
|
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2009-03-29 21:54:12 +04:00
|
|
|
timo = tstohz(&ts);
|
|
|
|
if (timo == 0 && ts.tv_sec == 0 && ts.tv_nsec != 0)
|
|
|
|
timo++;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remember current uptime, it would be used in
|
|
|
|
* ECANCELED/ERESTART case.
|
|
|
|
*/
|
|
|
|
getnanouptime(&tsstart);
|
2009-12-20 07:49:09 +03:00
|
|
|
} else {
|
|
|
|
memset(&tsstart, 0, sizeof(tsstart)); /* XXXgcc */
|
|
|
|
timo = 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
error = copyin(SCARG(uap, set), &l->l_sigwaitset,
|
|
|
|
sizeof(l->l_sigwaitset));
|
2009-12-20 07:49:09 +03:00
|
|
|
if (error)
|
|
|
|
return error;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Silently ignore SA_CANTMASK signals. psignal1() would ignore
|
|
|
|
* SA_CANTMASK signals in waitset, we do this only for the below
|
|
|
|
* siglist check.
|
|
|
|
*/
|
|
|
|
sigminusset(&sigcantmask, &l->l_sigwaitset);
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
/* SA processes can have no more than 1 sigwaiter. */
|
2008-10-15 10:51:17 +04:00
|
|
|
if ((p->p_sflag & PS_SA) != 0 && !LIST_EMPTY(&p->p_sigwaiters)) {
|
|
|
|
mutex_exit(p->p_lock);
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
/* Check for pending signals in the process, if no - then in LWP. */
|
2009-12-19 21:25:54 +03:00
|
|
|
if ((signum = sigget(&p->p_sigpend, &ksi, 0, &l->l_sigwaitset)) == 0)
|
|
|
|
signum = sigget(&l->l_sigpend, &ksi, 0, &l->l_sigwaitset);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (signum != 0) {
|
2009-12-20 07:49:09 +03:00
|
|
|
/* If found a pending signal, just copy it out to the user. */
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Set up the sigwait list and wait for signal to arrive.
|
|
|
|
* We can either be woken up or time out.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2009-12-19 21:25:54 +03:00
|
|
|
l->l_sigwaited = &ksi;
|
2007-02-10 00:55:00 +03:00
|
|
|
LIST_INSERT_HEAD(&p->p_sigwaiters, l, l_sigwaiter);
|
2008-04-24 22:39:20 +04:00
|
|
|
error = cv_timedwait_sig(&l->l_sigcv, p->p_lock, timo);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Need to find out if we woke as a result of _lwp_wakeup() or a
|
2007-02-10 00:55:00 +03:00
|
|
|
* signal outside our wait set.
|
|
|
|
*/
|
|
|
|
if (l->l_sigwaited != NULL) {
|
|
|
|
if (error == EINTR) {
|
2009-12-20 07:49:09 +03:00
|
|
|
/* Wakeup via _lwp_wakeup(). */
|
2007-02-10 00:55:00 +03:00
|
|
|
error = ECANCELED;
|
|
|
|
} else if (!error) {
|
2009-12-20 07:49:09 +03:00
|
|
|
/* Spurious wakeup - arrange for syscall restart. */
|
2007-02-10 00:55:00 +03:00
|
|
|
error = ERESTART;
|
|
|
|
}
|
|
|
|
l->l_sigwaited = NULL;
|
|
|
|
LIST_REMOVE(l, l_sigwaiter);
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the sleep was interrupted (either by signal or wakeup), update
|
|
|
|
* the timeout and copyout new value back. It would be used when
|
|
|
|
* the syscall would be restarted or called again.
|
|
|
|
*/
|
|
|
|
if (timo && (error == ERESTART || error == ECANCELED)) {
|
|
|
|
getnanouptime(&tsnow);
|
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
/* Compute how much time has passed since start. */
|
2007-02-10 00:55:00 +03:00
|
|
|
timespecsub(&tsnow, &tsstart, &tsnow);
|
2009-12-20 07:49:09 +03:00
|
|
|
|
|
|
|
/* Substract passed time from timeout. */
|
2007-02-10 00:55:00 +03:00
|
|
|
timespecsub(&ts, &tsnow, &ts);
|
|
|
|
|
|
|
|
if (ts.tv_sec < 0)
|
|
|
|
error = EAGAIN;
|
|
|
|
else {
|
2009-12-20 07:49:09 +03:00
|
|
|
/* Copy updated timeout to userland. */
|
|
|
|
error = (*storets)(&ts, SCARG(uap, timeout),
|
2007-02-10 00:55:00 +03:00
|
|
|
sizeof(ts));
|
|
|
|
}
|
|
|
|
}
|
2009-12-20 07:49:09 +03:00
|
|
|
out:
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* If a signal from the wait set arrived, copy it to userland.
|
|
|
|
* Copy only the used part of siginfo, the padding part is
|
|
|
|
* left unchanged (userland is not supposed to touch it anyway).
|
|
|
|
*/
|
2010-05-20 21:10:42 +04:00
|
|
|
if (error == 0 && SCARG(uap, info)) {
|
2009-12-20 07:49:09 +03:00
|
|
|
error = (*storeinf)(&ksi.ksi_info, SCARG(uap, info),
|
2009-12-19 21:25:54 +03:00
|
|
|
sizeof(ksi.ksi_info));
|
2009-12-20 07:49:09 +03:00
|
|
|
}
|
2010-05-20 21:10:42 +04:00
|
|
|
if (error == 0)
|
|
|
|
*retval = ksi.ksi_info._signo;
|
2007-02-10 00:55:00 +03:00
|
|
|
return error;
|
|
|
|
}
|