From owner-p4-projects@FreeBSD.ORG Mon Jul 31 15:20:32 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2E9EA16A4DF; Mon, 31 Jul 2006 15:20:32 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E8D1516A4DA for ; Mon, 31 Jul 2006 15:20:31 +0000 (UTC) (envelope-from rdivacky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 60D1443D49 for ; Mon, 31 Jul 2006 15:20:31 +0000 (GMT) (envelope-from rdivacky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k6VFKVTx034262 for ; Mon, 31 Jul 2006 15:20:31 GMT (envelope-from rdivacky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k6VFKVIR034259 for perforce@freebsd.org; Mon, 31 Jul 2006 15:20:31 GMT (envelope-from rdivacky@FreeBSD.org) Date: Mon, 31 Jul 2006 15:20:31 GMT Message-Id: <200607311520.k6VFKVIR034259@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to rdivacky@FreeBSD.org using -f From: Roman Divacky To: Perforce Change Reviews Cc: Subject: PERFORCE change 102852 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jul 2006 15:20:32 -0000 http://perforce.freebsd.org/chv.cgi?CH=102852 Change 102852 by rdivacky@rdivacky_witten on 2006/07/31 15:20:02 Implementation of exit_group() syscall. This might be changed later (the way I kill the processes). Affected files ... .. //depot/projects/soc2006/rdivacky_linuxolator/i386/linux/linux.h#14 edit .. //depot/projects/soc2006/rdivacky_linuxolator/i386/linux/linux_machdep.c#27 edit Differences ... ==== //depot/projects/soc2006/rdivacky_linuxolator/i386/linux/linux.h#14 (text+ko) ==== @@ -783,6 +783,8 @@ struct linux_emuldata_shared { int refs; pid_t group_pid; + + LIST_HEAD(, linux_emuldata) threads; /* head of list of linux threads */ }; /* modeled after similar structure in NetBSD @@ -797,6 +799,8 @@ struct linux_emuldata_shared *shared; SLIST_ENTRY(linux_emuldata) emuldatas; + + LIST_ENTRY(linux_emuldata) threads; /* list of linux threads */ }; #define EMUL_RLOCK(l) rw_rlock(l) ==== //depot/projects/soc2006/rdivacky_linuxolator/i386/linux/linux_machdep.c#27 (text+ko) ==== @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -1184,12 +1185,16 @@ em->shared = s; s->refs = 1; s->group_pid = child; + + LIST_INIT(&s->threads); } } - if (child != 0) + + if (child != 0) { + LIST_INSERT_HEAD(&em->shared->threads, em, threads); EMUL_WUNLOCK(&emul_lock); - else + } else EMUL_RUNLOCK(&emul_lock); @@ -1249,6 +1254,7 @@ * will exit on different cpus etc. */ EMUL_WLOCK(&emul_lock); + LIST_REMOVE(em, threads); SLIST_REMOVE(&emuldata_head, em, linux_emuldata, emuldatas); EMUL_WUNLOCK(&emul_lock); @@ -1344,3 +1350,46 @@ EMUL_RUNLOCK(&emul_lock); return 0; } + +int +linux_exit_group(struct thread *td, struct linux_exit_group_args *args) +{ + struct linux_emuldata *em, *td_em; + struct proc *sp; + struct kill_args ka; + int i = 0; + + td_em = em_find(td->td_proc->p_pid, EMUL_UNLOCKED); + + if (td_em == NULL) { +#ifdef DEBUG + printf(LMSG("we didnt find emuldata in exit_group.")); +#endif + return (0); + } + + LIST_FOREACH(em, &td_em->shared->threads, threads) { + if (i++ > 10) + break; + + if (em->pid == td_em->pid) + continue; + + sp = pfind(em->pid); + PROC_UNLOCK(sp); +#ifdef DEBUG + printf(LMSG("linux_sys_exit_group: kill PID %d\n"), em->pid); +#endif + ka.pid = em->pid; + ka.signum = SIGKILL; + /* XXX: ehm? */ + kill(FIRST_THREAD_IN_PROC(sp), &ka); + + } + + EMUL_RUNLOCK(&emul_lock); + + exit1(td, W_EXITCODE(args->error_code,0)); + + return (0); +}