2 * arch/s390x/kernel/linux32.c
5 * Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7 * Gerhard Tonn (ton@de.ibm.com)
8 * Thomas Spatzier (tspat@de.ibm.com)
10 * Conversion between 31bit and 64bit native syscalls.
12 * Heavily inspired by the 32-bit Sparc compat code which is
13 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
14 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
19 #include <linux/config.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
24 #include <linux/file.h>
25 #include <linux/signal.h>
26 #include <linux/resource.h>
27 #include <linux/times.h>
28 #include <linux/utsname.h>
29 #include <linux/timex.h>
30 #include <linux/smp.h>
31 #include <linux/smp_lock.h>
32 #include <linux/sem.h>
33 #include <linux/msg.h>
34 #include <linux/shm.h>
35 #include <linux/slab.h>
36 #include <linux/uio.h>
37 #include <linux/nfs_fs.h>
38 #include <linux/quota.h>
39 #include <linux/module.h>
40 #include <linux/sunrpc/svc.h>
41 #include <linux/nfsd/nfsd.h>
42 #include <linux/nfsd/cache.h>
43 #include <linux/nfsd/xdr.h>
44 #include <linux/nfsd/syscall.h>
45 #include <linux/poll.h>
46 #include <linux/personality.h>
47 #include <linux/stat.h>
48 #include <linux/filter.h>
49 #include <linux/highmem.h>
50 #include <linux/highuid.h>
51 #include <linux/mman.h>
52 #include <linux/ipv6.h>
54 #include <linux/icmpv6.h>
55 #include <linux/syscalls.h>
56 #include <linux/sysctl.h>
57 #include <linux/binfmts.h>
58 #include <linux/compat.h>
59 #include <linux/vfs.h>
60 #include <linux/ptrace.h>
62 #include <asm/types.h>
64 #include <asm/uaccess.h>
65 #include <asm/semaphore.h>
70 #include "compat_linux.h"
73 /* For this source file, we want overflow handling. */
83 #undef SET_OLDSTAT_UID
84 #undef SET_OLDSTAT_GID
88 #define high2lowuid(uid) ((uid) > 65535) ? (u16)overflowuid : (u16)(uid)
89 #define high2lowgid(gid) ((gid) > 65535) ? (u16)overflowgid : (u16)(gid)
90 #define low2highuid(uid) ((uid) == (u16)-1) ? (uid_t)-1 : (uid_t)(uid)
91 #define low2highgid(gid) ((gid) == (u16)-1) ? (gid_t)-1 : (gid_t)(gid)
92 #define SET_UID16(var, uid) var = high2lowuid(uid)
93 #define SET_GID16(var, gid) var = high2lowgid(gid)
94 #define NEW_TO_OLD_UID(uid) high2lowuid(uid)
95 #define NEW_TO_OLD_GID(gid) high2lowgid(gid)
96 #define SET_OLDSTAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
97 #define SET_OLDSTAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
98 #define SET_STAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
99 #define SET_STAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
101 asmlinkage long sys32_chown16(const char * filename, u16 user, u16 group)
103 return sys_chown(filename, low2highuid(user), low2highgid(group));
106 asmlinkage long sys32_lchown16(const char * filename, u16 user, u16 group)
108 return sys_lchown(filename, low2highuid(user), low2highgid(group));
111 asmlinkage long sys32_fchown16(unsigned int fd, u16 user, u16 group)
113 return sys_fchown(fd, low2highuid(user), low2highgid(group));
116 asmlinkage long sys32_setregid16(u16 rgid, u16 egid)
118 return sys_setregid(low2highgid(rgid), low2highgid(egid));
121 asmlinkage long sys32_setgid16(u16 gid)
123 return sys_setgid((gid_t)gid);
126 asmlinkage long sys32_setreuid16(u16 ruid, u16 euid)
128 return sys_setreuid(low2highuid(ruid), low2highuid(euid));
131 asmlinkage long sys32_setuid16(u16 uid)
133 return sys_setuid((uid_t)uid);
136 asmlinkage long sys32_setresuid16(u16 ruid, u16 euid, u16 suid)
138 return sys_setresuid(low2highuid(ruid), low2highuid(euid),
142 asmlinkage long sys32_getresuid16(u16 *ruid, u16 *euid, u16 *suid)
146 if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
147 !(retval = put_user(high2lowuid(current->euid), euid)))
148 retval = put_user(high2lowuid(current->suid), suid);
153 asmlinkage long sys32_setresgid16(u16 rgid, u16 egid, u16 sgid)
155 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
159 asmlinkage long sys32_getresgid16(u16 *rgid, u16 *egid, u16 *sgid)
163 if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
164 !(retval = put_user(high2lowgid(current->egid), egid)))
165 retval = put_user(high2lowgid(current->sgid), sgid);
170 asmlinkage long sys32_setfsuid16(u16 uid)
172 return sys_setfsuid((uid_t)uid);
175 asmlinkage long sys32_setfsgid16(u16 gid)
177 return sys_setfsgid((gid_t)gid);
180 static int groups16_to_user(u16 *grouplist, struct group_info *group_info)
185 for (i = 0; i < group_info->ngroups; i++) {
186 group = (u16)GROUP_AT(group_info, i);
187 if (put_user(group, grouplist+i))
194 static int groups16_from_user(struct group_info *group_info, u16 *grouplist)
199 for (i = 0; i < group_info->ngroups; i++) {
200 if (get_user(group, grouplist+i))
202 GROUP_AT(group_info, i) = (gid_t)group;
208 asmlinkage long sys32_getgroups16(int gidsetsize, u16 *grouplist)
215 get_group_info(current->group_info);
216 i = current->group_info->ngroups;
218 if (i > gidsetsize) {
222 if (groups16_to_user(grouplist, current->group_info)) {
228 put_group_info(current->group_info);
232 asmlinkage long sys32_setgroups16(int gidsetsize, u16 *grouplist)
234 struct group_info *group_info;
237 if (!capable(CAP_SETGID))
239 if ((unsigned)gidsetsize > NGROUPS_MAX)
242 group_info = groups_alloc(gidsetsize);
245 retval = groups16_from_user(group_info, grouplist);
247 put_group_info(group_info);
251 retval = set_current_groups(group_info);
252 put_group_info(group_info);
257 asmlinkage long sys32_getuid16(void)
259 return high2lowuid(current->uid);
262 asmlinkage long sys32_geteuid16(void)
264 return high2lowuid(current->euid);
267 asmlinkage long sys32_getgid16(void)
269 return high2lowgid(current->gid);
272 asmlinkage long sys32_getegid16(void)
274 return high2lowgid(current->egid);
277 /* 32-bit timeval and related flotsam. */
279 static inline long get_tv32(struct timeval *o, struct compat_timeval *i)
281 return (!access_ok(VERIFY_READ, tv32, sizeof(*tv32)) ||
282 (__get_user(o->tv_sec, &i->tv_sec) ||
283 __get_user(o->tv_usec, &i->tv_usec)));
286 static inline long put_tv32(struct compat_timeval *o, struct timeval *i)
288 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
289 (__put_user(i->tv_sec, &o->tv_sec) ||
290 __put_user(i->tv_usec, &o->tv_usec)));
294 * sys32_ipc() is the de-multiplexer for the SysV IPC calls in 32bit emulation.
296 * This is really horribly ugly.
298 asmlinkage long sys32_ipc(u32 call, int first, int second, int third, u32 ptr)
300 if (call >> 16) /* hack for backward compatibility */
307 return compat_sys_semtimedop(first, compat_ptr(ptr),
308 second, compat_ptr(third));
310 /* struct sembuf is the same on 32 and 64bit :)) */
311 return sys_semtimedop(first, compat_ptr(ptr),
314 return sys_semget(first, second, third);
316 return compat_sys_semctl(first, second, third,
319 return compat_sys_msgsnd(first, second, third,
322 return compat_sys_msgrcv(first, second, 0, third,
325 return sys_msgget((key_t) first, second);
327 return compat_sys_msgctl(first, second, compat_ptr(ptr));
329 return compat_sys_shmat(first, second, third,
332 return sys_shmdt(compat_ptr(ptr));
334 return sys_shmget(first, second, third);
336 return compat_sys_shmctl(first, second, compat_ptr(ptr));
342 asmlinkage long sys32_truncate64(const char * path, unsigned long high, unsigned long low)
347 return sys_truncate(path, (high << 32) | low);
350 asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
355 return sys_ftruncate(fd, (high << 32) | low);
358 /* readdir & getdents */
360 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
361 #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
363 struct old_linux_dirent32 {
366 unsigned short d_namlen;
370 struct readdir_callback32 {
371 struct old_linux_dirent32 * dirent;
375 static int fillonedir(void * __buf, const char * name, int namlen,
376 loff_t offset, ino_t ino, unsigned int d_type)
378 struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf;
379 struct old_linux_dirent32 * dirent;
384 dirent = buf->dirent;
385 put_user(ino, &dirent->d_ino);
386 put_user(offset, &dirent->d_offset);
387 put_user(namlen, &dirent->d_namlen);
388 copy_to_user(dirent->d_name, name, namlen);
389 put_user(0, dirent->d_name + namlen);
393 asmlinkage long old32_readdir(unsigned int fd, struct old_linux_dirent32 *dirent, unsigned int count)
397 struct readdir_callback32 buf;
406 error = vfs_readdir(file, fillonedir, &buf);
417 struct linux_dirent32 {
420 unsigned short d_reclen;
424 struct getdents_callback32 {
425 struct linux_dirent32 * current_dir;
426 struct linux_dirent32 * previous;
431 static int filldir(void * __buf, const char * name, int namlen, loff_t offset, ino_t ino,
434 struct linux_dirent32 * dirent;
435 struct getdents_callback32 * buf = (struct getdents_callback32 *) __buf;
436 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
438 buf->error = -EINVAL; /* only used if we fail.. */
439 if (reclen > buf->count)
441 dirent = buf->previous;
443 put_user(offset, &dirent->d_off);
444 dirent = buf->current_dir;
445 buf->previous = dirent;
446 put_user(ino, &dirent->d_ino);
447 put_user(reclen, &dirent->d_reclen);
448 copy_to_user(dirent->d_name, name, namlen);
449 put_user(0, dirent->d_name + namlen);
450 buf->current_dir = ((void *)dirent) + reclen;
451 buf->count -= reclen;
455 asmlinkage long sys32_getdents(unsigned int fd, struct linux_dirent32 *dirent, unsigned int count)
458 struct linux_dirent32 * lastdirent;
459 struct getdents_callback32 buf;
466 buf.current_dir = dirent;
471 error = vfs_readdir(file, filldir, &buf);
474 lastdirent = buf.previous;
477 put_user(file->f_pos, &lastdirent->d_off);
478 error = count - buf.count;
486 /* end of readdir & getdents */
488 int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf)
492 if (!old_valid_dev(stat->dev) || !old_valid_dev(stat->rdev))
495 err = put_user(old_encode_dev(stat->dev), &statbuf->st_dev);
496 err |= put_user(stat->ino, &statbuf->st_ino);
497 err |= put_user(stat->mode, &statbuf->st_mode);
498 err |= put_user(stat->nlink, &statbuf->st_nlink);
499 err |= put_user(high2lowuid(stat->uid), &statbuf->st_uid);
500 err |= put_user(high2lowgid(stat->gid), &statbuf->st_gid);
501 err |= put_user(old_encode_dev(stat->rdev), &statbuf->st_rdev);
502 err |= put_user(stat->size, &statbuf->st_size);
503 err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
504 err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
505 err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
506 err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
507 err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
508 err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
509 err |= put_user(stat->blksize, &statbuf->st_blksize);
510 err |= put_user(stat->blocks, &statbuf->st_blocks);
512 err |= put_user(0, &statbuf->__unused4[0]);
513 err |= put_user(0, &statbuf->__unused4[1]);
527 unsigned short procs;
531 unsigned int mem_unit;
535 asmlinkage long sys32_sysinfo(struct sysinfo32 __user *info)
539 mm_segment_t old_fs = get_fs ();
542 ret = sys_sysinfo(&s);
544 err = put_user (s.uptime, &info->uptime);
545 err |= __put_user (s.loads[0], &info->loads[0]);
546 err |= __put_user (s.loads[1], &info->loads[1]);
547 err |= __put_user (s.loads[2], &info->loads[2]);
548 err |= __put_user (s.totalram, &info->totalram);
549 err |= __put_user (s.freeram, &info->freeram);
550 err |= __put_user (s.sharedram, &info->sharedram);
551 err |= __put_user (s.bufferram, &info->bufferram);
552 err |= __put_user (s.totalswap, &info->totalswap);
553 err |= __put_user (s.freeswap, &info->freeswap);
554 err |= __put_user (s.procs, &info->procs);
555 err |= __put_user (s.totalhigh, &info->totalhigh);
556 err |= __put_user (s.freehigh, &info->freehigh);
557 err |= __put_user (s.mem_unit, &info->mem_unit);
563 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
564 struct compat_timespec __user *interval)
568 mm_segment_t old_fs = get_fs ();
571 ret = sys_sched_rr_get_interval(pid, &t);
573 if (put_compat_timespec(&t, interval))
578 asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
579 compat_sigset_t __user *oset, size_t sigsetsize)
584 mm_segment_t old_fs = get_fs();
587 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
589 switch (_NSIG_WORDS) {
590 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
591 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
592 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
593 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
597 ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL, sigsetsize);
601 switch (_NSIG_WORDS) {
602 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
603 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
604 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
605 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
607 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
613 asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
619 mm_segment_t old_fs = get_fs();
622 ret = sys_rt_sigpending(&s, sigsetsize);
625 switch (_NSIG_WORDS) {
626 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
627 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
628 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
629 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
631 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
638 copy_siginfo_to_user32(siginfo_t32 *to, siginfo_t *from);
641 sys32_rt_sigtimedwait(compat_sigset_t *uthese, siginfo_t32 *uinfo,
642 struct compat_timespec *uts, size_t sigsetsize)
646 compat_sigset_t these32;
651 /* XXX: Don't preclude handling different sized sigset_t's. */
652 if (sigsetsize != sizeof(sigset_t))
655 if (copy_from_user (&these32, uthese, sizeof(compat_sigset_t)))
658 switch (_NSIG_WORDS) {
659 case 4: these.sig[3] = these32.sig[6] | (((long)these32.sig[7]) << 32);
660 case 3: these.sig[2] = these32.sig[4] | (((long)these32.sig[5]) << 32);
661 case 2: these.sig[1] = these32.sig[2] | (((long)these32.sig[3]) << 32);
662 case 1: these.sig[0] = these32.sig[0] | (((long)these32.sig[1]) << 32);
666 * Invert the set of allowed signals to get those we
669 sigdelsetmask(&these, sigmask(SIGKILL)|sigmask(SIGSTOP));
673 if (get_compat_timespec(&ts, uts))
675 if (ts.tv_nsec >= 1000000000L || ts.tv_nsec < 0
680 spin_lock_irq(¤t->sighand->siglock);
681 sig = dequeue_signal(current, &these, &info);
683 /* None ready -- temporarily unblock those we're interested
684 in so that we'll be awakened when they arrive. */
685 current->real_blocked = current->blocked;
686 sigandsets(¤t->blocked, ¤t->blocked, &these);
688 spin_unlock_irq(¤t->sighand->siglock);
690 timeout = MAX_SCHEDULE_TIMEOUT;
692 timeout = (timespec_to_jiffies(&ts)
693 + (ts.tv_sec || ts.tv_nsec));
695 current->state = TASK_INTERRUPTIBLE;
696 timeout = schedule_timeout(timeout);
698 spin_lock_irq(¤t->sighand->siglock);
699 sig = dequeue_signal(current, &these, &info);
700 current->blocked = current->real_blocked;
701 siginitset(¤t->real_blocked, 0);
704 spin_unlock_irq(¤t->sighand->siglock);
709 if (copy_siginfo_to_user32(uinfo, &info))
722 sys32_rt_sigqueueinfo(int pid, int sig, siginfo_t32 __user *uinfo)
726 mm_segment_t old_fs = get_fs();
728 if (copy_from_user (&info, uinfo, 3*sizeof(int)) ||
729 copy_from_user (info._sifields._pad, uinfo->_sifields._pad, SI_PAD_SIZE))
732 ret = sys_rt_sigqueueinfo(pid, sig, &info);
738 * sys32_execve() executes a new program after the asm stub has set
739 * things up for us. This should basically do what I want it to.
742 sys32_execve(struct pt_regs regs)
747 filename = getname(compat_ptr(regs.orig_gpr2));
748 error = PTR_ERR(filename);
749 if (IS_ERR(filename))
751 error = compat_do_execve(filename, compat_ptr(regs.gprs[3]),
752 compat_ptr(regs.gprs[4]), ®s);
755 current->ptrace &= ~PT_DTRACE;
756 current->thread.fp_regs.fpc=0;
768 #ifdef CONFIG_MODULES
771 sys32_init_module(void __user *umod, unsigned long len,
772 const char __user *uargs)
774 return sys_init_module(umod, len, uargs);
778 sys32_delete_module(const char __user *name_user, unsigned int flags)
780 return sys_delete_module(name_user, flags);
783 #else /* CONFIG_MODULES */
786 sys32_init_module(void __user *umod, unsigned long len,
787 const char __user *uargs)
793 sys32_delete_module(const char __user *name_user, unsigned int flags)
798 #endif /* CONFIG_MODULES */
800 /* Translations due to time_t size differences. Which affects all
801 sorts of things, like timeval and itimerval. */
803 extern struct timezone sys_tz;
805 asmlinkage long sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz)
809 do_gettimeofday(&ktv);
810 if (put_tv32(tv, &ktv))
814 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
820 static inline long get_ts32(struct timespec *o, struct compat_timeval *i)
824 if (!access_ok(VERIFY_READ, i, sizeof(*i)))
826 if (__get_user(o->tv_sec, &i->tv_sec))
828 if (__get_user(usec, &i->tv_usec))
830 o->tv_nsec = usec * 1000;
834 asmlinkage long sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz)
840 if (get_ts32(&kts, tv))
844 if (copy_from_user(&ktz, tz, sizeof(ktz)))
848 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
851 /* These are here just in case some old sparc32 binary calls it. */
852 asmlinkage long sys32_pause(void)
854 current->state = TASK_INTERRUPTIBLE;
856 return -ERESTARTNOHAND;
859 asmlinkage long sys32_pread64(unsigned int fd, char *ubuf,
860 size_t count, u32 poshi, u32 poslo)
862 if ((compat_ssize_t) count < 0)
864 return sys_pread64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo));
867 asmlinkage long sys32_pwrite64(unsigned int fd, const char *ubuf,
868 size_t count, u32 poshi, u32 poslo)
870 if ((compat_ssize_t) count < 0)
872 return sys_pwrite64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo));
875 asmlinkage compat_ssize_t sys32_readahead(int fd, u32 offhi, u32 offlo, s32 count)
877 return sys_readahead(fd, ((loff_t)AA(offhi) << 32) | AA(offlo), count);
880 asmlinkage long sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset, size_t count)
882 mm_segment_t old_fs = get_fs();
886 if (offset && get_user(of, offset))
890 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
893 if (!ret && offset && put_user(of, offset))
899 asmlinkage long sys32_sendfile64(int out_fd, int in_fd,
900 compat_loff_t *offset, s32 count)
902 mm_segment_t old_fs = get_fs();
906 if (offset && get_user(lof, offset))
910 ret = sys_sendfile64(out_fd, in_fd, offset ? &lof : NULL, count);
913 if (offset && put_user(lof, offset))
919 /* Handle adjtimex compatibility. */
923 s32 offset, freq, maxerror, esterror;
924 s32 status, constant, precision, tolerance;
925 struct compat_timeval time;
927 s32 ppsfreq, jitter, shift, stabil;
928 s32 jitcnt, calcnt, errcnt, stbcnt;
929 s32 :32; s32 :32; s32 :32; s32 :32;
930 s32 :32; s32 :32; s32 :32; s32 :32;
931 s32 :32; s32 :32; s32 :32; s32 :32;
934 extern int do_adjtimex(struct timex *);
936 asmlinkage long sys32_adjtimex(struct timex32 *utp)
941 memset(&txc, 0, sizeof(struct timex));
943 if(get_user(txc.modes, &utp->modes) ||
944 __get_user(txc.offset, &utp->offset) ||
945 __get_user(txc.freq, &utp->freq) ||
946 __get_user(txc.maxerror, &utp->maxerror) ||
947 __get_user(txc.esterror, &utp->esterror) ||
948 __get_user(txc.status, &utp->status) ||
949 __get_user(txc.constant, &utp->constant) ||
950 __get_user(txc.precision, &utp->precision) ||
951 __get_user(txc.tolerance, &utp->tolerance) ||
952 __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
953 __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
954 __get_user(txc.tick, &utp->tick) ||
955 __get_user(txc.ppsfreq, &utp->ppsfreq) ||
956 __get_user(txc.jitter, &utp->jitter) ||
957 __get_user(txc.shift, &utp->shift) ||
958 __get_user(txc.stabil, &utp->stabil) ||
959 __get_user(txc.jitcnt, &utp->jitcnt) ||
960 __get_user(txc.calcnt, &utp->calcnt) ||
961 __get_user(txc.errcnt, &utp->errcnt) ||
962 __get_user(txc.stbcnt, &utp->stbcnt))
965 ret = do_adjtimex(&txc);
967 if(put_user(txc.modes, &utp->modes) ||
968 __put_user(txc.offset, &utp->offset) ||
969 __put_user(txc.freq, &utp->freq) ||
970 __put_user(txc.maxerror, &utp->maxerror) ||
971 __put_user(txc.esterror, &utp->esterror) ||
972 __put_user(txc.status, &utp->status) ||
973 __put_user(txc.constant, &utp->constant) ||
974 __put_user(txc.precision, &utp->precision) ||
975 __put_user(txc.tolerance, &utp->tolerance) ||
976 __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
977 __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
978 __put_user(txc.tick, &utp->tick) ||
979 __put_user(txc.ppsfreq, &utp->ppsfreq) ||
980 __put_user(txc.jitter, &utp->jitter) ||
981 __put_user(txc.shift, &utp->shift) ||
982 __put_user(txc.stabil, &utp->stabil) ||
983 __put_user(txc.jitcnt, &utp->jitcnt) ||
984 __put_user(txc.calcnt, &utp->calcnt) ||
985 __put_user(txc.errcnt, &utp->errcnt) ||
986 __put_user(txc.stbcnt, &utp->stbcnt))
992 struct __sysctl_args32 {
1002 asmlinkage long sys32_sysctl(struct __sysctl_args32 *args)
1004 struct __sysctl_args32 tmp;
1006 size_t oldlen, *oldlenp = NULL;
1007 unsigned long addr = (((long)&args->__unused[0]) + 7) & ~7;
1009 if (copy_from_user(&tmp, args, sizeof(tmp)))
1012 if (tmp.oldval && tmp.oldlenp) {
1013 /* Duh, this is ugly and might not work if sysctl_args
1014 is in read-only memory, but do_sysctl does indirectly
1015 a lot of uaccess in both directions and we'd have to
1016 basically copy the whole sysctl.c here, and
1017 glibc's __sysctl uses rw memory for the structure
1019 if (get_user(oldlen, (u32 *)A(tmp.oldlenp)) ||
1020 put_user(oldlen, (size_t *)addr))
1022 oldlenp = (size_t *)addr;
1026 error = do_sysctl((int *)A(tmp.name), tmp.nlen, (void *)A(tmp.oldval),
1027 oldlenp, (void *)A(tmp.newval), tmp.newlen);
1031 if (get_user(oldlen, (size_t *)addr) ||
1032 put_user(oldlen, (u32 *)A(tmp.oldlenp)))
1035 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
1040 struct stat64_emu31 {
1041 unsigned long long st_dev;
1042 unsigned int __pad1;
1043 #define STAT64_HAS_BROKEN_ST_INO 1
1045 unsigned int st_mode;
1046 unsigned int st_nlink;
1049 unsigned long long st_rdev;
1050 unsigned int __pad3;
1053 unsigned char __pad4[4];
1054 u32 __pad5; /* future possible st_blocks high bits */
1055 u32 st_blocks; /* Number 512-byte blocks allocated. */
1061 u32 __pad8; /* will be high 32 bits of ctime someday */
1062 unsigned long st_ino;
1065 static int cp_stat64(struct stat64_emu31 *ubuf, struct kstat *stat)
1067 struct stat64_emu31 tmp;
1069 memset(&tmp, 0, sizeof(tmp));
1071 tmp.st_dev = huge_encode_dev(stat->dev);
1072 tmp.st_ino = stat->ino;
1073 tmp.__st_ino = (u32)stat->ino;
1074 tmp.st_mode = stat->mode;
1075 tmp.st_nlink = (unsigned int)stat->nlink;
1076 tmp.st_uid = stat->uid;
1077 tmp.st_gid = stat->gid;
1078 tmp.st_rdev = huge_encode_dev(stat->rdev);
1079 tmp.st_size = stat->size;
1080 tmp.st_blksize = (u32)stat->blksize;
1081 tmp.st_blocks = (u32)stat->blocks;
1082 tmp.st_atime = (u32)stat->atime.tv_sec;
1083 tmp.st_mtime = (u32)stat->mtime.tv_sec;
1084 tmp.st_ctime = (u32)stat->ctime.tv_sec;
1086 return copy_to_user(ubuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
1089 asmlinkage long sys32_stat64(char * filename, struct stat64_emu31 * statbuf)
1092 int ret = vfs_stat(filename, &stat);
1094 ret = cp_stat64(statbuf, &stat);
1098 asmlinkage long sys32_lstat64(char * filename, struct stat64_emu31 * statbuf)
1101 int ret = vfs_lstat(filename, &stat);
1103 ret = cp_stat64(statbuf, &stat);
1107 asmlinkage long sys32_fstat64(unsigned long fd, struct stat64_emu31 * statbuf)
1110 int ret = vfs_fstat(fd, &stat);
1112 ret = cp_stat64(statbuf, &stat);
1117 * Linux/i386 didn't use to be able to handle more than
1118 * 4 system call parameters, so these system calls used a memory
1119 * block for parameter passing..
1122 struct mmap_arg_struct_emu31 {
1131 /* common code for old and new mmaps */
1132 static inline long do_mmap2(
1133 unsigned long addr, unsigned long len,
1134 unsigned long prot, unsigned long flags,
1135 unsigned long fd, unsigned long pgoff)
1137 struct file * file = NULL;
1138 unsigned long error = -EBADF;
1140 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1141 if (!(flags & MAP_ANONYMOUS)) {
1147 down_write(¤t->mm->mmap_sem);
1148 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1149 if (!IS_ERR((void *) error) && error + len >= 0x80000000ULL) {
1150 /* Result is out of bounds. */
1151 do_munmap(current->mm, addr, len);
1154 up_write(¤t->mm->mmap_sem);
1163 asmlinkage unsigned long
1164 old32_mmap(struct mmap_arg_struct_emu31 *arg)
1166 struct mmap_arg_struct_emu31 a;
1167 int error = -EFAULT;
1169 if (copy_from_user(&a, arg, sizeof(a)))
1173 if (a.offset & ~PAGE_MASK)
1176 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
1182 sys32_mmap2(struct mmap_arg_struct_emu31 *arg)
1184 struct mmap_arg_struct_emu31 a;
1185 int error = -EFAULT;
1187 if (copy_from_user(&a, arg, sizeof(a)))
1189 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
1194 asmlinkage long sys32_read(unsigned int fd, char * buf, size_t count)
1196 if ((compat_ssize_t) count < 0)
1199 return sys_read(fd, buf, count);
1202 asmlinkage long sys32_write(unsigned int fd, char * buf, size_t count)
1204 if ((compat_ssize_t) count < 0)
1207 return sys_write(fd, buf, count);
1210 asmlinkage long sys32_clone(struct pt_regs regs)
1212 unsigned long clone_flags;
1213 unsigned long newsp;
1214 int *parent_tidptr, *child_tidptr;
1216 clone_flags = regs.gprs[3] & 0xffffffffUL;
1217 newsp = regs.orig_gpr2 & 0x7fffffffUL;
1218 parent_tidptr = (int *) (regs.gprs[4] & 0x7fffffffUL);
1219 child_tidptr = (int *) (regs.gprs[5] & 0x7fffffffUL);
1221 newsp = regs.gprs[15];
1222 return do_fork(clone_flags & ~CLONE_IDLETASK, newsp, ®s, 0,
1223 parent_tidptr, child_tidptr);
1227 * Wrapper function for sys_timer_create.
1229 extern asmlinkage long
1230 sys_timer_create(clockid_t, struct sigevent *, timer_t *);
1233 sys32_timer_create(clockid_t which_clock, struct sigevent32 *se32,
1238 mm_segment_t old_fs;
1242 return sys_timer_create(which_clock, NULL, timer_id);
1244 /* XXX: converting se32 to se is filthy because of the
1245 * two union members. For now it is ok, because the pointers
1246 * are not touched in kernel.
1248 memset(&se, 0, sizeof(se));
1249 if (get_user(se.sigev_value.sival_int, &se32->sigev_value.sival_int) ||
1250 get_user(se.sigev_signo, &se32->sigev_signo) ||
1251 get_user(se.sigev_notify, &se32->sigev_notify) ||
1252 copy_from_user(&se._sigev_un._pad, &se32->_sigev_un._pad,
1253 sizeof(se._sigev_un._pad)))
1258 ret = sys_timer_create(which_clock, &se, &ktimer_id);
1262 ret = put_user (ktimer_id, timer_id);