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