Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Refactor pipe1() and correct a bug in sys_pipe2() (SYS_p...
details: https://anonhg.NetBSD.org/src/rev/9f6468956af2
branches: trunk
changeset: 358372:9f6468956af2
user: kamil <kamil%NetBSD.org@localhost>
date: Tue Dec 26 08:30:57 2017 +0000
description:
Refactor pipe1() and correct a bug in sys_pipe2() (SYS_pipe2)
sys_pipe2() returns two integers (values), the 2nd one is a copy of the 2nd
file descriptor that lands in fildes[2]. This is a side effect of reusing
the code for sys_pipe() (SYS_pipe) and not cleaning it up.
The first returned value is (on success) 0.
Introduced a small refactoring in pipe1() that it does not operate over
retval[], but on an array int[2]. A user sets retval[] for pipe() when
desired and needed.
This refactoring touches compat code: netbsd32, linux, linux32.
Before the changes on NetBSD/amd64:
$ ktruss -i ./a.out
[...]
15131 1 a.out pipe2(0x7f7fff2e62b8, 0) = 0, 4
[...]
After the changes:
$ ktruss -i ./a.out
[...]
782 1 a.out pipe2(0x7f7fff97e850, 0) = 0
[...]
There should not be a visible change for current users.
Sponsored by <The NetBSD Foundation>
diffstat:
sys/compat/linux/arch/alpha/linux_pipe.c | 18 ++++++-----
sys/compat/linux/common/linux_pipe.c | 47 ++++++++---------------------
sys/compat/linux32/common/linux32_unistd.c | 44 +++++++++++----------------
sys/compat/netbsd32/netbsd32_netbsd.c | 9 +---
sys/kern/sys_descrip.c | 19 ++++++++---
sys/kern/sys_pipe.c | 20 ++++++------
sys/kern/uipc_syscalls.c | 18 +++++-----
sys/sys/filedesc.h | 4 +-
8 files changed, 79 insertions(+), 100 deletions(-)
diffs (truncated from 465 to 300 lines):
diff -r d323606343ac -r 9f6468956af2 sys/compat/linux/arch/alpha/linux_pipe.c
--- a/sys/compat/linux/arch/alpha/linux_pipe.c Tue Dec 26 05:45:50 2017 +0000
+++ b/sys/compat/linux/arch/alpha/linux_pipe.c Tue Dec 26 08:30:57 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_pipe.c,v 1.17 2014/11/09 17:48:07 maxv Exp $ */
+/* $NetBSD: linux_pipe.c,v 1.18 2017/12/26 08:30:57 kamil Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_pipe.c,v 1.17 2014/11/09 17:48:07 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pipe.c,v 1.18 2017/12/26 08:30:57 kamil Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -62,12 +62,13 @@
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 @@
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 -r d323606343ac -r 9f6468956af2 sys/compat/linux/common/linux_pipe.c
--- a/sys/compat/linux/common/linux_pipe.c Tue Dec 26 05:45:50 2017 +0000
+++ b/sys/compat/linux/common/linux_pipe.c Tue Dec 26 08:30:57 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_pipe.c,v 1.67 2014/11/09 17:48:08 maxv Exp $ */
+/* $NetBSD: linux_pipe.c,v 1.68 2017/12/26 08:30:57 kamil Exp $ */
/*-
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_pipe.c,v 1.67 2014/11/09 17:48:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pipe.c,v 1.68 2017/12/26 08:30:57 kamil Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -57,31 +57,6 @@
/* 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 @@
/* {
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 @@
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 -r d323606343ac -r 9f6468956af2 sys/compat/linux32/common/linux32_unistd.c
--- a/sys/compat/linux32/common/linux32_unistd.c Tue Dec 26 05:45:50 2017 +0000
+++ b/sys/compat/linux32/common/linux32_unistd.c Tue Dec 26 08:30:57 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux32_unistd.c,v 1.39 2014/06/01 13:42:12 njoly Exp $ */
+/* $NetBSD: linux32_unistd.c,v 1.40 2017/12/26 08:30:58 kamil Exp $ */
/*-
* Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.39 2014/06/01 13:42:12 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.40 2017/12/26 08:30:58 kamil Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -225,51 +225,44 @@
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];
+ int f[2], error;
- pfds[0] = (int)retval[0];
- pfds[1] = (int)retval[1];
-
- 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 @@
return sys_pwrite(l, &pra, retval);
}
-
diff -r d323606343ac -r 9f6468956af2 sys/compat/netbsd32/netbsd32_netbsd.c
--- a/sys/compat/netbsd32/netbsd32_netbsd.c Tue Dec 26 05:45:50 2017 +0000
+++ b/sys/compat/netbsd32/netbsd32_netbsd.c Tue Dec 26 08:30:57 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_netbsd.c,v 1.211 2017/12/19 19:40:03 kamil Exp $ */
+/* $NetBSD: netbsd32_netbsd.c,v 1.212 2017/12/26 08:30:58 kamil Exp $ */
/*
* Copyright (c) 1998, 2001, 2008 Matthew R. Green
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.211 2017/12/19 19:40:03 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.212 2017/12/26 08:30:58 kamil Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ddb.h"
@@ -2687,13 +2687,10 @@
} */
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 -r d323606343ac -r 9f6468956af2 sys/kern/sys_descrip.c
--- a/sys/kern/sys_descrip.c Tue Dec 26 05:45:50 2017 +0000
+++ b/sys/kern/sys_descrip.c Tue Dec 26 08:30:57 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_descrip.c,v 1.30 2014/09/05 09:20:59 matt Exp $ */
+/* $NetBSD: sys_descrip.c,v 1.31 2017/12/26 08:30:58 kamil Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.30 2014/09/05 09:20:59 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.31 2017/12/26 08:30:58 kamil Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -764,7 +764,15 @@
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];
Home |
Main Index |
Thread Index |
Old Index