svn commit: r359988 - in head/sys: compat/freebsd32 kern sys

Brooks Davis brooks at FreeBSD.org
Wed Apr 15 20:23:56 UTC 2020


Author: brooks
Date: Wed Apr 15 20:23:55 2020
New Revision: 359988
URL: https://svnweb.freebsd.org/changeset/base/359988

Log:
  Export argc, argv, envc, envv, and ps_strings in auxargs.
  
  This simplifies discovery of these values, potentially with reducing the
  number of syscalls we need to make at runtime.  Longer term, we wish to
  convert the startup process to pass an auxargs pointer to _start() and
  use that rather than walking off the end of envv.  This is cleaner,
  more C-friendly, and for systems with strong bounds (e.g. CHERI)
  necessary.
  
  Reviewed by:	kib
  Obtained from:	CheriBSD
  Sponsored by:	DARPA
  Differential Revision:	https://reviews.freebsd.org/D24407

Modified:
  head/sys/compat/freebsd32/freebsd32_misc.c
  head/sys/kern/imgact_elf.c
  head/sys/kern/kern_exec.c
  head/sys/sys/elf_common.h
  head/sys/sys/imgact.h

Modified: head/sys/compat/freebsd32/freebsd32_misc.c
==============================================================================
--- head/sys/compat/freebsd32/freebsd32_misc.c	Wed Apr 15 20:21:30 2020	(r359987)
+++ head/sys/compat/freebsd32/freebsd32_misc.c	Wed Apr 15 20:23:55 2020	(r359988)
@@ -3237,6 +3237,7 @@ freebsd32_copyout_strings(struct image_params *imgp, u
 	/*
 	 * Fill in "ps_strings" struct for ps, w, etc.
 	 */
+	imgp->argv = vectp;
 	if (suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp) != 0 ||
 	    suword32(&arginfo->ps_nargvstr, argc) != 0)
 		return (EFAULT);
@@ -3256,6 +3257,7 @@ freebsd32_copyout_strings(struct image_params *imgp, u
 	if (suword32(vectp++, 0) != 0)
 		return (EFAULT);
 
+	imgp->envv = vectp;
 	if (suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp) != 0 ||
 	    suword32(&arginfo->ps_nenvstr, envc) != 0)
 		return (EFAULT);

Modified: head/sys/kern/imgact_elf.c
==============================================================================
--- head/sys/kern/imgact_elf.c	Wed Apr 15 20:21:30 2020	(r359987)
+++ head/sys/kern/imgact_elf.c	Wed Apr 15 20:23:55 2020	(r359988)
@@ -1374,6 +1374,11 @@ __elfN(freebsd_copyout_auxargs)(struct image_params *i
 		AUXARGS_ENTRY(pos, AT_HWCAP2, *imgp->sysent->sv_hwcap2);
 	AUXARGS_ENTRY(pos, AT_BSDFLAGS, __elfN(sigfastblock) ?
 	    ELF_BSDF_SIGFASTBLK : 0);
+	AUXARGS_ENTRY(pos, AT_ARGC, imgp->args->argc);
+	AUXARGS_ENTRY_PTR(pos, AT_ARGV, imgp->argv);
+	AUXARGS_ENTRY(pos, AT_ENVC, imgp->args->envc);
+	AUXARGS_ENTRY_PTR(pos, AT_ENVV, imgp->envv);
+	AUXARGS_ENTRY_PTR(pos, AT_PS_STRINGS, imgp->ps_strings);
 	AUXARGS_ENTRY(pos, AT_NULL, 0);
 
 	free(imgp->auxargs, M_TEMP);

Modified: head/sys/kern/kern_exec.c
==============================================================================
--- head/sys/kern/kern_exec.c	Wed Apr 15 20:21:30 2020	(r359987)
+++ head/sys/kern/kern_exec.c	Wed Apr 15 20:23:55 2020	(r359988)
@@ -1646,6 +1646,7 @@ exec_copyout_strings(struct image_params *imgp, uintpt
 	/*
 	 * Fill in "ps_strings" struct for ps, w, etc.
 	 */
+	imgp->argv = vectp;
 	if (suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp) != 0 ||
 	    suword32(&arginfo->ps_nargvstr, argc) != 0)
 		return (EFAULT);
@@ -1665,6 +1666,7 @@ exec_copyout_strings(struct image_params *imgp, uintpt
 	if (suword(vectp++, 0) != 0)
 		return (EFAULT);
 
+	imgp->envv = vectp;
 	if (suword(&arginfo->ps_envstr, (long)(intptr_t)vectp) != 0 ||
 	    suword32(&arginfo->ps_nenvstr, envc) != 0)
 		return (EFAULT);

Modified: head/sys/sys/elf_common.h
==============================================================================
--- head/sys/sys/elf_common.h	Wed Apr 15 20:21:30 2020	(r359987)
+++ head/sys/sys/elf_common.h	Wed Apr 15 20:23:55 2020	(r359988)
@@ -956,8 +956,13 @@ typedef struct {
 #define	AT_HWCAP	25	/* CPU feature flags. */
 #define	AT_HWCAP2	26	/* CPU feature flags 2. */
 #define	AT_BSDFLAGS	27	/* ELF BSD Flags. */
+#define	AT_ARGC		28	/* Argument count */
+#define	AT_ARGV		29	/* Argument vector */
+#define	AT_ENVC		30	/* Environment count */
+#define	AT_ENVV		31	/* Environment vector */
+#define	AT_PS_STRINGS	32	/* struct ps_strings */
 
-#define	AT_COUNT	28	/* Count of defined aux entry types. */
+#define	AT_COUNT	33	/* Count of defined aux entry types. */
 
 /*
  * Relocation types.

Modified: head/sys/sys/imgact.h
==============================================================================
--- head/sys/sys/imgact.h	Wed Apr 15 20:21:30 2020	(r359987)
+++ head/sys/sys/imgact.h	Wed Apr 15 20:23:55 2020	(r359988)
@@ -78,6 +78,8 @@ struct image_params {
 	void *ps_strings;		/* pointer to ps_string (user space) */
 	struct image_args *args;	/* system call arguments */
 	struct sysentvec *sysent;	/* system entry vector */
+	void *argv;			/* pointer to argv (user space) */
+	void *envv;			/* pointer to envv (user space) */
 	char *execpath;
 	unsigned long execpathp;
 	char *freepath;


More information about the svn-src-head mailing list