[Midnightbsd-cvs] src [7447] trunk/sys: Introduce pipe2 to linux emulation layer.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Mon Feb 22 08:05:12 EST 2016


Revision: 7447
          http://svnweb.midnightbsd.org/src/?rev=7447
Author:   laffer1
Date:     2016-02-22 08:05:11 -0500 (Mon, 22 Feb 2016)
Log Message:
-----------
Introduce pipe2 to linux emulation layer.

Based on an earlier FreeBSD patch by Jung-uk Kim. (jkim at freebsd.org)

We don't have the dtrace changes in this code like freebsd 9.2 has.

Modified Paths:
--------------
    trunk/sys/amd64/linux32/linux32_dummy.c
    trunk/sys/amd64/linux32/linux32_machdep.c
    trunk/sys/amd64/linux32/linux32_proto.h
    trunk/sys/amd64/linux32/linux32_sysent.c
    trunk/sys/amd64/linux32/linux32_systrace_args.c
    trunk/sys/amd64/linux32/syscalls.master
    trunk/sys/compat/linux/linux_file.c
    trunk/sys/i386/linux/linux_dummy.c
    trunk/sys/i386/linux/linux_machdep.c
    trunk/sys/i386/linux/linux_proto.h
    trunk/sys/i386/linux/linux_sysent.c
    trunk/sys/i386/linux/linux_systrace_args.c
    trunk/sys/i386/linux/syscalls.master
    trunk/sys/kern/sys_pipe.c

Modified: trunk/sys/amd64/linux32/linux32_dummy.c
===================================================================
--- trunk/sys/amd64/linux32/linux32_dummy.c	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/amd64/linux32/linux32_dummy.c	2016-02-22 13:05:11 UTC (rev 7447)
@@ -122,7 +122,6 @@
 DUMMY(eventfd2);
 DUMMY(epoll_create1);
 DUMMY(dup3);
-DUMMY(pipe2);
 DUMMY(inotify_init1);
 /* linux 2.6.30: */
 DUMMY(preadv);

Modified: trunk/sys/amd64/linux32/linux32_machdep.c
===================================================================
--- trunk/sys/amd64/linux32/linux32_machdep.c	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/amd64/linux32/linux32_machdep.c	2016-02-22 13:05:11 UTC (rev 7447)
@@ -698,25 +698,6 @@
 }
 
 int
-linux_pipe(struct thread *td, struct linux_pipe_args *args)
-{
-	int error;
-	int fildes[2];
-
-#ifdef DEBUG
-	if (ldebug(pipe))
-		printf(ARGS(pipe, "*"));
-#endif
-
-	error = kern_pipe(td, fildes);
-	if (error)
-		return (error);
-
-	/* XXX: Close descriptors on error. */
-	return (copyout(fildes, args->pipefds, sizeof fildes));
-}
-
-int
 linux_sigaction(struct thread *td, struct linux_sigaction_args *args)
 {
 	l_osigaction_t osa;

Modified: trunk/sys/amd64/linux32/linux32_proto.h
===================================================================
--- trunk/sys/amd64/linux32/linux32_proto.h	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/amd64/linux32/linux32_proto.h	2016-02-22 13:05:11 UTC (rev 7447)
@@ -152,7 +152,7 @@
 	char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
 };
 struct linux_pipe_args {
-	char pipefds_l_[PADL_(l_ulong *)]; l_ulong * pipefds; char pipefds_r_[PADR_(l_ulong *)];
+	char pipefds_l_[PADL_(l_int *)]; l_int * pipefds; char pipefds_r_[PADR_(l_int *)];
 };
 struct linux_times_args {
 	char buf_l_[PADL_(struct l_times_argv *)]; struct l_times_argv * buf; char buf_r_[PADR_(struct l_times_argv *)];
@@ -1044,7 +1044,8 @@
 	register_t dummy;
 };
 struct linux_pipe2_args {
-	register_t dummy;
+	char pipefds_l_[PADL_(l_int *)]; l_int * pipefds; char pipefds_r_[PADR_(l_int *)];
+	char flags_l_[PADL_(l_int)]; l_int flags; char flags_r_[PADR_(l_int)];
 };
 struct linux_inotify_init1_args {
 	register_t dummy;

Modified: trunk/sys/amd64/linux32/linux32_sysent.c
===================================================================
--- trunk/sys/amd64/linux32/linux32_sysent.c	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/amd64/linux32/linux32_sysent.c	2016-02-22 13:05:11 UTC (rev 7447)
@@ -350,7 +350,7 @@
 	{ 0, (sy_call_t *)linux_eventfd2, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 328 = linux_eventfd2 */
 	{ 0, (sy_call_t *)linux_epoll_create1, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 329 = linux_epoll_create1 */
 	{ 0, (sy_call_t *)linux_dup3, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 330 = linux_dup3 */
-	{ 0, (sy_call_t *)linux_pipe2, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 331 = linux_pipe2 */
+	{ AS(linux_pipe2_args), (sy_call_t *)linux_pipe2, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 331 = linux_pipe2 */
 	{ 0, (sy_call_t *)linux_inotify_init1, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 332 = linux_inotify_init1 */
 	{ 0, (sy_call_t *)linux_preadv, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 333 = linux_preadv */
 	{ 0, (sy_call_t *)linux_pwritev, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 334 = linux_pwritev */

Modified: trunk/sys/amd64/linux32/linux32_systrace_args.c
===================================================================
--- trunk/sys/amd64/linux32/linux32_systrace_args.c	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/amd64/linux32/linux32_systrace_args.c	2016-02-22 13:05:11 UTC (rev 7447)
@@ -287,7 +287,7 @@
 	/* linux_pipe */
 	case 42: {
 		struct linux_pipe_args *p = params;
-		uarg[0] = (intptr_t) p->pipefds; /* l_ulong * */
+		uarg[0] = (intptr_t) p->pipefds; /* l_int * */
 		*n_args = 1;
 		break;
 	}
@@ -2171,7 +2171,10 @@
 	}
 	/* linux_pipe2 */
 	case 331: {
-		*n_args = 0;
+		struct linux_pipe2_args *p = params;
+		uarg[0] = (intptr_t) p->pipefds; /* l_int * */
+		iarg[1] = p->flags; /* l_int */
+		*n_args = 2;
 		break;
 	}
 	/* linux_inotify_init1 */
@@ -2688,7 +2691,7 @@
 	case 42:
 		switch(ndx) {
 		case 0:
-			p = "l_ulong *";
+			p = "l_int *";
 			break;
 		default:
 			break;
@@ -5364,6 +5367,8 @@
 		break;
 	/* linux_pipe2 */
 	case 331:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
 		break;
 	/* linux_inotify_init1 */
 	case 332:

Modified: trunk/sys/amd64/linux32/syscalls.master
===================================================================
--- trunk/sys/amd64/linux32/syscalls.master	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/amd64/linux32/syscalls.master	2016-02-22 13:05:11 UTC (rev 7447)
@@ -95,7 +95,7 @@
 39	AUE_MKDIR	STD	{ int linux_mkdir(char *path, l_int mode); }
 40	AUE_RMDIR	STD	{ int linux_rmdir(char *path); }
 41	AUE_DUP		NOPROTO	{ int dup(u_int fd); }
-42	AUE_PIPE	STD	{ int linux_pipe(l_ulong *pipefds); }
+42	AUE_PIPE	STD	{ int linux_pipe(l_int *pipefds); }
 43	AUE_NULL	STD	{ int linux_times(struct l_times_argv *buf); }
 44	AUE_NULL	UNIMPL	prof
 45	AUE_NULL	STD	{ int linux_brk(l_ulong dsend); }
@@ -536,7 +536,7 @@
 328	AUE_NULL	STD	{ int linux_eventfd2(void); }
 329	AUE_NULL	STD	{ int linux_epoll_create1(void); }
 330	AUE_NULL	STD	{ int linux_dup3(void); }
-331	AUE_NULL	STD	{ int linux_pipe2(void); }
+331	AUE_NULL	STD	{ int linux_pipe2(l_int *pipefds, l_int flags); }
 332	AUE_NULL	STD	{ int linux_inotify_init1(void); }
 ; linux 2.6.30:
 333	AUE_NULL	STD	{ int linux_preadv(void); }

Modified: trunk/sys/compat/linux/linux_file.c
===================================================================
--- trunk/sys/compat/linux/linux_file.c	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/compat/linux/linux_file.c	2016-02-22 13:05:11 UTC (rev 7447)
@@ -69,6 +69,8 @@
 #include <compat/linux/linux_util.h>
 #include <compat/linux/linux_file.h>
 
+extern int do_pipe(struct thread *td, int fildes[2], int flags);
+
 int
 linux_creat(struct thread *td, struct linux_creat_args *args)
 {
@@ -1575,3 +1577,49 @@
 	return (kern_posix_fadvise(td, args->fd, args->offset, args->len,
 	    advice));
 }
+
+int
+linux_pipe(struct thread *td, struct linux_pipe_args *args)
+{
+	int fildes[2];
+	int error;
+
+#ifdef DEBUG
+	if (ldebug(pipe))
+		printf(ARGS(pipe, "*"));
+#endif
+
+	error = kern_pipe(td, fildes);
+	if (error)
+		return (error);
+
+	/* XXX: Close descriptors on error. */
+	return (copyout(fildes, args->pipefds, sizeof(fildes)));
+}
+
+int
+linux_pipe2(struct thread *td, struct linux_pipe2_args *args)
+{
+	int fildes[2];
+	int error, flags;
+
+#ifdef DEBUG
+	if (ldebug(pipe2))
+		printf(ARGS(pipe2, "*, %d"), args->flags);
+#endif
+
+	if ((args->flags & ~(LINUX_O_NONBLOCK | LINUX_O_CLOEXEC)) != 0)
+		return (EINVAL);
+
+	flags = 0;
+	if ((args->flags & LINUX_O_NONBLOCK) != 0)
+		flags |= O_NONBLOCK;
+	if ((args->flags & LINUX_O_CLOEXEC) != 0)
+		flags |= O_CLOEXEC;
+	error = do_pipe(td, fildes, flags);
+	if (error)
+		return (error);
+
+	/* XXX: Close descriptors on error. */
+	return (copyout(fildes, args->pipefds, sizeof(fildes)));
+}

Modified: trunk/sys/i386/linux/linux_dummy.c
===================================================================
--- trunk/sys/i386/linux/linux_dummy.c	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/i386/linux/linux_dummy.c	2016-02-22 13:05:11 UTC (rev 7447)
@@ -113,7 +113,6 @@
 DUMMY(eventfd2);
 DUMMY(epoll_create1);
 DUMMY(dup3);
-DUMMY(pipe2);
 DUMMY(inotify_init1);
 /* linux 2.6.30: */
 DUMMY(preadv);

Modified: trunk/sys/i386/linux/linux_machdep.c
===================================================================
--- trunk/sys/i386/linux/linux_machdep.c	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/i386/linux/linux_machdep.c	2016-02-22 13:05:11 UTC (rev 7447)
@@ -587,25 +587,6 @@
 }
 
 int
-linux_pipe(struct thread *td, struct linux_pipe_args *args)
-{
-	int error;
-	int fildes[2];
-
-#ifdef DEBUG
-	if (ldebug(pipe))
-		printf(ARGS(pipe, "*"));
-#endif
-
-	error = kern_pipe(td, fildes);
-	if (error)
-		return (error);
-
-	/* XXX: Close descriptors on error. */
-	return (copyout(fildes, args->pipefds, sizeof fildes));
-}
-
-int
 linux_ioperm(struct thread *td, struct linux_ioperm_args *args)
 {
 	int error;

Modified: trunk/sys/i386/linux/linux_proto.h
===================================================================
--- trunk/sys/i386/linux/linux_proto.h	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/i386/linux/linux_proto.h	2016-02-22 13:05:11 UTC (rev 7447)
@@ -156,7 +156,7 @@
 	char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
 };
 struct linux_pipe_args {
-	char pipefds_l_[PADL_(l_ulong *)]; l_ulong * pipefds; char pipefds_r_[PADR_(l_ulong *)];
+	char pipefds_l_[PADL_(l_int *)]; l_int * pipefds; char pipefds_r_[PADR_(l_int *)];
 };
 struct linux_times_args {
 	char buf_l_[PADL_(struct l_times_argv *)]; struct l_times_argv * buf; char buf_r_[PADR_(struct l_times_argv *)];
@@ -1063,7 +1063,8 @@
 	register_t dummy;
 };
 struct linux_pipe2_args {
-	register_t dummy;
+	char pipefds_l_[PADL_(l_int *)]; l_int * pipefds; char pipefds_r_[PADR_(l_int *)];
+	char flags_l_[PADL_(l_int)]; l_int flags; char flags_r_[PADR_(l_int)];
 };
 struct linux_inotify_init1_args {
 	register_t dummy;

Modified: trunk/sys/i386/linux/linux_sysent.c
===================================================================
--- trunk/sys/i386/linux/linux_sysent.c	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/i386/linux/linux_sysent.c	2016-02-22 13:05:11 UTC (rev 7447)
@@ -349,7 +349,7 @@
 	{ 0, (sy_call_t *)linux_eventfd2, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 328 = linux_eventfd2 */
 	{ 0, (sy_call_t *)linux_epoll_create1, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 329 = linux_epoll_create1 */
 	{ 0, (sy_call_t *)linux_dup3, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 330 = linux_dup3 */
-	{ 0, (sy_call_t *)linux_pipe2, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 331 = linux_pipe2 */
+	{ AS(linux_pipe2_args), (sy_call_t *)linux_pipe2, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 331 = linux_pipe2 */
 	{ 0, (sy_call_t *)linux_inotify_init1, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 332 = linux_inotify_init1 */
 	{ 0, (sy_call_t *)linux_preadv, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 333 = linux_preadv */
 	{ 0, (sy_call_t *)linux_pwritev, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 334 = linux_pwritev */

Modified: trunk/sys/i386/linux/linux_systrace_args.c
===================================================================
--- trunk/sys/i386/linux/linux_systrace_args.c	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/i386/linux/linux_systrace_args.c	2016-02-22 13:05:11 UTC (rev 7447)
@@ -295,7 +295,7 @@
 	/* linux_pipe */
 	case 42: {
 		struct linux_pipe_args *p = params;
-		uarg[0] = (intptr_t) p->pipefds; /* l_ulong * */
+		uarg[0] = (intptr_t) p->pipefds; /* l_int * */
 		*n_args = 1;
 		break;
 	}
@@ -2262,7 +2262,10 @@
 	}
 	/* linux_pipe2 */
 	case 331: {
-		*n_args = 0;
+		struct linux_pipe2_args *p = params;
+		uarg[0] = (intptr_t) p->pipefds; /* l_int * */
+		iarg[1] = p->flags; /* l_int */
+		*n_args = 2;
 		break;
 	}
 	/* linux_inotify_init1 */
@@ -2792,7 +2795,7 @@
 	case 42:
 		switch(ndx) {
 		case 0:
-			p = "l_ulong *";
+			p = "l_int *";
 			break;
 		default:
 			break;
@@ -5660,6 +5663,8 @@
 		break;
 	/* linux_pipe2 */
 	case 331:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
 		break;
 	/* linux_inotify_init1 */
 	case 332:

Modified: trunk/sys/i386/linux/syscalls.master
===================================================================
--- trunk/sys/i386/linux/syscalls.master	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/i386/linux/syscalls.master	2016-02-22 13:05:11 UTC (rev 7447)
@@ -95,7 +95,7 @@
 39	AUE_MKDIR	STD	{ int linux_mkdir(char *path, l_int mode); }
 40	AUE_RMDIR	STD	{ int linux_rmdir(char *path); }
 41	AUE_DUP		NOPROTO	{ int dup(u_int fd); }
-42	AUE_PIPE	STD	{ int linux_pipe(l_ulong *pipefds); }
+42	AUE_PIPE	STD	{ int linux_pipe(l_int *pipefds); }
 43	AUE_NULL	STD	{ int linux_times(struct l_times_argv *buf); }
 44	AUE_NULL	UNIMPL	prof
 45	AUE_NULL	STD	{ int linux_brk(l_ulong dsend); }
@@ -546,7 +546,7 @@
 328	AUE_NULL	STD	{ int linux_eventfd2(void); }
 329	AUE_NULL	STD	{ int linux_epoll_create1(void); }
 330	AUE_NULL	STD	{ int linux_dup3(void); }
-331	AUE_NULL	STD	{ int linux_pipe2(void); }
+331	AUE_NULL	STD	{ int linux_pipe2(l_int *pipefds, l_int flags); }
 332	AUE_NULL	STD	{ int linux_inotify_init1(void); }
 ; linux 2.6.30:
 333	AUE_NULL	STD	{ int linux_preadv(void); }

Modified: trunk/sys/kern/sys_pipe.c
===================================================================
--- trunk/sys/kern/sys_pipe.c	2016-02-20 15:10:44 UTC (rev 7446)
+++ trunk/sys/kern/sys_pipe.c	2016-02-22 13:05:11 UTC (rev 7447)
@@ -128,6 +128,8 @@
 #include <vm/vm_page.h>
 #include <vm/uma.h>
 
+int	do_pipe(struct thread *td, int fildes[2], int flags);
+
 /*
  * Use this define if you want to disable *fancy* VM things.  Expect an
  * approx 30% decrease in transfer rate.  This could be useful for
@@ -324,11 +326,17 @@
 int
 kern_pipe(struct thread *td, int fildes[2])
 {
+	return (do_pipe(td, fildes, 0));
+}
+
+int
+do_pipe(struct thread *td, int fildes[2], int flags)
+{
 	struct filedesc *fdp = td->td_proc->p_fd;
 	struct file *rf, *wf;
 	struct pipepair *pp;
 	struct pipe *rpipe, *wpipe;
-	int fd, error;
+	int fd, fflags, error;
 
 	pp = uma_zalloc(pipe_zone, M_WAITOK);
 #ifdef MAC
@@ -357,7 +365,7 @@
 	rpipe->pipe_state |= PIPE_DIRECTOK;
 	wpipe->pipe_state |= PIPE_DIRECTOK;
 
-	error = falloc(td, &rf, &fd, 0);
+	error = falloc(td, &rf, &fd, flags);
 	if (error) {
 		pipeclose(rpipe);
 		pipeclose(wpipe);
@@ -366,6 +374,10 @@
 	/* An extra reference on `rf' has been held for us by falloc(). */
 	fildes[0] = fd;
 
+	fflags = FREAD | FWRITE;
+	if ((flags & O_NONBLOCK) != 0)
+		fflags |= FNONBLOCK;
+
 	/*
 	 * Warning: once we've gotten past allocation of the fd for the
 	 * read-side, we can only drop the read side via fdrop() in order
@@ -372,8 +384,8 @@
 	 * to avoid races against processes which manage to dup() the read
 	 * side while we are blocked trying to allocate the write side.
 	 */
-	finit(rf, FREAD | FWRITE, DTYPE_PIPE, rpipe, &pipeops);
-	error = falloc(td, &wf, &fd, 0);
+	finit(rf, fflags, DTYPE_PIPE, rpipe, &pipeops);
+	error = falloc(td, &wf, &fd, flags);
 	if (error) {
 		fdclose(fdp, rf, fildes[0], td);
 		fdrop(rf, td);
@@ -382,7 +394,7 @@
 		return (error);
 	}
 	/* An extra reference on `wf' has been held for us by falloc(). */
-	finit(wf, FREAD | FWRITE, DTYPE_PIPE, wpipe, &pipeops);
+	finit(wf, fflags, DTYPE_PIPE, wpipe, &pipeops);
 	fdrop(wf, td);
 	fildes[1] = fd;
 	fdrop(rf, td);



More information about the Midnightbsd-cvs mailing list