2 * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on
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)
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.
17 * This file assumes that there is a hole at the end of user address space.
19 * Some of the functions are LE specific currently. These are hopefully all marked.
20 * This should be fixed.
23 #include <linux/config.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.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>
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/mman.h>
65 #include <asm/types.h>
66 #include <asm/uaccess.h>
67 #include <asm/semaphore.h>
69 #include <asm/atomic.h>
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)))
81 int cp_compat_stat(struct kstat *kbuf, struct compat_stat __user *ubuf)
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))
89 if (kbuf->size >= 0x7fffffff)
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))
113 sys32_truncate64(char __user * filename, unsigned long offset_low, unsigned long offset_high)
115 return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
119 sys32_ftruncate64(unsigned int fd, unsigned long offset_low, unsigned long offset_high)
121 return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
124 /* Another set for IA32/LFS -- x86_64 struct stat is different due to
125 support for 64bit inode numbers. */
128 cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
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))
157 sys32_stat64(char __user * filename, struct stat64 __user *statbuf)
160 int ret = vfs_stat(filename, &stat);
162 ret = cp_stat64(statbuf, &stat);
167 sys32_lstat64(char __user * filename, struct stat64 __user *statbuf)
170 int ret = vfs_lstat(filename, &stat);
172 ret = cp_stat64(statbuf, &stat);
177 sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
180 int ret = vfs_fstat(fd, &stat);
182 ret = cp_stat64(statbuf, &stat);
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..
192 struct mmap_arg_struct {
202 sys32_mmap(struct mmap_arg_struct __user *arg)
204 struct mmap_arg_struct a;
205 struct file *file = NULL;
206 unsigned long retval;
207 struct mm_struct *mm ;
209 if (copy_from_user(&a, arg, sizeof(a)))
212 if (a.offset & ~PAGE_MASK)
215 if (a.flags & MAP_FIXED) {
216 if (a.len > IA32_PAGE_OFFSET)
218 if (a.addr > IA32_PAGE_OFFSET - a.len)
222 if (!(a.flags & MAP_ANONYMOUS)) {
229 down_write(&mm->mmap_sem);
230 retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT);
234 up_write(&mm->mmap_sem);
240 sys32_munmap(unsigned long start, unsigned long len)
242 if ((start + len) > IA32_PAGE_OFFSET)
244 return sys_munmap(start, len);
248 sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
250 if ((start + PAGE_ALIGN(len)) >> 32)
252 return sys_mprotect(start,len,prot);
255 sys32_brk(unsigned long brk)
257 if (brk > IA32_PAGE_OFFSET)
262 extern unsigned long do_mremap(unsigned long addr,
263 unsigned long old_len, unsigned long new_len,
264 unsigned long flags, unsigned long new_addr);
266 asmlinkage unsigned long sys32_mremap(unsigned long addr,
267 unsigned long old_len, unsigned long new_len,
268 unsigned long flags, unsigned long new_addr)
270 struct vm_area_struct *vma;
271 unsigned long ret = -EINVAL;
273 if (old_len > IA32_PAGE_OFFSET || new_len > IA32_PAGE_OFFSET)
275 if (addr > IA32_PAGE_OFFSET - old_len)
277 down_write(¤t->mm->mmap_sem);
278 if (flags & MREMAP_FIXED) {
279 if (new_addr > IA32_PAGE_OFFSET - new_len)
281 } else if (addr > IA32_PAGE_OFFSET - new_len) {
282 unsigned long map_flags = 0;
283 struct file *file = NULL;
286 if (!(flags & MREMAP_MAYMOVE))
289 vma = find_vma(current->mm, addr);
291 if (vma->vm_flags & VM_SHARED)
292 map_flags |= MAP_SHARED;
296 /* MREMAP_FIXED checked above. */
297 new_addr = get_unmapped_area(file, addr, new_len,
298 vma ? vma->vm_pgoff : 0, map_flags);
300 if (new_addr & ~PAGE_MASK)
302 flags |= MREMAP_FIXED;
304 ret = do_mremap(addr, old_len, new_len, flags, new_addr);
306 up_write(¤t->mm->mmap_sem);
313 sys32_pipe(int __user *fd)
318 retval = do_pipe(fds);
321 if (copy_to_user(fd, fds, sizeof(fds)))
328 sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
329 struct sigaction32 __user *oact, unsigned int sigsetsize)
331 struct k_sigaction new_ka, old_ka;
333 compat_sigset_t set32;
335 /* XXX: Don't preclude handling different sized sigset_t's. */
336 if (sigsetsize != sizeof(compat_sigset_t))
340 compat_uptr_t handler, restorer;
342 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
343 __get_user(handler, &act->sa_handler) ||
344 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
345 __get_user(restorer, &act->sa_restorer)||
346 __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t)))
348 new_ka.sa.sa_handler = compat_ptr(handler);
349 new_ka.sa.sa_restorer = compat_ptr(restorer);
350 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
351 switch (_NSIG_WORDS) {
352 case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
353 | (((long)set32.sig[7]) << 32);
354 case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
355 | (((long)set32.sig[5]) << 32);
356 case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
357 | (((long)set32.sig[3]) << 32);
358 case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
359 | (((long)set32.sig[1]) << 32);
363 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
366 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
367 switch (_NSIG_WORDS) {
369 set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
370 set32.sig[6] = old_ka.sa.sa_mask.sig[3];
372 set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
373 set32.sig[4] = old_ka.sa.sa_mask.sig[2];
375 set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
376 set32.sig[2] = old_ka.sa.sa_mask.sig[1];
378 set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
379 set32.sig[0] = old_ka.sa.sa_mask.sig[0];
381 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
382 __put_user((long)old_ka.sa.sa_handler, &oact->sa_handler) ||
383 __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer) ||
384 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
385 __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t)))
393 sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
395 struct k_sigaction new_ka, old_ka;
399 compat_old_sigset_t mask;
400 compat_uptr_t handler, restorer;
402 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
403 __get_user(handler, &act->sa_handler) ||
404 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
405 __get_user(restorer, &act->sa_restorer) ||
406 __get_user(mask, &act->sa_mask))
409 new_ka.sa.sa_handler = compat_ptr(handler);
410 new_ka.sa.sa_restorer = compat_ptr(restorer);
412 siginitset(&new_ka.sa.sa_mask, mask);
415 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
418 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
419 __put_user((long)old_ka.sa.sa_handler, &oact->sa_handler) ||
420 __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer) ||
421 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
422 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
430 sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
431 compat_sigset_t __user *oset, unsigned int sigsetsize)
436 mm_segment_t old_fs = get_fs();
439 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
441 switch (_NSIG_WORDS) {
442 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
443 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
444 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
445 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
449 ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL,
454 switch (_NSIG_WORDS) {
455 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
456 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
457 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
458 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
460 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
467 get_tv32(struct timeval *o, struct compat_timeval __user *i)
470 if (access_ok(VERIFY_READ, i, sizeof(*i))) {
471 err = __get_user(o->tv_sec, &i->tv_sec);
472 err |= __get_user(o->tv_usec, &i->tv_usec);
478 put_tv32(struct compat_timeval __user *o, struct timeval *i)
481 if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
482 err = __put_user(i->tv_sec, &o->tv_sec);
483 err |= __put_user(i->tv_usec, &o->tv_usec);
488 extern int do_setitimer(int which, struct itimerval *, struct itimerval *);
491 sys32_alarm(unsigned int seconds)
493 struct itimerval it_new, it_old;
494 unsigned int oldalarm;
496 it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
497 it_new.it_value.tv_sec = seconds;
498 it_new.it_value.tv_usec = 0;
499 do_setitimer(ITIMER_REAL, &it_new, &it_old);
500 oldalarm = it_old.it_value.tv_sec;
501 /* ehhh.. We can't return 0 if we have an alarm pending.. */
502 /* And we'd better return too much than too little anyway */
503 if (it_old.it_value.tv_usec)
508 /* Translations due to time_t size differences. Which affects all
509 sorts of things, like timeval and itimerval. */
511 extern struct timezone sys_tz;
514 sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
518 do_gettimeofday(&ktv);
519 if (put_tv32(tv, &ktv))
523 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
530 sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
537 if (get_tv32(&ktv, tv))
539 kts.tv_sec = ktv.tv_sec;
540 kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
543 if (copy_from_user(&ktz, tz, sizeof(ktz)))
547 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
550 struct sel_arg_struct {
559 sys32_old_select(struct sel_arg_struct __user *arg)
561 struct sel_arg_struct a;
563 if (copy_from_user(&a, arg, sizeof(a)))
565 return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
566 compat_ptr(a.exp), compat_ptr(a.tvp));
570 * sys_time() can be implemented in user-level using
571 * sys_gettimeofday(). x86-64 did this but i386 Linux did not
572 * so we have to implement this system call here.
574 asmlinkage long sys32_time(int __user * tloc)
579 do_gettimeofday(&tv);
583 if (put_user(i,tloc))
589 extern asmlinkage long
590 compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
591 struct compat_rusage *ru);
594 sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
596 return compat_sys_wait4(pid, stat_addr, options, NULL);
599 int sys32_ni_syscall(int call)
601 struct task_struct *me = current;
602 static char lastcomm[sizeof(me->comm)];
604 if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
605 printk(KERN_INFO "IA32 syscall %d from %s not implemented\n",
607 strncpy(lastcomm, me->comm, sizeof(lastcomm));
612 /* 32-bit timeval and related flotsam. */
615 sys32_sysfs(int option, u32 arg1, u32 arg2)
617 return sys_sysfs(option, arg1, arg2);
629 unsigned short procs;
634 char _f[20-2*sizeof(u32)-sizeof(int)];
638 sys32_sysinfo(struct sysinfo32 __user *info)
642 mm_segment_t old_fs = get_fs ();
646 ret = sys_sysinfo(&s);
649 /* Check to see if any memory value is too large for 32-bit and scale
652 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
653 while (s.mem_unit < PAGE_SIZE) {
657 s.totalram >>= bitcount;
658 s.freeram >>= bitcount;
659 s.sharedram >>= bitcount;
660 s.bufferram >>= bitcount;
661 s.totalswap >>= bitcount;
662 s.freeswap >>= bitcount;
663 s.totalhigh >>= bitcount;
664 s.freehigh >>= bitcount;
667 if (verify_area(VERIFY_WRITE, info, sizeof(struct sysinfo32)) ||
668 __put_user (s.uptime, &info->uptime) ||
669 __put_user (s.loads[0], &info->loads[0]) ||
670 __put_user (s.loads[1], &info->loads[1]) ||
671 __put_user (s.loads[2], &info->loads[2]) ||
672 __put_user (s.totalram, &info->totalram) ||
673 __put_user (s.freeram, &info->freeram) ||
674 __put_user (s.sharedram, &info->sharedram) ||
675 __put_user (s.bufferram, &info->bufferram) ||
676 __put_user (s.totalswap, &info->totalswap) ||
677 __put_user (s.freeswap, &info->freeswap) ||
678 __put_user (s.procs, &info->procs) ||
679 __put_user (s.totalhigh, &info->totalhigh) ||
680 __put_user (s.freehigh, &info->freehigh) ||
681 __put_user (s.mem_unit, &info->mem_unit))
687 sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
691 mm_segment_t old_fs = get_fs ();
694 ret = sys_sched_rr_get_interval(pid, &t);
696 if (put_compat_timespec(&t, interval))
702 sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
707 mm_segment_t old_fs = get_fs();
710 ret = sys_rt_sigpending(&s, sigsetsize);
713 switch (_NSIG_WORDS) {
714 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
715 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
716 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
717 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
719 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
727 sys32_rt_sigtimedwait(compat_sigset_t __user *uthese, siginfo_t32 __user *uinfo,
728 struct compat_timespec __user *uts, compat_size_t sigsetsize)
734 mm_segment_t old_fs = get_fs();
737 if (copy_from_user (&s32, uthese, sizeof(compat_sigset_t)))
739 switch (_NSIG_WORDS) {
740 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
741 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
742 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
743 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
745 if (uts && get_compat_timespec(&t, uts))
748 /* stop data leak to user space in case of structure fill mismatch
749 * between sys_rt_sigtimedwait & ia32_copy_siginfo_to_user.
751 memset(&info, 0, sizeof(info));
754 ret = sys_rt_sigtimedwait(&s, uinfo ? &info : NULL, uts ? &t : NULL,
757 if (ret >= 0 && uinfo) {
758 if (ia32_copy_siginfo_to_user(uinfo, &info))
765 sys32_rt_sigqueueinfo(int pid, int sig, siginfo_t32 __user *uinfo)
769 mm_segment_t old_fs = get_fs();
771 if (ia32_copy_siginfo_from_user(&info, uinfo))
774 ret = sys_rt_sigqueueinfo(pid, sig, &info);
779 /* These are here just in case some old ia32 binary calls it. */
783 current->state = TASK_INTERRUPTIBLE;
785 return -ERESTARTNOHAND;
793 unsigned int oldlenp;
796 unsigned int __unused[4];
801 sys32_sysctl(struct sysctl_ia32 __user *args32)
803 #ifndef CONFIG_SYSCTL
806 struct sysctl_ia32 a32;
807 mm_segment_t old_fs = get_fs ();
808 void *oldvalp, *newvalp;
812 extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
813 void *newval, size_t newlen);
816 if (copy_from_user(&a32, args32, sizeof (a32)))
820 * We need to pre-validate these because we have to disable address checking
821 * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
822 * user specifying bad addresses here. Well, since we're dealing with 32 bit
823 * addresses, we KNOW that access_ok() will always succeed, so this is an
824 * expensive NOP, but so what...
826 namep = (int *) A(a32.name);
827 oldvalp = (void *) A(a32.oldval);
828 newvalp = (void *) A(a32.newval);
830 if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
831 || !access_ok(VERIFY_WRITE, namep, 0)
832 || !access_ok(VERIFY_WRITE, oldvalp, 0)
833 || !access_ok(VERIFY_WRITE, newvalp, 0))
838 ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, newvalp, (size_t) a32.newlen);
842 if (oldvalp && put_user (oldlen, (int __user *)compat_ptr(a32.oldlenp)))
849 /* warning: next two assume little endian */
851 sys32_pread(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
853 return sys_pread64(fd, ubuf, count,
854 ((loff_t)AA(poshi) << 32) | AA(poslo));
858 sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
860 return sys_pwrite64(fd, ubuf, count,
861 ((loff_t)AA(poshi) << 32) | AA(poslo));
866 sys32_personality(unsigned long personality)
869 if (personality(current->personality) == PER_LINUX32 &&
870 personality == PER_LINUX)
871 personality = PER_LINUX32;
872 ret = sys_personality(personality);
873 if (ret == PER_LINUX32)
879 sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
881 mm_segment_t old_fs = get_fs();
885 if (offset && get_user(of, offset))
889 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
892 if (!ret && offset && put_user(of, offset))
898 /* Handle adjtimex compatibility. */
902 s32 offset, freq, maxerror, esterror;
903 s32 status, constant, precision, tolerance;
904 struct compat_timeval time;
906 s32 ppsfreq, jitter, shift, stabil;
907 s32 jitcnt, calcnt, errcnt, stbcnt;
908 s32 :32; s32 :32; s32 :32; s32 :32;
909 s32 :32; s32 :32; s32 :32; s32 :32;
910 s32 :32; s32 :32; s32 :32; s32 :32;
913 extern int do_adjtimex(struct timex *);
916 sys32_adjtimex(struct timex32 __user *utp)
921 memset(&txc, 0, sizeof(struct timex));
923 if(verify_area(VERIFY_READ, utp, sizeof(struct timex32)) ||
924 __get_user(txc.modes, &utp->modes) ||
925 __get_user(txc.offset, &utp->offset) ||
926 __get_user(txc.freq, &utp->freq) ||
927 __get_user(txc.maxerror, &utp->maxerror) ||
928 __get_user(txc.esterror, &utp->esterror) ||
929 __get_user(txc.status, &utp->status) ||
930 __get_user(txc.constant, &utp->constant) ||
931 __get_user(txc.precision, &utp->precision) ||
932 __get_user(txc.tolerance, &utp->tolerance) ||
933 __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
934 __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
935 __get_user(txc.tick, &utp->tick) ||
936 __get_user(txc.ppsfreq, &utp->ppsfreq) ||
937 __get_user(txc.jitter, &utp->jitter) ||
938 __get_user(txc.shift, &utp->shift) ||
939 __get_user(txc.stabil, &utp->stabil) ||
940 __get_user(txc.jitcnt, &utp->jitcnt) ||
941 __get_user(txc.calcnt, &utp->calcnt) ||
942 __get_user(txc.errcnt, &utp->errcnt) ||
943 __get_user(txc.stbcnt, &utp->stbcnt))
946 ret = do_adjtimex(&txc);
948 if(verify_area(VERIFY_WRITE, utp, sizeof(struct timex32)) ||
949 __put_user(txc.modes, &utp->modes) ||
950 __put_user(txc.offset, &utp->offset) ||
951 __put_user(txc.freq, &utp->freq) ||
952 __put_user(txc.maxerror, &utp->maxerror) ||
953 __put_user(txc.esterror, &utp->esterror) ||
954 __put_user(txc.status, &utp->status) ||
955 __put_user(txc.constant, &utp->constant) ||
956 __put_user(txc.precision, &utp->precision) ||
957 __put_user(txc.tolerance, &utp->tolerance) ||
958 __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
959 __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
960 __put_user(txc.tick, &utp->tick) ||
961 __put_user(txc.ppsfreq, &utp->ppsfreq) ||
962 __put_user(txc.jitter, &utp->jitter) ||
963 __put_user(txc.shift, &utp->shift) ||
964 __put_user(txc.stabil, &utp->stabil) ||
965 __put_user(txc.jitcnt, &utp->jitcnt) ||
966 __put_user(txc.calcnt, &utp->calcnt) ||
967 __put_user(txc.errcnt, &utp->errcnt) ||
968 __put_user(txc.stbcnt, &utp->stbcnt))
974 asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
975 unsigned long prot, unsigned long flags,
976 unsigned long fd, unsigned long pgoff)
978 struct mm_struct *mm = current->mm;
980 struct file * file = NULL;
982 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
984 if (flags & MAP_FIXED) {
985 if (len > IA32_PAGE_OFFSET)
987 if (addr > IA32_PAGE_OFFSET - len)
991 if (!(flags & MAP_ANONYMOUS)) {
997 down_write(&mm->mmap_sem);
998 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
999 up_write(&mm->mmap_sem);
1006 asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
1012 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
1015 down_read(&uts_sem);
1017 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
1018 __put_user(0,name->sysname+__OLD_UTS_LEN);
1019 __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
1020 __put_user(0,name->nodename+__OLD_UTS_LEN);
1021 __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
1022 __put_user(0,name->release+__OLD_UTS_LEN);
1023 __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
1024 __put_user(0,name->version+__OLD_UTS_LEN);
1026 char *arch = "x86_64";
1027 if (personality(current->personality) == PER_LINUX32)
1030 __copy_to_user(&name->machine,arch,strlen(arch)+1);
1035 error = error ? -EFAULT : 0;
1040 long sys32_uname(struct old_utsname __user * name)
1045 down_read(&uts_sem);
1046 err=copy_to_user(name, &system_utsname, sizeof (*name));
1048 if (personality(current->personality) == PER_LINUX32)
1049 err |= copy_to_user(&name->machine, "i686", 5);
1050 return err?-EFAULT:0;
1053 long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
1061 ret = sys_ustat(dev,&u);
1064 if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) ||
1065 __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
1066 __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
1067 __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
1068 __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
1074 asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
1075 compat_uptr_t __user *envp, struct pt_regs *regs)
1080 filename = getname(name);
1081 error = PTR_ERR(filename);
1082 if (IS_ERR(filename))
1084 error = compat_do_execve(filename, argv, envp, regs);
1087 current->ptrace &= ~PT_DTRACE;
1088 task_unlock(current);
1094 asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
1095 struct pt_regs *regs)
1097 void __user *parent_tid = (void __user *)regs->rdx;
1098 void __user *child_tid = (void __user *)regs->rdi;
1101 return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
1104 asmlinkage long sys32_waitid(int which, compat_pid_t pid,
1105 siginfo_t32 __user *uinfo, int options,
1106 struct compat_rusage __user *uru)
1111 mm_segment_t old_fs = get_fs();
1115 ret = sys_waitid(which, pid, (siginfo_t __user *) &info, options,
1119 if (ret < 0 || info.si_signo == 0)
1122 if (uru && (ret = put_compat_rusage(&ru, uru)))
1125 BUG_ON(info.si_code & __SI_MASK);
1126 info.si_code |= __SI_CHLD;
1127 return ia32_copy_siginfo_to_user(uinfo, &info);
1131 * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
1134 long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
1136 return sys_lseek(fd, offset, whence);
1139 long sys32_kill(int pid, int sig)
1141 return sys_kill(pid, sig);
1144 asmlinkage long sys32_open(const char __user * filename, int flags, int mode)
1149 /* don't force O_LARGEFILE */
1150 tmp = getname(filename);
1153 fd = get_unused_fd();
1155 struct file *f = filp_open(tmp, flags, mode);
1172 u32 payload[(64 / 4) - 3];
1175 extern asmlinkage long
1176 sys_timer_create(clockid_t which_clock,
1177 struct sigevent __user *timer_event_spec,
1178 timer_t __user * created_timer_id);
1181 sys32_timer_create(u32 clock, struct sigevent32 __user *se32, timer_t __user *timer_id)
1183 struct sigevent __user *p = NULL;
1186 p = compat_alloc_user_space(sizeof(struct sigevent));
1187 memset(&se, 0, sizeof(struct sigevent));
1188 if (get_user(se.sigev_value.sival_int, &se32->sigev_value) ||
1189 __get_user(se.sigev_signo, &se32->sigev_signo) ||
1190 __get_user(se.sigev_notify, &se32->sigev_notify) ||
1191 __copy_from_user(&se._sigev_un._pad, &se32->payload,
1192 sizeof(se32->payload)) ||
1193 copy_to_user(p, &se, sizeof(se)))
1196 return sys_timer_create(clock, p, timer_id);
1199 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
1200 __u32 len_low, __u32 len_high, int advice)
1202 return sys_fadvise64_64(fd,
1203 (((u64)offset_high)<<32) | offset_low,
1204 (((u64)len_high)<<32) | len_low,
1208 long sys32_vm86_warning(void)
1210 struct task_struct *me = current;
1211 static char lastcomm[sizeof(me->comm)];
1212 if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
1213 printk(KERN_INFO "%s: vm86 mode not supported on 64 bit kernel\n",
1215 strncpy(lastcomm, me->comm, sizeof(lastcomm));
1220 long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
1221 char __user * buf, size_t len)
1223 return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);
1226 cond_syscall(sys32_ipc)
1228 static int __init ia32_init (void)
1230 printk("IA32 emulation $Id: sys_ia32.c,v 1.32 2002/03/24 13:02:28 ak Exp $\n");
1234 __initcall(ia32_init);
1236 extern unsigned long ia32_sys_call_table[];