svn commit: r266585 - in stable/9/sys: kern sys vm

Konstantin Belousov kib at FreeBSD.org
Fri May 23 11:56:33 UTC 2014


Author: kib
Date: Fri May 23 11:56:32 2014
New Revision: 266585
URL: http://svnweb.freebsd.org/changeset/base/266585

Log:
  MFC r266464:
  In execve(2), postpone the free of old vmspace until the threads are resumed
  and exited.
  
  Approved by:	re (marius)

Modified:
  stable/9/sys/kern/kern_exec.c
  stable/9/sys/sys/proc.h
  stable/9/sys/vm/vm_map.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/sys/   (props changed)

Modified: stable/9/sys/kern/kern_exec.c
==============================================================================
--- stable/9/sys/kern/kern_exec.c	Fri May 23 11:22:44 2014	(r266584)
+++ stable/9/sys/kern/kern_exec.c	Fri May 23 11:56:32 2014	(r266585)
@@ -282,6 +282,7 @@ kern_execve(td, args, mac_p)
 	struct mac *mac_p;
 {
 	struct proc *p = td->td_proc;
+	struct vmspace *oldvmspace;
 	int error;
 
 	AUDIT_ARG_ARGV(args->begin_argv, args->argc,
@@ -298,6 +299,8 @@ kern_execve(td, args, mac_p)
 		PROC_UNLOCK(p);
 	}
 
+	KASSERT((td->td_pflags & TDP_EXECVMSPC) == 0, ("nested execve"));
+	oldvmspace = td->td_proc->p_vmspace;
 	error = do_execve(td, args, mac_p);
 
 	if (p->p_flag & P_HADTHREADS) {
@@ -312,6 +315,12 @@ kern_execve(td, args, mac_p)
 			thread_single_end();
 		PROC_UNLOCK(p);
 	}
+	if ((td->td_pflags & TDP_EXECVMSPC) != 0) {
+		KASSERT(td->td_proc->p_vmspace != oldvmspace,
+		    ("oldvmspace still used"));
+		vmspace_free(oldvmspace);
+		td->td_pflags &= ~TDP_EXECVMSPC;
+	}
 
 	return (error);
 }

Modified: stable/9/sys/sys/proc.h
==============================================================================
--- stable/9/sys/sys/proc.h	Fri May 23 11:22:44 2014	(r266584)
+++ stable/9/sys/sys/proc.h	Fri May 23 11:56:32 2014	(r266585)
@@ -426,6 +426,7 @@ do {									\
 #define	TDP_NERRNO	0x08000000 /* Last errno is already in td_errno */
 #define	TDP_UIOHELD	0x10000000 /* Current uio has pages held in td_ma */
 #define	TDP_DEVMEMIO	0x20000000 /* Accessing memory for /dev/mem */
+#define	TDP_EXECVMSPC	0x40000000 /* Execve destroyed old vmspace */
 
 /*
  * Reasons that the current thread can not be run yet.

Modified: stable/9/sys/vm/vm_map.c
==============================================================================
--- stable/9/sys/vm/vm_map.c	Fri May 23 11:22:44 2014	(r266584)
+++ stable/9/sys/vm/vm_map.c	Fri May 23 11:56:32 2014	(r266585)
@@ -3752,6 +3752,8 @@ vmspace_exec(struct proc *p, vm_offset_t
 	struct vmspace *oldvmspace = p->p_vmspace;
 	struct vmspace *newvmspace;
 
+	KASSERT((curthread->td_pflags & TDP_EXECVMSPC) == 0,
+	    ("vmspace_exec recursed"));
 	newvmspace = vmspace_alloc(minuser, maxuser);
 	if (newvmspace == NULL)
 		return (ENOMEM);
@@ -3768,7 +3770,7 @@ vmspace_exec(struct proc *p, vm_offset_t
 	PROC_VMSPACE_UNLOCK(p);
 	if (p == curthread->td_proc)
 		pmap_activate(curthread);
-	vmspace_free(oldvmspace);
+	curthread->td_pflags |= TDP_EXECVMSPC;
 	return (0);
 }
 


More information about the svn-src-stable-9 mailing list