1*d46f49d3Skamil /* $NetBSD: linux_pipe.c,v 1.18 2017/12/26 08:30:57 kamil Exp $ */
2b5133645Serh
3b5133645Serh /*-
4b5133645Serh * Copyright (c) 1998 The NetBSD Foundation, Inc.
5b5133645Serh * All rights reserved.
6b5133645Serh *
7b5133645Serh * This code is derived from software contributed to The NetBSD Foundation
8b5133645Serh * by Eric Haszlakiewicz.
9b5133645Serh *
10b5133645Serh * Redistribution and use in source and binary forms, with or without
11b5133645Serh * modification, are permitted provided that the following conditions
12b5133645Serh * are met:
13b5133645Serh * 1. Redistributions of source code must retain the above copyright
14b5133645Serh * notice, this list of conditions and the following disclaimer.
15b5133645Serh * 2. Redistributions in binary form must reproduce the above copyright
16b5133645Serh * notice, this list of conditions and the following disclaimer in the
17b5133645Serh * documentation and/or other materials provided with the distribution.
18b5133645Serh *
19b5133645Serh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20b5133645Serh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21b5133645Serh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22b5133645Serh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23b5133645Serh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24b5133645Serh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25b5133645Serh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26b5133645Serh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27b5133645Serh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28b5133645Serh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29b5133645Serh * POSSIBILITY OF SUCH DAMAGE.
30b5133645Serh */
31b5133645Serh
32dab6ef8bSlukem #include <sys/cdefs.h>
33*d46f49d3Skamil __KERNEL_RCSID(0, "$NetBSD: linux_pipe.c,v 1.18 2017/12/26 08:30:57 kamil Exp $");
34dab6ef8bSlukem
35b5133645Serh #include <sys/param.h>
36b5133645Serh #include <sys/systm.h>
37b5133645Serh #include <sys/kernel.h>
38b5133645Serh #include <sys/mbuf.h>
39b5133645Serh #include <sys/mman.h>
40b5133645Serh #include <sys/mount.h>
415b09e159Serh #include <sys/proc.h>
42caa78eadSchristos #include <sys/filedesc.h>
43caa78eadSchristos #include <sys/fcntl.h>
44b5133645Serh
45b5133645Serh #include <sys/syscallargs.h>
46b5133645Serh
47908291d2Schristos #include <compat/linux/common/linux_types.h>
48908291d2Schristos #include <compat/linux/common/linux_mmap.h>
49908291d2Schristos #include <compat/linux/common/linux_signal.h>
50caa78eadSchristos #include <compat/linux/common/linux_fcntl.h>
51908291d2Schristos
52b5133645Serh #include <compat/linux/linux_syscallargs.h>
53b5133645Serh
54b5133645Serh /*
55b5133645Serh * The Alpha version of sys_pipe.
56b5133645Serh *
57b5133645Serh * Linux returns fd[1] in a4
58b5133645Serh * and fd[0] in the retval[0].
59b5133645Serh */
60b5133645Serh
61b5133645Serh
62b5133645Serh int
linux_sys_pipe(struct lwp * l,const void * v,register_t * retval)637e2790cfSdsl linux_sys_pipe(struct lwp *l, const void *v, register_t *retval)
64b5133645Serh {
65*d46f49d3Skamil int fd[2], error;
66b5133645Serh
67*d46f49d3Skamil if ((error = pipe1(l, fd, 0)))
68b5133645Serh return error;
69b5133645Serh
70*d46f49d3Skamil retval[0] = fd[0];
71*d46f49d3Skamil (l->l_md.md_tf)->tf_regs[FRAME_A4] = fd[1];
72b5133645Serh return 0;
73b5133645Serh }
74caa78eadSchristos
75caa78eadSchristos int
linux_sys_pipe2(struct lwp * l,const struct linux_sys_pipe2_args * uap,register_t * retval)76d6f2b33aShe linux_sys_pipe2(struct lwp *l, const struct linux_sys_pipe2_args *uap,
77caa78eadSchristos register_t *retval)
78caa78eadSchristos {
79caa78eadSchristos /* {
80caa78eadSchristos syscallarg(int *) pfds;
81caa78eadSchristos syscallarg(int) flags;
82caa78eadSchristos } */
83*d46f49d3Skamil int fd[2], error, flags;
84caa78eadSchristos
8588a8e046Snjoly flags = linux_to_bsd_ioflags(SCARG(uap, flags));
8688a8e046Snjoly if ((flags & ~(O_CLOEXEC|O_NONBLOCK)) != 0)
87caa78eadSchristos return EINVAL;
88caa78eadSchristos
89*d46f49d3Skamil if ((error = pipe1(l, fd, flags)))
90caa78eadSchristos return error;
91caa78eadSchristos
92*d46f49d3Skamil retval[0] = fd[0];
93*d46f49d3Skamil (l->l_md.md_tf)->tf_regs[FRAME_A4] = fd[1];
94caa78eadSchristos
95caa78eadSchristos return 0;
96caa78eadSchristos }
97