linux_pipe.c revision 1.59
11.59Snjoly/*	$NetBSD: linux_pipe.c,v 1.59 2007/10/19 18:52:11 njoly Exp $	*/
21.47Serh
31.47Serh/*-
41.49Sfvdl * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
51.47Serh * All rights reserved.
61.47Serh *
71.47Serh * This code is derived from software contributed to The NetBSD Foundation
81.49Sfvdl * by Frank van der Linden and Eric Haszlakiewicz.
91.47Serh *
101.47Serh * Redistribution and use in source and binary forms, with or without
111.47Serh * modification, are permitted provided that the following conditions
121.47Serh * are met:
131.47Serh * 1. Redistributions of source code must retain the above copyright
141.47Serh *    notice, this list of conditions and the following disclaimer.
151.47Serh * 2. Redistributions in binary form must reproduce the above copyright
161.47Serh *    notice, this list of conditions and the following disclaimer in the
171.47Serh *    documentation and/or other materials provided with the distribution.
181.47Serh * 3. All advertising materials mentioning features or use of this software
191.47Serh *    must display the following acknowledgement:
201.47Serh *	This product includes software developed by the NetBSD
211.47Serh *	Foundation, Inc. and its contributors.
221.47Serh * 4. Neither the name of The NetBSD Foundation nor the names of its
231.47Serh *    contributors may be used to endorse or promote products derived
241.47Serh *    from this software without specific prior written permission.
251.47Serh *
261.47Serh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.47Serh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.47Serh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.47Serh * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.47Serh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.47Serh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.47Serh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.47Serh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.47Serh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.47Serh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.47Serh * POSSIBILITY OF SUCH DAMAGE.
371.1Sfvdl */
381.52Slukem
391.52Slukem#include <sys/cdefs.h>
401.59Snjoly__KERNEL_RCSID(0, "$NetBSD: linux_pipe.c,v 1.59 2007/10/19 18:52:11 njoly Exp $");
411.1Sfvdl
421.1Sfvdl#include <sys/param.h>
431.1Sfvdl#include <sys/systm.h>
441.1Sfvdl#include <sys/kernel.h>
451.1Sfvdl#include <sys/malloc.h>
461.1Sfvdl#include <sys/mbuf.h>
471.1Sfvdl#include <sys/mman.h>
481.1Sfvdl#include <sys/mount.h>
491.1Sfvdl
501.1Sfvdl#include <sys/syscallargs.h>
511.1Sfvdl
521.48Schristos#include <compat/linux/common/linux_types.h>
531.48Schristos#include <compat/linux/common/linux_mmap.h>
541.48Schristos#include <compat/linux/common/linux_signal.h>
551.59Snjoly#include <compat/linux/common/linux_ipc.h>
561.59Snjoly#include <compat/linux/common/linux_sem.h>
571.48Schristos
581.1Sfvdl#include <compat/linux/linux_syscallargs.h>
591.1Sfvdl
601.54Smanu/* Used on: arm, i386, m68k, ppc, amd64 */
611.47Serh/* Not used on: alpha, mips, sparc, sparc64 */
621.47Serh/* Alpha, mips, sparc and sparc64 pass one of the fds in a register */
631.1Sfvdl
641.1Sfvdl/*
651.1Sfvdl * NetBSD passes fd[0] in retval[0], and fd[1] in retval[1].
661.1Sfvdl * Linux directly passes the pointer.
671.1Sfvdl */
681.1Sfvdlint
691.53Sthorpejlinux_sys_pipe(l, v, retval)
701.53Sthorpej	struct lwp *l;
711.20Sthorpej	void *v;
721.20Sthorpej	register_t *retval;
731.20Sthorpej{
741.21Smycroft	struct linux_sys_pipe_args /* {
751.1Sfvdl		syscallarg(int *) pfds;
761.20Sthorpej	} */ *uap = v;
771.1Sfvdl	int error;
781.54Smanu#ifdef __amd64__
791.54Smanu	int pfds[2];
801.54Smanu#endif
811.1Sfvdl
821.53Sthorpej	if ((error = sys_pipe(l, 0, retval)))
831.1Sfvdl		return error;
841.1Sfvdl
851.54Smanu#ifndef __amd64__
861.1Sfvdl	/* Assumes register_t is an int */
871.1Sfvdl	if ((error = copyout(retval, SCARG(uap, pfds), 2 * sizeof (int))))
881.1Sfvdl		return error;
891.54Smanu#else
901.54Smanu	/* On amd64, sizeof(register_t) != sizeof(int) */
911.54Smanu	pfds[0] = (int)retval[0];
921.54Smanu	pfds[1] = (int)retval[1];
931.54Smanu
941.54Smanu	if ((error = copyout(pfds, SCARG(uap, pfds), sizeof(pfds))))
951.54Smanu		return error;
961.54Smanu#endif
971.1Sfvdl
981.1Sfvdl	retval[0] = 0;
991.1Sfvdl	return 0;
1001.1Sfvdl}
101