svn commit: r265179 - in user/dchagin/lemul/sys: amd64/linux amd64/linux32 compat/linux

Dmitry Chagin dchagin at FreeBSD.org
Thu May 1 13:42:21 UTC 2014


Author: dchagin
Date: Thu May  1 13:42:19 2014
New Revision: 265179
URL: http://svnweb.freebsd.org/changeset/base/265179

Log:
  To fix a panic when in case of transition from linux binary execing
  to native binary we destroy emuldata thread entry and kern_execve()
  returns error a bit rewrite linux_execve system call. For now we destroy
  emuldata thread entry after kern_execve finished, not in event handler.

Modified:
  user/dchagin/lemul/sys/amd64/linux/linux_machdep.c
  user/dchagin/lemul/sys/amd64/linux32/linux32_machdep.c
  user/dchagin/lemul/sys/compat/linux/linux_emul.c
  user/dchagin/lemul/sys/compat/linux/linux_emul.h

Modified: user/dchagin/lemul/sys/amd64/linux/linux_machdep.c
==============================================================================
--- user/dchagin/lemul/sys/amd64/linux/linux_machdep.c	Thu May  1 13:30:14 2014	(r265178)
+++ user/dchagin/lemul/sys/amd64/linux/linux_machdep.c	Thu May  1 13:42:19 2014	(r265179)
@@ -126,7 +126,7 @@ linux_execve(struct thread *td, struct l
 	    args->envp);
 	free(path, M_TEMP);
 	if (error == 0)
-		error = kern_execve(td, &eargs, NULL);
+		error = linux_common_execve(td, &eargs);
 	return (error);
 }
 

Modified: user/dchagin/lemul/sys/amd64/linux32/linux32_machdep.c
==============================================================================
--- user/dchagin/lemul/sys/amd64/linux32/linux32_machdep.c	Thu May  1 13:30:14 2014	(r265178)
+++ user/dchagin/lemul/sys/amd64/linux32/linux32_machdep.c	Thu May  1 13:42:19 2014	(r265179)
@@ -150,7 +150,7 @@ linux_execve(struct thread *td, struct l
 	    args->argp, args->envp);
 	free(path, M_TEMP);
 	if (error == 0)
-		error = kern_execve(td, &eargs, NULL);
+		error = linux_common_execve(td, &eargs);
 	return (error);
 }
 

Modified: user/dchagin/lemul/sys/compat/linux/linux_emul.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_emul.c	Thu May  1 13:30:14 2014	(r265178)
+++ user/dchagin/lemul/sys/compat/linux/linux_emul.c	Thu May  1 13:42:19 2014	(r265179)
@@ -158,39 +158,23 @@ linux_proc_init(struct thread *td, struc
 	LIN_SDT_PROBE0(emul, proc_init, return);
 }
 
-void 
-linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp)
+int 
+linux_common_execve(struct thread *td, struct image_args *eargs)
 {
-	struct thread *td = curthread;
 	struct linux_emuldata *em;
+	struct proc *p;
+	int error;
 
-	/*
-	 * In a case of execing to linux binary we create linux
-	 * emuldata thread entry.
-	 */
-	if (__predict_false((imgp->sysent->sv_flags & SV_ABI_MASK) ==
-	    SV_ABI_LINUX)) {
-		LIN_SDT_PROBE2(emul, proc_exec, entry, p, imgp);
-		if (SV_PROC_ABI(p) == SV_ABI_LINUX)
-			linux_proc_init(td, NULL, 0);
-		else
-			linux_proc_init(td, td, 0);
-	}
+	error = kern_execve(td, eargs, NULL);
+	if (error)
+		return (error);
 
+	p = td->td_proc;
 	/*
 	 * In a case of transition from Linux binary execing to
 	 * FreeBSD binary we destroy linux emuldata thread entry.
 	 */
-	if (__predict_false((imgp->sysent->sv_flags & SV_ABI_MASK) != SV_ABI_LINUX &&
-	    SV_PROC_ABI(p) == SV_ABI_LINUX)) {
-
-		/* 
-		 * XXX:There's a race because here we assign p->p_emuldata NULL
-		 * but the process is still counted as linux one for a short
-		 * time so some other process might reference it and try to
-		 * access its p->p_emuldata and panicing on a NULL reference.
-		 */
-
+	if (SV_CURPROC_ABI() != SV_ABI_LINUX) {
 		PROC_LOCK(p);
 		em = em_find(td);
 		KASSERT(em != NULL, ("proc_exec: emuldata not found.\n"));
@@ -199,10 +183,30 @@ linux_proc_exec(void *arg __unused, stru
 
 		free(em, M_TEMP);
 	}
+	return (0);
+}
+
 
+
+void 
+linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp)
+{
+	struct thread *td = curthread;
+
+	/*
+	 * In a case of execing to linux binary we create linux
+	 * emuldata thread entry.
+	 */
 	if (__predict_false((imgp->sysent->sv_flags & SV_ABI_MASK) ==
-	    SV_ABI_LINUX))
+	    SV_ABI_LINUX)) {
+		LIN_SDT_PROBE2(emul, proc_exec, entry, p, imgp);
+		if (SV_PROC_ABI(p) == SV_ABI_LINUX)
+			linux_proc_init(td, NULL, 0);
+		else
+			linux_proc_init(td, td, 0);
+
 		LIN_SDT_PROBE0(emul, proc_exec, return);
+	}
 }
 
 void

Modified: user/dchagin/lemul/sys/compat/linux/linux_emul.h
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_emul.h	Thu May  1 13:30:14 2014	(r265178)
+++ user/dchagin/lemul/sys/compat/linux/linux_emul.h	Thu May  1 13:42:19 2014	(r265179)
@@ -54,6 +54,7 @@ struct linux_emuldata	*em_find(struct th
 #define	LINUX_XDEPR_REQUEUEOP	0x00000001	/* uses deprecated
 						   futex REQUEUE op*/
 
+int	linux_common_execve(struct thread *, struct image_args *);
 void	linux_proc_init(struct thread *, struct thread *, int);
 void	linux_schedtail(struct thread *);
 void	linux_proc_exec(void *, struct proc *, struct image_params *);


More information about the svn-src-user mailing list