Index: lib/libc/sys/sigqueue.2 =================================================================== --- lib/libc/sys/sigqueue.2 +++ lib/libc/sys/sigqueue.2 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 10, 2012 +.Dd May 5, 2017 .Dt SIGQUEUE 2 .Os .Sh NAME @@ -129,7 +129,6 @@ .Xr kill 2 , .Xr sigaction 2 , .Xr sigpending 2 , -.Xr sigqueue 2 , .Xr sigsuspend 2 , .Xr sigtimedwait 2 , .Xr sigwait 2 , @@ -147,3 +146,17 @@ .Tn POSIX realtime signal queue first appeared in .Fx 7.0 . +.Sh CAVEATS +When using +.Nm +to send signals to a process which may have a different ABI +(e.g., one is 32-bit and the other 64-bit) +the +.Va sival_int +member of +.Fa value +can be delivered reliably, but the +.Va sival_ptr +maybe be truncated in endian dependent ways and must not be relied on. +Portable programs should not rely on sending pointers to other processes +as many pointer integrity schemes disallow this. Index: sys/compat/freebsd32/freebsd32_sigqueue.c =================================================================== --- /dev/null +++ sys/compat/freebsd32/freebsd32_sigqueue.c @@ -0,0 +1,102 @@ +/*- + * Copyright (c) 2017 SRI International + * 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. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237 + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94 + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include + +#ifndef _FREEBSD32_SYSPROTO_H_ +struct freebsd32_sigqueue_args { + pid_t pid; + int signum; + /* union sigval32 */ int value; +}; +#endif +int +freebsd32_sigqueue(struct thread *td, struct freebsd32_sigqueue_args *uap) +{ + ksiginfo_t ksi; + struct proc *p; + int error; + + if ((u_int)uap->signum > _SIG_MAXSIG) + return (EINVAL); + + /* + * Specification says sigqueue can only send signal to + * single process. + */ + if (uap->pid <= 0) + return (EINVAL); + + if ((p = pfind(uap->pid)) == NULL) { + if ((p = zpfind(uap->pid)) == NULL) + return (ESRCH); + } + error = p_cansignal(td, p, uap->signum); + if (error == 0 && uap->signum != 0) { + ksiginfo_init(&ksi); + ksi.ksi_flags = KSI_SIGQ; + ksi.ksi_signo = uap->signum; + ksi.ksi_code = SI_QUEUE; + ksi.ksi_pid = td->td_proc->p_pid; + ksi.ksi_uid = td->td_ucred->cr_ruid; + /* + * On 32-bit ABIs, sival_int and sival_ptr are the same. + * On 64-bit little-endian ABIs, the low bits are the same. + * In 64-bit big-endian ABIs, sival_int overlaps with + * sival_ptr's HIGH bits. We choose to support sival_int + * rather than sival_ptr in this case as it seems to be + * more common. + */ + ksi.ksi_value.sival_int = uap->value; + error = pksignal(p, ksi.ksi_signo, &ksi); + } + PROC_UNLOCK(p); + return (error); +} Index: sys/compat/freebsd32/syscalls.master =================================================================== --- sys/compat/freebsd32/syscalls.master +++ sys/compat/freebsd32/syscalls.master @@ -819,8 +819,8 @@ 455 AUE_THR_NEW STD { int freebsd32_thr_new( \ struct thr_param32 *param, \ int param_size); } -456 AUE_NULL NOPROTO { int sigqueue(pid_t pid, int signum, \ - void *value); } +456 AUE_NULL STD { int freebsd32_sigqueue(pid_t pid, \ + int signum, int value); } 457 AUE_MQ_OPEN NOSTD { int freebsd32_kmq_open( \ const char *path, int flags, mode_t mode, \ const struct mq_attr32 *attr); } Index: sys/conf/files =================================================================== --- sys/conf/files +++ sys/conf/files @@ -303,6 +303,7 @@ compat/freebsd32/freebsd32_capability.c optional compat_freebsd32 compat/freebsd32/freebsd32_ioctl.c optional compat_freebsd32 compat/freebsd32/freebsd32_misc.c optional compat_freebsd32 +compat/freebsd32/freebsd32_sigqueue.c optional compat_freebsd32 compat/freebsd32/freebsd32_syscalls.c optional compat_freebsd32 compat/freebsd32/freebsd32_sysent.c optional compat_freebsd32 contrib/ck/src/ck_array.c standard compile-with "${NORMAL_C} -I$S/contrib/ck/include"