From owner-svn-src-head@freebsd.org Fri Nov 15 20:01:20 2019 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 056701AF241; Fri, 15 Nov 2019 20:01:20 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 47F8PB3msJz3yXh; Fri, 15 Nov 2019 20:01:18 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id xAFK18QH029252 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 15 Nov 2019 22:01:12 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua xAFK18QH029252 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id xAFK18Sr029251; Fri, 15 Nov 2019 22:01:08 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 15 Nov 2019 22:01:08 +0200 From: Konstantin Belousov To: John Baldwin 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> References: <201911151842.xAFIgDrJ093716@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201911151842.xAFIgDrJ093716@repo.freebsd.org> User-Agent: Mutt/1.12.2 (2019-09-21) X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on tom.home X-Rspamd-Queue-Id: 47F8PB3msJz3yXh X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com X-Spamd-Result: default: False [-2.00 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; FREEMAIL_FROM(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; R_SPF_SOFTFAIL(0.00)[~all:c]; IP_SCORE_FREEMAIL(0.00)[]; TO_DN_SOME(0.00)[]; IP_SCORE(0.00)[ip: (-2.72), ipnet: 2001:470::/32(-4.62), asn: 6939(-3.49), country: US(-0.05)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVFROM(0.00)[gmail.com]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none] 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: Fri, 15 Nov 2019 20:01:20 -0000 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 ?