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/vs_cvirt.h>
66 #include <asm/types.h>
67 #include <asm/uaccess.h>
68 #include <asm/semaphore.h>
70 #include <asm/atomic.h>
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)))
82 int cp_compat_stat(struct kstat *kbuf, struct compat_stat __user *ubuf)
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))
90 if (kbuf->size >= 0x7fffffff)
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))
114 sys32_truncate64(char __user * filename, unsigned long offset_low, unsigned long offset_high)
116 return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
120 sys32_ftruncate64(unsigned int fd, unsigned long offset_low, unsigned long offset_high)
122 return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
125 /* Another set for IA32/LFS -- x86_64 struct stat is different due to
126 support for 64bit inode numbers. */
129 cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
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))
158 sys32_stat64(char __user * filename, struct stat64 __user *statbuf)
161 int ret = vfs_stat(filename, &stat);
163 ret = cp_stat64(statbuf, &stat);
168 sys32_lstat64(char __user * filename, struct stat64 __user *statbuf)
171 int ret = vfs_lstat(filename, &stat);
173 ret = cp_stat64(statbuf, &stat);
178 sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
181 int ret = vfs_fstat(fd, &stat);
183 ret = cp_stat64(statbuf, &stat);
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..
193 struct mmap_arg_struct {
203 sys32_mmap(struct mmap_arg_struct __user *arg)
205 struct mmap_arg_struct a;
206 struct file *file = NULL;
207 unsigned long retval;
208 struct mm_struct *mm ;
210 if (copy_from_user(&a, arg, sizeof(a)))
213 if (a.offset & ~PAGE_MASK)
216 if (a.flags & MAP_FIXED) {
217 if (a.len > IA32_PAGE_OFFSET)
219 if (a.addr > IA32_PAGE_OFFSET - a.len)
223 if (!(a.flags & MAP_ANONYMOUS)) {
229 if (a.prot & PROT_READ)
230 a.prot |= vm_force_exec32;
233 down_write(&mm->mmap_sem);
234 retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT);
238 up_write(&mm->mmap_sem);
244 sys32_munmap(unsigned long start, unsigned long len)
246 if ((start + len) > IA32_PAGE_OFFSET)
248 return sys_munmap(start, len);
252 sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
254 if ((start + PAGE_ALIGN(len)) >> 32)
256 if (prot & PROT_READ)
257 prot |= vm_force_exec32;
258 return sys_mprotect(start,len,prot);
262 sys32_brk(unsigned long brk)
264 if (brk > IA32_PAGE_OFFSET)
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);
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)
277 struct vm_area_struct *vma;
278 unsigned long ret = -EINVAL;
280 if (old_len > IA32_PAGE_OFFSET || new_len > IA32_PAGE_OFFSET)
282 if (addr > IA32_PAGE_OFFSET - old_len)
284 down_write(¤t->mm->mmap_sem);
285 if (flags & MREMAP_FIXED) {
286 if (new_addr > IA32_PAGE_OFFSET - new_len)
288 } else if (addr > IA32_PAGE_OFFSET - new_len) {
289 unsigned long map_flags = 0;
290 struct file *file = NULL;
293 if (!(flags & MREMAP_MAYMOVE))
296 vma = find_vma(current->mm, addr);
298 if (vma->vm_flags & VM_SHARED)
299 map_flags |= MAP_SHARED;
303 /* MREMAP_FIXED checked above. */
304 new_addr = get_unmapped_area(file, addr, new_len,
305 vma ? vma->vm_pgoff : 0,
308 if (new_addr & ~PAGE_MASK)
310 flags |= MREMAP_FIXED;
312 ret = do_mremap(addr, old_len, new_len, flags, new_addr);
314 up_write(¤t->mm->mmap_sem);
320 sys32_pipe(int __user *fd)
325 retval = do_pipe(fds);
328 if (copy_to_user(fd, fds, sizeof(fds)))
335 sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
336 struct sigaction32 __user *oact, unsigned int sigsetsize)
338 struct k_sigaction new_ka, old_ka;
340 compat_sigset_t set32;
342 /* XXX: Don't preclude handling different sized sigset_t's. */
343 if (sigsetsize != sizeof(compat_sigset_t))
347 compat_uptr_t handler, restorer;
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)))
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);
370 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
373 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
374 switch (_NSIG_WORDS) {
376 set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
377 set32.sig[6] = old_ka.sa.sa_mask.sig[3];
379 set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
380 set32.sig[4] = old_ka.sa.sa_mask.sig[2];
382 set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
383 set32.sig[2] = old_ka.sa.sa_mask.sig[1];
385 set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
386 set32.sig[0] = old_ka.sa.sa_mask.sig[0];
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)))
400 sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
402 struct k_sigaction new_ka, old_ka;
406 compat_old_sigset_t mask;
407 compat_uptr_t handler, restorer;
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))
416 new_ka.sa.sa_handler = compat_ptr(handler);
417 new_ka.sa.sa_restorer = compat_ptr(restorer);
419 siginitset(&new_ka.sa.sa_mask, mask);
422 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
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))
437 sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
438 compat_sigset_t __user *oset, unsigned int sigsetsize)
443 mm_segment_t old_fs = get_fs();
446 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
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);
456 ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL,
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];
467 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
474 get_tv32(struct timeval *o, struct compat_timeval __user *i)
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);
485 put_tv32(struct compat_timeval __user *o, struct timeval *i)
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);
495 extern int do_setitimer(int which, struct itimerval *, struct itimerval *);
498 sys32_alarm(unsigned int seconds)
500 struct itimerval it_new, it_old;
501 unsigned int oldalarm;
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)
515 /* Translations due to time_t size differences. Which affects all
516 sorts of things, like timeval and itimerval. */
518 extern struct timezone sys_tz;
521 sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
525 do_gettimeofday(&ktv);
526 if (put_tv32(tv, &ktv))
530 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
537 sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
544 if (get_tv32(&ktv, tv))
546 kts.tv_sec = ktv.tv_sec;
547 kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
550 if (copy_from_user(&ktz, tz, sizeof(ktz)))
554 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
557 struct linux32_dirent {
564 struct old_linux32_dirent {
571 struct getdents32_callback {
572 struct linux32_dirent __user * current_dir;
573 struct linux32_dirent __user * previous;
578 struct readdir32_callback {
579 struct old_linux32_dirent __user * dirent;
584 filldir32 (void *__buf, const char *name, int namlen, loff_t offset, ino_t ino,
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);
591 buf->error = -EINVAL; /* only used if we fail.. */
592 if (reclen > buf->count)
594 dirent = buf->previous;
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;
611 sys32_getdents (unsigned int fd, void __user * dirent, unsigned int count)
614 struct linux32_dirent __user * lastdirent;
615 struct getdents32_callback buf;
623 buf.current_dir = (struct linux32_dirent __user *) dirent;
628 error = vfs_readdir(file, filldir32, &buf);
632 lastdirent = buf.previous;
634 put_user(file->f_pos, &lastdirent->d_off);
635 error = count - buf.count;
645 fillonedir32 (void * __buf, const char * name, int namlen, loff_t offset, ino_t ino, unsigned d_type)
647 struct readdir32_callback * buf = (struct readdir32_callback *) __buf;
648 struct old_linux32_dirent __user * dirent;
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);
663 sys32_oldreaddir (unsigned int fd, void __user * dirent, unsigned int count)
667 struct readdir32_callback buf;
677 error = vfs_readdir(file, fillonedir32, &buf);
685 struct sel_arg_struct {
694 sys32_old_select(struct sel_arg_struct __user *arg)
696 struct sel_arg_struct a;
698 if (copy_from_user(&a, arg, sizeof(a)))
700 return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
701 compat_ptr(a.exp), compat_ptr(a.tvp));
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.
709 asmlinkage long sys32_time(int __user * tloc)
714 do_gettimeofday(&tv);
718 if (put_user(i,tloc))
724 extern asmlinkage long
725 compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
726 struct compat_rusage *ru);
729 sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
731 return compat_sys_wait4(pid, stat_addr, options, NULL);
734 int sys32_ni_syscall(int call)
736 struct task_struct *me = current;
737 static char lastcomm[sizeof(me->comm)];
739 if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
740 printk(KERN_INFO "IA32 syscall %d from %s not implemented\n",
742 strncpy(lastcomm, me->comm, sizeof(lastcomm));
747 /* 32-bit timeval and related flotsam. */
750 sys32_sysfs(int option, u32 arg1, u32 arg2)
752 return sys_sysfs(option, arg1, arg2);
764 unsigned short procs;
769 char _f[20-2*sizeof(u32)-sizeof(int)];
773 sys32_sysinfo(struct sysinfo32 __user *info)
777 mm_segment_t old_fs = get_fs ();
781 ret = sys_sysinfo(&s);
784 /* Check to see if any memory value is too large for 32-bit and scale
787 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
788 while (s.mem_unit < PAGE_SIZE) {
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;
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))
822 sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
826 mm_segment_t old_fs = get_fs ();
829 ret = sys_sched_rr_get_interval(pid, &t);
831 if (put_compat_timespec(&t, interval))
837 sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
842 mm_segment_t old_fs = get_fs();
845 ret = sys_rt_sigpending(&s, sigsetsize);
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];
854 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
862 sys32_rt_sigtimedwait(compat_sigset_t __user *uthese, siginfo_t32 __user *uinfo,
863 struct compat_timespec __user *uts, compat_size_t sigsetsize)
869 mm_segment_t old_fs = get_fs();
872 if (copy_from_user (&s32, uthese, sizeof(compat_sigset_t)))
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);
880 if (uts && get_compat_timespec(&t, uts))
883 /* stop data leak to user space in case of structure fill mismatch
884 * between sys_rt_sigtimedwait & ia32_copy_siginfo_to_user.
886 memset(&info, 0, sizeof(info));
889 ret = sys_rt_sigtimedwait(&s, uinfo ? &info : NULL, uts ? &t : NULL,
892 if (ret >= 0 && uinfo) {
893 if (ia32_copy_siginfo_to_user(uinfo, &info))
900 sys32_rt_sigqueueinfo(int pid, int sig, siginfo_t32 __user *uinfo)
904 mm_segment_t old_fs = get_fs();
906 if (ia32_copy_siginfo_from_user(&info, uinfo))
909 ret = sys_rt_sigqueueinfo(pid, sig, &info);
914 /* These are here just in case some old ia32 binary calls it. */
918 current->state = TASK_INTERRUPTIBLE;
920 return -ERESTARTNOHAND;
928 unsigned int oldlenp;
931 unsigned int __unused[4];
936 sys32_sysctl(struct sysctl_ia32 __user *args32)
938 #ifndef CONFIG_SYSCTL
941 struct sysctl_ia32 a32;
942 mm_segment_t old_fs = get_fs ();
943 void *oldvalp, *newvalp;
947 extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
948 void *newval, size_t newlen);
951 if (copy_from_user(&a32, args32, sizeof (a32)))
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...
961 namep = (int *) A(a32.name);
962 oldvalp = (void *) A(a32.oldval);
963 newvalp = (void *) A(a32.newval);
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))
973 ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, newvalp, (size_t) a32.newlen);
977 if (oldvalp && put_user (oldlen, (int __user *)compat_ptr(a32.oldlenp)))
984 /* warning: next two assume little endian */
986 sys32_pread(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
988 return sys_pread64(fd, ubuf, count,
989 ((loff_t)AA(poshi) << 32) | AA(poslo));
993 sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
995 return sys_pwrite64(fd, ubuf, count,
996 ((loff_t)AA(poshi) << 32) | AA(poslo));
1001 sys32_personality(unsigned long personality)
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)
1014 sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
1016 mm_segment_t old_fs = get_fs();
1020 if (offset && get_user(of, offset))
1024 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
1027 if (!ret && offset && put_user(of, offset))
1033 /* Handle adjtimex compatibility. */
1037 s32 offset, freq, maxerror, esterror;
1038 s32 status, constant, precision, tolerance;
1039 struct compat_timeval time;
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;
1048 extern int do_adjtimex(struct timex *);
1051 sys32_adjtimex(struct timex32 __user *utp)
1056 memset(&txc, 0, sizeof(struct timex));
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))
1081 ret = do_adjtimex(&txc);
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))
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)
1113 struct mm_struct *mm = current->mm;
1114 unsigned long error;
1115 struct file * file = NULL;
1117 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1119 if (flags & MAP_FIXED) {
1120 if (len > IA32_PAGE_OFFSET)
1122 if (addr > IA32_PAGE_OFFSET - len)
1126 if (!(flags & MAP_ANONYMOUS)) {
1132 if (prot & PROT_READ)
1133 prot |= vm_force_exec32;
1135 down_write(&mm->mmap_sem);
1136 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1137 up_write(&mm->mmap_sem);
1144 asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
1147 struct new_utsname *ptr;
1151 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
1154 down_read(&uts_sem);
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);
1166 char *arch = "x86_64";
1167 if (personality(current->personality) == PER_LINUX32)
1170 __copy_to_user(&name->machine,arch,strlen(arch)+1);
1175 error = error ? -EFAULT : 0;
1180 long sys32_uname(struct old_utsname __user * name)
1185 down_read(&uts_sem);
1186 err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
1188 if (personality(current->personality) == PER_LINUX32)
1189 err |= copy_to_user(&name->machine, "i686", 5);
1190 return err?-EFAULT:0;
1193 long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
1201 ret = sys_ustat(dev,&u);
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)))
1214 asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
1215 compat_uptr_t __user *envp, struct pt_regs *regs)
1220 filename = getname(name);
1221 error = PTR_ERR(filename);
1222 if (IS_ERR(filename))
1224 error = compat_do_execve(filename, argv, envp, regs);
1226 current->ptrace &= ~PT_DTRACE;
1231 asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
1232 struct pt_regs *regs)
1234 void __user *parent_tid = (void __user *)regs->rdx;
1235 void __user *child_tid = (void __user *)regs->rdi;
1238 return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
1241 asmlinkage long sys32_waitid(int which, compat_pid_t pid,
1242 siginfo_t32 __user *uinfo, int options,
1243 struct compat_rusage __user *uru)
1248 mm_segment_t old_fs = get_fs();
1252 ret = sys_waitid(which, pid, (siginfo_t __user *) &info, options,
1256 if (ret < 0 || info.si_signo == 0)
1259 if (uru && (ret = put_compat_rusage(&ru, uru)))
1262 BUG_ON(info.si_code & __SI_MASK);
1263 info.si_code |= __SI_CHLD;
1264 return ia32_copy_siginfo_to_user(uinfo, &info);
1268 * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
1271 long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
1273 return sys_lseek(fd, offset, whence);
1276 long sys32_kill(int pid, int sig)
1278 return sys_kill(pid, sig);
1282 long sys32_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
1285 aio_context_t ctx64;
1286 mm_segment_t oldfs = get_fs();
1288 ret = sys_io_setup(nr_reqs, &ctx64);
1290 /* truncating is ok because it's a user address */
1292 ret = put_user((u32)ctx64, ctx32p);
1296 asmlinkage long sys32_io_submit(aio_context_t ctx_id, int nr,
1297 compat_uptr_t __user *iocbpp)
1303 if (unlikely(nr < 0))
1306 if (unlikely(!access_ok(VERIFY_READ, iocbpp, (nr*sizeof(*iocbpp)))))
1309 ctx = lookup_ioctx(ctx_id);
1310 if (unlikely(!ctx)) {
1311 pr_debug("EINVAL: io_submit: invalid context id\n");
1315 for (i=0; i<nr; i++) {
1317 struct iocb __user *user_iocb;
1320 if (unlikely(__get_user(p32, iocbpp + i))) {
1324 user_iocb = compat_ptr(p32);
1326 if (unlikely(copy_from_user(&tmp, user_iocb, sizeof(tmp)))) {
1331 ret = io_submit_one(ctx, user_iocb, &tmp);
1341 asmlinkage long sys32_io_getevents(aio_context_t ctx_id,
1342 unsigned long min_nr,
1344 struct io_event __user *events,
1345 struct compat_timespec __user *timeout)
1350 /* Harden against bogus ptrace */
1351 if (nr >= 0xffffffff ||
1352 !access_ok(VERIFY_WRITE, events, nr * sizeof(struct io_event)))
1354 if (timeout && get_compat_timespec(&t, timeout))
1358 ret = sys_io_getevents(ctx_id,min_nr,nr,events,timeout ? &t : NULL);
1360 if (!ret && timeout && put_compat_timespec(&t, timeout))
1365 asmlinkage long sys32_open(const char __user * filename, int flags, int mode)
1370 /* don't force O_LARGEFILE */
1371 tmp = getname(filename);
1374 fd = get_unused_fd();
1376 struct file *f = filp_open(tmp, flags, mode);
1393 u32 payload[(64 / 4) - 3];
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);
1402 sys32_timer_create(u32 clock, struct sigevent32 __user *se32, timer_t __user *timer_id)
1404 struct sigevent __user *p = NULL;
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)))
1417 return sys_timer_create(clock, p, timer_id);
1420 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
1421 __u32 len_low, __u32 len_high, int advice)
1423 return sys_fadvise64_64(fd,
1424 (((u64)offset_high)<<32) | offset_low,
1425 (((u64)len_high)<<32) | len_low,
1429 long sys32_vm86_warning(void)
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",
1436 strncpy(lastcomm, me->comm, sizeof(lastcomm));
1441 long sys32_quotactl(void)
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",
1448 strcpy(lastcomm, me->comm);
1453 long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
1454 char __user * buf, size_t len)
1456 return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);
1459 cond_syscall(sys32_ipc)
1461 static int __init ia32_init (void)
1463 printk("IA32 emulation $Id: sys_ia32.c,v 1.32 2002/03/24 13:02:28 ak Exp $\n");
1467 __initcall(ia32_init);
1469 extern unsigned long ia32_sys_call_table[];