Home | History | Annotate | Line # | Download | only in common
linux_signal.c revision 1.49.20.1
      1 /*	$NetBSD: linux_signal.c,v 1.49.20.1 2006/10/24 21:10:22 ad Exp $	*/
      2 /*-
      3  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Frank van der Linden and Eric Haszlakiewicz.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by the NetBSD
     20  *	Foundation, Inc. and its contributors.
     21  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  *    contributors may be used to endorse or promote products derived
     23  *    from this software without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 /*
     38  * heavily from: svr4_signal.c,v 1.7 1995/01/09 01:04:21 christos Exp
     39  */
     40 
     41 /*
     42  *   Functions in multiarch:
     43  *	linux_sys_signal	: linux_sig_notalpha.c
     44  *	linux_sys_siggetmask	: linux_sig_notalpha.c
     45  *	linux_sys_sigsetmask	: linux_sig_notalpha.c
     46  *	linux_sys_pause		: linux_sig_notalpha.c
     47  *	linux_sys_sigaction	: linux_sigaction.c
     48  *
     49  */
     50 
     51 /*
     52  *   Unimplemented:
     53  *	linux_sys_rt_sigtimedwait	: sigsuspend w/timeout.
     54  */
     55 
     56 #include <sys/cdefs.h>
     57 __KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.49.20.1 2006/10/24 21:10:22 ad Exp $");
     58 
     59 #define COMPAT_LINUX 1
     60 
     61 #include <sys/param.h>
     62 #include <sys/systm.h>
     63 #include <sys/namei.h>
     64 #include <sys/proc.h>
     65 #include <sys/filedesc.h>
     66 #include <sys/ioctl.h>
     67 #include <sys/mount.h>
     68 #include <sys/kernel.h>
     69 #include <sys/signal.h>
     70 #include <sys/signalvar.h>
     71 #include <sys/malloc.h>
     72 
     73 #include <sys/sa.h>
     74 #include <sys/syscallargs.h>
     75 
     76 #include <compat/linux/common/linux_types.h>
     77 #include <compat/linux/common/linux_signal.h>
     78 #include <compat/linux/common/linux_exec.h> /* For emul_linux */
     79 #include <compat/linux/common/linux_machdep.h> /* For LINUX_NPTL */
     80 #include <compat/linux/common/linux_emuldata.h> /* for linux_emuldata */
     81 #include <compat/linux/common/linux_siginfo.h>
     82 #include <compat/linux/common/linux_sigevent.h>
     83 #include <compat/linux/common/linux_util.h>
     84 
     85 #include <compat/linux/linux_syscallargs.h>
     86 
     87 /* Locally used defines (in bsd<->linux conversion functions): */
     88 #define	linux_sigemptyset(s)	memset((s), 0, sizeof(*(s)))
     89 #define	linux_sigismember(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     90 					& (1 << ((n) - 1) % LINUX__NSIG_BPW))
     91 #define	linux_sigaddset(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     92 					|= (1 << ((n) - 1) % LINUX__NSIG_BPW))
     93 
     94 #ifdef DEBUG_LINUX
     95 #define DPRINTF(a)	uprintf a
     96 #else
     97 #define DPRINTF(a)
     98 #endif
     99 
    100 extern const int native_to_linux_signo[];
    101 extern const int linux_to_native_signo[];
    102 
    103 /*
    104  * Convert between Linux and BSD signal sets.
    105  */
    106 #if LINUX__NSIG_WORDS > 1
    107 void
    108 linux_old_extra_to_native_sigset(bss, lss, extra)
    109 	sigset_t *bss;
    110 	const linux_old_sigset_t *lss;
    111 	const unsigned long *extra;
    112 {
    113 	linux_sigset_t lsnew;
    114 
    115 	/* convert old sigset to new sigset */
    116 	linux_sigemptyset(&lsnew);
    117 	lsnew.sig[0] = *lss;
    118 	if (extra)
    119 		memcpy(&lsnew.sig[1], extra,
    120 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    121 
    122 	linux_to_native_sigset(bss, &lsnew);
    123 }
    124 
    125 void
    126 native_to_linux_old_extra_sigset(lss, extra, bss)
    127 	linux_old_sigset_t *lss;
    128 	unsigned long *extra;
    129 	const sigset_t *bss;
    130 {
    131 	linux_sigset_t lsnew;
    132 
    133 	native_to_linux_sigset(&lsnew, bss);
    134 
    135 	/* convert new sigset to old sigset */
    136 	*lss = lsnew.sig[0];
    137 	if (extra)
    138 		memcpy(extra, &lsnew.sig[1],
    139 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    140 }
    141 #endif /* LINUX__NSIG_WORDS > 1 */
    142 
    143 void
    144 linux_to_native_sigset(bss, lss)
    145 	sigset_t *bss;
    146 	const linux_sigset_t *lss;
    147 {
    148 	int i, newsig;
    149 
    150 	sigemptyset(bss);
    151 	for (i = 1; i < LINUX__NSIG; i++) {
    152 		if (linux_sigismember(lss, i)) {
    153 			newsig = linux_to_native_signo[i];
    154 			if (newsig)
    155 				sigaddset(bss, newsig);
    156 		}
    157 	}
    158 }
    159 
    160 void
    161 native_to_linux_sigset(lss, bss)
    162 	linux_sigset_t *lss;
    163 	const sigset_t *bss;
    164 {
    165 	int i, newsig;
    166 
    167 	linux_sigemptyset(lss);
    168 	for (i = 1; i < NSIG; i++) {
    169 		if (sigismember(bss, i)) {
    170 			newsig = native_to_linux_signo[i];
    171 			if (newsig)
    172 				linux_sigaddset(lss, newsig);
    173 		}
    174 	}
    175 }
    176 
    177 unsigned int
    178 native_to_linux_sigflags(bsf)
    179 	const int bsf;
    180 {
    181 	unsigned int lsf = 0;
    182 	if ((bsf & SA_NOCLDSTOP) != 0)
    183 		lsf |= LINUX_SA_NOCLDSTOP;
    184 	if ((bsf & SA_NOCLDWAIT) != 0)
    185 		lsf |= LINUX_SA_NOCLDWAIT;
    186 	if ((bsf & SA_ONSTACK) != 0)
    187 		lsf |= LINUX_SA_ONSTACK;
    188 	if ((bsf & SA_RESTART) != 0)
    189 		lsf |= LINUX_SA_RESTART;
    190 	if ((bsf & SA_NODEFER) != 0)
    191 		lsf |= LINUX_SA_NOMASK;
    192 	if ((bsf & SA_RESETHAND) != 0)
    193 		lsf |= LINUX_SA_ONESHOT;
    194 	if ((bsf & SA_SIGINFO) != 0)
    195 		lsf |= LINUX_SA_SIGINFO;
    196 	return lsf;
    197 }
    198 
    199 int
    200 linux_to_native_sigflags(lsf)
    201 	const unsigned long lsf;
    202 {
    203 	int bsf = 0;
    204 	if ((lsf & LINUX_SA_NOCLDSTOP) != 0)
    205 		bsf |= SA_NOCLDSTOP;
    206 	if ((lsf & LINUX_SA_NOCLDWAIT) != 0)
    207 		bsf |= SA_NOCLDWAIT;
    208 	if ((lsf & LINUX_SA_ONSTACK) != 0)
    209 		bsf |= SA_ONSTACK;
    210 	if ((lsf & LINUX_SA_RESTART) != 0)
    211 		bsf |= SA_RESTART;
    212 	if ((lsf & LINUX_SA_ONESHOT) != 0)
    213 		bsf |= SA_RESETHAND;
    214 	if ((lsf & LINUX_SA_NOMASK) != 0)
    215 		bsf |= SA_NODEFER;
    216 	if ((lsf & LINUX_SA_SIGINFO) != 0)
    217 		bsf |= SA_SIGINFO;
    218 	if ((lsf & ~LINUX_SA_ALLBITS) != 0)
    219 		DPRINTF(("linux_old_to_native_sigflags: "
    220 		    "%lx extra bits ignored\n", lsf));
    221 	return bsf;
    222 }
    223 
    224 /*
    225  * Convert between Linux and BSD sigaction structures.
    226  */
    227 void
    228 linux_old_to_native_sigaction(bsa, lsa)
    229 	struct sigaction *bsa;
    230 	const struct linux_old_sigaction *lsa;
    231 {
    232 	bsa->sa_handler = lsa->linux_sa_handler;
    233 	linux_old_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
    234 	bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
    235 }
    236 
    237 void
    238 native_to_linux_old_sigaction(lsa, bsa)
    239 	struct linux_old_sigaction *lsa;
    240 	const struct sigaction *bsa;
    241 {
    242 	lsa->linux_sa_handler = bsa->sa_handler;
    243 	native_to_linux_old_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
    244 	lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    245 #ifndef __alpha__
    246 	lsa->linux_sa_restorer = NULL;
    247 #endif
    248 }
    249 
    250 /* ...and the new sigaction conversion funcs. */
    251 void
    252 linux_to_native_sigaction(bsa, lsa)
    253 	struct sigaction *bsa;
    254 	const struct linux_sigaction *lsa;
    255 {
    256 	bsa->sa_handler = lsa->linux_sa_handler;
    257 	linux_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
    258 	bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
    259 }
    260 
    261 void
    262 native_to_linux_sigaction(lsa, bsa)
    263 	struct linux_sigaction *lsa;
    264 	const struct sigaction *bsa;
    265 {
    266 	lsa->linux_sa_handler = bsa->sa_handler;
    267 	native_to_linux_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
    268 	lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    269 #ifndef __alpha__
    270 	lsa->linux_sa_restorer = NULL;
    271 #endif
    272 }
    273 
    274 /* ----------------------------------------------------------------------- */
    275 
    276 /*
    277  * The Linux sigaction() system call. Do the usual conversions,
    278  * and just call sigaction(). Some flags and values are silently
    279  * ignored (see above).
    280  */
    281 int
    282 linux_sys_rt_sigaction(l, v, retval)
    283 	struct lwp *l;
    284 	void *v;
    285 	register_t *retval;
    286 {
    287 	struct linux_sys_rt_sigaction_args /* {
    288 		syscallarg(int) signum;
    289 		syscallarg(const struct linux_sigaction *) nsa;
    290 		syscallarg(struct linux_sigaction *) osa;
    291 		syscallarg(size_t) sigsetsize;
    292 	} */ *uap = v;
    293 	struct linux_sigaction nlsa, olsa;
    294 	struct sigaction nbsa, obsa;
    295 	int error, sig;
    296 	void *tramp = NULL;
    297 	int vers = 0;
    298 #if defined __amd64__
    299 	struct sigacts *ps = l->l_proc->p_sigacts;
    300 #endif
    301 
    302 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    303 		return (EINVAL);
    304 
    305 	if (SCARG(uap, nsa)) {
    306 		error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
    307 		if (error)
    308 			return (error);
    309 		linux_to_native_sigaction(&nbsa, &nlsa);
    310 	}
    311 
    312 	sig = SCARG(uap, signum);
    313 	if (sig < 0 || sig >= LINUX__NSIG)
    314 		return (EINVAL);
    315 	if (sig > 0 && !linux_to_native_signo[sig]) {
    316 		/* Pretend that we did something useful for unknown signals. */
    317 		obsa.sa_handler = SIG_IGN;
    318 		sigemptyset(&obsa.sa_mask);
    319 		obsa.sa_flags = 0;
    320 	} else {
    321 #if defined __amd64__
    322 		if (nlsa.linux_sa_flags & LINUX_SA_RESTORER) {
    323 			if ((tramp = nlsa.linux_sa_restorer) != NULL)
    324 				vers = 2; /* XXX arch dependant */
    325 		}
    326 #endif
    327 
    328 		error = sigaction1(l, linux_to_native_signo[sig],
    329 		    SCARG(uap, nsa) ? &nbsa : NULL,
    330 		    SCARG(uap, osa) ? &obsa : NULL,
    331 		    tramp, vers);
    332 		if (error)
    333 			return (error);
    334 	}
    335 	if (SCARG(uap, osa)) {
    336 		native_to_linux_sigaction(&olsa, &obsa);
    337 
    338 #if defined __amd64__
    339 		if (ps->sa_sigdesc[sig].sd_vers != 0) {
    340 			olsa.linux_sa_restorer = ps->sa_sigdesc[sig].sd_tramp;
    341 			olsa.linux_sa_flags |= LINUX_SA_RESTORER;
    342 		}
    343 #endif
    344 
    345 		error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
    346 		if (error)
    347 			return (error);
    348 	}
    349 	return (0);
    350 }
    351 
    352 int
    353 linux_sigprocmask1(l, how, set, oset)
    354 	struct lwp *l;
    355 	int how;
    356 	const linux_old_sigset_t *set;
    357 	linux_old_sigset_t *oset;
    358 {
    359 	linux_old_sigset_t nlss, olss;
    360 	sigset_t nbss, obss;
    361 	int error;
    362 
    363 	switch (how) {
    364 	case LINUX_SIG_BLOCK:
    365 		how = SIG_BLOCK;
    366 		break;
    367 	case LINUX_SIG_UNBLOCK:
    368 		how = SIG_UNBLOCK;
    369 		break;
    370 	case LINUX_SIG_SETMASK:
    371 		how = SIG_SETMASK;
    372 		break;
    373 	default:
    374 		return (EINVAL);
    375 	}
    376 
    377 	if (set) {
    378 		error = copyin(set, &nlss, sizeof(nlss));
    379 		if (error)
    380 			return (error);
    381 		linux_old_to_native_sigset(&nbss, &nlss);
    382 	}
    383 	error = sigprocmask1(l, how,
    384 	    set ? &nbss : NULL, oset ? &obss : NULL);
    385 	if (error)
    386 		return (error);
    387 	if (oset) {
    388 		native_to_linux_old_sigset(&olss, &obss);
    389 		error = copyout(&olss, oset, sizeof(olss));
    390 		if (error)
    391 			return (error);
    392 	}
    393 	return (error);
    394 }
    395 
    396 int
    397 linux_sys_rt_sigprocmask(l, v, retval)
    398 	struct lwp *l;
    399 	void *v;
    400 	register_t *retval;
    401 {
    402 	struct linux_sys_rt_sigprocmask_args /* {
    403 		syscallarg(int) how;
    404 		syscallarg(const linux_sigset_t *) set;
    405 		syscallarg(linux_sigset_t *) oset;
    406 		syscallarg(size_t) sigsetsize;
    407 	} */ *uap = v;
    408 	linux_sigset_t nlss, olss, *oset;
    409 	const linux_sigset_t *set;
    410 	sigset_t nbss, obss;
    411 	int error, how;
    412 
    413 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    414 		return (EINVAL);
    415 
    416 	switch (SCARG(uap, how)) {
    417 	case LINUX_SIG_BLOCK:
    418 		how = SIG_BLOCK;
    419 		break;
    420 	case LINUX_SIG_UNBLOCK:
    421 		how = SIG_UNBLOCK;
    422 		break;
    423 	case LINUX_SIG_SETMASK:
    424 		how = SIG_SETMASK;
    425 		break;
    426 	default:
    427 		return (EINVAL);
    428 	}
    429 
    430 	set = SCARG(uap, set);
    431 	oset = SCARG(uap, oset);
    432 
    433 	if (set) {
    434 		error = copyin(set, &nlss, sizeof(nlss));
    435 		if (error)
    436 			return (error);
    437 		linux_to_native_sigset(&nbss, &nlss);
    438 	}
    439 	error = sigprocmask1(l, how,
    440 	    set ? &nbss : NULL, oset ? &obss : NULL);
    441 	if (!error && oset) {
    442 		native_to_linux_sigset(&olss, &obss);
    443 		error = copyout(&olss, oset, sizeof(olss));
    444 	}
    445 	return (error);
    446 }
    447 
    448 int
    449 linux_sys_rt_sigpending(l, v, retval)
    450 	struct lwp *l;
    451 	void *v;
    452 	register_t *retval;
    453 {
    454 	struct linux_sys_rt_sigpending_args /* {
    455 		syscallarg(linux_sigset_t *) set;
    456 		syscallarg(size_t) sigsetsize;
    457 	} */ *uap = v;
    458 	sigset_t bss;
    459 	linux_sigset_t lss;
    460 
    461 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    462 		return (EINVAL);
    463 
    464 	sigpending1(l, &bss);
    465 	native_to_linux_sigset(&lss, &bss);
    466 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    467 }
    468 
    469 #ifndef __amd64__
    470 int
    471 linux_sys_sigpending(l, v, retval)
    472 	struct lwp *l;
    473 	void *v;
    474 	register_t *retval;
    475 {
    476 	struct linux_sys_sigpending_args /* {
    477 		syscallarg(linux_old_sigset_t *) mask;
    478 	} */ *uap = v;
    479 	sigset_t bss;
    480 	linux_old_sigset_t lss;
    481 
    482 	sigpending1(l, &bss);
    483 	native_to_linux_old_sigset(&lss, &bss);
    484 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    485 }
    486 
    487 int
    488 linux_sys_sigsuspend(l, v, retval)
    489 	struct lwp *l;
    490 	void *v;
    491 	register_t *retval;
    492 {
    493 	struct linux_sys_sigsuspend_args /* {
    494 		syscallarg(caddr_t) restart;
    495 		syscallarg(int) oldmask;
    496 		syscallarg(int) mask;
    497 	} */ *uap = v;
    498 	linux_old_sigset_t lss;
    499 	sigset_t bss;
    500 
    501 	lss = SCARG(uap, mask);
    502 	linux_old_to_native_sigset(&bss, &lss);
    503 	return (sigsuspend1(l, &bss));
    504 }
    505 #endif /* __amd64__ */
    506 
    507 int
    508 linux_sys_rt_sigsuspend(l, v, retval)
    509 	struct lwp *l;
    510 	void *v;
    511 	register_t *retval;
    512 {
    513 	struct linux_sys_rt_sigsuspend_args /* {
    514 		syscallarg(linux_sigset_t *) unewset;
    515 		syscallarg(size_t) sigsetsize;
    516 	} */ *uap = v;
    517 	linux_sigset_t lss;
    518 	sigset_t bss;
    519 	int error;
    520 
    521 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    522 		return (EINVAL);
    523 
    524 	error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
    525 	if (error)
    526 		return (error);
    527 
    528 	linux_to_native_sigset(&bss, &lss);
    529 
    530 	return (sigsuspend1(l, &bss));
    531 }
    532 
    533 /*
    534  * Once more: only a signal conversion is needed.
    535  * Note: also used as sys_rt_queueinfo.  The info field is ignored.
    536  */
    537 int
    538 linux_sys_rt_queueinfo(l, v, retval)
    539 	struct lwp *l;
    540 	void *v;
    541 	register_t *retval;
    542 {
    543 	/* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
    544 #if 0
    545 	struct linux_sys_rt_queueinfo_args /* {
    546 		syscallarg(int) pid;
    547 		syscallarg(int) signum;
    548 		syscallarg(siginfo_t *) uinfo;
    549 	} */ *uap = v;
    550 #endif
    551 
    552 	/* XXX To really implement this we need to	*/
    553 	/* XXX keep a list of queued signals somewhere.	*/
    554 	return (linux_sys_kill(l, v, retval));
    555 }
    556 
    557 int
    558 linux_sys_kill(l, v, retval)
    559 	struct lwp *l;
    560 	void *v;
    561 	register_t *retval;
    562 {
    563 	struct linux_sys_kill_args /* {
    564 		syscallarg(int) pid;
    565 		syscallarg(int) signum;
    566 	} */ *uap = v;
    567 
    568 	struct sys_kill_args ka;
    569 	int sig;
    570 
    571 	SCARG(&ka, pid) = SCARG(uap, pid);
    572 	sig = SCARG(uap, signum);
    573 	if (sig < 0 || sig >= LINUX__NSIG)
    574 		return (EINVAL);
    575 	SCARG(&ka, signum) = linux_to_native_signo[sig];
    576 	return sys_kill(l, &ka, retval);
    577 }
    578 
    579 #ifdef LINUX_SS_ONSTACK
    580 static void linux_to_native_sigaltstack __P((struct sigaltstack *,
    581     const struct linux_sigaltstack *));
    582 
    583 static void
    584 linux_to_native_sigaltstack(bss, lss)
    585 	struct sigaltstack *bss;
    586 	const struct linux_sigaltstack *lss;
    587 {
    588 	bss->ss_sp = lss->ss_sp;
    589 	bss->ss_size = lss->ss_size;
    590 	if (lss->ss_flags & LINUX_SS_ONSTACK)
    591 	    bss->ss_flags = SS_ONSTACK;
    592 	else if (lss->ss_flags & LINUX_SS_DISABLE)
    593 	    bss->ss_flags = SS_DISABLE;
    594 	else
    595 	    bss->ss_flags = 0;
    596 }
    597 
    598 void
    599 native_to_linux_sigaltstack(lss, bss)
    600 	struct linux_sigaltstack *lss;
    601 	const struct sigaltstack *bss;
    602 {
    603 	lss->ss_sp = bss->ss_sp;
    604 	lss->ss_size = bss->ss_size;
    605 	if (bss->ss_flags & SS_ONSTACK)
    606 	    lss->ss_flags = LINUX_SS_ONSTACK;
    607 	else if (bss->ss_flags & SS_DISABLE)
    608 	    lss->ss_flags = LINUX_SS_DISABLE;
    609 	else
    610 	    lss->ss_flags = 0;
    611 }
    612 
    613 int
    614 linux_sys_sigaltstack(l, v, retval)
    615 	struct lwp *l;
    616 	void *v;
    617 	register_t *retval;
    618 {
    619 	struct linux_sys_sigaltstack_args /* {
    620 		syscallarg(const struct linux_sigaltstack *) ss;
    621 		syscallarg(struct linux_sigaltstack *) oss;
    622 	} */ *uap = v;
    623 	struct linux_sigaltstack ss;
    624 	struct sigaltstack nss;
    625 	struct proc *p = l->l_proc;
    626 	int error = 0;
    627 
    628 	if (SCARG(uap, oss)) {
    629 		native_to_linux_sigaltstack(&ss, l->l_sigstk);
    630 		if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
    631 			return error;
    632 	}
    633 
    634 	if (SCARG(uap, ss) != NULL) {
    635 		if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
    636 			return error;
    637 		linux_to_native_sigaltstack(&nss, &ss);
    638 
    639 		mutex_enter(&p->p_smutex);
    640 
    641 		if (nss.ss_flags & ~SS_ALLBITS)
    642 			error = EINVAL;
    643 		else if (nss.ss_flags & SS_DISABLE) {
    644 			if (l->l_sigstk->ss_flags & SS_ONSTACK)
    645 				error = EINVAL;
    646 		} else if (nss.ss_size < LINUX_MINSIGSTKSZ)
    647 			error = ENOMEM;
    648 
    649 		if (error == 0)
    650 			*l->l_sigstk = nss;
    651 
    652 		mutex_exit(&p->p_smutex);
    653 	}
    654 
    655 	return error;
    656 }
    657 #endif /* LINUX_SS_ONSTACK */
    658 
    659 #ifdef LINUX_NPTL
    660 int
    661 linux_sys_tkill(l, v, retval)
    662 	struct lwp *l;
    663 	void *v;
    664 	register_t *retval;
    665 {
    666 	struct linux_sys_tkill_args /* {
    667 		syscallarg(int) tid;
    668 		syscallarg(int) sig;
    669 	} */ *uap = v;
    670 	struct linux_sys_kill_args cup;
    671 
    672 	/* We use the PID as the TID ... */
    673 	SCARG(&cup, pid) = SCARG(uap, tid);
    674 	SCARG(&cup, signum) = SCARG(uap, sig);
    675 
    676 	return linux_sys_kill(l, &cup, retval);
    677 }
    678 
    679 int
    680 linux_sys_tgkill(l, v, retval)
    681 	struct lwp *l;
    682 	void *v;
    683 	register_t *retval;
    684 {
    685 	struct linux_sys_tgkill_args /* {
    686 		syscallarg(int) tgid;
    687 		syscallarg(int) tid;
    688 		syscallarg(int) sig;
    689 	} */ *uap = v;
    690 	struct linux_sys_kill_args cup;
    691 	struct linux_emuldata *led;
    692 	struct proc *p;
    693 
    694 	SCARG(&cup, pid) = SCARG(uap, tid);
    695 	SCARG(&cup, signum) = SCARG(uap, sig);
    696 
    697 	if (SCARG(uap, tgid) == -1)
    698 		return linux_sys_kill(l, &cup, retval);
    699 
    700 	/* We use the PID as the TID, but make sure the group ID is right */
    701 	if ((p = pfind(SCARG(uap, tid))) == NULL)
    702 		return ESRCH;
    703 
    704 	if (p->p_emul != &emul_linux)
    705 		return ESRCH;
    706 
    707 	led = p->p_emuldata;
    708 
    709 	if (led->s->group_pid != SCARG(uap, tgid))
    710 		return ESRCH;
    711 
    712 	return linux_sys_kill(l, &cup, retval);
    713 }
    714 #endif /* LINUX_NPTL */
    715