xref: /netbsd-src/sys/compat/linux/common/linux_signal.c (revision bfb6cb13d599546df69c7e4d20d70e22e15a549d)
1 /*	$NetBSD: linux_signal.c,v 1.54 2007/03/04 06:01:24 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Frank van der Linden and Eric Haszlakiewicz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 /*
39  * heavily from: svr4_signal.c,v 1.7 1995/01/09 01:04:21 christos Exp
40  */
41 
42 /*
43  *   Functions in multiarch:
44  *	linux_sys_signal	: linux_sig_notalpha.c
45  *	linux_sys_siggetmask	: linux_sig_notalpha.c
46  *	linux_sys_sigsetmask	: linux_sig_notalpha.c
47  *	linux_sys_pause		: linux_sig_notalpha.c
48  *	linux_sys_sigaction	: linux_sigaction.c
49  *
50  */
51 
52 /*
53  *   Unimplemented:
54  *	linux_sys_rt_sigtimedwait	: sigsuspend w/timeout.
55  */
56 
57 #include <sys/cdefs.h>
58 __KERNEL_RCSID(0, "$NetBSD: linux_signal.c,v 1.54 2007/03/04 06:01:24 christos Exp $");
59 
60 #define COMPAT_LINUX 1
61 
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/namei.h>
65 #include <sys/proc.h>
66 #include <sys/filedesc.h>
67 #include <sys/ioctl.h>
68 #include <sys/mount.h>
69 #include <sys/kernel.h>
70 #include <sys/signal.h>
71 #include <sys/signalvar.h>
72 #include <sys/malloc.h>
73 
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)
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 linux_sigaction nlsa, olsa;
292 	struct sigaction nbsa, obsa;
293 	int error, sig;
294 	void *tramp = NULL;
295 	int vers = 0;
296 #if defined __amd64__
297 	struct sigacts *ps = l->l_proc->p_sigacts;
298 #endif
299 
300 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
301 		return (EINVAL);
302 
303 	if (SCARG(uap, nsa)) {
304 		error = copyin(SCARG(uap, nsa), &nlsa, sizeof(nlsa));
305 		if (error)
306 			return (error);
307 		linux_to_native_sigaction(&nbsa, &nlsa);
308 	}
309 
310 	sig = SCARG(uap, signum);
311 	if (sig < 0 || sig >= LINUX__NSIG)
312 		return (EINVAL);
313 	if (sig > 0 && !linux_to_native_signo[sig]) {
314 		/* Pretend that we did something useful for unknown signals. */
315 		obsa.sa_handler = SIG_IGN;
316 		sigemptyset(&obsa.sa_mask);
317 		obsa.sa_flags = 0;
318 	} else {
319 #if defined __amd64__
320 		if (nlsa.linux_sa_flags & LINUX_SA_RESTORER) {
321 			if ((tramp = nlsa.linux_sa_restorer) != NULL)
322 				vers = 2; /* XXX arch dependant */
323 		}
324 #endif
325 
326 		error = sigaction1(l, linux_to_native_signo[sig],
327 		    SCARG(uap, nsa) ? &nbsa : NULL,
328 		    SCARG(uap, osa) ? &obsa : NULL,
329 		    tramp, vers);
330 		if (error)
331 			return (error);
332 	}
333 	if (SCARG(uap, osa)) {
334 		native_to_linux_sigaction(&olsa, &obsa);
335 
336 #if defined __amd64__
337 		if (ps->sa_sigdesc[sig].sd_vers != 0) {
338 			olsa.linux_sa_restorer = ps->sa_sigdesc[sig].sd_tramp;
339 			olsa.linux_sa_flags |= LINUX_SA_RESTORER;
340 		}
341 #endif
342 
343 		error = copyout(&olsa, SCARG(uap, osa), sizeof(olsa));
344 		if (error)
345 			return (error);
346 	}
347 	return (0);
348 }
349 
350 int
351 linux_sigprocmask1(l, how, set, oset)
352 	struct lwp *l;
353 	int how;
354 	const linux_old_sigset_t *set;
355 	linux_old_sigset_t *oset;
356 {
357 	struct proc *p = l->l_proc;
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 	mutex_enter(&p->p_smutex);
383 	error = sigprocmask1(l, how,
384 	    set ? &nbss : NULL, oset ? &obss : NULL);
385 	mutex_exit(&p->p_smutex);
386 	if (error)
387 		return (error);
388 	if (oset) {
389 		native_to_linux_old_sigset(&olss, &obss);
390 		error = copyout(&olss, oset, sizeof(olss));
391 		if (error)
392 			return (error);
393 	}
394 	return (error);
395 }
396 
397 int
398 linux_sys_rt_sigprocmask(struct lwp *l, void *v, register_t *retval)
399 {
400 	struct linux_sys_rt_sigprocmask_args /* {
401 		syscallarg(int) how;
402 		syscallarg(const linux_sigset_t *) set;
403 		syscallarg(linux_sigset_t *) oset;
404 		syscallarg(size_t) sigsetsize;
405 	} */ *uap = v;
406 	linux_sigset_t nlss, olss, *oset;
407 	const linux_sigset_t *set;
408 	struct proc *p = l->l_proc;
409 	sigset_t nbss, obss;
410 	int error, how;
411 
412 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
413 		return (EINVAL);
414 
415 	switch (SCARG(uap, how)) {
416 	case LINUX_SIG_BLOCK:
417 		how = SIG_BLOCK;
418 		break;
419 	case LINUX_SIG_UNBLOCK:
420 		how = SIG_UNBLOCK;
421 		break;
422 	case LINUX_SIG_SETMASK:
423 		how = SIG_SETMASK;
424 		break;
425 	default:
426 		return (EINVAL);
427 	}
428 
429 	set = SCARG(uap, set);
430 	oset = SCARG(uap, oset);
431 
432 	if (set) {
433 		error = copyin(set, &nlss, sizeof(nlss));
434 		if (error)
435 			return (error);
436 		linux_to_native_sigset(&nbss, &nlss);
437 	}
438 	mutex_enter(&p->p_smutex);
439 	error = sigprocmask1(l, how,
440 	    set ? &nbss : NULL, oset ? &obss : NULL);
441 	mutex_exit(&p->p_smutex);
442 	if (!error && oset) {
443 		native_to_linux_sigset(&olss, &obss);
444 		error = copyout(&olss, oset, sizeof(olss));
445 	}
446 	return (error);
447 }
448 
449 int
450 linux_sys_rt_sigpending(struct lwp *l, void *v, register_t *retval)
451 {
452 	struct linux_sys_rt_sigpending_args /* {
453 		syscallarg(linux_sigset_t *) set;
454 		syscallarg(size_t) sigsetsize;
455 	} */ *uap = v;
456 	sigset_t bss;
457 	linux_sigset_t lss;
458 
459 	if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
460 		return (EINVAL);
461 
462 	sigpending1(l, &bss);
463 	native_to_linux_sigset(&lss, &bss);
464 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
465 }
466 
467 #ifndef __amd64__
468 int
469 linux_sys_sigpending(struct lwp *l, void *v, register_t *retval)
470 {
471 	struct linux_sys_sigpending_args /* {
472 		syscallarg(linux_old_sigset_t *) mask;
473 	} */ *uap = v;
474 	sigset_t bss;
475 	linux_old_sigset_t lss;
476 
477 	sigpending1(l, &bss);
478 	native_to_linux_old_sigset(&lss, &bss);
479 	return copyout(&lss, SCARG(uap, set), sizeof(lss));
480 }
481 
482 int
483 linux_sys_sigsuspend(struct lwp *l, void *v, register_t *retval)
484 {
485 	struct linux_sys_sigsuspend_args /* {
486 		syscallarg(void *) restart;
487 		syscallarg(int) oldmask;
488 		syscallarg(int) mask;
489 	} */ *uap = v;
490 	linux_old_sigset_t lss;
491 	sigset_t bss;
492 
493 	lss = SCARG(uap, mask);
494 	linux_old_to_native_sigset(&bss, &lss);
495 	return (sigsuspend1(l, &bss));
496 }
497 #endif /* __amd64__ */
498 
499 int
500 linux_sys_rt_sigsuspend(struct lwp *l, void *v, register_t *retval)
501 {
502 	struct linux_sys_rt_sigsuspend_args /* {
503 		syscallarg(linux_sigset_t *) unewset;
504 		syscallarg(size_t) sigsetsize;
505 	} */ *uap = v;
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(l, &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)
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 linux_sigaltstack ss;
610 	struct sigaltstack nss;
611 	struct proc *p = l->l_proc;
612 	int error = 0;
613 
614 	if (SCARG(uap, oss)) {
615 		native_to_linux_sigaltstack(&ss, &l->l_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 		mutex_enter(&p->p_smutex);
626 
627 		if (nss.ss_flags & ~SS_ALLBITS)
628 			error = EINVAL;
629 		else if (nss.ss_flags & SS_DISABLE) {
630 			if (l->l_sigstk.ss_flags & SS_ONSTACK)
631 				error = EINVAL;
632 		} else if (nss.ss_size < LINUX_MINSIGSTKSZ)
633 			error = ENOMEM;
634 
635 		if (error == 0)
636 			l->l_sigstk = nss;
637 
638 		mutex_exit(&p->p_smutex);
639 	}
640 
641 	return error;
642 }
643 #endif /* LINUX_SS_ONSTACK */
644 
645 #ifdef LINUX_NPTL
646 int
647 linux_sys_tkill(l, v, retval)
648 	struct lwp *l;
649 	void *v;
650 	register_t *retval;
651 {
652 	struct linux_sys_tkill_args /* {
653 		syscallarg(int) tid;
654 		syscallarg(int) sig;
655 	} */ *uap = v;
656 	struct linux_sys_kill_args cup;
657 
658 	/* We use the PID as the TID ... */
659 	SCARG(&cup, pid) = SCARG(uap, tid);
660 	SCARG(&cup, signum) = SCARG(uap, sig);
661 
662 	return linux_sys_kill(l, &cup, retval);
663 }
664 
665 int
666 linux_sys_tgkill(l, v, retval)
667 	struct lwp *l;
668 	void *v;
669 	register_t *retval;
670 {
671 	struct linux_sys_tgkill_args /* {
672 		syscallarg(int) tgid;
673 		syscallarg(int) tid;
674 		syscallarg(int) sig;
675 	} */ *uap = v;
676 	struct linux_sys_kill_args cup;
677 	struct linux_emuldata *led;
678 	struct proc *p;
679 
680 	SCARG(&cup, pid) = SCARG(uap, tid);
681 	SCARG(&cup, signum) = SCARG(uap, sig);
682 
683 	if (SCARG(uap, tgid) == -1)
684 		return linux_sys_kill(l, &cup, retval);
685 
686 	/* We use the PID as the TID, but make sure the group ID is right */
687 	if ((p = pfind(SCARG(uap, tid))) == NULL)
688 		return ESRCH;
689 
690 	if (p->p_emul != &emul_linux)
691 		return ESRCH;
692 
693 	led = p->p_emuldata;
694 
695 	if (led->s->group_pid != SCARG(uap, tgid))
696 		return ESRCH;
697 
698 	return linux_sys_kill(l, &cup, retval);
699 }
700 #endif /* LINUX_NPTL */
701