Merge with http://kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
[sfrench/cifs-2.6.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/config.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/fs.h> 
21 #include <linux/mm.h> 
22 #include <linux/file.h> 
23 #include <linux/signal.h>
24 #include <linux/resource.h>
25 #include <linux/times.h>
26 #include <linux/utsname.h>
27 #include <linux/timex.h>
28 #include <linux/smp.h>
29 #include <linux/smp_lock.h>
30 #include <linux/sem.h>
31 #include <linux/msg.h>
32 #include <linux/shm.h>
33 #include <linux/poll.h>
34 #include <linux/personality.h>
35 #include <linux/stat.h>
36 #include <linux/mman.h>
37 #include <linux/in.h>
38 #include <linux/syscalls.h>
39 #include <linux/unistd.h>
40 #include <linux/sysctl.h>
41 #include <linux/binfmts.h>
42 #include <linux/security.h>
43 #include <linux/compat.h>
44 #include <linux/ptrace.h>
45 #include <linux/elf.h>
46
47 #include <asm/ptrace.h>
48 #include <asm/types.h>
49 #include <asm/ipc.h>
50 #include <asm/uaccess.h>
51 #include <asm/unistd.h>
52 #include <asm/semaphore.h>
53 #include <asm/time.h>
54 #include <asm/mmu_context.h>
55 #include <asm/ppc-pci.h>
56
57 /* readdir & getdents */
58 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
59 #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
60
61 struct old_linux_dirent32 {
62         u32             d_ino;
63         u32             d_offset;
64         unsigned short  d_namlen;
65         char            d_name[1];
66 };
67
68 struct readdir_callback32 {
69         struct old_linux_dirent32 __user * dirent;
70         int count;
71 };
72
73 static int fillonedir(void * __buf, const char * name, int namlen,
74                                   off_t offset, ino_t ino, unsigned int d_type)
75 {
76         struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf;
77         struct old_linux_dirent32 __user * dirent;
78
79         if (buf->count)
80                 return -EINVAL;
81         buf->count++;
82         dirent = buf->dirent;
83         put_user(ino, &dirent->d_ino);
84         put_user(offset, &dirent->d_offset);
85         put_user(namlen, &dirent->d_namlen);
86         copy_to_user(dirent->d_name, name, namlen);
87         put_user(0, dirent->d_name + namlen);
88         return 0;
89 }
90
91 asmlinkage int old32_readdir(unsigned int fd, struct old_linux_dirent32 __user *dirent, unsigned int count)
92 {
93         int error = -EBADF;
94         struct file * file;
95         struct readdir_callback32 buf;
96
97         file = fget(fd);
98         if (!file)
99                 goto out;
100
101         buf.count = 0;
102         buf.dirent = dirent;
103
104         error = vfs_readdir(file, (filldir_t)fillonedir, &buf);
105         if (error < 0)
106                 goto out_putf;
107         error = buf.count;
108
109 out_putf:
110         fput(file);
111 out:
112         return error;
113 }
114
115 asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp,
116                 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
117                 compat_uptr_t tvp_x)
118 {
119         /* sign extend n */
120         return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x));
121 }
122
123 int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
124 {
125         long err;
126
127         if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
128             !new_valid_dev(stat->rdev))
129                 return -EOVERFLOW;
130
131         err  = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT;
132         err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
133         err |= __put_user(stat->ino, &statbuf->st_ino);
134         err |= __put_user(stat->mode, &statbuf->st_mode);
135         err |= __put_user(stat->nlink, &statbuf->st_nlink);
136         err |= __put_user(stat->uid, &statbuf->st_uid);
137         err |= __put_user(stat->gid, &statbuf->st_gid);
138         err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
139         err |= __put_user(stat->size, &statbuf->st_size);
140         err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime);
141         err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
142         err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
143         err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
144         err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
145         err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
146         err |= __put_user(stat->blksize, &statbuf->st_blksize);
147         err |= __put_user(stat->blocks, &statbuf->st_blocks);
148         err |= __put_user(0, &statbuf->__unused4[0]);
149         err |= __put_user(0, &statbuf->__unused4[1]);
150
151         return err;
152 }
153
154 /* Note: it is necessary to treat option as an unsigned int,
155  * with the corresponding cast to a signed int to insure that the 
156  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
157  * and the register representation of a signed int (msr in 64-bit mode) is performed.
158  */
159 asmlinkage long compat_sys_sysfs(u32 option, u32 arg1, u32 arg2)
160 {
161         return sys_sysfs((int)option, arg1, arg2);
162 }
163
164 /* Handle adjtimex compatibility. */
165 struct timex32 {
166         u32 modes;
167         s32 offset, freq, maxerror, esterror;
168         s32 status, constant, precision, tolerance;
169         struct compat_timeval time;
170         s32 tick;
171         s32 ppsfreq, jitter, shift, stabil;
172         s32 jitcnt, calcnt, errcnt, stbcnt;
173         s32  :32; s32  :32; s32  :32; s32  :32;
174         s32  :32; s32  :32; s32  :32; s32  :32;
175         s32  :32; s32  :32; s32  :32; s32  :32;
176 };
177
178 extern int do_adjtimex(struct timex *);
179 extern void ppc_adjtimex(void);
180
181 asmlinkage long compat_sys_adjtimex(struct timex32 __user *utp)
182 {
183         struct timex txc;
184         int ret;
185         
186         memset(&txc, 0, sizeof(struct timex));
187
188         if(get_user(txc.modes, &utp->modes) ||
189            __get_user(txc.offset, &utp->offset) ||
190            __get_user(txc.freq, &utp->freq) ||
191            __get_user(txc.maxerror, &utp->maxerror) ||
192            __get_user(txc.esterror, &utp->esterror) ||
193            __get_user(txc.status, &utp->status) ||
194            __get_user(txc.constant, &utp->constant) ||
195            __get_user(txc.precision, &utp->precision) ||
196            __get_user(txc.tolerance, &utp->tolerance) ||
197            __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
198            __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
199            __get_user(txc.tick, &utp->tick) ||
200            __get_user(txc.ppsfreq, &utp->ppsfreq) ||
201            __get_user(txc.jitter, &utp->jitter) ||
202            __get_user(txc.shift, &utp->shift) ||
203            __get_user(txc.stabil, &utp->stabil) ||
204            __get_user(txc.jitcnt, &utp->jitcnt) ||
205            __get_user(txc.calcnt, &utp->calcnt) ||
206            __get_user(txc.errcnt, &utp->errcnt) ||
207            __get_user(txc.stbcnt, &utp->stbcnt))
208                 return -EFAULT;
209
210         ret = do_adjtimex(&txc);
211
212         /* adjust the conversion of TB to time of day to track adjtimex */
213         ppc_adjtimex();
214
215         if(put_user(txc.modes, &utp->modes) ||
216            __put_user(txc.offset, &utp->offset) ||
217            __put_user(txc.freq, &utp->freq) ||
218            __put_user(txc.maxerror, &utp->maxerror) ||
219            __put_user(txc.esterror, &utp->esterror) ||
220            __put_user(txc.status, &utp->status) ||
221            __put_user(txc.constant, &utp->constant) ||
222            __put_user(txc.precision, &utp->precision) ||
223            __put_user(txc.tolerance, &utp->tolerance) ||
224            __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
225            __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
226            __put_user(txc.tick, &utp->tick) ||
227            __put_user(txc.ppsfreq, &utp->ppsfreq) ||
228            __put_user(txc.jitter, &utp->jitter) ||
229            __put_user(txc.shift, &utp->shift) ||
230            __put_user(txc.stabil, &utp->stabil) ||
231            __put_user(txc.jitcnt, &utp->jitcnt) ||
232            __put_user(txc.calcnt, &utp->calcnt) ||
233            __put_user(txc.errcnt, &utp->errcnt) ||
234            __put_user(txc.stbcnt, &utp->stbcnt))
235                 ret = -EFAULT;
236
237         return ret;
238 }
239
240 asmlinkage long compat_sys_pause(void)
241 {
242         current->state = TASK_INTERRUPTIBLE;
243         schedule();
244         
245         return -ERESTARTNOHAND;
246 }
247
248 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
249 {
250         long usec;
251
252         if (!access_ok(VERIFY_READ, i, sizeof(*i)))
253                 return -EFAULT;
254         if (__get_user(o->tv_sec, &i->tv_sec))
255                 return -EFAULT;
256         if (__get_user(usec, &i->tv_usec))
257                 return -EFAULT;
258         o->tv_nsec = usec * 1000;
259         return 0;
260 }
261
262 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
263 {
264         return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
265                 (__put_user(i->tv_sec, &o->tv_sec) |
266                  __put_user(i->tv_usec, &o->tv_usec)));
267 }
268
269 struct sysinfo32 {
270         s32 uptime;
271         u32 loads[3];
272         u32 totalram;
273         u32 freeram;
274         u32 sharedram;
275         u32 bufferram;
276         u32 totalswap;
277         u32 freeswap;
278         unsigned short procs;
279         unsigned short pad;
280         u32 totalhigh;
281         u32 freehigh;
282         u32 mem_unit;
283         char _f[20-2*sizeof(int)-sizeof(int)];
284 };
285
286 asmlinkage long compat_sys_sysinfo(struct sysinfo32 __user *info)
287 {
288         struct sysinfo s;
289         int ret, err;
290         int bitcount=0;
291         mm_segment_t old_fs = get_fs ();
292         
293         /* The __user cast is valid due to set_fs() */
294         set_fs (KERNEL_DS);
295         ret = sys_sysinfo((struct sysinfo __user *)&s);
296         set_fs (old_fs);
297
298         /* Check to see if any memory value is too large for 32-bit and
299          * scale down if needed.
300          */
301         if ((s.totalram >> 32) || (s.totalswap >> 32)) {
302             while (s.mem_unit < PAGE_SIZE) {
303                 s.mem_unit <<= 1;
304                 bitcount++;
305             }
306             s.totalram >>=bitcount;
307             s.freeram >>= bitcount;
308             s.sharedram >>= bitcount;
309             s.bufferram >>= bitcount;
310             s.totalswap >>= bitcount;
311             s.freeswap >>= bitcount;
312             s.totalhigh >>= bitcount;
313             s.freehigh >>= bitcount;
314         }
315
316         err = put_user (s.uptime, &info->uptime);
317         err |= __put_user (s.loads[0], &info->loads[0]);
318         err |= __put_user (s.loads[1], &info->loads[1]);
319         err |= __put_user (s.loads[2], &info->loads[2]);
320         err |= __put_user (s.totalram, &info->totalram);
321         err |= __put_user (s.freeram, &info->freeram);
322         err |= __put_user (s.sharedram, &info->sharedram);
323         err |= __put_user (s.bufferram, &info->bufferram);
324         err |= __put_user (s.totalswap, &info->totalswap);
325         err |= __put_user (s.freeswap, &info->freeswap);
326         err |= __put_user (s.procs, &info->procs);
327         err |= __put_user (s.totalhigh, &info->totalhigh);
328         err |= __put_user (s.freehigh, &info->freehigh);
329         err |= __put_user (s.mem_unit, &info->mem_unit);
330         if (err)
331                 return -EFAULT;
332         
333         return ret;
334 }
335
336
337
338
339 /* Translations due to time_t size differences.  Which affects all
340    sorts of things, like timeval and itimerval.  */
341 extern struct timezone sys_tz;
342
343 asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
344 {
345         if (tv) {
346                 struct timeval ktv;
347                 do_gettimeofday(&ktv);
348                 if (put_tv32(tv, &ktv))
349                         return -EFAULT;
350         }
351         if (tz) {
352                 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
353                         return -EFAULT;
354         }
355         
356         return 0;
357 }
358
359
360
361 asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
362 {
363         struct timespec kts;
364         struct timezone ktz;
365         
366         if (tv) {
367                 if (get_ts32(&kts, tv))
368                         return -EFAULT;
369         }
370         if (tz) {
371                 if (copy_from_user(&ktz, tz, sizeof(ktz)))
372                         return -EFAULT;
373         }
374
375         return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
376 }
377
378 #ifdef CONFIG_SYSVIPC
379 long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
380                u32 fifth)
381 {
382         int version;
383
384         version = call >> 16; /* hack for backward compatibility */
385         call &= 0xffff;
386
387         switch (call) {
388
389         case SEMTIMEDOP:
390                 if (fifth)
391                         /* sign extend semid */
392                         return compat_sys_semtimedop((int)first,
393                                                      compat_ptr(ptr), second,
394                                                      compat_ptr(fifth));
395                 /* else fall through for normal semop() */
396         case SEMOP:
397                 /* struct sembuf is the same on 32 and 64bit :)) */
398                 /* sign extend semid */
399                 return sys_semtimedop((int)first, compat_ptr(ptr), second,
400                                       NULL);
401         case SEMGET:
402                 /* sign extend key, nsems */
403                 return sys_semget((int)first, (int)second, third);
404         case SEMCTL:
405                 /* sign extend semid, semnum */
406                 return compat_sys_semctl((int)first, (int)second, third,
407                                          compat_ptr(ptr));
408
409         case MSGSND:
410                 /* sign extend msqid */
411                 return compat_sys_msgsnd((int)first, (int)second, third,
412                                          compat_ptr(ptr));
413         case MSGRCV:
414                 /* sign extend msqid, msgtyp */
415                 return compat_sys_msgrcv((int)first, second, (int)fifth,
416                                          third, version, compat_ptr(ptr));
417         case MSGGET:
418                 /* sign extend key */
419                 return sys_msgget((int)first, second);
420         case MSGCTL:
421                 /* sign extend msqid */
422                 return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
423
424         case SHMAT:
425                 /* sign extend shmid */
426                 return compat_sys_shmat((int)first, second, third, version,
427                                         compat_ptr(ptr));
428         case SHMDT:
429                 return sys_shmdt(compat_ptr(ptr));
430         case SHMGET:
431                 /* sign extend key_t */
432                 return sys_shmget((int)first, second, third);
433         case SHMCTL:
434                 /* sign extend shmid */
435                 return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
436
437         default:
438                 return -ENOSYS;
439         }
440
441         return -ENOSYS;
442 }
443 #endif
444
445 /* Note: it is necessary to treat out_fd and in_fd as unsigned ints, 
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_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count)
451 {
452         mm_segment_t old_fs = get_fs();
453         int ret;
454         off_t of;
455         off_t __user *up;
456
457         if (offset && get_user(of, offset))
458                 return -EFAULT;
459
460         /* The __user pointer cast is valid because of the set_fs() */          
461         set_fs(KERNEL_DS);
462         up = offset ? (off_t __user *) &of : NULL;
463         ret = sys_sendfile((int)out_fd, (int)in_fd, up, count);
464         set_fs(old_fs);
465         
466         if (offset && put_user(of, offset))
467                 return -EFAULT;
468                 
469         return ret;
470 }
471
472 asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
473 {
474         mm_segment_t old_fs = get_fs();
475         int ret;
476         loff_t lof;
477         loff_t __user *up;
478         
479         if (offset && get_user(lof, offset))
480                 return -EFAULT;
481                 
482         /* The __user pointer cast is valid because of the set_fs() */          
483         set_fs(KERNEL_DS);
484         up = offset ? (loff_t __user *) &lof : NULL;
485         ret = sys_sendfile64(out_fd, in_fd, up, count);
486         set_fs(old_fs);
487         
488         if (offset && put_user(lof, offset))
489                 return -EFAULT;
490                 
491         return ret;
492 }
493
494 long compat_sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,
495                   unsigned long a3, unsigned long a4, unsigned long a5,
496                   struct pt_regs *regs)
497 {
498         int error;
499         char * filename;
500         
501         filename = getname((char __user *) a0);
502         error = PTR_ERR(filename);
503         if (IS_ERR(filename))
504                 goto out;
505         flush_fp_to_thread(current);
506         flush_altivec_to_thread(current);
507
508         error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs);
509
510         if (error == 0) {
511                 task_lock(current);
512                 current->ptrace &= ~PT_DTRACE;
513                 task_unlock(current);
514         }
515         putname(filename);
516
517 out:
518         return error;
519 }
520
521 /* Note: it is necessary to treat option 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_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
527 {
528         return sys_prctl((int)option,
529                          (unsigned long) arg2,
530                          (unsigned long) arg3,
531                          (unsigned long) arg4,
532                          (unsigned long) arg5);
533 }
534
535 /* Note: it is necessary to treat pid as an unsigned int, 
536  * with the corresponding cast to a signed int to insure that the 
537  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
538  * and the register representation of a signed int (msr in 64-bit mode) is performed.
539  */
540 asmlinkage long compat_sys_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
541 {
542         struct timespec t;
543         int ret;
544         mm_segment_t old_fs = get_fs ();
545
546         /* The __user pointer cast is valid because of the set_fs() */
547         set_fs (KERNEL_DS);
548         ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
549         set_fs (old_fs);
550         if (put_compat_timespec(&t, interval))
551                 return -EFAULT;
552         return ret;
553 }
554
555 asmlinkage int compat_sys_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
556 {
557         return sys_pciconfig_read((unsigned long) bus,
558                                   (unsigned long) dfn,
559                                   (unsigned long) off,
560                                   (unsigned long) len,
561                                   compat_ptr(ubuf));
562 }
563
564 asmlinkage int compat_sys_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
565 {
566         return sys_pciconfig_write((unsigned long) bus,
567                                    (unsigned long) dfn,
568                                    (unsigned long) off,
569                                    (unsigned long) len,
570                                    compat_ptr(ubuf));
571 }
572
573 asmlinkage int compat_sys_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)
574 {
575         return sys_pciconfig_iobase(which, in_bus, in_devfn);
576 }
577
578
579 /* Note: it is necessary to treat mode as an unsigned int,
580  * with the corresponding cast to a signed int to insure that the 
581  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
582  * and the register representation of a signed int (msr in 64-bit mode) is performed.
583  */
584 asmlinkage long compat_sys_access(const char __user * filename, u32 mode)
585 {
586         return sys_access(filename, (int)mode);
587 }
588
589
590 /* Note: it is necessary to treat mode as an unsigned int,
591  * with the corresponding cast to a signed int to insure that the 
592  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
593  * and the register representation of a signed int (msr in 64-bit mode) is performed.
594  */
595 asmlinkage long compat_sys_creat(const char __user * pathname, u32 mode)
596 {
597         return sys_creat(pathname, (int)mode);
598 }
599
600
601 /* Note: it is necessary to treat pid and options as unsigned ints,
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_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
607 {
608         return sys_waitpid((int)pid, stat_addr, (int)options);
609 }
610
611
612 /* Note: it is necessary to treat gidsetsize as an unsigned int,
613  * with the corresponding cast to a signed int to insure that the 
614  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
615  * and the register representation of a signed int (msr in 64-bit mode) is performed.
616  */
617 asmlinkage long compat_sys_getgroups(u32 gidsetsize, gid_t __user *grouplist)
618 {
619         return sys_getgroups((int)gidsetsize, grouplist);
620 }
621
622
623 /* Note: it is necessary to treat pid as an unsigned int,
624  * with the corresponding cast to a signed int to insure that the 
625  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
626  * and the register representation of a signed int (msr in 64-bit mode) is performed.
627  */
628 asmlinkage long compat_sys_getpgid(u32 pid)
629 {
630         return sys_getpgid((int)pid);
631 }
632
633
634
635 /* Note: it is necessary to treat pid as an unsigned int,
636  * with the corresponding cast to a signed int to insure that the 
637  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
638  * and the register representation of a signed int (msr in 64-bit mode) is performed.
639  */
640 asmlinkage long compat_sys_getsid(u32 pid)
641 {
642         return sys_getsid((int)pid);
643 }
644
645
646 /* Note: it is necessary to treat pid and sig as unsigned ints,
647  * with the corresponding cast to a signed int to insure that the 
648  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
649  * and the register representation of a signed int (msr in 64-bit mode) is performed.
650  */
651 asmlinkage long compat_sys_kill(u32 pid, u32 sig)
652 {
653         return sys_kill((int)pid, (int)sig);
654 }
655
656
657 /* Note: it is necessary to treat mode as an unsigned int,
658  * with the corresponding cast to a signed int to insure that the 
659  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
660  * and the register representation of a signed int (msr in 64-bit mode) is performed.
661  */
662 asmlinkage long compat_sys_mkdir(const char __user * pathname, u32 mode)
663 {
664         return sys_mkdir(pathname, (int)mode);
665 }
666
667 long compat_sys_nice(u32 increment)
668 {
669         /* sign extend increment */
670         return sys_nice((int)increment);
671 }
672
673 off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
674 {
675         /* sign extend n */
676         return sys_lseek(fd, (int)offset, origin);
677 }
678
679 /* Note: it is necessary to treat bufsiz as an unsigned int,
680  * with the corresponding cast to a signed int to insure that the 
681  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
682  * and the register representation of a signed int (msr in 64-bit mode) is performed.
683  */
684 asmlinkage long compat_sys_readlink(const char __user * path, char __user * buf, u32 bufsiz)
685 {
686         return sys_readlink(path, buf, (int)bufsiz);
687 }
688
689 /* Note: it is necessary to treat option as an unsigned int,
690  * with the corresponding cast to a signed int to insure that the 
691  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
692  * and the register representation of a signed int (msr in 64-bit mode) is performed.
693  */
694 asmlinkage long compat_sys_sched_get_priority_max(u32 policy)
695 {
696         return sys_sched_get_priority_max((int)policy);
697 }
698
699
700 /* Note: it is necessary to treat policy as an unsigned int,
701  * with the corresponding cast to a signed int to insure that the 
702  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
703  * and the register representation of a signed int (msr in 64-bit mode) is performed.
704  */
705 asmlinkage long compat_sys_sched_get_priority_min(u32 policy)
706 {
707         return sys_sched_get_priority_min((int)policy);
708 }
709
710
711 /* Note: it is necessary to treat pid as an unsigned int,
712  * with the corresponding cast to a signed int to insure that the 
713  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
714  * and the register representation of a signed int (msr in 64-bit mode) is performed.
715  */
716 asmlinkage long compat_sys_sched_getparam(u32 pid, struct sched_param __user *param)
717 {
718         return sys_sched_getparam((int)pid, param);
719 }
720
721
722 /* Note: it is necessary to treat pid as an unsigned int,
723  * with the corresponding cast to a signed int to insure that the 
724  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
725  * and the register representation of a signed int (msr in 64-bit mode) is performed.
726  */
727 asmlinkage long compat_sys_sched_getscheduler(u32 pid)
728 {
729         return sys_sched_getscheduler((int)pid);
730 }
731
732
733 /* Note: it is necessary to treat pid as an unsigned int,
734  * with the corresponding cast to a signed int to insure that the 
735  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
736  * and the register representation of a signed int (msr in 64-bit mode) is performed.
737  */
738 asmlinkage long compat_sys_sched_setparam(u32 pid, struct sched_param __user *param)
739 {
740         return sys_sched_setparam((int)pid, param);
741 }
742
743
744 /* Note: it is necessary to treat pid and policy as unsigned ints,
745  * with the corresponding cast to a signed int to insure that the 
746  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
747  * and the register representation of a signed int (msr in 64-bit mode) is performed.
748  */
749 asmlinkage long compat_sys_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
750 {
751         return sys_sched_setscheduler((int)pid, (int)policy, param);
752 }
753
754
755 /* Note: it is necessary to treat len as an unsigned int,
756  * with the corresponding cast to a signed int to insure that the 
757  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
758  * and the register representation of a signed int (msr in 64-bit mode) is performed.
759  */
760 asmlinkage long compat_sys_setdomainname(char __user *name, u32 len)
761 {
762         return sys_setdomainname(name, (int)len);
763 }
764
765
766 /* Note: it is necessary to treat gidsetsize as an unsigned int,
767  * with the corresponding cast to a signed int to insure that the 
768  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
769  * and the register representation of a signed int (msr in 64-bit mode) is performed.
770  */
771 asmlinkage long compat_sys_setgroups(u32 gidsetsize, gid_t __user *grouplist)
772 {
773         return sys_setgroups((int)gidsetsize, grouplist);
774 }
775
776
777 asmlinkage long compat_sys_sethostname(char __user *name, u32 len)
778 {
779         /* sign extend len */
780         return sys_sethostname(name, (int)len);
781 }
782
783
784 /* Note: it is necessary to treat pid and pgid as unsigned ints,
785  * with the corresponding cast to a signed int to insure that the 
786  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
787  * and the register representation of a signed int (msr in 64-bit mode) is performed.
788  */
789 asmlinkage long compat_sys_setpgid(u32 pid, u32 pgid)
790 {
791         return sys_setpgid((int)pid, (int)pgid);
792 }
793
794 long compat_sys_getpriority(u32 which, u32 who)
795 {
796         /* sign extend which and who */
797         return sys_getpriority((int)which, (int)who);
798 }
799
800 long compat_sys_setpriority(u32 which, u32 who, u32 niceval)
801 {
802         /* sign extend which, who and niceval */
803         return sys_setpriority((int)which, (int)who, (int)niceval);
804 }
805
806 long compat_sys_ioprio_get(u32 which, u32 who)
807 {
808         /* sign extend which and who */
809         return sys_ioprio_get((int)which, (int)who);
810 }
811
812 long compat_sys_ioprio_set(u32 which, u32 who, u32 ioprio)
813 {
814         /* sign extend which, who and ioprio */
815         return sys_ioprio_set((int)which, (int)who, (int)ioprio);
816 }
817
818 /* Note: it is necessary to treat newmask as an unsigned int,
819  * with the corresponding cast to a signed int to insure that the 
820  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
821  * and the register representation of a signed int (msr in 64-bit mode) is performed.
822  */
823 asmlinkage long compat_sys_ssetmask(u32 newmask)
824 {
825         return sys_ssetmask((int) newmask);
826 }
827
828 asmlinkage long compat_sys_syslog(u32 type, char __user * buf, u32 len)
829 {
830         /* sign extend len */
831         return sys_syslog(type, buf, (int)len);
832 }
833
834
835 /* Note: it is necessary to treat mask as an unsigned int,
836  * with the corresponding cast to a signed int to insure that the 
837  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
838  * and the register representation of a signed int (msr in 64-bit mode) is performed.
839  */
840 asmlinkage long compat_sys_umask(u32 mask)
841 {
842         return sys_umask((int)mask);
843 }
844
845 #ifdef CONFIG_SYSCTL
846 struct __sysctl_args32 {
847         u32 name;
848         int nlen;
849         u32 oldval;
850         u32 oldlenp;
851         u32 newval;
852         u32 newlen;
853         u32 __unused[4];
854 };
855
856 asmlinkage long compat_sys_sysctl(struct __sysctl_args32 __user *args)
857 {
858         struct __sysctl_args32 tmp;
859         int error;
860         size_t oldlen;
861         size_t __user *oldlenp = NULL;
862         unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
863
864         if (copy_from_user(&tmp, args, sizeof(tmp)))
865                 return -EFAULT;
866
867         if (tmp.oldval && tmp.oldlenp) {
868                 /* Duh, this is ugly and might not work if sysctl_args
869                    is in read-only memory, but do_sysctl does indirectly
870                    a lot of uaccess in both directions and we'd have to
871                    basically copy the whole sysctl.c here, and
872                    glibc's __sysctl uses rw memory for the structure
873                    anyway.  */
874                 oldlenp = (size_t __user *)addr;
875                 if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
876                     put_user(oldlen, oldlenp))
877                         return -EFAULT;
878         }
879
880         lock_kernel();
881         error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
882                           compat_ptr(tmp.oldval), oldlenp,
883                           compat_ptr(tmp.newval), tmp.newlen);
884         unlock_kernel();
885         if (oldlenp) {
886                 if (!error) {
887                         if (get_user(oldlen, oldlenp) ||
888                             put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
889                                 error = -EFAULT;
890                 }
891                 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
892         }
893         return error;
894 }
895 #endif
896
897 unsigned long compat_sys_mmap2(unsigned long addr, size_t len,
898                           unsigned long prot, unsigned long flags,
899                           unsigned long fd, unsigned long pgoff)
900 {
901         /* This should remain 12 even if PAGE_SIZE changes */
902         return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
903 }
904
905 long compat_sys_tgkill(u32 tgid, u32 pid, int sig)
906 {
907         /* sign extend tgid, pid */
908         return sys_tgkill((int)tgid, (int)pid, sig);
909 }
910
911 /* 
912  * long long munging:
913  * The 32 bit ABI passes long longs in an odd even register pair.
914  */
915
916 compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
917                              u32 reg6, u32 poshi, u32 poslo)
918 {
919         return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
920 }
921
922 compat_ssize_t compat_sys_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
923                               u32 reg6, u32 poshi, u32 poslo)
924 {
925         return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
926 }
927
928 compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
929 {
930         return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
931 }
932
933 asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4,
934                                 unsigned long high, unsigned long low)
935 {
936         return sys_truncate(path, (high << 32) | low);
937 }
938
939 asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
940                                  unsigned long low)
941 {
942         return sys_ftruncate(fd, (high << 32) | low);
943 }
944
945 long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
946                           size_t len)
947 {
948         return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
949                                   buf, len);
950 }
951
952 long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
953                      size_t len, int advice)
954 {
955         return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
956                              advice);
957 }
958
959 long ppc32_timer_create(clockid_t clock,
960                         struct compat_sigevent __user *ev32,
961                         timer_t __user *timer_id)
962 {
963         sigevent_t event;
964         timer_t t;
965         long err;
966         mm_segment_t savefs;
967
968         if (ev32 == NULL)
969                 return sys_timer_create(clock, NULL, timer_id);
970
971         if (get_compat_sigevent(&event, ev32))
972                 return -EFAULT;
973
974         if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t)))
975                 return -EFAULT;
976
977         savefs = get_fs();
978         set_fs(KERNEL_DS);
979         /* The __user pointer casts are valid due to the set_fs() */
980         err = sys_timer_create(clock,
981                 (sigevent_t __user *) &event,
982                 (timer_t __user *) &t);
983         set_fs(savefs);
984
985         if (err == 0)
986                 err = __put_user(t, timer_id);
987
988         return err;
989 }
990
991 asmlinkage long compat_sys_add_key(const char __user *_type,
992                               const char __user *_description,
993                               const void __user *_payload,
994                               u32 plen,
995                               u32 ringid)
996 {
997         return sys_add_key(_type, _description, _payload, plen, ringid);
998 }
999
1000 asmlinkage long compat_sys_request_key(const char __user *_type,
1001                                   const char __user *_description,
1002                                   const char __user *_callout_info,
1003                                   u32 destringid)
1004 {
1005         return sys_request_key(_type, _description, _callout_info, destringid);
1006 }
1007