2 * arch/ppc/kernel/sys_ppc.c
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
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).
12 * This file contains various random system calls that
13 * have a non-standard calling sequence on the Linux/PPC
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.
23 #include <linux/errno.h>
24 #include <linux/sched.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>
40 #include <asm/uaccess.h>
42 #include <asm/semaphore.h>
50 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
52 * This is really horribly ugly.
55 sys_ipc (uint call, int first, int second, int third, void __user *ptr, long fifth)
59 version = call >> 16; /* hack for backward compatibility */
65 ret = sys_semtimedop (first, (struct sembuf __user *)ptr,
69 ret = sys_semtimedop (first, (struct sembuf __user *)ptr,
70 second, (const struct timespec __user *) fifth);
73 ret = sys_semget (first, second, third);
80 if ((ret = access_ok(VERIFY_READ, ptr, sizeof(long)) ? 0 : -EFAULT)
81 || (ret = get_user(fourth.__pad, (void __user *__user *)ptr)))
83 ret = sys_semctl (first, second, third, fourth);
87 ret = sys_msgsnd (first, (struct msgbuf __user *) ptr, second, third);
92 struct ipc_kludge tmp;
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))
101 ret = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp,
106 ret = sys_msgrcv (first, (struct msgbuf __user *) ptr,
107 second, fifth, third);
112 ret = sys_msgget ((key_t) first, second);
115 ret = sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
120 if ((ret = access_ok(VERIFY_WRITE, (ulong __user *) third,
121 sizeof(ulong)) ? 0 : -EFAULT))
123 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
126 ret = put_user (raddr, (ulong __user *) third);
130 ret = sys_shmdt ((char __user *)ptr);
133 ret = sys_shmget (first, second, third);
136 ret = sys_shmctl (first, second, (struct shmid_ds __user *) ptr);
144 * sys_pipe() is the normal C calling standard for creating
145 * a pipe. It's not the way unix traditionally does this, though.
147 int sys_pipe(int __user *fildes)
154 if (copy_to_user(fildes, fd, 2*sizeof(int)))
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)
165 struct file * file = NULL;
168 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
169 if (!(flags & MAP_ANONYMOUS)) {
170 if (!(file = fget(fd)))
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);
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)
187 return do_mmap2(addr, len, prot, flags, fd, pgoff);
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)
196 if (offset & ~PAGE_MASK)
199 err = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
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
211 ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timeval __user *tvp)
213 if ( (unsigned long)n >= 4096 )
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))))
224 return sys_select(n, inp, outp, exp, tvp);
227 int sys_uname(struct old_utsname __user * name)
232 if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
238 int sys_olduname(struct oldold_utsname __user * name)
244 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
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);
260 error = error ? -EFAULT : 0;
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).
269 long ppc_fadvise64_64(int fd, int advice, loff_t offset, loff_t len)
271 return sys_fadvise64_64(fd, offset, len, advice);