From owner-svn-src-all@FreeBSD.ORG Tue Mar 19 20:18:32 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 8A172A98; Tue, 19 Mar 2013 20:18:32 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 7B6562A1; Tue, 19 Mar 2013 20:18:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r2JKIWDP026745; Tue, 19 Mar 2013 20:18:32 GMT (envelope-from jkim@svn.freebsd.org) Received: (from jkim@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r2JKIU55026730; Tue, 19 Mar 2013 20:18:30 GMT (envelope-from jkim@svn.freebsd.org) Message-Id: <201303192018.r2JKIU55026730@svn.freebsd.org> From: Jung-uk Kim Date: Tue, 19 Mar 2013 20:18:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r248532 - in stable/9/sys: amd64/linux32 compat/linux i386/linux kern X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Mar 2013 20:18:32 -0000 Author: jkim Date: Tue Mar 19 20:18:30 2013 New Revision: 248532 URL: http://svnweb.freebsd.org/changeset/base/248532 Log: MFC: r234352 Implement pipe2 syscall for Linuxulator. Modified: stable/9/sys/amd64/linux32/linux32_dummy.c stable/9/sys/amd64/linux32/linux32_machdep.c stable/9/sys/amd64/linux32/syscalls.master stable/9/sys/compat/linux/linux_file.c stable/9/sys/i386/linux/linux_dummy.c stable/9/sys/i386/linux/linux_machdep.c stable/9/sys/i386/linux/syscalls.master stable/9/sys/kern/sys_pipe.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/amd64/linux32/linux32_dummy.c ============================================================================== --- stable/9/sys/amd64/linux32/linux32_dummy.c Tue Mar 19 20:00:34 2013 (r248531) +++ stable/9/sys/amd64/linux32/linux32_dummy.c Tue Mar 19 20:18:30 2013 (r248532) @@ -131,7 +131,6 @@ DUMMY(signalfd4); DUMMY(eventfd2); DUMMY(epoll_create1); DUMMY(dup3); -DUMMY(pipe2); DUMMY(inotify_init1); /* linux 2.6.30: */ DUMMY(preadv); Modified: stable/9/sys/amd64/linux32/linux32_machdep.c ============================================================================== --- stable/9/sys/amd64/linux32/linux32_machdep.c Tue Mar 19 20:00:34 2013 (r248531) +++ stable/9/sys/amd64/linux32/linux32_machdep.c Tue Mar 19 20:18:30 2013 (r248532) @@ -698,25 +698,6 @@ linux_iopl(struct thread *td, struct lin } 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: stable/9/sys/amd64/linux32/syscalls.master ============================================================================== --- stable/9/sys/amd64/linux32/syscalls.master Tue Mar 19 20:00:34 2013 (r248531) +++ stable/9/sys/amd64/linux32/syscalls.master Tue Mar 19 20:18:30 2013 (r248532) @@ -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: stable/9/sys/compat/linux/linux_file.c ============================================================================== --- stable/9/sys/compat/linux/linux_file.c Tue Mar 19 20:00:34 2013 (r248531) +++ stable/9/sys/compat/linux/linux_file.c Tue Mar 19 20:18:30 2013 (r248532) @@ -69,6 +69,9 @@ __FBSDID("$FreeBSD$"); #include #include +/* XXX */ +int do_pipe(struct thread *td, int fildes[2], int flags); + int linux_creat(struct thread *td, struct linux_creat_args *args) { @@ -1571,3 +1574,49 @@ linux_fadvise64_64(struct thread *td, st 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 = do_pipe(td, fildes, 0); + 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: stable/9/sys/i386/linux/linux_dummy.c ============================================================================== --- stable/9/sys/i386/linux/linux_dummy.c Tue Mar 19 20:00:34 2013 (r248531) +++ stable/9/sys/i386/linux/linux_dummy.c Tue Mar 19 20:18:30 2013 (r248532) @@ -122,7 +122,6 @@ DUMMY(signalfd4); DUMMY(eventfd2); DUMMY(epoll_create1); DUMMY(dup3); -DUMMY(pipe2); DUMMY(inotify_init1); /* linux 2.6.30: */ DUMMY(preadv); Modified: stable/9/sys/i386/linux/linux_machdep.c ============================================================================== --- stable/9/sys/i386/linux/linux_machdep.c Tue Mar 19 20:00:34 2013 (r248531) +++ stable/9/sys/i386/linux/linux_machdep.c Tue Mar 19 20:18:30 2013 (r248532) @@ -587,25 +587,6 @@ linux_mprotect(struct thread *td, struct } 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: stable/9/sys/i386/linux/syscalls.master ============================================================================== --- stable/9/sys/i386/linux/syscalls.master Tue Mar 19 20:00:34 2013 (r248531) +++ stable/9/sys/i386/linux/syscalls.master Tue Mar 19 20:18:30 2013 (r248532) @@ -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: stable/9/sys/kern/sys_pipe.c ============================================================================== --- stable/9/sys/kern/sys_pipe.c Tue Mar 19 20:00:34 2013 (r248531) +++ stable/9/sys/kern/sys_pipe.c Tue Mar 19 20:18:30 2013 (r248532) @@ -128,6 +128,9 @@ __FBSDID("$FreeBSD$"); #include #include +/* XXX */ +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 +327,18 @@ pipe_zone_fini(void *mem, int size) 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 +367,7 @@ kern_pipe(struct thread *td, int fildes[ 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,14 +376,18 @@ kern_pipe(struct thread *td, int fildes[ /* 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 * 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 +396,7 @@ kern_pipe(struct thread *td, int fildes[ 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);