From owner-p4-projects@FreeBSD.ORG Sat Jul 29 09:33:42 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 35EC916A4E0; Sat, 29 Jul 2006 09:33:42 +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 EDE0A16A4DD for ; Sat, 29 Jul 2006 09:33:41 +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 9BE5943D49 for ; Sat, 29 Jul 2006 09:33:41 +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 k6T9Xf7a073751 for ; Sat, 29 Jul 2006 09:33:41 GMT (envelope-from rdivacky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k6T9XfVf073748 for perforce@freebsd.org; Sat, 29 Jul 2006 09:33:41 GMT (envelope-from rdivacky@FreeBSD.org) Date: Sat, 29 Jul 2006 09:33:41 GMT Message-Id: <200607290933.k6T9XfVf073748@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 102710 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: Sat, 29 Jul 2006 09:33:42 -0000 http://perforce.freebsd.org/chv.cgi?CH=102710 Change 102710 by rdivacky@rdivacky_witten on 2006/07/29 09:32:54 Fix the handling of td in linux_proc_init(). td points to parent proc/thread. This fixes panic with realplay. Also, dont leak emul_shared in a case of linux -> fbsd exec. Affected files ... .. //depot/projects/soc2006/rdivacky_linuxolator/compat/linux/linux_misc.c#6 edit .. //depot/projects/soc2006/rdivacky_linuxolator/i386/linux/linux_machdep.c#26 edit Differences ... ==== //depot/projects/soc2006/rdivacky_linuxolator/compat/linux/linux_misc.c#6 (text+ko) ==== @@ -1384,7 +1384,6 @@ if (pp->p_sysent == &elf_linux_sysvec) { em = em_find(pp->p_pid, EMUL_LOCKED); if (em == NULL) { - printf("this happens!\n"); #ifdef DEBUG printf(LMSG("emuldata not found.\n")); #endif ==== //depot/projects/soc2006/rdivacky_linuxolator/i386/linux/linux_machdep.c#26 (text+ko) ==== @@ -74,6 +74,8 @@ void linux_proc_exec(void *, struct proc *, struct image_params *); struct linux_emuldata *em_find(pid_t pid, int locked); +extern struct sysentvec elf32_freebsd_sysvec; /* defined in i386/i386/elf_machdep.c */ + struct l_descriptor { l_uint entry_number; l_ulong base_addr; @@ -1157,21 +1159,23 @@ em->child_clear_tid = NULL; em->child_set_tid = NULL; - /* allocate the shared struct only in non-exec cases */ + /* allocate the shared struct only in clone()/fork cases + * in the case of clone() td = calling proc and child = pid of + * the newly created proc + */ if (child != 0) { em->shared = NULL; if (flags & CLONE_VM) { /* lookup the parent */ - p_em = em_find(td->td_proc->p_pptr->p_pid, EMUL_LOCKED); + p_em = em_find(td->td_proc->p_pid, EMUL_LOCKED); if (p_em == NULL) { #ifdef DEBUG - printf(LMSG("parent emuldata not found for CLONE_VM.\n")); #endif + printf(LMSG("parent emuldata not found for CLONE_VM.\n")); + panic("impossible to continue\n"); } else { - em->shared = p_em->shared; + em->shared = p_em->shared; em->shared->refs++; -#ifdef DEBUG -#endif } } else { struct linux_emuldata_shared *s; @@ -1179,7 +1183,7 @@ MALLOC(s, struct linux_emuldata_shared *, sizeof *s, M_LINUX, M_WAITOK | M_ZERO); em->shared = s; s->refs = 1; - s->group_pid = td->td_proc->p_pid; + s->group_pid = child; } } @@ -1252,7 +1256,6 @@ FREE(em, M_LINUX); } -extern struct sysentvec elf32_freebsd_sysvec; /* defined in i386/i386/elf_machdep.c */ /* This is used in a case of transition from FreeBSD binary execing to linux binary * in this case we create linux emuldata proc entry with the pid of the currently running * process. @@ -1275,6 +1278,10 @@ #endif return; } + + em->shared->refs--; + if (em->shared->refs == 0) + FREE(em->shared, M_LINUX); EMUL_RUNLOCK(&emul_lock); /* XXX: there is a race but I think we can ommit that