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