From owner-svn-src-head@FreeBSD.ORG Tue Jul 27 17:31:03 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D15AD106566B; Tue, 27 Jul 2010 17:31:03 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BFAAA8FC0C; Tue, 27 Jul 2010 17:31:03 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o6RHV3LV061031; Tue, 27 Jul 2010 17:31:03 GMT (envelope-from alc@svn.freebsd.org) Received: (from alc@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o6RHV34O061025; Tue, 27 Jul 2010 17:31:03 GMT (envelope-from alc@svn.freebsd.org) Message-Id: <201007271731.o6RHV34O061025@svn.freebsd.org> From: Alan Cox Date: Tue, 27 Jul 2010 17:31:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210545 - in head/sys: compat/freebsd32 kern sys vm X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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: Tue, 27 Jul 2010 17:31:03 -0000 Author: alc Date: Tue Jul 27 17:31:03 2010 New Revision: 210545 URL: http://svn.freebsd.org/changeset/base/210545 Log: Introduce exec_alloc_args(). The objective being to encapsulate the details of the string buffer allocation in one place. Eliminate the portion of the string buffer that was dedicated to storing the interpreter name. The pointer to the interpreter name can simply be made to point to the appropriate argument string. Reviewed by: kib Modified: head/sys/compat/freebsd32/freebsd32_misc.c head/sys/kern/imgact_shell.c head/sys/kern/kern_exec.c head/sys/sys/imgact.h head/sys/vm/vm_init.c Modified: head/sys/compat/freebsd32/freebsd32_misc.c ============================================================================== --- head/sys/compat/freebsd32/freebsd32_misc.c Tue Jul 27 17:23:40 2010 (r210544) +++ head/sys/compat/freebsd32/freebsd32_misc.c Tue Jul 27 17:31:03 2010 (r210545) @@ -86,7 +86,6 @@ __FBSDID("$FreeBSD$"); #endif #include -#include #include #include #include @@ -279,19 +278,18 @@ freebsd32_exec_copyin_args(struct image_ return (EFAULT); /* - * Allocate temporary demand zeroed space for argument and - * environment strings + * Allocate demand-paged memory for the file name, argument, and + * environment strings. */ - args->buf = (char *) kmem_alloc_wait(exec_map, - PATH_MAX + ARG_MAX + MAXSHELLCMDLEN); - if (args->buf == NULL) - return (ENOMEM); + error = exec_alloc_args(args); + if (error != 0) + return (error); /* * Copy the file name. */ if (fname != NULL) { - args->fname = args->buf + MAXSHELLCMDLEN; + args->fname = args->buf; error = (segflg == UIO_SYSSPACE) ? copystr(fname, args->fname, PATH_MAX, &length) : copyinstr(fname, args->fname, PATH_MAX, &length); @@ -300,7 +298,7 @@ freebsd32_exec_copyin_args(struct image_ } else length = 0; - args->begin_argv = args->buf + MAXSHELLCMDLEN + length; + args->begin_argv = args->buf + length; args->endp = args->begin_argv; args->stringspace = ARG_MAX; Modified: head/sys/kern/imgact_shell.c ============================================================================== --- head/sys/kern/imgact_shell.c Tue Jul 27 17:23:40 2010 (r210544) +++ head/sys/kern/imgact_shell.c Tue Jul 27 17:31:03 2010 (r210545) @@ -240,8 +240,7 @@ exec_shell_imgact(imgp) imgp->args->stringspace, NULL); if (error == 0) - error = copystr(imgp->args->begin_argv, imgp->interpreter_name, - MAXSHELLCMDLEN, NULL); + imgp->interpreter_name = imgp->args->begin_argv; if (sname != NULL) sbuf_delete(sname); Modified: head/sys/kern/kern_exec.c ============================================================================== --- head/sys/kern/kern_exec.c Tue Jul 27 17:23:40 2010 (r210544) +++ head/sys/kern/kern_exec.c Tue Jul 27 17:31:03 2010 (r210545) @@ -375,7 +375,7 @@ do_execve(td, args, mac_p) imgp->vmspace_destroyed = 0; imgp->interpreted = 0; imgp->opened = 0; - imgp->interpreter_name = args->buf; + imgp->interpreter_name = NULL; imgp->auxargs = NULL; imgp->vp = NULL; imgp->object = NULL; @@ -1078,23 +1078,20 @@ exec_copyin_args(struct image_args *args bzero(args, sizeof(*args)); if (argv == NULL) return (EFAULT); + /* - * Allocate temporary demand zeroed space for argument and - * environment strings: - * - * o ARG_MAX for argument and environment; - * o MAXSHELLCMDLEN for the name of interpreters. + * Allocate demand-paged memory for the file name, argument, and + * environment strings. */ - args->buf = (char *) kmem_alloc_wait(exec_map, - PATH_MAX + ARG_MAX + MAXSHELLCMDLEN); - if (args->buf == NULL) - return (ENOMEM); + error = exec_alloc_args(args); + if (error != 0) + return (error); /* * Copy the file name. */ if (fname != NULL) { - args->fname = args->buf + MAXSHELLCMDLEN; + args->fname = args->buf; error = (segflg == UIO_SYSSPACE) ? copystr(fname, args->fname, PATH_MAX, &length) : copyinstr(fname, args->fname, PATH_MAX, &length); @@ -1103,7 +1100,7 @@ exec_copyin_args(struct image_args *args } else length = 0; - args->begin_argv = args->buf + MAXSHELLCMDLEN + length; + args->begin_argv = args->buf + length; args->endp = args->begin_argv; args->stringspace = ARG_MAX; @@ -1156,13 +1153,26 @@ err_exit: return (error); } +/* + * Allocate temporary demand-paged, zero-filled memory for the file name, + * argument, and environment strings. Returns zero if the allocation succeeds + * and ENOMEM otherwise. + */ +int +exec_alloc_args(struct image_args *args) +{ + + args->buf = (char *)kmem_alloc_wait(exec_map, PATH_MAX + ARG_MAX); + return (args->buf != NULL ? 0 : ENOMEM); +} + void exec_free_args(struct image_args *args) { if (args->buf != NULL) { kmem_free_wakeup(exec_map, (vm_offset_t)args->buf, - PATH_MAX + ARG_MAX + MAXSHELLCMDLEN); + PATH_MAX + ARG_MAX); args->buf = NULL; } } Modified: head/sys/sys/imgact.h ============================================================================== --- head/sys/sys/imgact.h Tue Jul 27 17:23:40 2010 (r210544) +++ head/sys/sys/imgact.h Tue Jul 27 17:31:03 2010 (r210545) @@ -78,6 +78,7 @@ struct thread; #define IMGACT_CORE_COMPRESS 0x01 +int exec_alloc_args(struct image_args *); int exec_check_permissions(struct image_params *); register_t *exec_copyout_strings(struct image_params *); void exec_free_args(struct image_args *); Modified: head/sys/vm/vm_init.c ============================================================================== --- head/sys/vm/vm_init.c Tue Jul 27 17:23:40 2010 (r210544) +++ head/sys/vm/vm_init.c Tue Jul 27 17:31:03 2010 (r210545) @@ -73,7 +73,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -195,8 +194,7 @@ again: (long)nswbuf * MAXPHYS, FALSE); pager_map->system_map = 1; exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, - exec_map_entries * round_page(PATH_MAX + ARG_MAX + MAXSHELLCMDLEN), - FALSE); + exec_map_entries * round_page(PATH_MAX + ARG_MAX), FALSE); pipe_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, maxpipekva, FALSE);