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>
46 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
48 * This is really horribly ugly.
51 sys_ipc (uint call, int first, int second, int third, void __user *ptr, long fifth)
55 version = call >> 16; /* hack for backward compatibility */
61 ret = sys_semtimedop (first, (struct sembuf __user *)ptr,
65 ret = sys_semtimedop (first, (struct sembuf __user *)ptr,
66 second, (const struct timespec __user *) fifth);
69 ret = sys_semget (first, second, third);
76 if ((ret = access_ok(VERIFY_READ, ptr, sizeof(long)) ? 0 : -EFAULT)
77 || (ret = get_user(fourth.__pad, (void __user *__user *)ptr)))
79 ret = sys_semctl (first, second, third, fourth);
83 ret = sys_msgsnd (first, (struct msgbuf __user *) ptr, second, third);
88 struct ipc_kludge tmp;
92 if ((ret = access_ok(VERIFY_READ, ptr, sizeof(tmp)) ? 0 : -EFAULT)
93 || (ret = copy_from_user(&tmp,
94 (struct ipc_kludge __user *) ptr,
95 sizeof (tmp)) ? -EFAULT : 0))
97 ret = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp,
102 ret = sys_msgrcv (first, (struct msgbuf __user *) ptr,
103 second, fifth, third);
108 ret = sys_msgget ((key_t) first, second);
111 ret = sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
116 if ((ret = access_ok(VERIFY_WRITE, (ulong __user *) third,
117 sizeof(ulong)) ? 0 : -EFAULT))
119 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
122 ret = put_user (raddr, (ulong __user *) third);
126 ret = sys_shmdt ((char __user *)ptr);
129 ret = sys_shmget (first, second, third);
132 ret = sys_shmctl (first, second, (struct shmid_ds __user *) ptr);
140 * sys_pipe() is the normal C calling standard for creating
141 * a pipe. It's not the way unix traditionally does this, though.
143 int sys_pipe(int __user *fildes)
150 if (copy_to_user(fildes, fd, 2*sizeof(int)))
156 static inline unsigned long
157 do_mmap2(unsigned long addr, size_t len,
158 unsigned long prot, unsigned long flags,
159 unsigned long fd, unsigned long pgoff)
161 struct file * file = NULL;
164 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
165 if (!(flags & MAP_ANONYMOUS)) {
166 if (!(file = fget(fd)))
170 down_write(¤t->mm->mmap_sem);
171 ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
172 up_write(¤t->mm->mmap_sem);
179 unsigned long sys_mmap2(unsigned long addr, size_t len,
180 unsigned long prot, unsigned long flags,
181 unsigned long fd, unsigned long pgoff)
183 return do_mmap2(addr, len, prot, flags, fd, pgoff);
186 unsigned long sys_mmap(unsigned long addr, size_t len,
187 unsigned long prot, unsigned long flags,
188 unsigned long fd, off_t offset)
192 if (offset & ~PAGE_MASK)
195 err = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
201 * Due to some executables calling the wrong select we sometimes
202 * get wrong args. This determines how the args are being passed
203 * (a single ptr to them all args passed) then calls
204 * sys_select() with the appropriate args. -- Cort
207 ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timeval __user *tvp)
209 if ( (unsigned long)n >= 4096 )
211 unsigned long __user *buffer = (unsigned long __user *)n;
212 if (!access_ok(VERIFY_READ, buffer, 5*sizeof(unsigned long))
213 || __get_user(n, buffer)
214 || __get_user(inp, ((fd_set __user * __user *)(buffer+1)))
215 || __get_user(outp, ((fd_set __user * __user *)(buffer+2)))
216 || __get_user(exp, ((fd_set __user * __user *)(buffer+3)))
217 || __get_user(tvp, ((struct timeval __user * __user *)(buffer+4))))
220 return sys_select(n, inp, outp, exp, tvp);
223 int sys_uname(struct old_utsname __user * name)
228 if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
234 int sys_olduname(struct oldold_utsname __user * name)
240 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
244 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
245 error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
246 error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
247 error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
248 error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
249 error -= __put_user(0,name->release+__OLD_UTS_LEN);
250 error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
251 error -= __put_user(0,name->version+__OLD_UTS_LEN);
252 error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
253 error = __put_user(0,name->machine+__OLD_UTS_LEN);
256 error = error ? -EFAULT : 0;
261 * We put the arguments in a different order so we only use 6
262 * registers for arguments, rather than 7 as sys_fadvise64_64 needs
263 * (because `offset' goes in r5/r6).
265 long ppc_fadvise64_64(int fd, int advice, loff_t offset, loff_t len)
267 return sys_fadvise64_64(fd, offset, len, advice);