Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Nov 2019 22:01:08 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r354741 - in head/sys: amd64/amd64 arm/arm arm64/arm64 compat/freebsd32 compat/ia32 i386/i386 kern mips/mips powerpc/powerpc riscv/riscv sparc64/sparc64 sys
Message-ID:  <20191115200108.GH2707@kib.kiev.ua>
In-Reply-To: <201911151842.xAFIgDrJ093716@repo.freebsd.org>
References:  <201911151842.xAFIgDrJ093716@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Nov 15, 2019 at 06:42:13PM +0000, John Baldwin wrote:
> Author: jhb
> Date: Fri Nov 15 18:42:13 2019
> New Revision: 354741
> URL: https://svnweb.freebsd.org/changeset/base/354741
> 
> Log:
>   Add a sv_copyout_auxargs() hook in sysentvec.
>   
>   Change the FreeBSD ELF ABIs to use this new hook to copyout ELF auxv
>   instead of doing it in the sv_fixup hook.  In particular, this new
>   hook allows the stack space to be allocated at the same time the auxv
>   values are copied out to userland.  This allows us to avoid wasting
>   space for unused auxv entries as well as not having to recalculate
>   where the auxv vector is by walking back up over the argv and
>   environment vectors.
>   
>   Reviewed by:	brooks, emaste
>   Tested on:	amd64 (amd64 and i386 binaries), i386, mips, mips64
>   Sponsored by:	DARPA
>   Differential Revision:	https://reviews.freebsd.org/D22355
> 
> Modified:
>   head/sys/amd64/amd64/elf_machdep.c
>   head/sys/arm/arm/elf_machdep.c
>   head/sys/arm64/arm64/elf32_machdep.c
>   head/sys/arm64/arm64/elf_machdep.c
>   head/sys/compat/freebsd32/freebsd32_misc.c
>   head/sys/compat/ia32/ia32_sysvec.c
>   head/sys/i386/i386/elf_machdep.c
>   head/sys/kern/imgact_elf.c
>   head/sys/kern/kern_exec.c
>   head/sys/mips/mips/elf_machdep.c
>   head/sys/mips/mips/freebsd32_machdep.c
>   head/sys/powerpc/powerpc/elf32_machdep.c
>   head/sys/powerpc/powerpc/elf64_machdep.c
>   head/sys/riscv/riscv/elf_machdep.c
>   head/sys/sparc64/sparc64/elf_machdep.c
>   head/sys/sys/imgact_elf.h
>   head/sys/sys/sysent.h
> 
> Modified: head/sys/amd64/amd64/elf_machdep.c
> ==============================================================================
> --- head/sys/amd64/amd64/elf_machdep.c	Fri Nov 15 18:34:36 2019	(r354740)
> +++ head/sys/amd64/amd64/elf_machdep.c	Fri Nov 15 18:42:13 2019	(r354741)
> @@ -68,6 +68,7 @@ struct sysentvec elf64_freebsd_sysvec = {
>  	.sv_usrstack	= USRSTACK,
>  	.sv_psstrings	= PS_STRINGS,
>  	.sv_stackprot	= VM_PROT_ALL,
> +	.sv_copyout_auxargs = __elfN(freebsd_copyout_auxargs),
>  	.sv_copyout_strings	= exec_copyout_strings,
>  	.sv_setregs	= exec_setregs,
>  	.sv_fixlimit	= NULL,
> 
> Modified: head/sys/arm/arm/elf_machdep.c
> ==============================================================================
> --- head/sys/arm/arm/elf_machdep.c	Fri Nov 15 18:34:36 2019	(r354740)
> +++ head/sys/arm/arm/elf_machdep.c	Fri Nov 15 18:42:13 2019	(r354741)
> @@ -75,6 +75,7 @@ struct sysentvec elf32_freebsd_sysvec = {
>  	.sv_usrstack	= USRSTACK,
>  	.sv_psstrings	= PS_STRINGS,
>  	.sv_stackprot	= VM_PROT_ALL,
> +	.sv_copyout_auxargs = __elfN(freebsd_copyout_auxargs),
>  	.sv_copyout_strings = exec_copyout_strings,
>  	.sv_setregs	= exec_setregs,
>  	.sv_fixlimit	= NULL,
> 
> Modified: head/sys/arm64/arm64/elf32_machdep.c
> ==============================================================================
> --- head/sys/arm64/arm64/elf32_machdep.c	Fri Nov 15 18:34:36 2019	(r354740)
> +++ head/sys/arm64/arm64/elf32_machdep.c	Fri Nov 15 18:42:13 2019	(r354741)
> @@ -92,6 +92,7 @@ static struct sysentvec elf32_freebsd_sysvec = {
>  	.sv_usrstack	= FREEBSD32_USRSTACK,
>  	.sv_psstrings	= FREEBSD32_PS_STRINGS,
>  	.sv_stackprot	= VM_PROT_READ | VM_PROT_WRITE,
> +	.sv_copyout_auxargs = elf32_freebsd_copyout_auxargs,
>  	.sv_copyout_strings = freebsd32_copyout_strings,
>  	.sv_setregs	= freebsd32_setregs,
>  	.sv_fixlimit	= NULL, // XXX
> 
> Modified: head/sys/arm64/arm64/elf_machdep.c
> ==============================================================================
> --- head/sys/arm64/arm64/elf_machdep.c	Fri Nov 15 18:34:36 2019	(r354740)
> +++ head/sys/arm64/arm64/elf_machdep.c	Fri Nov 15 18:42:13 2019	(r354741)
> @@ -76,6 +76,7 @@ static struct sysentvec elf64_freebsd_sysvec = {
>  	.sv_usrstack	= USRSTACK,
>  	.sv_psstrings	= PS_STRINGS,
>  	.sv_stackprot	= VM_PROT_READ | VM_PROT_WRITE,
> +	.sv_copyout_auxargs = __elfN(freebsd_copyout_auxargs),
>  	.sv_copyout_strings = exec_copyout_strings,
>  	.sv_setregs	= exec_setregs,
>  	.sv_fixlimit	= NULL,
> 
> Modified: head/sys/compat/freebsd32/freebsd32_misc.c
> ==============================================================================
> --- head/sys/compat/freebsd32/freebsd32_misc.c	Fri Nov 15 18:34:36 2019	(r354740)
> +++ head/sys/compat/freebsd32/freebsd32_misc.c	Fri Nov 15 18:42:13 2019	(r354741)
> @@ -3195,14 +3195,8 @@ freebsd32_copyout_strings(struct image_params *imgp)
>  	if (imgp->sysent->sv_stackgap != NULL)
>  		imgp->sysent->sv_stackgap(imgp, (u_long *)&vectp);
>  
> -	if (imgp->auxargs) {
> -		/*
> -		 * Allocate room on the stack for the ELF auxargs
> -		 * array.  It has up to AT_COUNT entries.
> -		 */
> -		vectp -= howmany(AT_COUNT * sizeof(Elf32_Auxinfo),
> -		    sizeof(*vectp));
> -	}
> +	if (imgp->auxargs)
> +		imgp->sysent->sv_copyout_auxargs(imgp, (u_long *)&vectp);
>  
>  	/*
>  	 * Allocate room for the argv[] and env vectors including the
> 
> Modified: head/sys/compat/ia32/ia32_sysvec.c
> ==============================================================================
> --- head/sys/compat/ia32/ia32_sysvec.c	Fri Nov 15 18:34:36 2019	(r354740)
> +++ head/sys/compat/ia32/ia32_sysvec.c	Fri Nov 15 18:42:13 2019	(r354741)
> @@ -114,6 +114,7 @@ struct sysentvec ia32_freebsd_sysvec = {
>  	.sv_usrstack	= FREEBSD32_USRSTACK,
>  	.sv_psstrings	= FREEBSD32_PS_STRINGS,
>  	.sv_stackprot	= VM_PROT_ALL,
> +	.sv_copyout_auxargs	= elf32_freebsd_copyout_auxargs,
>  	.sv_copyout_strings	= freebsd32_copyout_strings,
>  	.sv_setregs	= ia32_setregs,
>  	.sv_fixlimit	= ia32_fixlimit,
> 
> Modified: head/sys/i386/i386/elf_machdep.c
> ==============================================================================
> --- head/sys/i386/i386/elf_machdep.c	Fri Nov 15 18:34:36 2019	(r354740)
> +++ head/sys/i386/i386/elf_machdep.c	Fri Nov 15 18:42:13 2019	(r354741)
> @@ -70,6 +70,7 @@ struct sysentvec elf32_freebsd_sysvec = {
>  	.sv_usrstack	= USRSTACK,
>  	.sv_psstrings	= PS_STRINGS,
>  	.sv_stackprot	= VM_PROT_ALL,
> +	.sv_copyout_auxargs = __elfN(freebsd_copyout_auxargs),
>  	.sv_copyout_strings	= exec_copyout_strings,
>  	.sv_setregs	= exec_setregs,
>  	.sv_fixlimit	= NULL,
> 
> Modified: head/sys/kern/imgact_elf.c
> ==============================================================================
> --- head/sys/kern/imgact_elf.c	Fri Nov 15 18:34:36 2019	(r354740)
> +++ head/sys/kern/imgact_elf.c	Fri Nov 15 18:42:13 2019	(r354741)
> @@ -1289,7 +1289,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *i
>  		addr = et_dyn_addr;
>  
>  	/*
> -	 * Construct auxargs table (used by the fixup routine)
> +	 * Construct auxargs table (used by the copyout_auxargs routine)
>  	 */
>  	elf_auxargs = malloc(sizeof(Elf_Auxargs), M_TEMP, M_NOWAIT);
>  	if (elf_auxargs == NULL) {
> @@ -1323,16 +1323,13 @@ ret:
>  
>  #define	suword __CONCAT(suword, __ELF_WORD_SIZE)
>  
> -int
> -__elfN(freebsd_fixup)(register_t **stack_base, struct image_params *imgp)
> +void
> +__elfN(freebsd_copyout_auxargs)(struct image_params *imgp, u_long *base)
>  {
>  	Elf_Auxargs *args = (Elf_Auxargs *)imgp->auxargs;
>  	Elf_Auxinfo *argarray, *pos;
> -	Elf_Addr *base, *auxbase;
> -	int error;
> +	u_long auxlen;
>  
> -	base = (Elf_Addr *)*stack_base;
> -	auxbase = base + imgp->args->argc + 1 + imgp->args->envc + 1;
>  	argarray = pos = malloc(AT_COUNT * sizeof(*pos), M_TEMP,
>  	    M_WAITOK | M_ZERO);
>  
> @@ -1376,11 +1373,18 @@ __elfN(freebsd_fixup)(register_t **stack_base, struct 
>  	imgp->auxargs = NULL;
>  	KASSERT(pos - argarray <= AT_COUNT, ("Too many auxargs"));
>  
> -	error = copyout(argarray, auxbase, sizeof(*argarray) * AT_COUNT);
> +	auxlen = sizeof(*argarray) * (pos - argarray);
> +	*base -= auxlen;
> +	copyout(argarray, (void *)*base, auxlen);
>  	free(argarray, M_TEMP);
> -	if (error != 0)
> -		return (error);
> +}
So you are ignoring copyout errors ?



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20191115200108.GH2707>