From owner-p4-projects@FreeBSD.ORG Tue Aug 8 15:19:50 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 21DD816A4EA; Tue, 8 Aug 2006 15:19:50 +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 F075516A4E0 for ; Tue, 8 Aug 2006 15:19:49 +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 0C5F543D7B for ; Tue, 8 Aug 2006 15:18:52 +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 k78FIqPC006069 for ; Tue, 8 Aug 2006 15:18:52 GMT (envelope-from rdivacky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k78FIpCi006066 for perforce@freebsd.org; Tue, 8 Aug 2006 15:18:51 GMT (envelope-from rdivacky@FreeBSD.org) Date: Tue, 8 Aug 2006 15:18:51 GMT Message-Id: <200608081518.k78FIpCi006066@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 103449 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: Tue, 08 Aug 2006 15:19:50 -0000 http://perforce.freebsd.org/chv.cgi?CH=103449 Change 103449 by rdivacky@rdivacky_witten on 2006/08/08 15:18:25 Introduce poor-mans synchronization. This ensures that linux_proc_init() is always called before linux_schedtail. Sometimes it happened that linux_schedtail was called before proc_init which caused em_find() to return NULL. Now it should be fixed (this and the memleak it caused). Tested by: /glibc-2.3.6/configure --disable-sanity-checks Affected files ... .. //depot/projects/soc2006/rdivacky_linuxolator/i386/linux/linux_machdep.c#35 edit Differences ... ==== //depot/projects/soc2006/rdivacky_linuxolator/i386/linux/linux_machdep.c#35 (text+ko) ==== @@ -1160,6 +1160,7 @@ linux_proc_init(struct thread *td, pid_t child, int flags) { struct linux_emuldata *em, *p_em; + struct proc *p; /* XXX: locking? */ if (child != 0) { @@ -1218,10 +1219,14 @@ if (child != 0) { LIST_INSERT_HEAD(&em->shared->threads, em, threads); EMUL_WUNLOCK(&emul_lock); + + p = pfind(child); + PROC_UNLOCK(p); + /* we might have a sleeping linux_schedtail */ + wakeup(p->p_emuldata); } else EMUL_RUNLOCK(&emul_lock); - return (0); } @@ -1324,6 +1329,8 @@ } } +extern int hz; /* in subr_param.c */ + void linux_schedtail(void *arg __unused, struct proc *p) { @@ -1336,10 +1343,18 @@ if (p->p_sysent != &elf_linux_sysvec) return; +retry: /* find the emuldata */ em = em_find(p->p_pid, EMUL_UNLOCKED); if (em == NULL) { + /* We might have been called before proc_init for this process so + * tsleep and be woken up by it. We use p->p_emuldata for this + */ + + error = tsleep(p->p_emuldata, PLOCK, "linux_schedtail", hz); + if (error == 0) + goto retry; #ifdef DEBUG printf(LMSG("we didnt find emuldata for the userreting process.\n")); #endif