From owner-svn-src-stable-11@freebsd.org Wed Aug 1 17:40:20 2018 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C3354106478C; Wed, 1 Aug 2018 17:40:19 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 761107F4BD; Wed, 1 Aug 2018 17:40:19 +0000 (UTC) (envelope-from jhb@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 571B7259F3; Wed, 1 Aug 2018 17:40:19 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w71HeJhd086197; Wed, 1 Aug 2018 17:40:19 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w71HeIZu086191; Wed, 1 Aug 2018 17:40:18 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201808011740.w71HeIZu086191@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Wed, 1 Aug 2018 17:40:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r337046 - in stable/11/sys: amd64/linux amd64/linux32 compat/freebsd32 i386/linux kern sys X-SVN-Group: stable-11 X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: in stable/11/sys: amd64/linux amd64/linux32 compat/freebsd32 i386/linux kern sys X-SVN-Commit-Revision: 337046 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Aug 2018 17:40:20 -0000 Author: jhb Date: Wed Aug 1 17:40:17 2018 New Revision: 337046 URL: https://svnweb.freebsd.org/changeset/base/337046 Log: MFC 332782: Simplify the code to allocate stack for auxv, argv[], and environment vectors. Remove auxarg_size as it was only used once right after a confusing assignment in each of the variants of exec_copyout_strings(). Modified: stable/11/sys/amd64/linux/linux_sysvec.c stable/11/sys/amd64/linux32/linux32_sysvec.c stable/11/sys/compat/freebsd32/freebsd32_misc.c stable/11/sys/i386/linux/linux_sysvec.c stable/11/sys/kern/kern_exec.c stable/11/sys/sys/imgact.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/amd64/linux/linux_sysvec.c ============================================================================== --- stable/11/sys/amd64/linux/linux_sysvec.c Wed Aug 1 15:55:14 2018 (r337045) +++ stable/11/sys/amd64/linux/linux_sysvec.c Wed Aug 1 17:40:17 2018 (r337046) @@ -359,31 +359,21 @@ linux_copyout_strings(struct image_params *imgp) roundup(sizeof(canary), sizeof(char *)); copyout(canary, (void *)imgp->canary, sizeof(canary)); - /* If we have a valid auxargs ptr, prepare some room on the stack. */ + vectp = (char **)destp; if (imgp->auxargs) { /* - * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for - * lower compatibility. + * Allocate room on the stack for the ELF auxargs + * array. It has LINUX_AT_COUNT entries. */ - imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size : - (LINUX_AT_COUNT * 2); - - /* - * The '+ 2' is for the null pointers at the end of each of - * the arg and env vector sets,and imgp->auxarg_size is room - * for argument of Runtime loader. - */ - vectp = (char **)(destp - (imgp->args->argc + - imgp->args->envc + 2 + imgp->auxarg_size) * sizeof(char *)); - - } else { - /* - * The '+ 2' is for the null pointers at the end of each of - * the arg and env vector sets - */ - vectp = (char **)(destp - (imgp->args->argc + - imgp->args->envc + 2) * sizeof(char *)); + vectp -= howmany(LINUX_AT_COUNT * sizeof(Elf64_Auxinfo), + sizeof(*vectp)); } + + /* + * Allocate room for the argv[] and env vectors including the + * terminating NULL pointers. + */ + vectp -= imgp->args->argc + 1 + imgp->args->envc + 1; /* vectp also becomes our initial stack base. */ stack_base = (register_t *)vectp; Modified: stable/11/sys/amd64/linux32/linux32_sysvec.c ============================================================================== --- stable/11/sys/amd64/linux32/linux32_sysvec.c Wed Aug 1 15:55:14 2018 (r337045) +++ stable/11/sys/amd64/linux32/linux32_sysvec.c Wed Aug 1 17:40:17 2018 (r337046) @@ -854,31 +854,21 @@ linux_copyout_strings(struct image_params *imgp) roundup(sizeof(canary), sizeof(char *)); copyout(canary, (void *)imgp->canary, sizeof(canary)); - /* If we have a valid auxargs ptr, prepare some room on the stack. */ + vectp = (uint32_t *)destp; if (imgp->auxargs) { /* - * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for - * lower compatibility. + * Allocate room on the stack for the ELF auxargs + * array. It has LINUX_AT_COUNT entries. */ - imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size : - (LINUX_AT_COUNT * 2); - /* - * The '+ 2' is for the null pointers at the end of each of - * 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)); - - } else { - /* - * The '+ 2' is for the null pointers at the end of each of - * the arg and env vector sets - */ - vectp = (u_int32_t *)(destp - (imgp->args->argc + - imgp->args->envc + 2) * sizeof(u_int32_t)); + vectp -= howmany(LINUX_AT_COUNT * sizeof(Elf32_Auxinfo), + sizeof(*vectp)); } + + /* + * Allocate room for the argv[] and env vectors including the + * terminating NULL pointers. + */ + vectp -= imgp->args->argc + 1 + imgp->args->envc + 1; /* vectp also becomes our initial stack base. */ stack_base = vectp; Modified: stable/11/sys/compat/freebsd32/freebsd32_misc.c ============================================================================== --- stable/11/sys/compat/freebsd32/freebsd32_misc.c Wed Aug 1 15:55:14 2018 (r337045) +++ stable/11/sys/compat/freebsd32/freebsd32_misc.c Wed Aug 1 17:40:17 2018 (r337046) @@ -2885,33 +2885,21 @@ freebsd32_copyout_strings(struct image_params *imgp) destp -= ARG_MAX - imgp->args->stringspace; destp = rounddown2(destp, sizeof(uint32_t)); - /* - * If we have a valid auxargs ptr, prepare some room - * on the stack. - */ + vectp = (uint32_t *)destp; if (imgp->auxargs) { /* - * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for - * lower compatibility. + * Allocate room on the stack for the ELF auxargs + * array. It has up to AT_COUNT entries. */ - imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size - : (AT_COUNT * 2); - /* - * The '+ 2' is for the null pointers at the end of each of - * 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 + execpath_len) * - sizeof(u_int32_t)); - } else { - /* - * The '+ 2' is for the null pointers at the end of each of - * the arg and env vector sets - */ - vectp = (u_int32_t *)(destp - (imgp->args->argc + - imgp->args->envc + 2) * sizeof(u_int32_t)); + vectp -= howmany(AT_COUNT * sizeof(Elf32_Auxinfo), + sizeof(*vectp)); } + + /* + * Allocate room for the argv[] and env vectors including the + * terminating NULL pointers. + */ + vectp -= imgp->args->argc + 1 + imgp->args->envc + 1; /* * vectp also becomes our initial stack base Modified: stable/11/sys/i386/linux/linux_sysvec.c ============================================================================== --- stable/11/sys/i386/linux/linux_sysvec.c Wed Aug 1 15:55:14 2018 (r337045) +++ stable/11/sys/i386/linux/linux_sysvec.c Wed Aug 1 17:40:17 2018 (r337046) @@ -336,29 +336,21 @@ linux_copyout_strings(struct image_params *imgp) roundup(sizeof(canary), sizeof(char *)); copyout(canary, (void *)imgp->canary, sizeof(canary)); - /* If we have a valid auxargs ptr, prepare some room on the stack. */ + vectp = (char **)destp; if (imgp->auxargs) { /* - * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for - * lower compatibility. + * Allocate room on the stack for the ELF auxargs + * array. It has LINUX_AT_COUNT entries. */ - imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size : - (LINUX_AT_COUNT * 2); - /* - * The '+ 2' is for the null pointers at the end of each of - * the arg and env vector sets,and imgp->auxarg_size is room - * for argument of Runtime loader. - */ - vectp = (char **)(destp - (imgp->args->argc + - imgp->args->envc + 2 + imgp->auxarg_size) * sizeof(char *)); - } else { - /* - * The '+ 2' is for the null pointers at the end of each of - * the arg and env vector sets - */ - vectp = (char **)(destp - (imgp->args->argc + imgp->args->envc + 2) * - sizeof(char *)); + vectp -= howmany(LINUX_AT_COUNT * sizeof(Elf32_Auxinfo), + sizeof(*vectp)); } + + /* + * Allocate room for the argv[] and env vectors including the + * terminating NULL pointers. + */ + vectp -= imgp->args->argc + 1 + imgp->args->envc + 1; /* vectp also becomes our initial stack base. */ stack_base = (register_t *)vectp; Modified: stable/11/sys/kern/kern_exec.c ============================================================================== --- stable/11/sys/kern/kern_exec.c Wed Aug 1 15:55:14 2018 (r337045) +++ stable/11/sys/kern/kern_exec.c Wed Aug 1 17:40:17 2018 (r337046) @@ -1533,33 +1533,21 @@ exec_copyout_strings(struct image_params *imgp) destp -= ARG_MAX - imgp->args->stringspace; destp = rounddown2(destp, sizeof(void *)); - /* - * If we have a valid auxargs ptr, prepare some room - * on the stack. - */ + vectp = (char **)destp; if (imgp->auxargs) { /* - * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for - * lower compatibility. + * Allocate room on the stack for the ELF auxargs + * array. It has up to AT_COUNT entries. */ - imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size : - (AT_COUNT * 2); - /* - * The '+ 2' is for the null pointers at the end of each of - * the arg and env vector sets,and imgp->auxarg_size is room - * for argument of Runtime loader. - */ - vectp = (char **)(destp - (imgp->args->argc + - imgp->args->envc + 2 + imgp->auxarg_size) - * sizeof(char *)); - } else { - /* - * The '+ 2' is for the null pointers at the end of each of - * the arg and env vector sets - */ - vectp = (char **)(destp - (imgp->args->argc + imgp->args->envc - + 2) * sizeof(char *)); + vectp -= howmany(AT_COUNT * sizeof(Elf_Auxinfo), + sizeof(*vectp)); } + + /* + * Allocate room for the argv[] and env vectors including the + * terminating NULL pointers. + */ + vectp -= imgp->args->argc + 1 + imgp->args->envc + 1; /* * vectp also becomes our initial stack base Modified: stable/11/sys/sys/imgact.h ============================================================================== --- stable/11/sys/sys/imgact.h Wed Aug 1 15:55:14 2018 (r337045) +++ stable/11/sys/sys/imgact.h Wed Aug 1 17:40:17 2018 (r337046) @@ -73,7 +73,6 @@ struct image_params { void *auxargs; /* ELF Auxinfo structure pointer */ struct sf_buf *firstpage; /* first page that we mapped */ unsigned long ps_strings; /* PS_STRINGS for BSD/OS binaries */ - size_t auxarg_size; struct image_args *args; /* system call arguments */ struct sysentvec *sysent; /* system entry vector */ char *execpath;