vserver 1.9.3
[linux-2.6.git] / arch / x86_64 / ia32 / sys_ia32.c
1 /*
2  * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on
3  *             sys_sparc32 
4  *
5  * Copyright (C) 2000           VA Linux Co
6  * Copyright (C) 2000           Don Dugger <n0ano@valinux.com>
7  * Copyright (C) 1999           Arun Sharma <arun.sharma@intel.com>
8  * Copyright (C) 1997,1998      Jakub Jelinek (jj@sunsite.mff.cuni.cz)
9  * Copyright (C) 1997           David S. Miller (davem@caip.rutgers.edu)
10  * Copyright (C) 2000           Hewlett-Packard Co.
11  * Copyright (C) 2000           David Mosberger-Tang <davidm@hpl.hp.com>
12  * Copyright (C) 2000,2001,2002 Andi Kleen, SuSE Labs (x86-64 port) 
13  *
14  * These routines maintain argument size conversion between 32bit and 64bit
15  * environment. In 2.5 most of this should be moved to a generic directory. 
16  *
17  * This file assumes that there is a hole at the end of user address space.
18  * 
19  * Some of the functions are LE specific currently. These are hopefully all marked.
20  * This should be fixed.
21  */
22
23 #include <linux/config.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <linux/fs.h> 
27 #include <linux/file.h> 
28 #include <linux/signal.h>
29 #include <linux/syscalls.h>
30 #include <linux/resource.h>
31 #include <linux/times.h>
32 #include <linux/utsname.h>
33 #include <linux/timex.h>
34 #include <linux/smp.h>
35 #include <linux/smp_lock.h>
36 #include <linux/sem.h>
37 #include <linux/msg.h>
38 #include <linux/mm.h>
39 #include <linux/shm.h>
40 #include <linux/slab.h>
41 #include <linux/uio.h>
42 #include <linux/nfs_fs.h>
43 #include <linux/quota.h>
44 #include <linux/module.h>
45 #include <linux/sunrpc/svc.h>
46 #include <linux/nfsd/nfsd.h>
47 #include <linux/nfsd/cache.h>
48 #include <linux/nfsd/xdr.h>
49 #include <linux/nfsd/syscall.h>
50 #include <linux/poll.h>
51 #include <linux/personality.h>
52 #include <linux/stat.h>
53 #include <linux/ipc.h>
54 #include <linux/rwsem.h>
55 #include <linux/binfmts.h>
56 #include <linux/init.h>
57 #include <linux/aio_abi.h>
58 #include <linux/aio.h>
59 #include <linux/compat.h>
60 #include <linux/vfs.h>
61 #include <linux/ptrace.h>
62 #include <linux/highuid.h>
63 #include <linux/vmalloc.h>
64 #include <asm/mman.h>
65 #include <asm/types.h>
66 #include <asm/uaccess.h>
67 #include <asm/semaphore.h>
68 #include <asm/ipc.h>
69 #include <asm/atomic.h>
70 #include <asm/ldt.h>
71
72 #include <net/scm.h>
73 #include <net/sock.h>
74 #include <asm/ia32.h>
75
76 #define A(__x)          ((unsigned long)(__x))
77 #define AA(__x)         ((unsigned long)(__x))
78 #define ROUND_UP(x,a)   ((__typeof__(x))(((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)))
79 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
80
81 int cp_compat_stat(struct kstat *kbuf, struct compat_stat __user *ubuf)
82 {
83         typeof(ubuf->st_uid) uid = 0;
84         typeof(ubuf->st_gid) gid = 0;
85         SET_UID(uid, kbuf->uid);
86         SET_GID(gid, kbuf->gid);
87         if (!old_valid_dev(kbuf->dev) || !old_valid_dev(kbuf->rdev))
88                 return -EOVERFLOW;
89         if (kbuf->size >= 0x7fffffff)
90                 return -EOVERFLOW;
91         if (verify_area(VERIFY_WRITE, ubuf, sizeof(struct compat_stat)) ||
92             __put_user (old_encode_dev(kbuf->dev), &ubuf->st_dev) ||
93             __put_user (kbuf->ino, &ubuf->st_ino) ||
94             __put_user (kbuf->mode, &ubuf->st_mode) ||
95             __put_user (kbuf->nlink, &ubuf->st_nlink) ||
96             __put_user (uid, &ubuf->st_uid) ||
97             __put_user (gid, &ubuf->st_gid) ||
98             __put_user (old_encode_dev(kbuf->rdev), &ubuf->st_rdev) ||
99             __put_user (kbuf->size, &ubuf->st_size) ||
100             __put_user (kbuf->atime.tv_sec, &ubuf->st_atime) ||
101             __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime_nsec) ||
102             __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime) ||
103             __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
104             __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime) ||
105             __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
106             __put_user (kbuf->blksize, &ubuf->st_blksize) ||
107             __put_user (kbuf->blocks, &ubuf->st_blocks))
108                 return -EFAULT;
109         return 0;
110 }
111
112 asmlinkage long
113 sys32_truncate64(char __user * filename, unsigned long offset_low, unsigned long offset_high)
114 {
115        return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
116 }
117
118 asmlinkage long
119 sys32_ftruncate64(unsigned int fd, unsigned long offset_low, unsigned long offset_high)
120 {
121        return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
122 }
123
124 /* Another set for IA32/LFS -- x86_64 struct stat is different due to 
125    support for 64bit inode numbers. */
126
127 static int
128 cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
129 {
130         typeof(ubuf->st_uid) uid = 0;
131         typeof(ubuf->st_gid) gid = 0;
132         SET_UID(uid, stat->uid);
133         SET_GID(gid, stat->gid);
134         if (verify_area(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
135             __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
136             __put_user (stat->ino, &ubuf->__st_ino) ||
137             __put_user (stat->ino, &ubuf->st_ino) ||
138             __put_user (stat->mode, &ubuf->st_mode) ||
139             __put_user (stat->nlink, &ubuf->st_nlink) ||
140             __put_user (uid, &ubuf->st_uid) ||
141             __put_user (gid, &ubuf->st_gid) ||
142             __put_user (huge_encode_dev(stat->rdev), &ubuf->st_rdev) ||
143             __put_user (stat->size, &ubuf->st_size) ||
144             __put_user (stat->atime.tv_sec, &ubuf->st_atime) ||
145             __put_user (stat->atime.tv_nsec, &ubuf->st_atime_nsec) ||
146             __put_user (stat->mtime.tv_sec, &ubuf->st_mtime) ||
147             __put_user (stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
148             __put_user (stat->ctime.tv_sec, &ubuf->st_ctime) ||
149             __put_user (stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
150             __put_user (stat->blksize, &ubuf->st_blksize) ||
151             __put_user (stat->blocks, &ubuf->st_blocks))
152                 return -EFAULT;
153         return 0;
154 }
155
156 asmlinkage long
157 sys32_stat64(char __user * filename, struct stat64 __user *statbuf)
158 {
159         struct kstat stat;
160         int ret = vfs_stat(filename, &stat);
161         if (!ret)
162                 ret = cp_stat64(statbuf, &stat);
163         return ret;
164 }
165
166 asmlinkage long
167 sys32_lstat64(char __user * filename, struct stat64 __user *statbuf)
168 {
169         struct kstat stat;
170         int ret = vfs_lstat(filename, &stat);
171         if (!ret)
172                 ret = cp_stat64(statbuf, &stat);
173         return ret;
174 }
175
176 asmlinkage long
177 sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
178 {
179         struct kstat stat;
180         int ret = vfs_fstat(fd, &stat);
181         if (!ret)
182                 ret = cp_stat64(statbuf, &stat);
183         return ret;
184 }
185
186 /*
187  * Linux/i386 didn't use to be able to handle more than
188  * 4 system call parameters, so these system calls used a memory
189  * block for parameter passing..
190  */
191
192 struct mmap_arg_struct {
193         unsigned int addr;
194         unsigned int len;
195         unsigned int prot;
196         unsigned int flags;
197         unsigned int fd;
198         unsigned int offset;
199 };
200
201 asmlinkage long
202 sys32_mmap(struct mmap_arg_struct __user *arg)
203 {
204         struct mmap_arg_struct a;
205         struct file *file = NULL;
206         unsigned long retval;
207         struct mm_struct *mm ;
208
209         if (copy_from_user(&a, arg, sizeof(a)))
210                 return -EFAULT;
211
212         if (a.offset & ~PAGE_MASK)
213                 return -EINVAL; 
214
215         if (!(a.flags & MAP_ANONYMOUS)) {
216                 file = fget(a.fd);
217                 if (!file)
218                         return -EBADF;
219         }
220         
221         if (a.prot & PROT_READ) 
222                 a.prot |= vm_force_exec32;
223
224         mm = current->mm; 
225         down_write(&mm->mmap_sem); 
226         retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT);
227         if (file)
228                 fput(file);
229
230         up_write(&mm->mmap_sem); 
231
232         return retval;
233 }
234
235 asmlinkage long 
236 sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
237 {
238         if (prot & PROT_READ) 
239                 prot |= vm_force_exec32;
240         return sys_mprotect(start,len,prot); 
241 }
242
243 asmlinkage long
244 sys32_pipe(int __user *fd)
245 {
246         int retval;
247         int fds[2];
248
249         retval = do_pipe(fds);
250         if (retval)
251                 goto out;
252         if (copy_to_user(fd, fds, sizeof(fds)))
253                 retval = -EFAULT;
254   out:
255         return retval;
256 }
257
258 asmlinkage long
259 sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
260                    struct sigaction32 __user *oact,  unsigned int sigsetsize)
261 {
262         struct k_sigaction new_ka, old_ka;
263         int ret;
264         compat_sigset_t set32;
265
266         /* XXX: Don't preclude handling different sized sigset_t's.  */
267         if (sigsetsize != sizeof(compat_sigset_t))
268                 return -EINVAL;
269
270         if (act) {
271                 compat_uptr_t handler, restorer;
272
273                 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
274                     __get_user(handler, &act->sa_handler) ||
275                     __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
276                     __get_user(restorer, &act->sa_restorer)||
277                     __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t)))
278                         return -EFAULT;
279                 new_ka.sa.sa_handler = compat_ptr(handler);
280                 new_ka.sa.sa_restorer = compat_ptr(restorer);
281                 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
282                 switch (_NSIG_WORDS) {
283                 case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
284                                 | (((long)set32.sig[7]) << 32);
285                 case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
286                                 | (((long)set32.sig[5]) << 32);
287                 case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
288                                 | (((long)set32.sig[3]) << 32);
289                 case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
290                                 | (((long)set32.sig[1]) << 32);
291                 }
292         }
293
294         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
295
296         if (!ret && oact) {
297                 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
298                 switch (_NSIG_WORDS) {
299                 case 4:
300                         set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
301                         set32.sig[6] = old_ka.sa.sa_mask.sig[3];
302                 case 3:
303                         set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
304                         set32.sig[4] = old_ka.sa.sa_mask.sig[2];
305                 case 2:
306                         set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
307                         set32.sig[2] = old_ka.sa.sa_mask.sig[1];
308                 case 1:
309                         set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
310                         set32.sig[0] = old_ka.sa.sa_mask.sig[0];
311                 }
312                 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
313                     __put_user((long)old_ka.sa.sa_handler, &oact->sa_handler) ||
314                     __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer) ||
315                     __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
316                     __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t)))
317                         return -EFAULT;
318         }
319
320         return ret;
321 }
322
323 asmlinkage long
324 sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
325 {
326         struct k_sigaction new_ka, old_ka;
327         int ret;
328
329         if (act) {
330                 compat_old_sigset_t mask;
331                 compat_uptr_t handler, restorer;
332
333                 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
334                     __get_user(handler, &act->sa_handler) ||
335                     __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
336                     __get_user(restorer, &act->sa_restorer) ||
337                     __get_user(mask, &act->sa_mask))
338                         return -EFAULT;
339
340                 new_ka.sa.sa_handler = compat_ptr(handler);
341                 new_ka.sa.sa_restorer = compat_ptr(restorer);
342
343                 siginitset(&new_ka.sa.sa_mask, mask);
344         }
345
346         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
347
348         if (!ret && oact) {
349                 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
350                     __put_user((long)old_ka.sa.sa_handler, &oact->sa_handler) ||
351                     __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer) ||
352                     __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
353                     __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
354                         return -EFAULT;
355         }
356
357         return ret;
358 }
359
360 asmlinkage long
361 sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
362                         compat_sigset_t __user *oset, unsigned int sigsetsize)
363 {
364         sigset_t s;
365         compat_sigset_t s32;
366         int ret;
367         mm_segment_t old_fs = get_fs();
368         
369         if (set) {
370                 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
371                         return -EFAULT;
372                 switch (_NSIG_WORDS) {
373                 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
374                 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
375                 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
376                 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
377                 }
378         }
379         set_fs (KERNEL_DS);
380         ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL,
381                                  sigsetsize); 
382         set_fs (old_fs);
383         if (ret) return ret;
384         if (oset) {
385                 switch (_NSIG_WORDS) {
386                 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
387                 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
388                 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
389                 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
390                 }
391                 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
392                         return -EFAULT;
393         }
394         return 0;
395 }
396
397 static inline long
398 get_tv32(struct timeval *o, struct compat_timeval __user *i)
399 {
400         int err = -EFAULT; 
401         if (access_ok(VERIFY_READ, i, sizeof(*i))) { 
402                 err = __get_user(o->tv_sec, &i->tv_sec);
403                 err |= __get_user(o->tv_usec, &i->tv_usec);
404         }
405         return err; 
406 }
407
408 static inline long
409 put_tv32(struct compat_timeval __user *o, struct timeval *i)
410 {
411         int err = -EFAULT;
412         if (access_ok(VERIFY_WRITE, o, sizeof(*o))) { 
413                 err = __put_user(i->tv_sec, &o->tv_sec);
414                 err |= __put_user(i->tv_usec, &o->tv_usec);
415         } 
416         return err; 
417 }
418
419 extern int do_setitimer(int which, struct itimerval *, struct itimerval *);
420
421 asmlinkage long
422 sys32_alarm(unsigned int seconds)
423 {
424         struct itimerval it_new, it_old;
425         unsigned int oldalarm;
426
427         it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
428         it_new.it_value.tv_sec = seconds;
429         it_new.it_value.tv_usec = 0;
430         do_setitimer(ITIMER_REAL, &it_new, &it_old);
431         oldalarm = it_old.it_value.tv_sec;
432         /* ehhh.. We can't return 0 if we have an alarm pending.. */
433         /* And we'd better return too much than too little anyway */
434         if (it_old.it_value.tv_usec)
435                 oldalarm++;
436         return oldalarm;
437 }
438
439 /* Translations due to time_t size differences.  Which affects all
440    sorts of things, like timeval and itimerval.  */
441
442 extern struct timezone sys_tz;
443
444 asmlinkage long
445 sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
446 {
447         if (tv) {
448                 struct timeval ktv;
449                 do_gettimeofday(&ktv);
450                 if (put_tv32(tv, &ktv))
451                         return -EFAULT;
452         }
453         if (tz) {
454                 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
455                         return -EFAULT;
456         }
457         return 0;
458 }
459
460 asmlinkage long
461 sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
462 {
463         struct timeval ktv;
464         struct timespec kts;
465         struct timezone ktz;
466
467         if (tv) {
468                 if (get_tv32(&ktv, tv))
469                         return -EFAULT;
470                 kts.tv_sec = ktv.tv_sec;
471                 kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
472         }
473         if (tz) {
474                 if (copy_from_user(&ktz, tz, sizeof(ktz)))
475                         return -EFAULT;
476         }
477
478         return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
479 }
480
481 struct linux32_dirent {
482         u32     d_ino;
483         u32     d_off;
484         u16     d_reclen;
485         char    d_name[1];
486 };
487
488 struct old_linux32_dirent {
489         u32     d_ino;
490         u32     d_offset;
491         u16     d_namlen;
492         char    d_name[1];
493 };
494
495 struct getdents32_callback {
496         struct linux32_dirent __user * current_dir;
497         struct linux32_dirent __user * previous;
498         int count;
499         int error;
500 };
501
502 struct readdir32_callback {
503         struct old_linux32_dirent __user * dirent;
504         int count;
505 };
506
507 static int
508 filldir32 (void *__buf, const char *name, int namlen, loff_t offset, ino_t ino,
509            unsigned int d_type)
510 {
511         struct linux32_dirent __user * dirent;
512         struct getdents32_callback * buf = (struct getdents32_callback *) __buf;
513         int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2, 4);
514
515         buf->error = -EINVAL;   /* only used if we fail.. */
516         if (reclen > buf->count)
517                 return -EINVAL;
518         dirent = buf->previous;
519         if (dirent)
520                 put_user(offset, &dirent->d_off);
521         dirent = buf->current_dir;
522         buf->previous = dirent;
523         put_user(ino, &dirent->d_ino);
524         put_user(reclen, &dirent->d_reclen);
525         copy_to_user(dirent->d_name, name, namlen);
526         put_user(0, dirent->d_name + namlen);
527         put_user(d_type, (char __user *)dirent + reclen - 1); 
528         dirent = ((void __user *)dirent) + reclen;
529         buf->current_dir = dirent;
530         buf->count -= reclen;
531         return 0;
532 }
533
534 asmlinkage long
535 sys32_getdents (unsigned int fd, void __user * dirent, unsigned int count)
536 {
537         struct file * file;
538         struct linux32_dirent __user * lastdirent;
539         struct getdents32_callback buf;
540         int error;
541
542         error = -EBADF;
543         file = fget(fd);
544         if (!file)
545                 goto out;
546
547         buf.current_dir = (struct linux32_dirent __user *) dirent;
548         buf.previous = NULL;
549         buf.count = count;
550         buf.error = 0;
551
552         error = vfs_readdir(file, filldir32, &buf);
553         if (error < 0)
554                 goto out_putf;
555         error = buf.error;
556         lastdirent = buf.previous;
557         if (lastdirent) {
558                 put_user(file->f_pos, &lastdirent->d_off);
559                 error = count - buf.count;
560         }
561
562 out_putf:
563         fput(file);
564 out:
565         return error;
566 }
567
568 static int
569 fillonedir32 (void * __buf, const char * name, int namlen, loff_t offset, ino_t ino, unsigned d_type)
570 {
571         struct readdir32_callback * buf = (struct readdir32_callback *) __buf;
572         struct old_linux32_dirent __user * dirent;
573
574         if (buf->count)
575                 return -EINVAL;
576         buf->count++;
577         dirent = buf->dirent;
578         put_user(ino, &dirent->d_ino);
579         put_user(offset, &dirent->d_offset);
580         put_user(namlen, &dirent->d_namlen);
581         copy_to_user(dirent->d_name, name, namlen);
582         put_user(0, dirent->d_name + namlen);
583         return 0;
584 }
585
586 asmlinkage long
587 sys32_oldreaddir (unsigned int fd, void __user * dirent, unsigned int count)
588 {
589         int error;
590         struct file * file;
591         struct readdir32_callback buf;
592
593         error = -EBADF;
594         file = fget(fd);
595         if (!file)
596                 goto out;
597
598         buf.count = 0;
599         buf.dirent = dirent;
600
601         error = vfs_readdir(file, fillonedir32, &buf);
602         if (error >= 0)
603                 error = buf.count;
604         fput(file);
605 out:
606         return error;
607 }
608
609 struct sel_arg_struct {
610         unsigned int n;
611         unsigned int inp;
612         unsigned int outp;
613         unsigned int exp;
614         unsigned int tvp;
615 };
616
617 asmlinkage long
618 sys32_old_select(struct sel_arg_struct __user *arg)
619 {
620         struct sel_arg_struct a;
621
622         if (copy_from_user(&a, arg, sizeof(a)))
623                 return -EFAULT;
624         return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
625                                  compat_ptr(a.exp), compat_ptr(a.tvp));
626 }
627
628 /*
629  * sys_time() can be implemented in user-level using
630  * sys_gettimeofday().  x86-64 did this but i386 Linux did not
631  * so we have to implement this system call here.
632  */
633 asmlinkage long sys32_time(int __user * tloc)
634 {
635         int i;
636         struct timeval tv;
637
638         do_gettimeofday(&tv);
639         i = tv.tv_sec;
640
641         if (tloc) {
642                 if (put_user(i,tloc))
643                         i = -EFAULT;
644         }
645         return i;
646 }
647
648 extern asmlinkage long
649 compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
650                  struct compat_rusage *ru);
651
652 asmlinkage long
653 sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
654 {
655         return compat_sys_wait4(pid, stat_addr, options, NULL);
656 }
657
658 int sys32_ni_syscall(int call)
659
660         struct task_struct *me = current;
661         static char lastcomm[8];
662         if (strcmp(lastcomm, me->comm)) {
663         printk(KERN_INFO "IA32 syscall %d from %s not implemented\n", call,
664                current->comm);
665                 strcpy(lastcomm, me->comm); 
666         } 
667         return -ENOSYS;        
668
669
670 /* 32-bit timeval and related flotsam.  */
671
672 asmlinkage long
673 sys32_sysfs(int option, u32 arg1, u32 arg2)
674 {
675         return sys_sysfs(option, arg1, arg2);
676 }
677
678 struct sysinfo32 {
679         s32 uptime;
680         u32 loads[3];
681         u32 totalram;
682         u32 freeram;
683         u32 sharedram;
684         u32 bufferram;
685         u32 totalswap;
686         u32 freeswap;
687         unsigned short procs;
688         unsigned short pad; 
689         u32 totalhigh;
690         u32 freehigh;
691         u32 mem_unit;
692         char _f[20-2*sizeof(u32)-sizeof(int)];
693 };
694
695 asmlinkage long
696 sys32_sysinfo(struct sysinfo32 __user *info)
697 {
698         struct sysinfo s;
699         int ret;
700         mm_segment_t old_fs = get_fs ();
701         int bitcount = 0;
702         
703         set_fs (KERNEL_DS);
704         ret = sys_sysinfo(&s);
705         set_fs (old_fs);
706
707         /* Check to see if any memory value is too large for 32-bit and scale
708          *  down if needed
709          */
710         if ((s.totalram >> 32) || (s.totalswap >> 32)) {
711                 while (s.mem_unit < PAGE_SIZE) {
712                         s.mem_unit <<= 1;
713                         bitcount++;
714                 }
715                 s.totalram >>= bitcount;
716                 s.freeram >>= bitcount;
717                 s.sharedram >>= bitcount;
718                 s.bufferram >>= bitcount;
719                 s.totalswap >>= bitcount;
720                 s.freeswap >>= bitcount;
721                 s.totalhigh >>= bitcount;
722                 s.freehigh >>= bitcount;
723         }
724
725         if (verify_area(VERIFY_WRITE, info, sizeof(struct sysinfo32)) ||
726             __put_user (s.uptime, &info->uptime) ||
727             __put_user (s.loads[0], &info->loads[0]) ||
728             __put_user (s.loads[1], &info->loads[1]) ||
729             __put_user (s.loads[2], &info->loads[2]) ||
730             __put_user (s.totalram, &info->totalram) ||
731             __put_user (s.freeram, &info->freeram) ||
732             __put_user (s.sharedram, &info->sharedram) ||
733             __put_user (s.bufferram, &info->bufferram) ||
734             __put_user (s.totalswap, &info->totalswap) ||
735             __put_user (s.freeswap, &info->freeswap) ||
736             __put_user (s.procs, &info->procs) ||
737             __put_user (s.totalhigh, &info->totalhigh) || 
738             __put_user (s.freehigh, &info->freehigh) ||
739             __put_user (s.mem_unit, &info->mem_unit))
740                 return -EFAULT;
741         return 0;
742 }
743                 
744 asmlinkage long
745 sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
746 {
747         struct timespec t;
748         int ret;
749         mm_segment_t old_fs = get_fs ();
750         
751         set_fs (KERNEL_DS);
752         ret = sys_sched_rr_get_interval(pid, &t);
753         set_fs (old_fs);
754         if (put_compat_timespec(&t, interval))
755                 return -EFAULT;
756         return ret;
757 }
758
759 asmlinkage long
760 sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
761 {
762         sigset_t s;
763         compat_sigset_t s32;
764         int ret;
765         mm_segment_t old_fs = get_fs();
766                 
767         set_fs (KERNEL_DS);
768         ret = sys_rt_sigpending(&s, sigsetsize);
769         set_fs (old_fs);
770         if (!ret) {
771                 switch (_NSIG_WORDS) {
772                 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
773                 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
774                 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
775                 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
776                 }
777                 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
778                         return -EFAULT;
779         }
780         return ret;
781 }
782
783
784 asmlinkage long
785 sys32_rt_sigtimedwait(compat_sigset_t __user *uthese, siginfo_t32 __user *uinfo,
786                       struct compat_timespec __user *uts, compat_size_t sigsetsize)
787 {
788         sigset_t s;
789         compat_sigset_t s32;
790         struct timespec t;
791         int ret;
792         mm_segment_t old_fs = get_fs();
793         siginfo_t info;
794                 
795         if (copy_from_user (&s32, uthese, sizeof(compat_sigset_t)))
796                 return -EFAULT;
797         switch (_NSIG_WORDS) {
798         case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
799         case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
800         case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
801         case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
802         }
803         if (uts && get_compat_timespec(&t, uts))
804                 return -EFAULT;
805         if (uinfo) {
806                 /* stop data leak to user space in case of structure fill mismatch
807                  * between sys_rt_sigtimedwait & ia32_copy_siginfo_to_user.
808                  */
809                 memset(&info, 0, sizeof(info));
810         }
811         set_fs (KERNEL_DS);
812         ret = sys_rt_sigtimedwait(&s, uinfo ? &info : NULL, uts ? &t : NULL,
813                         sigsetsize);
814         set_fs (old_fs);
815         if (ret >= 0 && uinfo) {
816                 if (ia32_copy_siginfo_to_user(uinfo, &info))
817                         return -EFAULT;
818         }
819         return ret;
820 }
821
822 asmlinkage long
823 sys32_rt_sigqueueinfo(int pid, int sig, siginfo_t32 __user *uinfo)
824 {
825         siginfo_t info;
826         int ret;
827         mm_segment_t old_fs = get_fs();
828         
829         if (ia32_copy_siginfo_from_user(&info, uinfo))
830                 return -EFAULT;
831         set_fs (KERNEL_DS);
832         ret = sys_rt_sigqueueinfo(pid, sig, &info);
833         set_fs (old_fs);
834         return ret;
835 }
836
837 /* These are here just in case some old ia32 binary calls it. */
838 asmlinkage long
839 sys32_pause(void)
840 {
841         current->state = TASK_INTERRUPTIBLE;
842         schedule();
843         return -ERESTARTNOHAND;
844 }
845
846
847 struct sysctl_ia32 {
848         unsigned int    name;
849         int             nlen;
850         unsigned int    oldval;
851         unsigned int    oldlenp;
852         unsigned int    newval;
853         unsigned int    newlen;
854         unsigned int    __unused[4];
855 };
856
857
858 asmlinkage long
859 sys32_sysctl(struct sysctl_ia32 __user *args32)
860 {
861 #ifndef CONFIG_SYSCTL
862         return -ENOSYS; 
863 #else
864         struct sysctl_ia32 a32;
865         mm_segment_t old_fs = get_fs ();
866         void *oldvalp, *newvalp;
867         size_t oldlen;
868         int *namep;
869         long ret;
870         extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
871                      void *newval, size_t newlen);
872
873
874         if (copy_from_user(&a32, args32, sizeof (a32)))
875                 return -EFAULT;
876
877         /*
878          * We need to pre-validate these because we have to disable address checking
879          * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
880          * user specifying bad addresses here.  Well, since we're dealing with 32 bit
881          * addresses, we KNOW that access_ok() will always succeed, so this is an
882          * expensive NOP, but so what...
883          */
884         namep = (int *) A(a32.name);
885         oldvalp = (void *) A(a32.oldval);
886         newvalp = (void *) A(a32.newval);
887
888         if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
889             || !access_ok(VERIFY_WRITE, namep, 0)
890             || !access_ok(VERIFY_WRITE, oldvalp, 0)
891             || !access_ok(VERIFY_WRITE, newvalp, 0))
892                 return -EFAULT;
893
894         set_fs(KERNEL_DS);
895         lock_kernel();
896         ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, newvalp, (size_t) a32.newlen);
897         unlock_kernel();
898         set_fs(old_fs);
899
900         if (oldvalp && put_user (oldlen, (int __user *)compat_ptr(a32.oldlenp)))
901                 return -EFAULT;
902
903         return ret;
904 #endif
905 }
906
907 /* warning: next two assume little endian */ 
908 asmlinkage long
909 sys32_pread(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
910 {
911         return sys_pread64(fd, ubuf, count,
912                          ((loff_t)AA(poshi) << 32) | AA(poslo));
913 }
914
915 asmlinkage long
916 sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
917 {
918         return sys_pwrite64(fd, ubuf, count,
919                           ((loff_t)AA(poshi) << 32) | AA(poslo));
920 }
921
922
923 asmlinkage long
924 sys32_personality(unsigned long personality)
925 {
926         int ret;
927         if (personality(current->personality) == PER_LINUX32 && 
928                 personality == PER_LINUX)
929                 personality = PER_LINUX32;
930         ret = sys_personality(personality);
931         if (ret == PER_LINUX32)
932                 ret = PER_LINUX;
933         return ret;
934 }
935
936 asmlinkage long
937 sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
938 {
939         mm_segment_t old_fs = get_fs();
940         int ret;
941         off_t of;
942         
943         if (offset && get_user(of, offset))
944                 return -EFAULT;
945                 
946         set_fs(KERNEL_DS);
947         ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
948         set_fs(old_fs);
949         
950         if (!ret && offset && put_user(of, offset))
951                 return -EFAULT;
952                 
953         return ret;
954 }
955
956 /* Handle adjtimex compatibility. */
957
958 struct timex32 {
959         u32 modes;
960         s32 offset, freq, maxerror, esterror;
961         s32 status, constant, precision, tolerance;
962         struct compat_timeval time;
963         s32 tick;
964         s32 ppsfreq, jitter, shift, stabil;
965         s32 jitcnt, calcnt, errcnt, stbcnt;
966         s32  :32; s32  :32; s32  :32; s32  :32;
967         s32  :32; s32  :32; s32  :32; s32  :32;
968         s32  :32; s32  :32; s32  :32; s32  :32;
969 };
970
971 extern int do_adjtimex(struct timex *);
972
973 asmlinkage long
974 sys32_adjtimex(struct timex32 __user *utp)
975 {
976         struct timex txc;
977         int ret;
978
979         memset(&txc, 0, sizeof(struct timex));
980
981         if(verify_area(VERIFY_READ, utp, sizeof(struct timex32)) ||
982            __get_user(txc.modes, &utp->modes) ||
983            __get_user(txc.offset, &utp->offset) ||
984            __get_user(txc.freq, &utp->freq) ||
985            __get_user(txc.maxerror, &utp->maxerror) ||
986            __get_user(txc.esterror, &utp->esterror) ||
987            __get_user(txc.status, &utp->status) ||
988            __get_user(txc.constant, &utp->constant) ||
989            __get_user(txc.precision, &utp->precision) ||
990            __get_user(txc.tolerance, &utp->tolerance) ||
991            __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
992            __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
993            __get_user(txc.tick, &utp->tick) ||
994            __get_user(txc.ppsfreq, &utp->ppsfreq) ||
995            __get_user(txc.jitter, &utp->jitter) ||
996            __get_user(txc.shift, &utp->shift) ||
997            __get_user(txc.stabil, &utp->stabil) ||
998            __get_user(txc.jitcnt, &utp->jitcnt) ||
999            __get_user(txc.calcnt, &utp->calcnt) ||
1000            __get_user(txc.errcnt, &utp->errcnt) ||
1001            __get_user(txc.stbcnt, &utp->stbcnt))
1002                 return -EFAULT;
1003
1004         ret = do_adjtimex(&txc);
1005
1006         if(verify_area(VERIFY_WRITE, utp, sizeof(struct timex32)) ||
1007            __put_user(txc.modes, &utp->modes) ||
1008            __put_user(txc.offset, &utp->offset) ||
1009            __put_user(txc.freq, &utp->freq) ||
1010            __put_user(txc.maxerror, &utp->maxerror) ||
1011            __put_user(txc.esterror, &utp->esterror) ||
1012            __put_user(txc.status, &utp->status) ||
1013            __put_user(txc.constant, &utp->constant) ||
1014            __put_user(txc.precision, &utp->precision) ||
1015            __put_user(txc.tolerance, &utp->tolerance) ||
1016            __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
1017            __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
1018            __put_user(txc.tick, &utp->tick) ||
1019            __put_user(txc.ppsfreq, &utp->ppsfreq) ||
1020            __put_user(txc.jitter, &utp->jitter) ||
1021            __put_user(txc.shift, &utp->shift) ||
1022            __put_user(txc.stabil, &utp->stabil) ||
1023            __put_user(txc.jitcnt, &utp->jitcnt) ||
1024            __put_user(txc.calcnt, &utp->calcnt) ||
1025            __put_user(txc.errcnt, &utp->errcnt) ||
1026            __put_user(txc.stbcnt, &utp->stbcnt))
1027                 ret = -EFAULT;
1028
1029         return ret;
1030 }
1031
1032 asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
1033         unsigned long prot, unsigned long flags,
1034         unsigned long fd, unsigned long pgoff)
1035 {
1036         struct mm_struct *mm = current->mm;
1037         unsigned long error;
1038         struct file * file = NULL;
1039
1040         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1041         if (!(flags & MAP_ANONYMOUS)) {
1042                 file = fget(fd);
1043                 if (!file)
1044                         return -EBADF;
1045         }
1046
1047         if (prot & PROT_READ)
1048                 prot |= vm_force_exec32;
1049
1050         down_write(&mm->mmap_sem);
1051         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1052         up_write(&mm->mmap_sem);
1053
1054         if (file)
1055                 fput(file);
1056         return error;
1057 }
1058
1059 asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
1060 {
1061         int error;
1062         struct new_utsname *ptr;
1063
1064         if (!name)
1065                 return -EFAULT;
1066         if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
1067                 return -EFAULT;
1068   
1069         down_read(&uts_sem);
1070         
1071         ptr = vx_new_utsname();
1072         error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
1073          __put_user(0,name->sysname+__OLD_UTS_LEN);
1074          __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
1075          __put_user(0,name->nodename+__OLD_UTS_LEN);
1076          __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
1077          __put_user(0,name->release+__OLD_UTS_LEN);
1078          __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
1079          __put_user(0,name->version+__OLD_UTS_LEN);
1080          { 
1081                  char *arch = "x86_64";
1082                  if (personality(current->personality) == PER_LINUX32)
1083                          arch = "i686";
1084                  
1085                  __copy_to_user(&name->machine,arch,strlen(arch)+1);
1086          }
1087         
1088          up_read(&uts_sem);
1089          
1090          error = error ? -EFAULT : 0;
1091          
1092          return error;
1093 }
1094
1095 long sys32_uname(struct old_utsname __user * name)
1096 {
1097         int err;
1098         if (!name)
1099                 return -EFAULT;
1100         down_read(&uts_sem);
1101         err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
1102         up_read(&uts_sem);
1103         if (personality(current->personality) == PER_LINUX32) 
1104                 err |= copy_to_user(&name->machine, "i686", 5);
1105         return err?-EFAULT:0;
1106 }
1107
1108 long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
1109 {
1110         struct ustat u;
1111         mm_segment_t seg;
1112         int ret;
1113         
1114         seg = get_fs(); 
1115         set_fs(KERNEL_DS); 
1116         ret = sys_ustat(dev,&u); 
1117         set_fs(seg);
1118         if (ret >= 0) { 
1119                 if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) || 
1120                     __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
1121                     __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
1122                     __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
1123                     __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
1124                         ret = -EFAULT;
1125         }
1126         return ret;
1127
1128
1129 asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
1130                              compat_uptr_t __user *envp, struct pt_regs *regs)
1131 {
1132         long error;
1133         char * filename;
1134
1135         filename = getname(name);
1136         error = PTR_ERR(filename);
1137         if (IS_ERR(filename))
1138                 return error;
1139         error = compat_do_execve(filename, argv, envp, regs);
1140         if (error == 0)
1141                 current->ptrace &= ~PT_DTRACE;
1142         putname(filename);
1143         return error;
1144 }
1145
1146 asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
1147                             struct pt_regs *regs)
1148 {
1149         void __user *parent_tid = (void __user *)regs->rdx;
1150         void __user *child_tid = (void __user *)regs->rdi;
1151         if (!newsp)
1152                 newsp = regs->rsp;
1153         return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
1154 }
1155
1156 asmlinkage long sys32_waitid(int which, compat_pid_t pid,
1157                              siginfo_t32 __user *uinfo, int options,
1158                              struct compat_rusage __user *uru)
1159 {
1160         siginfo_t info;
1161         struct rusage ru;
1162         long ret;
1163         mm_segment_t old_fs = get_fs();
1164
1165         info.si_signo = 0;
1166         set_fs (KERNEL_DS);
1167         ret = sys_waitid(which, pid, (siginfo_t __user *) &info, options,
1168                          uru ? &ru : NULL);
1169         set_fs (old_fs);
1170
1171         if (ret < 0 || info.si_signo == 0)
1172                 return ret;
1173
1174         if (uru && (ret = put_compat_rusage(&ru, uru)))
1175                 return ret;
1176
1177         BUG_ON(info.si_code & __SI_MASK);
1178         info.si_code |= __SI_CHLD;
1179         return ia32_copy_siginfo_to_user(uinfo, &info);
1180 }
1181
1182 /*
1183  * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
1184  */ 
1185
1186 long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
1187 {
1188         return sys_lseek(fd, offset, whence);
1189 }
1190
1191 long sys32_kill(int pid, int sig)
1192 {
1193         return sys_kill(pid, sig);
1194 }
1195  
1196
1197 long sys32_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
1198
1199         long ret; 
1200         aio_context_t ctx64;
1201         mm_segment_t oldfs = get_fs();  
1202         set_fs(KERNEL_DS); 
1203         ret = sys_io_setup(nr_reqs, &ctx64); 
1204         set_fs(oldfs); 
1205         /* truncating is ok because it's a user address */
1206         if (!ret) 
1207                 ret = put_user((u32)ctx64, ctx32p);
1208         return ret;
1209
1210
1211 asmlinkage long sys32_io_submit(aio_context_t ctx_id, int nr,
1212                    compat_uptr_t __user *iocbpp)
1213 {
1214         struct kioctx *ctx;
1215         long ret = 0;
1216         int i;
1217         
1218         if (unlikely(nr < 0))
1219                 return -EINVAL;
1220
1221         if (unlikely(!access_ok(VERIFY_READ, iocbpp, (nr*sizeof(*iocbpp)))))
1222                 return -EFAULT;
1223
1224         ctx = lookup_ioctx(ctx_id);
1225         if (unlikely(!ctx)) {
1226                 pr_debug("EINVAL: io_submit: invalid context id\n");
1227                 return -EINVAL; 
1228         } 
1229
1230         for (i=0; i<nr; i++) {
1231                 compat_uptr_t p32;
1232                 struct iocb __user *user_iocb;
1233                 struct iocb tmp;
1234
1235                 if (unlikely(__get_user(p32, iocbpp + i))) {
1236                         ret = -EFAULT;
1237                         break;
1238                 } 
1239                 user_iocb = compat_ptr(p32);
1240
1241                 if (unlikely(copy_from_user(&tmp, user_iocb, sizeof(tmp)))) {
1242                         ret = -EFAULT;
1243                         break;
1244                 }
1245
1246                 ret = io_submit_one(ctx, user_iocb, &tmp);
1247                 if (ret)
1248                         break;
1249         }
1250
1251         put_ioctx(ctx);
1252         return i ? i : ret;
1253 }
1254
1255
1256 asmlinkage long sys32_io_getevents(aio_context_t ctx_id,
1257                                  unsigned long min_nr,
1258                                  unsigned long nr,
1259                                  struct io_event __user *events,
1260                                  struct compat_timespec __user *timeout)
1261 {       
1262         long ret;
1263         mm_segment_t oldfs; 
1264         struct timespec t;
1265         /* Harden against bogus ptrace */
1266         if (nr >= 0xffffffff || 
1267             !access_ok(VERIFY_WRITE, events, nr * sizeof(struct io_event)))
1268                 return -EFAULT;
1269         if (timeout && get_compat_timespec(&t, timeout))
1270                 return -EFAULT; 
1271         oldfs = get_fs();
1272         set_fs(KERNEL_DS); 
1273         ret = sys_io_getevents(ctx_id,min_nr,nr,events,timeout ? &t : NULL); 
1274         set_fs(oldfs); 
1275         if (!ret && timeout && put_compat_timespec(&t, timeout))
1276                 return -EFAULT;                 
1277         return ret;
1278
1279
1280 asmlinkage long sys32_open(const char __user * filename, int flags, int mode)
1281 {
1282         char * tmp;
1283         int fd, error;
1284
1285         /* don't force O_LARGEFILE */
1286         tmp = getname(filename);
1287         fd = PTR_ERR(tmp);
1288         if (!IS_ERR(tmp)) {
1289                 fd = get_unused_fd();
1290                 if (fd >= 0) {
1291                         struct file *f = filp_open(tmp, flags, mode);
1292                         error = PTR_ERR(f);
1293                         if (IS_ERR(f)) {
1294                                 put_unused_fd(fd); 
1295                                 fd = error;
1296                         } else
1297                                 fd_install(fd, f);
1298                 }
1299                 putname(tmp);
1300         }
1301         return fd;
1302 }
1303
1304 struct sigevent32 { 
1305         u32 sigev_value;
1306         u32 sigev_signo; 
1307         u32 sigev_notify; 
1308         u32 payload[(64 / 4) - 3]; 
1309 }; 
1310
1311 extern asmlinkage long
1312 sys_timer_create(clockid_t which_clock,
1313                  struct sigevent __user *timer_event_spec,
1314                  timer_t __user * created_timer_id);
1315
1316 long
1317 sys32_timer_create(u32 clock, struct sigevent32 __user *se32, timer_t __user *timer_id)
1318 {
1319         struct sigevent __user *p = NULL;
1320         if (se32) { 
1321                 struct sigevent se;
1322                 p = compat_alloc_user_space(sizeof(struct sigevent));
1323                 memset(&se, 0, sizeof(struct sigevent)); 
1324                 if (get_user(se.sigev_value.sival_int,  &se32->sigev_value) ||
1325                     __get_user(se.sigev_signo, &se32->sigev_signo) ||
1326                     __get_user(se.sigev_notify, &se32->sigev_notify) ||
1327                     __copy_from_user(&se._sigev_un._pad, &se32->payload, 
1328                                      sizeof(se32->payload)) ||
1329                     copy_to_user(p, &se, sizeof(se)))
1330                         return -EFAULT;
1331         } 
1332         return sys_timer_create(clock, p, timer_id);
1333
1334
1335 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high, 
1336                         __u32 len_low, __u32 len_high, int advice)
1337
1338         return sys_fadvise64_64(fd,
1339                                (((u64)offset_high)<<32) | offset_low,
1340                                (((u64)len_high)<<32) | len_low,
1341                                advice); 
1342
1343
1344 long sys32_vm86_warning(void)
1345
1346         struct task_struct *me = current;
1347         static char lastcomm[8];
1348         if (strcmp(lastcomm, me->comm)) {
1349                 printk(KERN_INFO "%s: vm86 mode not supported on 64 bit kernel\n",
1350                        me->comm);
1351                 strcpy(lastcomm, me->comm); 
1352         } 
1353         return -ENOSYS;
1354
1355
1356 long sys32_quotactl(void)
1357
1358         struct task_struct *me = current;
1359         static char lastcomm[8];
1360         if (strcmp(lastcomm, me->comm)) {
1361                 printk(KERN_INFO "%s: 32bit quotactl not supported on 64 bit kernel\n",
1362                        me->comm);
1363                 strcpy(lastcomm, me->comm); 
1364         } 
1365         return -ENOSYS;
1366
1367
1368 long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
1369                           char __user * buf, size_t len)
1370 {
1371         return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);
1372 }
1373
1374 cond_syscall(sys32_ipc)
1375
1376 static int __init ia32_init (void)
1377 {
1378         printk("IA32 emulation $Id: sys_ia32.c,v 1.32 2002/03/24 13:02:28 ak Exp $\n");  
1379         return 0;
1380 }
1381
1382 __initcall(ia32_init);
1383
1384 extern unsigned long ia32_sys_call_table[];
1385 EXPORT_SYMBOL(ia32_sys_call_table);