Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / ppc / kernel / syscalls.c
blob124313ce3c09055fe8ce73d680bc190196b08033
1 /*
2 * arch/ppc/kernel/sys_ppc.c
4 * PowerPC version
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
14 * platform.
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>
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>
40 #include <asm/uaccess.h>
41 #include <asm/ipc.h>
42 #include <asm/semaphore.h>
44 void
45 check_bugs(void)
50 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
52 * This is really horribly ugly.
54 int
55 sys_ipc (uint call, int first, int second, int third, void __user *ptr, long fifth)
57 int version, ret;
59 version = call >> 16; /* hack for backward compatibility */
60 call &= 0xffff;
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;
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;
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;
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;
105 default:
106 ret = sys_msgrcv (first, (struct msgbuf __user *) ptr,
107 second, fifth, third);
108 break;
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;
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;
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;
140 return ret;
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)
149 int fd[2];
150 int error;
152 error = do_pipe(fd);
153 if (!error) {
154 if (copy_to_user(fildes, fd, 2*sizeof(int)))
155 error = -EFAULT;
157 return error;
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;
166 int ret = -EBADF;
168 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
169 if (!(flags & MAP_ANONYMOUS)) {
170 if (!(file = fget(fd)))
171 goto out;
174 down_write(&current->mm->mmap_sem);
175 ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
176 up_write(&current->mm->mmap_sem);
177 if (file)
178 fput(file);
179 out:
180 return ret;
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)
194 int err = -EINVAL;
196 if (offset & ~PAGE_MASK)
197 goto out;
199 err = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
200 out:
201 return err;
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))))
222 return -EFAULT;
224 return sys_select(n, inp, outp, exp, tvp);
227 int sys_uname(struct old_utsname __user * name)
229 int err = -EFAULT;
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;
238 int sys_olduname(struct oldold_utsname __user * name)
240 int error;
242 if (!name)
243 return -EFAULT;
244 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
245 return -EFAULT;
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);
260 error = error ? -EFAULT : 0;
261 return error;
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);