linux_signal.c revision 1.49.20.2 1 /* $NetBSD: linux_signal.c,v 1.49.20.2 2006/11/18 21:39:08 ad 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.49.20.2 2006/11/18 21:39:08 ad 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/sa.h>
75 #include <sys/syscallargs.h>
76
77 #include <compat/linux/common/linux_types.h>
78 #include <compat/linux/common/linux_signal.h>
79 #include <compat/linux/common/linux_exec.h> /* For emul_linux */
80 #include <compat/linux/common/linux_machdep.h> /* For LINUX_NPTL */
81 #include <compat/linux/common/linux_emuldata.h> /* for linux_emuldata */
82 #include <compat/linux/common/linux_siginfo.h>
83 #include <compat/linux/common/linux_sigevent.h>
84 #include <compat/linux/common/linux_util.h>
85
86 #include <compat/linux/linux_syscallargs.h>
87
88 /* Locally used defines (in bsd<->linux conversion functions): */
89 #define linux_sigemptyset(s) memset((s), 0, sizeof(*(s)))
90 #define linux_sigismember(s, n) ((s)->sig[((n) - 1) / LINUX__NSIG_BPW] \
91 & (1 << ((n) - 1) % LINUX__NSIG_BPW))
92 #define linux_sigaddset(s, n) ((s)->sig[((n) - 1) / LINUX__NSIG_BPW] \
93 |= (1 << ((n) - 1) % LINUX__NSIG_BPW))
94
95 #ifdef DEBUG_LINUX
96 #define DPRINTF(a) uprintf a
97 #else
98 #define DPRINTF(a)
99 #endif
100
101 extern const int native_to_linux_signo[];
102 extern const int linux_to_native_signo[];
103
104 /*
105 * Convert between Linux and BSD signal sets.
106 */
107 #if LINUX__NSIG_WORDS > 1
108 void
109 linux_old_extra_to_native_sigset(bss, lss, extra)
110 sigset_t *bss;
111 const linux_old_sigset_t *lss;
112 const unsigned long *extra;
113 {
114 linux_sigset_t lsnew;
115
116 /* convert old sigset to new sigset */
117 linux_sigemptyset(&lsnew);
118 lsnew.sig[0] = *lss;
119 if (extra)
120 memcpy(&lsnew.sig[1], extra,
121 sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
122
123 linux_to_native_sigset(bss, &lsnew);
124 }
125
126 void
127 native_to_linux_old_extra_sigset(lss, extra, bss)
128 linux_old_sigset_t *lss;
129 unsigned long *extra;
130 const sigset_t *bss;
131 {
132 linux_sigset_t lsnew;
133
134 native_to_linux_sigset(&lsnew, bss);
135
136 /* convert new sigset to old sigset */
137 *lss = lsnew.sig[0];
138 if (extra)
139 memcpy(extra, &lsnew.sig[1],
140 sizeof(linux_sigset_t) - sizeof(linux_old_sigset_t));
141 }
142 #endif /* LINUX__NSIG_WORDS > 1 */
143
144 void
145 linux_to_native_sigset(bss, lss)
146 sigset_t *bss;
147 const linux_sigset_t *lss;
148 {
149 int i, newsig;
150
151 sigemptyset(bss);
152 for (i = 1; i < LINUX__NSIG; i++) {
153 if (linux_sigismember(lss, i)) {
154 newsig = linux_to_native_signo[i];
155 if (newsig)
156 sigaddset(bss, newsig);
157 }
158 }
159 }
160
161 void
162 native_to_linux_sigset(lss, bss)
163 linux_sigset_t *lss;
164 const sigset_t *bss;
165 {
166 int i, newsig;
167
168 linux_sigemptyset(lss);
169 for (i = 1; i < NSIG; i++) {
170 if (sigismember(bss, i)) {
171 newsig = native_to_linux_signo[i];
172 if (newsig)
173 linux_sigaddset(lss, newsig);
174 }
175 }
176 }
177
178 unsigned int
179 native_to_linux_sigflags(bsf)
180 const int bsf;
181 {
182 unsigned int lsf = 0;
183 if ((bsf & SA_NOCLDSTOP) != 0)
184 lsf |= LINUX_SA_NOCLDSTOP;
185 if ((bsf & SA_NOCLDWAIT) != 0)
186 lsf |= LINUX_SA_NOCLDWAIT;
187 if ((bsf & SA_ONSTACK) != 0)
188 lsf |= LINUX_SA_ONSTACK;
189 if ((bsf & SA_RESTART) != 0)
190 lsf |= LINUX_SA_RESTART;
191 if ((bsf & SA_NODEFER) != 0)
192 lsf |= LINUX_SA_NOMASK;
193 if ((bsf & SA_RESETHAND) != 0)
194 lsf |= LINUX_SA_ONESHOT;
195 if ((bsf & SA_SIGINFO) != 0)
196 lsf |= LINUX_SA_SIGINFO;
197 return lsf;
198 }
199
200 int
201 linux_to_native_sigflags(lsf)
202 const unsigned long lsf;
203 {
204 int bsf = 0;
205 if ((lsf & LINUX_SA_NOCLDSTOP) != 0)
206 bsf |= SA_NOCLDSTOP;
207 if ((lsf & LINUX_SA_NOCLDWAIT) != 0)
208 bsf |= SA_NOCLDWAIT;
209 if ((lsf & LINUX_SA_ONSTACK) != 0)
210 bsf |= SA_ONSTACK;
211 if ((lsf & LINUX_SA_RESTART) != 0)
212 bsf |= SA_RESTART;
213 if ((lsf & LINUX_SA_ONESHOT) != 0)
214 bsf |= SA_RESETHAND;
215 if ((lsf & LINUX_SA_NOMASK) != 0)
216 bsf |= SA_NODEFER;
217 if ((lsf & LINUX_SA_SIGINFO) != 0)
218 bsf |= SA_SIGINFO;
219 if ((lsf & ~LINUX_SA_ALLBITS) != 0) {
220 DPRINTF(("linux_old_to_native_sigflags: "
221 "%lx extra bits ignored\n", lsf));
222 }
223 return bsf;
224 }
225
226 /*
227 * Convert between Linux and BSD sigaction structures.
228 */
229 void
230 linux_old_to_native_sigaction(bsa, lsa)
231 struct sigaction *bsa;
232 const struct linux_old_sigaction *lsa;
233 {
234 bsa->sa_handler = lsa->linux_sa_handler;
235 linux_old_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
236 bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
237 }
238
239 void
240 native_to_linux_old_sigaction(lsa, bsa)
241 struct linux_old_sigaction *lsa;
242 const struct sigaction *bsa;
243 {
244 lsa->linux_sa_handler = bsa->sa_handler;
245 native_to_linux_old_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
246 lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
247 #ifndef __alpha__
248 lsa->linux_sa_restorer = NULL;
249 #endif
250 }
251
252 /* ...and the new sigaction conversion funcs. */
253 void
254 linux_to_native_sigaction(bsa, lsa)
255 struct sigaction *bsa;
256 const struct linux_sigaction *lsa;
257 {
258 bsa->sa_handler = lsa->linux_sa_handler;
259 linux_to_native_sigset(&bsa->sa_mask, &lsa->linux_sa_mask);
260 bsa->sa_flags = linux_to_native_sigflags(lsa->linux_sa_flags);
261 }
262
263 void
264 native_to_linux_sigaction(lsa, bsa)
265 struct linux_sigaction *lsa;
266 const struct sigaction *bsa;
267 {
268 lsa->linux_sa_handler = bsa->sa_handler;
269 native_to_linux_sigset(&lsa->linux_sa_mask, &bsa->sa_mask);
270 lsa->linux_sa_flags = native_to_linux_sigflags(bsa->sa_flags);
271 #ifndef __alpha__
272 lsa->linux_sa_restorer = NULL;
273 #endif
274 }
275
276 /* ----------------------------------------------------------------------- */
277
278 /*
279 * The Linux sigaction() system call. Do the usual conversions,
280 * and just call sigaction(). Some flags and values are silently
281 * ignored (see above).
282 */
283 int
284 linux_sys_rt_sigaction(struct lwp *l, void *v, register_t *retval)
285 {
286 struct linux_sys_rt_sigaction_args /* {
287 syscallarg(int) signum;
288 syscallarg(const struct linux_sigaction *) nsa;
289 syscallarg(struct linux_sigaction *) osa;
290 syscallarg(size_t) sigsetsize;
291 } */ *uap = v;
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 = l->l_proc->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(l, 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(l, how, set, oset)
353 struct lwp *l;
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(l, 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)
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 linux_sigset_t nlss, olss, *oset;
405 const linux_sigset_t *set;
406 sigset_t nbss, obss;
407 int error, how;
408
409 if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
410 return (EINVAL);
411
412 switch (SCARG(uap, how)) {
413 case LINUX_SIG_BLOCK:
414 how = SIG_BLOCK;
415 break;
416 case LINUX_SIG_UNBLOCK:
417 how = SIG_UNBLOCK;
418 break;
419 case LINUX_SIG_SETMASK:
420 how = SIG_SETMASK;
421 break;
422 default:
423 return (EINVAL);
424 }
425
426 set = SCARG(uap, set);
427 oset = SCARG(uap, oset);
428
429 if (set) {
430 error = copyin(set, &nlss, sizeof(nlss));
431 if (error)
432 return (error);
433 linux_to_native_sigset(&nbss, &nlss);
434 }
435 error = sigprocmask1(l, how,
436 set ? &nbss : NULL, oset ? &obss : NULL);
437 if (!error && oset) {
438 native_to_linux_sigset(&olss, &obss);
439 error = copyout(&olss, oset, sizeof(olss));
440 }
441 return (error);
442 }
443
444 int
445 linux_sys_rt_sigpending(struct lwp *l, void *v, register_t *retval)
446 {
447 struct linux_sys_rt_sigpending_args /* {
448 syscallarg(linux_sigset_t *) set;
449 syscallarg(size_t) sigsetsize;
450 } */ *uap = v;
451 sigset_t bss;
452 linux_sigset_t lss;
453
454 if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
455 return (EINVAL);
456
457 sigpending1(l, &bss);
458 native_to_linux_sigset(&lss, &bss);
459 return copyout(&lss, SCARG(uap, set), sizeof(lss));
460 }
461
462 #ifndef __amd64__
463 int
464 linux_sys_sigpending(struct lwp *l, void *v, register_t *retval)
465 {
466 struct linux_sys_sigpending_args /* {
467 syscallarg(linux_old_sigset_t *) mask;
468 } */ *uap = v;
469 sigset_t bss;
470 linux_old_sigset_t lss;
471
472 sigpending1(l, &bss);
473 native_to_linux_old_sigset(&lss, &bss);
474 return copyout(&lss, SCARG(uap, set), sizeof(lss));
475 }
476
477 int
478 linux_sys_sigsuspend(struct lwp *l, void *v, register_t *retval)
479 {
480 struct linux_sys_sigsuspend_args /* {
481 syscallarg(caddr_t) restart;
482 syscallarg(int) oldmask;
483 syscallarg(int) mask;
484 } */ *uap = v;
485 linux_old_sigset_t lss;
486 sigset_t bss;
487
488 lss = SCARG(uap, mask);
489 linux_old_to_native_sigset(&bss, &lss);
490 return (sigsuspend1(l, &bss));
491 }
492 #endif /* __amd64__ */
493
494 int
495 linux_sys_rt_sigsuspend(struct lwp *l, void *v, register_t *retval)
496 {
497 struct linux_sys_rt_sigsuspend_args /* {
498 syscallarg(linux_sigset_t *) unewset;
499 syscallarg(size_t) sigsetsize;
500 } */ *uap = v;
501 linux_sigset_t lss;
502 sigset_t bss;
503 int error;
504
505 if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
506 return (EINVAL);
507
508 error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
509 if (error)
510 return (error);
511
512 linux_to_native_sigset(&bss, &lss);
513
514 return (sigsuspend1(l, &bss));
515 }
516
517 /*
518 * Once more: only a signal conversion is needed.
519 * Note: also used as sys_rt_queueinfo. The info field is ignored.
520 */
521 int
522 linux_sys_rt_queueinfo(l, v, retval)
523 struct lwp *l;
524 void *v;
525 register_t *retval;
526 {
527 /* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
528 #if 0
529 struct linux_sys_rt_queueinfo_args /* {
530 syscallarg(int) pid;
531 syscallarg(int) signum;
532 syscallarg(siginfo_t *) uinfo;
533 } */ *uap = v;
534 #endif
535
536 /* XXX To really implement this we need to */
537 /* XXX keep a list of queued signals somewhere. */
538 return (linux_sys_kill(l, v, retval));
539 }
540
541 int
542 linux_sys_kill(l, v, retval)
543 struct lwp *l;
544 void *v;
545 register_t *retval;
546 {
547 struct linux_sys_kill_args /* {
548 syscallarg(int) pid;
549 syscallarg(int) signum;
550 } */ *uap = v;
551
552 struct sys_kill_args ka;
553 int sig;
554
555 SCARG(&ka, pid) = SCARG(uap, pid);
556 sig = SCARG(uap, signum);
557 if (sig < 0 || sig >= LINUX__NSIG)
558 return (EINVAL);
559 SCARG(&ka, signum) = linux_to_native_signo[sig];
560 return sys_kill(l, &ka, retval);
561 }
562
563 #ifdef LINUX_SS_ONSTACK
564 static void linux_to_native_sigaltstack __P((struct sigaltstack *,
565 const struct linux_sigaltstack *));
566
567 static void
568 linux_to_native_sigaltstack(bss, lss)
569 struct sigaltstack *bss;
570 const struct linux_sigaltstack *lss;
571 {
572 bss->ss_sp = lss->ss_sp;
573 bss->ss_size = lss->ss_size;
574 if (lss->ss_flags & LINUX_SS_ONSTACK)
575 bss->ss_flags = SS_ONSTACK;
576 else if (lss->ss_flags & LINUX_SS_DISABLE)
577 bss->ss_flags = SS_DISABLE;
578 else
579 bss->ss_flags = 0;
580 }
581
582 void
583 native_to_linux_sigaltstack(lss, bss)
584 struct linux_sigaltstack *lss;
585 const struct sigaltstack *bss;
586 {
587 lss->ss_sp = bss->ss_sp;
588 lss->ss_size = bss->ss_size;
589 if (bss->ss_flags & SS_ONSTACK)
590 lss->ss_flags = LINUX_SS_ONSTACK;
591 else if (bss->ss_flags & SS_DISABLE)
592 lss->ss_flags = LINUX_SS_DISABLE;
593 else
594 lss->ss_flags = 0;
595 }
596
597 int
598 linux_sys_sigaltstack(struct lwp *l, void *v, register_t *retval)
599 {
600 struct linux_sys_sigaltstack_args /* {
601 syscallarg(const struct linux_sigaltstack *) ss;
602 syscallarg(struct linux_sigaltstack *) oss;
603 } */ *uap = v;
604 struct linux_sigaltstack ss;
605 struct sigaltstack nss;
606 struct proc *p = l->l_proc;
607 int error = 0;
608
609 if (SCARG(uap, oss)) {
610 native_to_linux_sigaltstack(&ss, l->l_sigstk);
611 if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
612 return error;
613 }
614
615 if (SCARG(uap, ss) != NULL) {
616 if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
617 return error;
618 linux_to_native_sigaltstack(&nss, &ss);
619
620 mutex_enter(&p->p_smutex);
621
622 if (nss.ss_flags & ~SS_ALLBITS)
623 error = EINVAL;
624 else if (nss.ss_flags & SS_DISABLE) {
625 if (l->l_sigstk->ss_flags & SS_ONSTACK)
626 error = EINVAL;
627 } else if (nss.ss_size < LINUX_MINSIGSTKSZ)
628 error = ENOMEM;
629
630 if (error == 0)
631 *l->l_sigstk = nss;
632
633 mutex_exit(&p->p_smutex);
634 }
635
636 return error;
637 }
638 #endif /* LINUX_SS_ONSTACK */
639
640 #ifdef LINUX_NPTL
641 int
642 linux_sys_tkill(l, v, retval)
643 struct lwp *l;
644 void *v;
645 register_t *retval;
646 {
647 struct linux_sys_tkill_args /* {
648 syscallarg(int) tid;
649 syscallarg(int) sig;
650 } */ *uap = v;
651 struct linux_sys_kill_args cup;
652
653 /* We use the PID as the TID ... */
654 SCARG(&cup, pid) = SCARG(uap, tid);
655 SCARG(&cup, signum) = SCARG(uap, sig);
656
657 return linux_sys_kill(l, &cup, retval);
658 }
659
660 int
661 linux_sys_tgkill(l, v, retval)
662 struct lwp *l;
663 void *v;
664 register_t *retval;
665 {
666 struct linux_sys_tgkill_args /* {
667 syscallarg(int) tgid;
668 syscallarg(int) tid;
669 syscallarg(int) sig;
670 } */ *uap = v;
671 struct linux_sys_kill_args cup;
672 struct linux_emuldata *led;
673 struct proc *p;
674
675 SCARG(&cup, pid) = SCARG(uap, tid);
676 SCARG(&cup, signum) = SCARG(uap, sig);
677
678 if (SCARG(uap, tgid) == -1)
679 return linux_sys_kill(l, &cup, retval);
680
681 /* We use the PID as the TID, but make sure the group ID is right */
682 if ((p = pfind(SCARG(uap, tid))) == NULL)
683 return ESRCH;
684
685 if (p->p_emul != &emul_linux)
686 return ESRCH;
687
688 led = p->p_emuldata;
689
690 if (led->s->group_pid != SCARG(uap, tgid))
691 return ESRCH;
692
693 return linux_sys_kill(l, &cup, retval);
694 }
695 #endif /* LINUX_NPTL */
696