Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/v850/kernel/syscalls.c -- Various system-call definitions not |
| 3 | * defined in machine-independent code |
| 4 | * |
| 5 | * Copyright (C) 2001,02 NEC Corporation |
| 6 | * Copyright (C) 2001,02 Miles Bader <miles@gnu.org> |
| 7 | * |
| 8 | * This file is subject to the terms and conditions of the GNU General |
| 9 | * Public License. See the file COPYING in the main directory of this |
| 10 | * archive for more details. |
| 11 | * |
| 12 | * This file was derived the ppc version, arch/ppc/kernel/syscalls.c |
| 13 | * ... which was derived from "arch/i386/kernel/sys_i386.c" by Gary Thomas; |
| 14 | * modified by Cort Dougan (cort@cs.nmt.edu) |
| 15 | * and Paul Mackerras (paulus@cs.anu.edu.au). |
| 16 | */ |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/errno.h> |
| 19 | #include <linux/mm.h> |
| 20 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/syscalls.h> |
| 22 | #include <linux/sem.h> |
| 23 | #include <linux/msg.h> |
| 24 | #include <linux/shm.h> |
| 25 | #include <linux/stat.h> |
| 26 | #include <linux/mman.h> |
| 27 | #include <linux/sys.h> |
| 28 | #include <linux/ipc.h> |
| 29 | #include <linux/utsname.h> |
| 30 | #include <linux/file.h> |
| 31 | |
| 32 | #include <asm/uaccess.h> |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 33 | #include <asm/unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. |
| 37 | * |
| 38 | * This is really horribly ugly. |
| 39 | */ |
| 40 | int |
| 41 | sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth) |
| 42 | { |
| 43 | int version, ret; |
| 44 | |
| 45 | version = call >> 16; /* hack for backward compatibility */ |
| 46 | call &= 0xffff; |
| 47 | |
| 48 | ret = -EINVAL; |
| 49 | switch (call) { |
| 50 | case SEMOP: |
| 51 | ret = sys_semop (first, (struct sembuf *)ptr, second); |
| 52 | break; |
| 53 | case SEMGET: |
| 54 | ret = sys_semget (first, second, third); |
| 55 | break; |
| 56 | case SEMCTL: |
| 57 | { |
| 58 | union semun fourth; |
| 59 | |
| 60 | if (!ptr) |
| 61 | break; |
| 62 | if ((ret = access_ok(VERIFY_READ, ptr, sizeof(long)) ? 0 : -EFAULT) |
| 63 | || (ret = get_user(fourth.__pad, (void **)ptr))) |
| 64 | break; |
| 65 | ret = sys_semctl (first, second, third, fourth); |
| 66 | break; |
| 67 | } |
| 68 | case MSGSND: |
| 69 | ret = sys_msgsnd (first, (struct msgbuf *) ptr, second, third); |
| 70 | break; |
| 71 | case MSGRCV: |
| 72 | switch (version) { |
| 73 | case 0: { |
| 74 | struct ipc_kludge tmp; |
| 75 | |
| 76 | if (!ptr) |
| 77 | break; |
| 78 | if ((ret = access_ok(VERIFY_READ, ptr, sizeof(tmp)) ? 0 : -EFAULT) |
| 79 | || (ret = copy_from_user(&tmp, |
| 80 | (struct ipc_kludge *) ptr, |
| 81 | sizeof (tmp)))) |
| 82 | break; |
| 83 | ret = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, |
| 84 | third); |
| 85 | break; |
| 86 | } |
| 87 | default: |
| 88 | ret = sys_msgrcv (first, (struct msgbuf *) ptr, |
| 89 | second, fifth, third); |
| 90 | break; |
| 91 | } |
| 92 | break; |
| 93 | case MSGGET: |
| 94 | ret = sys_msgget ((key_t) first, second); |
| 95 | break; |
| 96 | case MSGCTL: |
| 97 | ret = sys_msgctl (first, second, (struct msqid_ds *) ptr); |
| 98 | break; |
| 99 | case SHMAT: |
| 100 | switch (version) { |
| 101 | default: { |
| 102 | ulong raddr; |
| 103 | |
| 104 | if ((ret = access_ok(VERIFY_WRITE, (ulong*) third, |
| 105 | sizeof(ulong)) ? 0 : -EFAULT)) |
| 106 | break; |
| 107 | ret = do_shmat (first, (char *) ptr, second, &raddr); |
| 108 | if (ret) |
| 109 | break; |
| 110 | ret = put_user (raddr, (ulong *) third); |
| 111 | break; |
| 112 | } |
| 113 | case 1: /* iBCS2 emulator entry point */ |
| 114 | if (!segment_eq(get_fs(), get_ds())) |
| 115 | break; |
| 116 | ret = do_shmat (first, (char *) ptr, second, |
| 117 | (ulong *) third); |
| 118 | break; |
| 119 | } |
| 120 | break; |
| 121 | case SHMDT: |
| 122 | ret = sys_shmdt ((char *)ptr); |
| 123 | break; |
| 124 | case SHMGET: |
| 125 | ret = sys_shmget (first, second, third); |
| 126 | break; |
| 127 | case SHMCTL: |
| 128 | ret = sys_shmctl (first, second, (struct shmid_ds *) ptr); |
| 129 | break; |
| 130 | } |
| 131 | |
| 132 | return ret; |
| 133 | } |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | static inline unsigned long |
| 136 | do_mmap2 (unsigned long addr, size_t len, |
| 137 | unsigned long prot, unsigned long flags, |
| 138 | unsigned long fd, unsigned long pgoff) |
| 139 | { |
| 140 | struct file * file = NULL; |
| 141 | int ret = -EBADF; |
| 142 | |
| 143 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
| 144 | if (! (flags & MAP_ANONYMOUS)) { |
| 145 | if (!(file = fget (fd))) |
| 146 | goto out; |
| 147 | } |
| 148 | |
| 149 | down_write (¤t->mm->mmap_sem); |
| 150 | ret = do_mmap_pgoff (file, addr, len, prot, flags, pgoff); |
| 151 | up_write (¤t->mm->mmap_sem); |
| 152 | if (file) |
| 153 | fput (file); |
| 154 | out: |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | unsigned long sys_mmap2 (unsigned long addr, size_t len, |
| 159 | unsigned long prot, unsigned long flags, |
| 160 | unsigned long fd, unsigned long pgoff) |
| 161 | { |
| 162 | return do_mmap2 (addr, len, prot, flags, fd, pgoff); |
| 163 | } |
| 164 | |
| 165 | unsigned long sys_mmap (unsigned long addr, size_t len, |
| 166 | unsigned long prot, unsigned long flags, |
| 167 | unsigned long fd, off_t offset) |
| 168 | { |
| 169 | int err = -EINVAL; |
| 170 | |
| 171 | if (offset & ~PAGE_MASK) |
| 172 | goto out; |
| 173 | |
| 174 | err = do_mmap2 (addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
| 175 | out: |
| 176 | return err; |
| 177 | } |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 178 | |
| 179 | /* |
| 180 | * Do a system call from kernel instead of calling sys_execve so we |
| 181 | * end up with proper pt_regs. |
| 182 | */ |
| 183 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]) |
| 184 | { |
| 185 | register char *__a __asm__ ("r6") = filename; |
| 186 | register void *__b __asm__ ("r7") = argv; |
| 187 | register void *__c __asm__ ("r8") = envp; |
| 188 | register unsigned long __syscall __asm__ ("r12") = __NR_execve; |
| 189 | register unsigned long __ret __asm__ ("r10"); |
| 190 | __asm__ __volatile__ ("trap 0" |
| 191 | : "=r" (__ret), "=r" (__syscall) |
| 192 | : "1" (__syscall), "r" (__a), "r" (__b), "r" (__c) |
| 193 | : "r1", "r5", "r11", "r13", "r14", |
| 194 | "r15", "r16", "r17", "r18", "r19"); |
| 195 | return __ret; |
| 196 | } |