The branch main has been updated by mjg:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=a0558fe90d3bebdf8583888cc96b4c170eab8cfb

commit a0558fe90d3bebdf8583888cc96b4c170eab8cfb
Author:     Mateusz Guzik <m...@freebsd.org>
AuthorDate: 2021-04-28 20:55:03 +0000
Commit:     Mateusz Guzik <m...@freebsd.org>
CommitDate: 2021-10-10 18:24:29 +0000

    Retire code added to support CloudABI
    
    CloudABI was removed in cf0ee8738e31aa9e6fbf4dca4dac56d89226a71a
---
 sys/kern/kern_descrip.c | 97 ++-----------------------------------------------
 sys/kern/kern_exec.c    | 88 ++++----------------------------------------
 sys/kern/kern_fork.c    |  4 +-
 sys/kern/subr_syscall.c |  2 -
 sys/sys/filedesc.h      |  5 ---
 sys/sys/imgact.h        |  3 --
 sys/sys/proc.h          |  2 +-
 7 files changed, 14 insertions(+), 187 deletions(-)

diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 755b5df51c6a..b10dcc2f9469 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -906,7 +906,7 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, 
int new)
        FILEDESC_XLOCK(fdp);
        if (fget_locked(fdp, old) == NULL)
                goto unlock;
-       if ((mode == FDDUP_FIXED || mode == FDDUP_MUSTREPLACE) && old == new) {
+       if (mode == FDDUP_FIXED && old == new) {
                td->td_retval[0] = new;
                if (flags & FDDUP_FLAG_CLOEXEC)
                        fdp->fd_ofiles[new].fde_flags |= UF_EXCLOSE;
@@ -932,13 +932,6 @@ kern_dup(struct thread *td, u_int mode, int flags, int 
old, int new)
                        goto unlock;
                }
                break;
-       case FDDUP_MUSTREPLACE:
-               /* Target file descriptor must exist. */
-               if (fget_locked(fdp, new) == NULL) {
-                       fdrop(oldfp, td);
-                       goto unlock;
-               }
-               break;
        case FDDUP_FIXED:
                if (new >= fdp->fd_nfiles) {
                        /*
@@ -2320,14 +2313,6 @@ pdunshare(struct thread *td)
        p->p_pd = pdp;
 }
 
-void
-fdinstall_remapped(struct thread *td, struct filedesc *fdp)
-{
-
-       fdescfree(td);
-       td->td_proc->p_fd = fdp;
-}
-
 /*
  * Copy a filedesc structure.  A NULL pointer in returns a NULL reference,
  * this is to ease callers, not catch errors.
@@ -2380,66 +2365,6 @@ pdcopy(struct pwddesc *pdp)
        return (newpdp);
 }
 
-/*
- * Copies a filedesc structure, while remapping all file descriptors
- * stored inside using a translation table.
- *
- * File descriptors are copied over to the new file descriptor table,
- * regardless of whether the close-on-exec flag is set.
- */
-int
-fdcopy_remapped(struct filedesc *fdp, const int *fds, size_t nfds,
-    struct filedesc **ret)
-{
-       struct filedesc *newfdp;
-       struct filedescent *nfde, *ofde;
-       int error, i, lastfile;
-
-       MPASS(fdp != NULL);
-
-       newfdp = fdinit(fdp, true, &lastfile);
-       if (nfds > lastfile + 1) {
-               /* New table cannot be larger than the old one. */
-               error = E2BIG;
-               goto bad;
-       }
-       /* Copy all passable descriptors (i.e. not kqueue). */
-       newfdp->fd_freefile = nfds;
-       for (i = 0; i < nfds; ++i) {
-               if (fds[i] < 0 || fds[i] > lastfile) {
-                       /* File descriptor out of bounds. */
-                       error = EBADF;
-                       goto bad;
-               }
-               ofde = &fdp->fd_ofiles[fds[i]];
-               if (ofde->fde_file == NULL) {
-                       /* Unused file descriptor. */
-                       error = EBADF;
-                       goto bad;
-               }
-               if ((ofde->fde_file->f_ops->fo_flags & DFLAG_PASSABLE) == 0) {
-                       /* File descriptor cannot be passed. */
-                       error = EINVAL;
-                       goto bad;
-               }
-               if (!fhold(ofde->fde_file)) {
-                       error = EBADF;
-                       goto bad;
-               }
-               nfde = &newfdp->fd_ofiles[i];
-               *nfde = *ofde;
-               filecaps_copy(&ofde->fde_caps, &nfde->fde_caps, true);
-               fdused_init(newfdp, i);
-       }
-       FILEDESC_SUNLOCK(fdp);
-       *ret = newfdp;
-       return (0);
-bad:
-       FILEDESC_SUNLOCK(fdp);
-       fdescfree_remapped(newfdp);
-       return (error);
-}
-
 /*
  * Clear POSIX style locks. This is only used when fdp looses a reference (i.e.
  * one of processes using it exits) and the table used to be shared.
@@ -2526,7 +2451,7 @@ retry:
  * Release a filedesc structure.
  */
 static void
-fdescfree_fds(struct thread *td, struct filedesc *fdp, bool needclose)
+fdescfree_fds(struct thread *td, struct filedesc *fdp)
 {
        struct filedesc0 *fdp0;
        struct freetable *ft, *tft;
@@ -2551,10 +2476,7 @@ fdescfree_fds(struct thread *td, struct filedesc *fdp, 
bool needclose)
                fp = fde->fde_file;
                if (fp != NULL) {
                        fdefree_last(fde);
-                       if (needclose)
-                               (void) closef(fp, td);
-                       else
-                               fdrop(fp, td);
+                       (void) closef(fp, td);
                }
        }
 
@@ -2598,7 +2520,7 @@ fdescfree(struct thread *td)
        if (refcount_release(&fdp->fd_refcnt) == 0)
                return;
 
-       fdescfree_fds(td, fdp, 1);
+       fdescfree_fds(td, fdp);
 }
 
 void
@@ -2621,17 +2543,6 @@ pdescfree(struct thread *td)
        pddrop(pdp);
 }
 
-void
-fdescfree_remapped(struct filedesc *fdp)
-{
-#ifdef INVARIANTS
-       /* fdescfree_fds() asserts that fd_refcnt == 0. */
-       if (!refcount_release(&fdp->fd_refcnt))
-               panic("%s: fd table %p has extra references", __func__, fdp);
-#endif
-       fdescfree_fds(curthread, fdp, 0);
-}
-
 /*
  * For setugid programs, we don't want to people to use that setugidness
  * to generate error messages which write to a file which otherwise would
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 7ec405ee6a62..50e75fda6cfb 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -704,21 +704,14 @@ interpret:
                goto exec_fail_dealloc;
        }
 
-       if (args->fdp != NULL) {
-               /* Install a brand new file descriptor table. */
-               fdinstall_remapped(td, args->fdp);
-               args->fdp = NULL;
-       } else {
-               /*
-                * Keep on using the existing file descriptor table. For
-                * security and other reasons, the file descriptor table
-                * cannot be shared after an exec.
-                */
-               fdunshare(td);
-               pdunshare(td);
-               /* close files on exec */
-               fdcloseexec(td);
-       }
+       /*
+        * For security and other reasons, the file descriptor table cannot be
+        * shared after an exec.
+        */
+       fdunshare(td);
+       pdunshare(td);
+       /* close files on exec */
+       fdcloseexec(td);
 
        /*
         * Malloc things before we need locks.
@@ -1239,69 +1232,6 @@ err_exit:
        return (error);
 }
 
-int
-exec_copyin_data_fds(struct thread *td, struct image_args *args,
-    const void *data, size_t datalen, const int *fds, size_t fdslen)
-{
-       struct filedesc *ofdp;
-       const char *p;
-       int *kfds;
-       int error;
-
-       memset(args, '\0', sizeof(*args));
-       ofdp = td->td_proc->p_fd;
-       if (datalen >= ARG_MAX || fdslen >= ofdp->fd_nfiles)
-               return (E2BIG);
-       error = exec_alloc_args(args);
-       if (error != 0)
-               return (error);
-
-       args->begin_argv = args->buf;
-       args->stringspace = ARG_MAX;
-
-       if (datalen > 0) {
-               /*
-                * Argument buffer has been provided. Copy it into the
-                * kernel as a single string and add a terminating null
-                * byte.
-                */
-               error = copyin(data, args->begin_argv, datalen);
-               if (error != 0)
-                       goto err_exit;
-               args->begin_argv[datalen] = '\0';
-               args->endp = args->begin_argv + datalen + 1;
-               args->stringspace -= datalen + 1;
-
-               /*
-                * Traditional argument counting. Count the number of
-                * null bytes.
-                */
-               for (p = args->begin_argv; p < args->endp; ++p)
-                       if (*p == '\0')
-                               ++args->argc;
-       } else {
-               /* No argument buffer provided. */
-               args->endp = args->begin_argv;
-       }
-
-       /* Create new file descriptor table. */
-       kfds = malloc(fdslen * sizeof(int), M_TEMP, M_WAITOK);
-       error = copyin(fds, kfds, fdslen * sizeof(int));
-       if (error != 0) {
-               free(kfds, M_TEMP);
-               goto err_exit;
-       }
-       error = fdcopy_remapped(ofdp, kfds, fdslen, &args->fdp);
-       free(kfds, M_TEMP);
-       if (error != 0)
-               goto err_exit;
-
-       return (0);
-err_exit:
-       exec_free_args(args);
-       return (error);
-}
-
 struct exec_args_kva {
        vm_offset_t addr;
        u_int gen;
@@ -1438,8 +1368,6 @@ exec_free_args(struct image_args *args)
                free(args->fname_buf, M_TEMP);
                args->fname_buf = NULL;
        }
-       if (args->fdp != NULL)
-               fdescfree_remapped(args->fdp);
 }
 
 /*
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 2d8381894a7c..606801283a1f 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -597,8 +597,7 @@ do_fork(struct thread *td, struct fork_req *fr, struct proc 
*p2, struct thread *
         * been preserved.
         */
        p2->p_flag |= p1->p_flag & P_SUGID;
-       td2->td_pflags |= (td->td_pflags & (TDP_ALTSTACK |
-           TDP_SIGFASTBLOCK)) | TDP_FORKING;
+       td2->td_pflags |= (td->td_pflags & (TDP_ALTSTACK | TDP_SIGFASTBLOCK));
        SESS_LOCK(p1->p_session);
        if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT)
                p2->p_flag |= P_CONTROLT;
@@ -1100,7 +1099,6 @@ fork_exit(void (*callout)(void *, struct trapframe *), 
void *arg,
 
        if (p->p_sysent->sv_schedtail != NULL)
                (p->p_sysent->sv_schedtail)(td);
-       td->td_pflags &= ~TDP_FORKING;
 }
 
 /*
diff --git a/sys/kern/subr_syscall.c b/sys/kern/subr_syscall.c
index 2304e3e7f3f9..ada2053bc87c 100644
--- a/sys/kern/subr_syscall.c
+++ b/sys/kern/subr_syscall.c
@@ -215,8 +215,6 @@ syscallret(struct thread *td)
        ksiginfo_t ksi;
        int traced;
 
-       KASSERT((td->td_pflags & TDP_FORKING) == 0,
-           ("fork() did not clear TDP_FORKING upon completion"));
        KASSERT(td->td_errno != ERELOOKUP,
            ("ERELOOKUP not consumed syscall %d", td->td_sa.code));
 
diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h
index f17fdf601ba1..30392c1bf0fd 100644
--- a/sys/sys/filedesc.h
+++ b/sys/sys/filedesc.h
@@ -203,7 +203,6 @@ enum {
        FDDUP_NORMAL,           /* dup() behavior. */
        FDDUP_FCNTL,            /* fcntl()-style errors. */
        FDDUP_FIXED,            /* Force fixed allocation. */
-       FDDUP_MUSTREPLACE,      /* Target must exist. */
        FDDUP_LASTMODE,
 };
 
@@ -250,12 +249,8 @@ void       fdclose(struct thread *td, struct file *fp, int 
idx);
 void   fdcloseexec(struct thread *td);
 void   fdsetugidsafety(struct thread *td);
 struct filedesc *fdcopy(struct filedesc *fdp);
-int    fdcopy_remapped(struct filedesc *fdp, const int *fds, size_t nfds,
-           struct filedesc **newfdp);
-void   fdinstall_remapped(struct thread *td, struct filedesc *fdp);
 void   fdunshare(struct thread *td);
 void   fdescfree(struct thread *td);
-void   fdescfree_remapped(struct filedesc *fdp);
 int    fdlastfile(struct filedesc *fdp);
 int    fdlastfile_single(struct filedesc *fdp);
 struct filedesc *fdinit(struct filedesc *fdp, bool prepfiles, int *lastfile);
diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h
index cd130551c050..ef4de48c3e6d 100644
--- a/sys/sys/imgact.h
+++ b/sys/sys/imgact.h
@@ -55,7 +55,6 @@ struct image_args {
        int argc;               /* count of argument strings */
        int envc;               /* count of environment strings */
        int fd;                 /* file descriptor of the executable */
-       struct filedesc *fdp;   /* new file descriptor table */
 };
 
 struct image_params {
@@ -120,8 +119,6 @@ void        exec_setregs(struct thread *, struct 
image_params *, uintptr_t);
 int    exec_shell_imgact(struct image_params *);
 int    exec_copyin_args(struct image_args *, const char *, enum uio_seg,
        char **, char **);
-int    exec_copyin_data_fds(struct thread *, struct image_args *, const void *,
-       size_t, const int *, size_t);
 void   exec_stackgap(struct image_params *imgp, uintptr_t *dp);
 int    pre_execve(struct thread *td, struct vmspace **oldvmspace);
 void   post_execve(struct thread *td, int error, struct vmspace *oldvmspace);
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 691bdae8b41a..1e3d7359a55b 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -524,7 +524,7 @@ do {                                                        
                \
 #define        TDP_RESETSPUR   0x04000000 /* Reset spurious page fault 
history. */
 #define        TDP_NERRNO      0x08000000 /* Last errno is already in td_errno 
*/
 #define        TDP_UIOHELD     0x10000000 /* Current uio has pages held in 
td_ma */
-#define        TDP_FORKING     0x20000000 /* Thread is being created through 
fork() */
+#define        TDP_UNUSED0     0x20000000 /* UNUSED */
 #define        TDP_EXECVMSPC   0x40000000 /* Execve destroyed old vmspace */
 #define        TDP_SIGFASTPENDING 0x80000000 /* Pending signal due to 
sigfastblock */
 

Reply via email to