Pull altix-mmr into release branch
[sfrench/cifs-2.6.git] / arch / ppc64 / kernel / syscalls.c
1 /*
2  * linux/arch/ppc64/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/syscalls.h>
26 #include <linux/mm.h>
27 #include <linux/smp.h>
28 #include <linux/smp_lock.h>
29 #include <linux/sem.h>
30 #include <linux/msg.h>
31 #include <linux/shm.h>
32 #include <linux/stat.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/init.h>
39 #include <linux/personality.h>
40
41 #include <asm/uaccess.h>
42 #include <asm/ipc.h>
43 #include <asm/semaphore.h>
44 #include <asm/time.h>
45 #include <asm/unistd.h>
46
47 extern unsigned long wall_jiffies;
48
49
50 /*
51  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
52  *
53  * This is really horribly ugly.
54  */
55 asmlinkage int 
56 sys_ipc (uint call, int first, unsigned long second, long third,
57          void __user *ptr, long fifth)
58 {
59         int version, ret;
60
61         version = call >> 16; /* hack for backward compatibility */
62         call &= 0xffff;
63
64         ret = -ENOSYS;
65         switch (call) {
66         case SEMOP:
67                 ret = sys_semtimedop(first, (struct sembuf __user *)ptr,
68                                       (unsigned)second, NULL);
69                 break;
70         case SEMTIMEDOP:
71                 ret = sys_semtimedop(first, (struct sembuf __user *)ptr,
72                                       (unsigned)second,
73                                       (const struct timespec __user *) fifth);
74                 break;
75         case SEMGET:
76                 ret = sys_semget (first, (int)second, third);
77                 break;
78         case SEMCTL: {
79                 union semun fourth;
80
81                 ret = -EINVAL;
82                 if (!ptr)
83                         break;
84                 if ((ret = get_user(fourth.__pad, (void __user * __user *)ptr)))
85                         break;
86                 ret = sys_semctl(first, (int)second, third, fourth);
87                 break;
88         }
89         case MSGSND:
90                 ret = sys_msgsnd(first, (struct msgbuf __user *)ptr,
91                                   (size_t)second, third);
92                 break;
93         case MSGRCV:
94                 switch (version) {
95                 case 0: {
96                         struct ipc_kludge tmp;
97
98                         ret = -EINVAL;
99                         if (!ptr)
100                                 break;
101                         if ((ret = copy_from_user(&tmp,
102                                                 (struct ipc_kludge __user *) ptr,
103                                                 sizeof (tmp)) ? -EFAULT : 0))
104                                 break;
105                         ret = sys_msgrcv(first, tmp.msgp, (size_t) second,
106                                           tmp.msgtyp, third);
107                         break;
108                 }
109                 default:
110                         ret = sys_msgrcv (first, (struct msgbuf __user *) ptr,
111                                           (size_t)second, fifth, third);
112                         break;
113                 }
114                 break;
115         case MSGGET:
116                 ret = sys_msgget ((key_t)first, (int)second);
117                 break;
118         case MSGCTL:
119                 ret = sys_msgctl(first, (int)second,
120                                   (struct msqid_ds __user *)ptr);
121                 break;
122         case SHMAT:
123                 switch (version) {
124                 default: {
125                         ulong raddr;
126                         ret = do_shmat(first, (char __user *) ptr,
127                                         (int)second, &raddr);
128                         if (ret)
129                                 break;
130                         ret = put_user (raddr, (ulong __user *) third);
131                         break;
132                 }
133                 case 1: /* iBCS2 emulator entry point */
134                         ret = -EINVAL;
135                         if (!segment_eq(get_fs(), get_ds()))
136                                 break;
137                         ret = do_shmat(first, (char __user *)ptr,
138                                         (int)second, (ulong *)third);
139                         break;
140                 }
141                 break;
142         case SHMDT: 
143                 ret = sys_shmdt ((char __user *)ptr);
144                 break;
145         case SHMGET:
146                 ret = sys_shmget (first, (size_t)second, third);
147                 break;
148         case SHMCTL:
149                 ret = sys_shmctl(first, (int)second,
150                                   (struct shmid_ds __user *)ptr);
151                 break;
152         }
153
154         return ret;
155 }
156
157 /*
158  * sys_pipe() is the normal C calling standard for creating
159  * a pipe. It's not the way unix traditionally does this, though.
160  */
161 asmlinkage int sys_pipe(int __user *fildes)
162 {
163         int fd[2];
164         int error;
165         
166         error = do_pipe(fd);
167         if (!error) {
168                 if (copy_to_user(fildes, fd, 2*sizeof(int)))
169                         error = -EFAULT;
170         }
171         
172         return error;
173 }
174
175 unsigned long sys_mmap(unsigned long addr, size_t len,
176                        unsigned long prot, unsigned long flags,
177                        unsigned long fd, off_t offset)
178 {
179         struct file * file = NULL;
180         unsigned long ret = -EBADF;
181
182         if (!(flags & MAP_ANONYMOUS)) {
183                 if (!(file = fget(fd)))
184                         goto out;
185         }
186
187         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
188         down_write(&current->mm->mmap_sem);
189         ret = do_mmap(file, addr, len, prot, flags, offset);
190         up_write(&current->mm->mmap_sem);
191         if (file)
192                 fput(file);
193
194 out:
195         return ret;
196 }
197
198 long ppc64_personality(unsigned long personality)
199 {
200         long ret;
201
202         if (personality(current->personality) == PER_LINUX32
203             && personality == PER_LINUX)
204                 personality = PER_LINUX32;
205         ret = sys_personality(personality);
206         if (ret == PER_LINUX32)
207                 ret = PER_LINUX;
208         return ret;
209 }
210
211 long ppc64_newuname(struct new_utsname __user * name)
212 {
213         int err = 0;
214
215         down_read(&uts_sem);
216         if (copy_to_user(name, &system_utsname, sizeof(*name)))
217                 err = -EFAULT;
218         up_read(&uts_sem);
219         if (!err && personality(current->personality) == PER_LINUX32) {
220                 /* change ppc64 to ppc */
221                 if (__put_user(0, name->machine + 3)
222                     || __put_user(0, name->machine + 4))
223                         err = -EFAULT;
224         }
225         return err;
226 }
227
228 asmlinkage time_t sys64_time(time_t __user * tloc)
229 {
230         time_t secs;
231         time_t usecs;
232
233         long tb_delta = tb_ticks_since(tb_last_stamp);
234         tb_delta += (jiffies - wall_jiffies) * tb_ticks_per_jiffy;
235
236         secs  = xtime.tv_sec;  
237         usecs = (xtime.tv_nsec/1000) + tb_delta / tb_ticks_per_usec;
238         while (usecs >= USEC_PER_SEC) {
239                 ++secs;
240                 usecs -= USEC_PER_SEC;
241         }
242
243         if (tloc) {
244                 if (put_user(secs,tloc))
245                         secs = -EFAULT;
246         }
247
248         return secs;
249 }
250
251 void do_show_syscall(unsigned long r3, unsigned long r4, unsigned long r5,
252                      unsigned long r6, unsigned long r7, unsigned long r8,
253                      struct pt_regs *regs)
254 {
255         printk("syscall %ld(%lx, %lx, %lx, %lx, %lx, %lx) regs=%p current=%p"
256                " cpu=%d\n", regs->gpr[0], r3, r4, r5, r6, r7, r8, regs,
257                current, smp_processor_id());
258 }
259
260 void do_show_syscall_exit(unsigned long r3)
261 {
262         printk(" -> %lx, current=%p cpu=%d\n", r3, current, smp_processor_id());
263 }