]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/powerpc/kernel/sys_ppc32.c
powerpc: Use sys_pause for 32-bit pause entry point
[linux-2.6-omap-h63xx.git] / arch / powerpc / kernel / sys_ppc32.c
1 /*
2  * sys_ppc32.c: Conversion between 32bit and 64bit native syscalls.
3  *
4  * Copyright (C) 2001 IBM
5  * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6  * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
7  *
8  * These routines maintain argument size conversion between 32bit and 64bit
9  * environment.
10  *
11  *      This program is free software; you can redistribute it and/or
12  *      modify it under the terms of the GNU General Public License
13  *      as published by the Free Software Foundation; either version
14  *      2 of the License, or (at your option) any later version.
15  */
16
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/fs.h> 
20 #include <linux/mm.h> 
21 #include <linux/file.h> 
22 #include <linux/signal.h>
23 #include <linux/resource.h>
24 #include <linux/times.h>
25 #include <linux/utsname.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/poll.h>
32 #include <linux/personality.h>
33 #include <linux/stat.h>
34 #include <linux/mman.h>
35 #include <linux/in.h>
36 #include <linux/syscalls.h>
37 #include <linux/unistd.h>
38 #include <linux/sysctl.h>
39 #include <linux/binfmts.h>
40 #include <linux/security.h>
41 #include <linux/compat.h>
42 #include <linux/ptrace.h>
43 #include <linux/elf.h>
44 #include <linux/ipc.h>
45
46 #include <asm/ptrace.h>
47 #include <asm/types.h>
48 #include <asm/uaccess.h>
49 #include <asm/unistd.h>
50 #include <asm/time.h>
51 #include <asm/mmu_context.h>
52 #include <asm/ppc-pci.h>
53 #include <asm/syscalls.h>
54
55
56 asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp,
57                 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
58                 compat_uptr_t tvp_x)
59 {
60         /* sign extend n */
61         return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x));
62 }
63
64 int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
65 {
66         compat_ino_t ino;
67         long err;
68
69         if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
70             !new_valid_dev(stat->rdev))
71                 return -EOVERFLOW;
72
73         ino = stat->ino;
74         if (sizeof(ino) < sizeof(stat->ino) && ino != stat->ino)
75                 return -EOVERFLOW;
76
77         err  = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT;
78         err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
79         err |= __put_user(ino, &statbuf->st_ino);
80         err |= __put_user(stat->mode, &statbuf->st_mode);
81         err |= __put_user(stat->nlink, &statbuf->st_nlink);
82         err |= __put_user(stat->uid, &statbuf->st_uid);
83         err |= __put_user(stat->gid, &statbuf->st_gid);
84         err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
85         err |= __put_user(stat->size, &statbuf->st_size);
86         err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime);
87         err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
88         err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
89         err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
90         err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
91         err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
92         err |= __put_user(stat->blksize, &statbuf->st_blksize);
93         err |= __put_user(stat->blocks, &statbuf->st_blocks);
94         err |= __put_user(0, &statbuf->__unused4[0]);
95         err |= __put_user(0, &statbuf->__unused4[1]);
96
97         return err;
98 }
99
100 /* Note: it is necessary to treat option as an unsigned int,
101  * with the corresponding cast to a signed int to insure that the 
102  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
103  * and the register representation of a signed int (msr in 64-bit mode) is performed.
104  */
105 asmlinkage long compat_sys_sysfs(u32 option, u32 arg1, u32 arg2)
106 {
107         return sys_sysfs((int)option, arg1, arg2);
108 }
109
110 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
111 {
112         long usec;
113
114         if (!access_ok(VERIFY_READ, i, sizeof(*i)))
115                 return -EFAULT;
116         if (__get_user(o->tv_sec, &i->tv_sec))
117                 return -EFAULT;
118         if (__get_user(usec, &i->tv_usec))
119                 return -EFAULT;
120         o->tv_nsec = usec * 1000;
121         return 0;
122 }
123
124 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
125 {
126         return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
127                 (__put_user(i->tv_sec, &o->tv_sec) |
128                  __put_user(i->tv_usec, &o->tv_usec)));
129 }
130
131
132
133
134 /* Translations due to time_t size differences.  Which affects all
135    sorts of things, like timeval and itimerval.  */
136 extern struct timezone sys_tz;
137
138 asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
139 {
140         if (tv) {
141                 struct timeval ktv;
142                 do_gettimeofday(&ktv);
143                 if (put_tv32(tv, &ktv))
144                         return -EFAULT;
145         }
146         if (tz) {
147                 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
148                         return -EFAULT;
149         }
150         
151         return 0;
152 }
153
154
155
156 asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
157 {
158         struct timespec kts;
159         struct timezone ktz;
160         
161         if (tv) {
162                 if (get_ts32(&kts, tv))
163                         return -EFAULT;
164         }
165         if (tz) {
166                 if (copy_from_user(&ktz, tz, sizeof(ktz)))
167                         return -EFAULT;
168         }
169
170         return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
171 }
172
173 #ifdef CONFIG_SYSVIPC
174 long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
175                u32 fifth)
176 {
177         int version;
178
179         version = call >> 16; /* hack for backward compatibility */
180         call &= 0xffff;
181
182         switch (call) {
183
184         case SEMTIMEDOP:
185                 if (fifth)
186                         /* sign extend semid */
187                         return compat_sys_semtimedop((int)first,
188                                                      compat_ptr(ptr), second,
189                                                      compat_ptr(fifth));
190                 /* else fall through for normal semop() */
191         case SEMOP:
192                 /* struct sembuf is the same on 32 and 64bit :)) */
193                 /* sign extend semid */
194                 return sys_semtimedop((int)first, compat_ptr(ptr), second,
195                                       NULL);
196         case SEMGET:
197                 /* sign extend key, nsems */
198                 return sys_semget((int)first, (int)second, third);
199         case SEMCTL:
200                 /* sign extend semid, semnum */
201                 return compat_sys_semctl((int)first, (int)second, third,
202                                          compat_ptr(ptr));
203
204         case MSGSND:
205                 /* sign extend msqid */
206                 return compat_sys_msgsnd((int)first, (int)second, third,
207                                          compat_ptr(ptr));
208         case MSGRCV:
209                 /* sign extend msqid, msgtyp */
210                 return compat_sys_msgrcv((int)first, second, (int)fifth,
211                                          third, version, compat_ptr(ptr));
212         case MSGGET:
213                 /* sign extend key */
214                 return sys_msgget((int)first, second);
215         case MSGCTL:
216                 /* sign extend msqid */
217                 return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
218
219         case SHMAT:
220                 /* sign extend shmid */
221                 return compat_sys_shmat((int)first, second, third, version,
222                                         compat_ptr(ptr));
223         case SHMDT:
224                 return sys_shmdt(compat_ptr(ptr));
225         case SHMGET:
226                 /* sign extend key_t */
227                 return sys_shmget((int)first, second, third);
228         case SHMCTL:
229                 /* sign extend shmid */
230                 return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
231
232         default:
233                 return -ENOSYS;
234         }
235
236         return -ENOSYS;
237 }
238 #endif
239
240 /* Note: it is necessary to treat out_fd and in_fd as unsigned ints, 
241  * with the corresponding cast to a signed int to insure that the 
242  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
243  * and the register representation of a signed int (msr in 64-bit mode) is performed.
244  */
245 asmlinkage long compat_sys_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count)
246 {
247         mm_segment_t old_fs = get_fs();
248         int ret;
249         off_t of;
250         off_t __user *up;
251
252         if (offset && get_user(of, offset))
253                 return -EFAULT;
254
255         /* The __user pointer cast is valid because of the set_fs() */          
256         set_fs(KERNEL_DS);
257         up = offset ? (off_t __user *) &of : NULL;
258         ret = sys_sendfile((int)out_fd, (int)in_fd, up, count);
259         set_fs(old_fs);
260         
261         if (offset && put_user(of, offset))
262                 return -EFAULT;
263                 
264         return ret;
265 }
266
267 asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
268 {
269         mm_segment_t old_fs = get_fs();
270         int ret;
271         loff_t lof;
272         loff_t __user *up;
273         
274         if (offset && get_user(lof, offset))
275                 return -EFAULT;
276                 
277         /* The __user pointer cast is valid because of the set_fs() */          
278         set_fs(KERNEL_DS);
279         up = offset ? (loff_t __user *) &lof : NULL;
280         ret = sys_sendfile64(out_fd, in_fd, up, count);
281         set_fs(old_fs);
282         
283         if (offset && put_user(lof, offset))
284                 return -EFAULT;
285                 
286         return ret;
287 }
288
289 long compat_sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,
290                   unsigned long a3, unsigned long a4, unsigned long a5,
291                   struct pt_regs *regs)
292 {
293         int error;
294         char * filename;
295         
296         filename = getname((char __user *) a0);
297         error = PTR_ERR(filename);
298         if (IS_ERR(filename))
299                 goto out;
300         flush_fp_to_thread(current);
301         flush_altivec_to_thread(current);
302
303         error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs);
304
305         putname(filename);
306
307 out:
308         return error;
309 }
310
311 /* Note: it is necessary to treat option as an unsigned int, 
312  * with the corresponding cast to a signed int to insure that the 
313  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
314  * and the register representation of a signed int (msr in 64-bit mode) is performed.
315  */
316 asmlinkage long compat_sys_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
317 {
318         return sys_prctl((int)option,
319                          (unsigned long) arg2,
320                          (unsigned long) arg3,
321                          (unsigned long) arg4,
322                          (unsigned long) arg5);
323 }
324
325 /* Note: it is necessary to treat pid as an unsigned int, 
326  * with the corresponding cast to a signed int to insure that the 
327  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
328  * and the register representation of a signed int (msr in 64-bit mode) is performed.
329  */
330 asmlinkage long compat_sys_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
331 {
332         struct timespec t;
333         int ret;
334         mm_segment_t old_fs = get_fs ();
335
336         /* The __user pointer cast is valid because of the set_fs() */
337         set_fs (KERNEL_DS);
338         ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
339         set_fs (old_fs);
340         if (put_compat_timespec(&t, interval))
341                 return -EFAULT;
342         return ret;
343 }
344
345 /* Note: it is necessary to treat mode as an unsigned int,
346  * with the corresponding cast to a signed int to insure that the 
347  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
348  * and the register representation of a signed int (msr in 64-bit mode) is performed.
349  */
350 asmlinkage long compat_sys_access(const char __user * filename, u32 mode)
351 {
352         return sys_access(filename, (int)mode);
353 }
354
355
356 /* Note: it is necessary to treat mode as an unsigned int,
357  * with the corresponding cast to a signed int to insure that the 
358  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
359  * and the register representation of a signed int (msr in 64-bit mode) is performed.
360  */
361 asmlinkage long compat_sys_creat(const char __user * pathname, u32 mode)
362 {
363         return sys_creat(pathname, (int)mode);
364 }
365
366
367 /* Note: it is necessary to treat pid and options as unsigned ints,
368  * with the corresponding cast to a signed int to insure that the 
369  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
370  * and the register representation of a signed int (msr in 64-bit mode) is performed.
371  */
372 asmlinkage long compat_sys_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
373 {
374         return sys_waitpid((int)pid, stat_addr, (int)options);
375 }
376
377
378 /* Note: it is necessary to treat gidsetsize as an unsigned int,
379  * with the corresponding cast to a signed int to insure that the 
380  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
381  * and the register representation of a signed int (msr in 64-bit mode) is performed.
382  */
383 asmlinkage long compat_sys_getgroups(u32 gidsetsize, gid_t __user *grouplist)
384 {
385         return sys_getgroups((int)gidsetsize, grouplist);
386 }
387
388
389 /* Note: it is necessary to treat pid as an unsigned int,
390  * with the corresponding cast to a signed int to insure that the 
391  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
392  * and the register representation of a signed int (msr in 64-bit mode) is performed.
393  */
394 asmlinkage long compat_sys_getpgid(u32 pid)
395 {
396         return sys_getpgid((int)pid);
397 }
398
399
400
401 /* Note: it is necessary to treat pid as an unsigned int,
402  * with the corresponding cast to a signed int to insure that the 
403  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
404  * and the register representation of a signed int (msr in 64-bit mode) is performed.
405  */
406 asmlinkage long compat_sys_getsid(u32 pid)
407 {
408         return sys_getsid((int)pid);
409 }
410
411
412 /* Note: it is necessary to treat pid and sig as unsigned ints,
413  * with the corresponding cast to a signed int to insure that the 
414  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
415  * and the register representation of a signed int (msr in 64-bit mode) is performed.
416  */
417 asmlinkage long compat_sys_kill(u32 pid, u32 sig)
418 {
419         return sys_kill((int)pid, (int)sig);
420 }
421
422
423 /* Note: it is necessary to treat mode as an unsigned int,
424  * with the corresponding cast to a signed int to insure that the 
425  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
426  * and the register representation of a signed int (msr in 64-bit mode) is performed.
427  */
428 asmlinkage long compat_sys_mkdir(const char __user * pathname, u32 mode)
429 {
430         return sys_mkdir(pathname, (int)mode);
431 }
432
433 long compat_sys_nice(u32 increment)
434 {
435         /* sign extend increment */
436         return sys_nice((int)increment);
437 }
438
439 off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
440 {
441         /* sign extend n */
442         return sys_lseek(fd, (int)offset, origin);
443 }
444
445 /* Note: it is necessary to treat bufsiz as an unsigned int,
446  * with the corresponding cast to a signed int to insure that the 
447  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
448  * and the register representation of a signed int (msr in 64-bit mode) is performed.
449  */
450 asmlinkage long compat_sys_readlink(const char __user * path, char __user * buf, u32 bufsiz)
451 {
452         return sys_readlink(path, buf, (int)bufsiz);
453 }
454
455 /* Note: it is necessary to treat option as an unsigned int,
456  * with the corresponding cast to a signed int to insure that the 
457  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
458  * and the register representation of a signed int (msr in 64-bit mode) is performed.
459  */
460 asmlinkage long compat_sys_sched_get_priority_max(u32 policy)
461 {
462         return sys_sched_get_priority_max((int)policy);
463 }
464
465
466 /* Note: it is necessary to treat policy as an unsigned int,
467  * with the corresponding cast to a signed int to insure that the 
468  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
469  * and the register representation of a signed int (msr in 64-bit mode) is performed.
470  */
471 asmlinkage long compat_sys_sched_get_priority_min(u32 policy)
472 {
473         return sys_sched_get_priority_min((int)policy);
474 }
475
476
477 /* Note: it is necessary to treat pid as an unsigned int,
478  * with the corresponding cast to a signed int to insure that the 
479  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
480  * and the register representation of a signed int (msr in 64-bit mode) is performed.
481  */
482 asmlinkage long compat_sys_sched_getparam(u32 pid, struct sched_param __user *param)
483 {
484         return sys_sched_getparam((int)pid, param);
485 }
486
487
488 /* Note: it is necessary to treat pid as an unsigned int,
489  * with the corresponding cast to a signed int to insure that the 
490  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
491  * and the register representation of a signed int (msr in 64-bit mode) is performed.
492  */
493 asmlinkage long compat_sys_sched_getscheduler(u32 pid)
494 {
495         return sys_sched_getscheduler((int)pid);
496 }
497
498
499 /* Note: it is necessary to treat pid as an unsigned int,
500  * with the corresponding cast to a signed int to insure that the 
501  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
502  * and the register representation of a signed int (msr in 64-bit mode) is performed.
503  */
504 asmlinkage long compat_sys_sched_setparam(u32 pid, struct sched_param __user *param)
505 {
506         return sys_sched_setparam((int)pid, param);
507 }
508
509
510 /* Note: it is necessary to treat pid and policy as unsigned ints,
511  * with the corresponding cast to a signed int to insure that the 
512  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
513  * and the register representation of a signed int (msr in 64-bit mode) is performed.
514  */
515 asmlinkage long compat_sys_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
516 {
517         return sys_sched_setscheduler((int)pid, (int)policy, param);
518 }
519
520
521 /* Note: it is necessary to treat len as an unsigned int,
522  * with the corresponding cast to a signed int to insure that the 
523  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
524  * and the register representation of a signed int (msr in 64-bit mode) is performed.
525  */
526 asmlinkage long compat_sys_setdomainname(char __user *name, u32 len)
527 {
528         return sys_setdomainname(name, (int)len);
529 }
530
531
532 /* Note: it is necessary to treat gidsetsize as an unsigned int,
533  * with the corresponding cast to a signed int to insure that the 
534  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
535  * and the register representation of a signed int (msr in 64-bit mode) is performed.
536  */
537 asmlinkage long compat_sys_setgroups(u32 gidsetsize, gid_t __user *grouplist)
538 {
539         return sys_setgroups((int)gidsetsize, grouplist);
540 }
541
542
543 asmlinkage long compat_sys_sethostname(char __user *name, u32 len)
544 {
545         /* sign extend len */
546         return sys_sethostname(name, (int)len);
547 }
548
549
550 /* Note: it is necessary to treat pid and pgid as unsigned ints,
551  * with the corresponding cast to a signed int to insure that the 
552  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
553  * and the register representation of a signed int (msr in 64-bit mode) is performed.
554  */
555 asmlinkage long compat_sys_setpgid(u32 pid, u32 pgid)
556 {
557         return sys_setpgid((int)pid, (int)pgid);
558 }
559
560 long compat_sys_getpriority(u32 which, u32 who)
561 {
562         /* sign extend which and who */
563         return sys_getpriority((int)which, (int)who);
564 }
565
566 long compat_sys_setpriority(u32 which, u32 who, u32 niceval)
567 {
568         /* sign extend which, who and niceval */
569         return sys_setpriority((int)which, (int)who, (int)niceval);
570 }
571
572 long compat_sys_ioprio_get(u32 which, u32 who)
573 {
574         /* sign extend which and who */
575         return sys_ioprio_get((int)which, (int)who);
576 }
577
578 long compat_sys_ioprio_set(u32 which, u32 who, u32 ioprio)
579 {
580         /* sign extend which, who and ioprio */
581         return sys_ioprio_set((int)which, (int)who, (int)ioprio);
582 }
583
584 /* Note: it is necessary to treat newmask as an unsigned int,
585  * with the corresponding cast to a signed int to insure that the 
586  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
587  * and the register representation of a signed int (msr in 64-bit mode) is performed.
588  */
589 asmlinkage long compat_sys_ssetmask(u32 newmask)
590 {
591         return sys_ssetmask((int) newmask);
592 }
593
594 asmlinkage long compat_sys_syslog(u32 type, char __user * buf, u32 len)
595 {
596         /* sign extend len */
597         return sys_syslog(type, buf, (int)len);
598 }
599
600
601 /* Note: it is necessary to treat mask as an unsigned int,
602  * with the corresponding cast to a signed int to insure that the 
603  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
604  * and the register representation of a signed int (msr in 64-bit mode) is performed.
605  */
606 asmlinkage long compat_sys_umask(u32 mask)
607 {
608         return sys_umask((int)mask);
609 }
610
611 #ifdef CONFIG_SYSCTL_SYSCALL
612 struct __sysctl_args32 {
613         u32 name;
614         int nlen;
615         u32 oldval;
616         u32 oldlenp;
617         u32 newval;
618         u32 newlen;
619         u32 __unused[4];
620 };
621
622 asmlinkage long compat_sys_sysctl(struct __sysctl_args32 __user *args)
623 {
624         struct __sysctl_args32 tmp;
625         int error;
626         size_t oldlen;
627         size_t __user *oldlenp = NULL;
628         unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
629
630         if (copy_from_user(&tmp, args, sizeof(tmp)))
631                 return -EFAULT;
632
633         if (tmp.oldval && tmp.oldlenp) {
634                 /* Duh, this is ugly and might not work if sysctl_args
635                    is in read-only memory, but do_sysctl does indirectly
636                    a lot of uaccess in both directions and we'd have to
637                    basically copy the whole sysctl.c here, and
638                    glibc's __sysctl uses rw memory for the structure
639                    anyway.  */
640                 oldlenp = (size_t __user *)addr;
641                 if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
642                     put_user(oldlen, oldlenp))
643                         return -EFAULT;
644         }
645
646         lock_kernel();
647         error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
648                           compat_ptr(tmp.oldval), oldlenp,
649                           compat_ptr(tmp.newval), tmp.newlen);
650         unlock_kernel();
651         if (oldlenp) {
652                 if (!error) {
653                         if (get_user(oldlen, oldlenp) ||
654                             put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
655                                 error = -EFAULT;
656                 }
657                 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
658         }
659         return error;
660 }
661 #endif
662
663 unsigned long compat_sys_mmap2(unsigned long addr, size_t len,
664                           unsigned long prot, unsigned long flags,
665                           unsigned long fd, unsigned long pgoff)
666 {
667         /* This should remain 12 even if PAGE_SIZE changes */
668         return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
669 }
670
671 long compat_sys_tgkill(u32 tgid, u32 pid, int sig)
672 {
673         /* sign extend tgid, pid */
674         return sys_tgkill((int)tgid, (int)pid, sig);
675 }
676
677 /* 
678  * long long munging:
679  * The 32 bit ABI passes long longs in an odd even register pair.
680  */
681
682 compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
683                              u32 reg6, u32 poshi, u32 poslo)
684 {
685         return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
686 }
687
688 compat_ssize_t compat_sys_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
689                               u32 reg6, u32 poshi, u32 poslo)
690 {
691         return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
692 }
693
694 compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
695 {
696         return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
697 }
698
699 asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4,
700                                 unsigned long high, unsigned long low)
701 {
702         return sys_truncate(path, (high << 32) | low);
703 }
704
705 asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
706                                      u32 lenhi, u32 lenlo)
707 {
708         return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
709                              ((loff_t)lenhi << 32) | lenlo);
710 }
711
712 asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
713                                  unsigned long low)
714 {
715         return sys_ftruncate(fd, (high << 32) | low);
716 }
717
718 long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
719                           size_t len)
720 {
721         return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
722                                   buf, len);
723 }
724
725 long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
726                      size_t len, int advice)
727 {
728         return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
729                              advice);
730 }
731
732 asmlinkage long compat_sys_add_key(const char __user *_type,
733                               const char __user *_description,
734                               const void __user *_payload,
735                               u32 plen,
736                               u32 ringid)
737 {
738         return sys_add_key(_type, _description, _payload, plen, ringid);
739 }
740
741 asmlinkage long compat_sys_request_key(const char __user *_type,
742                                   const char __user *_description,
743                                   const char __user *_callout_info,
744                                   u32 destringid)
745 {
746         return sys_request_key(_type, _description, _callout_info, destringid);
747 }
748
749 asmlinkage long compat_sys_sync_file_range2(int fd, unsigned int flags,
750                                    unsigned offset_hi, unsigned offset_lo,
751                                    unsigned nbytes_hi, unsigned nbytes_lo)
752 {
753         loff_t offset = ((loff_t)offset_hi << 32) | offset_lo;
754         loff_t nbytes = ((loff_t)nbytes_hi << 32) | nbytes_lo;
755
756         return sys_sync_file_range(fd, offset, nbytes, flags);
757 }