From owner-svn-src-head@freebsd.org Wed Apr 15 20:23:56 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A283B2C1383; Wed, 15 Apr 2020 20:23:56 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 492Yj83lrqz4McJ; Wed, 15 Apr 2020 20:23:56 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7C17D24C03; Wed, 15 Apr 2020 20:23:56 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03FKNula095498; Wed, 15 Apr 2020 20:23:56 GMT (envelope-from brooks@FreeBSD.org) Received: (from brooks@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03FKNttZ095493; Wed, 15 Apr 2020 20:23:55 GMT (envelope-from brooks@FreeBSD.org) Message-Id: <202004152023.03FKNttZ095493@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: brooks set sender to brooks@FreeBSD.org using -f From: Brooks Davis Date: Wed, 15 Apr 2020 20:23:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r359988 - in head/sys: compat/freebsd32 kern sys X-SVN-Group: head X-SVN-Commit-Author: brooks X-SVN-Commit-Paths: in head/sys: compat/freebsd32 kern sys X-SVN-Commit-Revision: 359988 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Apr 2020 20:23:56 -0000 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;