Source-Changes-HG archive

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

[src/trunk]: src/sys/compat/netbsd32 Adapt to recent posix_spawn extensions.



details:   https://anonhg.NetBSD.org/src/rev/2a1302838e2f
branches:  trunk
changeset: 1025542:2a1302838e2f
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Nov 11 17:32:46 2021 +0000

description:
Adapt to recent posix_spawn extensions.

diffstat:

 sys/compat/netbsd32/netbsd32.h        |   8 +++++-
 sys/compat/netbsd32/netbsd32_execve.c |  42 +++++++++++++++++++++++++----------
 2 files changed, 36 insertions(+), 14 deletions(-)

diffs (117 lines):

diff -r 953a102ef3e3 -r 2a1302838e2f sys/compat/netbsd32/netbsd32.h
--- a/sys/compat/netbsd32/netbsd32.h    Thu Nov 11 14:24:24 2021 +0000
+++ b/sys/compat/netbsd32/netbsd32.h    Thu Nov 11 17:32:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32.h,v 1.138 2021/11/06 20:42:56 thorpej Exp $   */
+/*     $NetBSD: netbsd32.h,v 1.139 2021/11/11 17:32:46 martin Exp $    */
 
 /*
  * Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
@@ -1152,7 +1152,8 @@
 };
 
 struct netbsd32_posix_spawn_file_actions_entry {
-       enum { FAE32_OPEN, FAE32_DUP2, FAE32_CLOSE } fae_action;
+       enum { FAE32_OPEN, FAE32_DUP2, FAE32_CLOSE,
+           FAE32_CHDIR, FAE32_FCHDIR } fae_action;
 
        int fae_fildes;
        union {
@@ -1164,6 +1165,9 @@
                struct {
                        int newfildes;
                } dup2;
+               struct {
+                       netbsd32_charp path;
+               } chdir;
        } fae_data;
 };
 
diff -r 953a102ef3e3 -r 2a1302838e2f sys/compat/netbsd32/netbsd32_execve.c
--- a/sys/compat/netbsd32/netbsd32_execve.c     Thu Nov 11 14:24:24 2021 +0000
+++ b/sys/compat/netbsd32/netbsd32_execve.c     Thu Nov 11 17:32:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_execve.c,v 1.43 2021/04/13 05:28:16 mrg Exp $ */
+/*     $NetBSD: netbsd32_execve.c,v 1.44 2021/11/11 17:32:46 martin 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.43 2021/04/13 05:28:16 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.44 2021/11/11 17:32:46 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -90,6 +90,26 @@
            SCARG_P32(uap, envp), netbsd32_execve_fetch_element);
 }
 
+static __inline bool
+netbsd32_posix_spawn_fae_path(
+    struct posix_spawn_file_actions_entry *fae,
+    struct netbsd32_posix_spawn_file_actions_entry *fae32,
+    char ***pathp, char **pathp32)
+{
+       switch (fae->fae_action) {
+       case FAE_OPEN:
+               *pathp = &fae->fae_path;
+               *pathp32 = NETBSD32PTR64(fae32->fae_data.open.path);
+               return true;
+       case FAE_CHDIR:
+               *pathp = &fae->fae_chdir_path;
+               *pathp32 = NETBSD32PTR64(fae32->fae_data.chdir.path);
+               return true;
+       default:
+               return false;
+       }
+}
+
 static int
 netbsd32_posix_spawn_fa_alloc(struct posix_spawn_file_actions **fap,
     const struct netbsd32_posix_spawn_file_actions *ufa, rlim_t lim)
@@ -98,7 +118,7 @@
        struct netbsd32_posix_spawn_file_actions fa32;
        struct netbsd32_posix_spawn_file_actions_entry *fae32 = NULL, *f32 = NULL;
        struct posix_spawn_file_actions_entry *fae;
-       char *pbuf = NULL;
+       char *pbuf = NULL, **pathp = NULL, *pathp32 = NULL;
        int error;
        size_t fal, fal32, slen, i = 0;
 
@@ -135,26 +155,24 @@
                if (fae->fae_action == FAE_DUP2)
                        fae->fae_data.dup2.newfildes =
                            f32->fae_data.dup2.newfildes;
-               if (fae->fae_action != FAE_OPEN)
+               if (!netbsd32_posix_spawn_fae_path(fae, f32, &pathp, &pathp32)
+                   || pathp == NULL || pathp32 == NULL)
                        continue;
-               error = copyinstr(NETBSD32PTR64(f32->fae_path), pbuf,
-                   MAXPATHLEN, &slen);
+               error = copyinstr(pathp32, pbuf, MAXPATHLEN, &slen);
                if (error)
                        goto out;
-               fae->fae_path = kmem_alloc(slen, KM_SLEEP);
-               memcpy(fae->fae_path, pbuf, slen);
+               *pathp = kmem_alloc(slen, KM_SLEEP);
+               memcpy(*pathp, pbuf, slen);
                fae->fae_oflag = f32->fae_oflag;
                fae->fae_mode = f32->fae_mode;
        }
        PNBUF_PUT(pbuf);
-       if (fae32)
-               kmem_free(fae32, fal32);
+       kmem_free(fae32, fal32);
        *fap = fa;
        return 0;
 
 out:
-       if (fae32)
-               kmem_free(fae32, fal32);
+       kmem_free(fae32, fal32);
        if (pbuf)
                PNBUF_PUT(pbuf);
        posix_spawn_fa_free(fa, i);



Home | Main Index | Thread Index | Old Index