unified (weak) sys_pipe implementation
[pandora-kernel.git] / arch / avr32 / kernel / sys_avr32.c
1 /*
2  * Copyright (C) 2004-2006 Atmel Corporation
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8 #include <linux/errno.h>
9 #include <linux/fs.h>
10 #include <linux/file.h>
11 #include <linux/mm.h>
12 #include <linux/unistd.h>
13
14 #include <asm/mman.h>
15 #include <asm/uaccess.h>
16
17 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
18                           unsigned long prot, unsigned long flags,
19                           unsigned long fd, off_t offset)
20 {
21         int error = -EBADF;
22         struct file *file = NULL;
23
24         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
25         if (!(flags & MAP_ANONYMOUS)) {
26                 file = fget(fd);
27                 if (!file)
28                         return error;
29         }
30
31         down_write(&current->mm->mmap_sem);
32         error = do_mmap_pgoff(file, addr, len, prot, flags, offset);
33         up_write(&current->mm->mmap_sem);
34
35         if (file)
36                 fput(file);
37         return error;
38 }
39
40 int kernel_execve(const char *file, char **argv, char **envp)
41 {
42         register long scno asm("r8") = __NR_execve;
43         register long sc1 asm("r12") = (long)file;
44         register long sc2 asm("r11") = (long)argv;
45         register long sc3 asm("r10") = (long)envp;
46
47         asm volatile("scall"
48                      : "=r"(sc1)
49                      : "r"(scno), "0"(sc1), "r"(sc2), "r"(sc3)
50                      : "cc", "memory");
51         return sc1;
52 }