linux_signal.c revision 1.49.20.3 1 /* $NetBSD: linux_signal.c,v 1.49.20.3 2007/01/19 20:18:46 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.3 2007/01/19 20:18:46 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 struct proc *p = l->l_proc;
359 linux_old_sigset_t nlss, olss;
360 sigset_t nbss, obss;
361 int error;
362
363 switch (how) {
364 case LINUX_SIG_BLOCK:
365 how = SIG_BLOCK;
366 break;
367 case LINUX_SIG_UNBLOCK:
368 how = SIG_UNBLOCK;
369 break;
370 case LINUX_SIG_SETMASK:
371 how = SIG_SETMASK;
372 break;
373 default:
374 return (EINVAL);
375 }
376
377 if (set) {
378 error = copyin(set, &nlss, sizeof(nlss));
379 if (error)
380 return (error);
381 linux_old_to_native_sigset(&nbss, &nlss);
382 }
383 mutex_enter(&p->p_smutex);
384 error = sigprocmask1(l, how,
385 set ? &nbss : NULL, oset ? &obss : NULL);
386 mutex_exit(&p->p_smutex);
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(struct lwp *l, void *v, register_t *retval)
400 {
401 struct linux_sys_rt_sigprocmask_args /* {
402 syscallarg(int) how;
403 syscallarg(const linux_sigset_t *) set;
404 syscallarg(linux_sigset_t *) oset;
405 syscallarg(size_t) sigsetsize;
406 } */ *uap = v;
407 linux_sigset_t nlss, olss, *oset;
408 const linux_sigset_t *set;
409 struct proc *p = l->l_proc;
410 sigset_t nbss, obss;
411 int error, how;
412
413 if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
414 return (EINVAL);
415
416 switch (SCARG(uap, how)) {
417 case LINUX_SIG_BLOCK:
418 how = SIG_BLOCK;
419 break;
420 case LINUX_SIG_UNBLOCK:
421 how = SIG_UNBLOCK;
422 break;
423 case LINUX_SIG_SETMASK:
424 how = SIG_SETMASK;
425 break;
426 default:
427 return (EINVAL);
428 }
429
430 set = SCARG(uap, set);
431 oset = SCARG(uap, oset);
432
433 if (set) {
434 error = copyin(set, &nlss, sizeof(nlss));
435 if (error)
436 return (error);
437 linux_to_native_sigset(&nbss, &nlss);
438 }
439 mutex_enter(&p->p_smutex);
440 error = sigprocmask1(l, how,
441 set ? &nbss : NULL, oset ? &obss : NULL);
442 mutex_exit(&p->p_smutex);
443 if (!error && oset) {
444 native_to_linux_sigset(&olss, &obss);
445 error = copyout(&olss, oset, sizeof(olss));
446 }
447 return (error);
448 }
449
450 int
451 linux_sys_rt_sigpending(struct lwp *l, void *v, register_t *retval)
452 {
453 struct linux_sys_rt_sigpending_args /* {
454 syscallarg(linux_sigset_t *) set;
455 syscallarg(size_t) sigsetsize;
456 } */ *uap = v;
457 sigset_t bss;
458 linux_sigset_t lss;
459
460 if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
461 return (EINVAL);
462
463 sigpending1(l, &bss);
464 native_to_linux_sigset(&lss, &bss);
465 return copyout(&lss, SCARG(uap, set), sizeof(lss));
466 }
467
468 #ifndef __amd64__
469 int
470 linux_sys_sigpending(struct lwp *l, void *v, register_t *retval)
471 {
472 struct linux_sys_sigpending_args /* {
473 syscallarg(linux_old_sigset_t *) mask;
474 } */ *uap = v;
475 sigset_t bss;
476 linux_old_sigset_t lss;
477
478 sigpending1(l, &bss);
479 native_to_linux_old_sigset(&lss, &bss);
480 return copyout(&lss, SCARG(uap, set), sizeof(lss));
481 }
482
483 int
484 linux_sys_sigsuspend(struct lwp *l, void *v, register_t *retval)
485 {
486 struct linux_sys_sigsuspend_args /* {
487 syscallarg(caddr_t) restart;
488 syscallarg(int) oldmask;
489 syscallarg(int) mask;
490 } */ *uap = v;
491 linux_old_sigset_t lss;
492 sigset_t bss;
493
494 lss = SCARG(uap, mask);
495 linux_old_to_native_sigset(&bss, &lss);
496 return (sigsuspend1(l, &bss));
497 }
498 #endif /* __amd64__ */
499
500 int
501 linux_sys_rt_sigsuspend(struct lwp *l, void *v, register_t *retval)
502 {
503 struct linux_sys_rt_sigsuspend_args /* {
504 syscallarg(linux_sigset_t *) unewset;
505 syscallarg(size_t) sigsetsize;
506 } */ *uap = v;
507 linux_sigset_t lss;
508 sigset_t bss;
509 int error;
510
511 if (SCARG(uap, sigsetsize) != sizeof(linux_sigset_t))
512 return (EINVAL);
513
514 error = copyin(SCARG(uap, unewset), &lss, sizeof(linux_sigset_t));
515 if (error)
516 return (error);
517
518 linux_to_native_sigset(&bss, &lss);
519
520 return (sigsuspend1(l, &bss));
521 }
522
523 /*
524 * Once more: only a signal conversion is needed.
525 * Note: also used as sys_rt_queueinfo. The info field is ignored.
526 */
527 int
528 linux_sys_rt_queueinfo(l, v, retval)
529 struct lwp *l;
530 void *v;
531 register_t *retval;
532 {
533 /* XXX XAX This isn't this really int, int, siginfo_t *, is it? */
534 #if 0
535 struct linux_sys_rt_queueinfo_args /* {
536 syscallarg(int) pid;
537 syscallarg(int) signum;
538 syscallarg(siginfo_t *) uinfo;
539 } */ *uap = v;
540 #endif
541
542 /* XXX To really implement this we need to */
543 /* XXX keep a list of queued signals somewhere. */
544 return (linux_sys_kill(l, v, retval));
545 }
546
547 int
548 linux_sys_kill(l, v, retval)
549 struct lwp *l;
550 void *v;
551 register_t *retval;
552 {
553 struct linux_sys_kill_args /* {
554 syscallarg(int) pid;
555 syscallarg(int) signum;
556 } */ *uap = v;
557
558 struct sys_kill_args ka;
559 int sig;
560
561 SCARG(&ka, pid) = SCARG(uap, pid);
562 sig = SCARG(uap, signum);
563 if (sig < 0 || sig >= LINUX__NSIG)
564 return (EINVAL);
565 SCARG(&ka, signum) = linux_to_native_signo[sig];
566 return sys_kill(l, &ka, retval);
567 }
568
569 #ifdef LINUX_SS_ONSTACK
570 static void linux_to_native_sigaltstack __P((struct sigaltstack *,
571 const struct linux_sigaltstack *));
572
573 static void
574 linux_to_native_sigaltstack(bss, lss)
575 struct sigaltstack *bss;
576 const struct linux_sigaltstack *lss;
577 {
578 bss->ss_sp = lss->ss_sp;
579 bss->ss_size = lss->ss_size;
580 if (lss->ss_flags & LINUX_SS_ONSTACK)
581 bss->ss_flags = SS_ONSTACK;
582 else if (lss->ss_flags & LINUX_SS_DISABLE)
583 bss->ss_flags = SS_DISABLE;
584 else
585 bss->ss_flags = 0;
586 }
587
588 void
589 native_to_linux_sigaltstack(lss, bss)
590 struct linux_sigaltstack *lss;
591 const struct sigaltstack *bss;
592 {
593 lss->ss_sp = bss->ss_sp;
594 lss->ss_size = bss->ss_size;
595 if (bss->ss_flags & SS_ONSTACK)
596 lss->ss_flags = LINUX_SS_ONSTACK;
597 else if (bss->ss_flags & SS_DISABLE)
598 lss->ss_flags = LINUX_SS_DISABLE;
599 else
600 lss->ss_flags = 0;
601 }
602
603 int
604 linux_sys_sigaltstack(struct lwp *l, void *v, register_t *retval)
605 {
606 struct linux_sys_sigaltstack_args /* {
607 syscallarg(const struct linux_sigaltstack *) ss;
608 syscallarg(struct linux_sigaltstack *) oss;
609 } */ *uap = v;
610 struct linux_sigaltstack ss;
611 struct sigaltstack nss;
612 struct proc *p = l->l_proc;
613 int error = 0;
614
615 if (SCARG(uap, oss)) {
616 native_to_linux_sigaltstack(&ss, l->l_sigstk);
617 if ((error = copyout(&ss, SCARG(uap, oss), sizeof(ss))) != 0)
618 return error;
619 }
620
621 if (SCARG(uap, ss) != NULL) {
622 if ((error = copyin(SCARG(uap, ss), &ss, sizeof(ss))) != 0)
623 return error;
624 linux_to_native_sigaltstack(&nss, &ss);
625
626 mutex_enter(&p->p_smutex);
627
628 if (nss.ss_flags & ~SS_ALLBITS)
629 error = EINVAL;
630 else if (nss.ss_flags & SS_DISABLE) {
631 if (l->l_sigstk->ss_flags & SS_ONSTACK)
632 error = EINVAL;
633 } else if (nss.ss_size < LINUX_MINSIGSTKSZ)
634 error = ENOMEM;
635
636 if (error == 0)
637 *l->l_sigstk = nss;
638
639 mutex_exit(&p->p_smutex);
640 }
641
642 return error;
643 }
644 #endif /* LINUX_SS_ONSTACK */
645
646 #ifdef LINUX_NPTL
647 int
648 linux_sys_tkill(l, v, retval)
649 struct lwp *l;
650 void *v;
651 register_t *retval;
652 {
653 struct linux_sys_tkill_args /* {
654 syscallarg(int) tid;
655 syscallarg(int) sig;
656 } */ *uap = v;
657 struct linux_sys_kill_args cup;
658
659 /* We use the PID as the TID ... */
660 SCARG(&cup, pid) = SCARG(uap, tid);
661 SCARG(&cup, signum) = SCARG(uap, sig);
662
663 return linux_sys_kill(l, &cup, retval);
664 }
665
666 int
667 linux_sys_tgkill(l, v, retval)
668 struct lwp *l;
669 void *v;
670 register_t *retval;
671 {
672 struct linux_sys_tgkill_args /* {
673 syscallarg(int) tgid;
674 syscallarg(int) tid;
675 syscallarg(int) sig;
676 } */ *uap = v;
677 struct linux_sys_kill_args cup;
678 struct linux_emuldata *led;
679 struct proc *p;
680
681 SCARG(&cup, pid) = SCARG(uap, tid);
682 SCARG(&cup, signum) = SCARG(uap, sig);
683
684 if (SCARG(uap, tgid) == -1)
685 return linux_sys_kill(l, &cup, retval);
686
687 /* We use the PID as the TID, but make sure the group ID is right */
688 if ((p = pfind(SCARG(uap, tid))) == NULL)
689 return ESRCH;
690
691 if (p->p_emul != &emul_linux)
692 return ESRCH;
693
694 led = p->p_emuldata;
695
696 if (led->s->group_pid != SCARG(uap, tgid))
697 return ESRCH;
698
699 return linux_sys_kill(l, &cup, retval);
700 }
701 #endif /* LINUX_NPTL */
702