Module Name:    src
Committed By:   uebayasi
Date:           Wed Apr 16 02:22:38 UTC 2014

Modified Files:
        src/sys/kern: kern_exec.c

Log Message:
execve_runproc: Isolate vmcmd execution code into a function.


To generate a diff of this commit:
cvs rdiff -u -r1.400 -r1.401 src/sys/kern/kern_exec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.400 src/sys/kern/kern_exec.c:1.401
--- src/sys/kern/kern_exec.c:1.400	Wed Apr 16 01:30:33 2014
+++ src/sys/kern/kern_exec.c	Wed Apr 16 02:22:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.400 2014/04/16 01:30:33 uebayasi Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.401 2014/04/16 02:22:38 uebayasi Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.400 2014/04/16 01:30:33 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.401 2014/04/16 02:22:38 uebayasi Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -779,6 +779,60 @@ execve_loadvm(struct lwp *l, const char 
 	return error;
 }
 
+static int
+execve_dovmcmds(struct lwp *l, struct execve_data * restrict data)
+{
+	struct exec_package	* const epp = &data->ed_pack;
+	struct proc		*p = l->l_proc;
+	struct exec_vmcmd	*base_vcp;
+	int			error = 0;
+	int			i;
+
+	/* record proc's vnode, for use by procfs and others */
+	if (p->p_textvp)
+		vrele(p->p_textvp);
+	vref(epp->ep_vp);
+	p->p_textvp = epp->ep_vp;
+
+	/* create the new process's VM space by running the vmcmds */
+	KASSERTMSG(epp->ep_vmcmds.evs_used != 0, "%s: no vmcmds", __func__);
+
+	DUMPVMCMDS(epp, 0, 0);
+
+	base_vcp = NULL;
+
+	for (i = 0; i < epp->ep_vmcmds.evs_used && !error; i++) {
+		struct exec_vmcmd *vcp;
+
+		vcp = &epp->ep_vmcmds.evs_cmds[i];
+		if (vcp->ev_flags & VMCMD_RELATIVE) {
+			KASSERTMSG(base_vcp != NULL,
+			    "%s: relative vmcmd with no base", __func__);
+			KASSERTMSG((vcp->ev_flags & VMCMD_BASE) == 0,
+			    "%s: illegal base & relative vmcmd", __func__);
+			vcp->ev_addr += base_vcp->ev_addr;
+		}
+		error = (*vcp->ev_proc)(l, vcp);
+		if (error)
+			DUMPVMCMDS(epp, i, error);
+		if (vcp->ev_flags & VMCMD_BASE)
+			base_vcp = vcp;
+	}
+
+	/* free the vmspace-creation commands, and release their references */
+	kill_vmcmds(&epp->ep_vmcmds);
+
+	vn_lock(epp->ep_vp, LK_EXCLUSIVE | LK_RETRY);
+	VOP_CLOSE(epp->ep_vp, FREAD, l->l_cred);
+	vput(epp->ep_vp);
+
+	/* if an error happened, deallocate and punt */
+	if (error != 0) {
+		DPRINTF(("%s: vmcmd %zu failed: %d\n", __func__, i - 1, error));
+	}
+	return error;
+}
+
 static void
 execve_free_data(struct execve_data *data)
 {
@@ -997,13 +1051,6 @@ execve_runproc(struct lwp *l, struct exe
 		    epp->ep_vm_maxaddr,
 		    epp->ep_flags & EXEC_TOPDOWN_VM);
 
-	/* record proc's vnode, for use by procfs and others */
-	if (p->p_textvp)
-		vrele(p->p_textvp);
-	vref(epp->ep_vp);
-	p->p_textvp = epp->ep_vp;
-
-	/* Now map address space */
 	struct vmspace		*vm;
 	vm = p->p_vmspace;
 	vm->vm_taddr = (void *)epp->ep_taddr;
@@ -1019,46 +1066,10 @@ execve_runproc(struct lwp *l, struct exe
 	pax_aslr_init(l, vm);
 #endif /* PAX_ASLR */
 
-	/* create the new process's VM space by running the vmcmds */
-	KASSERTMSG(epp->ep_vmcmds.evs_used != 0, "%s: no vmcmds", __func__);
-
-	DUMPVMCMDS(epp, 0, 0);
-
-	size_t			i;
-	struct exec_vmcmd	*base_vcp;
-
-	base_vcp = NULL;
-
-	for (i = 0; i < epp->ep_vmcmds.evs_used && !error; i++) {
-		struct exec_vmcmd *vcp;
-
-		vcp = &epp->ep_vmcmds.evs_cmds[i];
-		if (vcp->ev_flags & VMCMD_RELATIVE) {
-			KASSERTMSG(base_vcp != NULL,
-			    "%s: relative vmcmd with no base", __func__);
-			KASSERTMSG((vcp->ev_flags & VMCMD_BASE) == 0,
-			    "%s: illegal base & relative vmcmd", __func__);
-			vcp->ev_addr += base_vcp->ev_addr;
-		}
-		error = (*vcp->ev_proc)(l, vcp);
-		if (error)
-			DUMPVMCMDS(epp, i, error);
-		if (vcp->ev_flags & VMCMD_BASE)
-			base_vcp = vcp;
-	}
-
-	/* free the vmspace-creation commands, and release their references */
-	kill_vmcmds(&epp->ep_vmcmds);
-
-	vn_lock(epp->ep_vp, LK_EXCLUSIVE | LK_RETRY);
-	VOP_CLOSE(epp->ep_vp, FREAD, l->l_cred);
-	vput(epp->ep_vp);
-
-	/* if an error happened, deallocate and punt */
-	if (error) {
-		DPRINTF(("%s: vmcmd %zu failed: %d\n", __func__, i - 1, error));
+	/* Now map address space. */
+	error = execve_dovmcmds(l, data);
+	if (error != 0)
 		goto exec_abort;
-	}
 
 	pathexec(epp, p, data->ed_pathstring);
 

Reply via email to