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>
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 *) (de)))
81 int cp_compat_stat(struct kstat *kbuf, struct compat_stat *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 * 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 *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 * filename, struct stat64 *statbuf)
160 int ret = vfs_stat(filename, &stat);
162 ret = cp_stat64(statbuf, &stat);
167 sys32_lstat64(char * filename, struct stat64 *statbuf)
170 int ret = vfs_lstat(filename, &stat);
172 ret = cp_stat64(statbuf, &stat);
177 sys32_fstat64(unsigned int fd, struct stat64 *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 *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_ANONYMOUS)) {
221 if (a.prot & PROT_READ)
222 a.prot |= vm_force_exec32;
225 down_write(&mm->mmap_sem);
226 retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT);
230 up_write(&mm->mmap_sem);
236 sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
238 if (prot & PROT_READ)
239 prot |= vm_force_exec32;
240 return sys_mprotect(start,len,prot);
249 retval = do_pipe(fds);
252 if (copy_to_user(fd, fds, sizeof(fds)))
259 sys32_rt_sigaction(int sig, struct sigaction32 *act,
260 struct sigaction32 *oact, unsigned int sigsetsize)
262 struct k_sigaction new_ka, old_ka;
264 compat_sigset_t set32;
266 /* XXX: Don't preclude handling different sized sigset_t's. */
267 if (sigsetsize != sizeof(compat_sigset_t))
271 compat_uptr_t handler, restorer;
273 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
274 __get_user(handler, &act->sa_handler) ||
275 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
276 __get_user(restorer, &act->sa_restorer)||
277 __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t)))
279 new_ka.sa.sa_handler = compat_ptr(handler);
280 new_ka.sa.sa_restorer = compat_ptr(restorer);
281 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
282 switch (_NSIG_WORDS) {
283 case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
284 | (((long)set32.sig[7]) << 32);
285 case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
286 | (((long)set32.sig[5]) << 32);
287 case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
288 | (((long)set32.sig[3]) << 32);
289 case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
290 | (((long)set32.sig[1]) << 32);
294 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
297 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
298 switch (_NSIG_WORDS) {
300 set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
301 set32.sig[6] = old_ka.sa.sa_mask.sig[3];
303 set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
304 set32.sig[4] = old_ka.sa.sa_mask.sig[2];
306 set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
307 set32.sig[2] = old_ka.sa.sa_mask.sig[1];
309 set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
310 set32.sig[0] = old_ka.sa.sa_mask.sig[0];
312 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
313 __put_user((long)old_ka.sa.sa_handler, &oact->sa_handler) ||
314 __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer) ||
315 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
316 __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t)))
324 sys32_sigaction (int sig, struct old_sigaction32 *act, struct old_sigaction32 *oact)
326 struct k_sigaction new_ka, old_ka;
330 compat_old_sigset_t mask;
331 compat_uptr_t handler, restorer;
333 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
334 __get_user(handler, &act->sa_handler) ||
335 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
336 __get_user(restorer, &act->sa_restorer) ||
337 __get_user(mask, &act->sa_mask))
340 new_ka.sa.sa_handler = compat_ptr(handler);
341 new_ka.sa.sa_restorer = compat_ptr(restorer);
343 siginitset(&new_ka.sa.sa_mask, mask);
346 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
349 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
350 __put_user((long)old_ka.sa.sa_handler, &oact->sa_handler) ||
351 __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer) ||
352 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
353 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
361 sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
362 compat_sigset_t __user *oset, unsigned int sigsetsize)
367 mm_segment_t old_fs = get_fs();
370 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
372 switch (_NSIG_WORDS) {
373 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
374 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
375 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
376 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
380 ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL,
385 switch (_NSIG_WORDS) {
386 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
387 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
388 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
389 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
391 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
398 get_tv32(struct timeval *o, struct compat_timeval *i)
401 if (access_ok(VERIFY_READ, i, sizeof(*i))) {
402 err = __get_user(o->tv_sec, &i->tv_sec);
403 err |= __get_user(o->tv_usec, &i->tv_usec);
409 put_tv32(struct compat_timeval *o, struct timeval *i)
412 if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
413 err = __put_user(i->tv_sec, &o->tv_sec);
414 err |= __put_user(i->tv_usec, &o->tv_usec);
419 extern int do_setitimer(int which, struct itimerval *, struct itimerval *);
422 sys32_alarm(unsigned int seconds)
424 struct itimerval it_new, it_old;
425 unsigned int oldalarm;
427 it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
428 it_new.it_value.tv_sec = seconds;
429 it_new.it_value.tv_usec = 0;
430 do_setitimer(ITIMER_REAL, &it_new, &it_old);
431 oldalarm = it_old.it_value.tv_sec;
432 /* ehhh.. We can't return 0 if we have an alarm pending.. */
433 /* And we'd better return too much than too little anyway */
434 if (it_old.it_value.tv_usec)
439 /* Translations due to time_t size differences. Which affects all
440 sorts of things, like timeval and itimerval. */
442 extern struct timezone sys_tz;
445 sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz)
449 do_gettimeofday(&ktv);
450 if (put_tv32(tv, &ktv))
454 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
461 sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz)
468 if (get_tv32(&ktv, tv))
470 kts.tv_sec = ktv.tv_sec;
471 kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
474 if (copy_from_user(&ktz, tz, sizeof(ktz)))
478 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
481 struct linux32_dirent {
488 struct old_linux32_dirent {
495 struct getdents32_callback {
496 struct linux32_dirent * current_dir;
497 struct linux32_dirent * previous;
502 struct readdir32_callback {
503 struct old_linux32_dirent * dirent;
508 filldir32 (void *__buf, const char *name, int namlen, loff_t offset, ino_t ino,
511 struct linux32_dirent * dirent;
512 struct getdents32_callback * buf = (struct getdents32_callback *) __buf;
513 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2, 4);
515 buf->error = -EINVAL; /* only used if we fail.. */
516 if (reclen > buf->count)
518 dirent = buf->previous;
520 put_user(offset, &dirent->d_off);
521 dirent = buf->current_dir;
522 buf->previous = dirent;
523 put_user(ino, &dirent->d_ino);
524 put_user(reclen, &dirent->d_reclen);
525 copy_to_user(dirent->d_name, name, namlen);
526 put_user(0, dirent->d_name + namlen);
527 put_user(d_type, (char *)dirent + reclen - 1);
528 dirent = ((void *)dirent) + reclen;
529 buf->current_dir = dirent;
530 buf->count -= reclen;
535 sys32_getdents (unsigned int fd, void * dirent, unsigned int count)
538 struct linux32_dirent * lastdirent;
539 struct getdents32_callback buf;
547 buf.current_dir = (struct linux32_dirent *) dirent;
552 error = vfs_readdir(file, filldir32, &buf);
556 lastdirent = buf.previous;
558 put_user(file->f_pos, &lastdirent->d_off);
559 error = count - buf.count;
569 fillonedir32 (void * __buf, const char * name, int namlen, loff_t offset, ino_t ino, unsigned d_type)
571 struct readdir32_callback * buf = (struct readdir32_callback *) __buf;
572 struct old_linux32_dirent * dirent;
577 dirent = buf->dirent;
578 put_user(ino, &dirent->d_ino);
579 put_user(offset, &dirent->d_offset);
580 put_user(namlen, &dirent->d_namlen);
581 copy_to_user(dirent->d_name, name, namlen);
582 put_user(0, dirent->d_name + namlen);
587 sys32_oldreaddir (unsigned int fd, void * dirent, unsigned int count)
591 struct readdir32_callback buf;
601 error = vfs_readdir(file, fillonedir32, &buf);
609 struct sel_arg_struct {
618 sys32_old_select(struct sel_arg_struct *arg)
620 struct sel_arg_struct a;
622 if (copy_from_user(&a, arg, sizeof(a)))
624 return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
625 compat_ptr(a.exp), compat_ptr(a.tvp));
629 * sys_time() can be implemented in user-level using
630 * sys_gettimeofday(). x86-64 did this but i386 Linux did not
631 * so we have to implement this system call here.
633 asmlinkage long sys32_time(int * tloc)
638 do_gettimeofday(&tv);
642 if (put_user(i,tloc))
648 extern asmlinkage long
649 compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
650 struct compat_rusage *ru);
653 sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
655 return compat_sys_wait4(pid, stat_addr, options, NULL);
658 int sys32_ni_syscall(int call)
660 struct task_struct *me = current;
661 static char lastcomm[8];
662 if (strcmp(lastcomm, me->comm)) {
663 printk(KERN_INFO "IA32 syscall %d from %s not implemented\n", call,
665 strcpy(lastcomm, me->comm);
670 /* 32-bit timeval and related flotsam. */
673 sys32_sysfs(int option, u32 arg1, u32 arg2)
675 return sys_sysfs(option, arg1, arg2);
687 unsigned short procs;
692 char _f[20-2*sizeof(u32)-sizeof(int)];
696 sys32_sysinfo(struct sysinfo32 *info)
700 mm_segment_t old_fs = get_fs ();
704 ret = sys_sysinfo(&s);
707 /* Check to see if any memory value is too large for 32-bit and scale
710 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
711 while (s.mem_unit < PAGE_SIZE) {
715 s.totalram >>= bitcount;
716 s.freeram >>= bitcount;
717 s.sharedram >>= bitcount;
718 s.bufferram >>= bitcount;
719 s.totalswap >>= bitcount;
720 s.freeswap >>= bitcount;
721 s.totalhigh >>= bitcount;
722 s.freehigh >>= bitcount;
725 if (verify_area(VERIFY_WRITE, info, sizeof(struct sysinfo32)) ||
726 __put_user (s.uptime, &info->uptime) ||
727 __put_user (s.loads[0], &info->loads[0]) ||
728 __put_user (s.loads[1], &info->loads[1]) ||
729 __put_user (s.loads[2], &info->loads[2]) ||
730 __put_user (s.totalram, &info->totalram) ||
731 __put_user (s.freeram, &info->freeram) ||
732 __put_user (s.sharedram, &info->sharedram) ||
733 __put_user (s.bufferram, &info->bufferram) ||
734 __put_user (s.totalswap, &info->totalswap) ||
735 __put_user (s.freeswap, &info->freeswap) ||
736 __put_user (s.procs, &info->procs) ||
737 __put_user (s.totalhigh, &info->totalhigh) ||
738 __put_user (s.freehigh, &info->freehigh) ||
739 __put_user (s.mem_unit, &info->mem_unit))
745 sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec *interval)
749 mm_segment_t old_fs = get_fs ();
752 ret = sys_sched_rr_get_interval(pid, &t);
754 if (put_compat_timespec(&t, interval))
760 sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
765 mm_segment_t old_fs = get_fs();
768 ret = sys_rt_sigpending(&s, sigsetsize);
771 switch (_NSIG_WORDS) {
772 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
773 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
774 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
775 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
777 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
785 sys32_rt_sigtimedwait(compat_sigset_t *uthese, siginfo_t32 *uinfo,
786 struct compat_timespec *uts, compat_size_t sigsetsize)
792 mm_segment_t old_fs = get_fs();
795 if (copy_from_user (&s32, uthese, sizeof(compat_sigset_t)))
797 switch (_NSIG_WORDS) {
798 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
799 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
800 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
801 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
803 if (uts && get_compat_timespec(&t, uts))
806 /* stop data leak to user space in case of structure fill mismatch
807 * between sys_rt_sigtimedwait & ia32_copy_siginfo_to_user.
809 memset(&info, 0, sizeof(info));
812 ret = sys_rt_sigtimedwait(&s, uinfo ? &info : NULL, uts ? &t : NULL,
815 if (ret >= 0 && uinfo) {
816 if (ia32_copy_siginfo_to_user(uinfo, &info))
823 sys32_rt_sigqueueinfo(int pid, int sig, siginfo_t32 *uinfo)
827 mm_segment_t old_fs = get_fs();
829 if (ia32_copy_siginfo_from_user(&info, uinfo))
832 ret = sys_rt_sigqueueinfo(pid, sig, &info);
837 /* These are here just in case some old ia32 binary calls it. */
841 current->state = TASK_INTERRUPTIBLE;
843 return -ERESTARTNOHAND;
851 unsigned int oldlenp;
854 unsigned int __unused[4];
859 sys32_sysctl(struct sysctl_ia32 *args32)
861 #ifndef CONFIG_SYSCTL
864 struct sysctl_ia32 a32;
865 mm_segment_t old_fs = get_fs ();
866 void *oldvalp, *newvalp;
870 extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
871 void *newval, size_t newlen);
874 if (copy_from_user(&a32, args32, sizeof (a32)))
878 * We need to pre-validate these because we have to disable address checking
879 * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
880 * user specifying bad addresses here. Well, since we're dealing with 32 bit
881 * addresses, we KNOW that access_ok() will always succeed, so this is an
882 * expensive NOP, but so what...
884 namep = (int *) A(a32.name);
885 oldvalp = (void *) A(a32.oldval);
886 newvalp = (void *) A(a32.newval);
888 if ((oldvalp && get_user(oldlen, (int *) A(a32.oldlenp)))
889 || !access_ok(VERIFY_WRITE, namep, 0)
890 || !access_ok(VERIFY_WRITE, oldvalp, 0)
891 || !access_ok(VERIFY_WRITE, newvalp, 0))
896 ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, newvalp, (size_t) a32.newlen);
900 if (oldvalp && put_user (oldlen, (int *) A(a32.oldlenp)))
907 /* warning: next two assume little endian */
909 sys32_pread(unsigned int fd, char *ubuf, u32 count, u32 poslo, u32 poshi)
911 return sys_pread64(fd, ubuf, count,
912 ((loff_t)AA(poshi) << 32) | AA(poslo));
916 sys32_pwrite(unsigned int fd, char *ubuf, u32 count, u32 poslo, u32 poshi)
918 return sys_pwrite64(fd, ubuf, count,
919 ((loff_t)AA(poshi) << 32) | AA(poslo));
924 sys32_personality(unsigned long personality)
927 if (personality(current->personality) == PER_LINUX32 &&
928 personality == PER_LINUX)
929 personality = PER_LINUX32;
930 ret = sys_personality(personality);
931 if (ret == PER_LINUX32)
937 sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset, s32 count)
939 mm_segment_t old_fs = get_fs();
943 if (offset && get_user(of, offset))
947 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
950 if (!ret && offset && put_user(of, offset))
956 /* Handle adjtimex compatibility. */
960 s32 offset, freq, maxerror, esterror;
961 s32 status, constant, precision, tolerance;
962 struct compat_timeval time;
964 s32 ppsfreq, jitter, shift, stabil;
965 s32 jitcnt, calcnt, errcnt, stbcnt;
966 s32 :32; s32 :32; s32 :32; s32 :32;
967 s32 :32; s32 :32; s32 :32; s32 :32;
968 s32 :32; s32 :32; s32 :32; s32 :32;
971 extern int do_adjtimex(struct timex *);
974 sys32_adjtimex(struct timex32 *utp)
979 memset(&txc, 0, sizeof(struct timex));
981 if(verify_area(VERIFY_READ, utp, sizeof(struct timex32)) ||
982 __get_user(txc.modes, &utp->modes) ||
983 __get_user(txc.offset, &utp->offset) ||
984 __get_user(txc.freq, &utp->freq) ||
985 __get_user(txc.maxerror, &utp->maxerror) ||
986 __get_user(txc.esterror, &utp->esterror) ||
987 __get_user(txc.status, &utp->status) ||
988 __get_user(txc.constant, &utp->constant) ||
989 __get_user(txc.precision, &utp->precision) ||
990 __get_user(txc.tolerance, &utp->tolerance) ||
991 __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
992 __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
993 __get_user(txc.tick, &utp->tick) ||
994 __get_user(txc.ppsfreq, &utp->ppsfreq) ||
995 __get_user(txc.jitter, &utp->jitter) ||
996 __get_user(txc.shift, &utp->shift) ||
997 __get_user(txc.stabil, &utp->stabil) ||
998 __get_user(txc.jitcnt, &utp->jitcnt) ||
999 __get_user(txc.calcnt, &utp->calcnt) ||
1000 __get_user(txc.errcnt, &utp->errcnt) ||
1001 __get_user(txc.stbcnt, &utp->stbcnt))
1004 ret = do_adjtimex(&txc);
1006 if(verify_area(VERIFY_WRITE, utp, sizeof(struct timex32)) ||
1007 __put_user(txc.modes, &utp->modes) ||
1008 __put_user(txc.offset, &utp->offset) ||
1009 __put_user(txc.freq, &utp->freq) ||
1010 __put_user(txc.maxerror, &utp->maxerror) ||
1011 __put_user(txc.esterror, &utp->esterror) ||
1012 __put_user(txc.status, &utp->status) ||
1013 __put_user(txc.constant, &utp->constant) ||
1014 __put_user(txc.precision, &utp->precision) ||
1015 __put_user(txc.tolerance, &utp->tolerance) ||
1016 __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
1017 __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
1018 __put_user(txc.tick, &utp->tick) ||
1019 __put_user(txc.ppsfreq, &utp->ppsfreq) ||
1020 __put_user(txc.jitter, &utp->jitter) ||
1021 __put_user(txc.shift, &utp->shift) ||
1022 __put_user(txc.stabil, &utp->stabil) ||
1023 __put_user(txc.jitcnt, &utp->jitcnt) ||
1024 __put_user(txc.calcnt, &utp->calcnt) ||
1025 __put_user(txc.errcnt, &utp->errcnt) ||
1026 __put_user(txc.stbcnt, &utp->stbcnt))
1032 asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
1033 unsigned long prot, unsigned long flags,
1034 unsigned long fd, unsigned long pgoff)
1036 struct mm_struct *mm = current->mm;
1037 unsigned long error;
1038 struct file * file = NULL;
1040 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1041 if (!(flags & MAP_ANONYMOUS)) {
1047 if (prot & PROT_READ)
1048 prot |= vm_force_exec32;
1050 down_write(&mm->mmap_sem);
1051 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1052 up_write(&mm->mmap_sem);
1059 asmlinkage long sys32_olduname(struct oldold_utsname * name)
1062 struct new_utsname *ptr;
1066 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
1069 down_read(&uts_sem);
1071 ptr = vx_new_utsname();
1072 error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
1073 __put_user(0,name->sysname+__OLD_UTS_LEN);
1074 __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
1075 __put_user(0,name->nodename+__OLD_UTS_LEN);
1076 __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
1077 __put_user(0,name->release+__OLD_UTS_LEN);
1078 __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
1079 __put_user(0,name->version+__OLD_UTS_LEN);
1081 char *arch = "x86_64";
1082 if (personality(current->personality) == PER_LINUX32)
1085 __copy_to_user(&name->machine,arch,strlen(arch)+1);
1090 error = error ? -EFAULT : 0;
1095 long sys32_uname(struct old_utsname * name)
1100 down_read(&uts_sem);
1101 err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
1103 if (personality(current->personality) == PER_LINUX32)
1104 err |= copy_to_user(&name->machine, "i686", 5);
1105 return err?-EFAULT:0;
1108 long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
1116 ret = sys_ustat(dev,&u);
1119 if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) ||
1120 __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
1121 __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
1122 __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
1123 __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
1129 asmlinkage long sys32_execve(char *name, compat_uptr_t __user *argv,
1130 compat_uptr_t __user *envp, struct pt_regs regs)
1135 filename = getname(name);
1136 error = PTR_ERR(filename);
1137 if (IS_ERR(filename))
1139 error = compat_do_execve(filename, argv, envp, ®s);
1141 current->ptrace &= ~PT_DTRACE;
1146 asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp, struct pt_regs regs)
1148 void *parent_tid = (void *)regs.rdx;
1149 void *child_tid = (void *)regs.rdi;
1152 return do_fork(clone_flags & ~CLONE_IDLETASK, newsp, ®s, 0,
1153 parent_tid, child_tid);
1157 * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
1160 long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
1162 return sys_lseek(fd, offset, whence);
1165 long sys32_kill(int pid, int sig)
1167 return sys_kill(pid, sig);
1171 long sys32_io_setup(unsigned nr_reqs, u32 *ctx32p)
1174 aio_context_t ctx64;
1175 mm_segment_t oldfs = get_fs();
1177 ret = sys_io_setup(nr_reqs, &ctx64);
1179 /* truncating is ok because it's a user address */
1181 ret = put_user((u32)ctx64, ctx32p);
1185 asmlinkage long sys32_io_submit(aio_context_t ctx_id, int nr,
1186 compat_uptr_t *iocbpp)
1192 if (unlikely(nr < 0))
1195 if (unlikely(!access_ok(VERIFY_READ, iocbpp, (nr*sizeof(*iocbpp)))))
1198 ctx = lookup_ioctx(ctx_id);
1199 if (unlikely(!ctx)) {
1200 pr_debug("EINVAL: io_submit: invalid context id\n");
1204 for (i=0; i<nr; i++) {
1206 struct iocb *user_iocb, tmp;
1208 if (unlikely(__get_user(p32, iocbpp + i))) {
1212 user_iocb = compat_ptr(p32);
1214 if (unlikely(copy_from_user(&tmp, user_iocb, sizeof(tmp)))) {
1219 ret = io_submit_one(ctx, user_iocb, &tmp);
1229 asmlinkage long sys32_io_getevents(aio_context_t ctx_id,
1230 unsigned long min_nr,
1232 struct io_event *events,
1233 struct compat_timespec *timeout)
1238 /* Harden against bogus ptrace */
1239 if (nr >= 0xffffffff ||
1240 !access_ok(VERIFY_WRITE, events, nr * sizeof(struct io_event)))
1242 if (timeout && get_compat_timespec(&t, timeout))
1246 ret = sys_io_getevents(ctx_id,min_nr,nr,events,timeout ? &t : NULL);
1248 if (!ret && timeout && put_compat_timespec(&t, timeout))
1253 asmlinkage long sys32_open(const char * filename, int flags, int mode)
1258 /* don't force O_LARGEFILE */
1259 tmp = getname(filename);
1262 fd = get_unused_fd();
1264 struct file *f = filp_open(tmp, flags, mode);
1266 if (unlikely(IS_ERR(f))) {
1281 u32 payload[(64 / 4) - 3];
1284 extern asmlinkage long
1285 sys_timer_create(clockid_t which_clock,
1286 struct sigevent __user *timer_event_spec,
1287 timer_t __user * created_timer_id);
1290 sys32_timer_create(u32 clock, struct sigevent32 *se32, timer_t *timer_id)
1297 memset(&se, 0, sizeof(struct sigevent));
1298 if (get_user(se.sigev_value.sival_int, &se32->sigev_value) ||
1299 __get_user(se.sigev_signo, &se32->sigev_signo) ||
1300 __get_user(se.sigev_notify, &se32->sigev_notify) ||
1301 __copy_from_user(&se._sigev_un._pad, &se32->payload,
1302 sizeof(se32->payload)))
1305 if (!access_ok(VERIFY_WRITE,timer_id,sizeof(timer_t)))
1310 err = sys_timer_create(clock, se32 ? &se : NULL, timer_id);
1316 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
1317 __u32 len_low, __u32 len_high, int advice)
1319 return sys_fadvise64_64(fd,
1320 (((u64)offset_high)<<32) | offset_low,
1321 (((u64)len_high)<<32) | len_low,
1325 long sys32_vm86_warning(void)
1327 struct task_struct *me = current;
1328 static char lastcomm[8];
1329 if (strcmp(lastcomm, me->comm)) {
1330 printk(KERN_INFO "%s: vm86 mode not supported on 64 bit kernel\n",
1332 strcpy(lastcomm, me->comm);
1337 long sys32_quotactl(void)
1339 struct task_struct *me = current;
1340 static char lastcomm[8];
1341 if (strcmp(lastcomm, me->comm)) {
1342 printk(KERN_INFO "%s: 32bit quotactl not supported on 64 bit kernel\n",
1344 strcpy(lastcomm, me->comm);
1349 cond_syscall(sys32_ipc)
1351 static int __init ia32_init (void)
1353 printk("IA32 emulation $Id: sys_ia32.c,v 1.32 2002/03/24 13:02:28 ak Exp $\n");
1357 __initcall(ia32_init);
1359 extern unsigned long ia32_sys_call_table[];