Skip to content

Commit

Permalink
unified (weak) sys_pipe implementation
Browse files Browse the repository at this point in the history
This replaces the duplicated arch-specific versions of "sys_pipe()" with
one unified implementation.  This removes almost 250 lines of duplicated
code.

It's marked __weak, so that *if* an architecture wants to override the
default implementation it can do so by simply having its own replacement
version, since many architectures use alternate calling conventions for
the 'pipe()' system call for legacy reasons (ie traditional UNIX
implementations often return the two file descriptors in registers)

I still haven't changed the cris version even though Linus says the BKL
isn't needed.  The arch maintainer can easily do it if there are really
no obstacles.

Signed-off-by: Ulrich Drepper <drepper@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Ulrich Drepper authored and Linus Torvalds committed May 3, 2008
1 parent 2ddcca3 commit d35c7b0
Show file tree
Hide file tree
Showing 18 changed files with 18 additions and 265 deletions.
17 changes: 0 additions & 17 deletions arch/arm/kernel/sys_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,6 @@ extern unsigned long do_mremap(unsigned long addr, unsigned long old_len,
unsigned long new_len, unsigned long flags,
unsigned long new_addr);

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way unix traditionally does this, though.
*/
asmlinkage int sys_pipe(unsigned long __user *fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

/* common code for old and new mmaps */
inline long do_mmap2(
unsigned long addr, unsigned long len,
Expand Down
13 changes: 0 additions & 13 deletions arch/avr32/kernel/sys_avr32.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@
#include <asm/mman.h>
#include <asm/uaccess.h>

asmlinkage int sys_pipe(unsigned long __user *filedes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(filedes, fd, sizeof(fd)))
error = -EFAULT;
}
return error;
}

asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, off_t offset)
Expand Down
17 changes: 0 additions & 17 deletions arch/blackfin/kernel/sys_bfin.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,6 @@
#include <asm/cacheflush.h>
#include <asm/dma.h>

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way unix traditionally does this, though.
*/
asmlinkage int sys_pipe(unsigned long __user *fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2 * sizeof(int)))
error = -EFAULT;
}
return error;
}

/* common code for old and new mmaps */
static inline long
do_mmap2(unsigned long addr, unsigned long len,
Expand Down
17 changes: 0 additions & 17 deletions arch/frv/kernel/sys_frv.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@
#include <asm/setup.h>
#include <asm/uaccess.h>

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way unix traditionally does this, though.
*/
asmlinkage long sys_pipe(unsigned long __user * fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff)
Expand Down
17 changes: 0 additions & 17 deletions arch/h8300/kernel/sys_h8300.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,6 @@
#include <asm/traps.h>
#include <asm/unistd.h>

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way unix traditionally does this, though.
*/
asmlinkage int sys_pipe(unsigned long * fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

/* common code for old and new mmaps */
static inline long do_mmap2(
unsigned long addr, unsigned long len,
Expand Down
17 changes: 0 additions & 17 deletions arch/m68k/kernel/sys_m68k.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,6 @@
#include <asm/page.h>
#include <asm/unistd.h>

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way unix traditionally does this, though.
*/
asmlinkage int sys_pipe(unsigned long __user * fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

/* common code for old and new mmaps */
static inline long do_mmap2(
unsigned long addr, unsigned long len,
Expand Down
17 changes: 0 additions & 17 deletions arch/m68knommu/kernel/sys_m68k.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@
#include <asm/cacheflush.h>
#include <asm/unistd.h>

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way unix traditionally does this, though.
*/
asmlinkage int sys_pipe(unsigned long * fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

/* common code for old and new mmaps */
static inline long do_mmap2(
unsigned long addr, unsigned long len,
Expand Down
17 changes: 0 additions & 17 deletions arch/mn10300/kernel/sys_mn10300.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@

#define MIN_MAP_ADDR PAGE_SIZE /* minimum fixed mmap address */

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way Unix traditionally does this, though.
*/
asmlinkage long sys_pipe(unsigned long __user *fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2 * sizeof(int)))
error = -EFAULT;
}
return error;
}

/*
* memory mapping syscall
*/
Expand Down
13 changes: 0 additions & 13 deletions arch/parisc/kernel/sys_parisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@
#include <linux/utsname.h>
#include <linux/personality.h>

int sys_pipe(int __user *fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
{
struct vm_area_struct *vma;
Expand Down
17 changes: 0 additions & 17 deletions arch/powerpc/kernel/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,6 @@ int sys_ipc(uint call, int first, unsigned long second, long third,
return ret;
}

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way unix traditionally does this, though.
*/
int sys_pipe(int __user *fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

static inline unsigned long do_mmap2(unsigned long addr, size_t len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long off, int shift)
Expand Down
17 changes: 0 additions & 17 deletions arch/s390/kernel/sys_s390.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,6 @@
#include <asm/uaccess.h>
#include "entry.h"

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way Unix traditionally does this, though.
*/
asmlinkage long sys_pipe(unsigned long __user *fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

/* common code for old and new mmaps */
static inline long do_mmap2(
unsigned long addr, unsigned long len,
Expand Down
17 changes: 0 additions & 17 deletions arch/sh/kernel/sys_sh64.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,6 @@
#include <asm/ptrace.h>
#include <asm/unistd.h>

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way Unix traditionally does this, though.
*/
asmlinkage int sys_pipe(unsigned long * fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

/*
* Do a system call from kernel instead of calling sys_execve so we
* end up with proper pt_regs.
Expand Down
17 changes: 0 additions & 17 deletions arch/um/kernel/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,6 @@ long old_mmap(unsigned long addr, unsigned long len,
out:
return err;
}
/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way unix traditionally does this, though.
*/
long sys_pipe(unsigned long __user * fildes)
{
int fd[2];
long error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, sizeof(fd)))
error = -EFAULT;
}
return error;
}


long sys_uname(struct old_utsname __user * name)
{
Expand Down
17 changes: 0 additions & 17 deletions arch/v850/kernel/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,6 @@ sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
return ret;
}

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way unix traditionally does this, though.
*/
int sys_pipe (int *fildes)
{
int fd[2];
int error;

error = do_pipe (fd);
if (!error) {
if (copy_to_user (fildes, fd, 2*sizeof (int)))
error = -EFAULT;
}
return error;
}

static inline unsigned long
do_mmap2 (unsigned long addr, size_t len,
unsigned long prot, unsigned long flags,
Expand Down
17 changes: 0 additions & 17 deletions arch/x86/kernel/sys_i386_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,6 @@
#include <asm/uaccess.h>
#include <asm/unistd.h>

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way Unix traditionally does this, though.
*/
asmlinkage int sys_pipe(unsigned long __user * fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff)
Expand Down
17 changes: 0 additions & 17 deletions arch/x86/kernel/sys_x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,6 @@
#include <asm/uaccess.h>
#include <asm/ia32.h>

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way Unix traditionally does this, though.
*/
asmlinkage long sys_pipe(int __user *fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
error = -EFAULT;
}
return error;
}

asmlinkage long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long off)
{
Expand Down
17 changes: 17 additions & 0 deletions fs/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,23 @@ int do_pipe(int *fd)
return error;
}

/*
* sys_pipe() is the normal C calling standard for creating
* a pipe. It's not the way Unix traditionally does this, though.
*/
asmlinkage long __weak sys_pipe(int __user *fildes)
{
int fd[2];
int error;

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, sizeof(fd)))
error = -EFAULT;
}
return error;
}

/*
* pipefs should _never_ be mounted by userland - too much of security hassle,
* no real gain from having the whole whorehouse mounted. So we don't need
Expand Down
Loading

0 comments on commit d35c7b0

Please sign in to comment.