svn commit: r200864 - in stable/7/sys: compat/ia32 kern sys

Konstantin Belousov kib at FreeBSD.org
Tue Dec 22 20:05:09 UTC 2009


Author: kib
Date: Tue Dec 22 20:05:09 2009
New Revision: 200864
URL: http://svn.freebsd.org/changeset/base/200864

Log:
  MFC r189927:
  Supply AT_EXECPATH auxinfo entry to the interpreter, both for native and
  compat32 binaries.
  
  Note that the merge was edited due to fexecve(2) support not present in
  stable/7.
  
  Tested by:	bms, Mykola Dzham <freebsd levsha org ua>

Modified:
  stable/7/sys/compat/ia32/ia32_sysvec.c
  stable/7/sys/kern/imgact_elf.c
  stable/7/sys/kern/kern_exec.c
  stable/7/sys/sys/imgact.h
Directory Properties:
  stable/7/sys/   (props changed)
  stable/7/sys/cddl/contrib/opensolaris/   (props changed)
  stable/7/sys/contrib/dev/acpica/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)

Modified: stable/7/sys/compat/ia32/ia32_sysvec.c
==============================================================================
--- stable/7/sys/compat/ia32/ia32_sysvec.c	Tue Dec 22 20:02:06 2009	(r200863)
+++ stable/7/sys/compat/ia32/ia32_sysvec.c	Tue Dec 22 20:05:09 2009	(r200864)
@@ -203,15 +203,21 @@ ia32_copyout_strings(struct image_params
 	char *stringp, *destp;
 	u_int32_t *stack_base;
 	struct freebsd32_ps_strings *arginfo;
+	size_t execpath_len;
 	int szsigcode;
 
 	/*
 	 * Calculate string base and vector table pointers.
 	 * Also deal with signal trampoline code for this exec type.
 	 */
+	if (imgp->execpath != NULL && imgp->auxargs != NULL)
+		execpath_len = strlen(imgp->execpath) + 1;
+	else
+		execpath_len = 0;
 	arginfo = (struct freebsd32_ps_strings *)FREEBSD32_PS_STRINGS;
 	szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
 	destp =	(caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
+		roundup(execpath_len, sizeof(char *)) -
 		roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
 
 	/*
@@ -222,6 +228,15 @@ ia32_copyout_strings(struct image_params
 			((caddr_t)arginfo - szsigcode), szsigcode);
 
 	/*
+	 * Copy the image path for the rtld.
+	 */
+	if (execpath_len != 0) {
+		imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len;
+		copyout(imgp->execpath, (void *)imgp->execpathp,
+		    execpath_len);
+	}
+
+	/*
 	 * If we have a valid auxargs ptr, prepare some room
 	 * on the stack.
 	 */
@@ -237,9 +252,9 @@ ia32_copyout_strings(struct image_params
 		 * the arg and env vector sets,and imgp->auxarg_size is room
 		 * for argument of Runtime loader.
 		 */
-		vectp = (u_int32_t *) (destp - (imgp->args->argc + imgp->args->envc + 2 +
-				       imgp->auxarg_size) * sizeof(u_int32_t));
-
+		vectp = (u_int32_t *) (destp - (imgp->args->argc +
+		    imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
+		    sizeof(u_int32_t));
 	} else
 		/*
 		 * The '+ 2' is for the null pointers at the end of each of

Modified: stable/7/sys/kern/imgact_elf.c
==============================================================================
--- stable/7/sys/kern/imgact_elf.c	Tue Dec 22 20:02:06 2009	(r200863)
+++ stable/7/sys/kern/imgact_elf.c	Tue Dec 22 20:05:09 2009	(r200864)
@@ -953,6 +953,8 @@ __elfN(freebsd_fixup)(register_t **stack
 	AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
 	AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
 	AUXARGS_ENTRY(pos, AT_BASE, args->base);
+	if (imgp->execpathp != 0)
+		AUXARGS_ENTRY(pos, AT_EXECPATH, imgp->execpathp);
 	AUXARGS_ENTRY(pos, AT_NULL, 0);
 
 	free(imgp->auxargs, M_TEMP);

Modified: stable/7/sys/kern/kern_exec.c
==============================================================================
--- stable/7/sys/kern/kern_exec.c	Tue Dec 22 20:02:06 2009	(r200863)
+++ stable/7/sys/kern/kern_exec.c	Tue Dec 22 20:05:09 2009	(r200864)
@@ -360,6 +360,8 @@ do_execve(td, args, mac_p)
 	imgp->ps_strings = 0;
 	imgp->auxarg_size = 0;
 	imgp->args = args;
+	imgp->execpath = imgp->freepath = NULL;
+	imgp->execpathp = 0;
 
 #ifdef MAC
 	error = mac_execve_enter(imgp, mac_p);
@@ -486,6 +488,10 @@ interpret:
 	 * of the sv_copyout_strings/sv_fixup operations require the vnode.
 	 */
 	VOP_UNLOCK(imgp->vp, 0, td);
+
+	if (imgp->auxargs != NULL)
+		vn_fullpath(td, imgp->vp, &imgp->execpath, &imgp->freepath);
+
 	/*
 	 * Copy out strings (args and env) and initialize stack base
 	 */
@@ -814,6 +820,8 @@ exec_fail_dealloc:
 	if (imgp->object != NULL)
 		vm_object_deallocate(imgp->object);
 
+	free(imgp->freepath, M_TEMP);
+
 	if (error == 0) {
 		/*
 		 * Stop the process here if its stop event mask has
@@ -1125,18 +1133,24 @@ exec_copyout_strings(imgp)
 	register_t *stack_base;
 	struct ps_strings *arginfo;
 	struct proc *p;
+	size_t execpath_len;
 	int szsigcode;
 
 	/*
 	 * Calculate string base and vector table pointers.
 	 * Also deal with signal trampoline code for this exec type.
 	 */
+	if (imgp->execpath != NULL && imgp->auxargs != NULL)
+		execpath_len = strlen(imgp->execpath) + 1;
+	else
+		execpath_len = 0;
 	p = imgp->proc;
 	szsigcode = 0;
 	arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
 	if (p->p_sysent->sv_szsigcode != NULL)
 		szsigcode = *(p->p_sysent->sv_szsigcode);
 	destp =	(caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
+	    roundup(execpath_len, sizeof(char *)) -
 	    roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
 
 	/*
@@ -1147,6 +1161,15 @@ exec_copyout_strings(imgp)
 		    szsigcode), szsigcode);
 
 	/*
+	 * Copy the image path for the rtld.
+	 */
+	if (execpath_len != 0) {
+		imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len;
+		copyout(imgp->execpath, (void *)imgp->execpathp,
+		    execpath_len);
+	}
+
+	/*
 	 * If we have a valid auxargs ptr, prepare some room
 	 * on the stack.
 	 */
@@ -1163,9 +1186,8 @@ exec_copyout_strings(imgp)
 		 * for argument of Runtime loader.
 		 */
 		vectp = (char **)(destp - (imgp->args->argc +
-		    imgp->args->envc + 2 + imgp->auxarg_size) *
+		    imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
 		    sizeof(char *));
-
 	} else {
 		/*
 		 * The '+ 2' is for the null pointers at the end of each of

Modified: stable/7/sys/sys/imgact.h
==============================================================================
--- stable/7/sys/sys/imgact.h	Tue Dec 22 20:02:06 2009	(r200863)
+++ stable/7/sys/sys/imgact.h	Tue Dec 22 20:05:09 2009	(r200864)
@@ -65,6 +65,9 @@ struct image_params {
 	size_t auxarg_size;
 	struct image_args *args;	/* system call arguments */
 	struct sysentvec *sysent;	/* system entry vector */
+	char *execpath;
+	unsigned long execpathp;
+	char *freepath;
 };
 
 #ifdef _KERNEL


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