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