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> |
| 21 | #include <linux/smp_lock.h> |
| 22 | #include <linux/syscalls.h> |
| 23 | #include <linux/sem.h> |
| 24 | #include <linux/msg.h> |
| 25 | #include <linux/shm.h> |
| 26 | #include <linux/stat.h> |
| 27 | #include <linux/mman.h> |
| 28 | #include <linux/sys.h> |
| 29 | #include <linux/ipc.h> |
| 30 | #include <linux/utsname.h> |
| 31 | #include <linux/file.h> |
| 32 | |
| 33 | #include <asm/uaccess.h> |
| 34 | #include <asm/ipc.h> |
| 35 | #include <asm/semaphore.h> |
| 36 | |
| 37 | /* |
| 38 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. |
| 39 | * |
| 40 | * This is really horribly ugly. |
| 41 | */ |
| 42 | int |
| 43 | sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth) |
| 44 | { |
| 45 | int version, ret; |
| 46 | |
| 47 | version = call >> 16; /* hack for backward compatibility */ |
| 48 | call &= 0xffff; |
| 49 | |
| 50 | ret = -EINVAL; |
| 51 | switch (call) { |
| 52 | case SEMOP: |
| 53 | ret = sys_semop (first, (struct sembuf *)ptr, second); |
| 54 | break; |
| 55 | case SEMGET: |
| 56 | ret = sys_semget (first, second, third); |
| 57 | break; |
| 58 | case SEMCTL: |
| 59 | { |
| 60 | union semun fourth; |
| 61 | |
| 62 | if (!ptr) |
| 63 | break; |
| 64 | if ((ret = access_ok(VERIFY_READ, ptr, sizeof(long)) ? 0 : -EFAULT) |
| 65 | || (ret = get_user(fourth.__pad, (void **)ptr))) |
| 66 | break; |
| 67 | ret = sys_semctl (first, second, third, fourth); |
| 68 | break; |
| 69 | } |
| 70 | case MSGSND: |
| 71 | ret = sys_msgsnd (first, (struct msgbuf *) ptr, second, third); |
| 72 | break; |
| 73 | case MSGRCV: |
| 74 | switch (version) { |
| 75 | case 0: { |
| 76 | struct ipc_kludge tmp; |
| 77 | |
| 78 | if (!ptr) |
| 79 | break; |
| 80 | if ((ret = access_ok(VERIFY_READ, ptr, sizeof(tmp)) ? 0 : -EFAULT) |
| 81 | || (ret = copy_from_user(&tmp, |
| 82 | (struct ipc_kludge *) ptr, |
| 83 | sizeof (tmp)))) |
| 84 | break; |
| 85 | ret = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, |
| 86 | third); |
| 87 | break; |
| 88 | } |
| 89 | default: |
| 90 | ret = sys_msgrcv (first, (struct msgbuf *) ptr, |
| 91 | second, fifth, third); |
| 92 | break; |
| 93 | } |
| 94 | break; |
| 95 | case MSGGET: |
| 96 | ret = sys_msgget ((key_t) first, second); |
| 97 | break; |
| 98 | case MSGCTL: |
| 99 | ret = sys_msgctl (first, second, (struct msqid_ds *) ptr); |
| 100 | break; |
| 101 | case SHMAT: |
| 102 | switch (version) { |
| 103 | default: { |
| 104 | ulong raddr; |
| 105 | |
| 106 | if ((ret = access_ok(VERIFY_WRITE, (ulong*) third, |
| 107 | sizeof(ulong)) ? 0 : -EFAULT)) |
| 108 | break; |
| 109 | ret = do_shmat (first, (char *) ptr, second, &raddr); |
| 110 | if (ret) |
| 111 | break; |
| 112 | ret = put_user (raddr, (ulong *) third); |
| 113 | break; |
| 114 | } |
| 115 | case 1: /* iBCS2 emulator entry point */ |
| 116 | if (!segment_eq(get_fs(), get_ds())) |
| 117 | break; |
| 118 | ret = do_shmat (first, (char *) ptr, second, |
| 119 | (ulong *) third); |
| 120 | break; |
| 121 | } |
| 122 | break; |
| 123 | case SHMDT: |
| 124 | ret = sys_shmdt ((char *)ptr); |
| 125 | break; |
| 126 | case SHMGET: |
| 127 | ret = sys_shmget (first, second, third); |
| 128 | break; |
| 129 | case SHMCTL: |
| 130 | ret = sys_shmctl (first, second, (struct shmid_ds *) ptr); |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * sys_pipe() is the normal C calling standard for creating |
| 139 | * a pipe. It's not the way unix traditionally does this, though. |
| 140 | */ |
| 141 | int sys_pipe (int *fildes) |
| 142 | { |
| 143 | int fd[2]; |
| 144 | int error; |
| 145 | |
| 146 | error = do_pipe (fd); |
| 147 | if (!error) { |
| 148 | if (copy_to_user (fildes, fd, 2*sizeof (int))) |
| 149 | error = -EFAULT; |
| 150 | } |
| 151 | return error; |
| 152 | } |
| 153 | |
| 154 | static inline unsigned long |
| 155 | do_mmap2 (unsigned long addr, size_t len, |
| 156 | unsigned long prot, unsigned long flags, |
| 157 | unsigned long fd, unsigned long pgoff) |
| 158 | { |
| 159 | struct file * file = NULL; |
| 160 | int ret = -EBADF; |
| 161 | |
| 162 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
| 163 | if (! (flags & MAP_ANONYMOUS)) { |
| 164 | if (!(file = fget (fd))) |
| 165 | goto out; |
| 166 | } |
| 167 | |
| 168 | down_write (¤t->mm->mmap_sem); |
| 169 | ret = do_mmap_pgoff (file, addr, len, prot, flags, pgoff); |
| 170 | up_write (¤t->mm->mmap_sem); |
| 171 | if (file) |
| 172 | fput (file); |
| 173 | out: |
| 174 | return ret; |
| 175 | } |
| 176 | |
| 177 | unsigned long sys_mmap2 (unsigned long addr, size_t len, |
| 178 | unsigned long prot, unsigned long flags, |
| 179 | unsigned long fd, unsigned long pgoff) |
| 180 | { |
| 181 | return do_mmap2 (addr, len, prot, flags, fd, pgoff); |
| 182 | } |
| 183 | |
| 184 | unsigned long sys_mmap (unsigned long addr, size_t len, |
| 185 | unsigned long prot, unsigned long flags, |
| 186 | unsigned long fd, off_t offset) |
| 187 | { |
| 188 | int err = -EINVAL; |
| 189 | |
| 190 | if (offset & ~PAGE_MASK) |
| 191 | goto out; |
| 192 | |
| 193 | err = do_mmap2 (addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
| 194 | out: |
| 195 | return err; |
| 196 | } |