Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/compat/linux/common - implement dup3 and pipe2
details: https://anonhg.NetBSD.org/src/rev/da1b515fb0a0
branches: trunk
changeset: 764025:da1b515fb0a0
user: christos <christos%NetBSD.org@localhost>
date: Sun Apr 10 15:50:34 2011 +0000
description:
- implement dup3 and pipe2
- eliminate amd64 ifdef
diffstat:
sys/compat/linux/common/linux_pipe.c | 94 +++++++++++++++++++++++++++++------
1 files changed, 77 insertions(+), 17 deletions(-)
diffs (141 lines):
diff -r 8a3f8b91c3d4 -r da1b515fb0a0 sys/compat/linux/common/linux_pipe.c
--- a/sys/compat/linux/common/linux_pipe.c Sun Apr 10 15:49:56 2011 +0000
+++ b/sys/compat/linux/common/linux_pipe.c Sun Apr 10 15:50:34 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_pipe.c,v 1.63 2008/06/18 12:24:18 tsutsui Exp $ */
+/* $NetBSD: linux_pipe.c,v 1.64 2011/04/10 15:50:34 christos 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.63 2008/06/18 12:24:18 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_pipe.c,v 1.64 2011/04/10 15:50:34 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -39,6 +39,8 @@
#include <sys/mbuf.h>
#include <sys/mman.h>
#include <sys/mount.h>
+#include <sys/fcntl.h>
+#include <sys/filedesc.h>
#include <sys/sched.h>
#include <sys/syscallargs.h>
@@ -48,6 +50,7 @@
#include <compat/linux/common/linux_signal.h>
#include <compat/linux/common/linux_ipc.h>
#include <compat/linux/common/linux_sem.h>
+#include <compat/linux/common/linux_fcntl.h>
#include <compat/linux/linux_syscallargs.h>
@@ -59,33 +62,90 @@
* 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 flags)
+{
+ 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;
+ }
+ if (flags & LINUX_O_CLOEXEC) {
+ fd_set_exclose(l, retval[0], true);
+ fd_set_exclose(l, retval[1], true);
+ }
+ retval[0] = 0;
+ return 0;
+}
+
int
-linux_sys_pipe(struct lwp *l, const struct linux_sys_pipe_args *uap, register_t *retval)
+linux_sys_pipe(struct lwp *l, const struct linux_sys_pipe_args *uap,
+ register_t *retval)
{
/* {
syscallarg(int *) pfds;
} */
int error;
-#ifdef __amd64__
- int pfds[2];
-#endif
- if ((error = sys_pipe(l, 0, retval)))
+ if ((error = pipe1(l, retval, 0)))
return error;
-#ifndef __amd64__
- /* Assumes register_t is an int */
- if ((error = copyout(retval, SCARG(uap, pfds), 2 * sizeof (int))))
+ return linux_pipe_return(l, SCARG(uap, pfds), retval, 0);
+}
+
+int
+linux_sys_pipe2(struct lwp *l, const struct linux_sys_pipe2_args *uap,
+ register_t *retval)
+{
+ /* {
+ syscallarg(int *) pfds;
+ syscallarg(int) flags;
+ } */
+ int error;
+ int flag = 0;
+
+ switch (SCARG(uap, flags)) {
+ case LINUX_O_CLOEXEC:
+ break;
+ case LINUX_O_NONBLOCK:
+ case LINUX_O_NONBLOCK|LINUX_O_CLOEXEC:
+ flag = O_NONBLOCK;
+ break;
+ default:
+ return EINVAL;
+ }
+
+ if ((error = pipe1(l, retval, flag)))
return error;
-#else
- /* On amd64, sizeof(register_t) != sizeof(int) */
- pfds[0] = (int)retval[0];
- pfds[1] = (int)retval[1];
+
+ return linux_pipe_return(l, SCARG(uap, pfds), retval,
+ SCARG(uap, flags));
+}
- if ((error = copyout(pfds, SCARG(uap, pfds), sizeof(pfds))))
+int
+linux_sys_dup3(struct lwp *l, const struct linux_sys_dup3_args *uap,
+ register_t *retval)
+{
+ /* {
+ syscallarg(int) from;
+ syscallarg(int) to;
+ syscallarg(int) flags;
+ } */
+ int error;
+ if ((error = sys_dup2(l, (const struct sys_dup2_args *)uap, retval)))
return error;
-#endif
- retval[0] = 0;
+ if (SCARG(uap, flags) & LINUX_O_CLOEXEC)
+ fd_set_exclose(l, SCARG(uap, to), true);
+
return 0;
}
Home |
Main Index |
Thread Index |
Old Index