Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add a boolean argument to indicate if we have a path/tru...



details:   https://anonhg.NetBSD.org/src/rev/30578b96adc0
branches:  trunk
changeset: 845094:30578b96adc0
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Sep 17 15:19:27 2019 +0000

description:
Add a boolean argument to indicate if we have a path/true (execve) or an
fd/false (fexecve). This is needed to differentiate between them because
NULL/-1 can be readily passed from userland.

diffstat:

 sys/compat/netbsd32/netbsd32_execve.c |   8 +++---
 sys/compat/sunos32/sunos32_misc.c     |  11 ++++-----
 sys/kern/kern_exec.c                  |  39 ++++++++++++++++++----------------
 sys/sys/exec.h                        |   8 +++---
 4 files changed, 34 insertions(+), 32 deletions(-)

diffs (208 lines):

diff -r cb1429fc0ac6 -r 30578b96adc0 sys/compat/netbsd32/netbsd32_execve.c
--- a/sys/compat/netbsd32/netbsd32_execve.c     Tue Sep 17 07:58:54 2019 +0000
+++ b/sys/compat/netbsd32/netbsd32_execve.c     Tue Sep 17 15:19:27 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_execve.c,v 1.40 2019/09/15 20:26:51 christos Exp $    */
+/*     $NetBSD: netbsd32_execve.c,v 1.41 2019/09/17 15:19:27 christos Exp $    */
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.40 2019/09/15 20:26:51 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.41 2019/09/17 15:19:27 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -72,7 +72,7 @@
                syscallarg(netbsd32_charpp) envp;
        } */
 
-       return execve1(l, SCARG_P32(uap, path), -1, SCARG_P32(uap, argp),
+       return execve1(l, true, SCARG_P32(uap, path), -1, SCARG_P32(uap, argp),
            SCARG_P32(uap, envp), netbsd32_execve_fetch_element);
 }
 
@@ -86,7 +86,7 @@
                syscallarg(netbsd32_charpp) envp;
        } */
 
-       return execve1(l, NULL, SCARG(uap, fd), SCARG_P32(uap, argp),
+       return execve1(l, false, NULL, SCARG(uap, fd), SCARG_P32(uap, argp),
            SCARG_P32(uap, envp), netbsd32_execve_fetch_element);
 }
 
diff -r cb1429fc0ac6 -r 30578b96adc0 sys/compat/sunos32/sunos32_misc.c
--- a/sys/compat/sunos32/sunos32_misc.c Tue Sep 17 07:58:54 2019 +0000
+++ b/sys/compat/sunos32/sunos32_misc.c Tue Sep 17 15:19:27 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sunos32_misc.c,v 1.80 2019/09/17 07:58:54 mrg Exp $    */
+/*     $NetBSD: sunos32_misc.c,v 1.81 2019/09/17 15:19:27 christos Exp $       */
 /* from :NetBSD: sunos_misc.c,v 1.107 2000/12/01 19:25:10 jdolecek Exp */
 
 /*
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.80 2019/09/17 07:58:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.81 2019/09/17 15:19:27 christos Exp $");
 
 #define COMPAT_SUNOS 1
 
@@ -388,7 +388,7 @@
        } */
        const char *path = SCARG_P32(uap, path);
 
-       return execve1(l, path, -1, SCARG_P32(uap, argp), NULL,
+       return execve1(l, true, path, -1, SCARG_P32(uap, argp), NULL,
            sunos32_execve_fetch_element);
 }
 
@@ -402,9 +402,8 @@
        } */
        const char *path = SCARG_P32(uap, path);
 
-       return execve1(l, path, -1, SCARG_P32(uap, argp),
-           SCARG_P32(uap, envp),
-           sunos32_execve_fetch_element);
+       return execve1(l, true, path, -1, SCARG_P32(uap, argp),
+           SCARG_P32(uap, envp), sunos32_execve_fetch_element);
 }
 
 int
diff -r cb1429fc0ac6 -r 30578b96adc0 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Tue Sep 17 07:58:54 2019 +0000
+++ b/sys/kern/kern_exec.c      Tue Sep 17 15:19:27 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.480 2019/09/15 20:23:50 christos Exp $ */
+/*     $NetBSD: kern_exec.c,v 1.481 2019/09/17 15:19:27 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.480 2019/09/15 20:23:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.481 2019/09/17 15:19:27 christos Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -583,7 +583,7 @@
                syscallarg(char * const *)      envp;
        } */
 
-       return execve1(l, SCARG(uap, path), -1, SCARG(uap, argp),
+       return execve1(l, true, SCARG(uap, path), -1, SCARG(uap, argp),
            SCARG(uap, envp), execve_fetch_element);
 }
 
@@ -597,7 +597,7 @@
                syscallarg(char * const *)      envp;
        } */
 
-       return execve1(l, NULL, SCARG(uap, fd), SCARG(uap, argp),
+       return execve1(l, false, NULL, SCARG(uap, fd), SCARG(uap, argp),
            SCARG(uap, envp), execve_fetch_element);
 }
 
@@ -719,8 +719,9 @@
 }
 
 static int
-execve_loadvm(struct lwp *l, const char *path, int fd, char * const *args,
-       char * const *envs, execve_fetch_element_t fetch_element,
+execve_loadvm(struct lwp *l, bool has_path, const char *path, int fd,
+       char * const *args, char * const *envs,
+       execve_fetch_element_t fetch_element,
        struct execve_data * restrict data)
 {
        struct exec_package     * const epp = &data->ed_pack;
@@ -770,14 +771,7 @@
         */
        rw_enter(&p->p_reflock, RW_WRITER);
 
-       if (path == NULL) {
-               data->ed_pathbuf = pathbuf_assimilate(strcpy(PNBUF_GET(), "/"));
-               data->ed_pathstring = pathbuf_stringcopy_get(data->ed_pathbuf);
-               epp->ep_kname = "*fexecve*";
-               data->ed_resolvedname = NULL;
-               epp->ep_resolvedname = NULL;
-               epp->ep_xfd = fd;
-       } else {
+       if (has_path) {
                size_t  offs;
                /*
                 * Init the namei data to point the file user's program name.
@@ -794,6 +788,13 @@
                data->ed_resolvedname = PNBUF_GET();
                epp->ep_resolvedname = data->ed_resolvedname;
                epp->ep_xfd = -1;
+       } else {
+               data->ed_pathbuf = pathbuf_assimilate(strcpy(PNBUF_GET(), "/"));
+               data->ed_pathstring = pathbuf_stringcopy_get(data->ed_pathbuf);
+               epp->ep_kname = "*fexecve*";
+               data->ed_resolvedname = NULL;
+               epp->ep_resolvedname = NULL;
+               epp->ep_xfd = fd;
        }
 
 
@@ -1406,13 +1407,15 @@
 }
 
 int
-execve1(struct lwp *l, const char *path, int fd, char * const *args,
-    char * const *envs, execve_fetch_element_t fetch_element)
+execve1(struct lwp *l, bool has_path, const char *path, int fd,
+    char * const *args, char * const *envs,
+    execve_fetch_element_t fetch_element)
 {
        struct execve_data data;
        int error;
 
-       error = execve_loadvm(l, path, fd, args, envs, fetch_element, &data);
+       error = execve_loadvm(l, has_path, path, fd, args, envs, fetch_element,
+           &data);
        if (error)
                return error;
        error = execve_runproc(l, &data, false, false);
@@ -2436,7 +2439,7 @@
         * Do the first part of the exec now, collect state
         * in spawn_data.
         */
-       error = execve_loadvm(l1, path, -1, argv,
+       error = execve_loadvm(l1, true, path, -1, argv,
            envp, fetch, &spawn_data->sed_exec);
        if (error == EJUSTRETURN)
                error = 0;
diff -r cb1429fc0ac6 -r 30578b96adc0 sys/sys/exec.h
--- a/sys/sys/exec.h    Tue Sep 17 07:58:54 2019 +0000
+++ b/sys/sys/exec.h    Tue Sep 17 15:19:27 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec.h,v 1.155 2019/09/15 20:26:27 christos Exp $      */
+/*     $NetBSD: exec.h,v 1.156 2019/09/17 15:19:27 christos Exp $      */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -302,14 +302,14 @@
        new_vmcmd(evsp,lwp,len,addr,vp,offset,prot,flags)
 
 typedef        int (*execve_fetch_element_t)(char * const *, size_t, char **);
-int    execve1(struct lwp *, const char *, int, char * const *, char * const *,
-    execve_fetch_element_t);
+int    execve1(struct lwp *, bool, const char *, int, char * const *,
+    char * const *, execve_fetch_element_t);
 
 struct posix_spawn_file_actions;
 struct posix_spawnattr;
 int    check_posix_spawn       (struct lwp *);
 void   posix_spawn_fa_free(struct posix_spawn_file_actions *, size_t);
-int    do_posix_spawn(struct lwp *, pid_t *, bool*, const char *,
+int    do_posix_spawn(struct lwp *, pid_t *, bool *, const char *,
     struct posix_spawn_file_actions *, struct posix_spawnattr *,
     char *const *, char *const *, execve_fetch_element_t);
 int      exec_makepathbuf(struct lwp *, const char *, enum uio_seg,



Home | Main Index | Thread Index | Old Index