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