Description: Partially rollback illumos' pipe2 patch Instead of breaking existing pipe syscall, add a new one - pipe2 Index: uts/usr/src/uts/common/sys/syscall.h =================================================================== --- uts.orig/usr/src/uts/common/sys/syscall.h 2014-03-01 16:18:38.000000000 +0400 +++ uts/usr/src/uts/common/sys/syscall.h 2014-03-08 00:52:38.180807354 +0400 @@ -94,6 +94,7 @@ * setpgid(pid,pgid) :: syscall(39,5,pid,pgid) */ #define SYS_uucopystr 40 +#define SYS_pipe2 41 #define SYS_pipe 42 #define SYS_times 43 #define SYS_profil 44 Index: uts/usr/src/uts/common/syscall/pipe.c =================================================================== --- uts.orig/usr/src/uts/common/syscall/pipe.c 2014-03-01 16:18:38.000000000 +0400 +++ uts/usr/src/uts/common/syscall/pipe.c 2014-03-09 13:21:48.767394625 +0400 @@ -42,7 +42,6 @@ #include #include #include -#include /* * This is the loadable module wrapper. @@ -50,11 +49,11 @@ #include #include -int pipe(intptr_t fds, int); +longlong_t pipe(); static struct sysent pipe_sysent = { - 2, - SE_ARGC | SE_32RVAL1 | SE_NOUNLOAD, + 0, + SE_32RVAL1 | SE_32RVAL2 | SE_NOUNLOAD | SE_ARGC, (int (*)())pipe }; @@ -62,12 +61,12 @@ * Module linkage information for the kernel. */ static struct modlsys modlsys = { - &mod_syscallops, "pipe(2) syscall", &pipe_sysent + &mod_syscallops, "pipe syscall", &pipe_sysent }; #ifdef _SYSCALL32_IMPL static struct modlsys modlsys32 = { - &mod_syscallops32, "32-bit pipe(2) syscall", &pipe_sysent + &mod_syscallops32, "32-bit pipe syscall", &pipe_sysent }; #endif @@ -99,27 +98,17 @@ } /* - * pipe(2) system call. - * Create a pipe by connecting two streams together. Associate - * each end of the pipe with a vnode, a file descriptor and - * one of the streams. + * pipe system call. */ -int -pipe(intptr_t arg, int flags) +longlong_t pipe() { vnode_t *vp1, *vp2; struct file *fp1, *fp2; int error = 0; - int flag1, flag2, iflags; int fd1, fd2; + rval_t r; /* - * Validate allowed flags. - */ - if ((flags & ~(FCLOEXEC|FNONBLOCK)) != 0) { - return (set_errno(EINVAL)); - } - /* * Allocate and initialize two vnodes. */ makepipe(&vp1, &vp2); @@ -132,7 +121,7 @@ if (error = falloc(vp1, FWRITE|FREAD, &fp1, &fd1)) { VN_RELE(vp1); VN_RELE(vp2); - return (set_errno(error)); + return ((longlong_t)set_errno(error)); } if (error = falloc(vp2, FWRITE|FREAD, &fp2, &fd2)) @@ -155,36 +144,6 @@ VTOF(vp1)->fn_ino = VTOF(vp2)->fn_ino = fifogetid(); /* - * Set the O_NONBLOCK flag if requested. - */ - if (flags & FNONBLOCK) { - flag1 = fp1->f_flag; - flag2 = fp2->f_flag; - iflags = flags & FNONBLOCK; - - if (error = VOP_SETFL(vp1, flag1, iflags, fp1->f_cred, NULL)) { - goto out_vop_close; - } - fp1->f_flag |= iflags; - - if (error = VOP_SETFL(vp2, flag2, iflags, fp2->f_cred, NULL)) { - goto out_vop_close; - } - fp2->f_flag |= iflags; - } - - /* - * Return the file descriptors to the user. They now - * point to two different vnodes which have different - * stream heads. - */ - if (copyout(&fd1, &((int *)arg)[0], sizeof (int)) || - copyout(&fd2, &((int *)arg)[1], sizeof (int))) { - error = EFAULT; - goto out_vop_close; - } - - /* * Now fill in the entries that falloc reserved */ mutex_exit(&fp1->f_tlock); @@ -193,24 +152,20 @@ setf(fd2, fp2); /* - * Optionally set the FCLOEXEC flag + * Return the file descriptors to the user. They now + * point to two different vnodes which have different + * stream heads. */ - if ((flags & FCLOEXEC) != 0) { - f_setfd(fd1, FD_CLOEXEC); - f_setfd(fd2, FD_CLOEXEC); - } - - return (0); -out_vop_close: - (void) VOP_CLOSE(vp1, FWRITE|FREAD, 1, (offset_t)0, fp1->f_cred, NULL); - (void) VOP_CLOSE(vp2, FWRITE|FREAD, 1, (offset_t)0, fp2->f_cred, NULL); + r.r_val1 = fd1; + r.r_val2 = fd2; + return (r.r_vals); out: - setf(fd2, NULL); unfalloc(fp2); + setf(fd2, NULL); out2: - setf(fd1, NULL); unfalloc(fp1); + setf(fd1, NULL); VN_RELE(vp1); VN_RELE(vp2); - return (set_errno(error)); + return ((longlong_t)set_errno(error)); } Index: uts/usr/src/uts/common/os/sysent.c =================================================================== --- uts.orig/usr/src/uts/common/os/sysent.c 2014-03-01 16:18:35.000000000 +0400 +++ uts/usr/src/uts/common/os/sysent.c 2014-03-08 23:02:09.835148736 +0400 @@ -480,7 +480,7 @@ SYSENT_CI("fstatfs", fstatfs32, 4)), /* 39 */ SYSENT_CI("setpgrp", setpgrp, 3), /* 40 */ SYSENT_CI("uucopystr", uucopystr, 3), - /* 41 */ SYSENT_LOADABLE(), /* (was dup) */ + /* 41 */ SYSENT_LOADABLE(), /* pipe2 */ /* 42 */ SYSENT_LOADABLE(), /* pipe */ /* 43 */ SYSENT_CL("times", times, 1), /* 44 */ SYSENT_CI("prof", profil, 4), @@ -855,7 +855,7 @@ /* 38 */ SYSENT_CI("fstatfs", fstatfs32, 4), /* 39 */ SYSENT_CI("setpgrp", setpgrp, 3), /* 40 */ SYSENT_CI("uucopystr", uucopystr, 3), - /* 41 */ SYSENT_LOADABLE32(), /* (was dup) */ + /* 41 */ SYSENT_LOADABLE32(), /* pipe2 */ /* 42 */ SYSENT_LOADABLE32(), /* pipe */ /* 43 */ SYSENT_CI("times", times32, 1), /* 44 */ SYSENT_CI("prof", profil, 4), Index: uts/usr/src/uts/intel/os/name_to_sysnum =================================================================== --- uts.orig/usr/src/uts/intel/os/name_to_sysnum 2014-03-01 16:18:40.000000000 +0400 +++ uts/usr/src/uts/intel/os/name_to_sysnum 2014-03-08 00:52:38.188767591 +0400 @@ -36,6 +36,7 @@ fstatfs 38 setpgrp 39 uucopystr 40 +pipe2 41 pipe 42 times 43 profil 44 Index: uts/usr/src/uts/sparc/os/name_to_sysnum =================================================================== --- uts.orig/usr/src/uts/sparc/os/name_to_sysnum 2014-03-01 16:18:40.000000000 +0400 +++ uts/usr/src/uts/sparc/os/name_to_sysnum 2014-03-08 00:52:38.192958963 +0400 @@ -36,6 +36,7 @@ fstatfs 38 setpgrp 39 uucopystr 40 +pipe2 41 pipe 42 times 43 profil 44 Index: uts/usr/src/uts/common/syscall/pipe2.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ uts/usr/src/uts/common/syscall/pipe2.c 2014-03-09 13:53:56.026466909 +0400 @@ -0,0 +1,216 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * Copyright (c) 2011 Bayard G. Bell. All rights reserved. + */ + +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * This is the loadable module wrapper. + */ +#include +#include + +int pipe2(intptr_t fds, int); + +static struct sysent pipe2_sysent = { + 2, + SE_ARGC | SE_32RVAL1 | SE_NOUNLOAD, + (int (*)())pipe2 +}; + +/* + * Module linkage information for the kernel. + */ +static struct modlsys modlsys_2 = { + &mod_syscallops, "pipe2 syscall", &pipe2_sysent +}; + +#ifdef _SYSCALL32_IMPL +static struct modlsys modlsys32_2 = { + &mod_syscallops32, "32-bit pipe2 syscall", &pipe2_sysent +}; +#endif + +static struct modlinkage modlinkage = { + MODREV_1, + &modlsys_2, +#ifdef _SYSCALL32_IMPL + &modlsys32_2, +#endif + NULL +}; + +int +_init(void) +{ + return (mod_install(&modlinkage)); +} + +int +_fini(void) +{ + return (EBUSY); +} + +int +_info(struct modinfo *modinfop) +{ + return (mod_info(&modlinkage, modinfop)); +} + +/* + * pipe2 system call. + * Create a pipe by connecting two streams together. Associate + * each end of the pipe with a vnode, a file descriptor and + * one of the streams. + */ +int +pipe2(intptr_t arg, int flags) +{ + vnode_t *vp1, *vp2; + struct file *fp1, *fp2; + int error = 0; + int flag1, flag2, iflags; + int fd1, fd2; + + /* + * Validate allowed flags. + */ + if ((flags & ~(FCLOEXEC|FNONBLOCK)) != 0) { + return (set_errno(EINVAL)); + } + /* + * Allocate and initialize two vnodes. + */ + makepipe(&vp1, &vp2); + + /* + * Allocate and initialize two file table entries and two + * file pointers. Each file pointer is open for read and + * write. + */ + if (error = falloc(vp1, FWRITE|FREAD, &fp1, &fd1)) { + VN_RELE(vp1); + VN_RELE(vp2); + return (set_errno(error)); + } + + if (error = falloc(vp2, FWRITE|FREAD, &fp2, &fd2)) + goto out2; + + /* + * Create two stream heads and attach to each vnode. + */ + if (error = fifo_stropen(&vp1, FWRITE|FREAD, fp1->f_cred, 0, 0)) + goto out; + + if (error = fifo_stropen(&vp2, FWRITE|FREAD, fp2->f_cred, 0, 0)) { + (void) VOP_CLOSE(vp1, FWRITE|FREAD, 1, (offset_t)0, + fp1->f_cred, NULL); + goto out; + } + + strmate(vp1, vp2); + + VTOF(vp1)->fn_ino = VTOF(vp2)->fn_ino = fifogetid(); + + /* + * Set the O_NONBLOCK flag if requested. + */ + if (flags & FNONBLOCK) { + flag1 = fp1->f_flag; + flag2 = fp2->f_flag; + iflags = flags & FNONBLOCK; + + if (error = VOP_SETFL(vp1, flag1, iflags, fp1->f_cred, NULL)) { + goto out_vop_close; + } + fp1->f_flag |= iflags; + + if (error = VOP_SETFL(vp2, flag2, iflags, fp2->f_cred, NULL)) { + goto out_vop_close; + } + fp2->f_flag |= iflags; + } + + /* + * Return the file descriptors to the user. They now + * point to two different vnodes which have different + * stream heads. + */ + if (copyout(&fd1, &((int *)arg)[0], sizeof (int)) || + copyout(&fd2, &((int *)arg)[1], sizeof (int))) { + error = EFAULT; + goto out_vop_close; + } + + /* + * Now fill in the entries that falloc reserved + */ + mutex_exit(&fp1->f_tlock); + mutex_exit(&fp2->f_tlock); + setf(fd1, fp1); + setf(fd2, fp2); + + /* + * Optionally set the FCLOEXEC flag + */ + if ((flags & FCLOEXEC) != 0) { + f_setfd(fd1, FD_CLOEXEC); + f_setfd(fd2, FD_CLOEXEC); + } + + return (0); +out_vop_close: + (void) VOP_CLOSE(vp1, FWRITE|FREAD, 1, (offset_t)0, fp1->f_cred, NULL); + (void) VOP_CLOSE(vp2, FWRITE|FREAD, 1, (offset_t)0, fp2->f_cred, NULL); +out: + setf(fd2, NULL); + unfalloc(fp2); +out2: + setf(fd1, NULL); + unfalloc(fp1); + VN_RELE(vp1); + VN_RELE(vp2); + return (set_errno(error)); +} Index: uts/usr/src/uts/intel/Makefile.intel =================================================================== --- uts.orig/usr/src/uts/intel/Makefile.intel 2014-03-08 00:52:31.876090953 +0400 +++ uts/usr/src/uts/intel/Makefile.intel 2014-03-09 13:23:51.917303566 +0400 @@ -548,6 +548,7 @@ SYS_KMODS += inst_sync SYS_KMODS += kaio SYS_KMODS += msgsys +SYS_KMODS += pipe2 SYS_KMODS += pipe SYS_KMODS += portfs SYS_KMODS += pset Index: uts/usr/src/uts/sparc/Makefile.sparc =================================================================== --- uts.orig/usr/src/uts/sparc/Makefile.sparc 2014-03-01 16:18:40.000000000 +0400 +++ uts/usr/src/uts/sparc/Makefile.sparc 2014-03-09 13:24:25.514172389 +0400 @@ -371,6 +371,7 @@ SYS_KMODS += c2audit SYS_KMODS += exacctsys SYS_KMODS += inst_sync kaio msgsys semsys shmsys sysacct pipe +SYS_KMODS += pipe2 SYS_KMODS += doorfs pset acctctl portfs # Index: uts/usr/src/uts/intel/pipe2/Makefile =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ uts/usr/src/uts/intel/pipe2/Makefile 2014-03-09 13:52:28.292820250 +0400 @@ -0,0 +1,90 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License, Version 1.0 only +# (the "License"). You may not use this file except in compliance +# with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# +# +# uts/intel/pipe2/Makefile +# +# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# Copyright (c) 2011 Bayard G. Bell. All rights reserved. +# +# This makefile drives the production of the pipe2 syscall module. +# +# intel architecture dependent +# + +# +# Path to the base of the uts directory tree (usually /usr/src/uts). +# +UTSBASE = ../.. + +# +# Define the module and object file sets. +# +MODULE = pipe2 +OBJECTS = $(PIPE2_OBJS:%=$(OBJS_DIR)/%) +LINTS = $(PIPE2_OBJS:%.o=$(LINTS_DIR)/%.ln) +ROOTMODULE = $(ROOT_SYS_DIR)/$(MODULE) + +# +# Include common rules. +# +include $(UTSBASE)/intel/Makefile.intel + +CERRWARN += -_gcc=-Wno-parentheses + +# +# Define targets +# +ALL_TARGET = $(BINARY) +LINT_TARGET = $(MODULE).lint +INSTALL_TARGET = $(BINARY) $(ROOTMODULE) + +# +# Define dependency on fifofs +# +LDFLAGS += -dy -N fs/fifofs + +# +# Default build targets. +# +.KEEP_STATE: + +def: $(DEF_DEPS) + +all: $(ALL_DEPS) + +clean: $(CLEAN_DEPS) + +clobber: $(CLOBBER_DEPS) + +lint: $(LINT_DEPS) + +modlintlib: $(MODLINTLIB_DEPS) + +clean.lint: $(CLEAN_LINT_DEPS) + +install: $(INSTALL_DEPS) + +# +# Include common targets. +# +include $(UTSBASE)/intel/Makefile.targ Index: uts/usr/src/uts/common/Makefile.files =================================================================== --- uts.orig/usr/src/uts/common/Makefile.files 2014-03-01 16:18:28.000000000 +0400 +++ uts/usr/src/uts/common/Makefile.files 2014-03-09 13:52:04.166361329 +0400 @@ -1142,6 +1142,7 @@ FIFO_OBJS += fifosubr.o fifovnops.o PIPE_OBJS += pipe.o +PIPE2_OBJS += pipe2.o HSFS_OBJS += hsfs_node.o hsfs_subr.o hsfs_vfsops.o hsfs_vnops.o \ hsfs_susp.o hsfs_rrip.o hsfs_susp_subr.o