Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * arch/ppc/kernel/sys_ppc.c |
| 3 | * |
| 4 | * PowerPC version |
| 5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 6 | * |
| 7 | * Derived from "arch/i386/kernel/sys_i386.c" |
| 8 | * Adapted from the i386 version by Gary Thomas |
| 9 | * Modified by Cort Dougan (cort@cs.nmt.edu) |
| 10 | * and Paul Mackerras (paulus@cs.anu.edu.au). |
| 11 | * |
| 12 | * This file contains various random system calls that |
| 13 | * have a non-standard calling sequence on the Linux/PPC |
| 14 | * platform. |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU General Public License |
| 18 | * as published by the Free Software Foundation; either version |
| 19 | * 2 of the License, or (at your option) any later version. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/sched.h> |
| 25 | #include <linux/mm.h> |
| 26 | #include <linux/smp.h> |
| 27 | #include <linux/smp_lock.h> |
| 28 | #include <linux/sem.h> |
| 29 | #include <linux/msg.h> |
| 30 | #include <linux/shm.h> |
| 31 | #include <linux/stat.h> |
| 32 | #include <linux/syscalls.h> |
| 33 | #include <linux/mman.h> |
| 34 | #include <linux/sys.h> |
| 35 | #include <linux/ipc.h> |
| 36 | #include <linux/utsname.h> |
| 37 | #include <linux/file.h> |
| 38 | #include <linux/unistd.h> |
| 39 | |
| 40 | #include <asm/uaccess.h> |
| 41 | #include <asm/ipc.h> |
| 42 | #include <asm/semaphore.h> |
| 43 | |
| 44 | void |
| 45 | check_bugs(void) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. |
| 51 | * |
| 52 | * This is really horribly ugly. |
| 53 | */ |
| 54 | int |
| 55 | sys_ipc (uint call, int first, int second, int third, void __user *ptr, long fifth) |
| 56 | { |
| 57 | int version, ret; |
| 58 | |
| 59 | version = call >> 16; /* hack for backward compatibility */ |
| 60 | call &= 0xffff; |
| 61 | |
| 62 | ret = -ENOSYS; |
| 63 | switch (call) { |
| 64 | case SEMOP: |
| 65 | ret = sys_semtimedop (first, (struct sembuf __user *)ptr, |
| 66 | second, NULL); |
| 67 | break; |
| 68 | case SEMTIMEDOP: |
| 69 | ret = sys_semtimedop (first, (struct sembuf __user *)ptr, |
| 70 | second, (const struct timespec __user *) fifth); |
| 71 | break; |
| 72 | case SEMGET: |
| 73 | ret = sys_semget (first, second, third); |
| 74 | break; |
| 75 | case SEMCTL: { |
| 76 | union semun fourth; |
| 77 | |
| 78 | if (!ptr) |
| 79 | break; |
| 80 | if ((ret = access_ok(VERIFY_READ, ptr, sizeof(long)) ? 0 : -EFAULT) |
| 81 | || (ret = get_user(fourth.__pad, (void __user *__user *)ptr))) |
| 82 | break; |
| 83 | ret = sys_semctl (first, second, third, fourth); |
| 84 | break; |
| 85 | } |
| 86 | case MSGSND: |
| 87 | ret = sys_msgsnd (first, (struct msgbuf __user *) ptr, second, third); |
| 88 | break; |
| 89 | case MSGRCV: |
| 90 | switch (version) { |
| 91 | case 0: { |
| 92 | struct ipc_kludge tmp; |
| 93 | |
| 94 | if (!ptr) |
| 95 | break; |
| 96 | if ((ret = access_ok(VERIFY_READ, ptr, sizeof(tmp)) ? 0 : -EFAULT) |
| 97 | || (ret = copy_from_user(&tmp, |
| 98 | (struct ipc_kludge __user *) ptr, |
| 99 | sizeof (tmp)) ? -EFAULT : 0)) |
| 100 | break; |
| 101 | ret = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, |
| 102 | third); |
| 103 | break; |
| 104 | } |
| 105 | default: |
| 106 | ret = sys_msgrcv (first, (struct msgbuf __user *) ptr, |
| 107 | second, fifth, third); |
| 108 | break; |
| 109 | } |
| 110 | break; |
| 111 | case MSGGET: |
| 112 | ret = sys_msgget ((key_t) first, second); |
| 113 | break; |
| 114 | case MSGCTL: |
| 115 | ret = sys_msgctl (first, second, (struct msqid_ds __user *) ptr); |
| 116 | break; |
| 117 | case SHMAT: { |
| 118 | ulong raddr; |
| 119 | |
| 120 | if ((ret = access_ok(VERIFY_WRITE, (ulong __user *) third, |
| 121 | sizeof(ulong)) ? 0 : -EFAULT)) |
| 122 | break; |
| 123 | ret = do_shmat (first, (char __user *) ptr, second, &raddr); |
| 124 | if (ret) |
| 125 | break; |
| 126 | ret = put_user (raddr, (ulong __user *) third); |
| 127 | break; |
| 128 | } |
| 129 | case SHMDT: |
| 130 | ret = sys_shmdt ((char __user *)ptr); |
| 131 | break; |
| 132 | case SHMGET: |
| 133 | ret = sys_shmget (first, second, third); |
| 134 | break; |
| 135 | case SHMCTL: |
| 136 | ret = sys_shmctl (first, second, (struct shmid_ds __user *) ptr); |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * sys_pipe() is the normal C calling standard for creating |
| 145 | * a pipe. It's not the way unix traditionally does this, though. |
| 146 | */ |
| 147 | int sys_pipe(int __user *fildes) |
| 148 | { |
| 149 | int fd[2]; |
| 150 | int error; |
| 151 | |
| 152 | error = do_pipe(fd); |
| 153 | if (!error) { |
| 154 | if (copy_to_user(fildes, fd, 2*sizeof(int))) |
| 155 | error = -EFAULT; |
| 156 | } |
| 157 | return error; |
| 158 | } |
| 159 | |
| 160 | static inline unsigned long |
| 161 | do_mmap2(unsigned long addr, size_t len, |
| 162 | unsigned long prot, unsigned long flags, |
| 163 | unsigned long fd, unsigned long pgoff) |
| 164 | { |
| 165 | struct file * file = NULL; |
| 166 | int ret = -EBADF; |
| 167 | |
| 168 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
| 169 | if (!(flags & MAP_ANONYMOUS)) { |
| 170 | if (!(file = fget(fd))) |
| 171 | goto out; |
| 172 | } |
| 173 | |
| 174 | down_write(¤t->mm->mmap_sem); |
| 175 | ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); |
| 176 | up_write(¤t->mm->mmap_sem); |
| 177 | if (file) |
| 178 | fput(file); |
| 179 | out: |
| 180 | return ret; |
| 181 | } |
| 182 | |
| 183 | unsigned long sys_mmap2(unsigned long addr, size_t len, |
| 184 | unsigned long prot, unsigned long flags, |
| 185 | unsigned long fd, unsigned long pgoff) |
| 186 | { |
| 187 | return do_mmap2(addr, len, prot, flags, fd, pgoff); |
| 188 | } |
| 189 | |
| 190 | unsigned long sys_mmap(unsigned long addr, size_t len, |
| 191 | unsigned long prot, unsigned long flags, |
| 192 | unsigned long fd, off_t offset) |
| 193 | { |
| 194 | int err = -EINVAL; |
| 195 | |
| 196 | if (offset & ~PAGE_MASK) |
| 197 | goto out; |
| 198 | |
| 199 | err = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
| 200 | out: |
| 201 | return err; |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * Due to some executables calling the wrong select we sometimes |
| 206 | * get wrong args. This determines how the args are being passed |
| 207 | * (a single ptr to them all args passed) then calls |
| 208 | * sys_select() with the appropriate args. -- Cort |
| 209 | */ |
| 210 | int |
| 211 | ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timeval __user *tvp) |
| 212 | { |
| 213 | if ( (unsigned long)n >= 4096 ) |
| 214 | { |
| 215 | unsigned long __user *buffer = (unsigned long __user *)n; |
| 216 | if (!access_ok(VERIFY_READ, buffer, 5*sizeof(unsigned long)) |
| 217 | || __get_user(n, buffer) |
| 218 | || __get_user(inp, ((fd_set __user * __user *)(buffer+1))) |
| 219 | || __get_user(outp, ((fd_set __user * __user *)(buffer+2))) |
| 220 | || __get_user(exp, ((fd_set __user * __user *)(buffer+3))) |
| 221 | || __get_user(tvp, ((struct timeval __user * __user *)(buffer+4)))) |
| 222 | return -EFAULT; |
| 223 | } |
| 224 | return sys_select(n, inp, outp, exp, tvp); |
| 225 | } |
| 226 | |
| 227 | int sys_uname(struct old_utsname __user * name) |
| 228 | { |
| 229 | int err = -EFAULT; |
| 230 | |
| 231 | down_read(&uts_sem); |
| 232 | if (name && !copy_to_user(name, &system_utsname, sizeof (*name))) |
| 233 | err = 0; |
| 234 | up_read(&uts_sem); |
| 235 | return err; |
| 236 | } |
| 237 | |
| 238 | int sys_olduname(struct oldold_utsname __user * name) |
| 239 | { |
| 240 | int error; |
| 241 | |
| 242 | if (!name) |
| 243 | return -EFAULT; |
| 244 | if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) |
| 245 | return -EFAULT; |
| 246 | |
| 247 | down_read(&uts_sem); |
| 248 | error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN); |
| 249 | error -= __put_user(0,name->sysname+__OLD_UTS_LEN); |
| 250 | error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN); |
| 251 | error -= __put_user(0,name->nodename+__OLD_UTS_LEN); |
| 252 | error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN); |
| 253 | error -= __put_user(0,name->release+__OLD_UTS_LEN); |
| 254 | error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN); |
| 255 | error -= __put_user(0,name->version+__OLD_UTS_LEN); |
| 256 | error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN); |
| 257 | error = __put_user(0,name->machine+__OLD_UTS_LEN); |
| 258 | up_read(&uts_sem); |
| 259 | |
| 260 | error = error ? -EFAULT : 0; |
| 261 | return error; |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | * We put the arguments in a different order so we only use 6 |
| 266 | * registers for arguments, rather than 7 as sys_fadvise64_64 needs |
| 267 | * (because `offset' goes in r5/r6). |
| 268 | */ |
| 269 | long ppc_fadvise64_64(int fd, int advice, loff_t offset, loff_t len) |
| 270 | { |
| 271 | return sys_fadvise64_64(fd, offset, len, advice); |
| 272 | } |