From owner-svn-src-user@FreeBSD.ORG  Sun May  4 15:49:28 2014
Return-Path: <owner-svn-src-user@FreeBSD.ORG>
Delivered-To: svn-src-user@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by hub.freebsd.org (Postfix) with ESMTPS id 1177F5E2;
 Sun,  4 May 2014 15:49:28 +0000 (UTC)
Received: from svn.freebsd.org (svn.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id E6D3E10F4;
 Sun,  4 May 2014 15:49:27 +0000 (UTC)
Received: from svn.freebsd.org ([127.0.1.70])
 by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s44FnRTH049091;
 Sun, 4 May 2014 15:49:27 GMT (envelope-from dchagin@svn.freebsd.org)
Received: (from dchagin@localhost)
 by svn.freebsd.org (8.14.8/8.14.8/Submit) id s44FnRn0049087;
 Sun, 4 May 2014 15:49:27 GMT (envelope-from dchagin@svn.freebsd.org)
Message-Id: <201405041549.s44FnRn0049087@svn.freebsd.org>
From: Dmitry Chagin <dchagin@FreeBSD.org>
Date: Sun, 4 May 2014 15:49:27 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
Subject: svn commit: r265325 - in user/dchagin/lemul/sys: amd64/linux
 amd64/linux32 compat/linux i386/linux
X-SVN-Group: user
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-user@freebsd.org
X-Mailman-Version: 2.1.17
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
 src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sun, 04 May 2014 15:49:28 -0000

Author: dchagin
Date: Sun May  4 15:49:26 2014
New Revision: 265325
URL: http://svnweb.freebsd.org/changeset/base/265325

Log:
  We can have both 64 & 32 bit Linuxulator running,
  so any eventhandler can be called twice for us. To prevent this
  we will check that proc is handled by corresponding module.

Modified:
  user/dchagin/lemul/sys/amd64/linux/linux_sysvec.c
  user/dchagin/lemul/sys/amd64/linux32/linux32_sysvec.c
  user/dchagin/lemul/sys/compat/linux/linux_emul.c
  user/dchagin/lemul/sys/i386/linux/linux_sysvec.c

Modified: user/dchagin/lemul/sys/amd64/linux/linux_sysvec.c
==============================================================================
--- user/dchagin/lemul/sys/amd64/linux/linux_sysvec.c	Sun May  4 15:47:58 2014	(r265324)
+++ user/dchagin/lemul/sys/amd64/linux/linux_sysvec.c	Sun May  4 15:49:26 2014	(r265325)
@@ -961,9 +961,9 @@ linux64_elf_modevent(module_t mod, int t
 			LIST_INIT(&futex_list);
 			mtx_init(&futex_mtx, "ftllk64", NULL, MTX_DEF);
 			linux_exit_tag = EVENTHANDLER_REGISTER(process_exit,
-			    linux_proc_exit, NULL, 1000);
+			    linux_proc_exit, (void *) (long) elf_linux_sysvec.sv_flags, 1000);
 			linux_exec_tag = EVENTHANDLER_REGISTER(process_exec,
-			    linux_proc_exec, NULL, 1000);
+			    linux_proc_exec, (void *) (long)elf_linux_sysvec.sv_flags, 1000);
 			linux_thread_dtor_tag = EVENTHANDLER_REGISTER(thread_dtor,
 			    linux_thread_dtor, NULL, EVENTHANDLER_PRI_ANY);
 			linux_osd_jail_register();

Modified: user/dchagin/lemul/sys/amd64/linux32/linux32_sysvec.c
==============================================================================
--- user/dchagin/lemul/sys/amd64/linux32/linux32_sysvec.c	Sun May  4 15:47:58 2014	(r265324)
+++ user/dchagin/lemul/sys/amd64/linux32/linux32_sysvec.c	Sun May  4 15:49:26 2014	(r265325)
@@ -1171,9 +1171,9 @@ linux_elf_modevent(module_t mod, int typ
 			LIST_INIT(&futex_list);
 			mtx_init(&futex_mtx, "ftllk", NULL, MTX_DEF);
 			linux_exit_tag = EVENTHANDLER_REGISTER(process_exit,
-			    linux_proc_exit, NULL, 1000);
+			    linux_proc_exit, (void *) (long) elf_linux_sysvec.sv_flags, 1000);
 			linux_exec_tag = EVENTHANDLER_REGISTER(process_exec,
-			    linux_proc_exec, NULL, 1000);
+			    linux_proc_exec, (void *) (long)elf_linux_sysvec.sv_flags, 1000);
 			linux_thread_dtor_tag = EVENTHANDLER_REGISTER(thread_dtor,
 			    linux_thread_dtor, NULL, EVENTHANDLER_PRI_ANY);
 			linux_osd_jail_register();

Modified: user/dchagin/lemul/sys/compat/linux/linux_emul.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_emul.c	Sun May  4 15:47:58 2014	(r265324)
+++ user/dchagin/lemul/sys/compat/linux/linux_emul.c	Sun May  4 15:49:26 2014	(r265325)
@@ -220,9 +220,10 @@ linux_common_execve(struct thread *td, s
 }
 
 void 
-linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp)
+linux_proc_exec(void *arg, struct proc *p, struct image_params *imgp)
 {
 	struct thread *td = curthread;
+	int sv_flags;
 
 	/*
 	 * In a case of execing to linux binary we create linux
@@ -230,6 +231,16 @@ linux_proc_exec(void *arg __unused, stru
 	 */
 	if (__predict_false((imgp->sysent->sv_flags & SV_ABI_MASK) ==
 	    SV_ABI_LINUX)) {
+
+		/*
+		 * We can have both 64 & 32 bit Linuxulator running,
+		 * so eventhandler is called twice for us. To prevent this
+		 * we will check that proc is handled by corresponding module.
+		 */
+		sv_flags = (int) arg;
+		if ((sv_flags & SV_IS_MASK) != SV_PROC_IS(p))
+			return;
+
 		LIN_SDT_PROBE2(emul, proc_exec, entry, p, imgp);
 		if (SV_PROC_ABI(p) == SV_ABI_LINUX)
 			linux_proc_init(td, NULL, 0);
@@ -363,13 +374,23 @@ linux_set_tid_address(struct thread *td,
 }
 
 void
-linux_proc_exit(void *arg __unused, struct proc *p)
+linux_proc_exit(void *arg, struct proc *p)
 {
 	struct linux_pemuldata *pem;
+	int sv_flags;
 
 	if (__predict_true(SV_PROC_ABI(p) != SV_ABI_LINUX))
 		return;
 
+	/*
+	 * We can have both 64 & 32 bit Linuxulator running,
+	 * so eventhandler is called twice for us. To prevent this
+	 * we will check that proc is handled by corresponding module.
+	 */
+	sv_flags = (int) arg;
+	if ((sv_flags & SV_IS_MASK) != SV_PROC_IS(p))
+		return;
+
 	pem = pem_find(p);
 	KASSERT(pem != NULL, ("proc_exit: proc emuldata not found.\n"));
 	p->p_emuldata = NULL;

Modified: user/dchagin/lemul/sys/i386/linux/linux_sysvec.c
==============================================================================
--- user/dchagin/lemul/sys/i386/linux/linux_sysvec.c	Sun May  4 15:47:58 2014	(r265324)
+++ user/dchagin/lemul/sys/i386/linux/linux_sysvec.c	Sun May  4 15:49:26 2014	(r265325)
@@ -1150,9 +1150,9 @@ linux_elf_modevent(module_t mod, int typ
 			LIST_INIT(&futex_list);
 			mtx_init(&futex_mtx, "ftllk", NULL, MTX_DEF);
 			linux_exit_tag = EVENTHANDLER_REGISTER(process_exit,
-			    linux_proc_exit, NULL, 1000);
+			    linux_proc_exit, (void *) elf_linux_sysvec.sv_flags, 1000);
 			linux_exec_tag = EVENTHANDLER_REGISTER(process_exec,
-			    linux_proc_exec, NULL, 1000);
+			    linux_proc_exec, (void *) elf_linux_sysvec.sv_flags, 1000);
 			linux_thread_dtor_tag = EVENTHANDLER_REGISTER(thread_dtor,
 			    linux_thread_dtor, NULL, EVENTHANDLER_PRI_ANY);
 			linux_get_machine(&linux_kplatform);