2013-11-23 01:04:11 +04:00
|
|
|
/* $NetBSD: kern_sig.c,v 1.319 2013/11/22 21:04:11 christos 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.
|
|
|
|
*/
|
1994-06-29 10:29:24 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-06-29 10:29:24 +04:00
|
|
|
* 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.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)kern_sig.c 8.14 (Berkeley) 5/14/95
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
|
|
|
|
2011-04-27 04:38:37 +04:00
|
|
|
/*
|
|
|
|
* Signal subsystem.
|
|
|
|
*/
|
|
|
|
|
2001-11-12 18:25:01 +03:00
|
|
|
#include <sys/cdefs.h>
|
2013-11-23 01:04:11 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.319 2013/11/22 21:04:11 christos Exp $");
|
2001-11-12 18:25:01 +03:00
|
|
|
|
2006-09-02 01:04:45 +04:00
|
|
|
#include "opt_ptrace.h"
|
1998-06-26 03:40:33 +04:00
|
|
|
#include "opt_compat_sunos.h"
|
2003-09-23 18:34:07 +04:00
|
|
|
#include "opt_compat_netbsd.h"
|
2005-02-27 00:34:55 +03:00
|
|
|
#include "opt_compat_netbsd32.h"
|
2006-11-22 05:02:51 +03:00
|
|
|
#include "opt_pax.h"
|
1998-02-10 17:08:44 +03:00
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
#define SIGPROP /* include signal properties table */
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/ktrace.h>
|
|
|
|
#include <sys/syslog.h>
|
1996-10-24 03:13:19 +04:00
|
|
|
#include <sys/filedesc.h>
|
2007-02-10 00:55:00 +03:00
|
|
|
#include <sys/file.h>
|
1999-05-01 01:23:49 +04:00
|
|
|
#include <sys/pool.h>
|
2003-01-18 13:06:22 +03:00
|
|
|
#include <sys/ucontext.h>
|
2001-12-08 03:35:25 +03:00
|
|
|
#include <sys/exec.h>
|
2006-05-15 01:15:11 +04:00
|
|
|
#include <sys/kauth.h>
|
2007-02-10 00:55:00 +03:00
|
|
|
#include <sys/acct.h>
|
|
|
|
#include <sys/callout.h>
|
2007-12-01 02:05:43 +03:00
|
|
|
#include <sys/atomic.h>
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/cpu.h>
|
2008-11-19 21:35:57 +03:00
|
|
|
#include <sys/module.h>
|
DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider. Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
2010-03-02 00:10:13 +03:00
|
|
|
#include <sys/sdt.h>
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2006-11-22 05:02:51 +03:00
|
|
|
#ifdef PAX_SEGVGUARD
|
|
|
|
#include <sys/pax.h>
|
|
|
|
#endif /* PAX_SEGVGUARD */
|
|
|
|
|
1998-02-05 10:59:28 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2011-04-27 04:38:37 +04:00
|
|
|
static pool_cache_t sigacts_cache __read_mostly;
|
|
|
|
static pool_cache_t ksiginfo_cache __read_mostly;
|
|
|
|
static callout_t proc_stop_ch __cacheline_aligned;
|
|
|
|
|
|
|
|
sigset_t contsigmask __cacheline_aligned;
|
|
|
|
static sigset_t stopsigmask __cacheline_aligned;
|
|
|
|
sigset_t sigcantmask __cacheline_aligned;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
static void ksiginfo_exechook(struct proc *, void *);
|
|
|
|
static void proc_stop_callout(void *);
|
2009-03-29 09:02:46 +04:00
|
|
|
static int sigchecktrace(void);
|
2012-02-20 01:05:51 +04:00
|
|
|
static int sigpost(struct lwp *, sig_t, int, int);
|
2009-03-29 09:02:46 +04:00
|
|
|
static void sigput(sigpend_t *, struct proc *, ksiginfo_t *);
|
|
|
|
static int sigunwait(struct proc *, const ksiginfo_t *);
|
|
|
|
static void sigswitch(bool, int, int);
|
1998-10-03 18:29:02 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
static void sigacts_poolpage_free(struct pool *, void *);
|
|
|
|
static void *sigacts_poolpage_alloc(struct pool *, int);
|
2004-06-04 16:23:50 +04:00
|
|
|
|
2008-11-19 21:35:57 +03:00
|
|
|
void (*sendsig_sigcontext_vec)(const struct ksiginfo *, const sigset_t *);
|
|
|
|
int (*coredump_vec)(struct lwp *, const char *) =
|
|
|
|
(int (*)(struct lwp *, const char *))enosys;
|
|
|
|
|
DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider. Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
2010-03-02 00:10:13 +03:00
|
|
|
/*
|
|
|
|
* DTrace SDT provider definitions
|
|
|
|
*/
|
2013-06-09 05:13:47 +04:00
|
|
|
SDT_PROBE_DEFINE(proc,,,signal_send,signal-send,
|
DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider. Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
2010-03-02 00:10:13 +03:00
|
|
|
"struct lwp *", NULL, /* target thread */
|
|
|
|
"struct proc *", NULL, /* target process */
|
|
|
|
"int", NULL, /* signal */
|
|
|
|
NULL, NULL, NULL, NULL);
|
2013-06-09 05:13:47 +04:00
|
|
|
SDT_PROBE_DEFINE(proc,,,signal_discard,signal-discard,
|
DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider. Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
2010-03-02 00:10:13 +03:00
|
|
|
"struct lwp *", NULL, /* target thread */
|
|
|
|
"struct proc *", NULL, /* target process */
|
|
|
|
"int", NULL, /* signal */
|
|
|
|
NULL, NULL, NULL, NULL);
|
2013-06-09 05:13:47 +04:00
|
|
|
SDT_PROBE_DEFINE(proc,,,signal_clear,signal-clear,
|
DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider. Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
2010-03-02 00:10:13 +03:00
|
|
|
"int", NULL, /* signal */
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL);
|
2013-06-09 05:13:47 +04:00
|
|
|
SDT_PROBE_DEFINE(proc,,,signal_handle,signal-handle,
|
DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider. Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
2010-03-02 00:10:13 +03:00
|
|
|
"int", NULL, /* signal */
|
|
|
|
"ksiginfo_t *", NULL,
|
|
|
|
"void (*)(void)", NULL, /* handler address */
|
|
|
|
NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
|
2004-06-04 16:23:50 +04:00
|
|
|
static struct pool_allocator sigactspool_allocator = {
|
2009-12-20 07:49:09 +03:00
|
|
|
.pa_alloc = sigacts_poolpage_alloc,
|
|
|
|
.pa_free = sigacts_poolpage_free
|
2004-06-04 16:23:50 +04:00
|
|
|
};
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
int kern_logsigexit = 1;
|
|
|
|
#else
|
|
|
|
int kern_logsigexit = 0;
|
|
|
|
#endif
|
2006-11-03 15:18:41 +03:00
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
static const char logcoredump[] =
|
2007-02-10 00:55:00 +03:00
|
|
|
"pid %d (%s), uid %d: exited on signal %d (core dumped)\n";
|
2009-12-20 07:49:09 +03:00
|
|
|
static const char lognocoredump[] =
|
2007-02-10 00:55:00 +03:00
|
|
|
"pid %d (%s), uid %d: exited on signal %d (core not dumped, err = %d)\n";
|
2006-11-03 15:18:41 +03:00
|
|
|
|
2009-10-03 03:24:15 +04:00
|
|
|
static kauth_listener_t signal_listener;
|
|
|
|
|
|
|
|
static int
|
|
|
|
signal_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
|
|
|
|
void *arg0, void *arg1, void *arg2, void *arg3)
|
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
int result, signum;
|
|
|
|
|
|
|
|
result = KAUTH_RESULT_DEFER;
|
|
|
|
p = arg0;
|
|
|
|
signum = (int)(unsigned long)arg1;
|
|
|
|
|
|
|
|
if (action != KAUTH_PROCESS_SIGNAL)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (kauth_cred_uidmatch(cred, p->p_cred) ||
|
|
|
|
(signum == SIGCONT && (curproc->p_session == p->p_session)))
|
|
|
|
result = KAUTH_RESULT_ALLOW;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-09-14 10:59:13 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* signal_init:
|
|
|
|
*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Initialize global signal-related data structures.
|
2003-09-14 10:59:13 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
void
|
|
|
|
signal_init(void)
|
2003-09-14 10:59:13 +04:00
|
|
|
{
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
sigactspool_allocator.pa_pagesz = (PAGE_SIZE)*2;
|
2003-09-14 10:59:13 +04:00
|
|
|
|
2008-04-25 15:24:11 +04:00
|
|
|
sigacts_cache = pool_cache_init(sizeof(struct sigacts), 0, 0, 0,
|
|
|
|
"sigacts", sizeof(struct sigacts) > PAGE_SIZE ?
|
|
|
|
&sigactspool_allocator : NULL, IPL_NONE, NULL, NULL, NULL);
|
2008-06-25 15:05:46 +04:00
|
|
|
ksiginfo_cache = pool_cache_init(sizeof(ksiginfo_t), 0, 0, 0,
|
|
|
|
"ksiginfo", NULL, IPL_VM, NULL, NULL, NULL);
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
exechook_establish(ksiginfo_exechook, NULL);
|
2003-09-16 16:07:11 +04:00
|
|
|
|
2008-01-24 16:57:52 +03:00
|
|
|
callout_init(&proc_stop_ch, CALLOUT_MPSAFE);
|
2007-02-10 00:55:00 +03:00
|
|
|
callout_setfunc(&proc_stop_ch, proc_stop_callout, NULL);
|
2009-10-03 03:24:15 +04:00
|
|
|
|
|
|
|
signal_listener = kauth_listen_scope(KAUTH_SCOPE_PROCESS,
|
|
|
|
signal_listener_cb, NULL);
|
2003-09-14 10:59:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* sigacts_poolpage_alloc:
|
|
|
|
*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Allocate a page for the sigacts memory pool.
|
2003-09-14 10:59:13 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
static void *
|
|
|
|
sigacts_poolpage_alloc(struct pool *pp, int flags)
|
2003-09-14 10:59:13 +04:00
|
|
|
{
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
return (void *)uvm_km_alloc(kernel_map,
|
2009-12-20 07:49:09 +03:00
|
|
|
PAGE_SIZE * 2, PAGE_SIZE * 2,
|
2007-02-10 00:55:00 +03:00
|
|
|
((flags & PR_WAITOK) ? 0 : UVM_KMF_NOWAIT | UVM_KMF_TRYLOCK)
|
|
|
|
| UVM_KMF_WIRED);
|
2003-09-14 10:59:13 +04:00
|
|
|
}
|
|
|
|
|
1999-05-01 01:23:49 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* sigacts_poolpage_free:
|
|
|
|
*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Free a page on behalf of the sigacts memory pool.
|
1999-05-01 01:23:49 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
static void
|
|
|
|
sigacts_poolpage_free(struct pool *pp, void *v)
|
1999-05-01 01:23:49 +04:00
|
|
|
{
|
2008-04-25 15:24:11 +04:00
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
uvm_km_free(kernel_map, (vaddr_t)v, PAGE_SIZE * 2, UVM_KMF_WIRED);
|
1999-05-01 01:23:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* sigactsinit:
|
2009-12-20 07:49:09 +03:00
|
|
|
*
|
|
|
|
* Create an initial sigacts structure, using the same signal state
|
|
|
|
* as of specified process. If 'share' is set, share the sigacts by
|
|
|
|
* holding a reference, otherwise just copy it from parent.
|
1999-05-01 01:23:49 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
struct sigacts *
|
|
|
|
sigactsinit(struct proc *pp, int share)
|
1999-05-01 01:23:49 +04:00
|
|
|
{
|
2009-12-31 02:31:56 +03:00
|
|
|
struct sigacts *ps = pp->p_sigacts, *ps2;
|
1999-05-01 01:23:49 +04:00
|
|
|
|
2009-12-31 02:31:56 +03:00
|
|
|
if (__predict_false(share)) {
|
2008-04-25 15:24:11 +04:00
|
|
|
atomic_inc_uint(&ps->sa_refcnt);
|
2009-12-31 02:31:56 +03:00
|
|
|
return ps;
|
2000-12-23 01:58:52 +03:00
|
|
|
}
|
2009-12-31 02:31:56 +03:00
|
|
|
ps2 = pool_cache_get(sigacts_cache, PR_WAITOK);
|
|
|
|
mutex_init(&ps2->sa_mutex, MUTEX_DEFAULT, IPL_SCHED);
|
|
|
|
ps2->sa_refcnt = 1;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2009-12-31 02:31:56 +03:00
|
|
|
mutex_enter(&ps->sa_mutex);
|
|
|
|
memcpy(ps2->sa_sigdesc, ps->sa_sigdesc, sizeof(ps2->sa_sigdesc));
|
|
|
|
mutex_exit(&ps->sa_mutex);
|
2007-11-27 04:27:30 +03:00
|
|
|
return ps2;
|
1999-05-01 01:23:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* sigactsunshare:
|
2009-12-20 07:49:09 +03:00
|
|
|
*
|
|
|
|
* Make this process not share its sigacts, maintaining all signal state.
|
1999-05-01 01:23:49 +04:00
|
|
|
*/
|
|
|
|
void
|
2001-02-27 00:58:30 +03:00
|
|
|
sigactsunshare(struct proc *p)
|
1999-05-01 01:23:49 +04:00
|
|
|
{
|
2009-12-31 02:31:56 +03:00
|
|
|
struct sigacts *ps, *oldps = p->p_sigacts;
|
1999-05-01 01:23:49 +04:00
|
|
|
|
2009-12-31 02:31:56 +03:00
|
|
|
if (__predict_true(oldps->sa_refcnt == 1))
|
2007-02-10 00:55:00 +03:00
|
|
|
return;
|
2009-12-31 02:31:56 +03:00
|
|
|
|
2008-04-25 15:24:11 +04:00
|
|
|
ps = pool_cache_get(sigacts_cache, PR_WAITOK);
|
2007-12-05 10:06:50 +03:00
|
|
|
mutex_init(&ps->sa_mutex, MUTEX_DEFAULT, IPL_SCHED);
|
2011-09-17 02:07:17 +04:00
|
|
|
memcpy(ps->sa_sigdesc, oldps->sa_sigdesc, sizeof(ps->sa_sigdesc));
|
2009-12-31 02:31:56 +03:00
|
|
|
ps->sa_refcnt = 1;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_sigacts = ps;
|
|
|
|
sigactsfree(oldps);
|
1999-05-01 01:23:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* sigactsfree;
|
|
|
|
*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Release a sigacts structure.
|
1999-05-01 01:23:49 +04:00
|
|
|
*/
|
|
|
|
void
|
2004-05-05 01:25:47 +04:00
|
|
|
sigactsfree(struct sigacts *ps)
|
1999-05-01 01:23:49 +04:00
|
|
|
{
|
|
|
|
|
2008-04-25 15:24:11 +04:00
|
|
|
if (atomic_dec_uint_nv(&ps->sa_refcnt) == 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_destroy(&ps->sa_mutex);
|
2008-04-25 15:24:11 +04:00
|
|
|
pool_cache_put(sigacts_cache, ps);
|
2002-07-05 03:32:02 +04:00
|
|
|
}
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* siginit:
|
|
|
|
*
|
|
|
|
* Initialize signal state for process 0; set to ignore signals that
|
|
|
|
* are ignored by default and disable the signal stack. Locking not
|
|
|
|
* required as the system is still cold.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
|
|
|
void
|
2001-02-27 00:58:30 +03:00
|
|
|
siginit(struct proc *p)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct lwp *l;
|
|
|
|
struct sigacts *ps;
|
|
|
|
int signo, prop;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2001-02-27 00:58:30 +03:00
|
|
|
ps = p->p_sigacts;
|
1998-09-11 16:50:05 +04:00
|
|
|
sigemptyset(&contsigmask);
|
|
|
|
sigemptyset(&stopsigmask);
|
|
|
|
sigemptyset(&sigcantmask);
|
2007-02-10 00:55:00 +03:00
|
|
|
for (signo = 1; signo < NSIG; signo++) {
|
|
|
|
prop = sigprop[signo];
|
1998-09-11 16:50:05 +04:00
|
|
|
if (prop & SA_CONT)
|
2007-02-10 00:55:00 +03:00
|
|
|
sigaddset(&contsigmask, signo);
|
1998-09-11 16:50:05 +04:00
|
|
|
if (prop & SA_STOP)
|
2007-02-10 00:55:00 +03:00
|
|
|
sigaddset(&stopsigmask, signo);
|
1998-09-11 16:50:05 +04:00
|
|
|
if (prop & SA_CANTMASK)
|
2007-02-10 00:55:00 +03:00
|
|
|
sigaddset(&sigcantmask, signo);
|
|
|
|
if (prop & SA_IGNORE && signo != SIGCONT)
|
|
|
|
sigaddset(&p->p_sigctx.ps_sigignore, signo);
|
|
|
|
sigemptyset(&SIGACTION_PS(ps, signo).sa_mask);
|
|
|
|
SIGACTION_PS(ps, signo).sa_flags = SA_RESTART;
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
2000-12-23 01:58:52 +03:00
|
|
|
sigemptyset(&p->p_sigctx.ps_sigcatch);
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_sflag &= ~PS_NOCLDSTOP;
|
|
|
|
|
|
|
|
ksiginfo_queue_init(&p->p_sigpend.sp_info);
|
|
|
|
sigemptyset(&p->p_sigpend.sp_set);
|
1998-09-11 16:50:05 +04:00
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Reset per LWP state.
|
1998-09-11 16:50:05 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
l = LIST_FIRST(&p->p_lwps);
|
|
|
|
l->l_sigwaited = NULL;
|
|
|
|
l->l_sigstk.ss_flags = SS_DISABLE;
|
|
|
|
l->l_sigstk.ss_size = 0;
|
|
|
|
l->l_sigstk.ss_sp = 0;
|
|
|
|
ksiginfo_queue_init(&l->l_sigpend.sp_info);
|
|
|
|
sigemptyset(&l->l_sigpend.sp_set);
|
1999-05-01 01:23:49 +04:00
|
|
|
|
|
|
|
/* One reference. */
|
2000-12-23 01:58:52 +03:00
|
|
|
ps->sa_refcnt = 1;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* execsigs:
|
|
|
|
*
|
|
|
|
* Reset signals for an exec of the specified process.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
|
|
|
void
|
2001-02-27 00:58:30 +03:00
|
|
|
execsigs(struct proc *p)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct sigacts *ps;
|
|
|
|
struct lwp *l;
|
|
|
|
int signo, prop;
|
|
|
|
sigset_t tset;
|
|
|
|
ksiginfoq_t kq;
|
|
|
|
|
|
|
|
KASSERT(p->p_nlwps == 1);
|
|
|
|
|
2001-07-18 09:34:58 +04:00
|
|
|
sigactsunshare(p);
|
2001-02-27 00:58:30 +03:00
|
|
|
ps = p->p_sigacts;
|
2001-07-18 09:34:58 +04:00
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Reset caught signals. Held signals remain held through
|
|
|
|
* l->l_sigmask (unless they were caught, and are now ignored
|
|
|
|
* by default).
|
2007-11-27 04:27:30 +03:00
|
|
|
*
|
|
|
|
* No need to lock yet, the process has only one LWP and
|
|
|
|
* at this point the sigacts are private to the process.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
sigemptyset(&tset);
|
|
|
|
for (signo = 1; signo < NSIG; signo++) {
|
|
|
|
if (sigismember(&p->p_sigctx.ps_sigcatch, signo)) {
|
|
|
|
prop = sigprop[signo];
|
1998-09-11 16:50:05 +04:00
|
|
|
if (prop & SA_IGNORE) {
|
|
|
|
if ((prop & SA_CONT) == 0)
|
2001-02-27 00:58:30 +03:00
|
|
|
sigaddset(&p->p_sigctx.ps_sigignore,
|
2007-02-10 00:55:00 +03:00
|
|
|
signo);
|
|
|
|
sigaddset(&tset, signo);
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
SIGACTION_PS(ps, signo).sa_handler = SIG_DFL;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
sigemptyset(&SIGACTION_PS(ps, signo).sa_mask);
|
|
|
|
SIGACTION_PS(ps, signo).sa_flags = SA_RESTART;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_queue_init(&kq);
|
2007-11-27 04:27:30 +03:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
sigclearall(p, &tset, &kq);
|
2000-12-23 01:58:52 +03:00
|
|
|
sigemptyset(&p->p_sigctx.ps_sigcatch);
|
2005-04-09 20:07:52 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset no zombies if child dies flag as Solaris does.
|
|
|
|
*/
|
2007-02-18 01:31:36 +03:00
|
|
|
p->p_flag &= ~(PK_NOCLDWAIT | PK_CLDSIGIGN);
|
2005-04-09 20:07:52 +04:00
|
|
|
if (SIGACTION_PS(ps, SIGCHLD).sa_handler == SIG_IGN)
|
|
|
|
SIGACTION_PS(ps, SIGCHLD).sa_handler = SIG_DFL;
|
1998-09-11 16:50:05 +04:00
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Reset per-LWP state.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
l = LIST_FIRST(&p->p_lwps);
|
|
|
|
l->l_sigwaited = NULL;
|
|
|
|
l->l_sigstk.ss_flags = SS_DISABLE;
|
|
|
|
l->l_sigstk.ss_size = 0;
|
|
|
|
l->l_sigstk.ss_sp = 0;
|
|
|
|
ksiginfo_queue_init(&l->l_sigpend.sp_info);
|
|
|
|
sigemptyset(&l->l_sigpend.sp_set);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-11-27 04:27:30 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_queue_drain(&kq);
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* ksiginfo_exechook:
|
|
|
|
*
|
|
|
|
* Free all pending ksiginfo entries from a process on exec.
|
|
|
|
* Additionally, drain any unused ksiginfo structures in the
|
|
|
|
* system back to the pool.
|
|
|
|
*
|
|
|
|
* XXX This should not be a hook, every process has signals.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ksiginfo_exechook(struct proc *p, void *v)
|
1998-09-11 16:50:05 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfoq_t kq;
|
1998-09-11 16:50:05 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_queue_init(&kq);
|
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
|
|
|
sigclearall(p, NULL, &kq);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
1998-09-11 16:50:05 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_queue_drain(&kq);
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
2005-02-27 00:34:55 +03:00
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* ksiginfo_alloc:
|
|
|
|
*
|
|
|
|
* Allocate a new ksiginfo structure from the pool, and optionally copy
|
|
|
|
* an existing one. If the existing ksiginfo_t is from the pool, and
|
|
|
|
* has not been queued somewhere, then just return it. Additionally,
|
|
|
|
* if the existing ksiginfo_t does not contain any information beyond
|
|
|
|
* the signal number, then just return it.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_t *
|
|
|
|
ksiginfo_alloc(struct proc *p, ksiginfo_t *ok, int flags)
|
1995-09-20 01:40:36 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_t *kp;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if (ok != NULL) {
|
|
|
|
if ((ok->ksi_flags & (KSI_QUEUED | KSI_FROMPOOL)) ==
|
|
|
|
KSI_FROMPOOL)
|
2009-12-20 07:49:09 +03:00
|
|
|
return ok;
|
2007-02-10 00:55:00 +03:00
|
|
|
if (KSI_EMPTY_P(ok))
|
|
|
|
return ok;
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-06-25 15:05:46 +04:00
|
|
|
kp = pool_cache_get(ksiginfo_cache, flags);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (kp == NULL) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("Out of memory allocating ksiginfo for pid %d\n",
|
|
|
|
p->p_pid);
|
|
|
|
#endif
|
|
|
|
return NULL;
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (ok != NULL) {
|
|
|
|
memcpy(kp, ok, sizeof(*kp));
|
|
|
|
kp->ksi_flags &= ~KSI_QUEUED;
|
|
|
|
} else
|
|
|
|
KSI_INIT_EMPTY(kp);
|
|
|
|
|
|
|
|
kp->ksi_flags |= KSI_FROMPOOL;
|
|
|
|
|
|
|
|
return kp;
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* ksiginfo_free:
|
|
|
|
*
|
|
|
|
* If the given ksiginfo_t is from the pool and has not been queued,
|
|
|
|
* then free it.
|
|
|
|
*/
|
1998-09-11 16:50:05 +04:00
|
|
|
void
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_free(ksiginfo_t *kp)
|
1998-09-11 16:50:05 +04:00
|
|
|
{
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((kp->ksi_flags & (KSI_QUEUED | KSI_FROMPOOL)) != KSI_FROMPOOL)
|
|
|
|
return;
|
2008-06-25 15:05:46 +04:00
|
|
|
pool_cache_put(ksiginfo_cache, kp);
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* ksiginfo_queue_drain:
|
|
|
|
*
|
|
|
|
* Drain a non-empty ksiginfo_t queue.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ksiginfo_queue_drain0(ksiginfoq_t *kq)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_t *ksi;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2013-11-23 01:04:11 +04:00
|
|
|
KASSERT(!TAILQ_EMPTY(kq));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2013-11-23 01:04:11 +04:00
|
|
|
while (!TAILQ_EMPTY(kq)) {
|
|
|
|
ksi = TAILQ_FIRST(kq);
|
|
|
|
TAILQ_REMOVE(kq, ksi, ksi_list);
|
2008-06-25 15:05:46 +04:00
|
|
|
pool_cache_put(ksiginfo_cache, ksi);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
|
|
|
|
2011-09-04 17:09:12 +04:00
|
|
|
static bool
|
|
|
|
siggetinfo(sigpend_t *sp, ksiginfo_t *out, int signo)
|
|
|
|
{
|
|
|
|
ksiginfo_t *ksi;
|
|
|
|
|
|
|
|
if (sp == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Find siginfo and copy it out. */
|
2013-11-23 01:04:11 +04:00
|
|
|
TAILQ_FOREACH(ksi, &sp->sp_info, ksi_list) {
|
2011-09-04 17:09:12 +04:00
|
|
|
if (ksi->ksi_signo != signo)
|
|
|
|
continue;
|
2013-11-23 01:04:11 +04:00
|
|
|
TAILQ_REMOVE(&sp->sp_info, ksi, ksi_list);
|
2011-09-04 17:09:12 +04:00
|
|
|
KASSERT((ksi->ksi_flags & KSI_FROMPOOL) != 0);
|
|
|
|
KASSERT((ksi->ksi_flags & KSI_QUEUED) != 0);
|
|
|
|
ksi->ksi_flags &= ~KSI_QUEUED;
|
|
|
|
if (out != NULL) {
|
|
|
|
memcpy(out, ksi, sizeof(*out));
|
|
|
|
out->ksi_flags &= ~(KSI_FROMPOOL | KSI_QUEUED);
|
|
|
|
}
|
|
|
|
ksiginfo_free(ksi); /* XXXSMP */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* If there is no siginfo, then manufacture it. */
|
|
|
|
if (out != NULL) {
|
|
|
|
KSI_INIT(out);
|
|
|
|
out->ksi_info._signo = signo;
|
|
|
|
out->ksi_info._code = SI_NOINFO;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* sigget:
|
|
|
|
*
|
|
|
|
* Fetch the first pending signal from a set. Optionally, also fetch
|
|
|
|
* or manufacture a ksiginfo element. Returns the number of the first
|
|
|
|
* pending signal, or zero.
|
|
|
|
*/
|
1998-09-11 16:50:05 +04:00
|
|
|
int
|
2008-02-19 15:24:34 +03:00
|
|
|
sigget(sigpend_t *sp, ksiginfo_t *out, int signo, const sigset_t *mask)
|
1998-09-11 16:50:05 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
sigset_t tset;
|
|
|
|
|
|
|
|
/* If there's no pending set, the signal is from the debugger. */
|
2008-09-13 01:33:39 +04:00
|
|
|
if (sp == NULL)
|
|
|
|
goto out;
|
1998-09-11 16:50:05 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/* Construct mask from signo, and 'mask'. */
|
|
|
|
if (signo == 0) {
|
|
|
|
if (mask != NULL) {
|
|
|
|
tset = *mask;
|
|
|
|
__sigandset(&sp->sp_set, &tset);
|
|
|
|
} else
|
|
|
|
tset = sp->sp_set;
|
2009-12-20 07:49:09 +03:00
|
|
|
|
|
|
|
/* If there are no signals pending - return. */
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((signo = firstsig(&tset)) == 0)
|
2008-09-13 01:33:39 +04:00
|
|
|
goto out;
|
2007-02-10 00:55:00 +03:00
|
|
|
} else {
|
|
|
|
KASSERT(sigismember(&sp->sp_set, signo));
|
|
|
|
}
|
|
|
|
|
|
|
|
sigdelset(&sp->sp_set, signo);
|
2008-09-13 01:33:39 +04:00
|
|
|
out:
|
2011-09-04 17:09:12 +04:00
|
|
|
(void)siggetinfo(sp, out, signo);
|
2007-02-10 00:55:00 +03:00
|
|
|
return signo;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* sigput:
|
2009-12-20 07:49:09 +03:00
|
|
|
*
|
2009-03-27 13:58:38 +03:00
|
|
|
* Append a new ksiginfo element to the list of pending ksiginfo's.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2009-03-29 09:02:46 +04:00
|
|
|
static void
|
2007-02-10 00:55:00 +03:00
|
|
|
sigput(sigpend_t *sp, struct proc *p, ksiginfo_t *ksi)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_t *kp;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
KASSERT((ksi->ksi_flags & KSI_QUEUED) == 0);
|
|
|
|
|
|
|
|
sigaddset(&sp->sp_set, ksi->ksi_signo);
|
|
|
|
|
|
|
|
/*
|
2009-03-27 13:58:38 +03:00
|
|
|
* If there is no siginfo, we are done.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2009-03-27 13:58:38 +03:00
|
|
|
if (KSI_EMPTY_P(ksi))
|
2007-02-10 00:55:00 +03:00
|
|
|
return;
|
1998-09-11 16:50:05 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
KASSERT((ksi->ksi_flags & KSI_FROMPOOL) != 0);
|
|
|
|
|
|
|
|
#ifdef notyet /* XXX: QUEUING */
|
|
|
|
if (ksi->ksi_signo < SIGRTMIN)
|
|
|
|
#endif
|
|
|
|
{
|
2013-11-23 01:04:11 +04:00
|
|
|
TAILQ_FOREACH(kp, &sp->sp_info, ksi_list) {
|
2007-02-10 00:55:00 +03:00
|
|
|
if (kp->ksi_signo == ksi->ksi_signo) {
|
|
|
|
KSI_COPY(ksi, kp);
|
|
|
|
kp->ksi_flags |= KSI_QUEUED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
ksi->ksi_flags |= KSI_QUEUED;
|
2013-11-23 01:04:11 +04:00
|
|
|
TAILQ_INSERT_TAIL(&sp->sp_info, ksi, ksi_list);
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* sigclear:
|
|
|
|
*
|
|
|
|
* Clear all pending signals in the specified set.
|
|
|
|
*/
|
|
|
|
void
|
2008-02-19 15:24:34 +03:00
|
|
|
sigclear(sigpend_t *sp, const sigset_t *mask, ksiginfoq_t *kq)
|
1998-09-11 16:50:05 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_t *ksi, *next;
|
|
|
|
|
|
|
|
if (mask == NULL)
|
|
|
|
sigemptyset(&sp->sp_set);
|
|
|
|
else
|
|
|
|
sigminusset(mask, &sp->sp_set);
|
|
|
|
|
2013-11-23 01:04:11 +04:00
|
|
|
TAILQ_FOREACH_SAFE(ksi, &sp->sp_info, ksi_list, next) {
|
2007-02-10 00:55:00 +03:00
|
|
|
if (mask == NULL || sigismember(mask, ksi->ksi_signo)) {
|
2013-11-23 01:04:11 +04:00
|
|
|
TAILQ_REMOVE(&sp->sp_info, ksi, ksi_list);
|
2007-02-10 00:55:00 +03:00
|
|
|
KASSERT((ksi->ksi_flags & KSI_FROMPOOL) != 0);
|
|
|
|
KASSERT((ksi->ksi_flags & KSI_QUEUED) != 0);
|
2013-11-23 01:04:11 +04:00
|
|
|
TAILQ_INSERT_TAIL(kq, ksi, ksi_list);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sigclearall:
|
|
|
|
*
|
|
|
|
* Clear all pending signals in the specified set from a process and
|
|
|
|
* its LWPs.
|
|
|
|
*/
|
|
|
|
void
|
2008-02-19 15:24:34 +03:00
|
|
|
sigclearall(struct proc *p, const sigset_t *mask, ksiginfoq_t *kq)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
struct lwp *l;
|
2001-02-27 00:58:30 +03:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
1998-09-11 16:50:05 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
sigclear(&p->p_sigpend, mask, kq);
|
1998-09-11 16:50:05 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
LIST_FOREACH(l, &p->p_lwps, l_sibling) {
|
|
|
|
sigclear(&l->l_sigpend, mask, kq);
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* sigispending:
|
|
|
|
*
|
2011-08-31 20:05:44 +04:00
|
|
|
* Return the first signal number if there are pending signals for the
|
|
|
|
* current LWP. May be called unlocked provided that LW_PENDSIG is set,
|
|
|
|
* and that the signal has been posted to the appopriate queue before
|
|
|
|
* LW_PENDSIG is set.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
1996-02-04 05:15:01 +03:00
|
|
|
int
|
2007-02-10 00:55:00 +03:00
|
|
|
sigispending(struct lwp *l, int signo)
|
1995-09-20 01:40:36 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
sigset_t tset;
|
|
|
|
|
2007-12-01 02:05:43 +03:00
|
|
|
membar_consumer();
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
tset = l->l_sigpend.sp_set;
|
|
|
|
sigplusset(&p->p_sigpend.sp_set, &tset);
|
|
|
|
sigminusset(&p->p_sigctx.ps_sigignore, &tset);
|
|
|
|
sigminusset(&l->l_sigmask, &tset);
|
|
|
|
|
|
|
|
if (signo == 0) {
|
2011-09-01 02:43:19 +04:00
|
|
|
return firstsig(&tset);
|
|
|
|
}
|
|
|
|
return sigismember(&tset, signo) ? signo : 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
getucontext(struct lwp *l, ucontext_t *ucp)
|
|
|
|
{
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
ucp->uc_flags = 0;
|
|
|
|
ucp->uc_link = l->l_ctxlink;
|
2012-02-20 01:05:51 +04:00
|
|
|
ucp->uc_sigmask = l->l_sigmask;
|
2007-02-10 00:55:00 +03:00
|
|
|
ucp->uc_flags |= _UC_SIGMASK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The (unsupplied) definition of the `current execution stack'
|
|
|
|
* in the System V Interface Definition appears to allow returning
|
|
|
|
* the main context stack.
|
|
|
|
*/
|
|
|
|
if ((l->l_sigstk.ss_flags & SS_ONSTACK) == 0) {
|
2007-12-27 01:11:47 +03:00
|
|
|
ucp->uc_stack.ss_sp = (void *)l->l_proc->p_stackbase;
|
2007-02-10 00:55:00 +03:00
|
|
|
ucp->uc_stack.ss_size = ctob(l->l_proc->p_vmspace->vm_ssize);
|
|
|
|
ucp->uc_stack.ss_flags = 0; /* XXX, def. is Very Fishy */
|
|
|
|
} else {
|
|
|
|
/* Simply copy alternate signal execution stack. */
|
|
|
|
ucp->uc_stack = l->l_sigstk;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
ucp->uc_flags |= _UC_STACK;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
cpu_getmcontext(l, &ucp->uc_mcontext, &ucp->uc_flags);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-02-10 00:55:00 +03:00
|
|
|
setucontext(struct lwp *l, const ucontext_t *ucp)
|
1995-09-20 01:40:36 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2006-06-13 17:56:50 +04:00
|
|
|
int error;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if ((ucp->uc_flags & _UC_SIGMASK) != 0) {
|
|
|
|
error = sigprocmask1(l, SIG_SETMASK, &ucp->uc_sigmask, NULL);
|
|
|
|
if (error != 0)
|
2006-06-13 17:56:50 +04:00
|
|
|
return error;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
error = cpu_setmcontext(l, &ucp->uc_mcontext, ucp->uc_flags);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
l->l_ctxlink = ucp->uc_link;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there was stack information, update whether or not we are
|
|
|
|
* still running on an alternate signal stack.
|
|
|
|
*/
|
|
|
|
if ((ucp->uc_flags & _UC_STACK) != 0) {
|
|
|
|
if (ucp->uc_stack.ss_flags & SS_ONSTACK)
|
|
|
|
l->l_sigstk.ss_flags |= SS_ONSTACK;
|
|
|
|
else
|
|
|
|
l->l_sigstk.ss_flags &= ~SS_ONSTACK;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
return 0;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-12-20 07:49:09 +03:00
|
|
|
* killpg1: common code for kill process group/broadcast kill.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
1996-02-04 05:15:01 +03:00
|
|
|
int
|
2006-07-24 02:06:03 +04:00
|
|
|
killpg1(struct lwp *l, ksiginfo_t *ksi, int pgid, int all)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2006-07-24 02:06:03 +04:00
|
|
|
struct proc *p, *cp;
|
2006-05-15 01:15:11 +04:00
|
|
|
kauth_cred_t pc;
|
2001-02-27 00:58:30 +03:00
|
|
|
struct pgrp *pgrp;
|
|
|
|
int nfound;
|
2007-02-10 00:55:00 +03:00
|
|
|
int signo = ksi->ksi_signo;
|
2005-02-27 00:34:55 +03:00
|
|
|
|
2006-07-24 02:06:03 +04:00
|
|
|
cp = l->l_proc;
|
|
|
|
pc = l->l_cred;
|
2001-02-27 00:58:30 +03:00
|
|
|
nfound = 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
1999-07-23 01:08:30 +04:00
|
|
|
if (all) {
|
2005-02-27 00:34:55 +03:00
|
|
|
/*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Broadcast.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2004-10-01 20:30:52 +04:00
|
|
|
PROCLIST_FOREACH(p, &allproc) {
|
2008-04-29 19:55:24 +04:00
|
|
|
if (p->p_pid <= 1 || p == cp ||
|
2010-03-03 03:47:30 +03:00
|
|
|
(p->p_flag & PK_SYSTEM) != 0)
|
1994-06-29 10:29:24 +04:00
|
|
|
continue;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (kauth_authorize_process(pc,
|
2008-01-23 20:52:32 +03:00
|
|
|
KAUTH_PROCESS_SIGNAL, p, KAUTH_ARG(signo), NULL,
|
|
|
|
NULL) == 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
nfound++;
|
2008-04-24 22:39:20 +04:00
|
|
|
if (signo)
|
2007-02-10 00:55:00 +03:00
|
|
|
kpsignal2(p, ksi);
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
1999-07-23 01:08:30 +04:00
|
|
|
} else {
|
2005-02-27 00:34:55 +03:00
|
|
|
if (pgid == 0)
|
2009-12-20 07:49:09 +03:00
|
|
|
/* Zero pgid means send to my process group. */
|
1994-06-29 10:29:24 +04:00
|
|
|
pgrp = cp->p_pgrp;
|
|
|
|
else {
|
2010-07-01 06:38:26 +04:00
|
|
|
pgrp = pgrp_find(pgid);
|
1994-06-29 10:29:24 +04:00
|
|
|
if (pgrp == NULL)
|
2007-02-10 00:55:00 +03:00
|
|
|
goto out;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
2002-09-04 05:32:31 +04:00
|
|
|
LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
|
2007-02-18 01:31:36 +03:00
|
|
|
if (p->p_pid <= 1 || p->p_flag & PK_SYSTEM)
|
1994-06-29 10:29:24 +04:00
|
|
|
continue;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2008-01-23 20:52:32 +03:00
|
|
|
if (kauth_authorize_process(pc, KAUTH_PROCESS_SIGNAL,
|
|
|
|
p, KAUTH_ARG(signo), NULL, NULL) == 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
nfound++;
|
2008-04-24 22:39:20 +04:00
|
|
|
if (signo && P_ZOMBIE(p) == 0)
|
|
|
|
kpsignal2(p, ksi);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
}
|
2009-12-20 07:49:09 +03:00
|
|
|
out:
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2009-12-20 07:49:09 +03:00
|
|
|
return nfound ? 0 : ESRCH;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Send a signal to a process group. If checktty is set, limit to members
|
2007-02-10 00:55:00 +03:00
|
|
|
* which have a controlling terminal.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
|
|
|
void
|
2007-02-10 00:55:00 +03:00
|
|
|
pgsignal(struct pgrp *pgrp, int sig, int checkctty)
|
2003-09-07 02:03:09 +04:00
|
|
|
{
|
|
|
|
ksiginfo_t ksi;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
KASSERT(!cpu_intr_p());
|
|
|
|
KASSERT(mutex_owned(proc_lock));
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2004-04-03 23:43:08 +04:00
|
|
|
KSI_INIT_EMPTY(&ksi);
|
2003-09-07 02:03:09 +04:00
|
|
|
ksi.ksi_signo = sig;
|
|
|
|
kpgsignal(pgrp, &ksi, NULL, checkctty);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kpgsignal(struct pgrp *pgrp, ksiginfo_t *ksi, void *data, int checkctty)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2000-03-30 13:27:11 +04:00
|
|
|
struct proc *p;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
KASSERT(!cpu_intr_p());
|
|
|
|
KASSERT(mutex_owned(proc_lock));
|
2009-12-20 07:49:09 +03:00
|
|
|
KASSERT(pgrp != NULL);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2009-03-29 09:02:46 +04:00
|
|
|
LIST_FOREACH(p, &pgrp->pg_members, p_pglist)
|
|
|
|
if (checkctty == 0 || p->p_lflag & PL_CONTROLT)
|
|
|
|
kpsignal(p, ksi, data);
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Send a signal caused by a trap to the current LWP. If it will be caught
|
|
|
|
* immediately, deliver it with correct code. Otherwise, post it normally.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2003-09-07 02:03:09 +04:00
|
|
|
void
|
2007-02-10 00:55:00 +03:00
|
|
|
trapsignal(struct lwp *l, ksiginfo_t *ksi)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2003-01-18 13:06:22 +03:00
|
|
|
struct proc *p;
|
|
|
|
struct sigacts *ps;
|
2007-02-10 00:55:00 +03:00
|
|
|
int signo = ksi->ksi_signo;
|
2008-10-15 10:51:17 +04:00
|
|
|
sigset_t *mask;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2003-10-08 04:28:40 +04:00
|
|
|
KASSERT(KSI_TRAP_P(ksi));
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
ksi->ksi_lid = l->l_lid;
|
2003-01-18 13:06:22 +03:00
|
|
|
p = l->l_proc;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
KASSERT(!cpu_intr_p());
|
|
|
|
mutex_enter(proc_lock);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2012-02-20 01:05:51 +04:00
|
|
|
mask = &l->l_sigmask;
|
2001-02-27 00:58:30 +03:00
|
|
|
ps = p->p_sigacts;
|
2012-02-20 01:05:51 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((p->p_slflag & PSL_TRACED) == 0 &&
|
|
|
|
sigismember(&p->p_sigctx.ps_sigcatch, signo) &&
|
2008-10-15 10:51:17 +04:00
|
|
|
!sigismember(mask, signo)) {
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2008-03-27 22:06:51 +03:00
|
|
|
l->l_ru.ru_nsignals++;
|
2008-10-15 10:51:17 +04:00
|
|
|
kpsendsig(l, ksi, mask);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2009-12-20 07:49:09 +03:00
|
|
|
ktrpsig(signo, SIGACTION_PS(ps, signo).sa_handler, mask, ksi);
|
1994-06-29 10:29:24 +04:00
|
|
|
} else {
|
2003-09-14 10:59:13 +04:00
|
|
|
/* XXX for core dump/debugger */
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_sigctx.ps_lwp = l->l_lid;
|
2003-09-14 10:59:13 +04:00
|
|
|
p->p_sigctx.ps_signo = ksi->ksi_signo;
|
|
|
|
p->p_sigctx.ps_code = ksi->ksi_trap;
|
2006-11-01 12:46:14 +03:00
|
|
|
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);
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-13 19:32:40 +04:00
|
|
|
/*
|
|
|
|
* Fill in signal information and signal the parent for a child status change.
|
|
|
|
*/
|
2006-03-05 10:21:37 +03:00
|
|
|
void
|
2007-02-10 00:55:00 +03:00
|
|
|
child_psignal(struct proc *p, int mask)
|
2003-09-13 19:32:40 +04:00
|
|
|
{
|
|
|
|
ksiginfo_t ksi;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *q;
|
|
|
|
int xstat;
|
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
KASSERT(mutex_owned(proc_lock));
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
xstat = p->p_xstat;
|
2003-09-13 19:32:40 +04:00
|
|
|
|
2004-04-03 23:38:04 +04:00
|
|
|
KSI_INIT(&ksi);
|
2003-09-13 19:32:40 +04:00
|
|
|
ksi.ksi_signo = SIGCHLD;
|
2007-02-10 00:55:00 +03:00
|
|
|
ksi.ksi_code = (xstat == SIGCONT ? CLD_CONTINUED : CLD_STOPPED);
|
2003-09-13 19:32:40 +04:00
|
|
|
ksi.ksi_pid = p->p_pid;
|
2006-05-15 01:15:11 +04:00
|
|
|
ksi.ksi_uid = kauth_cred_geteuid(p->p_cred);
|
2007-02-10 00:55:00 +03:00
|
|
|
ksi.ksi_status = xstat;
|
2003-09-13 19:32:40 +04:00
|
|
|
ksi.ksi_utime = p->p_stats->p_ru.ru_utime.tv_sec;
|
|
|
|
ksi.ksi_stime = p->p_stats->p_ru.ru_stime.tv_sec;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
q = p->p_pptr;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
|
|
|
mutex_enter(q->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if ((q->p_sflag & mask) == 0)
|
|
|
|
kpsignal2(q, &ksi);
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(q->p_lock);
|
|
|
|
mutex_enter(p->p_lock);
|
2003-09-13 19:32:40 +04:00
|
|
|
}
|
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
void
|
2007-02-10 00:55:00 +03:00
|
|
|
psignal(struct proc *p, int signo)
|
2003-09-07 02:03:09 +04:00
|
|
|
{
|
2003-10-07 04:23:17 +04:00
|
|
|
ksiginfo_t ksi;
|
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
KASSERT(!cpu_intr_p());
|
|
|
|
KASSERT(mutex_owned(proc_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2004-04-03 23:43:08 +04:00
|
|
|
KSI_INIT_EMPTY(&ksi);
|
2007-02-10 00:55:00 +03:00
|
|
|
ksi.ksi_signo = signo;
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2006-11-01 12:46:14 +03:00
|
|
|
kpsignal2(p, &ksi);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2003-09-07 02:03:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-11-01 12:46:14 +03:00
|
|
|
kpsignal(struct proc *p, ksiginfo_t *ksi, void *data)
|
2003-09-26 01:59:18 +04:00
|
|
|
{
|
2008-03-22 00:54:58 +03:00
|
|
|
fdfile_t *ff;
|
|
|
|
file_t *fp;
|
2009-05-25 01:41:25 +04:00
|
|
|
fdtab_t *dt;
|
2003-10-07 04:23:17 +04:00
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
KASSERT(!cpu_intr_p());
|
|
|
|
KASSERT(mutex_owned(proc_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if ((p->p_sflag & PS_WEXIT) == 0 && data) {
|
2003-09-26 01:59:18 +04:00
|
|
|
size_t fd;
|
2008-03-22 00:54:58 +03:00
|
|
|
filedesc_t *fdp = p->p_fd;
|
2003-10-07 04:23:17 +04:00
|
|
|
|
2008-03-22 00:54:58 +03:00
|
|
|
/* XXXSMP locking */
|
2003-09-26 01:59:18 +04:00
|
|
|
ksi->ksi_fd = -1;
|
2009-05-25 01:41:25 +04:00
|
|
|
dt = fdp->fd_dt;
|
|
|
|
for (fd = 0; fd < dt->dt_nfiles; fd++) {
|
|
|
|
if ((ff = dt->dt_ff[fd]) == NULL)
|
2008-03-22 00:54:58 +03:00
|
|
|
continue;
|
|
|
|
if ((fp = ff->ff_file) == NULL)
|
|
|
|
continue;
|
|
|
|
if (fp->f_data == data) {
|
2003-09-26 01:59:18 +04:00
|
|
|
ksi->ksi_fd = fd;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2006-11-01 12:46:14 +03:00
|
|
|
kpsignal2(p, ksi);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2003-09-26 01:59:18 +04:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* sigismasked:
|
|
|
|
*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Returns true if signal is ignored or masked for the specified LWP.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
sigismasked(struct lwp *l, int sig)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2012-02-20 01:05:51 +04:00
|
|
|
return sigismember(&p->p_sigctx.ps_sigignore, sig) ||
|
|
|
|
sigismember(&l->l_sigmask, sig);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2003-09-07 02:03:09 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* sigpost:
|
|
|
|
*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Post a pending signal to an LWP. Returns non-zero if the LWP may
|
|
|
|
* be able to take the signal.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2009-03-29 09:02:46 +04:00
|
|
|
static int
|
2012-02-20 01:05:51 +04:00
|
|
|
sigpost(struct lwp *l, sig_t action, int prop, int sig)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
int rv, masked;
|
2008-10-15 10:51:17 +04:00
|
|
|
struct proc *p = l->l_proc;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-10-15 10:51:17 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2003-09-07 02:03:09 +04:00
|
|
|
|
2002-10-23 13:10:23 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If the LWP is on the way out, sigclear() will be busy draining all
|
|
|
|
* pending signals. Don't give it more.
|
2002-10-23 13:10:23 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (l->l_refcnt == 0)
|
|
|
|
return 0;
|
2002-10-23 13:10:23 +04:00
|
|
|
|
DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider. Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
2010-03-02 00:10:13 +03:00
|
|
|
SDT_PROBE(proc,,,signal_send, l, p, sig, 0, 0);
|
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Have the LWP check for signals. This ensures that even if no LWP
|
|
|
|
* is found to take the signal immediately, it should be taken soon.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2008-12-13 23:43:38 +03:00
|
|
|
lwp_lock(l);
|
2007-02-18 01:31:36 +03:00
|
|
|
l->l_flag |= LW_PENDSIG;
|
2004-09-28 12:59:20 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
2009-03-29 09:02:46 +04:00
|
|
|
* SIGCONT can be masked, but if LWP is stopped, it needs restart.
|
|
|
|
* Note: SIGKILL and SIGSTOP cannot be masked.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2012-02-20 01:05:51 +04:00
|
|
|
masked = sigismember(&l->l_sigmask, sig);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (masked && ((prop & SA_CONT) == 0 || l->l_stat != LSSTOP)) {
|
|
|
|
lwp_unlock(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-20 20:47:03 +03:00
|
|
|
/*
|
|
|
|
* If killing the process, make it run fast.
|
|
|
|
*/
|
|
|
|
if (__predict_false((prop & SA_KILL) != 0) &&
|
2008-01-31 03:50:32 +03:00
|
|
|
action == SIG_DFL && l->l_priority < MAXPRI_USER) {
|
|
|
|
KASSERT(l->l_class == SCHED_OTHER);
|
|
|
|
lwp_changepri(l, MAXPRI_USER);
|
|
|
|
}
|
2007-02-20 20:47:03 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* If the LWP is running or on a run queue, then we win. If it's
|
|
|
|
* sleeping interruptably, wake it and make it take the signal. If
|
|
|
|
* the sleep isn't interruptable, then the chances are it will get
|
|
|
|
* to see the signal soon anyhow. If suspended, it can't take the
|
|
|
|
* signal right now. If it's LWP private or for all LWPs, save it
|
|
|
|
* for later; otherwise punt.
|
|
|
|
*/
|
|
|
|
rv = 0;
|
|
|
|
|
|
|
|
switch (l->l_stat) {
|
|
|
|
case LSRUN:
|
|
|
|
case LSONPROC:
|
|
|
|
lwp_need_userret(l);
|
|
|
|
rv = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LSSLEEP:
|
2007-02-18 01:31:36 +03:00
|
|
|
if ((l->l_flag & LW_SINTR) != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
/* setrunnable() will release the lock. */
|
|
|
|
setrunnable(l);
|
|
|
|
return 1;
|
2006-10-28 12:09:31 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LSSUSPENDED:
|
2011-07-26 17:33:43 +04:00
|
|
|
if ((prop & SA_KILL) != 0 && (l->l_flag & LW_WCORE) != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
/* lwp_continue() will release the lock. */
|
|
|
|
lwp_continue(l);
|
|
|
|
return 1;
|
2004-04-01 20:56:44 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LSSTOP:
|
|
|
|
if ((prop & SA_STOP) != 0)
|
|
|
|
break;
|
2004-09-28 12:59:20 +04:00
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If the LWP is stopped and we are sending a continue
|
|
|
|
* signal, then start it again.
|
2004-09-28 12:59:20 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((prop & SA_CONT) != 0) {
|
|
|
|
if (l->l_wchan != NULL) {
|
|
|
|
l->l_stat = LSSLEEP;
|
2008-10-15 10:51:17 +04:00
|
|
|
p->p_nrlwps++;
|
2007-02-10 00:55:00 +03:00
|
|
|
rv = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* setrunnable() will release the lock. */
|
|
|
|
setrunnable(l);
|
|
|
|
return 1;
|
2007-02-18 01:31:36 +03:00
|
|
|
} else if (l->l_wchan == NULL || (l->l_flag & LW_SINTR) != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
/* setrunnable() will release the lock. */
|
|
|
|
setrunnable(l);
|
|
|
|
return 1;
|
1995-07-24 07:18:42 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
default:
|
|
|
|
break;
|
2003-02-15 23:54:38 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(l);
|
|
|
|
return rv;
|
|
|
|
}
|
2003-10-25 20:50:37 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Notify an LWP that it has a pending signal.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
signotify(struct lwp *l)
|
|
|
|
{
|
2007-03-05 23:29:14 +03:00
|
|
|
KASSERT(lwp_locked(l, NULL));
|
2003-10-25 20:50:37 +04:00
|
|
|
|
2007-02-18 01:31:36 +03:00
|
|
|
l->l_flag |= LW_PENDSIG;
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_need_userret(l);
|
|
|
|
}
|
2006-10-23 00:48:45 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Find an LWP within process p that is waiting on signal ksi, and hand
|
|
|
|
* it on.
|
|
|
|
*/
|
2009-03-29 09:02:46 +04:00
|
|
|
static int
|
2007-02-10 00:55:00 +03:00
|
|
|
sigunwait(struct proc *p, const ksiginfo_t *ksi)
|
|
|
|
{
|
|
|
|
struct lwp *l;
|
|
|
|
int signo;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
signo = ksi->ksi_signo;
|
|
|
|
|
|
|
|
if (ksi->ksi_lid != 0) {
|
2005-02-27 00:34:55 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Signal came via _lwp_kill(). Find the LWP and see if
|
|
|
|
* it's interested.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((l = lwp_find(p, ksi->ksi_lid)) == NULL)
|
|
|
|
return 0;
|
|
|
|
if (l->l_sigwaited == NULL ||
|
|
|
|
!sigismember(&l->l_sigwaitset, signo))
|
|
|
|
return 0;
|
2003-01-18 13:06:22 +03:00
|
|
|
} else {
|
2003-11-02 19:26:10 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Look for any LWP that may be interested.
|
2003-11-02 19:26:10 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
LIST_FOREACH(l, &p->p_sigwaiters, l_sigwaiter) {
|
|
|
|
KASSERT(l->l_sigwaited != NULL);
|
|
|
|
if (sigismember(&l->l_sigwaitset, signo))
|
2003-11-02 19:26:10 +03:00
|
|
|
break;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
2003-11-02 19:26:10 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if (l != NULL) {
|
|
|
|
l->l_sigwaited->ksi_info = ksi->ksi_info;
|
|
|
|
l->l_sigwaited = NULL;
|
|
|
|
LIST_REMOVE(l, l_sigwaiter);
|
|
|
|
cv_signal(&l->l_sigcv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the signal to the process. If the signal has an action, the action
|
|
|
|
* is usually performed by the target process rather than the caller; we add
|
|
|
|
* the signal to the set of pending signals for the process.
|
|
|
|
*
|
|
|
|
* Exceptions:
|
|
|
|
* o When a stop signal is sent to a sleeping process that takes the
|
|
|
|
* default action, the process is stopped without awakening it.
|
|
|
|
* o SIGCONT restarts stopped processes (or puts them back to sleep)
|
|
|
|
* regardless of the signal action (eg, blocked or ignored).
|
|
|
|
*
|
|
|
|
* Other ignored signals are discarded immediately.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
kpsignal2(struct proc *p, ksiginfo_t *ksi)
|
|
|
|
{
|
2009-12-20 07:49:09 +03:00
|
|
|
int prop, signo = ksi->ksi_signo;
|
2007-11-27 04:27:30 +03:00
|
|
|
struct sigacts *sa;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct lwp *l;
|
|
|
|
ksiginfo_t *kp;
|
2009-12-20 07:49:09 +03:00
|
|
|
lwpid_t lid;
|
2007-02-10 00:55:00 +03:00
|
|
|
sig_t action;
|
2009-12-20 07:49:09 +03:00
|
|
|
bool toall;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
KASSERT(!cpu_intr_p());
|
|
|
|
KASSERT(mutex_owned(proc_lock));
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
KASSERT((ksi->ksi_flags & KSI_QUEUED) == 0);
|
|
|
|
KASSERT(signo > 0 && signo < NSIG);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the process is being created by fork, is a zombie or is
|
|
|
|
* exiting, then just drop the signal here and bail out.
|
|
|
|
*/
|
|
|
|
if (p->p_stat != SACTIVE && p->p_stat != SSTOP)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify any interested parties of the signal.
|
2009-12-20 07:49:09 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
KNOTE(&p->p_klist, NOTE_SIGNAL | signo);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some signals including SIGKILL must act on the entire process.
|
|
|
|
*/
|
|
|
|
kp = NULL;
|
|
|
|
prop = sigprop[signo];
|
|
|
|
toall = ((prop & SA_TOALL) != 0);
|
2009-12-20 07:49:09 +03:00
|
|
|
lid = toall ? 0 : ksi->ksi_lid;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If proc is traced, always give parent a chance.
|
|
|
|
*/
|
|
|
|
if (p->p_slflag & PSL_TRACED) {
|
|
|
|
action = SIG_DFL;
|
2005-02-27 00:34:55 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if (lid == 0) {
|
|
|
|
/*
|
|
|
|
* If the process is being traced and the signal
|
|
|
|
* is being caught, make sure to save any ksiginfo.
|
|
|
|
*/
|
|
|
|
if ((kp = ksiginfo_alloc(p, ksi, PR_NOWAIT)) == NULL)
|
|
|
|
return;
|
|
|
|
sigput(&p->p_sigpend, p, kp);
|
|
|
|
}
|
|
|
|
} else {
|
2003-11-02 19:30:55 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If the signal was the result of a trap and is not being
|
|
|
|
* caught, then reset it to default action so that the
|
|
|
|
* process dumps core immediately.
|
2003-11-02 19:30:55 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (KSI_TRAP_P(ksi)) {
|
2007-11-27 04:27:30 +03:00
|
|
|
sa = p->p_sigacts;
|
|
|
|
mutex_enter(&sa->sa_mutex);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (!sigismember(&p->p_sigctx.ps_sigcatch, signo)) {
|
|
|
|
sigdelset(&p->p_sigctx.ps_sigignore, signo);
|
|
|
|
SIGACTION(p, signo).sa_handler = SIG_DFL;
|
|
|
|
}
|
2007-11-27 04:27:30 +03:00
|
|
|
mutex_exit(&sa->sa_mutex);
|
2003-11-02 19:30:55 +03:00
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2003-11-02 19:30:55 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If the signal is being ignored, then drop it. Note: we
|
|
|
|
* don't set SIGCONT in ps_sigignore, and if it is set to
|
|
|
|
* SIG_IGN, action will be SIG_DFL here.
|
2003-11-02 19:30:55 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (sigismember(&p->p_sigctx.ps_sigignore, signo))
|
|
|
|
return;
|
|
|
|
|
|
|
|
else if (sigismember(&p->p_sigctx.ps_sigcatch, signo))
|
|
|
|
action = SIG_CATCH;
|
|
|
|
else {
|
|
|
|
action = SIG_DFL;
|
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If sending a tty stop signal to a member of an
|
|
|
|
* orphaned process group, discard the signal here if
|
|
|
|
* the action is default; don't stop the process below
|
|
|
|
* if sleeping, and don't clear any pending SIGCONT.
|
2003-01-18 13:06:22 +03:00
|
|
|
*/
|
2008-04-24 19:35:27 +04:00
|
|
|
if (prop & SA_TTYSTOP && p->p_pgrp->pg_jobc == 0)
|
2007-02-10 00:55:00 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (prop & SA_KILL && p->p_nice > NZERO)
|
|
|
|
p->p_nice = NZERO;
|
2003-11-02 19:30:55 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2003-11-02 19:30:55 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* If stopping or continuing a process, discard any pending
|
|
|
|
* signals that would do the inverse.
|
|
|
|
*/
|
|
|
|
if ((prop & (SA_CONT | SA_STOP)) != 0) {
|
2009-12-20 07:49:09 +03:00
|
|
|
ksiginfoq_t kq;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_queue_init(&kq);
|
|
|
|
if ((prop & SA_CONT) != 0)
|
|
|
|
sigclear(&p->p_sigpend, &stopsigmask, &kq);
|
|
|
|
if ((prop & SA_STOP) != 0)
|
|
|
|
sigclear(&p->p_sigpend, &contsigmask, &kq);
|
|
|
|
ksiginfo_queue_drain(&kq); /* XXXSMP */
|
|
|
|
}
|
|
|
|
|
2012-02-20 01:05:51 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If the signal doesn't have SA_CANTMASK (no override for SIGKILL,
|
|
|
|
* please!), check if any LWPs are waiting on it. If yes, pass on
|
|
|
|
* the signal info. The signal won't be processed further here.
|
|
|
|
*/
|
|
|
|
if ((prop & SA_CANTMASK) == 0 && !LIST_EMPTY(&p->p_sigwaiters) &&
|
|
|
|
p->p_stat == SACTIVE && (p->p_sflag & PS_STOPPING) == 0 &&
|
|
|
|
sigunwait(p, ksi))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXXSMP Should be allocated by the caller, we're holding locks
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
if (kp == NULL && (kp = ksiginfo_alloc(p, ksi, PR_NOWAIT)) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LWP private signals are easy - just find the LWP and post
|
|
|
|
* the signal to it.
|
|
|
|
*/
|
|
|
|
if (lid != 0) {
|
|
|
|
l = lwp_find(p, lid);
|
|
|
|
if (l != NULL) {
|
|
|
|
sigput(&l->l_sigpend, p, kp);
|
2007-12-01 02:05:43 +03:00
|
|
|
membar_producer();
|
2012-02-20 01:05:51 +04:00
|
|
|
(void)sigpost(l, action, prop, kp->ksi_signo);
|
2003-11-02 19:30:55 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-10-15 10:51:17 +04:00
|
|
|
* Some signals go to all LWPs, even if posted with _lwp_kill()
|
|
|
|
* or for an SA process.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
|
|
|
if (p->p_stat == SACTIVE && (p->p_sflag & PS_STOPPING) == 0) {
|
|
|
|
if ((p->p_slflag & PSL_TRACED) != 0)
|
|
|
|
goto deliver;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2003-11-02 19:30:55 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If SIGCONT is default (or ignored) and process is
|
|
|
|
* asleep, we are finished; the process should not
|
|
|
|
* be awakened.
|
2003-11-02 19:30:55 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((prop & SA_CONT) != 0 && action == SIG_DFL)
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
/*
|
2009-11-14 22:06:54 +03:00
|
|
|
* Process is stopped or stopping.
|
|
|
|
* - If traced, then no action is needed, unless killing.
|
|
|
|
* - Run the process only if sending SIGCONT or SIGKILL.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2009-11-14 22:06:54 +03:00
|
|
|
if ((p->p_slflag & PSL_TRACED) != 0 && signo != SIGKILL) {
|
2007-02-10 00:55:00 +03:00
|
|
|
goto out;
|
2009-11-14 22:06:54 +03:00
|
|
|
}
|
2009-03-29 09:02:46 +04:00
|
|
|
if ((prop & SA_CONT) != 0 || signo == SIGKILL) {
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Re-adjust p_nstopchild if the process wasn't
|
|
|
|
* collected by its parent.
|
|
|
|
*/
|
|
|
|
p->p_stat = SACTIVE;
|
|
|
|
p->p_sflag &= ~PS_STOPPING;
|
2009-11-14 22:06:54 +03:00
|
|
|
if (!p->p_waited) {
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_pptr->p_nstopchild--;
|
2009-11-14 22:06:54 +03:00
|
|
|
}
|
|
|
|
if (p->p_slflag & PSL_TRACED) {
|
|
|
|
KASSERT(signo == SIGKILL);
|
|
|
|
goto deliver;
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
2009-03-29 09:02:46 +04:00
|
|
|
* Do not make signal pending if SIGCONT is default.
|
|
|
|
*
|
|
|
|
* If the process catches SIGCONT, let it handle the
|
|
|
|
* signal itself (if waiting on event - process runs,
|
|
|
|
* otherwise continues sleeping).
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2009-03-29 09:02:46 +04:00
|
|
|
if ((prop & SA_CONT) != 0 && action == SIG_DFL) {
|
|
|
|
KASSERT(signo != SIGKILL);
|
|
|
|
goto deliver;
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
} else if ((prop & SA_STOP) != 0) {
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
2003-11-02 19:30:55 +03:00
|
|
|
* Already stopped, don't need to stop again.
|
|
|
|
* (If we did the shell could get confused.)
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
goto out;
|
2009-03-29 09:02:46 +04:00
|
|
|
}
|
2003-11-02 19:30:55 +03:00
|
|
|
}
|
2009-03-29 09:02:46 +04:00
|
|
|
/*
|
|
|
|
* Make signal pending.
|
|
|
|
*/
|
2009-11-14 22:06:54 +03:00
|
|
|
KASSERT((p->p_slflag & PSL_TRACED) == 0);
|
2009-03-29 09:02:46 +04:00
|
|
|
sigput(&p->p_sigpend, p, kp);
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
deliver:
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
2008-02-19 19:16:06 +03:00
|
|
|
* Before we set LW_PENDSIG on any LWP, ensure that the signal is
|
2007-02-10 00:55:00 +03:00
|
|
|
* visible on the per process list (for sigispending()). This
|
|
|
|
* is unlikely to be needed in practice, but...
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2007-12-01 02:05:43 +03:00
|
|
|
membar_producer();
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Try to find an LWP that can take the signal.
|
|
|
|
*/
|
2009-12-20 07:49:09 +03:00
|
|
|
LIST_FOREACH(l, &p->p_lwps, l_sibling) {
|
2012-02-20 01:05:51 +04:00
|
|
|
if (sigpost(l, action, prop, kp->ksi_signo) && !toall)
|
2009-12-20 07:49:09 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
/*
|
|
|
|
* If the ksiginfo wasn't used, then bin it. XXXSMP freeing memory
|
|
|
|
* with locks held. The caller should take care of this.
|
|
|
|
*/
|
|
|
|
ksiginfo_free(kp);
|
2005-10-02 21:51:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-02-10 00:55:00 +03:00
|
|
|
kpsendsig(struct lwp *l, const ksiginfo_t *ksi, const sigset_t *mask)
|
2005-10-02 21:51:27 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2005-10-02 21:51:27 +04:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
(*p->p_emul->e_sendsig)(ksi, mask);
|
2005-10-02 21:51:27 +04:00
|
|
|
}
|
|
|
|
|
2008-02-20 14:48:46 +03:00
|
|
|
/*
|
|
|
|
* Stop any LWPs sleeping interruptably.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
proc_stop_lwps(struct proc *p)
|
|
|
|
{
|
|
|
|
struct lwp *l;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2008-02-20 14:48:46 +03:00
|
|
|
KASSERT((p->p_sflag & PS_STOPPING) != 0);
|
|
|
|
|
|
|
|
LIST_FOREACH(l, &p->p_lwps, l_sibling) {
|
|
|
|
lwp_lock(l);
|
|
|
|
if (l->l_stat == LSSLEEP && (l->l_flag & LW_SINTR) != 0) {
|
|
|
|
l->l_stat = LSSTOP;
|
|
|
|
p->p_nrlwps--;
|
|
|
|
}
|
|
|
|
lwp_unlock(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish stopping of a process. Mark it stopped and notify the parent.
|
|
|
|
*
|
2008-04-24 22:39:20 +04:00
|
|
|
* Drop p_lock briefly if PS_NOTIFYSTOP is set and ppsig is true.
|
2008-02-20 14:48:46 +03:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
proc_stop_done(struct proc *p, bool ppsig, int ppmask)
|
|
|
|
{
|
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
KASSERT(mutex_owned(proc_lock));
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2008-02-20 14:48:46 +03:00
|
|
|
KASSERT((p->p_sflag & PS_STOPPING) != 0);
|
|
|
|
KASSERT(p->p_nrlwps == 0 || (p->p_nrlwps == 1 && p == curproc));
|
|
|
|
|
|
|
|
p->p_sflag &= ~PS_STOPPING;
|
|
|
|
p->p_stat = SSTOP;
|
|
|
|
p->p_waited = 0;
|
|
|
|
p->p_pptr->p_nstopchild++;
|
|
|
|
if ((p->p_sflag & PS_NOTIFYSTOP) != 0) {
|
|
|
|
if (ppsig) {
|
2008-04-24 22:39:20 +04:00
|
|
|
/* child_psignal drops p_lock briefly. */
|
2008-02-20 14:48:46 +03:00
|
|
|
child_psignal(p, ppmask);
|
|
|
|
}
|
|
|
|
cv_broadcast(&p->p_pptr->p_waitcv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Stop the current process and switch away when being stopped or traced.
|
|
|
|
*/
|
2009-03-29 09:02:46 +04:00
|
|
|
static void
|
2007-02-22 02:48:10 +03:00
|
|
|
sigswitch(bool ppsig, int ppmask, int signo)
|
2003-01-18 13:06:22 +03:00
|
|
|
{
|
2008-02-20 14:48:46 +03:00
|
|
|
struct lwp *l = curlwp;
|
2003-01-18 13:06:22 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2007-02-16 03:35:20 +03:00
|
|
|
int biglocks;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-03-05 23:29:14 +03:00
|
|
|
KASSERT(l->l_stat == LSONPROC);
|
|
|
|
KASSERT(p->p_nrlwps > 0);
|
2003-07-17 22:16:58 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* On entry we know that the process needs to stop. If it's
|
|
|
|
* the result of a 'sideways' stop signal that has been sourced
|
|
|
|
* through issignal(), then stop other LWPs in the process too.
|
|
|
|
*/
|
|
|
|
if (p->p_stat == SACTIVE && (p->p_sflag & PS_STOPPING) == 0) {
|
|
|
|
KASSERT(signo != 0);
|
2008-02-20 14:48:46 +03:00
|
|
|
proc_stop(p, 1, signo);
|
2007-03-05 23:29:14 +03:00
|
|
|
KASSERT(p->p_nrlwps > 0);
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* If we are the last live LWP, and the stop was a result of
|
|
|
|
* a new signal, then signal the parent.
|
|
|
|
*/
|
|
|
|
if ((p->p_sflag & PS_STOPPING) != 0) {
|
2008-04-24 19:35:27 +04:00
|
|
|
if (!mutex_tryenter(proc_lock)) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p->p_nrlwps == 1 && (p->p_sflag & PS_STOPPING) != 0) {
|
2008-02-20 14:48:46 +03:00
|
|
|
/*
|
|
|
|
* Note that proc_stop_done() can drop
|
2008-04-24 22:39:20 +04:00
|
|
|
* p->p_lock briefly.
|
2008-02-20 14:48:46 +03:00
|
|
|
*/
|
|
|
|
proc_stop_done(p, ppsig, ppmask);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlock and switch away.
|
|
|
|
*/
|
2007-02-16 03:35:20 +03:00
|
|
|
KERNEL_UNLOCK_ALL(l, &biglocks);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) {
|
|
|
|
p->p_nrlwps--;
|
|
|
|
lwp_lock(l);
|
|
|
|
KASSERT(l->l_stat == LSONPROC || l->l_stat == LSSLEEP);
|
|
|
|
l->l_stat = LSSTOP;
|
|
|
|
lwp_unlock(l);
|
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_lock(l);
|
2007-05-17 18:51:11 +04:00
|
|
|
mi_switch(l);
|
2007-02-16 03:35:20 +03:00
|
|
|
KERNEL_LOCK(biglocks, l);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
1998-09-11 16:50:05 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Check for a signal from the debugger.
|
|
|
|
*/
|
2009-03-29 09:02:46 +04:00
|
|
|
static int
|
2008-12-13 23:43:38 +03:00
|
|
|
sigchecktrace(void)
|
1998-09-11 16:50:05 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct lwp *l = curlwp;
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
int signo;
|
1998-09-11 16:50:05 +04:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-12-13 21:55:01 +03:00
|
|
|
/* If there's a pending SIGKILL, process it immediately. */
|
|
|
|
if (sigismember(&p->p_sigpend.sp_set, SIGKILL))
|
|
|
|
return 0;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* If we are no longer being traced, or the parent didn't
|
2010-04-06 17:50:22 +04:00
|
|
|
* give us a signal, or we're stopping, look for more signals.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
2010-04-06 17:50:22 +04:00
|
|
|
if ((p->p_slflag & PSL_TRACED) == 0 || p->p_xstat == 0 ||
|
|
|
|
(p->p_sflag & PS_STOPPING) != 0)
|
2007-02-10 00:55:00 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the new signal is being masked, look for other signals.
|
|
|
|
* `p->p_sigctx.ps_siglist |= mask' is done in setrunnable().
|
|
|
|
*/
|
|
|
|
signo = p->p_xstat;
|
|
|
|
p->p_xstat = 0;
|
2012-02-20 01:05:51 +04:00
|
|
|
if (sigismember(&l->l_sigmask, signo)) {
|
2007-02-10 00:55:00 +03:00
|
|
|
signo = 0;
|
2012-02-20 01:05:51 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
return signo;
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
|
|
|
* If the current process has received a signal (should be caught or cause
|
|
|
|
* termination, should interrupt current syscall), return the signal number.
|
2007-02-10 00:55:00 +03:00
|
|
|
*
|
1994-06-29 10:29:24 +04:00
|
|
|
* Stop signals with default action are processed immediately, then cleared;
|
|
|
|
* they aren't returned. This is checked after each entry to the system for
|
2007-02-10 00:55:00 +03:00
|
|
|
* a syscall or trap.
|
1994-06-29 10:29:24 +04:00
|
|
|
*
|
2007-02-10 00:55:00 +03:00
|
|
|
* We will also return -1 if the process is exiting and the current LWP must
|
|
|
|
* follow suit.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
|
|
|
int
|
2003-01-18 13:06:22 +03:00
|
|
|
issignal(struct lwp *l)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2008-12-13 23:43:38 +03:00
|
|
|
struct proc *p;
|
|
|
|
int signo, prop;
|
|
|
|
sigpend_t *sp;
|
2007-02-10 00:55:00 +03:00
|
|
|
sigset_t ss;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2008-12-13 23:43:38 +03:00
|
|
|
p = l->l_proc;
|
|
|
|
sp = NULL;
|
|
|
|
signo = 0;
|
|
|
|
|
|
|
|
KASSERT(p == curproc);
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2003-07-17 22:16:58 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
for (;;) {
|
|
|
|
/* Discard any signals that we have decided not to take. */
|
2011-09-04 17:09:12 +04:00
|
|
|
if (signo != 0) {
|
2007-02-10 00:55:00 +03:00
|
|
|
(void)sigget(sp, NULL, signo, NULL);
|
2011-09-04 17:09:12 +04:00
|
|
|
}
|
2006-11-03 22:46:03 +03:00
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If the process is stopped/stopping, then stop ourselves
|
|
|
|
* now that we're on the kernel/userspace boundary. When
|
|
|
|
* we awaken, check for a signal from the debugger.
|
2003-01-18 13:06:22 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) {
|
2007-02-22 09:34:42 +03:00
|
|
|
sigswitch(true, PS_NOCLDSTOP, 0);
|
2008-12-13 23:43:38 +03:00
|
|
|
signo = sigchecktrace();
|
2007-02-10 00:55:00 +03:00
|
|
|
} else
|
|
|
|
signo = 0;
|
|
|
|
|
2008-12-13 23:43:38 +03:00
|
|
|
/* Signals from the debugger are "out of band". */
|
|
|
|
sp = NULL;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* If the debugger didn't provide a signal, find a pending
|
|
|
|
* signal from our set. Check per-LWP signals first, and
|
|
|
|
* then per-process.
|
|
|
|
*/
|
|
|
|
if (signo == 0) {
|
|
|
|
sp = &l->l_sigpend;
|
|
|
|
ss = sp->sp_set;
|
2008-06-16 13:51:14 +04:00
|
|
|
if ((p->p_lflag & PL_PPWAIT) != 0)
|
2007-02-10 00:55:00 +03:00
|
|
|
sigminusset(&stopsigmask, &ss);
|
|
|
|
sigminusset(&l->l_sigmask, &ss);
|
|
|
|
|
|
|
|
if ((signo = firstsig(&ss)) == 0) {
|
|
|
|
sp = &p->p_sigpend;
|
|
|
|
ss = sp->sp_set;
|
2008-06-16 13:51:14 +04:00
|
|
|
if ((p->p_lflag & PL_PPWAIT) != 0)
|
2007-02-10 00:55:00 +03:00
|
|
|
sigminusset(&stopsigmask, &ss);
|
|
|
|
sigminusset(&l->l_sigmask, &ss);
|
|
|
|
|
|
|
|
if ((signo = firstsig(&ss)) == 0) {
|
|
|
|
/*
|
|
|
|
* No signal pending - clear the
|
|
|
|
* indicator and bail out.
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
sp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-09-11 16:50:05 +04:00
|
|
|
}
|
1995-06-09 03:51:01 +04:00
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* We should see pending but ignored signals only if
|
|
|
|
* we are being traced.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (sigismember(&p->p_sigctx.ps_sigignore, signo) &&
|
|
|
|
(p->p_slflag & PSL_TRACED) == 0) {
|
|
|
|
/* Discard the signal. */
|
1994-06-29 10:29:24 +04:00
|
|
|
continue;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
1995-06-09 03:51:01 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* If traced, always stop, and stay stopped until released
|
|
|
|
* by the debugger. If the our parent process is waiting
|
|
|
|
* for us, don't hang as we could deadlock.
|
|
|
|
*/
|
|
|
|
if ((p->p_slflag & PSL_TRACED) != 0 &&
|
2008-06-16 13:51:14 +04:00
|
|
|
(p->p_lflag & PL_PPWAIT) == 0 && signo != SIGKILL) {
|
2011-09-03 23:33:40 +04:00
|
|
|
/*
|
|
|
|
* Take the signal, but don't remove it from the
|
|
|
|
* siginfo queue, because the debugger can send
|
|
|
|
* it later.
|
|
|
|
*/
|
2011-09-05 03:03:00 +04:00
|
|
|
if (sp)
|
|
|
|
sigdelset(&sp->sp_set, signo);
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_xstat = signo;
|
Move the sigfilter hook to a more adequate location, and rename it to better
fit what it does.
The softsignal feature is used in Darwin to trace processes. When the
traced process gets a signal, this raises an exception. The debugger will
receive the exception message, use ptrace with PT_THUPDATE to pass the
signal to the child or discard it, and then it will send a reply to the
exception message, to resume the child.
With the hook at the beginnng of kpsignal2, we are in the context of the
signal sender, which can be the kill(1) command, for instance. We cannot
afford to sleep until the debugger tells us if the signal should be
delivered or not.
Therefore, the hook to generate the Mach exception must be in the traced
process context. That was we can sleep awaiting for the debugger opinion
about the signal, this is not a problem. The hook is hence located into
issignal, at the place where normally SIGCHILD is sent to the debugger,
whereas the traced process is stopped. If the hook returns 0, we bypass
thoses operations, the Mach exception mecanism will take care of notifying
the debugger (through a Mach exception), and stop the faulting thread.
2003-12-25 01:53:59 +03:00
|
|
|
|
|
|
|
/* Emulation-specific handling of signal trace */
|
2007-02-10 00:55:00 +03:00
|
|
|
if (p->p_emul->e_tracesig == NULL ||
|
|
|
|
(*p->p_emul->e_tracesig)(p, signo) == 0)
|
|
|
|
sigswitch(!(p->p_slflag & PSL_FSTRACE), 0,
|
|
|
|
signo);
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/* Check for a signal from the debugger. */
|
2008-12-13 23:43:38 +03:00
|
|
|
if ((signo = sigchecktrace()) == 0)
|
1994-06-29 10:29:24 +04:00
|
|
|
continue;
|
2008-12-13 23:43:38 +03:00
|
|
|
|
|
|
|
/* Signals from the debugger are "out of band". */
|
|
|
|
sp = NULL;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
prop = sigprop[signo];
|
1995-06-09 03:51:01 +04:00
|
|
|
|
DTrace: Add an SDT (Statically Defined Tracing) provider framework, and
implement most of the proc provider. Adds proc:::create, exec,
exec_success, exec_faillure, signal_send, signal_discard, signal_handle,
lwp_create, lwp_start, lwp_exit.
2010-03-02 00:10:13 +03:00
|
|
|
/* XXX no siginfo? */
|
|
|
|
SDT_PROBE(proc,,,signal_handle, signo, 0,
|
|
|
|
SIGACTION(p, signo).sa_handler, 0, 0);
|
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
|
|
|
* Decide whether the signal should be returned.
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
switch ((long)SIGACTION(p, signo).sa_handler) {
|
1994-10-30 22:15:46 +03:00
|
|
|
case (long)SIG_DFL:
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
|
|
|
* Don't take default actions on system processes.
|
|
|
|
*/
|
|
|
|
if (p->p_pid <= 1) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/*
|
|
|
|
* Are you sure you want to ignore SIGSEGV
|
|
|
|
* in init? XXX
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
printf_nolog("Process (pid %d) got sig %d\n",
|
|
|
|
p->p_pid, signo);
|
1994-06-29 10:29:24 +04:00
|
|
|
#endif
|
2007-02-10 00:55:00 +03:00
|
|
|
continue;
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If there is a pending stop signal to process with
|
|
|
|
* default action, stop here, then clear the signal.
|
|
|
|
* However, if process is member of an orphaned
|
1994-06-29 10:29:24 +04:00
|
|
|
* process group, ignore tty stop signals.
|
|
|
|
*/
|
|
|
|
if (prop & SA_STOP) {
|
2008-04-24 19:35:27 +04:00
|
|
|
/*
|
|
|
|
* XXX Don't hold proc_lock for p_lflag,
|
|
|
|
* but it's not a big deal.
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (p->p_slflag & PSL_TRACED ||
|
2009-12-20 07:49:09 +03:00
|
|
|
((p->p_lflag & PL_ORPHANPG) != 0 &&
|
2007-02-10 00:55:00 +03:00
|
|
|
prop & SA_TTYSTOP)) {
|
2009-12-20 07:49:09 +03:00
|
|
|
/* Ignore the signal. */
|
2007-02-10 00:55:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Take the signal. */
|
|
|
|
(void)sigget(sp, NULL, signo, NULL);
|
|
|
|
p->p_xstat = signo;
|
|
|
|
signo = 0;
|
2007-02-22 09:34:42 +03:00
|
|
|
sigswitch(true, PS_NOCLDSTOP, p->p_xstat);
|
1994-06-29 10:29:24 +04:00
|
|
|
} else if (prop & SA_IGNORE) {
|
|
|
|
/*
|
|
|
|
* Except for SIGCONT, shouldn't get here.
|
|
|
|
* Default action is to ignore; drop it.
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1994-10-30 22:15:46 +03:00
|
|
|
case (long)SIG_IGN:
|
2007-02-10 00:55:00 +03:00
|
|
|
#ifdef DEBUG_ISSIGNAL
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
|
|
|
* Masking above should prevent us ever trying
|
|
|
|
* to take action on an ignored signal other
|
|
|
|
* than SIGCONT, unless process is traced.
|
|
|
|
*/
|
|
|
|
if ((prop & SA_CONT) == 0 &&
|
2007-02-10 00:55:00 +03:00
|
|
|
(p->p_slflag & PSL_TRACED) == 0)
|
|
|
|
printf_nolog("issignal\n");
|
2002-11-29 00:00:27 +03:00
|
|
|
#endif
|
2007-02-10 00:55:00 +03:00
|
|
|
continue;
|
1994-06-29 10:29:24 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* This signal has an action, let postsig() process
|
|
|
|
* it.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
2003-11-02 19:26:10 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
break;
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
2003-11-02 19:26:10 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
l->l_sigpendset = sp;
|
|
|
|
return signo;
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
|
|
|
* Take the action for the specified signal
|
|
|
|
* from the current set of pending signals.
|
|
|
|
*/
|
|
|
|
void
|
2007-02-10 00:55:00 +03:00
|
|
|
postsig(int signo)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct lwp *l;
|
2001-02-27 00:58:30 +03:00
|
|
|
struct proc *p;
|
|
|
|
struct sigacts *ps;
|
|
|
|
sig_t action;
|
|
|
|
sigset_t *returnmask;
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_t ksi;
|
2001-02-27 00:58:30 +03:00
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
l = curlwp;
|
|
|
|
p = l->l_proc;
|
2001-02-27 00:58:30 +03:00
|
|
|
ps = p->p_sigacts;
|
2000-08-22 21:28:28 +04:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
KASSERT(signo > 0);
|
2000-08-22 21:28:28 +04:00
|
|
|
|
2004-03-21 21:41:38 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Set the new mask value and also defer further occurrences of this
|
|
|
|
* signal.
|
|
|
|
*
|
2008-02-19 15:20:02 +03:00
|
|
|
* Special case: user has done a sigsuspend. Here the current mask is
|
2008-12-13 23:43:38 +03:00
|
|
|
* not of interest, but rather the mask from before the sigsuspend is
|
2007-02-10 00:55:00 +03:00
|
|
|
* what we want restored after the signal processing is completed.
|
2004-03-21 21:41:38 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (l->l_sigrestore) {
|
|
|
|
returnmask = &l->l_sigoldmask;
|
|
|
|
l->l_sigrestore = 0;
|
|
|
|
} else
|
|
|
|
returnmask = &l->l_sigmask;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Commit to taking the signal before releasing the mutex.
|
|
|
|
*/
|
|
|
|
action = SIGACTION_PS(ps, signo).sa_handler;
|
2008-03-27 22:06:51 +03:00
|
|
|
l->l_ru.ru_nsignals++;
|
2011-09-04 17:09:12 +04:00
|
|
|
if (l->l_sigpendset == NULL) {
|
2011-09-03 23:33:40 +04:00
|
|
|
/* From the debugger */
|
2011-09-04 17:09:12 +04:00
|
|
|
if (!siggetinfo(&l->l_sigpend, &ksi, signo))
|
|
|
|
(void)siggetinfo(&p->p_sigpend, &ksi, signo);
|
|
|
|
} else
|
|
|
|
sigget(l->l_sigpendset, &ksi, signo, NULL);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-08-15 16:07:23 +04:00
|
|
|
if (ktrpoint(KTR_PSIG)) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-09-13 01:33:39 +04:00
|
|
|
ktrpsig(signo, action, returnmask, &ksi);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2004-03-21 21:41:38 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2003-09-20 02:51:31 +04:00
|
|
|
if (action == SIG_DFL) {
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
|
|
|
* Default action, where the default is to kill
|
|
|
|
* the process. (Other cases were ignored above.)
|
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
sigexit(l, signo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we get here, the signal must be caught.
|
|
|
|
*/
|
1994-06-29 10:29:24 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2007-02-10 00:55:00 +03:00
|
|
|
if (action == SIG_IGN || sigismember(&l->l_sigmask, signo))
|
|
|
|
panic("postsig action");
|
2003-09-20 02:51:31 +04:00
|
|
|
#endif
|
2000-08-22 21:28:28 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
kpsendsig(l, &ksi, returnmask);
|
|
|
|
}
|
|
|
|
|
2008-11-19 21:35:57 +03:00
|
|
|
/*
|
|
|
|
* sendsig:
|
|
|
|
*
|
|
|
|
* Default signal delivery method for NetBSD.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sendsig(const struct ksiginfo *ksi, const sigset_t *mask)
|
|
|
|
{
|
|
|
|
struct sigacts *sa;
|
|
|
|
int sig;
|
|
|
|
|
|
|
|
sig = ksi->ksi_signo;
|
|
|
|
sa = curproc->p_sigacts;
|
|
|
|
|
|
|
|
switch (sa->sa_sigdesc[sig].sd_vers) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
/* Compat for 1.6 and earlier. */
|
|
|
|
if (sendsig_sigcontext_vec == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
(*sendsig_sigcontext_vec)(ksi, mask);
|
|
|
|
return;
|
|
|
|
case 2:
|
2008-11-25 18:05:38 +03:00
|
|
|
case 3:
|
2008-11-19 21:35:57 +03:00
|
|
|
sendsig_siginfo(ksi, mask);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("sendsig: bad version %d\n", sa->sa_sigdesc[sig].sd_vers);
|
|
|
|
sigexit(curlwp, SIGILL);
|
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* sendsig_reset:
|
|
|
|
*
|
|
|
|
* Reset the signal action. Called from emulation specific sendsig()
|
|
|
|
* before unlocking to deliver the signal.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sendsig_reset(struct lwp *l, int signo)
|
|
|
|
{
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct sigacts *ps = p->p_sigacts;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
p->p_sigctx.ps_lwp = 0;
|
|
|
|
p->p_sigctx.ps_code = 0;
|
|
|
|
p->p_sigctx.ps_signo = 0;
|
|
|
|
|
2007-11-27 04:27:30 +03:00
|
|
|
mutex_enter(&ps->sa_mutex);
|
2012-02-20 01:05:51 +04:00
|
|
|
sigplusset(&SIGACTION_PS(ps, signo).sa_mask, &l->l_sigmask);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (SIGACTION_PS(ps, signo).sa_flags & SA_RESETHAND) {
|
|
|
|
sigdelset(&p->p_sigctx.ps_sigcatch, signo);
|
|
|
|
if (signo != SIGCONT && sigprop[signo] & SA_IGNORE)
|
|
|
|
sigaddset(&p->p_sigctx.ps_sigignore, signo);
|
|
|
|
SIGACTION_PS(ps, signo).sa_handler = SIG_DFL;
|
|
|
|
}
|
2007-11-27 04:27:30 +03:00
|
|
|
mutex_exit(&ps->sa_mutex);
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kill the current process for stated reason.
|
|
|
|
*/
|
1996-02-04 05:15:01 +03:00
|
|
|
void
|
2002-07-29 02:18:51 +04:00
|
|
|
killproc(struct proc *p, const char *why)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2008-04-24 19:35:27 +04:00
|
|
|
|
|
|
|
KASSERT(mutex_owned(proc_lock));
|
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
log(LOG_ERR, "pid %d was killed: %s\n", p->p_pid, why);
|
2007-02-10 00:55:00 +03:00
|
|
|
uprintf_locked("sorry, pid %d was killed: %s\n", p->p_pid, why);
|
1994-06-29 10:29:24 +04:00
|
|
|
psignal(p, SIGKILL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force the current process to exit with the specified signal, dumping core
|
2007-02-10 00:55:00 +03:00
|
|
|
* if appropriate. We bypass the normal tests for masked and caught
|
|
|
|
* signals, allowing unrecoverable failures to terminate the process without
|
|
|
|
* changing signal state. Mark the accounting record with the signal
|
|
|
|
* termination. If dumping core, save the signal number for the debugger.
|
|
|
|
* Calls exit and does not return.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
1996-02-04 05:15:01 +03:00
|
|
|
void
|
2007-02-10 00:55:00 +03:00
|
|
|
sigexit(struct lwp *l, int signo)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
int exitsig, error, docore;
|
|
|
|
struct proc *p;
|
|
|
|
struct lwp *t;
|
2003-01-18 13:06:22 +03:00
|
|
|
|
|
|
|
p = l->l_proc;
|
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2007-02-10 00:55:00 +03:00
|
|
|
KERNEL_UNLOCK_ALL(l, NULL);
|
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Don't permit coredump() multiple times in the same process.
|
|
|
|
* Call back into sigexit, where we will be suspended until
|
|
|
|
* the deed is done. Note that this is a recursive call, but
|
2007-02-18 01:31:36 +03:00
|
|
|
* LW_WCORE will prevent us from coming back this way.
|
2003-01-18 13:06:22 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((p->p_sflag & PS_WCORE) != 0) {
|
|
|
|
lwp_lock(l);
|
2007-02-18 01:31:36 +03:00
|
|
|
l->l_flag |= (LW_WCORE | LW_WEXIT | LW_WSUSPEND);
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(l);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_userret(l);
|
2008-04-29 18:04:06 +04:00
|
|
|
panic("sigexit 1");
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If process is already on the way out, then bail now. */
|
|
|
|
if ((p->p_sflag & PS_WEXIT) != 0) {
|
|
|
|
mutex_exit(p->p_lock);
|
|
|
|
lwp_exit(l);
|
|
|
|
panic("sigexit 2");
|
2007-02-10 00:55:00 +03:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Prepare all other LWPs for exit. If dumping core, suspend them
|
|
|
|
* so that their registers are available long enough to be dumped.
|
|
|
|
*/
|
|
|
|
if ((docore = (sigprop[signo] & SA_CORE)) != 0) {
|
|
|
|
p->p_sflag |= PS_WCORE;
|
|
|
|
for (;;) {
|
|
|
|
LIST_FOREACH(t, &p->p_lwps, l_sibling) {
|
|
|
|
lwp_lock(t);
|
|
|
|
if (t == l) {
|
2007-02-18 01:31:36 +03:00
|
|
|
t->l_flag &= ~LW_WSUSPEND;
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(t);
|
|
|
|
continue;
|
|
|
|
}
|
2007-02-18 01:31:36 +03:00
|
|
|
t->l_flag |= (LW_WCORE | LW_WEXIT);
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_suspend(l, t);
|
|
|
|
}
|
Add kernel logging of processes which exit on signals which can
cause a core to drop, and whether the core dropped, or, if it did
not, why not (i.e. error number). Logs process ID, name, signal that
hit it, and whether the core dump was successful.
logging only happens if kern_logsigexit is non-zero, and it can be
changed by the new sysctl(3) value KERN_LOGSIGEXIT. The name of this
sysctl and its function are taken from FreeBSD, at the suggestion
of Greg Woods in PR 6224. Default behavior is zero for a normal
kernel, and one for a kernel compiled with DIAGNOSTIC.
2000-02-06 10:29:56 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if (p->p_nrlwps == 1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kick any LWPs sitting in lwp_wait1(), and wait
|
|
|
|
* for everyone else to stop before proceeding.
|
|
|
|
*/
|
|
|
|
p->p_nlwpwait++;
|
|
|
|
cv_broadcast(&p->p_lwpcv);
|
2008-04-24 22:39:20 +04:00
|
|
|
cv_wait(&p->p_lwpcv, p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_nlwpwait--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exitsig = signo;
|
1994-06-29 10:29:24 +04:00
|
|
|
p->p_acflag |= AXSIG;
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_sigctx.ps_signo = signo;
|
|
|
|
|
|
|
|
if (docore) {
|
2008-04-29 18:04:06 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2008-11-19 21:35:57 +03:00
|
|
|
if ((error = (*coredump_vec)(l, NULL)) == 0)
|
2000-07-08 22:10:25 +04:00
|
|
|
exitsig |= WCOREFLAG;
|
|
|
|
|
|
|
|
if (kern_logsigexit) {
|
2006-07-24 02:06:03 +04:00
|
|
|
int uid = l->l_cred ?
|
|
|
|
(int)kauth_cred_geteuid(l->l_cred) : -1;
|
2000-07-08 22:10:25 +04:00
|
|
|
|
2005-02-27 00:34:55 +03:00
|
|
|
if (error)
|
2000-07-08 22:10:25 +04:00
|
|
|
log(LOG_INFO, lognocoredump, p->p_pid,
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_comm, uid, signo, error);
|
2000-07-08 22:10:25 +04:00
|
|
|
else
|
|
|
|
log(LOG_INFO, logcoredump, p->p_pid,
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_comm, uid, signo);
|
Add kernel logging of processes which exit on signals which can
cause a core to drop, and whether the core dropped, or, if it did
not, why not (i.e. error number). Logs process ID, name, signal that
hit it, and whether the core dump was successful.
logging only happens if kern_logsigexit is non-zero, and it can be
changed by the new sysctl(3) value KERN_LOGSIGEXIT. The name of this
sysctl and its function are taken from FreeBSD, at the suggestion
of Greg Woods in PR 6224. Default behavior is zero for a normal
kernel, and one for a kernel compiled with DIAGNOSTIC.
2000-02-06 10:29:56 +03:00
|
|
|
}
|
|
|
|
|
2006-11-22 05:02:51 +03:00
|
|
|
#ifdef PAX_SEGVGUARD
|
2007-02-22 09:34:42 +03:00
|
|
|
pax_segvguard(l, p->p_textvp, p->p_comm, true);
|
2006-11-22 05:02:51 +03:00
|
|
|
#endif /* PAX_SEGVGUARD */
|
2008-04-29 18:04:06 +04:00
|
|
|
/* Acquire the sched state mutex. exit1() will release it. */
|
|
|
|
mutex_enter(p->p_lock);
|
1994-06-29 10:29:24 +04:00
|
|
|
}
|
Add kernel logging of processes which exit on signals which can
cause a core to drop, and whether the core dropped, or, if it did
not, why not (i.e. error number). Logs process ID, name, signal that
hit it, and whether the core dump was successful.
logging only happens if kern_logsigexit is non-zero, and it can be
changed by the new sysctl(3) value KERN_LOGSIGEXIT. The name of this
sysctl and its function are taken from FreeBSD, at the suggestion
of Greg Woods in PR 6224. Default behavior is zero for a normal
kernel, and one for a kernel compiled with DIAGNOSTIC.
2000-02-06 10:29:56 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/* No longer dumping core. */
|
|
|
|
p->p_sflag &= ~PS_WCORE;
|
2005-06-10 09:10:12 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
exit1(l, W_EXITCODE(0, exitsig));
|
|
|
|
/* NOTREACHED */
|
2005-06-10 09:10:12 +04:00
|
|
|
}
|
|
|
|
|
1994-06-29 10:29:24 +04:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Put process 'p' into the stopped state and optionally, notify the parent.
|
1994-06-29 10:29:24 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
void
|
|
|
|
proc_stop(struct proc *p, int notify, int signo)
|
1994-06-29 10:29:24 +04:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
struct lwp *l;
|
1996-10-24 03:13:19 +04:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
1996-10-24 03:13:19 +04:00
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* First off, set the stopping indicator and bring all sleeping
|
|
|
|
* LWPs to a halt so they are included in p->p_nrlwps. We musn't
|
|
|
|
* unlock between here and the p->p_nrlwps check below.
|
1996-10-24 03:13:19 +04:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_sflag |= PS_STOPPING;
|
2008-02-20 14:48:46 +03:00
|
|
|
if (notify)
|
|
|
|
p->p_sflag |= PS_NOTIFYSTOP;
|
|
|
|
else
|
|
|
|
p->p_sflag &= ~PS_NOTIFYSTOP;
|
2007-12-01 02:05:43 +03:00
|
|
|
membar_producer();
|
1999-09-28 18:47:00 +04:00
|
|
|
|
2008-02-20 14:48:46 +03:00
|
|
|
proc_stop_lwps(p);
|
2003-01-18 13:06:22 +03:00
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If there are no LWPs available to take the signal, then we
|
|
|
|
* signal the parent process immediately. Otherwise, the last
|
|
|
|
* LWP to stop will take care of it.
|
2003-01-18 13:06:22 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
if (p->p_nrlwps == 0) {
|
2008-02-20 14:48:46 +03:00
|
|
|
proc_stop_done(p, true, PS_NOCLDSTOP);
|
2003-01-18 13:06:22 +03:00
|
|
|
} else {
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Have the remaining LWPs come to a halt, and trigger
|
|
|
|
* proc_stop_callout() to ensure that they do.
|
|
|
|
*/
|
2012-02-20 01:05:51 +04:00
|
|
|
LIST_FOREACH(l, &p->p_lwps, l_sibling) {
|
|
|
|
sigpost(l, SIG_DFL, SA_STOP, signo);
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
callout_schedule(&proc_stop_ch, 1);
|
2004-03-04 03:05:58 +03:00
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
}
|
|
|
|
|
2003-02-15 23:54:38 +03:00
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* When stopping a process, we do not immediatly set sleeping LWPs stopped,
|
|
|
|
* but wait for them to come to a halt at the kernel-user boundary. This is
|
|
|
|
* to allow LWPs to release any locks that they may hold before stopping.
|
2003-02-15 23:54:38 +03:00
|
|
|
*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Non-interruptable sleeps can be long, and there is the potential for an
|
|
|
|
* LWP to begin sleeping interruptably soon after the process has been set
|
|
|
|
* stopping (PS_STOPPING). These LWPs will not notice that the process is
|
|
|
|
* stopping, and so complete halt of the process and the return of status
|
|
|
|
* information to the parent could be delayed indefinitely.
|
|
|
|
*
|
|
|
|
* To handle this race, proc_stop_callout() runs once per tick while there
|
2007-08-17 21:25:14 +04:00
|
|
|
* are stopping processes in the system. It sets LWPs that are sleeping
|
2007-02-10 00:55:00 +03:00
|
|
|
* interruptably into the LSSTOP state.
|
|
|
|
*
|
|
|
|
* Note that we are not concerned about keeping all LWPs stopped while the
|
|
|
|
* process is stopped: stopped LWPs can awaken briefly to handle signals.
|
|
|
|
* What we do need to ensure is that all LWPs in a stopping process have
|
|
|
|
* stopped at least once, so that notification can be sent to the parent
|
|
|
|
* process.
|
2003-02-15 23:54:38 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
static void
|
|
|
|
proc_stop_callout(void *cookie)
|
2003-02-15 23:54:38 +03:00
|
|
|
{
|
2007-02-22 02:48:10 +03:00
|
|
|
bool more, restart;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p;
|
2003-02-15 23:54:38 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
(void)cookie;
|
2006-05-11 01:53:14 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
do {
|
2007-02-22 09:34:42 +03:00
|
|
|
restart = false;
|
|
|
|
more = false;
|
2003-11-01 10:44:14 +03:00
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
PROCLIST_FOREACH(p, &allproc) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2003-02-15 23:54:38 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((p->p_sflag & PS_STOPPING) == 0) {
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
2003-02-15 23:54:38 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/* Stop any LWPs sleeping interruptably. */
|
2008-02-20 14:48:46 +03:00
|
|
|
proc_stop_lwps(p);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (p->p_nrlwps == 0) {
|
|
|
|
/*
|
|
|
|
* We brought the process to a halt.
|
|
|
|
* Mark it as stopped and notify the
|
|
|
|
* parent.
|
|
|
|
*/
|
|
|
|
if ((p->p_sflag & PS_NOTIFYSTOP) != 0) {
|
|
|
|
/*
|
2008-02-20 14:48:46 +03:00
|
|
|
* Note that proc_stop_done() will
|
2008-04-24 22:39:20 +04:00
|
|
|
* drop p->p_lock briefly.
|
2007-02-10 00:55:00 +03:00
|
|
|
* Arrange to restart and check
|
|
|
|
* all processes again.
|
|
|
|
*/
|
2007-02-22 09:34:42 +03:00
|
|
|
restart = true;
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2008-02-20 14:48:46 +03:00
|
|
|
proc_stop_done(p, true, PS_NOCLDSTOP);
|
2007-02-10 00:55:00 +03:00
|
|
|
} else
|
2007-02-22 09:34:42 +03:00
|
|
|
more = true;
|
2003-02-15 23:54:38 +03:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
if (restart)
|
|
|
|
break;
|
2007-01-10 10:53:26 +03:00
|
|
|
}
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
} while (restart);
|
2003-02-15 23:54:38 +03:00
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* If we noted processes that are stopping but still have
|
|
|
|
* running LWPs, then arrange to check again in 1 tick.
|
2003-02-15 23:54:38 +03:00
|
|
|
*/
|
2007-02-10 00:55:00 +03:00
|
|
|
if (more)
|
|
|
|
callout_schedule(&proc_stop_ch, 1);
|
|
|
|
}
|
2003-02-15 23:54:38 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* Given a process in state SSTOP, set the state back to SACTIVE and
|
|
|
|
* move LSSTOP'd LWPs to LSSLEEP or make them runnable.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
proc_unstop(struct proc *p)
|
|
|
|
{
|
|
|
|
struct lwp *l;
|
|
|
|
int sig;
|
2003-02-15 23:54:38 +03:00
|
|
|
|
2008-04-24 19:35:27 +04:00
|
|
|
KASSERT(mutex_owned(proc_lock));
|
2008-04-24 22:39:20 +04:00
|
|
|
KASSERT(mutex_owned(p->p_lock));
|
2003-02-15 23:54:38 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
p->p_stat = SACTIVE;
|
|
|
|
p->p_sflag &= ~PS_STOPPING;
|
|
|
|
sig = p->p_xstat;
|
2003-02-15 23:54:38 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if (!p->p_waited)
|
|
|
|
p->p_pptr->p_nstopchild--;
|
2003-02-15 23:54:38 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
LIST_FOREACH(l, &p->p_lwps, l_sibling) {
|
|
|
|
lwp_lock(l);
|
|
|
|
if (l->l_stat != LSSTOP) {
|
|
|
|
lwp_unlock(l);
|
|
|
|
continue;
|
2003-02-15 23:54:38 +03:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
if (l->l_wchan == NULL) {
|
|
|
|
setrunnable(l);
|
|
|
|
continue;
|
|
|
|
}
|
2007-02-18 01:31:36 +03:00
|
|
|
if (sig && (l->l_flag & LW_SINTR) != 0) {
|
2009-12-20 07:49:09 +03:00
|
|
|
setrunnable(l);
|
|
|
|
sig = 0;
|
2007-03-05 23:29:14 +03:00
|
|
|
} else {
|
|
|
|
l->l_stat = LSSLEEP;
|
|
|
|
p->p_nrlwps++;
|
2007-02-10 00:55:00 +03:00
|
|
|
lwp_unlock(l);
|
2007-03-05 23:29:14 +03:00
|
|
|
}
|
2003-02-15 23:54:38 +03:00
|
|
|
}
|
2000-11-05 18:37:09 +03:00
|
|
|
}
|
2002-10-23 13:10:23 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
filt_sigattach(struct knote *kn)
|
|
|
|
{
|
|
|
|
struct proc *p = curproc;
|
|
|
|
|
2008-03-22 00:54:58 +03:00
|
|
|
kn->kn_obj = p;
|
2009-12-20 07:49:09 +03:00
|
|
|
kn->kn_flags |= EV_CLEAR; /* automatically set */
|
2002-10-23 13:10:23 +04:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2002-10-23 13:10:23 +04:00
|
|
|
SLIST_INSERT_HEAD(&p->p_klist, kn, kn_selnext);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2002-10-23 13:10:23 +04:00
|
|
|
|
2009-12-20 07:49:09 +03:00
|
|
|
return 0;
|
2002-10-23 13:10:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
filt_sigdetach(struct knote *kn)
|
|
|
|
{
|
2008-03-22 00:54:58 +03:00
|
|
|
struct proc *p = kn->kn_obj;
|
2002-10-23 13:10:23 +04:00
|
|
|
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2002-10-23 13:10:23 +04:00
|
|
|
SLIST_REMOVE(&p->p_klist, kn, knote, kn_selnext);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2002-10-23 13:10:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-12-20 07:49:09 +03:00
|
|
|
* Signal knotes are shared with proc knotes, so we apply a mask to
|
2002-10-23 13:10:23 +04:00
|
|
|
* the hint in order to differentiate them from process hints. This
|
|
|
|
* could be avoided by using a signal-specific knote list, but probably
|
|
|
|
* isn't worth the trouble.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
filt_signal(struct knote *kn, long hint)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (hint & NOTE_SIGNAL) {
|
|
|
|
hint &= ~NOTE_SIGNAL;
|
|
|
|
|
|
|
|
if (kn->kn_id == hint)
|
|
|
|
kn->kn_data++;
|
|
|
|
}
|
|
|
|
return (kn->kn_data != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct filterops sig_filtops = {
|
|
|
|
0, filt_sigattach, filt_sigdetach, filt_signal
|
|
|
|
};
|