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_ANONYMOUS)) {
222 if (a.prot & PROT_READ)
223 a.prot |= vm_force_exec32;
226 down_write(&mm->mmap_sem);
227 retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT);
231 up_write(&mm->mmap_sem);
237 sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
239 if (prot & PROT_READ)
240 prot |= vm_force_exec32;
241 return sys_mprotect(start,len,prot);
245 sys32_pipe(int __user *fd)
250 retval = do_pipe(fds);
253 if (copy_to_user(fd, fds, sizeof(fds)))
260 sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
261 struct sigaction32 __user *oact, unsigned int sigsetsize)
263 struct k_sigaction new_ka, old_ka;
265 compat_sigset_t set32;
267 /* XXX: Don't preclude handling different sized sigset_t's. */
268 if (sigsetsize != sizeof(compat_sigset_t))
272 compat_uptr_t handler, restorer;
274 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
275 __get_user(handler, &act->sa_handler) ||
276 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
277 __get_user(restorer, &act->sa_restorer)||
278 __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t)))
280 new_ka.sa.sa_handler = compat_ptr(handler);
281 new_ka.sa.sa_restorer = compat_ptr(restorer);
282 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
283 switch (_NSIG_WORDS) {
284 case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
285 | (((long)set32.sig[7]) << 32);
286 case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
287 | (((long)set32.sig[5]) << 32);
288 case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
289 | (((long)set32.sig[3]) << 32);
290 case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
291 | (((long)set32.sig[1]) << 32);
295 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
298 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
299 switch (_NSIG_WORDS) {
301 set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
302 set32.sig[6] = old_ka.sa.sa_mask.sig[3];
304 set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
305 set32.sig[4] = old_ka.sa.sa_mask.sig[2];
307 set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
308 set32.sig[2] = old_ka.sa.sa_mask.sig[1];
310 set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
311 set32.sig[0] = old_ka.sa.sa_mask.sig[0];
313 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
314 __put_user((long)old_ka.sa.sa_handler, &oact->sa_handler) ||
315 __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer) ||
316 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
317 __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t)))
325 sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
327 struct k_sigaction new_ka, old_ka;
331 compat_old_sigset_t mask;
332 compat_uptr_t handler, restorer;
334 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
335 __get_user(handler, &act->sa_handler) ||
336 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
337 __get_user(restorer, &act->sa_restorer) ||
338 __get_user(mask, &act->sa_mask))
341 new_ka.sa.sa_handler = compat_ptr(handler);
342 new_ka.sa.sa_restorer = compat_ptr(restorer);
344 siginitset(&new_ka.sa.sa_mask, mask);
347 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
350 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
351 __put_user((long)old_ka.sa.sa_handler, &oact->sa_handler) ||
352 __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer) ||
353 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
354 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
362 sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
363 compat_sigset_t __user *oset, unsigned int sigsetsize)
368 mm_segment_t old_fs = get_fs();
371 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
373 switch (_NSIG_WORDS) {
374 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
375 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
376 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
377 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
381 ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL,
386 switch (_NSIG_WORDS) {
387 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
388 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
389 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
390 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
392 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
399 get_tv32(struct timeval *o, struct compat_timeval __user *i)
402 if (access_ok(VERIFY_READ, i, sizeof(*i))) {
403 err = __get_user(o->tv_sec, &i->tv_sec);
404 err |= __get_user(o->tv_usec, &i->tv_usec);
410 put_tv32(struct compat_timeval __user *o, struct timeval *i)
413 if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
414 err = __put_user(i->tv_sec, &o->tv_sec);
415 err |= __put_user(i->tv_usec, &o->tv_usec);
420 extern int do_setitimer(int which, struct itimerval *, struct itimerval *);
423 sys32_alarm(unsigned int seconds)
425 struct itimerval it_new, it_old;
426 unsigned int oldalarm;
428 it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
429 it_new.it_value.tv_sec = seconds;
430 it_new.it_value.tv_usec = 0;
431 do_setitimer(ITIMER_REAL, &it_new, &it_old);
432 oldalarm = it_old.it_value.tv_sec;
433 /* ehhh.. We can't return 0 if we have an alarm pending.. */
434 /* And we'd better return too much than too little anyway */
435 if (it_old.it_value.tv_usec)
440 /* Translations due to time_t size differences. Which affects all
441 sorts of things, like timeval and itimerval. */
443 extern struct timezone sys_tz;
446 sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
450 do_gettimeofday(&ktv);
451 if (put_tv32(tv, &ktv))
455 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
462 sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
469 if (get_tv32(&ktv, tv))
471 kts.tv_sec = ktv.tv_sec;
472 kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
475 if (copy_from_user(&ktz, tz, sizeof(ktz)))
479 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
482 struct linux32_dirent {
489 struct old_linux32_dirent {
496 struct getdents32_callback {
497 struct linux32_dirent __user * current_dir;
498 struct linux32_dirent __user * previous;
503 struct readdir32_callback {
504 struct old_linux32_dirent __user * dirent;
509 filldir32 (void *__buf, const char *name, int namlen, loff_t offset, ino_t ino,
512 struct linux32_dirent __user * dirent;
513 struct getdents32_callback * buf = (struct getdents32_callback *) __buf;
514 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2, 4);
516 buf->error = -EINVAL; /* only used if we fail.. */
517 if (reclen > buf->count)
519 dirent = buf->previous;
521 put_user(offset, &dirent->d_off);
522 dirent = buf->current_dir;
523 buf->previous = dirent;
524 put_user(ino, &dirent->d_ino);
525 put_user(reclen, &dirent->d_reclen);
526 copy_to_user(dirent->d_name, name, namlen);
527 put_user(0, dirent->d_name + namlen);
528 put_user(d_type, (char __user *)dirent + reclen - 1);
529 dirent = ((void __user *)dirent) + reclen;
530 buf->current_dir = dirent;
531 buf->count -= reclen;
536 sys32_getdents (unsigned int fd, void __user * dirent, unsigned int count)
539 struct linux32_dirent __user * lastdirent;
540 struct getdents32_callback buf;
548 buf.current_dir = (struct linux32_dirent __user *) dirent;
553 error = vfs_readdir(file, filldir32, &buf);
557 lastdirent = buf.previous;
559 put_user(file->f_pos, &lastdirent->d_off);
560 error = count - buf.count;
570 fillonedir32 (void * __buf, const char * name, int namlen, loff_t offset, ino_t ino, unsigned d_type)
572 struct readdir32_callback * buf = (struct readdir32_callback *) __buf;
573 struct old_linux32_dirent __user * dirent;
578 dirent = buf->dirent;
579 put_user(ino, &dirent->d_ino);
580 put_user(offset, &dirent->d_offset);
581 put_user(namlen, &dirent->d_namlen);
582 copy_to_user(dirent->d_name, name, namlen);
583 put_user(0, dirent->d_name + namlen);
588 sys32_oldreaddir (unsigned int fd, void __user * dirent, unsigned int count)
592 struct readdir32_callback buf;
602 error = vfs_readdir(file, fillonedir32, &buf);
610 struct sel_arg_struct {
619 sys32_old_select(struct sel_arg_struct __user *arg)
621 struct sel_arg_struct a;
623 if (copy_from_user(&a, arg, sizeof(a)))
625 return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
626 compat_ptr(a.exp), compat_ptr(a.tvp));
630 * sys_time() can be implemented in user-level using
631 * sys_gettimeofday(). x86-64 did this but i386 Linux did not
632 * so we have to implement this system call here.
634 asmlinkage long sys32_time(int __user * tloc)
639 do_gettimeofday(&tv);
643 if (put_user(i,tloc))
649 extern asmlinkage long
650 compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
651 struct compat_rusage *ru);
654 sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
656 return compat_sys_wait4(pid, stat_addr, options, NULL);
659 int sys32_ni_syscall(int call)
661 struct task_struct *me = current;
662 static char lastcomm[8];
663 if (strcmp(lastcomm, me->comm)) {
664 printk(KERN_INFO "IA32 syscall %d from %s not implemented\n", call,
666 strcpy(lastcomm, me->comm);
671 /* 32-bit timeval and related flotsam. */
674 sys32_sysfs(int option, u32 arg1, u32 arg2)
676 return sys_sysfs(option, arg1, arg2);
688 unsigned short procs;
693 char _f[20-2*sizeof(u32)-sizeof(int)];
697 sys32_sysinfo(struct sysinfo32 __user *info)
701 mm_segment_t old_fs = get_fs ();
705 ret = sys_sysinfo(&s);
708 /* Check to see if any memory value is too large for 32-bit and scale
711 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
712 while (s.mem_unit < PAGE_SIZE) {
716 s.totalram >>= bitcount;
717 s.freeram >>= bitcount;
718 s.sharedram >>= bitcount;
719 s.bufferram >>= bitcount;
720 s.totalswap >>= bitcount;
721 s.freeswap >>= bitcount;
722 s.totalhigh >>= bitcount;
723 s.freehigh >>= bitcount;
726 if (verify_area(VERIFY_WRITE, info, sizeof(struct sysinfo32)) ||
727 __put_user (s.uptime, &info->uptime) ||
728 __put_user (s.loads[0], &info->loads[0]) ||
729 __put_user (s.loads[1], &info->loads[1]) ||
730 __put_user (s.loads[2], &info->loads[2]) ||
731 __put_user (s.totalram, &info->totalram) ||
732 __put_user (s.freeram, &info->freeram) ||
733 __put_user (s.sharedram, &info->sharedram) ||
734 __put_user (s.bufferram, &info->bufferram) ||
735 __put_user (s.totalswap, &info->totalswap) ||
736 __put_user (s.freeswap, &info->freeswap) ||
737 __put_user (s.procs, &info->procs) ||
738 __put_user (s.totalhigh, &info->totalhigh) ||
739 __put_user (s.freehigh, &info->freehigh) ||
740 __put_user (s.mem_unit, &info->mem_unit))
746 sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
750 mm_segment_t old_fs = get_fs ();
753 ret = sys_sched_rr_get_interval(pid, &t);
755 if (put_compat_timespec(&t, interval))
761 sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
766 mm_segment_t old_fs = get_fs();
769 ret = sys_rt_sigpending(&s, sigsetsize);
772 switch (_NSIG_WORDS) {
773 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
774 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
775 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
776 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
778 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
786 sys32_rt_sigtimedwait(compat_sigset_t __user *uthese, siginfo_t32 __user *uinfo,
787 struct compat_timespec __user *uts, compat_size_t sigsetsize)
793 mm_segment_t old_fs = get_fs();
796 if (copy_from_user (&s32, uthese, sizeof(compat_sigset_t)))
798 switch (_NSIG_WORDS) {
799 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
800 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
801 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
802 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
804 if (uts && get_compat_timespec(&t, uts))
807 /* stop data leak to user space in case of structure fill mismatch
808 * between sys_rt_sigtimedwait & ia32_copy_siginfo_to_user.
810 memset(&info, 0, sizeof(info));
813 ret = sys_rt_sigtimedwait(&s, uinfo ? &info : NULL, uts ? &t : NULL,
816 if (ret >= 0 && uinfo) {
817 if (ia32_copy_siginfo_to_user(uinfo, &info))
824 sys32_rt_sigqueueinfo(int pid, int sig, siginfo_t32 __user *uinfo)
828 mm_segment_t old_fs = get_fs();
830 if (ia32_copy_siginfo_from_user(&info, uinfo))
833 ret = sys_rt_sigqueueinfo(pid, sig, &info);
838 /* These are here just in case some old ia32 binary calls it. */
842 current->state = TASK_INTERRUPTIBLE;
844 return -ERESTARTNOHAND;
852 unsigned int oldlenp;
855 unsigned int __unused[4];
860 sys32_sysctl(struct sysctl_ia32 __user *args32)
862 #ifndef CONFIG_SYSCTL
865 struct sysctl_ia32 a32;
866 mm_segment_t old_fs = get_fs ();
867 void *oldvalp, *newvalp;
871 extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
872 void *newval, size_t newlen);
875 if (copy_from_user(&a32, args32, sizeof (a32)))
879 * We need to pre-validate these because we have to disable address checking
880 * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
881 * user specifying bad addresses here. Well, since we're dealing with 32 bit
882 * addresses, we KNOW that access_ok() will always succeed, so this is an
883 * expensive NOP, but so what...
885 namep = (int *) A(a32.name);
886 oldvalp = (void *) A(a32.oldval);
887 newvalp = (void *) A(a32.newval);
889 if ((oldvalp && get_user(oldlen, (int *) A(a32.oldlenp)))
890 || !access_ok(VERIFY_WRITE, namep, 0)
891 || !access_ok(VERIFY_WRITE, oldvalp, 0)
892 || !access_ok(VERIFY_WRITE, newvalp, 0))
897 ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, newvalp, (size_t) a32.newlen);
901 if (oldvalp && put_user (oldlen, (int *) A(a32.oldlenp)))
908 /* warning: next two assume little endian */
910 sys32_pread(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
912 return sys_pread64(fd, ubuf, count,
913 ((loff_t)AA(poshi) << 32) | AA(poslo));
917 sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
919 return sys_pwrite64(fd, ubuf, count,
920 ((loff_t)AA(poshi) << 32) | AA(poslo));
925 sys32_personality(unsigned long personality)
928 if (personality(current->personality) == PER_LINUX32 &&
929 personality == PER_LINUX)
930 personality = PER_LINUX32;
931 ret = sys_personality(personality);
932 if (ret == PER_LINUX32)
938 sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
940 mm_segment_t old_fs = get_fs();
944 if (offset && get_user(of, offset))
948 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
951 if (!ret && offset && put_user(of, offset))
957 /* Handle adjtimex compatibility. */
961 s32 offset, freq, maxerror, esterror;
962 s32 status, constant, precision, tolerance;
963 struct compat_timeval time;
965 s32 ppsfreq, jitter, shift, stabil;
966 s32 jitcnt, calcnt, errcnt, stbcnt;
967 s32 :32; s32 :32; s32 :32; s32 :32;
968 s32 :32; s32 :32; s32 :32; s32 :32;
969 s32 :32; s32 :32; s32 :32; s32 :32;
972 extern int do_adjtimex(struct timex *);
975 sys32_adjtimex(struct timex32 __user *utp)
980 memset(&txc, 0, sizeof(struct timex));
982 if(verify_area(VERIFY_READ, utp, sizeof(struct timex32)) ||
983 __get_user(txc.modes, &utp->modes) ||
984 __get_user(txc.offset, &utp->offset) ||
985 __get_user(txc.freq, &utp->freq) ||
986 __get_user(txc.maxerror, &utp->maxerror) ||
987 __get_user(txc.esterror, &utp->esterror) ||
988 __get_user(txc.status, &utp->status) ||
989 __get_user(txc.constant, &utp->constant) ||
990 __get_user(txc.precision, &utp->precision) ||
991 __get_user(txc.tolerance, &utp->tolerance) ||
992 __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
993 __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
994 __get_user(txc.tick, &utp->tick) ||
995 __get_user(txc.ppsfreq, &utp->ppsfreq) ||
996 __get_user(txc.jitter, &utp->jitter) ||
997 __get_user(txc.shift, &utp->shift) ||
998 __get_user(txc.stabil, &utp->stabil) ||
999 __get_user(txc.jitcnt, &utp->jitcnt) ||
1000 __get_user(txc.calcnt, &utp->calcnt) ||
1001 __get_user(txc.errcnt, &utp->errcnt) ||
1002 __get_user(txc.stbcnt, &utp->stbcnt))
1005 ret = do_adjtimex(&txc);
1007 if(verify_area(VERIFY_WRITE, utp, sizeof(struct timex32)) ||
1008 __put_user(txc.modes, &utp->modes) ||
1009 __put_user(txc.offset, &utp->offset) ||
1010 __put_user(txc.freq, &utp->freq) ||
1011 __put_user(txc.maxerror, &utp->maxerror) ||
1012 __put_user(txc.esterror, &utp->esterror) ||
1013 __put_user(txc.status, &utp->status) ||
1014 __put_user(txc.constant, &utp->constant) ||
1015 __put_user(txc.precision, &utp->precision) ||
1016 __put_user(txc.tolerance, &utp->tolerance) ||
1017 __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
1018 __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
1019 __put_user(txc.tick, &utp->tick) ||
1020 __put_user(txc.ppsfreq, &utp->ppsfreq) ||
1021 __put_user(txc.jitter, &utp->jitter) ||
1022 __put_user(txc.shift, &utp->shift) ||
1023 __put_user(txc.stabil, &utp->stabil) ||
1024 __put_user(txc.jitcnt, &utp->jitcnt) ||
1025 __put_user(txc.calcnt, &utp->calcnt) ||
1026 __put_user(txc.errcnt, &utp->errcnt) ||
1027 __put_user(txc.stbcnt, &utp->stbcnt))
1033 asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
1034 unsigned long prot, unsigned long flags,
1035 unsigned long fd, unsigned long pgoff)
1037 struct mm_struct *mm = current->mm;
1038 unsigned long error;
1039 struct file * file = NULL;
1041 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1042 if (!(flags & MAP_ANONYMOUS)) {
1048 if (prot & PROT_READ)
1049 prot |= vm_force_exec32;
1051 down_write(&mm->mmap_sem);
1052 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1053 up_write(&mm->mmap_sem);
1060 asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
1063 struct new_utsname *ptr;
1067 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
1070 down_read(&uts_sem);
1072 ptr = vx_new_utsname();
1073 error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
1074 __put_user(0,name->sysname+__OLD_UTS_LEN);
1075 __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
1076 __put_user(0,name->nodename+__OLD_UTS_LEN);
1077 __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
1078 __put_user(0,name->release+__OLD_UTS_LEN);
1079 __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
1080 __put_user(0,name->version+__OLD_UTS_LEN);
1082 char *arch = "x86_64";
1083 if (personality(current->personality) == PER_LINUX32)
1086 __copy_to_user(&name->machine,arch,strlen(arch)+1);
1091 error = error ? -EFAULT : 0;
1096 long sys32_uname(struct old_utsname __user * name)
1101 down_read(&uts_sem);
1102 err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
1104 if (personality(current->personality) == PER_LINUX32)
1105 err |= copy_to_user(&name->machine, "i686", 5);
1106 return err?-EFAULT:0;
1109 long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
1117 ret = sys_ustat(dev,&u);
1120 if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) ||
1121 __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
1122 __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
1123 __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
1124 __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
1130 asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
1131 compat_uptr_t __user *envp, struct pt_regs regs)
1136 filename = getname(name);
1137 error = PTR_ERR(filename);
1138 if (IS_ERR(filename))
1140 error = compat_do_execve(filename, argv, envp, ®s);
1142 current->ptrace &= ~PT_DTRACE;
1147 asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp, struct pt_regs regs)
1149 void __user *parent_tid = (void __user *)regs.rdx;
1150 void __user *child_tid = (void __user *)regs.rdi;
1153 return do_fork(clone_flags & ~CLONE_IDLETASK, newsp, ®s, 0,
1154 parent_tid, child_tid);
1158 * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
1161 long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
1163 return sys_lseek(fd, offset, whence);
1166 long sys32_kill(int pid, int sig)
1168 return sys_kill(pid, sig);
1172 long sys32_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
1175 aio_context_t ctx64;
1176 mm_segment_t oldfs = get_fs();
1178 ret = sys_io_setup(nr_reqs, &ctx64);
1180 /* truncating is ok because it's a user address */
1182 ret = put_user((u32)ctx64, ctx32p);
1186 asmlinkage long sys32_io_submit(aio_context_t ctx_id, int nr,
1187 compat_uptr_t __user *iocbpp)
1193 if (unlikely(nr < 0))
1196 if (unlikely(!access_ok(VERIFY_READ, iocbpp, (nr*sizeof(*iocbpp)))))
1199 ctx = lookup_ioctx(ctx_id);
1200 if (unlikely(!ctx)) {
1201 pr_debug("EINVAL: io_submit: invalid context id\n");
1205 for (i=0; i<nr; i++) {
1207 struct iocb __user *user_iocb;
1210 if (unlikely(__get_user(p32, iocbpp + i))) {
1214 user_iocb = compat_ptr(p32);
1216 if (unlikely(copy_from_user(&tmp, user_iocb, sizeof(tmp)))) {
1221 ret = io_submit_one(ctx, user_iocb, &tmp);
1231 asmlinkage long sys32_io_getevents(aio_context_t ctx_id,
1232 unsigned long min_nr,
1234 struct io_event __user *events,
1235 struct compat_timespec __user *timeout)
1240 /* Harden against bogus ptrace */
1241 if (nr >= 0xffffffff ||
1242 !access_ok(VERIFY_WRITE, events, nr * sizeof(struct io_event)))
1244 if (timeout && get_compat_timespec(&t, timeout))
1248 ret = sys_io_getevents(ctx_id,min_nr,nr,events,timeout ? &t : NULL);
1250 if (!ret && timeout && put_compat_timespec(&t, timeout))
1255 asmlinkage long sys32_open(const char __user * filename, int flags, int mode)
1260 /* don't force O_LARGEFILE */
1261 tmp = getname(filename);
1264 fd = get_unused_fd();
1266 struct file *f = filp_open(tmp, flags, mode);
1268 if (unlikely(IS_ERR(f))) {
1283 u32 payload[(64 / 4) - 3];
1286 extern asmlinkage long
1287 sys_timer_create(clockid_t which_clock,
1288 struct sigevent __user *timer_event_spec,
1289 timer_t __user * created_timer_id);
1292 sys32_timer_create(u32 clock, struct sigevent32 __user *se32, timer_t __user *timer_id)
1299 memset(&se, 0, sizeof(struct sigevent));
1300 if (get_user(se.sigev_value.sival_int, &se32->sigev_value) ||
1301 __get_user(se.sigev_signo, &se32->sigev_signo) ||
1302 __get_user(se.sigev_notify, &se32->sigev_notify) ||
1303 __copy_from_user(&se._sigev_un._pad, &se32->payload,
1304 sizeof(se32->payload)))
1307 if (!access_ok(VERIFY_WRITE,timer_id,sizeof(timer_t)))
1312 err = sys_timer_create(clock, se32 ? &se : NULL, timer_id);
1318 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
1319 __u32 len_low, __u32 len_high, int advice)
1321 return sys_fadvise64_64(fd,
1322 (((u64)offset_high)<<32) | offset_low,
1323 (((u64)len_high)<<32) | len_low,
1327 long sys32_vm86_warning(void)
1329 struct task_struct *me = current;
1330 static char lastcomm[8];
1331 if (strcmp(lastcomm, me->comm)) {
1332 printk(KERN_INFO "%s: vm86 mode not supported on 64 bit kernel\n",
1334 strcpy(lastcomm, me->comm);
1339 long sys32_quotactl(void)
1341 struct task_struct *me = current;
1342 static char lastcomm[8];
1343 if (strcmp(lastcomm, me->comm)) {
1344 printk(KERN_INFO "%s: 32bit quotactl not supported on 64 bit kernel\n",
1346 strcpy(lastcomm, me->comm);
1351 cond_syscall(sys32_ipc)
1353 static int __init ia32_init (void)
1355 printk("IA32 emulation $Id: sys_ia32.c,v 1.32 2002/03/24 13:02:28 ak Exp $\n");
1359 __initcall(ia32_init);
1361 extern unsigned long ia32_sys_call_table[];
1362 EXPORT_SYMBOL(ia32_sys_call_table);