diff --git a/sys/compat/linux/arch/alpha/linux_pipe.c b/sys/compat/linux/arch/alpha/linux_pipe.c index eaa32af8e6e8..9a90658deb0f 100644 --- a/sys/compat/linux/arch/alpha/linux_pipe.c +++ b/sys/compat/linux/arch/alpha/linux_pipe.c @@ -62,12 +62,13 @@ __KERNEL_RCSID(0, "$NetBSD: linux_pipe.c,v 1.17 2014/11/09 17:48:07 maxv Exp $") int linux_sys_pipe(struct lwp *l, const void *v, register_t *retval) { - int error; + int fd[2], error; - if ((error = pipe1(l, retval, 0))) + if ((error = pipe1(l, fd, 0))) return error; - (l->l_md.md_tf)->tf_regs[FRAME_A4] = retval[1]; + retval[0] = fd[0]; + (l->l_md.md_tf)->tf_regs[FRAME_A4] = fd[1]; return 0; } @@ -79,16 +80,17 @@ linux_sys_pipe2(struct lwp *l, const struct linux_sys_pipe2_args *uap, syscallarg(int *) pfds; syscallarg(int) flags; } */ - int error, flags; + int fd[2], error, flags; flags = linux_to_bsd_ioflags(SCARG(uap, flags)); if ((flags & ~(O_CLOEXEC|O_NONBLOCK)) != 0) return EINVAL; - if ((error = pipe1(l, retval, flags))) + if ((error = pipe1(l, fd, flags))) return error; - (l->l_md.md_tf)->tf_regs[FRAME_A4] = retval[1]; + retval[0] = fd[0]; + (l->l_md.md_tf)->tf_regs[FRAME_A4] = fd[1]; return 0; } diff --git a/sys/compat/linux/common/linux_pipe.c b/sys/compat/linux/common/linux_pipe.c index 2f5a9ee9ea58..d570dffd0cb8 100644 --- a/sys/compat/linux/common/linux_pipe.c +++ b/sys/compat/linux/common/linux_pipe.c @@ -57,31 +57,6 @@ __KERNEL_RCSID(0, "$NetBSD: linux_pipe.c,v 1.67 2014/11/09 17:48:08 maxv Exp $") /* Not used on: alpha, mips, sparc, sparc64 */ /* Alpha, mips, sparc and sparc64 pass one of the fds in a register */ -/* - * NetBSD passes fd[0] in retval[0], and fd[1] in retval[1]. - * Linux directly passes the pointer. - */ -static int -linux_pipe_return(struct lwp *l, int *pfds, register_t *retval) -{ - int error; - - if (sizeof(*retval) != sizeof(*pfds)) { - /* On amd64, sizeof(register_t) != sizeof(int) */ - int rpfds[2]; - rpfds[0] = (int)retval[0]; - rpfds[1] = (int)retval[1]; - - if ((error = copyout(rpfds, pfds, sizeof(rpfds)))) - return error; - } else { - if ((error = copyout(retval, pfds, 2 * sizeof(*pfds)))) - return error; - } - retval[0] = 0; - return 0; -} - int linux_sys_pipe(struct lwp *l, const struct linux_sys_pipe_args *uap, register_t *retval) @@ -89,12 +64,15 @@ linux_sys_pipe(struct lwp *l, const struct linux_sys_pipe_args *uap, /* { syscallarg(int *) pfds; } */ - int error; + int fd[2], error; - if ((error = pipe1(l, retval, 0))) + if ((error = pipe1(l, fd, 0))) return error; - return linux_pipe_return(l, SCARG(uap, pfds), retval); + if ((error = copyout(fd, SCARG(uap, pfds), sizeof(fd))) != 0) + return error; + retval[0] = 0; + return 0; } int @@ -105,14 +83,17 @@ linux_sys_pipe2(struct lwp *l, const struct linux_sys_pipe2_args *uap, syscallarg(int *) pfds; syscallarg(int) flags; } */ - int error, flags; + int fd[2], error, flags; flags = linux_to_bsd_ioflags(SCARG(uap, flags)); if ((flags & ~(O_CLOEXEC|O_NONBLOCK)) != 0) return EINVAL; - if ((error = pipe1(l, retval, flags))) + if ((error = pipe1(l, fd, flags))) return error; - return linux_pipe_return(l, SCARG(uap, pfds), retval); + if ((error = copyout(fd, SCARG(uap, pfds), sizeof(fd))) != 0) + return error; + retval[0] = 0; + return 0; } diff --git a/sys/compat/linux32/common/linux32_unistd.c b/sys/compat/linux32/common/linux32_unistd.c index a9f81fa22ff0..b3c19e70b35b 100644 --- a/sys/compat/linux32/common/linux32_unistd.c +++ b/sys/compat/linux32/common/linux32_unistd.c @@ -225,51 +225,44 @@ linux32_select1(struct lwp *l, register_t *retval, int nfds, return 0; } -static int -linux32_pipe(struct lwp *l, int *fd, register_t *retval) +int +linux32_sys_pipe(struct lwp *l, const struct linux32_sys_pipe_args *uap, + register_t *retval) { /* { syscallarg(netbsd32_intp) fd; } */ - int error; - int pfds[2]; - - pfds[0] = (int)retval[0]; - pfds[1] = (int)retval[1]; + int f[2], error; - if ((error = copyout(pfds, fd, 2 * sizeof(*fd))) != 0) + if ((error = pipe1(l, f, 0))) return error; + if ((error = copyout(f, SCARG_P32(uap, fd), sizeof(f))) != 0) + return error; retval[0] = 0; - retval[1] = 0; - return 0; } -int -linux32_sys_pipe(struct lwp *l, const struct linux32_sys_pipe_args *uap, - register_t *retval) -{ - int error; - if ((error = pipe1(l, retval, 0))) - return error; - return linux32_pipe(l, SCARG_P32(uap, fd), retval); -} - int linux32_sys_pipe2(struct lwp *l, const struct linux32_sys_pipe2_args *uap, register_t *retval) { - int flags, error; + /* { + syscallarg(netbsd32_intp) fd; + } */ + int f[2], flags, error; flags = linux_to_bsd_ioflags(SCARG(uap, flags)); if ((flags & ~(O_CLOEXEC|O_NONBLOCK)) != 0) return EINVAL; - if ((error = pipe1(l, retval, flags))) + if ((error = pipe1(l, f, flags))) return error; - return linux32_pipe(l, SCARG_P32(uap, fd), retval); + if ((error = copyout(f, SCARG_P32(uap, fd), sizeof(f))) != 0) + return error; + retval[0] = 0; + return 0; } int @@ -741,4 +734,3 @@ linux32_sys_pwrite(struct lwp *l, return sys_pwrite(l, &pra, retval); } - diff --git a/sys/compat/netbsd32/netbsd32_netbsd.c b/sys/compat/netbsd32/netbsd32_netbsd.c index d41053ebdcc4..736d072193ba 100644 --- a/sys/compat/netbsd32/netbsd32_netbsd.c +++ b/sys/compat/netbsd32/netbsd32_netbsd.c @@ -2687,13 +2687,10 @@ netbsd32_pipe2(struct lwp *l, const struct netbsd32_pipe2_args *uap, } */ int fd[2], error; - error = pipe1(l, retval, SCARG(uap, flags)); + error = pipe1(l, fd, SCARG(uap, flags)); if (error != 0) return error; - fd[0] = retval[0]; - fd[1] = retval[1]; - error = copyout(fd, SCARG_P32(uap, fildes), sizeof(fd)); if (error != 0) return error; diff --git a/sys/kern/sys_descrip.c b/sys/kern/sys_descrip.c index 3f4f822fa12d..8a47f9af8264 100644 --- a/sys/kern/sys_descrip.c +++ b/sys/kern/sys_descrip.c @@ -764,7 +764,15 @@ sys___posix_fadvise50(struct lwp *l, int sys_pipe(struct lwp *l, const void *v, register_t *retval) { - return pipe1(l, retval, 0); + int fd[2], error; + + if ((error = pipe1(l, fd, 0)) != 0) + return error; + + retval[0] = fd[0]; + retval[1] = fd[1]; + + return 0; } int @@ -776,10 +784,9 @@ sys_pipe2(struct lwp *l, const struct sys_pipe2_args *uap, register_t *retval) } */ int fd[2], error; - if ((error = pipe1(l, retval, SCARG(uap, flags))) != 0) + if ((error = pipe1(l, fd, SCARG(uap, flags))) != 0) return error; - fd[0] = retval[0]; - fd[1] = retval[1]; + if ((error = copyout(fd, SCARG(uap, fildes), sizeof(fd))) != 0) return error; retval[0] = 0; diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 67b574aca9eb..83629129141d 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -245,7 +245,7 @@ pipe_dtor(void *arg, void *obj) * The pipe system call for the DTYPE_PIPE type of pipes */ int -pipe1(struct lwp *l, register_t *retval, int flags) +pipe1(struct lwp *l, int *fildes, int flags) { struct pipe *rpipe, *wpipe; file_t *rf, *wf; @@ -267,33 +267,33 @@ pipe1(struct lwp *l, register_t *retval, int flags) error = fd_allocfile(&rf, &fd); if (error) goto free2; - retval[0] = fd; + fildes[0] = fd; error = fd_allocfile(&wf, &fd); if (error) goto free3; - retval[1] = fd; + fildes[1] = fd; rf->f_flag = FREAD | flags; rf->f_type = DTYPE_PIPE; rf->f_pipe = rpipe; rf->f_ops = &pipeops; - fd_set_exclose(l, (int)retval[0], (flags & O_CLOEXEC) != 0); + fd_set_exclose(l, fildes[0], (flags & O_CLOEXEC) != 0); wf->f_flag = FWRITE | flags; wf->f_type = DTYPE_PIPE; wf->f_pipe = wpipe; wf->f_ops = &pipeops; - fd_set_exclose(l, (int)retval[1], (flags & O_CLOEXEC) != 0); + fd_set_exclose(l, fildes[1], (flags & O_CLOEXEC) != 0); rpipe->pipe_peer = wpipe; wpipe->pipe_peer = rpipe; - fd_affix(p, rf, (int)retval[0]); - fd_affix(p, wf, (int)retval[1]); + fd_affix(p, rf, fildes[0]); + fd_affix(p, wf, fildes[1]); return (0); free3: - fd_abort(p, rf, (int)retval[0]); + fd_abort(p, rf, fildes[0]); free2: pipeclose(wpipe); pipeclose(rpipe); diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 128189219e98..a87278773ab9 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1265,7 +1265,7 @@ sys_getsockopt(struct lwp *l, const struct sys_getsockopt_args *uap, #ifdef PIPE_SOCKETPAIR int -pipe1(struct lwp *l, register_t *retval, int flags) +pipe1(struct lwp *l, int *fildes, int flags) { file_t *rf, *wf; struct socket *rso, *wso; @@ -1284,7 +1284,7 @@ pipe1(struct lwp *l, register_t *retval, int flags) rso->so_state |= SS_ISAPIPE; if ((error = fd_allocfile(&rf, &fd)) != 0) goto free2; - retval[0] = fd; + fildes[0] = fd; rf->f_flag = FREAD | flags; rf->f_type = DTYPE_SOCKET; rf->f_ops = &socketops; @@ -1295,19 +1295,19 @@ pipe1(struct lwp *l, register_t *retval, int flags) wf->f_type = DTYPE_SOCKET; wf->f_ops = &socketops; wf->f_socket = wso; - retval[1] = fd; + fildes[1] = fd; solock(wso); error = unp_connect2(wso, rso); sounlock(wso); if (error != 0) goto free4; - fd_affix(p, wf, (int)retval[1]); - fd_affix(p, rf, (int)retval[0]); + fd_affix(p, wf, fildes[1]); + fd_affix(p, rf, fildes[0]); return (0); free4: - fd_abort(p, wf, (int)retval[1]); + fd_abort(p, wf, fildes[1]); free3: - fd_abort(p, rf, (int)retval[0]); + fd_abort(p, rf, fildes[0]); free2: (void)soclose(wso); free1: diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 2c96313ee01c..3312dd4f1137 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -209,7 +209,7 @@ int fd_dup(file_t *, int, int *, bool); int fd_dup2(file_t *, unsigned, int); int fd_clone(file_t *, unsigned, int, const struct fileops *, void *); void fd_set_exclose(struct lwp *, int, bool); -int pipe1(struct lwp *, register_t *, int); +int pipe1(struct lwp *, int *, int); int dodup(struct lwp *, int, int, int, register_t *); void cwd_sys_init(void);