- patches.fixes/patch-2.6.11-rc1: 2.6.11-rc1.
[linux-flexiantxendom0-3.2.10.git] / arch / ppc64 / 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/slab.h>
34 #include <linux/uio.h>
35 #include <linux/aio.h>
36 #include <linux/nfs_fs.h>
37 #include <linux/module.h>
38 #include <linux/sunrpc/svc.h>
39 #include <linux/nfsd/nfsd.h>
40 #include <linux/nfsd/cache.h>
41 #include <linux/nfsd/xdr.h>
42 #include <linux/nfsd/syscall.h>
43 #include <linux/poll.h>
44 #include <linux/personality.h>
45 #include <linux/stat.h>
46 #include <linux/filter.h>
47 #include <linux/highmem.h>
48 #include <linux/highuid.h>
49 #include <linux/mman.h>
50 #include <linux/ipv6.h>
51 #include <linux/in.h>
52 #include <linux/icmpv6.h>
53 #include <linux/syscalls.h>
54 #include <linux/unistd.h>
55 #include <linux/sysctl.h>
56 #include <linux/binfmts.h>
57 #include <linux/dnotify.h>
58 #include <linux/security.h>
59 #include <linux/compat.h>
60 #include <linux/ptrace.h>
61 #include <linux/aio_abi.h>
62 #include <linux/elf.h>
63
64 #include <net/scm.h>
65 #include <net/sock.h>
66
67 #include <asm/ptrace.h>
68 #include <asm/types.h>
69 #include <asm/ipc.h>
70 #include <asm/uaccess.h>
71 #include <asm/unistd.h>
72 #include <asm/semaphore.h>
73 #include <asm/ppcdebug.h>
74 #include <asm/time.h>
75 #include <asm/mmu_context.h>
76 #include <asm/systemcfg.h>
77
78 #include "pci.h"
79
80 /* readdir & getdents */
81 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
82 #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
83
84 struct old_linux_dirent32 {
85         u32             d_ino;
86         u32             d_offset;
87         unsigned short  d_namlen;
88         char            d_name[1];
89 };
90
91 struct readdir_callback32 {
92         struct old_linux_dirent32 __user * dirent;
93         int count;
94 };
95
96 static int fillonedir(void * __buf, const char * name, int namlen,
97                                   off_t offset, ino_t ino, unsigned int d_type)
98 {
99         struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf;
100         struct old_linux_dirent32 __user * dirent;
101
102         if (buf->count)
103                 return -EINVAL;
104         buf->count++;
105         dirent = buf->dirent;
106         put_user(ino, &dirent->d_ino);
107         put_user(offset, &dirent->d_offset);
108         put_user(namlen, &dirent->d_namlen);
109         copy_to_user(dirent->d_name, name, namlen);
110         put_user(0, dirent->d_name + namlen);
111         return 0;
112 }
113
114 asmlinkage int old32_readdir(unsigned int fd, struct old_linux_dirent32 __user *dirent, unsigned int count)
115 {
116         int error = -EBADF;
117         struct file * file;
118         struct readdir_callback32 buf;
119
120         file = fget(fd);
121         if (!file)
122                 goto out;
123
124         buf.count = 0;
125         buf.dirent = dirent;
126
127         error = vfs_readdir(file, (filldir_t)fillonedir, &buf);
128         if (error < 0)
129                 goto out_putf;
130         error = buf.count;
131
132 out_putf:
133         fput(file);
134 out:
135         return error;
136 }
137
138 struct linux_dirent32 {
139         u32             d_ino;
140         u32             d_off;
141         unsigned short  d_reclen;
142         char            d_name[1];
143 };
144
145 struct getdents_callback32 {
146         struct linux_dirent32 __user * current_dir;
147         struct linux_dirent32 __user * previous;
148         int count;
149         int error;
150 };
151
152 static int filldir(void * __buf, const char * name, int namlen, off_t offset,
153                    ino_t ino, unsigned int d_type)
154 {
155         struct linux_dirent32 __user * dirent;
156         struct getdents_callback32 * buf = (struct getdents_callback32 *) __buf;
157         int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2);
158
159         buf->error = -EINVAL;   /* only used if we fail.. */
160         if (reclen > buf->count)
161                 return -EINVAL;
162         dirent = buf->previous;
163         if (dirent) {
164                 if (__put_user(offset, &dirent->d_off))
165                         goto efault;
166         }
167         dirent = buf->current_dir;
168         if (__put_user(ino, &dirent->d_ino))
169                 goto efault;
170         if (__put_user(reclen, &dirent->d_reclen))
171                 goto efault;
172         if (copy_to_user(dirent->d_name, name, namlen))
173                 goto efault;
174         if (__put_user(0, dirent->d_name + namlen))
175                 goto efault;
176         if (__put_user(d_type, (char __user *) dirent + reclen - 1))
177                 goto efault;
178         buf->previous = dirent;
179         dirent = (void __user *)dirent + reclen;
180         buf->current_dir = dirent;
181         buf->count -= reclen;
182         return 0;
183 efault:
184         buf->error = -EFAULT;
185         return -EFAULT;
186 }
187
188 asmlinkage long sys32_getdents(unsigned int fd, struct linux_dirent32 __user *dirent,
189                     unsigned int count)
190 {
191         struct file * file;
192         struct linux_dirent32 __user * lastdirent;
193         struct getdents_callback32 buf;
194         int error;
195
196         error = -EFAULT;
197         if (!access_ok(VERIFY_WRITE, dirent, count))
198                 goto out;
199
200         error = -EBADF;
201         file = fget(fd);
202         if (!file)
203                 goto out;
204
205         buf.current_dir = dirent;
206         buf.previous = NULL;
207         buf.count = count;
208         buf.error = 0;
209
210         error = vfs_readdir(file, (filldir_t)filldir, &buf);
211         if (error < 0)
212                 goto out_putf;
213         error = buf.error;
214         lastdirent = buf.previous;
215         if (lastdirent) {
216                 if (put_user(file->f_pos, &lastdirent->d_off))
217                         error = -EFAULT;
218                 else
219                         error = count - buf.count;
220         }
221
222 out_putf:
223         fput(file);
224 out:
225         return error;
226 }
227
228 asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp,
229                 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
230                 compat_uptr_t tvp_x)
231 {
232         /* sign extend n */
233         return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x));
234 }
235
236 int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
237 {
238         long err;
239
240         if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
241             !new_valid_dev(stat->rdev))
242                 return -EOVERFLOW;
243
244         err  = verify_area(VERIFY_WRITE, statbuf, sizeof(*statbuf));
245         err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
246         err |= __put_user(stat->ino, &statbuf->st_ino);
247         err |= __put_user(stat->mode, &statbuf->st_mode);
248         err |= __put_user(stat->nlink, &statbuf->st_nlink);
249         err |= __put_user(stat->uid, &statbuf->st_uid);
250         err |= __put_user(stat->gid, &statbuf->st_gid);
251         err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
252         err |= __put_user(stat->size, &statbuf->st_size);
253         err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime);
254         err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
255         err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
256         err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
257         err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
258         err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
259         err |= __put_user(stat->blksize, &statbuf->st_blksize);
260         err |= __put_user(stat->blocks, &statbuf->st_blocks);
261         err |= __put_user(0, &statbuf->__unused4[0]);
262         err |= __put_user(0, &statbuf->__unused4[1]);
263
264         return err;
265 }
266
267 /* Note: it is necessary to treat option as an unsigned int,
268  * with the corresponding cast to a signed int to insure that the 
269  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
270  * and the register representation of a signed int (msr in 64-bit mode) is performed.
271  */
272 asmlinkage long sys32_sysfs(u32 option, u32 arg1, u32 arg2)
273 {
274         return sys_sysfs((int)option, arg1, arg2);
275 }
276
277 /* Handle adjtimex compatibility. */
278 struct timex32 {
279         u32 modes;
280         s32 offset, freq, maxerror, esterror;
281         s32 status, constant, precision, tolerance;
282         struct compat_timeval time;
283         s32 tick;
284         s32 ppsfreq, jitter, shift, stabil;
285         s32 jitcnt, calcnt, errcnt, stbcnt;
286         s32  :32; s32  :32; s32  :32; s32  :32;
287         s32  :32; s32  :32; s32  :32; s32  :32;
288         s32  :32; s32  :32; s32  :32; s32  :32;
289 };
290
291 extern int do_adjtimex(struct timex *);
292 extern void ppc_adjtimex(void);
293
294 asmlinkage long sys32_adjtimex(struct timex32 __user *utp)
295 {
296         struct timex txc;
297         int ret;
298         
299         memset(&txc, 0, sizeof(struct timex));
300
301         if(get_user(txc.modes, &utp->modes) ||
302            __get_user(txc.offset, &utp->offset) ||
303            __get_user(txc.freq, &utp->freq) ||
304            __get_user(txc.maxerror, &utp->maxerror) ||
305            __get_user(txc.esterror, &utp->esterror) ||
306            __get_user(txc.status, &utp->status) ||
307            __get_user(txc.constant, &utp->constant) ||
308            __get_user(txc.precision, &utp->precision) ||
309            __get_user(txc.tolerance, &utp->tolerance) ||
310            __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
311            __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
312            __get_user(txc.tick, &utp->tick) ||
313            __get_user(txc.ppsfreq, &utp->ppsfreq) ||
314            __get_user(txc.jitter, &utp->jitter) ||
315            __get_user(txc.shift, &utp->shift) ||
316            __get_user(txc.stabil, &utp->stabil) ||
317            __get_user(txc.jitcnt, &utp->jitcnt) ||
318            __get_user(txc.calcnt, &utp->calcnt) ||
319            __get_user(txc.errcnt, &utp->errcnt) ||
320            __get_user(txc.stbcnt, &utp->stbcnt))
321                 return -EFAULT;
322
323         ret = do_adjtimex(&txc);
324
325         /* adjust the conversion of TB to time of day to track adjtimex */
326         ppc_adjtimex();
327
328         if(put_user(txc.modes, &utp->modes) ||
329            __put_user(txc.offset, &utp->offset) ||
330            __put_user(txc.freq, &utp->freq) ||
331            __put_user(txc.maxerror, &utp->maxerror) ||
332            __put_user(txc.esterror, &utp->esterror) ||
333            __put_user(txc.status, &utp->status) ||
334            __put_user(txc.constant, &utp->constant) ||
335            __put_user(txc.precision, &utp->precision) ||
336            __put_user(txc.tolerance, &utp->tolerance) ||
337            __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
338            __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
339            __put_user(txc.tick, &utp->tick) ||
340            __put_user(txc.ppsfreq, &utp->ppsfreq) ||
341            __put_user(txc.jitter, &utp->jitter) ||
342            __put_user(txc.shift, &utp->shift) ||
343            __put_user(txc.stabil, &utp->stabil) ||
344            __put_user(txc.jitcnt, &utp->jitcnt) ||
345            __put_user(txc.calcnt, &utp->calcnt) ||
346            __put_user(txc.errcnt, &utp->errcnt) ||
347            __put_user(txc.stbcnt, &utp->stbcnt))
348                 ret = -EFAULT;
349
350         return ret;
351 }
352
353
354 /* These are here just in case some old sparc32 binary calls it. */
355 asmlinkage long sys32_pause(void)
356 {
357         current->state = TASK_INTERRUPTIBLE;
358         schedule();
359         
360         return -ERESTARTNOHAND;
361 }
362
363
364
365 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
366 {
367         long usec;
368
369         if (!access_ok(VERIFY_READ, i, sizeof(*i)))
370                 return -EFAULT;
371         if (__get_user(o->tv_sec, &i->tv_sec))
372                 return -EFAULT;
373         if (__get_user(usec, &i->tv_usec))
374                 return -EFAULT;
375         o->tv_nsec = usec * 1000;
376         return 0;
377 }
378
379 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
380 {
381         return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
382                 (__put_user(i->tv_sec, &o->tv_sec) |
383                  __put_user(i->tv_usec, &o->tv_usec)));
384 }
385
386 struct sysinfo32 {
387         s32 uptime;
388         u32 loads[3];
389         u32 totalram;
390         u32 freeram;
391         u32 sharedram;
392         u32 bufferram;
393         u32 totalswap;
394         u32 freeswap;
395         unsigned short procs;
396         unsigned short pad;
397         u32 totalhigh;
398         u32 freehigh;
399         u32 mem_unit;
400         char _f[20-2*sizeof(int)-sizeof(int)];
401 };
402
403 asmlinkage long sys32_sysinfo(struct sysinfo32 __user *info)
404 {
405         struct sysinfo s;
406         int ret, err;
407         int bitcount=0;
408         mm_segment_t old_fs = get_fs ();
409         
410         /* The __user cast is valid due to set_fs() */
411         set_fs (KERNEL_DS);
412         ret = sys_sysinfo((struct sysinfo __user *)&s);
413         set_fs (old_fs);
414
415         /* Check to see if any memory value is too large for 32-bit and
416          * scale down if needed.
417          */
418         if ((s.totalram >> 32) || (s.totalswap >> 32)) {
419             while (s.mem_unit < PAGE_SIZE) {
420                 s.mem_unit <<= 1;
421                 bitcount++;
422             }
423             s.totalram >>=bitcount;
424             s.freeram >>= bitcount;
425             s.sharedram >>= bitcount;
426             s.bufferram >>= bitcount;
427             s.totalswap >>= bitcount;
428             s.freeswap >>= bitcount;
429             s.totalhigh >>= bitcount;
430             s.freehigh >>= bitcount;
431         }
432
433         err = put_user (s.uptime, &info->uptime);
434         err |= __put_user (s.loads[0], &info->loads[0]);
435         err |= __put_user (s.loads[1], &info->loads[1]);
436         err |= __put_user (s.loads[2], &info->loads[2]);
437         err |= __put_user (s.totalram, &info->totalram);
438         err |= __put_user (s.freeram, &info->freeram);
439         err |= __put_user (s.sharedram, &info->sharedram);
440         err |= __put_user (s.bufferram, &info->bufferram);
441         err |= __put_user (s.totalswap, &info->totalswap);
442         err |= __put_user (s.freeswap, &info->freeswap);
443         err |= __put_user (s.procs, &info->procs);
444         err |= __put_user (s.totalhigh, &info->totalhigh);
445         err |= __put_user (s.freehigh, &info->freehigh);
446         err |= __put_user (s.mem_unit, &info->mem_unit);
447         if (err)
448                 return -EFAULT;
449         
450         return ret;
451 }
452
453
454
455
456 /* Translations due to time_t size differences.  Which affects all
457    sorts of things, like timeval and itimerval.  */
458 extern struct timezone sys_tz;
459
460 asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
461 {
462         if (tv) {
463                 struct timeval ktv;
464                 do_gettimeofday(&ktv);
465                 if (put_tv32(tv, &ktv))
466                         return -EFAULT;
467         }
468         if (tz) {
469                 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
470                         return -EFAULT;
471         }
472         
473         return 0;
474 }
475
476
477
478 asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
479 {
480         struct timespec kts;
481         struct timezone ktz;
482         
483         if (tv) {
484                 if (get_ts32(&kts, tv))
485                         return -EFAULT;
486         }
487         if (tz) {
488                 if (copy_from_user(&ktz, tz, sizeof(ktz)))
489                         return -EFAULT;
490         }
491
492         return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
493 }
494
495 long sys32_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
496                u32 fifth)
497 {
498         int version;
499
500         version = call >> 16; /* hack for backward compatibility */
501         call &= 0xffff;
502
503         switch (call) {
504
505         case SEMTIMEDOP:
506                 if (third)
507                         /* sign extend semid */
508                         return compat_sys_semtimedop((int)first,
509                                                      compat_ptr(ptr), second,
510                                                      compat_ptr(third));
511                 /* else fall through for normal semop() */
512         case SEMOP:
513                 /* struct sembuf is the same on 32 and 64bit :)) */
514                 /* sign extend semid */
515                 return sys_semtimedop((int)first, compat_ptr(ptr), second,
516                                       NULL);
517         case SEMGET:
518                 /* sign extend key, nsems */
519                 return sys_semget((int)first, (int)second, third);
520         case SEMCTL:
521                 /* sign extend semid, semnum */
522                 return compat_sys_semctl((int)first, (int)second, third,
523                                          compat_ptr(ptr));
524
525         case MSGSND:
526                 /* sign extend msqid */
527                 return compat_sys_msgsnd((int)first, (int)second, third,
528                                          compat_ptr(ptr));
529         case MSGRCV:
530                 /* sign extend msqid, msgtyp */
531                 return compat_sys_msgrcv((int)first, second, (int)fifth,
532                                          third, version, compat_ptr(ptr));
533         case MSGGET:
534                 /* sign extend key */
535                 return sys_msgget((int)first, second);
536         case MSGCTL:
537                 /* sign extend msqid */
538                 return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
539
540         case SHMAT:
541                 /* sign extend shmid */
542                 return compat_sys_shmat((int)first, second, third, version,
543                                         compat_ptr(ptr));
544         case SHMDT:
545                 return sys_shmdt(compat_ptr(ptr));
546         case SHMGET:
547                 /* sign extend key_t */
548                 return sys_shmget((int)first, second, third);
549         case SHMCTL:
550                 /* sign extend shmid */
551                 return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
552
553         default:
554                 return -ENOSYS;
555         }
556
557         return -ENOSYS;
558 }
559
560 /* Note: it is necessary to treat out_fd and in_fd as unsigned ints, 
561  * with the corresponding cast to a signed int to insure that the 
562  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
563  * and the register representation of a signed int (msr in 64-bit mode) is performed.
564  */
565 asmlinkage long sys32_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count)
566 {
567         mm_segment_t old_fs = get_fs();
568         int ret;
569         off_t of;
570         off_t __user *up;
571
572         if (offset && get_user(of, offset))
573                 return -EFAULT;
574
575         /* The __user pointer cast is valid because of the set_fs() */          
576         set_fs(KERNEL_DS);
577         up = offset ? (off_t __user *) &of : NULL;
578         ret = sys_sendfile((int)out_fd, (int)in_fd, up, count);
579         set_fs(old_fs);
580         
581         if (offset && put_user(of, offset))
582                 return -EFAULT;
583                 
584         return ret;
585 }
586
587 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
588 {
589         mm_segment_t old_fs = get_fs();
590         int ret;
591         loff_t lof;
592         loff_t __user *up;
593         
594         if (offset && get_user(lof, offset))
595                 return -EFAULT;
596                 
597         /* The __user pointer cast is valid because of the set_fs() */          
598         set_fs(KERNEL_DS);
599         up = offset ? (loff_t __user *) &lof : NULL;
600         ret = sys_sendfile64(out_fd, in_fd, up, count);
601         set_fs(old_fs);
602         
603         if (offset && put_user(lof, offset))
604                 return -EFAULT;
605                 
606         return ret;
607 }
608
609 long sys32_execve(unsigned long a0, unsigned long a1, unsigned long a2,
610                   unsigned long a3, unsigned long a4, unsigned long a5,
611                   struct pt_regs *regs)
612 {
613         int error;
614         char * filename;
615         
616         filename = getname((char __user *) a0);
617         error = PTR_ERR(filename);
618         if (IS_ERR(filename))
619                 goto out;
620         flush_fp_to_thread(current);
621         flush_altivec_to_thread(current);
622
623         error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs);
624
625         if (error == 0) {
626                 task_lock(current);
627                 current->ptrace &= ~PT_DTRACE;
628                 task_unlock(current);
629         }
630         putname(filename);
631
632 out:
633         return error;
634 }
635
636 /* Set up a thread for executing a new program. */
637 void start_thread32(struct pt_regs* regs, unsigned long nip, unsigned long sp)
638 {
639         set_fs(USER_DS);
640
641         /*
642          * If we exec out of a kernel thread then thread.regs will not be
643          * set. Do it now.
644          */
645         if (!current->thread.regs) {
646                 unsigned long childregs = (unsigned long)current->thread_info +
647                                                 THREAD_SIZE;
648                 childregs -= sizeof(struct pt_regs);
649                 current->thread.regs = (struct pt_regs *)childregs;
650         }
651
652         /*
653          * ELF_PLAT_INIT already clears all registers but it also sets r2.
654          * So just clear r2 here.
655          */
656         regs->gpr[2] = 0;
657
658         regs->nip = nip;
659         regs->gpr[1] = sp;
660         regs->msr = MSR_USER32;
661 #ifndef CONFIG_SMP
662         if (last_task_used_math == current)
663                 last_task_used_math = 0;
664 #endif /* CONFIG_SMP */
665         current->thread.fpscr = 0;
666         memset(current->thread.fpr, 0, sizeof(current->thread.fpr));
667 #ifdef CONFIG_ALTIVEC
668 #ifndef CONFIG_SMP
669         if (last_task_used_altivec == current)
670                 last_task_used_altivec = 0;
671 #endif /* CONFIG_SMP */
672         memset(current->thread.vr, 0, sizeof(current->thread.vr));
673         current->thread.vscr.u[0] = 0;
674         current->thread.vscr.u[1] = 0;
675         current->thread.vscr.u[2] = 0;
676         current->thread.vscr.u[3] = 0x00010000; /* Java mode disabled */
677         current->thread.vrsave = 0;
678         current->thread.used_vr = 0;
679 #endif /* CONFIG_ALTIVEC */
680 }
681
682 /* Note: it is necessary to treat option as an unsigned int, 
683  * with the corresponding cast to a signed int to insure that the 
684  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
685  * and the register representation of a signed int (msr in 64-bit mode) is performed.
686  */
687 asmlinkage long sys32_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
688 {
689         return sys_prctl((int)option,
690                          (unsigned long) arg2,
691                          (unsigned long) arg3,
692                          (unsigned long) arg4,
693                          (unsigned long) arg5);
694 }
695
696 /* Note: it is necessary to treat pid as an unsigned int, 
697  * with the corresponding cast to a signed int to insure that the 
698  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
699  * and the register representation of a signed int (msr in 64-bit mode) is performed.
700  */
701 asmlinkage long sys32_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
702 {
703         struct timespec t;
704         int ret;
705         mm_segment_t old_fs = get_fs ();
706
707         /* The __user pointer cast is valid because of the set_fs() */
708         set_fs (KERNEL_DS);
709         ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
710         set_fs (old_fs);
711         if (put_compat_timespec(&t, interval))
712                 return -EFAULT;
713         return ret;
714 }
715
716 asmlinkage int sys32_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
717 {
718         return sys_pciconfig_read((unsigned long) bus,
719                                   (unsigned long) dfn,
720                                   (unsigned long) off,
721                                   (unsigned long) len,
722                                   compat_ptr(ubuf));
723 }
724
725 asmlinkage int sys32_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
726 {
727         return sys_pciconfig_write((unsigned long) bus,
728                                    (unsigned long) dfn,
729                                    (unsigned long) off,
730                                    (unsigned long) len,
731                                    compat_ptr(ubuf));
732 }
733
734 #define IOBASE_BRIDGE_NUMBER    0
735 #define IOBASE_MEMORY           1
736 #define IOBASE_IO               2
737 #define IOBASE_ISA_IO           3
738 #define IOBASE_ISA_MEM          4
739
740 asmlinkage int sys32_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)
741 {
742         struct pci_controller* hose;
743         struct list_head *ln;
744         struct pci_bus *bus = NULL;
745         struct device_node *hose_node;
746
747         /* Argh ! Please forgive me for that hack, but that's the
748          * simplest way to get existing XFree to not lockup on some
749          * G5 machines... So when something asks for bus 0 io base
750          * (bus 0 is HT root), we return the AGP one instead.
751          */
752 #ifdef CONFIG_PPC_PMAC
753         if (systemcfg->platform == PLATFORM_POWERMAC &&
754             machine_is_compatible("MacRISC4"))
755                 if (in_bus == 0)
756                         in_bus = 0xf0;
757 #endif /* CONFIG_PPC_PMAC */
758
759         /* That syscall isn't quite compatible with PCI domains, but it's
760          * used on pre-domains setup. We return the first match
761          */
762
763         for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
764                 bus = pci_bus_b(ln);
765                 if (in_bus >= bus->number && in_bus < (bus->number + bus->subordinate))
766                         break;
767                 bus = NULL;
768         }
769         if (bus == NULL || bus->sysdata == NULL)
770                 return -ENODEV;
771
772         hose_node = (struct device_node *)bus->sysdata;
773         hose = hose_node->phb;
774
775         switch (which) {
776         case IOBASE_BRIDGE_NUMBER:
777                 return (long)hose->first_busno;
778         case IOBASE_MEMORY:
779                 return (long)hose->pci_mem_offset;
780         case IOBASE_IO:
781                 return (long)hose->io_base_phys;
782         case IOBASE_ISA_IO:
783                 return (long)isa_io_base;
784         case IOBASE_ISA_MEM:
785                 return -EINVAL;
786         }
787
788         return -EOPNOTSUPP;
789 }
790
791
792 asmlinkage int ppc64_newuname(struct new_utsname __user * name)
793 {
794         int errno = sys_newuname(name);
795
796         if (current->personality == PER_LINUX32 && !errno) {
797                 if(copy_to_user(name->machine, "ppc\0\0", 8)) {
798                         errno = -EFAULT;
799                 }
800         }
801         return errno;
802 }
803
804 asmlinkage int ppc64_personality(unsigned long personality)
805 {
806         int ret;
807         if (current->personality == PER_LINUX32 && personality == PER_LINUX)
808                 personality = PER_LINUX32;
809         ret = sys_personality(personality);
810         if (ret == PER_LINUX32)
811                 ret = PER_LINUX;
812         return ret;
813 }
814
815
816
817 /* Note: it is necessary to treat mode as an unsigned int,
818  * with the corresponding cast to a signed int to insure that the 
819  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
820  * and the register representation of a signed int (msr in 64-bit mode) is performed.
821  */
822 asmlinkage long sys32_access(const char __user * filename, u32 mode)
823 {
824         return sys_access(filename, (int)mode);
825 }
826
827
828 /* Note: it is necessary to treat mode as an unsigned int,
829  * with the corresponding cast to a signed int to insure that the 
830  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
831  * and the register representation of a signed int (msr in 64-bit mode) is performed.
832  */
833 asmlinkage long sys32_creat(const char __user * pathname, u32 mode)
834 {
835         return sys_creat(pathname, (int)mode);
836 }
837
838
839 /* Note: it is necessary to treat pid and options as unsigned ints,
840  * with the corresponding cast to a signed int to insure that the 
841  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
842  * and the register representation of a signed int (msr in 64-bit mode) is performed.
843  */
844 asmlinkage long sys32_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
845 {
846         return sys_waitpid((int)pid, stat_addr, (int)options);
847 }
848
849
850 /* Note: it is necessary to treat gidsetsize as an unsigned int,
851  * with the corresponding cast to a signed int to insure that the 
852  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
853  * and the register representation of a signed int (msr in 64-bit mode) is performed.
854  */
855 asmlinkage long sys32_getgroups(u32 gidsetsize, gid_t __user *grouplist)
856 {
857         return sys_getgroups((int)gidsetsize, grouplist);
858 }
859
860
861 /* Note: it is necessary to treat pid as an unsigned int,
862  * with the corresponding cast to a signed int to insure that the 
863  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
864  * and the register representation of a signed int (msr in 64-bit mode) is performed.
865  */
866 asmlinkage long sys32_getpgid(u32 pid)
867 {
868         return sys_getpgid((int)pid);
869 }
870
871
872 /* Note: it is necessary to treat which and who as unsigned ints,
873  * with the corresponding cast to a signed int to insure that the 
874  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
875  * and the register representation of a signed int (msr in 64-bit mode) is performed.
876  */
877 asmlinkage long sys32_getpriority(u32 which, u32 who)
878 {
879         return sys_getpriority((int)which, (int)who);
880 }
881
882
883 /* Note: it is necessary to treat pid as an unsigned int,
884  * with the corresponding cast to a signed int to insure that the 
885  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
886  * and the register representation of a signed int (msr in 64-bit mode) is performed.
887  */
888 asmlinkage long sys32_getsid(u32 pid)
889 {
890         return sys_getsid((int)pid);
891 }
892
893
894 /* Note: it is necessary to treat pid and sig as unsigned ints,
895  * with the corresponding cast to a signed int to insure that the 
896  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
897  * and the register representation of a signed int (msr in 64-bit mode) is performed.
898  */
899 asmlinkage long sys32_kill(u32 pid, u32 sig)
900 {
901         return sys_kill((int)pid, (int)sig);
902 }
903
904
905 /* Note: it is necessary to treat mode as an unsigned int,
906  * with the corresponding cast to a signed int to insure that the 
907  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
908  * and the register representation of a signed int (msr in 64-bit mode) is performed.
909  */
910 asmlinkage long sys32_mkdir(const char __user * pathname, u32 mode)
911 {
912         return sys_mkdir(pathname, (int)mode);
913 }
914
915 long sys32_nice(u32 increment)
916 {
917         /* sign extend increment */
918         return sys_nice((int)increment);
919 }
920
921 off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
922 {
923         /* sign extend n */
924         return sys_lseek(fd, (int)offset, origin);
925 }
926
927 /*
928  * This is just a version for 32-bit applications which does
929  * not force O_LARGEFILE on.
930  */
931 asmlinkage long sys32_open(const char __user * filename, int flags, int mode)
932 {
933         char * tmp;
934         int fd, error;
935
936         tmp = getname(filename);
937         fd = PTR_ERR(tmp);
938         if (!IS_ERR(tmp)) {
939                 fd = get_unused_fd();
940                 if (fd >= 0) {
941                         struct file * f = filp_open(tmp, flags, mode);
942                         error = PTR_ERR(f);
943                         if (IS_ERR(f))
944                                 goto out_error;
945                         fd_install(fd, f);
946                 }
947 out:
948                 putname(tmp);
949         }
950         return fd;
951
952 out_error:
953         put_unused_fd(fd);
954         fd = error;
955         goto out;
956 }
957
958 /* Note: it is necessary to treat bufsiz as an unsigned int,
959  * with the corresponding cast to a signed int to insure that the 
960  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
961  * and the register representation of a signed int (msr in 64-bit mode) is performed.
962  */
963 asmlinkage long sys32_readlink(const char __user * path, char __user * buf, u32 bufsiz)
964 {
965         return sys_readlink(path, buf, (int)bufsiz);
966 }
967
968 /* Note: it is necessary to treat option as an unsigned int,
969  * with the corresponding cast to a signed int to insure that the 
970  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
971  * and the register representation of a signed int (msr in 64-bit mode) is performed.
972  */
973 asmlinkage long sys32_sched_get_priority_max(u32 policy)
974 {
975         return sys_sched_get_priority_max((int)policy);
976 }
977
978
979 /* Note: it is necessary to treat policy as an unsigned int,
980  * with the corresponding cast to a signed int to insure that the 
981  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
982  * and the register representation of a signed int (msr in 64-bit mode) is performed.
983  */
984 asmlinkage long sys32_sched_get_priority_min(u32 policy)
985 {
986         return sys_sched_get_priority_min((int)policy);
987 }
988
989
990 /* Note: it is necessary to treat pid as an unsigned int,
991  * with the corresponding cast to a signed int to insure that the 
992  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
993  * and the register representation of a signed int (msr in 64-bit mode) is performed.
994  */
995 asmlinkage long sys32_sched_getparam(u32 pid, struct sched_param __user *param)
996 {
997         return sys_sched_getparam((int)pid, param);
998 }
999
1000
1001 /* Note: it is necessary to treat pid as an unsigned int,
1002  * with the corresponding cast to a signed int to insure that the 
1003  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1004  * and the register representation of a signed int (msr in 64-bit mode) is performed.
1005  */
1006 asmlinkage long sys32_sched_getscheduler(u32 pid)
1007 {
1008         return sys_sched_getscheduler((int)pid);
1009 }
1010
1011
1012 /* Note: it is necessary to treat pid as an unsigned int,
1013  * with the corresponding cast to a signed int to insure that the 
1014  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1015  * and the register representation of a signed int (msr in 64-bit mode) is performed.
1016  */
1017 asmlinkage long sys32_sched_setparam(u32 pid, struct sched_param __user *param)
1018 {
1019         return sys_sched_setparam((int)pid, param);
1020 }
1021
1022
1023 /* Note: it is necessary to treat pid and policy as unsigned ints,
1024  * with the corresponding cast to a signed int to insure that the 
1025  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1026  * and the register representation of a signed int (msr in 64-bit mode) is performed.
1027  */
1028 asmlinkage long sys32_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
1029 {
1030         return sys_sched_setscheduler((int)pid, (int)policy, param);
1031 }
1032
1033
1034 /* Note: it is necessary to treat len as an unsigned int,
1035  * with the corresponding cast to a signed int to insure that the 
1036  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1037  * and the register representation of a signed int (msr in 64-bit mode) is performed.
1038  */
1039 asmlinkage long sys32_setdomainname(char __user *name, u32 len)
1040 {
1041         return sys_setdomainname(name, (int)len);
1042 }
1043
1044
1045 /* Note: it is necessary to treat gidsetsize as an unsigned int,
1046  * with the corresponding cast to a signed int to insure that the 
1047  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1048  * and the register representation of a signed int (msr in 64-bit mode) is performed.
1049  */
1050 asmlinkage long sys32_setgroups(u32 gidsetsize, gid_t __user *grouplist)
1051 {
1052         return sys_setgroups((int)gidsetsize, grouplist);
1053 }
1054
1055
1056 asmlinkage long sys32_sethostname(char __user *name, u32 len)
1057 {
1058         /* sign extend len */
1059         return sys_sethostname(name, (int)len);
1060 }
1061
1062
1063 /* Note: it is necessary to treat pid and pgid as unsigned ints,
1064  * with the corresponding cast to a signed int to insure that the 
1065  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1066  * and the register representation of a signed int (msr in 64-bit mode) is performed.
1067  */
1068 asmlinkage long sys32_setpgid(u32 pid, u32 pgid)
1069 {
1070         return sys_setpgid((int)pid, (int)pgid);
1071 }
1072
1073
1074 long sys32_setpriority(u32 which, u32 who, u32 niceval)
1075 {
1076         /* sign extend which, who and niceval */
1077         return sys_setpriority((int)which, (int)who, (int)niceval);
1078 }
1079
1080 /* Note: it is necessary to treat newmask as an unsigned int,
1081  * with the corresponding cast to a signed int to insure that the 
1082  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1083  * and the register representation of a signed int (msr in 64-bit mode) is performed.
1084  */
1085 asmlinkage long sys32_ssetmask(u32 newmask)
1086 {
1087         return sys_ssetmask((int) newmask);
1088 }
1089
1090 asmlinkage long sys32_syslog(u32 type, char __user * buf, u32 len)
1091 {
1092         /* sign extend len */
1093         return sys_syslog(type, buf, (int)len);
1094 }
1095
1096
1097 /* Note: it is necessary to treat mask as an unsigned int,
1098  * with the corresponding cast to a signed int to insure that the 
1099  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
1100  * and the register representation of a signed int (msr in 64-bit mode) is performed.
1101  */
1102 asmlinkage long sys32_umask(u32 mask)
1103 {
1104         return sys_umask((int)mask);
1105 }
1106
1107 struct __sysctl_args32 {
1108         u32 name;
1109         int nlen;
1110         u32 oldval;
1111         u32 oldlenp;
1112         u32 newval;
1113         u32 newlen;
1114         u32 __unused[4];
1115 };
1116
1117 asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
1118 {
1119         struct __sysctl_args32 tmp;
1120         int error;
1121         size_t oldlen;
1122         size_t __user *oldlenp = NULL;
1123         unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
1124
1125         if (copy_from_user(&tmp, args, sizeof(tmp)))
1126                 return -EFAULT;
1127
1128         if (tmp.oldval && tmp.oldlenp) {
1129                 /* Duh, this is ugly and might not work if sysctl_args
1130                    is in read-only memory, but do_sysctl does indirectly
1131                    a lot of uaccess in both directions and we'd have to
1132                    basically copy the whole sysctl.c here, and
1133                    glibc's __sysctl uses rw memory for the structure
1134                    anyway.  */
1135                 oldlenp = (size_t __user *)addr;
1136                 if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
1137                     put_user(oldlen, oldlenp))
1138                         return -EFAULT;
1139         }
1140
1141         lock_kernel();
1142         error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
1143                           compat_ptr(tmp.oldval), oldlenp,
1144                           compat_ptr(tmp.newval), tmp.newlen);
1145         unlock_kernel();
1146         if (oldlenp) {
1147                 if (!error) {
1148                         if (get_user(oldlen, oldlenp) ||
1149                             put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
1150                                 error = -EFAULT;
1151                 }
1152                 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
1153         }
1154         return error;
1155 }
1156
1157 asmlinkage int sys32_olduname(struct oldold_utsname __user * name)
1158 {
1159         int error;
1160         
1161         if (!name)
1162                 return -EFAULT;
1163         if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
1164                 return -EFAULT;
1165   
1166         down_read(&uts_sem);
1167         error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
1168         error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
1169         error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
1170         error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
1171         error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
1172         error -= __put_user(0,name->release+__OLD_UTS_LEN);
1173         error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
1174         error -= __put_user(0,name->version+__OLD_UTS_LEN);
1175         error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
1176         error = __put_user(0,name->machine+__OLD_UTS_LEN);
1177         up_read(&uts_sem);
1178
1179         error = error ? -EFAULT : 0;
1180         
1181         return error;
1182 }
1183
1184 unsigned long sys32_mmap2(unsigned long addr, size_t len,
1185                           unsigned long prot, unsigned long flags,
1186                           unsigned long fd, unsigned long pgoff)
1187 {
1188         /* This should remain 12 even if PAGE_SIZE changes */
1189         return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
1190 }
1191
1192 int get_compat_timeval(struct timeval *tv, struct compat_timeval __user *ctv)
1193 {
1194         return (verify_area(VERIFY_READ, ctv, sizeof(*ctv)) ||
1195                 __get_user(tv->tv_sec, &ctv->tv_sec) ||
1196                 __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
1197 }
1198
1199 asmlinkage long sys32_utimes(char __user *filename, struct compat_timeval __user *tvs)
1200 {
1201         struct timeval ktvs[2], *ptr;
1202
1203         ptr = NULL;
1204         if (tvs) {
1205                 if (get_compat_timeval(&ktvs[0], &tvs[0]) ||
1206                     get_compat_timeval(&ktvs[1], &tvs[1]))
1207                         return -EFAULT;
1208                 ptr = ktvs;
1209         }
1210
1211         return do_utimes(filename, ptr);
1212 }
1213
1214 long sys32_tgkill(u32 tgid, u32 pid, int sig)
1215 {
1216         /* sign extend tgid, pid */
1217         return sys_tgkill((int)tgid, (int)pid, sig);
1218 }
1219
1220 /* 
1221  * long long munging:
1222  * The 32 bit ABI passes long longs in an odd even register pair.
1223  */
1224
1225 compat_ssize_t sys32_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
1226                              u32 reg6, u32 poshi, u32 poslo)
1227 {
1228         return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
1229 }
1230
1231 compat_ssize_t sys32_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
1232                               u32 reg6, u32 poshi, u32 poslo)
1233 {
1234         return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
1235 }
1236
1237 compat_ssize_t sys32_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
1238 {
1239         return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
1240 }
1241
1242 asmlinkage int sys32_truncate64(const char __user * path, u32 reg4,
1243                                 unsigned long high, unsigned long low)
1244 {
1245         return sys_truncate(path, (high << 32) | low);
1246 }
1247
1248 asmlinkage int sys32_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
1249                                  unsigned long low)
1250 {
1251         return sys_ftruncate(fd, (high << 32) | low);
1252 }
1253
1254 long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
1255                           size_t len)
1256 {
1257         return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
1258                                   buf, len);
1259 }
1260
1261 long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
1262                      size_t len, int advice)
1263 {
1264         return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
1265                              advice);
1266 }
1267
1268 long ppc32_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
1269                         u32 len_high, u32 len_low)
1270 {
1271         return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low,
1272                              (u64)len_high << 32 | len_low, advice);
1273 }
1274
1275 extern asmlinkage long sys_timer_create(clockid_t, sigevent_t __user *, timer_t __user *);
1276
1277 long ppc32_timer_create(clockid_t clock,
1278                         struct compat_sigevent __user *ev32,
1279                         timer_t __user *timer_id)
1280 {
1281         sigevent_t event;
1282         timer_t t;
1283         long err;
1284         mm_segment_t savefs;
1285
1286         if (ev32 == NULL)
1287                 return sys_timer_create(clock, NULL, timer_id);
1288
1289         memset(&event, 0, sizeof(event));
1290         if (!access_ok(VERIFY_READ, ev32, sizeof(struct compat_sigevent))
1291             || __get_user(event.sigev_value.sival_int,
1292                           &ev32->sigev_value.sival_int)
1293             || __get_user(event.sigev_signo, &ev32->sigev_signo)
1294             || __get_user(event.sigev_notify, &ev32->sigev_notify)
1295             || __get_user(event.sigev_notify_thread_id,
1296                           &ev32->sigev_notify_thread_id))
1297                 return -EFAULT;
1298
1299         if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t)))
1300                 return -EFAULT;
1301
1302         savefs = get_fs();
1303         set_fs(KERNEL_DS);
1304         /* The __user pointer casts are valid due to the set_fs() */
1305         err = sys_timer_create(clock,
1306                 (sigevent_t __user *) &event,
1307                 (timer_t __user *) &t);
1308         set_fs(savefs);
1309
1310         if (err == 0)
1311                 err = __put_user(t, timer_id);
1312
1313         return err;
1314 }
1315
1316 asmlinkage long sys32_add_key(const char __user *_type,
1317                               const char __user *_description,
1318                               const void __user *_payload,
1319                               u32 plen,
1320                               u32 ringid)
1321 {
1322         return sys_add_key(_type, _description, _payload, plen, ringid);
1323 }
1324
1325 asmlinkage long sys32_request_key(const char __user *_type,
1326                                   const char __user *_description,
1327                                   const char __user *_callout_info,
1328                                   u32 destringid)
1329 {
1330         return sys_request_key(_type, _description, _callout_info, destringid);
1331 }
1332