Home | History | Annotate | Line # | Download | only in common
linux_signal.c revision 1.35
      1 /*	$NetBSD: linux_signal.c,v 1.35 2002/03/19 20:52:00 christos 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.35 2002/03/19 20:52:00 christos 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/syscallargs.h>
     74 
     75 #include <compat/linux/common/linux_types.h>
     76 #include <compat/linux/common/linux_signal.h>
     77 #include <compat/linux/common/linux_siginfo.h>
     78 #include <compat/linux/common/linux_util.h>
     79 
     80 #include <compat/linux/linux_syscallargs.h>
     81 
     82 /* Locally used defines (in bsd<->linux conversion functions): */
     83 #define	linux_sigemptyset(s)	memset((s), 0, sizeof(*(s)))
     84 #define	linux_sigismember(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     85 					& (1 << ((n) - 1) % LINUX__NSIG_BPW))
     86 #define	linux_sigaddset(s, n)	((s)->sig[((n) - 1) / LINUX__NSIG_BPW]	\
     87 					|= (1 << ((n) - 1) % LINUX__NSIG_BPW))
     88 
     89 #ifndef LINUX_SIGINFO
     90 #define LINUX_SIGINFO	0
     91 #endif
     92 #ifndef LINUX_SIGEMT
     93 #define LINUX_SIGEMT	0
     94 #endif
     95 /* Note: linux_to_native_sig[] is in <arch>/linux_sigarray.c */
     96 const int native_to_linux_sig[] = {
     97 	0,			/* 0 */
     98 	LINUX_SIGHUP,		/* 1 */
     99 	LINUX_SIGINT,		/* 2 */
    100 	LINUX_SIGQUIT,		/* 3 */
    101 	LINUX_SIGILL,		/* 4 */
    102 	LINUX_SIGTRAP,		/* 5 */
    103 	LINUX_SIGABRT,		/* 6 */
    104 	LINUX_SIGEMT,		/* 7 */
    105 	LINUX_SIGFPE,		/* 8 */
    106 	LINUX_SIGKILL,		/* 9 */
    107 	LINUX_SIGBUS,		/* 10 */
    108 	LINUX_SIGSEGV,		/* 11 */
    109 	LINUX_SIGSYS,		/* 12 */
    110 	LINUX_SIGPIPE,		/* 13 */
    111 	LINUX_SIGALRM,		/* 14 */
    112 	LINUX_SIGTERM,		/* 15 */
    113 	LINUX_SIGURG,		/* 16 */
    114 	LINUX_SIGSTOP,		/* 17 */
    115 	LINUX_SIGTSTP,		/* 18 */
    116 	LINUX_SIGCONT,		/* 19 */
    117 	LINUX_SIGCHLD,		/* 20 */
    118 	LINUX_SIGTTIN,		/* 21 */
    119 	LINUX_SIGTTOU,		/* 22 */
    120 	LINUX_SIGIO,		/* 23 */
    121 	LINUX_SIGXCPU,		/* 24 */
    122 	LINUX_SIGXFSZ,		/* 25 */
    123 	LINUX_SIGVTALRM,	/* 26 */
    124 	LINUX_SIGPROF,		/* 27 */
    125 	LINUX_SIGWINCH,		/* 28 */
    126 	LINUX_SIGINFO,		/* 29 */
    127 	LINUX_SIGUSR1,		/* 30 */
    128 	LINUX_SIGUSR2,		/* 31 */
    129 	LINUX_SIGPWR,		/* 32 */
    130 	LINUX_SIGRTMIN + 0,	/* 33 */
    131 	LINUX_SIGRTMIN + 1,	/* 34 */
    132 	LINUX_SIGRTMIN + 2,	/* 35 */
    133 	LINUX_SIGRTMIN + 3,	/* 36 */
    134 	LINUX_SIGRTMIN + 4,	/* 37 */
    135 	LINUX_SIGRTMIN + 5,	/* 38 */
    136 	LINUX_SIGRTMIN + 6,	/* 39 */
    137 	LINUX_SIGRTMIN + 7,	/* 40 */
    138 	LINUX_SIGRTMIN + 8,	/* 41 */
    139 	LINUX_SIGRTMIN + 9,	/* 42 */
    140 	LINUX_SIGRTMIN + 10,	/* 43 */
    141 	LINUX_SIGRTMIN + 11,	/* 44 */
    142 	LINUX_SIGRTMIN + 12,	/* 45 */
    143 	LINUX_SIGRTMIN + 13,	/* 46 */
    144 	LINUX_SIGRTMIN + 14,	/* 47 */
    145 	LINUX_SIGRTMIN + 15,	/* 48 */
    146 	LINUX_SIGRTMIN + 16,	/* 49 */
    147 	LINUX_SIGRTMIN + 17,	/* 50 */
    148 	LINUX_SIGRTMIN + 18,	/* 51 */
    149 	LINUX_SIGRTMIN + 19,	/* 52 */
    150 	LINUX_SIGRTMIN + 20,	/* 53 */
    151 	LINUX_SIGRTMIN + 21,	/* 54 */
    152 	LINUX_SIGRTMIN + 22,	/* 55 */
    153 	LINUX_SIGRTMIN + 23,	/* 56 */
    154 	LINUX_SIGRTMIN + 24,	/* 57 */
    155 	LINUX_SIGRTMIN + 25,	/* 58 */
    156 	LINUX_SIGRTMIN + 26,	/* 59 */
    157 	LINUX_SIGRTMIN + 27,	/* 60 */
    158 	LINUX_SIGRTMIN + 28,	/* 61 */
    159 	LINUX_SIGRTMIN + 29,	/* 62 */
    160 	LINUX_SIGRTMIN + 30,	/* 63 */
    161 
    162 };
    163 
    164 /*
    165  * Convert between Linux and BSD signal sets.
    166  */
    167 #if LINUX__NSIG_WORDS > 1
    168 void
    169 linux_old_extra_to_native_sigset(bss, lss, extra)
    170 	sigset_t *bss;
    171 	const linux_old_sigset_t *lss;
    172 	const unsigned long *extra;
    173 {
    174 	linux_sigset_t lsnew;
    175 
    176 	/* convert old sigset to new sigset */
    177 	linux_sigemptyset(&lsnew);
    178 	lsnew.sig[0] = *lss;
    179 	if (extra)
    180 		memcpy(&lsnew.sig[1], extra,
    181 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    182 
    183 	linux_to_native_sigset(bss, &lsnew);
    184 }
    185 
    186 void
    187 native_to_linux_old_extra_sigset(lss, extra, bss)
    188 	linux_old_sigset_t *lss;
    189 	unsigned long *extra;
    190 	const sigset_t *bss;
    191 {
    192 	linux_sigset_t lsnew;
    193 
    194 	native_to_linux_sigset(&lsnew, bss);
    195 
    196 	/* convert new sigset to old sigset */
    197 	*lss = lsnew.sig[0];
    198 	if (extra)
    199 		memcpy(extra, &lsnew.sig[1],
    200 		    sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
    201 }
    202 #endif
    203 
    204 void
    205 linux_to_native_sigset(bss, lss)
    206 	sigset_t *bss;
    207 	const linux_sigset_t *lss;
    208 {
    209 	int i, newsig;
    210 
    211 	sigemptyset(bss);
    212 	for (i = 1; i < LINUX__NSIG; i++) {
    213 		if (linux_sigismember(lss, i)) {
    214 			newsig = linux_to_native_sig[i];
    215 			if (newsig)
    216 				sigaddset(bss, newsig);
    217 		}
    218 	}
    219 }
    220 
    221 void
    222 native_to_linux_sigset(lss, bss)
    223 	linux_sigset_t *lss;
    224 	const sigset_t *bss;
    225 {
    226 	int i, newsig;
    227 
    228 	linux_sigemptyset(lss);
    229 	for (i = 1; i < NSIG; i++) {
    230 		if (sigismember(bss, i)) {
    231 			newsig = native_to_linux_sig[i];
    232 			if (newsig)
    233 				linux_sigaddset(lss, newsig);
    234 		}
    235 	}
    236 }
    237 
    238 unsigned int
    239 native_to_linux_sigflags(bsf)
    240 	const int bsf;
    241 {
    242 	unsigned int lsf = 0;
    243 	if ((bsf & SA_NOCLDSTOP) != 0)
    244 		lsf |= LINUX_SA_NOCLDSTOP;
    245 	if ((bsf & SA_NOCLDWAIT) != 0)
    246 		lsf |= LINUX_SA_NOCLDWAIT;
    247 	if ((bsf & SA_ONSTACK) != 0)
    248 		lsf |= LINUX_SA_ONSTACK;
    249 	if ((bsf & SA_RESTART) != 0)
    250 		lsf |= LINUX_SA_RESTART;
    251 	if ((bsf & SA_NODEFER) != 0)
    252 		lsf |= LINUX_SA_NOMASK;
    253 	if ((bsf & SA_RESETHAND) != 0)
    254 		lsf |= LINUX_SA_ONESHOT;
    255 	if ((bsf & SA_SIGINFO) != 0)
    256 		lsf |= LINUX_SA_SIGINFO;
    257 	return lsf;
    258 }
    259 
    260 int
    261 linux_to_native_sigflags(lsf)
    262 	const unsigned long lsf;
    263 {
    264 	int bsf = 0;
    265 	if ((lsf & LINUX_SA_NOCLDSTOP) != 0)
    266 		bsf |= SA_NOCLDSTOP;
    267 	if ((lsf & LINUX_SA_NOCLDWAIT) != 0)
    268 		bsf |= SA_NOCLDWAIT;
    269 	if ((lsf & LINUX_SA_ONSTACK) != 0)
    270 		bsf |= SA_ONSTACK;
    271 	if ((lsf & LINUX_SA_RESTART) != 0)
    272 		bsf |= SA_RESTART;
    273 	if ((lsf & LINUX_SA_ONESHOT) != 0)
    274 		bsf |= SA_RESETHAND;
    275 	if ((lsf & LINUX_SA_NOMASK) != 0)
    276 		bsf |= SA_NODEFER;
    277 	if ((lsf & LINUX_SA_SIGINFO) != 0)
    278 		bsf |= SA_SIGINFO;
    279 #ifdef DEBUG_LINUX
    280 	if ((lsf & ~LINUX_SA_ALLBITS) != 0)
    281 		uprintf(
    282 		    "linux_old_to_native_sigflags: %lx extra bits ignored\n",
    283 		    lsf);
    284 #endif
    285 	return bsf;
    286 }
    287 
    288 /*
    289  * Convert between Linux and BSD sigaction structures. Linux sometimes
    290  * has one extra field (sa_restorer) which we don't support.
    291  */
    292 void
    293 linux_old_to_native_sigaction(bsa, lsa)
    294 	struct sigaction *bsa;
    295 	const struct linux_old_sigaction *lsa;
    296 {
    297 	bsa->sa_handler = lsa->sa_handler;
    298 	linux_old_to_native_sigset(&bsa->sa_mask, &lsa->sa_mask);
    299 	bsa->sa_flags = linux_to_native_sigflags(lsa->sa_flags);
    300 #ifndef __alpha__
    301 /*
    302  * XXX: On the alpha sa_restorer is elsewhere.
    303  */
    304 #ifdef DEBUG_LINUX
    305 	if (lsa->sa_restorer != NULL)
    306 		uprintf("linux_old_to_native_sigaction: sa_restorer ignored\n");
    307 #endif
    308 #endif
    309 }
    310 
    311 void
    312 native_to_linux_old_sigaction(lsa, bsa)
    313 	struct linux_old_sigaction *lsa;
    314 	const struct sigaction *bsa;
    315 {
    316 	lsa->sa_handler = bsa->sa_handler;
    317 	native_to_linux_old_sigset(&lsa->sa_mask, &bsa->sa_mask);
    318 	lsa->sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    319 #ifndef __alpha__
    320 	lsa->sa_restorer = NULL;
    321 #endif
    322 }
    323 
    324 /* ...and the new sigaction conversion funcs. */
    325 void
    326 linux_to_native_sigaction(bsa, lsa)
    327 	struct sigaction *bsa;
    328 	const struct linux_sigaction *lsa;
    329 {
    330 	bsa->sa_handler = lsa->sa_handler;
    331 	linux_to_native_sigset(&bsa->sa_mask, &lsa->sa_mask);
    332 	bsa->sa_flags = linux_to_native_sigflags(lsa->sa_flags);
    333 #ifndef __alpha__
    334 #ifdef DEBUG_LINUX
    335 	if (lsa->sa_restorer != 0)
    336 		uprintf("linux_to_native_sigaction: sa_restorer ignored\n");
    337 #endif
    338 #endif
    339 }
    340 
    341 void
    342 native_to_linux_sigaction(lsa, bsa)
    343 	struct linux_sigaction *lsa;
    344 	const struct sigaction *bsa;
    345 {
    346 	lsa->sa_handler = bsa->sa_handler;
    347 	native_to_linux_sigset(&lsa->sa_mask, &bsa->sa_mask);
    348 	lsa->sa_flags = native_to_linux_sigflags(bsa->sa_flags);
    349 #ifndef __alpha__
    350 	lsa->sa_restorer = NULL;
    351 #endif
    352 }
    353 
    354 /* ----------------------------------------------------------------------- */
    355 
    356 /*
    357  * The Linux sigaction() system call. Do the usual conversions,
    358  * and just call sigaction(). Some flags and values are silently
    359  * ignored (see above).
    360  */
    361 int
    362 linux_sys_rt_sigaction(p, v, retval)
    363 	struct proc *p;
    364 	void *v;
    365 	register_t *retval;
    366 {
    367 	struct linux_sys_rt_sigaction_args /* {
    368 		syscallarg(int) signum;
    369 		syscallarg(const struct linux_sigaction *) nsa;
    370 		syscallarg(struct linux_sigaction *) osa;
    371 		syscallarg(size_t) sigsetsize;
    372 	} */ *uap = v;
    373 	struct linux_sigaction nlsa, olsa;
    374 	struct sigaction nbsa, obsa;
    375 	int error, sig;
    376 
    377 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    378 		return (EINVAL);
    379 
    380 	if (SCARG(uap, nsa)) {
    381 		error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
    382 		if (error)
    383 			return (error);
    384 		linux_to_native_sigaction(&nbsa, &nlsa);
    385 	}
    386 	sig = SCARG(uap, signum);
    387 	if (sig < 0 || sig >= LINUX__NSIG)
    388 		return (EINVAL);
    389 	if (sig > 0 && !linux_to_native_sig[sig]) {
    390 		/* Pretend that we did something useful for unknown signals. */
    391 		obsa.sa_handler = SIG_IGN;
    392 		sigemptyset(&obsa.sa_mask);
    393 		obsa.sa_flags = 0;
    394 	} else {
    395 		error = sigaction1(p, linux_to_native_sig[sig],
    396 		    SCARG(uap, nsa) ? &nbsa : NULL, SCARG(uap, osa) ? &obsa : NULL);
    397 		if (error)
    398 			return (error);
    399 	}
    400 	if (SCARG(uap, osa)) {
    401 		native_to_linux_sigaction(&olsa, &obsa);
    402 		error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
    403 		if (error)
    404 			return (error);
    405 	}
    406 	return (0);
    407 }
    408 
    409 int
    410 linux_sigprocmask1(p, how, set, oset)
    411 	struct proc *p;
    412 	int how;
    413 	const linux_old_sigset_t *set;
    414 	linux_old_sigset_t *oset;
    415 {
    416 	linux_old_sigset_t nlss, olss;
    417 	sigset_t nbss, obss;
    418 	int error;
    419 
    420 	switch (how) {
    421 	case LINUX_SIG_BLOCK:
    422 		how = SIG_BLOCK;
    423 		break;
    424 	case LINUX_SIG_UNBLOCK:
    425 		how = SIG_UNBLOCK;
    426 		break;
    427 	case LINUX_SIG_SETMASK:
    428 		how = SIG_SETMASK;
    429 		break;
    430 	default:
    431 		return (EINVAL);
    432 	}
    433 
    434 	if (set) {
    435 		error = copyin(set, &nlss, sizeof(nlss));
    436 		if (error)
    437 			return (error);
    438 		linux_old_to_native_sigset(&nbss, &nlss);
    439 	}
    440 	error = sigprocmask1(p, how,
    441 	    set ? &nbss : NULL, oset ? &obss : NULL);
    442 	if (error)
    443 		return (error);
    444 	if (oset) {
    445 		native_to_linux_old_sigset(&olss, &obss);
    446 		error = copyout(&olss, oset, sizeof(olss));
    447 		if (error)
    448 			return (error);
    449 	}
    450 	return (error);
    451 }
    452 
    453 int
    454 linux_sys_rt_sigprocmask(p, v, retval)
    455 	struct proc *p;
    456 	void *v;
    457 	register_t *retval;
    458 {
    459 	struct linux_sys_rt_sigprocmask_args /* {
    460 		syscallarg(int) how;
    461 		syscallarg(const linux_sigset_t *) set;
    462 		syscallarg(linux_sigset_t *) oset;
    463 		syscallarg(size_t) sigsetsize;
    464 	} */ *uap = v;
    465 
    466 	linux_sigset_t nlss, olss, *oset;
    467 	const linux_sigset_t *set;
    468 	sigset_t nbss, obss;
    469 	int error, how;
    470 
    471 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    472 		return (EINVAL);
    473 
    474 	switch (SCARG(uap, how)) {
    475 	case LINUX_SIG_BLOCK:
    476 		how = SIG_BLOCK;
    477 		break;
    478 	case LINUX_SIG_UNBLOCK:
    479 		how = SIG_UNBLOCK;
    480 		break;
    481 	case LINUX_SIG_SETMASK:
    482 		how = SIG_SETMASK;
    483 		break;
    484 	default:
    485 		return (EINVAL);
    486 	}
    487 
    488 	set = SCARG(uap, set);
    489 	oset = SCARG(uap, oset);
    490 
    491 	if (set) {
    492 		error = copyin(set, &nlss, sizeof(nlss));
    493 		if (error)
    494 			return (error);
    495 		linux_to_native_sigset(&nbss, &nlss);
    496 	}
    497 	error = sigprocmask1(p, how,
    498 	    set ? &nbss : NULL, oset ? &obss : NULL);
    499 	if (!error && oset) {
    500 		native_to_linux_sigset(&olss, &obss);
    501 		error = copyout(&olss, oset, sizeof(olss));
    502 	}
    503 	return (error);
    504 }
    505 
    506 int
    507 linux_sys_rt_sigpending(p, v, retval)
    508 	struct proc *p;
    509 	void *v;
    510 	register_t *retval;
    511 {
    512 	struct linux_sys_rt_sigpending_args /* {
    513 		syscallarg(linux_sigset_t *) set;
    514 		syscallarg(size_t) sigsetsize;
    515 	} */ *uap = v;
    516 	sigset_t bss;
    517 	linux_sigset_t lss;
    518 
    519 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    520 		return (EINVAL);
    521 
    522 	sigpending1(p, &bss);
    523 	native_to_linux_sigset(&lss, &bss);
    524 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    525 }
    526 
    527 int
    528 linux_sys_sigpending(p, v, retval)
    529 	struct proc *p;
    530 	void *v;
    531 	register_t *retval;
    532 {
    533 	struct linux_sys_sigpending_args /* {
    534 		syscallarg(linux_old_sigset_t *) mask;
    535 	} */ *uap = v;
    536 	sigset_t bss;
    537 	linux_old_sigset_t lss;
    538 
    539 	sigpending1(p, &bss);
    540 	native_to_linux_old_sigset(&lss, &bss);
    541 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
    542 }
    543 
    544 int
    545 linux_sys_sigsuspend(p, v, retval)
    546 	struct proc *p;
    547 	void *v;
    548 	register_t *retval;
    549 {
    550 	struct linux_sys_sigsuspend_args /* {
    551 		syscallarg(caddr_t) restart;
    552 		syscallarg(int) oldmask;
    553 		syscallarg(int) mask;
    554 	} */ *uap = v;
    555 	linux_old_sigset_t lss;
    556 	sigset_t bss;
    557 
    558 	lss = SCARG(uap, mask);
    559 	linux_old_to_native_sigset(&bss, &lss);
    560 	return (sigsuspend1(p, &bss));
    561 }
    562 int
    563 linux_sys_rt_sigsuspend(p, v, retval)
    564 	struct proc *p;
    565 	void *v;
    566 	register_t *retval;
    567 {
    568 	struct linux_sys_rt_sigsuspend_args /* {
    569 		syscallarg(linux_sigset_t *) unewset;
    570 		syscallarg(size_t) sigsetsize;
    571 	} */ *uap = v;
    572 	linux_sigset_t lss;
    573 	sigset_t bss;
    574 	int error;
    575 
    576 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
    577 		return (EINVAL);
    578 
    579 	error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
    580 	if (error)
    581 		return (error);
    582 
    583 	linux_to_native_sigset(&bss, &lss);
    584 
    585 	return (sigsuspend1(p, &bss));
    586 }
    587 
    588 /*
    589  * Once more: only a signal conversion is needed.
    590  * Note: also used as sys_rt_queueinfo.  The info field is ignored.
    591  */
    592 int
    593 linux_sys_rt_queueinfo(p, v, retval)
    594 	struct proc *p;
    595 	void *v;
    596 	register_t *retval;
    597 {
    598 	/* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
    599 #if 0
    600 	struct linux_sys_rt_queueinfo_args /* {
    601 		syscallarg(int) pid;
    602 		syscallarg(int) signum;
    603 		syscallarg(siginfo_t *) uinfo;
    604 	} */ *uap = v;
    605 #endif
    606 
    607 	/* XXX To really implement this we need to	*/
    608 	/* XXX keep a list of queued signals somewhere.	*/
    609 	return (linux_sys_kill(p, v, retval));
    610 }
    611 
    612 int
    613 linux_sys_kill(p, v, retval)
    614 	struct proc *p;
    615 	void *v;
    616 	register_t *retval;
    617 {
    618 	struct linux_sys_kill_args /* {
    619 		syscallarg(int) pid;
    620 		syscallarg(int) signum;
    621 	} */ *uap = v;
    622 	struct sys_kill_args ka;
    623 	int sig;
    624 
    625 	SCARG(&ka, pid) = SCARG(uap, pid);
    626 	sig = SCARG(uap, signum);
    627 	if (sig < 0 || sig >= LINUX__NSIG)
    628 		return (EINVAL);
    629 	SCARG(&ka, signum) = linux_to_native_sig[sig];
    630 	return sys_kill(p, &ka, retval);
    631 }
    632 
    633 #ifdef LINUX_SS_ONSTACK
    634 static void linux_to_native_sigaltstack __P((struct sigaltstack *,
    635     const struct linux_sigaltstack *));
    636 static void native_to_linux_sigaltstack __P((struct linux_sigaltstack *,
    637     const struct sigaltstack *));
    638 
    639 static void
    640 linux_to_native_sigaltstack(bss, lss)
    641 	struct sigaltstack *bss;
    642 	const struct linux_sigaltstack *lss;
    643 {
    644 	bss->ss_sp = lss->ss_sp;
    645 	bss->ss_size = lss->ss_size;
    646 	if (lss->ss_flags & LINUX_SS_ONSTACK)
    647 	    bss->ss_flags = SS_ONSTACK;
    648 	else if (lss->ss_flags & LINUX_SS_DISABLE)
    649 	    bss->ss_flags = SS_DISABLE;
    650 	else
    651 	    bss->ss_flags = 0;
    652 }
    653 
    654 static void
    655 native_to_linux_sigaltstack(lss, bss)
    656 	struct linux_sigaltstack *lss;
    657 	const struct sigaltstack *bss;
    658 {
    659 	lss->ss_sp = bss->ss_sp;
    660 	lss->ss_size = bss->ss_size;
    661 	if (bss->ss_flags & SS_ONSTACK)
    662 	    lss->ss_flags = LINUX_SS_ONSTACK;
    663 	else if (bss->ss_flags & SS_DISABLE)
    664 	    lss->ss_flags = LINUX_SS_DISABLE;
    665 	else
    666 	    lss->ss_flags = 0;
    667 }
    668 
    669 int
    670 linux_sys_sigaltstack(p, v, retval)
    671 	struct proc *p;
    672 	void *v;
    673 	register_t *retval;
    674 {
    675 	struct linux_sys_sigaltstack_args /* {
    676 		syscallarg(const struct linux_sigaltstack *) ss;
    677 		syscallarg(struct linux_sigaltstack *) oss;
    678 	} */ *uap = v;
    679 	struct linux_sigaltstack ss;
    680 	struct sigaltstack nss, oss;
    681 	int error;
    682 
    683 	if (SCARG(uap, ss) != NULL) {
    684 		if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
    685 			return error;
    686 		linux_to_native_sigaltstack(&nss, &ss);
    687 	}
    688 
    689 	error = sigaltstack1(p,
    690 	    SCARG(uap, ss) ? &nss : NULL, SCARG(uap, oss) ? &oss : NULL);
    691 	if (error)
    692 		return error;
    693 
    694 	if (SCARG(uap, oss) != NULL) {
    695 		native_to_linux_sigaltstack(&ss, &oss);
    696 		if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
    697 			return error;
    698 	}
    699 	return 0;
    700 }
    701 #endif
    702