]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/parisc/kernel/sys_parisc32.c
2c3af17e049cb4c4bcc6633d22faab2a0097ce44
[linux-2.6-omap-h63xx.git] / arch / parisc / kernel / sys_parisc32.c
1 /*
2  * sys_parisc32.c: Conversion between 32bit and 64bit native syscalls.
3  *
4  * Copyright (C) 2000-2001 Hewlett Packard Company
5  * Copyright (C) 2000 John Marvin
6  * Copyright (C) 2001 Matthew Wilcox
7  *
8  * These routines maintain argument size conversion between 32bit and 64bit
9  * environment. Based heavily on sys_ia32.c and sys_sparc32.c.
10  */
11
12 #include <linux/compat.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/fs.h> 
16 #include <linux/mm.h> 
17 #include <linux/file.h> 
18 #include <linux/signal.h>
19 #include <linux/resource.h>
20 #include <linux/times.h>
21 #include <linux/utsname.h>
22 #include <linux/time.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/sem.h>
26 #include <linux/msg.h>
27 #include <linux/shm.h>
28 #include <linux/slab.h>
29 #include <linux/uio.h>
30 #include <linux/nfs_fs.h>
31 #include <linux/ncp_fs.h>
32 #include <linux/sunrpc/svc.h>
33 #include <linux/nfsd/nfsd.h>
34 #include <linux/nfsd/cache.h>
35 #include <linux/nfsd/xdr.h>
36 #include <linux/nfsd/syscall.h>
37 #include <linux/poll.h>
38 #include <linux/personality.h>
39 #include <linux/stat.h>
40 #include <linux/highmem.h>
41 #include <linux/highuid.h>
42 #include <linux/mman.h>
43 #include <linux/binfmts.h>
44 #include <linux/namei.h>
45 #include <linux/vfs.h>
46 #include <linux/ptrace.h>
47 #include <linux/swap.h>
48 #include <linux/syscalls.h>
49
50 #include <asm/types.h>
51 #include <asm/uaccess.h>
52 #include <asm/mmu_context.h>
53
54 #include "sys32.h"
55
56 #undef DEBUG
57
58 #ifdef DEBUG
59 #define DBG(x)  printk x
60 #else
61 #define DBG(x)
62 #endif
63
64 /*
65  * sys32_execve() executes a new program.
66  */
67
68 asmlinkage int sys32_execve(struct pt_regs *regs)
69 {
70         int error;
71         char *filename;
72
73         DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26]));
74         filename = getname((const char __user *) regs->gr[26]);
75         error = PTR_ERR(filename);
76         if (IS_ERR(filename))
77                 goto out;
78         error = compat_do_execve(filename, compat_ptr(regs->gr[25]),
79                                  compat_ptr(regs->gr[24]), regs);
80         if (error == 0) {
81                 task_lock(current);
82                 current->ptrace &= ~PT_DTRACE;
83                 task_unlock(current);
84         }
85         putname(filename);
86 out:
87
88         return error;
89 }
90
91 asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,
92         int r22, int r21, int r20)
93 {
94     printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n", 
95         current->comm, current->pid, r20);
96     return -ENOSYS;
97 }
98
99 #ifdef CONFIG_SYSCTL
100
101 struct __sysctl_args32 {
102         u32 name;
103         int nlen;
104         u32 oldval;
105         u32 oldlenp;
106         u32 newval;
107         u32 newlen;
108         u32 __unused[4];
109 };
110
111 asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
112 {
113 #ifndef CONFIG_SYSCTL_SYSCALL
114         return -ENOSYS;
115 #else
116         struct __sysctl_args32 tmp;
117         int error;
118         unsigned int oldlen32;
119         size_t oldlen, __user *oldlenp = NULL;
120         unsigned long addr = (((long __force)&args->__unused[0]) + 7) & ~7;
121
122         DBG(("sysctl32(%p)\n", args));
123
124         if (copy_from_user(&tmp, args, sizeof(tmp)))
125                 return -EFAULT;
126
127         if (tmp.oldval && tmp.oldlenp) {
128                 /* Duh, this is ugly and might not work if sysctl_args
129                    is in read-only memory, but do_sysctl does indirectly
130                    a lot of uaccess in both directions and we'd have to
131                    basically copy the whole sysctl.c here, and
132                    glibc's __sysctl uses rw memory for the structure
133                    anyway.  */
134                 /* a possibly better hack than this, which will avoid the
135                  * problem if the struct is read only, is to push the
136                  * 'oldlen' value out to the user's stack instead. -PB
137                  */
138                 if (get_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
139                         return -EFAULT;
140                 oldlen = oldlen32;
141                 if (put_user(oldlen, (size_t *)addr))
142                         return -EFAULT;
143                 oldlenp = (size_t *)addr;
144         }
145
146         lock_kernel();
147         error = do_sysctl((int __user *)(u64)tmp.name, tmp.nlen,
148                           (void __user *)(u64)tmp.oldval, oldlenp,
149                           (void __user *)(u64)tmp.newval, tmp.newlen);
150         unlock_kernel();
151         if (oldlenp) {
152                 if (!error) {
153                         if (get_user(oldlen, (size_t *)addr)) {
154                                 error = -EFAULT;
155                         } else {
156                                 oldlen32 = oldlen;
157                                 if (put_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
158                                         error = -EFAULT;
159                         }
160                 }
161                 if (copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
162                         error = -EFAULT;
163         }
164         return error;
165 #endif
166 }
167
168 #endif /* CONFIG_SYSCTL */
169
170 asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
171         struct compat_timespec __user *interval)
172 {
173         struct timespec t;
174         int ret;
175
176         KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, (struct timespec __user *)&t);
177         if (put_compat_timespec(&t, interval))
178                 return -EFAULT;
179         return ret;
180 }
181
182 static int
183 put_compat_timeval(struct compat_timeval __user *u, struct timeval *t)
184 {
185         struct compat_timeval t32;
186         t32.tv_sec = t->tv_sec;
187         t32.tv_usec = t->tv_usec;
188         return copy_to_user(u, &t32, sizeof t32);
189 }
190
191 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
192 {
193         long usec;
194
195         if (__get_user(o->tv_sec, &i->tv_sec))
196                 return -EFAULT;
197         if (__get_user(usec, &i->tv_usec))
198                 return -EFAULT;
199         o->tv_nsec = usec * 1000;
200         return 0;
201 }
202
203 asmlinkage int
204 sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
205 {
206     extern void do_gettimeofday(struct timeval *tv);
207
208     if (tv) {
209             struct timeval ktv;
210             do_gettimeofday(&ktv);
211             if (put_compat_timeval(tv, &ktv))
212                     return -EFAULT;
213     }
214     if (tz) {
215             extern struct timezone sys_tz;
216             if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
217                     return -EFAULT;
218     }
219     return 0;
220 }
221
222 asmlinkage 
223 int sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
224 {
225         struct timespec kts;
226         struct timezone ktz;
227
228         if (tv) {
229                 if (get_ts32(&kts, tv))
230                         return -EFAULT;
231         }
232         if (tz) {
233                 if (copy_from_user(&ktz, tz, sizeof(ktz)))
234                         return -EFAULT;
235         }
236
237         return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
238 }
239
240 /*** copied from mips64 ***/
241 /*
242  * Ooo, nasty.  We need here to frob 32-bit unsigned longs to
243  * 64-bit unsigned longs.
244  */
245
246 static inline int
247 get_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
248 {
249         n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
250         if (ufdset) {
251                 unsigned long odd;
252
253                 if (!access_ok(VERIFY_WRITE, ufdset, n*sizeof(u32)))
254                         return -EFAULT;
255
256                 odd = n & 1UL;
257                 n &= ~1UL;
258                 while (n) {
259                         unsigned long h, l;
260                         __get_user(l, ufdset);
261                         __get_user(h, ufdset+1);
262                         ufdset += 2;
263                         *fdset++ = h << 32 | l;
264                         n -= 2;
265                 }
266                 if (odd)
267                         __get_user(*fdset, ufdset);
268         } else {
269                 /* Tricky, must clear full unsigned long in the
270                  * kernel fdset at the end, this makes sure that
271                  * actually happens.
272                  */
273                 memset(fdset, 0, ((n + 1) & ~1)*sizeof(u32));
274         }
275         return 0;
276 }
277
278 static inline void
279 set_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
280 {
281         unsigned long odd;
282         n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
283
284         if (!ufdset)
285                 return;
286
287         odd = n & 1UL;
288         n &= ~1UL;
289         while (n) {
290                 unsigned long h, l;
291                 l = *fdset++;
292                 h = l >> 32;
293                 __put_user(l, ufdset);
294                 __put_user(h, ufdset+1);
295                 ufdset += 2;
296                 n -= 2;
297         }
298         if (odd)
299                 __put_user(*fdset, ufdset);
300 }
301
302 struct msgbuf32 {
303     int mtype;
304     char mtext[1];
305 };
306
307 asmlinkage long sys32_msgsnd(int msqid,
308                                 struct msgbuf32 __user *umsgp32,
309                                 size_t msgsz, int msgflg)
310 {
311         struct msgbuf *mb;
312         struct msgbuf32 mb32;
313         int err;
314
315         if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
316                 return -ENOMEM;
317
318         err = get_user(mb32.mtype, &umsgp32->mtype);
319         mb->mtype = mb32.mtype;
320         err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz);
321
322         if (err)
323                 err = -EFAULT;
324         else
325                 KERNEL_SYSCALL(err, sys_msgsnd, msqid, (struct msgbuf __user *)mb, msgsz, msgflg);
326
327         kfree(mb);
328         return err;
329 }
330
331 asmlinkage long sys32_msgrcv(int msqid,
332                                 struct msgbuf32 __user *umsgp32,
333                                 size_t msgsz, long msgtyp, int msgflg)
334 {
335         struct msgbuf *mb;
336         struct msgbuf32 mb32;
337         int err, len;
338
339         if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
340                 return -ENOMEM;
341
342         KERNEL_SYSCALL(err, sys_msgrcv, msqid, (struct msgbuf __user *)mb, msgsz, msgtyp, msgflg);
343
344         if (err >= 0) {
345                 len = err;
346                 mb32.mtype = mb->mtype;
347                 err = put_user(mb32.mtype, &umsgp32->mtype);
348                 err |= copy_to_user(&umsgp32->mtext, mb->mtext, len);
349                 if (err)
350                         err = -EFAULT;
351                 else
352                         err = len;
353         }
354
355         kfree(mb);
356         return err;
357 }
358
359 asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
360 {
361         mm_segment_t old_fs = get_fs();
362         int ret;
363         off_t of;
364
365         if (offset && get_user(of, offset))
366                 return -EFAULT;
367
368         set_fs(KERNEL_DS);
369         ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count);
370         set_fs(old_fs);
371
372         if (offset && put_user(of, offset))
373                 return -EFAULT;
374
375         return ret;
376 }
377
378 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
379 {
380         mm_segment_t old_fs = get_fs();
381         int ret;
382         loff_t lof;
383         
384         if (offset && get_user(lof, offset))
385                 return -EFAULT;
386                 
387         set_fs(KERNEL_DS);
388         ret = sys_sendfile64(out_fd, in_fd, offset ? (loff_t __user *)&lof : NULL, count);
389         set_fs(old_fs);
390         
391         if (offset && put_user(lof, offset))
392                 return -EFAULT;
393                 
394         return ret;
395 }
396
397
398 /* lseek() needs a wrapper because 'offset' can be negative, but the top
399  * half of the argument has been zeroed by syscall.S.
400  */
401
402 asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin)
403 {
404         return sys_lseek(fd, offset, origin);
405 }
406
407 asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
408 {
409         union semun u;
410         
411         if (cmd == SETVAL) {
412                 /* Ugh.  arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
413                  * The int should be in the first 4, but our argument
414                  * frobbing has left it in the last 4.
415                  */
416                 u.val = *((int *)&arg + 1);
417                 return sys_semctl (semid, semnum, cmd, u);
418         }
419         return sys_semctl (semid, semnum, cmd, arg);
420 }
421
422 long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
423                           size_t len)
424 {
425         return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
426                                   buf, len);
427 }
428
429 asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
430                                 u32 lenhi, u32 lenlo)
431 {
432         return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
433                              ((loff_t)lenhi << 32) | lenlo);
434 }