Home | History | Annotate | Line # | Download | only in common
linux_signal.c revision 1.50.2.1
      1 /*	$NetBSD: linux_signal.c,v 1.50.2.1 2006/10/22 06:05:24 yamt 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.50.2.1 2006/10/22 06:05:24 yamt 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 	}
    222 	return bsf;
    223 }
    224 
    225 /*
    226  * Convert between Linux and BSD sigaction structures.
    227  */
    228 void
    229 linux_old_to_native_sigaction(bsa, lsa)
    230 	struct sigaction *bsa;
    231 	const struct linux_old_sigaction *lsa;
    232 {
    233 	bsa->sa_handler = lsa->linux_sa_handler;
    234 	linux_old_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
    235 	bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
    236 }
    237 
    238 void
    239 native_to_linux_old_sigaction(lsa, bsa)
    240 	struct linux_old_sigaction *lsa;
    241 	const struct sigaction *bsa;
    242 {
    243 	lsa->linux_sa_handler = bsa->sa_handler;
    244 	native_to_linux_old_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
    245 	lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    246 #ifndef __alpha__
    247 	lsa->linux_sa_restorer = NULL;
    248 #endif
    249 }
    250 
    251 /* ...and the new sigaction conversion funcs. */
    252 void
    253 linux_to_native_sigaction(bsa, lsa)
    254 	struct sigaction *bsa;
    255 	const struct linux_sigaction *lsa;
    256 {
    257 	bsa->sa_handler = lsa->linux_sa_handler;
    258 	linux_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
    259 	bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
    260 }
    261 
    262 void
    263 native_to_linux_sigaction(lsa, bsa)
    264 	struct linux_sigaction *lsa;
    265 	const struct sigaction *bsa;
    266 {
    267 	lsa->linux_sa_handler = bsa->sa_handler;
    268 	native_to_linux_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
    269 	lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    270 #ifndef __alpha__
    271 	lsa->linux_sa_restorer = NULL;
    272 #endif
    273 }
    274 
    275 /* ----------------------------------------------------------------------- */
    276 
    277 /*
    278  * The Linux sigaction() system call. Do the usual conversions,
    279  * and just call sigaction(). Some flags and values are silently
    280  * ignored (see above).
    281  */
    282 int
    283 linux_sys_rt_sigaction(struct lwp *l, void *v, register_t *retval __unused)
    284 {
    285 	struct linux_sys_rt_sigaction_args /* {
    286 		syscallarg(int) signum;
    287 		syscallarg(const struct linux_sigaction *) nsa;
    288 		syscallarg(struct linux_sigaction *) osa;
    289 		syscallarg(size_t) sigsetsize;
    290 	} */ *uap = v;
    291 	struct proc *p = l->l_proc;
    292 	struct linux_sigaction nlsa, olsa;
    293 	struct sigaction nbsa, obsa;
    294 	int error, sig;
    295 	void *tramp = NULL;
    296 	int vers = 0;
    297 #if defined __amd64__
    298 	struct sigacts *ps = p->p_sigacts;
    299 #endif
    300 
    301 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    302 		return (EINVAL);
    303 
    304 	if (SCARG(uap, nsa)) {
    305 		error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
    306 		if (error)
    307 			return (error);
    308 		linux_to_native_sigaction(&nbsa, &nlsa);
    309 	}
    310 
    311 	sig = SCARG(uap, signum);
    312 	if (sig < 0 || sig >= LINUX__NSIG)
    313 		return (EINVAL);
    314 	if (sig > 0 && !linux_to_native_signo[sig]) {
    315 		/* Pretend that we did something useful for unknown signals. */
    316 		obsa.sa_handler = SIG_IGN;
    317 		sigemptyset(&obsa.sa_mask);
    318 		obsa.sa_flags = 0;
    319 	} else {
    320 #if defined __amd64__
    321 		if (nlsa.linux_sa_flags & LINUX_SA_RESTORER) {
    322 			if ((tramp = nlsa.linux_sa_restorer) != NULL)
    323 				vers = 2; /* XXX arch dependant */
    324 		}
    325 #endif
    326 
    327 		error = sigaction1(p, linux_to_native_signo[sig],
    328 		    SCARG(uap, nsa) ? &nbsa : NULL,
    329 		    SCARG(uap, osa) ? &obsa : NULL,
    330 		    tramp, vers);
    331 		if (error)
    332 			return (error);
    333 	}
    334 	if (SCARG(uap, osa)) {
    335 		native_to_linux_sigaction(&olsa, &obsa);
    336 
    337 #if defined __amd64__
    338 		if (ps->sa_sigdesc[sig].sd_vers != 0) {
    339 			olsa.linux_sa_restorer = ps->sa_sigdesc[sig].sd_tramp;
    340 			olsa.linux_sa_flags |= LINUX_SA_RESTORER;
    341 		}
    342 #endif
    343 
    344 		error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
    345 		if (error)
    346 			return (error);
    347 	}
    348 	return (0);
    349 }
    350 
    351 int
    352 linux_sigprocmask1(p, how, set, oset)
    353 	struct proc *p;
    354 	int how;
    355 	const linux_old_sigset_t *set;
    356 	linux_old_sigset_t *oset;
    357 {
    358 	linux_old_sigset_t nlss, olss;
    359 	sigset_t nbss, obss;
    360 	int error;
    361 
    362 	switch (how) {
    363 	case LINUX_SIG_BLOCK:
    364 		how = SIG_BLOCK;
    365 		break;
    366 	case LINUX_SIG_UNBLOCK:
    367 		how = SIG_UNBLOCK;
    368 		break;
    369 	case LINUX_SIG_SETMASK:
    370 		how = SIG_SETMASK;
    371 		break;
    372 	default:
    373 		return (EINVAL);
    374 	}
    375 
    376 	if (set) {
    377 		error = copyin(set, &nlss, sizeof(nlss));
    378 		if (error)
    379 			return (error);
    380 		linux_old_to_native_sigset(&nbss, &nlss);
    381 	}
    382 	error = sigprocmask1(p, how,
    383 	    set ? &nbss : NULL, oset ? &obss : NULL);
    384 	if (error)
    385 		return (error);
    386 	if (oset) {
    387 		native_to_linux_old_sigset(&olss, &obss);
    388 		error = copyout(&olss, oset, sizeof(olss));
    389 		if (error)
    390 			return (error);
    391 	}
    392 	return (error);
    393 }
    394 
    395 int
    396 linux_sys_rt_sigprocmask(struct lwp *l, void *v, register_t *retval __unused)
    397 {
    398 	struct linux_sys_rt_sigprocmask_args /* {
    399 		syscallarg(int) how;
    400 		syscallarg(const linux_sigset_t *) set;
    401 		syscallarg(linux_sigset_t *) oset;
    402 		syscallarg(size_t) sigsetsize;
    403 	} */ *uap = v;
    404 	struct proc *p = l->l_proc;
    405 	linux_sigset_t nlss, olss, *oset;
    406 	const linux_sigset_t *set;
    407 	sigset_t nbss, obss;
    408 	int error, how;
    409 
    410 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    411 		return (EINVAL);
    412 
    413 	switch (SCARG(uap, how)) {
    414 	case LINUX_SIG_BLOCK:
    415 		how = SIG_BLOCK;
    416 		break;
    417 	case LINUX_SIG_UNBLOCK:
    418 		how = SIG_UNBLOCK;
    419 		break;
    420 	case LINUX_SIG_SETMASK:
    421 		how = SIG_SETMASK;
    422 		break;
    423 	default:
    424 		return (EINVAL);
    425 	}
    426 
    427 	set = SCARG(uap, set);
    428 	oset = SCARG(uap, oset);
    429 
    430 	if (set) {
    431 		error = copyin(set, &nlss, sizeof(nlss));
    432 		if (error)
    433 			return (error);
    434 		linux_to_native_sigset(&nbss, &nlss);
    435 	}
    436 	error = sigprocmask1(p, how,
    437 	    set ? &nbss : NULL, oset ? &obss : NULL);
    438 	if (!error && oset) {
    439 		native_to_linux_sigset(&olss, &obss);
    440 		error = copyout(&olss, oset, sizeof(olss));
    441 	}
    442 	return (error);
    443 }
    444 
    445 int
    446 linux_sys_rt_sigpending(struct lwp *l, void *v, register_t *retval __unused)
    447 {
    448 	struct linux_sys_rt_sigpending_args /* {
    449 		syscallarg(linux_sigset_t *) set;
    450 		syscallarg(size_t) sigsetsize;
    451 	} */ *uap = v;
    452 	struct proc *p = l->l_proc;
    453 	sigset_t bss;
    454 	linux_sigset_t lss;
    455 
    456 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    457 		return (EINVAL);
    458 
    459 	sigpending1(p, &bss);
    460 	native_to_linux_sigset(&lss, &bss);
    461 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    462 }
    463 
    464 #ifndef __amd64__
    465 int
    466 linux_sys_sigpending(struct lwp *l, void *v, register_t *retval __unused)
    467 {
    468 	struct linux_sys_sigpending_args /* {
    469 		syscallarg(linux_old_sigset_t *) mask;
    470 	} */ *uap = v;
    471 	struct proc *p = l->l_proc;
    472 	sigset_t bss;
    473 	linux_old_sigset_t lss;
    474 
    475 	sigpending1(p, &bss);
    476 	native_to_linux_old_sigset(&lss, &bss);
    477 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    478 }
    479 
    480 int
    481 linux_sys_sigsuspend(struct lwp *l, void *v, register_t *retval __unused)
    482 {
    483 	struct linux_sys_sigsuspend_args /* {
    484 		syscallarg(caddr_t) restart;
    485 		syscallarg(int) oldmask;
    486 		syscallarg(int) mask;
    487 	} */ *uap = v;
    488 	struct proc *p = l->l_proc;
    489 	linux_old_sigset_t lss;
    490 	sigset_t bss;
    491 
    492 	lss = SCARG(uap, mask);
    493 	linux_old_to_native_sigset(&bss, &lss);
    494 	return (sigsuspend1(p, &bss));
    495 }
    496 #endif /* __amd64__ */
    497 
    498 int
    499 linux_sys_rt_sigsuspend(struct lwp *l, void *v, register_t *retval __unused)
    500 {
    501 	struct linux_sys_rt_sigsuspend_args /* {
    502 		syscallarg(linux_sigset_t *) unewset;
    503 		syscallarg(size_t) sigsetsize;
    504 	} */ *uap = v;
    505 	struct proc *p = l->l_proc;
    506 	linux_sigset_t lss;
    507 	sigset_t bss;
    508 	int error;
    509 
    510 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    511 		return (EINVAL);
    512 
    513 	error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
    514 	if (error)
    515 		return (error);
    516 
    517 	linux_to_native_sigset(&bss, &lss);
    518 
    519 	return (sigsuspend1(p, &bss));
    520 }
    521 
    522 /*
    523  * Once more: only a signal conversion is needed.
    524  * Note: also used as sys_rt_queueinfo.  The info field is ignored.
    525  */
    526 int
    527 linux_sys_rt_queueinfo(l, v, retval)
    528 	struct lwp *l;
    529 	void *v;
    530 	register_t *retval;
    531 {
    532 	/* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
    533 #if 0
    534 	struct linux_sys_rt_queueinfo_args /* {
    535 		syscallarg(int) pid;
    536 		syscallarg(int) signum;
    537 		syscallarg(siginfo_t *) uinfo;
    538 	} */ *uap = v;
    539 #endif
    540 
    541 	/* XXX To really implement this we need to	*/
    542 	/* XXX keep a list of queued signals somewhere.	*/
    543 	return (linux_sys_kill(l, v, retval));
    544 }
    545 
    546 int
    547 linux_sys_kill(l, v, retval)
    548 	struct lwp *l;
    549 	void *v;
    550 	register_t *retval;
    551 {
    552 	struct linux_sys_kill_args /* {
    553 		syscallarg(int) pid;
    554 		syscallarg(int) signum;
    555 	} */ *uap = v;
    556 
    557 	struct sys_kill_args ka;
    558 	int sig;
    559 
    560 	SCARG(&ka, pid) = SCARG(uap, pid);
    561 	sig = SCARG(uap, signum);
    562 	if (sig < 0 || sig >= LINUX__NSIG)
    563 		return (EINVAL);
    564 	SCARG(&ka, signum) = linux_to_native_signo[sig];
    565 	return sys_kill(l, &ka, retval);
    566 }
    567 
    568 #ifdef LINUX_SS_ONSTACK
    569 static void linux_to_native_sigaltstack __P((struct sigaltstack *,
    570     const struct linux_sigaltstack *));
    571 
    572 static void
    573 linux_to_native_sigaltstack(bss, lss)
    574 	struct sigaltstack *bss;
    575 	const struct linux_sigaltstack *lss;
    576 {
    577 	bss->ss_sp = lss->ss_sp;
    578 	bss->ss_size = lss->ss_size;
    579 	if (lss->ss_flags & LINUX_SS_ONSTACK)
    580 	    bss->ss_flags = SS_ONSTACK;
    581 	else if (lss->ss_flags & LINUX_SS_DISABLE)
    582 	    bss->ss_flags = SS_DISABLE;
    583 	else
    584 	    bss->ss_flags = 0;
    585 }
    586 
    587 void
    588 native_to_linux_sigaltstack(lss, bss)
    589 	struct linux_sigaltstack *lss;
    590 	const struct sigaltstack *bss;
    591 {
    592 	lss->ss_sp = bss->ss_sp;
    593 	lss->ss_size = bss->ss_size;
    594 	if (bss->ss_flags & SS_ONSTACK)
    595 	    lss->ss_flags = LINUX_SS_ONSTACK;
    596 	else if (bss->ss_flags & SS_DISABLE)
    597 	    lss->ss_flags = LINUX_SS_DISABLE;
    598 	else
    599 	    lss->ss_flags = 0;
    600 }
    601 
    602 int
    603 linux_sys_sigaltstack(struct lwp *l, void *v, register_t *retval __unused)
    604 {
    605 	struct linux_sys_sigaltstack_args /* {
    606 		syscallarg(const struct linux_sigaltstack *) ss;
    607 		syscallarg(struct linux_sigaltstack *) oss;
    608 	} */ *uap = v;
    609 	struct proc *p = l->l_proc;
    610 	struct linux_sigaltstack ss;
    611 	struct sigaltstack nss;
    612 	int error;
    613 
    614 	if (SCARG(uap, oss)) {
    615 		native_to_linux_sigaltstack(&ss, &p->p_sigctx.ps_sigstk);
    616 		if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
    617 			return error;
    618 	}
    619 
    620 	if (SCARG(uap, ss) != NULL) {
    621 		if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
    622 			return error;
    623 		linux_to_native_sigaltstack(&nss, &ss);
    624 
    625 		if (nss.ss_flags & ~SS_ALLBITS)
    626 			return EINVAL;
    627 
    628 		if (nss.ss_flags & SS_DISABLE) {
    629 			if (p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK)
    630 				return EINVAL;
    631 		} else {
    632 			if (nss.ss_size < LINUX_MINSIGSTKSZ)
    633 				return ENOMEM;
    634 		}
    635 		p->p_sigctx.ps_sigstk = nss;
    636 	}
    637 
    638 	return 0;
    639 }
    640 #endif /* LINUX_SS_ONSTACK */
    641 
    642 #ifdef LINUX_NPTL
    643 int
    644 linux_sys_tkill(l, v, retval)
    645 	struct lwp *l;
    646 	void *v;
    647 	register_t *retval;
    648 {
    649 	struct linux_sys_tkill_args /* {
    650 		syscallarg(int) tid;
    651 		syscallarg(int) sig;
    652 	} */ *uap = v;
    653 	struct linux_sys_kill_args cup;
    654 
    655 	/* We use the PID as the TID ... */
    656 	SCARG(&cup, pid) = SCARG(uap, tid);
    657 	SCARG(&cup, signum) = SCARG(uap, sig);
    658 
    659 	return linux_sys_kill(l, &cup, retval);
    660 }
    661 
    662 int
    663 linux_sys_tgkill(l, v, retval)
    664 	struct lwp *l;
    665 	void *v;
    666 	register_t *retval;
    667 {
    668 	struct linux_sys_tgkill_args /* {
    669 		syscallarg(int) tgid;
    670 		syscallarg(int) tid;
    671 		syscallarg(int) sig;
    672 	} */ *uap = v;
    673 	struct linux_sys_kill_args cup;
    674 	struct linux_emuldata *led;
    675 	struct proc *p;
    676 
    677 	SCARG(&cup, pid) = SCARG(uap, tid);
    678 	SCARG(&cup, signum) = SCARG(uap, sig);
    679 
    680 	if (SCARG(uap, tgid) == -1)
    681 		return linux_sys_kill(l, &cup, retval);
    682 
    683 	/* We use the PID as the TID, but make sure the group ID is right */
    684 	if ((p = pfind(SCARG(uap, tid))) == NULL)
    685 		return ESRCH;
    686 
    687 	if (p->p_emul != &emul_linux)
    688 		return ESRCH;
    689 
    690 	led = p->p_emuldata;
    691 
    692 	if (led->s->group_pid != SCARG(uap, tgid))
    693 		return ESRCH;
    694 
    695 	return linux_sys_kill(l, &cup, retval);
    696 }
    697 #endif /* LINUX_NPTL */
    698