linux_signal.c (165869) | linux_signal.c (184058) |
---|---|
1/*- 2 * Copyright (c) 1994-1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1994-1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_signal.c 165869 2007-01-07 19:14:06Z netchild $"); | 30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_signal.c 184058 2008-10-19 10:02:26Z kib $"); |
31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/lock.h> 35#include <sys/mutex.h> 36#include <sys/sx.h> 37#include <sys/proc.h> 38#include <sys/signalvar.h> 39#include <sys/syscallsubr.h> 40#include <sys/sysproto.h> 41 | 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/lock.h> 35#include <sys/mutex.h> 36#include <sys/sx.h> 37#include <sys/proc.h> 38#include <sys/signalvar.h> 39#include <sys/syscallsubr.h> 40#include <sys/sysproto.h> 41 |
42#include <security/audit/audit.h> 43 |
|
42#include "opt_compat.h" 43 44#ifdef COMPAT_LINUX32 45#include <machine/../linux32/linux.h> 46#include <machine/../linux32/linux32_proto.h> 47#else 48#include <machine/../linux/linux.h> 49#include <machine/../linux/linux_proto.h> --- 480 unchanged lines hidden (view full) --- 530 tmp.signum = linux_to_bsd_signal[_SIG_IDX(args->signum)]; 531 else 532 tmp.signum = args->signum; 533 534 tmp.pid = args->pid; 535 return (kill(td, &tmp)); 536} 537 | 44#include "opt_compat.h" 45 46#ifdef COMPAT_LINUX32 47#include <machine/../linux32/linux.h> 48#include <machine/../linux32/linux32_proto.h> 49#else 50#include <machine/../linux/linux.h> 51#include <machine/../linux/linux_proto.h> --- 480 unchanged lines hidden (view full) --- 532 tmp.signum = linux_to_bsd_signal[_SIG_IDX(args->signum)]; 533 else 534 tmp.signum = args->signum; 535 536 tmp.pid = args->pid; 537 return (kill(td, &tmp)); 538} 539 |
538int 539linux_tgkill(struct thread *td, struct linux_tgkill_args *args) | 540static int 541linux_do_tkill(struct thread *td, l_int tgid, l_int pid, l_int signum) |
540{ | 542{ |
541 struct linux_emuldata *em; 542 struct linux_kill_args ka; | 543 struct proc *proc = td->td_proc; 544 struct linux_emuldata *em; |
543 struct proc *p; | 545 struct proc *p; |
546 ksiginfo_t ksi; 547 int error; |
|
544 | 548 |
545#ifdef DEBUG 546 if (ldebug(tgkill)) 547 printf(ARGS(tgkill, "%d, %d, %d"), args->tgid, args->pid, args->sig); 548#endif | 549 AUDIT_ARG(signum, signum); 550 AUDIT_ARG(pid, pid); |
549 | 551 |
550 ka.pid = args->pid; 551 ka.signum = args->sig; | 552 /* 553 * Allow signal 0 as a means to check for privileges 554 */ 555 if (!LINUX_SIG_VALID(signum) && signum != 0) 556 return (EINVAL); |
552 | 557 |
553 if (args->tgid == -1) 554 return linux_kill(td, &ka); | 558 if (signum > 0 && signum <= LINUX_SIGTBLSZ) 559 signum = linux_to_bsd_signal[_SIG_IDX(signum)]; |
555 | 560 |
556 if ((p = pfind(args->pid)) == NULL) 557 return ESRCH; | 561 if ((p = pfind(pid)) == NULL) { 562 if ((p = zpfind(pid)) == NULL) 563 return (ESRCH); 564 } |
558 | 565 |
559 if (p->p_sysent != &elf_linux_sysvec) 560 return ESRCH; | 566 AUDIT_ARG(process, p); 567 error = p_cansignal(td, p, signum); 568 if (error) 569 goto out; |
561 | 570 |
562 PROC_UNLOCK(p); 563 | 571 error = ESRCH; |
564 em = em_find(p, EMUL_DONTLOCK); 565 566 if (em == NULL) { 567#ifdef DEBUG | 572 em = em_find(p, EMUL_DONTLOCK); 573 574 if (em == NULL) { 575#ifdef DEBUG |
568 printf("emuldata not found in tgkill.\n"); | 576 printf("emuldata not found in do_tkill.\n"); |
569#endif | 577#endif |
570 return ESRCH; | 578 goto out; |
571 } | 579 } |
580 if (tgid > 0 && em->shared->group_pid != tgid) 581 goto out; |
|
572 | 582 |
573 if (em->shared->group_pid != args->tgid) 574 return ESRCH; | 583 ksiginfo_init(&ksi); 584 ksi.ksi_signo = signum; 585 ksi.ksi_code = LINUX_SI_TKILL; 586 ksi.ksi_errno = 0; 587 ksi.ksi_pid = proc->p_pid; 588 ksi.ksi_uid = proc->p_ucred->cr_ruid; |
575 | 589 |
576 return linux_kill(td, &ka); | 590 error = tdsignal(p, NULL, ksi.ksi_signo, &ksi); 591 592out: 593 PROC_UNLOCK(p); 594 return (error); |
577} 578 579int | 595} 596 597int |
598linux_tgkill(struct thread *td, struct linux_tgkill_args *args) 599{ 600 601#ifdef DEBUG 602 if (ldebug(tgkill)) 603 printf(ARGS(tgkill, "%d, %d, %d"), args->tgid, args->pid, args->sig); 604#endif 605 if (args->pid <= 0 || args->tgid <=0) 606 return (EINVAL); 607 608 return (linux_do_tkill(td, args->tgid, args->pid, args->sig)); 609} 610 611int |
|
580linux_tkill(struct thread *td, struct linux_tkill_args *args) 581{ 582#ifdef DEBUG 583 if (ldebug(tkill)) 584 printf(ARGS(tkill, "%i, %i"), args->tid, args->sig); 585#endif | 612linux_tkill(struct thread *td, struct linux_tkill_args *args) 613{ 614#ifdef DEBUG 615 if (ldebug(tkill)) 616 printf(ARGS(tkill, "%i, %i"), args->tid, args->sig); 617#endif |
618 if (args->tid <= 0) 619 return (EINVAL); |
|
586 | 620 |
587 return (linux_kill(td, (struct linux_kill_args *) args)); | 621 return (linux_do_tkill(td, 0, args->tid, args->sig)); |
588} | 622} |
623 624void 625ksiginfo_to_lsiginfo(ksiginfo_t *ksi, l_siginfo_t *lsi, l_int sig) 626{ 627 628 lsi->lsi_signo = sig; 629 lsi->lsi_code = ksi->ksi_code; 630 631 switch (sig) { 632 case LINUX_SIGPOLL: 633 /* XXX si_fd? */ 634 lsi->lsi_band = ksi->ksi_band; 635 break; 636 case LINUX_SIGCHLD: 637 lsi->lsi_pid = ksi->ksi_pid; 638 lsi->lsi_uid = ksi->ksi_uid; 639 lsi->lsi_status = ksi->ksi_status; 640 break; 641 case LINUX_SIGBUS: 642 case LINUX_SIGILL: 643 case LINUX_SIGFPE: 644 case LINUX_SIGSEGV: 645 lsi->lsi_addr = PTROUT(ksi->ksi_addr); 646 break; 647 default: 648 /* XXX SI_TIMER etc... */ 649 lsi->lsi_pid = ksi->ksi_pid; 650 lsi->lsi_uid = ksi->ksi_uid; 651 break; 652 } 653} |
|