Home | History | Annotate | Line # | Download | only in kern
sys_sig.c revision 1.57
      1  1.57        ad /*	$NetBSD: sys_sig.c,v 1.57 2023/10/04 20:42:38 ad Exp $	*/
      2   1.2        ad 
      3   1.2        ad /*-
      4  1.14        ad  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
      5   1.2        ad  * All rights reserved.
      6   1.2        ad  *
      7   1.2        ad  * This code is derived from software contributed to The NetBSD Foundation
      8   1.2        ad  * by Andrew Doran.
      9   1.2        ad  *
     10   1.2        ad  * Redistribution and use in source and binary forms, with or without
     11   1.2        ad  * modification, are permitted provided that the following conditions
     12   1.2        ad  * are met:
     13   1.2        ad  * 1. Redistributions of source code must retain the above copyright
     14   1.2        ad  *    notice, this list of conditions and the following disclaimer.
     15   1.2        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.2        ad  *    notice, this list of conditions and the following disclaimer in the
     17   1.2        ad  *    documentation and/or other materials provided with the distribution.
     18   1.2        ad  *
     19   1.2        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.2        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.2        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.2        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.2        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.2        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.2        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.2        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.2        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.2        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.2        ad  * POSSIBILITY OF SUCH DAMAGE.
     30   1.2        ad  */
     31   1.2        ad 
     32   1.2        ad /*
     33   1.2        ad  * Copyright (c) 1982, 1986, 1989, 1991, 1993
     34   1.2        ad  *	The Regents of the University of California.  All rights reserved.
     35   1.2        ad  * (c) UNIX System Laboratories, Inc.
     36   1.2        ad  * All or some portions of this file are derived from material licensed
     37   1.2        ad  * to the University of California by American Telephone and Telegraph
     38   1.2        ad  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     39   1.2        ad  * the permission of UNIX System Laboratories, Inc.
     40   1.2        ad  *
     41   1.2        ad  * Redistribution and use in source and binary forms, with or without
     42   1.2        ad  * modification, are permitted provided that the following conditions
     43   1.2        ad  * are met:
     44   1.2        ad  * 1. Redistributions of source code must retain the above copyright
     45   1.2        ad  *    notice, this list of conditions and the following disclaimer.
     46   1.2        ad  * 2. Redistributions in binary form must reproduce the above copyright
     47   1.2        ad  *    notice, this list of conditions and the following disclaimer in the
     48   1.2        ad  *    documentation and/or other materials provided with the distribution.
     49   1.2        ad  * 3. Neither the name of the University nor the names of its contributors
     50   1.2        ad  *    may be used to endorse or promote products derived from this software
     51   1.2        ad  *    without specific prior written permission.
     52   1.2        ad  *
     53   1.2        ad  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     54   1.2        ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     55   1.2        ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     56   1.2        ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     57   1.2        ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     58   1.2        ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     59   1.2        ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60   1.2        ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61   1.2        ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62   1.2        ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63   1.2        ad  * SUCH DAMAGE.
     64   1.2        ad  *
     65   1.2        ad  *	@(#)kern_sig.c	8.14 (Berkeley) 5/14/95
     66   1.2        ad  */
     67   1.2        ad 
     68   1.2        ad #include <sys/cdefs.h>
     69  1.57        ad __KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.57 2023/10/04 20:42:38 ad Exp $");
     70  1.45  christos 
     71  1.45  christos #include "opt_dtrace.h"
     72   1.2        ad 
     73   1.2        ad #include <sys/param.h>
     74   1.2        ad #include <sys/kernel.h>
     75   1.2        ad #include <sys/signalvar.h>
     76   1.2        ad #include <sys/proc.h>
     77   1.2        ad #include <sys/pool.h>
     78   1.2        ad #include <sys/syscallargs.h>
     79   1.2        ad #include <sys/kauth.h>
     80   1.2        ad #include <sys/wait.h>
     81   1.2        ad #include <sys/kmem.h>
     82  1.19        ad #include <sys/module.h>
     83  1.45  christos #include <sys/sdt.h>
     84  1.50  pgoyette #include <sys/compat_stub.h>
     85  1.45  christos 
     86  1.45  christos SDT_PROVIDER_DECLARE(proc);
     87  1.45  christos SDT_PROBE_DEFINE2(proc, kernel, , signal__clear,
     88  1.45  christos     "int", 		/* signal */
     89  1.45  christos     "ksiginfo_t *");	/* signal-info */
     90   1.2        ad 
     91   1.2        ad int
     92  1.25     rmind sys___sigaction_sigtramp(struct lwp *l,
     93  1.25     rmind     const struct sys___sigaction_sigtramp_args *uap, register_t *retval)
     94   1.2        ad {
     95   1.9       dsl 	/* {
     96   1.2        ad 		syscallarg(int)				signum;
     97   1.2        ad 		syscallarg(const struct sigaction *)	nsa;
     98   1.2        ad 		syscallarg(struct sigaction *)		osa;
     99   1.2        ad 		syscallarg(void *)			tramp;
    100   1.2        ad 		syscallarg(int)				vers;
    101   1.9       dsl 	} */
    102   1.2        ad 	struct sigaction nsa, osa;
    103   1.2        ad 	int error;
    104   1.2        ad 
    105   1.2        ad 	if (SCARG(uap, nsa)) {
    106   1.2        ad 		error = copyin(SCARG(uap, nsa), &nsa, sizeof(nsa));
    107   1.2        ad 		if (error)
    108   1.2        ad 			return (error);
    109   1.2        ad 	}
    110   1.2        ad 	error = sigaction1(l, SCARG(uap, signum),
    111   1.2        ad 	    SCARG(uap, nsa) ? &nsa : 0, SCARG(uap, osa) ? &osa : 0,
    112   1.2        ad 	    SCARG(uap, tramp), SCARG(uap, vers));
    113   1.2        ad 	if (error)
    114   1.2        ad 		return (error);
    115   1.2        ad 	if (SCARG(uap, osa)) {
    116   1.2        ad 		error = copyout(&osa, SCARG(uap, osa), sizeof(osa));
    117   1.2        ad 		if (error)
    118   1.2        ad 			return (error);
    119   1.2        ad 	}
    120  1.25     rmind 	return 0;
    121   1.2        ad }
    122   1.2        ad 
    123   1.2        ad /*
    124   1.2        ad  * Manipulate signal mask.  Note that we receive new mask, not pointer, and
    125   1.2        ad  * return old mask as return value; the library stub does the rest.
    126   1.2        ad  */
    127   1.2        ad int
    128  1.25     rmind sys___sigprocmask14(struct lwp *l, const struct sys___sigprocmask14_args *uap,
    129  1.25     rmind     register_t *retval)
    130   1.2        ad {
    131   1.9       dsl 	/* {
    132   1.2        ad 		syscallarg(int)			how;
    133   1.2        ad 		syscallarg(const sigset_t *)	set;
    134   1.2        ad 		syscallarg(sigset_t *)		oset;
    135   1.9       dsl 	} */
    136   1.2        ad 	struct proc	*p = l->l_proc;
    137   1.2        ad 	sigset_t	nss, oss;
    138   1.2        ad 	int		error;
    139   1.2        ad 
    140   1.2        ad 	if (SCARG(uap, set)) {
    141   1.2        ad 		error = copyin(SCARG(uap, set), &nss, sizeof(nss));
    142   1.2        ad 		if (error)
    143  1.25     rmind 			return error;
    144   1.2        ad 	}
    145  1.14        ad 	mutex_enter(p->p_lock);
    146   1.2        ad 	error = sigprocmask1(l, SCARG(uap, how),
    147   1.2        ad 	    SCARG(uap, set) ? &nss : 0, SCARG(uap, oset) ? &oss : 0);
    148  1.14        ad 	mutex_exit(p->p_lock);
    149   1.2        ad 	if (error)
    150  1.25     rmind 		return error;
    151   1.2        ad 	if (SCARG(uap, oset)) {
    152   1.2        ad 		error = copyout(&oss, SCARG(uap, oset), sizeof(oss));
    153   1.2        ad 		if (error)
    154  1.25     rmind 			return error;
    155   1.2        ad 	}
    156  1.25     rmind 	return 0;
    157   1.2        ad }
    158   1.2        ad 
    159   1.2        ad int
    160  1.25     rmind sys___sigpending14(struct lwp *l, const struct sys___sigpending14_args *uap,
    161  1.25     rmind     register_t *retval)
    162   1.2        ad {
    163   1.9       dsl 	/* {
    164   1.2        ad 		syscallarg(sigset_t *)	set;
    165   1.9       dsl 	} */
    166   1.2        ad 	sigset_t ss;
    167   1.2        ad 
    168   1.2        ad 	sigpending1(l, &ss);
    169  1.25     rmind 	return copyout(&ss, SCARG(uap, set), sizeof(ss));
    170   1.2        ad }
    171   1.2        ad 
    172   1.2        ad /*
    173   1.2        ad  * Suspend process until signal, providing mask to be set in the meantime.
    174   1.2        ad  * Note nonstandard calling convention: libc stub passes mask, not pointer,
    175   1.2        ad  * to save a copyin.
    176   1.2        ad  */
    177   1.2        ad int
    178  1.25     rmind sys___sigsuspend14(struct lwp *l, const struct sys___sigsuspend14_args *uap,
    179  1.25     rmind     register_t *retval)
    180   1.2        ad {
    181   1.9       dsl 	/* {
    182   1.2        ad 		syscallarg(const sigset_t *)	set;
    183   1.9       dsl 	} */
    184   1.2        ad 	sigset_t	ss;
    185   1.2        ad 	int		error;
    186   1.2        ad 
    187   1.2        ad 	if (SCARG(uap, set)) {
    188   1.2        ad 		error = copyin(SCARG(uap, set), &ss, sizeof(ss));
    189   1.2        ad 		if (error)
    190  1.25     rmind 			return error;
    191   1.2        ad 	}
    192  1.25     rmind 	return sigsuspend1(l, SCARG(uap, set) ? &ss : 0);
    193   1.2        ad }
    194   1.2        ad 
    195   1.2        ad int
    196  1.25     rmind sys___sigaltstack14(struct lwp *l, const struct sys___sigaltstack14_args *uap,
    197  1.25     rmind     register_t *retval)
    198   1.2        ad {
    199   1.9       dsl 	/* {
    200   1.2        ad 		syscallarg(const struct sigaltstack *)	nss;
    201   1.2        ad 		syscallarg(struct sigaltstack *)	oss;
    202   1.9       dsl 	} */
    203  1.54   thorpej 	stack_t	nss, oss;
    204  1.54   thorpej 	int	error;
    205   1.2        ad 
    206   1.2        ad 	if (SCARG(uap, nss)) {
    207   1.2        ad 		error = copyin(SCARG(uap, nss), &nss, sizeof(nss));
    208   1.2        ad 		if (error)
    209  1.25     rmind 			return error;
    210   1.2        ad 	}
    211   1.2        ad 	error = sigaltstack1(l,
    212   1.2        ad 	    SCARG(uap, nss) ? &nss : 0, SCARG(uap, oss) ? &oss : 0);
    213   1.2        ad 	if (error)
    214  1.25     rmind 		return error;
    215   1.2        ad 	if (SCARG(uap, oss)) {
    216   1.2        ad 		error = copyout(&oss, SCARG(uap, oss), sizeof(oss));
    217   1.2        ad 		if (error)
    218  1.25     rmind 			return error;
    219   1.2        ad 	}
    220  1.25     rmind 	return 0;
    221   1.2        ad }
    222   1.2        ad 
    223  1.44    martin int
    224  1.30  christos kill1(struct lwp *l, pid_t pid, ksiginfo_t *ksi, register_t *retval)
    225   1.2        ad {
    226   1.2        ad 	int error;
    227  1.30  christos 	struct proc *p;
    228   1.2        ad 
    229  1.30  christos 	if ((u_int)ksi->ksi_signo >= NSIG)
    230  1.25     rmind 		return EINVAL;
    231  1.30  christos 
    232  1.32    martin 	if (pid != l->l_proc->p_pid) {
    233  1.32    martin 		if (ksi->ksi_pid != l->l_proc->p_pid)
    234  1.32    martin 			return EPERM;
    235  1.32    martin 
    236  1.32    martin 		if (ksi->ksi_uid != kauth_cred_geteuid(l->l_cred))
    237  1.32    martin 			return EPERM;
    238  1.32    martin 
    239  1.32    martin 		switch (ksi->ksi_code) {
    240  1.32    martin 		case SI_USER:
    241  1.32    martin 		case SI_QUEUE:
    242  1.32    martin 			break;
    243  1.32    martin 		default:
    244  1.32    martin 			return EPERM;
    245  1.32    martin 		}
    246  1.32    martin 	}
    247  1.30  christos 
    248  1.30  christos 	if (pid > 0) {
    249   1.2        ad 		/* kill single process */
    250  1.51        ad 		mutex_enter(&proc_lock);
    251  1.38  christos 		p = proc_find_raw(pid);
    252  1.38  christos 		if (p == NULL || (p->p_stat != SACTIVE && p->p_stat != SSTOP)) {
    253  1.51        ad 			mutex_exit(&proc_lock);
    254  1.38  christos 			/* IEEE Std 1003.1-2001: return success for zombies */
    255  1.38  christos 			return p ? 0 : ESRCH;
    256  1.13        ad 		}
    257  1.14        ad 		mutex_enter(p->p_lock);
    258   1.2        ad 		error = kauth_authorize_process(l->l_cred,
    259  1.30  christos 		    KAUTH_PROCESS_SIGNAL, p, KAUTH_ARG(ksi->ksi_signo),
    260   1.2        ad 		    NULL, NULL);
    261  1.30  christos 		if (!error && ksi->ksi_signo) {
    262  1.46  christos 			error = kpsignal2(p, ksi);
    263   1.2        ad 		}
    264  1.14        ad 		mutex_exit(p->p_lock);
    265  1.51        ad 		mutex_exit(&proc_lock);
    266  1.25     rmind 		return error;
    267   1.2        ad 	}
    268  1.30  christos 
    269  1.30  christos 	switch (pid) {
    270   1.2        ad 	case -1:		/* broadcast signal */
    271  1.30  christos 		return killpg1(l, ksi, 0, 1);
    272   1.2        ad 	case 0:			/* signal own process group */
    273  1.30  christos 		return killpg1(l, ksi, 0, 0);
    274   1.2        ad 	default:		/* negative explicit process group */
    275  1.30  christos 		return killpg1(l, ksi, -pid, 0);
    276   1.2        ad 	}
    277   1.2        ad 	/* NOTREACHED */
    278   1.2        ad }
    279   1.2        ad 
    280   1.2        ad int
    281  1.30  christos sys_sigqueueinfo(struct lwp *l, const struct sys_sigqueueinfo_args *uap,
    282  1.30  christos     register_t *retval)
    283  1.30  christos {
    284  1.30  christos 	/* {
    285  1.30  christos 		syscallarg(pid_t int)	pid;
    286  1.30  christos 		syscallarg(const siginfo_t *)	info;
    287  1.30  christos 	} */
    288  1.30  christos 	ksiginfo_t	ksi;
    289  1.30  christos 	int error;
    290  1.30  christos 
    291  1.30  christos 	KSI_INIT(&ksi);
    292  1.30  christos 
    293  1.30  christos 	if ((error = copyin(&SCARG(uap, info)->_info, &ksi.ksi_info,
    294  1.30  christos 	    sizeof(ksi.ksi_info))) != 0)
    295  1.30  christos 		return error;
    296  1.30  christos 
    297  1.30  christos 	return kill1(l, SCARG(uap, pid), &ksi, retval);
    298  1.30  christos }
    299  1.30  christos 
    300  1.30  christos int
    301  1.30  christos sys_kill(struct lwp *l, const struct sys_kill_args *uap, register_t *retval)
    302  1.30  christos {
    303  1.30  christos 	/* {
    304  1.30  christos 		syscallarg(pid_t)	pid;
    305  1.30  christos 		syscallarg(int)	signum;
    306  1.30  christos 	} */
    307  1.30  christos 	ksiginfo_t	ksi;
    308  1.30  christos 
    309  1.30  christos 	KSI_INIT(&ksi);
    310  1.30  christos 
    311  1.30  christos 	ksi.ksi_signo = SCARG(uap, signum);
    312  1.30  christos 	ksi.ksi_code = SI_USER;
    313  1.30  christos 	ksi.ksi_pid = l->l_proc->p_pid;
    314  1.30  christos 	ksi.ksi_uid = kauth_cred_geteuid(l->l_cred);
    315  1.30  christos 
    316  1.30  christos 	return kill1(l, SCARG(uap, pid), &ksi, retval);
    317  1.30  christos }
    318  1.30  christos 
    319  1.30  christos int
    320  1.25     rmind sys_getcontext(struct lwp *l, const struct sys_getcontext_args *uap,
    321  1.25     rmind     register_t *retval)
    322   1.2        ad {
    323   1.9       dsl 	/* {
    324   1.2        ad 		syscallarg(struct __ucontext *) ucp;
    325   1.9       dsl 	} */
    326   1.2        ad 	struct proc *p = l->l_proc;
    327   1.2        ad 	ucontext_t uc;
    328   1.2        ad 
    329  1.31     joerg 	memset(&uc, 0, sizeof(uc));
    330  1.31     joerg 
    331  1.14        ad 	mutex_enter(p->p_lock);
    332   1.2        ad 	getucontext(l, &uc);
    333  1.14        ad 	mutex_exit(p->p_lock);
    334   1.2        ad 
    335  1.25     rmind 	return copyout(&uc, SCARG(uap, ucp), sizeof (*SCARG(uap, ucp)));
    336   1.2        ad }
    337   1.2        ad 
    338   1.2        ad int
    339  1.25     rmind sys_setcontext(struct lwp *l, const struct sys_setcontext_args *uap,
    340  1.25     rmind     register_t *retval)
    341   1.2        ad {
    342   1.9       dsl 	/* {
    343   1.2        ad 		syscallarg(const ucontext_t *) ucp;
    344   1.9       dsl 	} */
    345   1.2        ad 	struct proc *p = l->l_proc;
    346   1.2        ad 	ucontext_t uc;
    347   1.2        ad 	int error;
    348   1.2        ad 
    349   1.2        ad 	error = copyin(SCARG(uap, ucp), &uc, sizeof (uc));
    350   1.2        ad 	if (error)
    351  1.25     rmind 		return error;
    352  1.25     rmind 	if ((uc.uc_flags & _UC_CPU) == 0)
    353  1.25     rmind 		return EINVAL;
    354  1.14        ad 	mutex_enter(p->p_lock);
    355   1.2        ad 	error = setucontext(l, &uc);
    356  1.14        ad 	mutex_exit(p->p_lock);
    357   1.2        ad 	if (error)
    358  1.25     rmind  		return error;
    359   1.2        ad 
    360  1.25     rmind 	return EJUSTRETURN;
    361   1.2        ad }
    362   1.2        ad 
    363   1.2        ad /*
    364   1.2        ad  * sigtimedwait(2) system call, used also for implementation
    365   1.2        ad  * of sigwaitinfo() and sigwait().
    366   1.2        ad  *
    367   1.2        ad  * This only handles single LWP in signal wait. libpthread provides
    368  1.43       snj  * its own sigtimedwait() wrapper to DTRT WRT individual threads.
    369   1.2        ad  */
    370   1.2        ad int
    371  1.21  christos sys_____sigtimedwait50(struct lwp *l,
    372  1.21  christos     const struct sys_____sigtimedwait50_args *uap, register_t *retval)
    373   1.2        ad {
    374   1.2        ad 
    375  1.36  christos 	return sigtimedwait1(l, uap, retval, copyin, copyout, copyin, copyout);
    376   1.2        ad }
    377   1.2        ad 
    378   1.2        ad int
    379   1.2        ad sigaction1(struct lwp *l, int signum, const struct sigaction *nsa,
    380   1.2        ad 	struct sigaction *osa, const void *tramp, int vers)
    381   1.2        ad {
    382   1.2        ad 	struct proc *p;
    383   1.2        ad 	struct sigacts *ps;
    384   1.2        ad 	sigset_t tset;
    385   1.2        ad 	int prop, error;
    386   1.2        ad 	ksiginfoq_t kq;
    387  1.20        ad 	static bool v0v1valid;
    388   1.2        ad 
    389   1.2        ad 	if (signum <= 0 || signum >= NSIG)
    390  1.25     rmind 		return EINVAL;
    391   1.2        ad 
    392   1.2        ad 	p = l->l_proc;
    393   1.2        ad 	error = 0;
    394   1.2        ad 	ksiginfo_queue_init(&kq);
    395   1.2        ad 
    396   1.2        ad 	/*
    397  1.53   thorpej 	 * Trampoline ABI version __SIGTRAMP_SIGCODE_VERSION (0) is reserved
    398  1.53   thorpej 	 * for the legacy kernel provided on-stack trampoline.  Conversely,
    399  1.53   thorpej 	 * if we are using a non-0 ABI version, we must have a trampoline.
    400  1.53   thorpej 	 * Only validate the vers if a new sigaction was supplied and there
    401  1.53   thorpej 	 * was an actual handler specified (not SIG_IGN or SIG_DFL), which
    402  1.53   thorpej 	 * don't require a trampoline. Emulations use legacy kernel
    403  1.53   thorpej 	 * trampolines with version 0, alternatively check for that too.
    404  1.19        ad 	 *
    405  1.53   thorpej 	 * If version < __SIGTRAMP_SIGINFO_VERSION_MIN (usually 2), we try
    406  1.53   thorpej 	 * to autoload the compat module.  Note that we interlock with the
    407  1.53   thorpej 	 * unload check in compat_modcmd() using kernconfig_lock.  If the
    408  1.53   thorpej 	 * autoload fails, we don't try it again for this process.
    409  1.19        ad 	 */
    410  1.42  christos 	if (nsa != NULL && nsa->sa_handler != SIG_IGN
    411  1.42  christos 	    && nsa->sa_handler != SIG_DFL) {
    412  1.53   thorpej 		if (__predict_false(vers < __SIGTRAMP_SIGINFO_VERSION_MIN)) {
    413  1.53   thorpej 			if (vers == __SIGTRAMP_SIGCODE_VERSION &&
    414  1.52       ryo 			    p->p_sigctx.ps_sigcode != NULL) {
    415  1.52       ryo 				/*
    416  1.52       ryo 				 * if sigcode is used for this emulation,
    417  1.52       ryo 				 * version 0 is allowed.
    418  1.52       ryo 				 */
    419  1.53   thorpej 			}
    420  1.53   thorpej #ifdef __HAVE_STRUCT_SIGCONTEXT
    421  1.53   thorpej 			else if (p->p_flag & PK_32) {
    422  1.55   thorpej 				/*
    423  1.55   thorpej 				 * The 32-bit compat module will have
    424  1.55   thorpej 				 * pre-validated this for us.
    425  1.55   thorpej 				 */
    426  1.53   thorpej 				v0v1valid = true;
    427  1.52       ryo 			} else if ((p->p_lflag & PL_SIGCOMPAT) == 0) {
    428  1.39  christos 				kernconfig_lock();
    429  1.50  pgoyette 				(void)module_autoload("compat_16",
    430  1.50  pgoyette 				    MODULE_CLASS_ANY);
    431  1.50  pgoyette 				if (sendsig_sigcontext_16_hook.hooked) {
    432  1.39  christos 					/*
    433  1.39  christos 					 * We need to remember if the
    434  1.39  christos 					 * sigcontext method may be useable,
    435  1.39  christos 					 * because libc may use it even
    436  1.39  christos 					 * if siginfo is available.
    437  1.39  christos 					 */
    438  1.39  christos 					v0v1valid = true;
    439  1.39  christos 				}
    440  1.51        ad 				mutex_enter(&proc_lock);
    441  1.20        ad 				/*
    442  1.39  christos 				 * Prevent unload of compat module while
    443  1.39  christos 				 * this process remains.
    444  1.20        ad 				 */
    445  1.39  christos 				p->p_lflag |= PL_SIGCOMPAT;
    446  1.51        ad 				mutex_exit(&proc_lock);
    447  1.39  christos 				kernconfig_unlock();
    448  1.20        ad 			}
    449  1.53   thorpej #endif /* __HAVE_STRUCT_SIGCONTEXT */
    450  1.19        ad 		}
    451  1.19        ad 
    452  1.20        ad 		switch (vers) {
    453  1.53   thorpej 		case __SIGTRAMP_SIGCODE_VERSION:
    454  1.53   thorpej 			/* kernel supplied trampoline. */
    455  1.52       ryo 			if (tramp != NULL ||
    456  1.52       ryo 			    (p->p_sigctx.ps_sigcode == NULL && !v0v1valid)) {
    457  1.20        ad 				return EINVAL;
    458  1.20        ad 			}
    459  1.20        ad 			break;
    460  1.53   thorpej #ifdef __HAVE_STRUCT_SIGCONTEXT
    461  1.53   thorpej 		case __SIGTRAMP_SIGCONTEXT_VERSION_MIN ...
    462  1.53   thorpej 		     __SIGTRAMP_SIGCONTEXT_VERSION_MAX:
    463  1.20        ad 			/* sigcontext, user supplied trampoline. */
    464  1.20        ad 			if (tramp == NULL || !v0v1valid) {
    465  1.20        ad 				return EINVAL;
    466  1.20        ad 			}
    467  1.20        ad 			break;
    468  1.53   thorpej #endif /* __HAVE_STRUCT_SIGCONTEXT */
    469  1.53   thorpej 		case __SIGTRAMP_SIGINFO_VERSION_MIN ...
    470  1.53   thorpej 		     __SIGTRAMP_SIGINFO_VERSION_MAX:
    471  1.20        ad 			/* siginfo, user supplied trampoline. */
    472  1.20        ad 			if (tramp == NULL) {
    473  1.20        ad 				return EINVAL;
    474  1.20        ad 			}
    475  1.20        ad 			break;
    476  1.20        ad 		default:
    477  1.53   thorpej 			/* Invalid trampoline version. */
    478  1.20        ad 			return EINVAL;
    479  1.20        ad 		}
    480   1.2        ad 	}
    481   1.2        ad 
    482  1.14        ad 	mutex_enter(p->p_lock);
    483   1.2        ad 
    484   1.2        ad 	ps = p->p_sigacts;
    485   1.2        ad 	if (osa)
    486  1.48      maxv 		sigaction_copy(osa, &SIGACTION_PS(ps, signum));
    487   1.2        ad 	if (!nsa)
    488   1.2        ad 		goto out;
    489   1.2        ad 
    490   1.2        ad 	prop = sigprop[signum];
    491   1.2        ad 	if ((nsa->sa_flags & ~SA_ALLBITS) || (prop & SA_CANTMASK)) {
    492   1.2        ad 		error = EINVAL;
    493   1.2        ad 		goto out;
    494   1.2        ad 	}
    495   1.2        ad 
    496  1.48      maxv 	sigaction_copy(&SIGACTION_PS(ps, signum), nsa);
    497   1.2        ad 	ps->sa_sigdesc[signum].sd_tramp = tramp;
    498   1.2        ad 	ps->sa_sigdesc[signum].sd_vers = vers;
    499   1.2        ad 	sigminusset(&sigcantmask, &SIGACTION_PS(ps, signum).sa_mask);
    500   1.2        ad 
    501   1.2        ad 	if ((prop & SA_NORESET) != 0)
    502   1.2        ad 		SIGACTION_PS(ps, signum).sa_flags &= ~SA_RESETHAND;
    503   1.2        ad 
    504   1.2        ad 	if (signum == SIGCHLD) {
    505   1.2        ad 		if (nsa->sa_flags & SA_NOCLDSTOP)
    506   1.2        ad 			p->p_sflag |= PS_NOCLDSTOP;
    507   1.2        ad 		else
    508   1.2        ad 			p->p_sflag &= ~PS_NOCLDSTOP;
    509   1.2        ad 		if (nsa->sa_flags & SA_NOCLDWAIT) {
    510   1.2        ad 			/*
    511   1.2        ad 			 * Paranoia: since SA_NOCLDWAIT is implemented by
    512   1.2        ad 			 * reparenting the dying child to PID 1 (and trust
    513   1.2        ad 			 * it to reap the zombie), PID 1 itself is forbidden
    514   1.2        ad 			 * to set SA_NOCLDWAIT.
    515   1.2        ad 			 */
    516   1.2        ad 			if (p->p_pid == 1)
    517   1.4     pavel 				p->p_flag &= ~PK_NOCLDWAIT;
    518   1.2        ad 			else
    519   1.4     pavel 				p->p_flag |= PK_NOCLDWAIT;
    520   1.2        ad 		} else
    521   1.4     pavel 			p->p_flag &= ~PK_NOCLDWAIT;
    522   1.2        ad 
    523   1.2        ad 		if (nsa->sa_handler == SIG_IGN) {
    524   1.2        ad 			/*
    525   1.2        ad 			 * Paranoia: same as above.
    526   1.2        ad 			 */
    527   1.2        ad 			if (p->p_pid == 1)
    528   1.4     pavel 				p->p_flag &= ~PK_CLDSIGIGN;
    529   1.2        ad 			else
    530   1.4     pavel 				p->p_flag |= PK_CLDSIGIGN;
    531   1.2        ad 		} else
    532   1.4     pavel 			p->p_flag &= ~PK_CLDSIGIGN;
    533   1.2        ad 	}
    534   1.2        ad 
    535   1.2        ad 	if ((nsa->sa_flags & SA_NODEFER) == 0)
    536   1.2        ad 		sigaddset(&SIGACTION_PS(ps, signum).sa_mask, signum);
    537   1.2        ad 	else
    538   1.2        ad 		sigdelset(&SIGACTION_PS(ps, signum).sa_mask, signum);
    539   1.2        ad 
    540   1.2        ad 	/*
    541   1.2        ad 	 * Set bit in p_sigctx.ps_sigignore for signals that are set to
    542   1.2        ad 	 * SIG_IGN, and for signals set to SIG_DFL where the default is to
    543   1.2        ad 	 * ignore. However, don't put SIGCONT in p_sigctx.ps_sigignore, as
    544   1.2        ad 	 * we have to restart the process.
    545   1.2        ad 	 */
    546   1.2        ad 	if (nsa->sa_handler == SIG_IGN ||
    547   1.2        ad 	    (nsa->sa_handler == SIG_DFL && (prop & SA_IGNORE) != 0)) {
    548   1.2        ad 		/* Never to be seen again. */
    549   1.2        ad 		sigemptyset(&tset);
    550   1.2        ad 		sigaddset(&tset, signum);
    551   1.2        ad 		sigclearall(p, &tset, &kq);
    552   1.2        ad 		if (signum != SIGCONT) {
    553   1.2        ad 			/* Easier in psignal */
    554   1.2        ad 			sigaddset(&p->p_sigctx.ps_sigignore, signum);
    555   1.2        ad 		}
    556   1.2        ad 		sigdelset(&p->p_sigctx.ps_sigcatch, signum);
    557   1.2        ad 	} else {
    558   1.2        ad 		sigdelset(&p->p_sigctx.ps_sigignore, signum);
    559   1.2        ad 		if (nsa->sa_handler == SIG_DFL)
    560   1.2        ad 			sigdelset(&p->p_sigctx.ps_sigcatch, signum);
    561   1.2        ad 		else
    562   1.2        ad 			sigaddset(&p->p_sigctx.ps_sigcatch, signum);
    563   1.2        ad 	}
    564   1.2        ad 
    565   1.2        ad 	/*
    566   1.2        ad 	 * Previously held signals may now have become visible.  Ensure that
    567   1.2        ad 	 * we check for them before returning to userspace.
    568   1.2        ad 	 */
    569   1.6        ad 	if (sigispending(l, 0)) {
    570   1.6        ad 		lwp_lock(l);
    571   1.6        ad 		l->l_flag |= LW_PENDSIG;
    572  1.57        ad 		lwp_need_userret(l);
    573   1.6        ad 		lwp_unlock(l);
    574   1.6        ad 	}
    575  1.25     rmind out:
    576  1.14        ad 	mutex_exit(p->p_lock);
    577   1.2        ad 	ksiginfo_queue_drain(&kq);
    578   1.2        ad 
    579  1.25     rmind 	return error;
    580   1.2        ad }
    581   1.2        ad 
    582   1.2        ad int
    583   1.2        ad sigprocmask1(struct lwp *l, int how, const sigset_t *nss, sigset_t *oss)
    584   1.2        ad {
    585  1.37     rmind 	sigset_t *mask = &l->l_sigmask;
    586  1.37     rmind 	bool more;
    587   1.2        ad 
    588  1.37     rmind 	KASSERT(mutex_owned(l->l_proc->p_lock));
    589   1.2        ad 
    590  1.37     rmind 	if (oss) {
    591  1.17  wrstuden 		*oss = *mask;
    592   1.2        ad 	}
    593   1.2        ad 
    594  1.37     rmind 	if (nss == NULL) {
    595  1.37     rmind 		return 0;
    596  1.37     rmind 	}
    597  1.37     rmind 
    598  1.37     rmind 	switch (how) {
    599  1.37     rmind 	case SIG_BLOCK:
    600  1.37     rmind 		sigplusset(nss, mask);
    601  1.37     rmind 		more = false;
    602  1.37     rmind 		break;
    603  1.37     rmind 	case SIG_UNBLOCK:
    604  1.37     rmind 		sigminusset(nss, mask);
    605  1.37     rmind 		more = true;
    606  1.37     rmind 		break;
    607  1.37     rmind 	case SIG_SETMASK:
    608  1.37     rmind 		*mask = *nss;
    609  1.37     rmind 		more = true;
    610  1.37     rmind 		break;
    611  1.37     rmind 	default:
    612  1.37     rmind 		return EINVAL;
    613  1.37     rmind 	}
    614  1.37     rmind 	sigminusset(&sigcantmask, mask);
    615  1.37     rmind 	if (more && sigispending(l, 0)) {
    616  1.37     rmind 		/*
    617  1.37     rmind 		 * Check for pending signals on return to user.
    618  1.37     rmind 		 */
    619  1.37     rmind 		lwp_lock(l);
    620  1.37     rmind 		l->l_flag |= LW_PENDSIG;
    621  1.57        ad 		lwp_need_userret(l);
    622  1.37     rmind 		lwp_unlock(l);
    623  1.37     rmind 	}
    624  1.25     rmind 	return 0;
    625   1.2        ad }
    626   1.2        ad 
    627   1.2        ad void
    628   1.2        ad sigpending1(struct lwp *l, sigset_t *ss)
    629   1.2        ad {
    630   1.2        ad 	struct proc *p = l->l_proc;
    631   1.2        ad 
    632  1.14        ad 	mutex_enter(p->p_lock);
    633   1.2        ad 	*ss = l->l_sigpend.sp_set;
    634   1.2        ad 	sigplusset(&p->p_sigpend.sp_set, ss);
    635  1.14        ad 	mutex_exit(p->p_lock);
    636   1.2        ad }
    637   1.2        ad 
    638  1.33  christos void
    639  1.33  christos sigsuspendsetup(struct lwp *l, const sigset_t *ss)
    640   1.2        ad {
    641  1.25     rmind 	struct proc *p = l->l_proc;
    642   1.2        ad 
    643  1.33  christos 	/*
    644  1.33  christos 	 * When returning from sigsuspend/pselect/pollts, we want
    645  1.33  christos 	 * the old mask to be restored after the
    646  1.33  christos 	 * signal handler has finished.  Thus, we
    647  1.33  christos 	 * save it here and mark the sigctx structure
    648  1.33  christos 	 * to indicate this.
    649  1.33  christos 	 */
    650  1.33  christos 	mutex_enter(p->p_lock);
    651  1.33  christos 	l->l_sigrestore = 1;
    652  1.33  christos 	l->l_sigoldmask = l->l_sigmask;
    653  1.33  christos 	l->l_sigmask = *ss;
    654  1.33  christos 	sigminusset(&sigcantmask, &l->l_sigmask);
    655   1.2        ad 
    656  1.33  christos 	/* Check for pending signals when sleeping. */
    657  1.33  christos 	if (sigispending(l, 0)) {
    658  1.33  christos 		lwp_lock(l);
    659  1.33  christos 		l->l_flag |= LW_PENDSIG;
    660  1.57        ad 		lwp_need_userret(l);
    661  1.33  christos 		lwp_unlock(l);
    662   1.2        ad 	}
    663  1.33  christos 	mutex_exit(p->p_lock);
    664  1.33  christos }
    665  1.33  christos 
    666  1.34  christos void
    667  1.34  christos sigsuspendteardown(struct lwp *l)
    668  1.34  christos {
    669  1.34  christos 	struct proc *p = l->l_proc;
    670  1.34  christos 
    671  1.34  christos 	mutex_enter(p->p_lock);
    672  1.35  christos 	/* Check for pending signals when sleeping. */
    673  1.34  christos 	if (l->l_sigrestore) {
    674  1.35  christos 		if (sigispending(l, 0)) {
    675  1.35  christos 			lwp_lock(l);
    676  1.35  christos 			l->l_flag |= LW_PENDSIG;
    677  1.57        ad 			lwp_need_userret(l);
    678  1.35  christos 			lwp_unlock(l);
    679  1.35  christos 		} else {
    680  1.35  christos 			l->l_sigrestore = 0;
    681  1.35  christos 			l->l_sigmask = l->l_sigoldmask;
    682  1.35  christos 		}
    683  1.34  christos 	}
    684  1.34  christos 	mutex_exit(p->p_lock);
    685  1.34  christos }
    686  1.34  christos 
    687  1.33  christos int
    688  1.33  christos sigsuspend1(struct lwp *l, const sigset_t *ss)
    689  1.33  christos {
    690  1.33  christos 
    691  1.33  christos 	if (ss)
    692  1.33  christos 		sigsuspendsetup(l, ss);
    693   1.2        ad 
    694   1.5   thorpej 	while (kpause("pause", true, 0, NULL) == 0)
    695   1.2        ad 		;
    696   1.2        ad 
    697   1.2        ad 	/* always return EINTR rather than ERESTART... */
    698  1.25     rmind 	return EINTR;
    699   1.2        ad }
    700   1.2        ad 
    701   1.2        ad int
    702  1.54   thorpej sigaltstack1(struct lwp *l, const stack_t *nss, stack_t *oss)
    703   1.2        ad {
    704   1.2        ad 	struct proc *p = l->l_proc;
    705   1.2        ad 	int error = 0;
    706   1.2        ad 
    707  1.14        ad 	mutex_enter(p->p_lock);
    708   1.2        ad 
    709   1.2        ad 	if (oss)
    710   1.2        ad 		*oss = l->l_sigstk;
    711   1.2        ad 
    712   1.2        ad 	if (nss) {
    713   1.2        ad 		if (nss->ss_flags & ~SS_ALLBITS)
    714   1.2        ad 			error = EINVAL;
    715   1.2        ad 		else if (nss->ss_flags & SS_DISABLE) {
    716   1.2        ad 			if (l->l_sigstk.ss_flags & SS_ONSTACK)
    717   1.2        ad 				error = EINVAL;
    718   1.2        ad 		} else if (nss->ss_size < MINSIGSTKSZ)
    719   1.2        ad 			error = ENOMEM;
    720   1.2        ad 
    721   1.2        ad 		if (!error)
    722   1.2        ad 			l->l_sigstk = *nss;
    723   1.2        ad 	}
    724   1.2        ad 
    725  1.14        ad 	mutex_exit(p->p_lock);
    726   1.2        ad 
    727  1.25     rmind 	return error;
    728   1.2        ad }
    729   1.2        ad 
    730   1.2        ad int
    731  1.26     pooka sigtimedwait1(struct lwp *l, const struct sys_____sigtimedwait50_args *uap,
    732  1.36  christos     register_t *retval, copyin_t fetchss, copyout_t storeinf, copyin_t fetchts,
    733  1.36  christos     copyout_t storets)
    734   1.2        ad {
    735   1.9       dsl 	/* {
    736   1.2        ad 		syscallarg(const sigset_t *) set;
    737   1.2        ad 		syscallarg(siginfo_t *) info;
    738   1.2        ad 		syscallarg(struct timespec *) timeout;
    739   1.9       dsl 	} */
    740   1.2        ad 	struct proc *p = l->l_proc;
    741  1.25     rmind 	int error, signum, timo;
    742   1.2        ad 	struct timespec ts, tsstart, tsnow;
    743  1.24     rmind 	ksiginfo_t ksi;
    744   1.2        ad 
    745   1.2        ad 	/*
    746   1.2        ad 	 * Calculate timeout, if it was specified.
    747  1.40       apb 	 *
    748  1.40       apb 	 * NULL pointer means an infinite timeout.
    749  1.40       apb 	 * {.tv_sec = 0, .tv_nsec = 0} means do not block.
    750   1.2        ad 	 */
    751   1.2        ad 	if (SCARG(uap, timeout)) {
    752  1.25     rmind 		error = (*fetchts)(SCARG(uap, timeout), &ts, sizeof(ts));
    753  1.23  christos 		if (error)
    754  1.23  christos 			return error;
    755   1.2        ad 
    756  1.23  christos 		if ((error = itimespecfix(&ts)) != 0)
    757  1.23  christos 			return error;
    758   1.2        ad 
    759  1.23  christos 		timo = tstohz(&ts);
    760  1.41       apb 		if (timo == 0) {
    761  1.41       apb 			if (ts.tv_sec == 0 && ts.tv_nsec == 0)
    762  1.41       apb 				timo = -1; /* do not block */
    763  1.41       apb 			else
    764  1.41       apb 				timo = 1; /* the shortest possible timeout */
    765  1.41       apb 		}
    766   1.2        ad 
    767   1.2        ad 		/*
    768   1.2        ad 		 * Remember current uptime, it would be used in
    769   1.2        ad 		 * ECANCELED/ERESTART case.
    770   1.2        ad 		 */
    771   1.2        ad 		getnanouptime(&tsstart);
    772  1.25     rmind 	} else {
    773  1.25     rmind 		memset(&tsstart, 0, sizeof(tsstart)); /* XXXgcc */
    774  1.41       apb 		timo = 0; /* infinite timeout */
    775   1.2        ad 	}
    776   1.2        ad 
    777  1.36  christos 	error = (*fetchss)(SCARG(uap, set), &l->l_sigwaitset,
    778   1.2        ad 	    sizeof(l->l_sigwaitset));
    779  1.25     rmind 	if (error)
    780  1.25     rmind 		return error;
    781   1.2        ad 
    782   1.2        ad 	/*
    783   1.2        ad 	 * Silently ignore SA_CANTMASK signals. psignal1() would ignore
    784   1.2        ad 	 * SA_CANTMASK signals in waitset, we do this only for the below
    785   1.2        ad 	 * siglist check.
    786   1.2        ad 	 */
    787   1.2        ad 	sigminusset(&sigcantmask, &l->l_sigwaitset);
    788   1.2        ad 
    789  1.47      maxv 	memset(&ksi.ksi_info, 0, sizeof(ksi.ksi_info));
    790  1.47      maxv 
    791  1.14        ad 	mutex_enter(p->p_lock);
    792   1.2        ad 
    793  1.25     rmind 	/* Check for pending signals in the process, if no - then in LWP. */
    794  1.24     rmind 	if ((signum = sigget(&p->p_sigpend, &ksi, 0, &l->l_sigwaitset)) == 0)
    795  1.24     rmind 		signum = sigget(&l->l_sigpend, &ksi, 0, &l->l_sigwaitset);
    796   1.2        ad 
    797   1.2        ad 	if (signum != 0) {
    798  1.25     rmind 		/* If found a pending signal, just copy it out to the user. */
    799  1.14        ad 		mutex_exit(p->p_lock);
    800   1.2        ad 		goto out;
    801   1.2        ad 	}
    802   1.2        ad 
    803  1.41       apb 	if (timo < 0) {
    804  1.41       apb 		/* If not allowed to block, return an error */
    805  1.41       apb 		mutex_exit(p->p_lock);
    806  1.41       apb 		return EAGAIN;
    807  1.41       apb 	}
    808  1.41       apb 
    809   1.2        ad 	/*
    810  1.25     rmind 	 * Set up the sigwait list and wait for signal to arrive.
    811  1.25     rmind 	 * We can either be woken up or time out.
    812   1.2        ad 	 */
    813  1.24     rmind 	l->l_sigwaited = &ksi;
    814   1.2        ad 	LIST_INSERT_HEAD(&p->p_sigwaiters, l, l_sigwaiter);
    815  1.14        ad 	error = cv_timedwait_sig(&l->l_sigcv, p->p_lock, timo);
    816   1.2        ad 
    817   1.2        ad 	/*
    818  1.25     rmind 	 * Need to find out if we woke as a result of _lwp_wakeup() or a
    819   1.2        ad 	 * signal outside our wait set.
    820   1.2        ad 	 */
    821   1.2        ad 	if (l->l_sigwaited != NULL) {
    822   1.2        ad 		if (error == EINTR) {
    823  1.25     rmind 			/* Wakeup via _lwp_wakeup(). */
    824   1.2        ad 			error = ECANCELED;
    825   1.2        ad 		} else if (!error) {
    826  1.25     rmind 			/* Spurious wakeup - arrange for syscall restart. */
    827   1.2        ad 			error = ERESTART;
    828   1.2        ad 		}
    829   1.2        ad 		l->l_sigwaited = NULL;
    830   1.2        ad 		LIST_REMOVE(l, l_sigwaiter);
    831   1.2        ad 	}
    832  1.14        ad 	mutex_exit(p->p_lock);
    833   1.2        ad 
    834   1.2        ad 	/*
    835   1.2        ad 	 * If the sleep was interrupted (either by signal or wakeup), update
    836   1.2        ad 	 * the timeout and copyout new value back.  It would be used when
    837   1.2        ad 	 * the syscall would be restarted or called again.
    838   1.2        ad 	 */
    839   1.2        ad 	if (timo && (error == ERESTART || error == ECANCELED)) {
    840   1.2        ad 		getnanouptime(&tsnow);
    841   1.2        ad 
    842  1.25     rmind 		/* Compute how much time has passed since start. */
    843   1.2        ad 		timespecsub(&tsnow, &tsstart, &tsnow);
    844  1.25     rmind 
    845  1.56    andvar 		/* Subtract passed time from timeout. */
    846   1.2        ad 		timespecsub(&ts, &tsnow, &ts);
    847   1.2        ad 
    848   1.2        ad 		if (ts.tv_sec < 0)
    849   1.2        ad 			error = EAGAIN;
    850   1.2        ad 		else {
    851  1.25     rmind 			/* Copy updated timeout to userland. */
    852  1.25     rmind 			error = (*storets)(&ts, SCARG(uap, timeout),
    853   1.2        ad 			    sizeof(ts));
    854   1.2        ad 		}
    855   1.2        ad 	}
    856  1.25     rmind out:
    857   1.2        ad 	/*
    858   1.2        ad 	 * If a signal from the wait set arrived, copy it to userland.
    859   1.2        ad 	 * Copy only the used part of siginfo, the padding part is
    860   1.2        ad 	 * left unchanged (userland is not supposed to touch it anyway).
    861   1.2        ad 	 */
    862  1.27  drochner 	if (error == 0 && SCARG(uap, info)) {
    863  1.25     rmind 		error = (*storeinf)(&ksi.ksi_info, SCARG(uap, info),
    864  1.24     rmind 		    sizeof(ksi.ksi_info));
    865  1.25     rmind 	}
    866  1.45  christos 	if (error == 0) {
    867  1.27  drochner 		*retval = ksi.ksi_info._signo;
    868  1.45  christos 		SDT_PROBE(proc, kernel, , signal__clear, *retval,
    869  1.45  christos 		    &ksi, 0, 0, 0);
    870  1.45  christos 	}
    871   1.2        ad 	return error;
    872   1.2        ad }
    873