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/capability.h>
59 #include <linux/compat.h>
60 #include <linux/vfs.h>
61 #include <linux/ptrace.h>
62 #include <linux/fadvise.h>
64 #include <asm/types.h>
66 #include <asm/uaccess.h>
67 #include <asm/semaphore.h>
72 #include "compat_linux.h"
75 /* For this source file, we want overflow handling. */
85 #undef SET_OLDSTAT_UID
86 #undef SET_OLDSTAT_GID
90 #define high2lowuid(uid) ((uid) > 65535) ? (u16)overflowuid : (u16)(uid)
91 #define high2lowgid(gid) ((gid) > 65535) ? (u16)overflowgid : (u16)(gid)
92 #define low2highuid(uid) ((uid) == (u16)-1) ? (uid_t)-1 : (uid_t)(uid)
93 #define low2highgid(gid) ((gid) == (u16)-1) ? (gid_t)-1 : (gid_t)(gid)
94 #define SET_UID16(var, uid) var = high2lowuid(uid)
95 #define SET_GID16(var, gid) var = high2lowgid(gid)
96 #define NEW_TO_OLD_UID(uid) high2lowuid(uid)
97 #define NEW_TO_OLD_GID(gid) high2lowgid(gid)
98 #define SET_OLDSTAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
99 #define SET_OLDSTAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
100 #define SET_STAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
101 #define SET_STAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
103 asmlinkage long sys32_chown16(const char __user * filename, u16 user, u16 group)
105 return sys_chown(filename, low2highuid(user), low2highgid(group));
108 asmlinkage long sys32_lchown16(const char __user * filename, u16 user, u16 group)
110 return sys_lchown(filename, low2highuid(user), low2highgid(group));
113 asmlinkage long sys32_fchown16(unsigned int fd, u16 user, u16 group)
115 return sys_fchown(fd, low2highuid(user), low2highgid(group));
118 asmlinkage long sys32_setregid16(u16 rgid, u16 egid)
120 return sys_setregid(low2highgid(rgid), low2highgid(egid));
123 asmlinkage long sys32_setgid16(u16 gid)
125 return sys_setgid((gid_t)gid);
128 asmlinkage long sys32_setreuid16(u16 ruid, u16 euid)
130 return sys_setreuid(low2highuid(ruid), low2highuid(euid));
133 asmlinkage long sys32_setuid16(u16 uid)
135 return sys_setuid((uid_t)uid);
138 asmlinkage long sys32_setresuid16(u16 ruid, u16 euid, u16 suid)
140 return sys_setresuid(low2highuid(ruid), low2highuid(euid),
144 asmlinkage long sys32_getresuid16(u16 __user *ruid, u16 __user *euid, u16 __user *suid)
148 if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
149 !(retval = put_user(high2lowuid(current->euid), euid)))
150 retval = put_user(high2lowuid(current->suid), suid);
155 asmlinkage long sys32_setresgid16(u16 rgid, u16 egid, u16 sgid)
157 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
161 asmlinkage long sys32_getresgid16(u16 __user *rgid, u16 __user *egid, u16 __user *sgid)
165 if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
166 !(retval = put_user(high2lowgid(current->egid), egid)))
167 retval = put_user(high2lowgid(current->sgid), sgid);
172 asmlinkage long sys32_setfsuid16(u16 uid)
174 return sys_setfsuid((uid_t)uid);
177 asmlinkage long sys32_setfsgid16(u16 gid)
179 return sys_setfsgid((gid_t)gid);
182 static int groups16_to_user(u16 __user *grouplist, struct group_info *group_info)
187 for (i = 0; i < group_info->ngroups; i++) {
188 group = (u16)GROUP_AT(group_info, i);
189 if (put_user(group, grouplist+i))
196 static int groups16_from_user(struct group_info *group_info, u16 __user *grouplist)
201 for (i = 0; i < group_info->ngroups; i++) {
202 if (get_user(group, grouplist+i))
204 GROUP_AT(group_info, i) = (gid_t)group;
210 asmlinkage long sys32_getgroups16(int gidsetsize, u16 __user *grouplist)
217 get_group_info(current->group_info);
218 i = current->group_info->ngroups;
220 if (i > gidsetsize) {
224 if (groups16_to_user(grouplist, current->group_info)) {
230 put_group_info(current->group_info);
234 asmlinkage long sys32_setgroups16(int gidsetsize, u16 __user *grouplist)
236 struct group_info *group_info;
239 if (!capable(CAP_SETGID))
241 if ((unsigned)gidsetsize > NGROUPS_MAX)
244 group_info = groups_alloc(gidsetsize);
247 retval = groups16_from_user(group_info, grouplist);
249 put_group_info(group_info);
253 retval = set_current_groups(group_info);
254 put_group_info(group_info);
259 asmlinkage long sys32_getuid16(void)
261 return high2lowuid(current->uid);
264 asmlinkage long sys32_geteuid16(void)
266 return high2lowuid(current->euid);
269 asmlinkage long sys32_getgid16(void)
271 return high2lowgid(current->gid);
274 asmlinkage long sys32_getegid16(void)
276 return high2lowgid(current->egid);
279 /* 32-bit timeval and related flotsam. */
281 static inline long get_tv32(struct timeval *o, struct compat_timeval __user *i)
283 return (!access_ok(VERIFY_READ, o, sizeof(*o)) ||
284 (__get_user(o->tv_sec, &i->tv_sec) ||
285 __get_user(o->tv_usec, &i->tv_usec)));
288 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
290 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
291 (__put_user(i->tv_sec, &o->tv_sec) ||
292 __put_user(i->tv_usec, &o->tv_usec)));
296 * sys32_ipc() is the de-multiplexer for the SysV IPC calls in 32bit emulation.
298 * This is really horribly ugly.
300 asmlinkage long sys32_ipc(u32 call, int first, int second, int third, u32 ptr)
302 if (call >> 16) /* hack for backward compatibility */
309 return compat_sys_semtimedop(first, compat_ptr(ptr),
310 second, compat_ptr(third));
312 /* struct sembuf is the same on 32 and 64bit :)) */
313 return sys_semtimedop(first, compat_ptr(ptr),
316 return sys_semget(first, second, third);
318 return compat_sys_semctl(first, second, third,
321 return compat_sys_msgsnd(first, second, third,
324 return compat_sys_msgrcv(first, second, 0, third,
327 return sys_msgget((key_t) first, second);
329 return compat_sys_msgctl(first, second, compat_ptr(ptr));
331 return compat_sys_shmat(first, second, third,
334 return sys_shmdt(compat_ptr(ptr));
336 return sys_shmget(first, (unsigned)second, third);
338 return compat_sys_shmctl(first, second, compat_ptr(ptr));
344 asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
349 return sys_truncate(path, (high << 32) | low);
352 asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
357 return sys_ftruncate(fd, (high << 32) | low);
360 int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
364 if (!old_valid_dev(stat->dev) || !old_valid_dev(stat->rdev))
367 err = put_user(old_encode_dev(stat->dev), &statbuf->st_dev);
368 err |= put_user(stat->ino, &statbuf->st_ino);
369 err |= put_user(stat->mode, &statbuf->st_mode);
370 err |= put_user(stat->nlink, &statbuf->st_nlink);
371 err |= put_user(high2lowuid(stat->uid), &statbuf->st_uid);
372 err |= put_user(high2lowgid(stat->gid), &statbuf->st_gid);
373 err |= put_user(old_encode_dev(stat->rdev), &statbuf->st_rdev);
374 err |= put_user(stat->size, &statbuf->st_size);
375 err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
376 err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
377 err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
378 err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
379 err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
380 err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
381 err |= put_user(stat->blksize, &statbuf->st_blksize);
382 err |= put_user(stat->blocks, &statbuf->st_blocks);
384 err |= put_user(0, &statbuf->__unused4[0]);
385 err |= put_user(0, &statbuf->__unused4[1]);
399 unsigned short procs;
403 unsigned int mem_unit;
407 asmlinkage long sys32_sysinfo(struct sysinfo32 __user *info)
411 mm_segment_t old_fs = get_fs ();
414 ret = sys_sysinfo(&s);
416 err = put_user (s.uptime, &info->uptime);
417 err |= __put_user (s.loads[0], &info->loads[0]);
418 err |= __put_user (s.loads[1], &info->loads[1]);
419 err |= __put_user (s.loads[2], &info->loads[2]);
420 err |= __put_user (s.totalram, &info->totalram);
421 err |= __put_user (s.freeram, &info->freeram);
422 err |= __put_user (s.sharedram, &info->sharedram);
423 err |= __put_user (s.bufferram, &info->bufferram);
424 err |= __put_user (s.totalswap, &info->totalswap);
425 err |= __put_user (s.freeswap, &info->freeswap);
426 err |= __put_user (s.procs, &info->procs);
427 err |= __put_user (s.totalhigh, &info->totalhigh);
428 err |= __put_user (s.freehigh, &info->freehigh);
429 err |= __put_user (s.mem_unit, &info->mem_unit);
435 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
436 struct compat_timespec __user *interval)
440 mm_segment_t old_fs = get_fs ();
443 ret = sys_sched_rr_get_interval(pid, &t);
445 if (put_compat_timespec(&t, interval))
450 asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
451 compat_sigset_t __user *oset, size_t sigsetsize)
456 mm_segment_t old_fs = get_fs();
459 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
461 switch (_NSIG_WORDS) {
462 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
463 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
464 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
465 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
469 ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL, sigsetsize);
473 switch (_NSIG_WORDS) {
474 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
475 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
476 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
477 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
479 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
485 asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
491 mm_segment_t old_fs = get_fs();
494 ret = sys_rt_sigpending(&s, sigsetsize);
497 switch (_NSIG_WORDS) {
498 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
499 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
500 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
501 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
503 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
510 sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
514 mm_segment_t old_fs = get_fs();
516 if (copy_siginfo_from_user32(&info, uinfo))
519 ret = sys_rt_sigqueueinfo(pid, sig, &info);
525 * sys32_execve() executes a new program after the asm stub has set
526 * things up for us. This should basically do what I want it to.
529 sys32_execve(struct pt_regs regs)
534 filename = getname(compat_ptr(regs.orig_gpr2));
535 error = PTR_ERR(filename);
536 if (IS_ERR(filename))
538 error = compat_do_execve(filename, compat_ptr(regs.gprs[3]),
539 compat_ptr(regs.gprs[4]), ®s);
543 current->ptrace &= ~PT_DTRACE;
544 task_unlock(current);
545 current->thread.fp_regs.fpc=0;
557 #ifdef CONFIG_MODULES
560 sys32_init_module(void __user *umod, unsigned long len,
561 const char __user *uargs)
563 return sys_init_module(umod, len, uargs);
567 sys32_delete_module(const char __user *name_user, unsigned int flags)
569 return sys_delete_module(name_user, flags);
572 #else /* CONFIG_MODULES */
575 sys32_init_module(void __user *umod, unsigned long len,
576 const char __user *uargs)
582 sys32_delete_module(const char __user *name_user, unsigned int flags)
587 #endif /* CONFIG_MODULES */
589 /* Translations due to time_t size differences. Which affects all
590 sorts of things, like timeval and itimerval. */
592 extern struct timezone sys_tz;
594 asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
598 do_gettimeofday(&ktv);
599 if (put_tv32(tv, &ktv))
603 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
609 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
613 if (!access_ok(VERIFY_READ, i, sizeof(*i)))
615 if (__get_user(o->tv_sec, &i->tv_sec))
617 if (__get_user(usec, &i->tv_usec))
619 o->tv_nsec = usec * 1000;
623 asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
629 if (get_ts32(&kts, tv))
633 if (copy_from_user(&ktz, tz, sizeof(ktz)))
637 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
640 /* These are here just in case some old sparc32 binary calls it. */
641 asmlinkage long sys32_pause(void)
643 current->state = TASK_INTERRUPTIBLE;
645 return -ERESTARTNOHAND;
648 asmlinkage long sys32_pread64(unsigned int fd, char __user *ubuf,
649 size_t count, u32 poshi, u32 poslo)
651 if ((compat_ssize_t) count < 0)
653 return sys_pread64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo));
656 asmlinkage long sys32_pwrite64(unsigned int fd, const char __user *ubuf,
657 size_t count, u32 poshi, u32 poslo)
659 if ((compat_ssize_t) count < 0)
661 return sys_pwrite64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo));
664 asmlinkage compat_ssize_t sys32_readahead(int fd, u32 offhi, u32 offlo, s32 count)
666 return sys_readahead(fd, ((loff_t)AA(offhi) << 32) | AA(offlo), count);
669 asmlinkage long sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, size_t count)
671 mm_segment_t old_fs = get_fs();
675 if (offset && get_user(of, offset))
679 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
682 if (offset && put_user(of, offset))
688 asmlinkage long sys32_sendfile64(int out_fd, int in_fd,
689 compat_loff_t __user *offset, s32 count)
691 mm_segment_t old_fs = get_fs();
695 if (offset && get_user(lof, offset))
699 ret = sys_sendfile64(out_fd, in_fd, offset ? &lof : NULL, count);
702 if (offset && put_user(lof, offset))
708 /* Handle adjtimex compatibility. */
712 s32 offset, freq, maxerror, esterror;
713 s32 status, constant, precision, tolerance;
714 struct compat_timeval time;
716 s32 ppsfreq, jitter, shift, stabil;
717 s32 jitcnt, calcnt, errcnt, stbcnt;
718 s32 :32; s32 :32; s32 :32; s32 :32;
719 s32 :32; s32 :32; s32 :32; s32 :32;
720 s32 :32; s32 :32; s32 :32; s32 :32;
723 extern int do_adjtimex(struct timex *);
725 asmlinkage long sys32_adjtimex(struct timex32 __user *utp)
730 memset(&txc, 0, sizeof(struct timex));
732 if(get_user(txc.modes, &utp->modes) ||
733 __get_user(txc.offset, &utp->offset) ||
734 __get_user(txc.freq, &utp->freq) ||
735 __get_user(txc.maxerror, &utp->maxerror) ||
736 __get_user(txc.esterror, &utp->esterror) ||
737 __get_user(txc.status, &utp->status) ||
738 __get_user(txc.constant, &utp->constant) ||
739 __get_user(txc.precision, &utp->precision) ||
740 __get_user(txc.tolerance, &utp->tolerance) ||
741 __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
742 __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
743 __get_user(txc.tick, &utp->tick) ||
744 __get_user(txc.ppsfreq, &utp->ppsfreq) ||
745 __get_user(txc.jitter, &utp->jitter) ||
746 __get_user(txc.shift, &utp->shift) ||
747 __get_user(txc.stabil, &utp->stabil) ||
748 __get_user(txc.jitcnt, &utp->jitcnt) ||
749 __get_user(txc.calcnt, &utp->calcnt) ||
750 __get_user(txc.errcnt, &utp->errcnt) ||
751 __get_user(txc.stbcnt, &utp->stbcnt))
754 ret = do_adjtimex(&txc);
756 if(put_user(txc.modes, &utp->modes) ||
757 __put_user(txc.offset, &utp->offset) ||
758 __put_user(txc.freq, &utp->freq) ||
759 __put_user(txc.maxerror, &utp->maxerror) ||
760 __put_user(txc.esterror, &utp->esterror) ||
761 __put_user(txc.status, &utp->status) ||
762 __put_user(txc.constant, &utp->constant) ||
763 __put_user(txc.precision, &utp->precision) ||
764 __put_user(txc.tolerance, &utp->tolerance) ||
765 __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
766 __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
767 __put_user(txc.tick, &utp->tick) ||
768 __put_user(txc.ppsfreq, &utp->ppsfreq) ||
769 __put_user(txc.jitter, &utp->jitter) ||
770 __put_user(txc.shift, &utp->shift) ||
771 __put_user(txc.stabil, &utp->stabil) ||
772 __put_user(txc.jitcnt, &utp->jitcnt) ||
773 __put_user(txc.calcnt, &utp->calcnt) ||
774 __put_user(txc.errcnt, &utp->errcnt) ||
775 __put_user(txc.stbcnt, &utp->stbcnt))
782 struct __sysctl_args32 {
792 asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
794 struct __sysctl_args32 tmp;
797 size_t __user *oldlenp = NULL;
798 unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
800 if (copy_from_user(&tmp, args, sizeof(tmp)))
803 if (tmp.oldval && tmp.oldlenp) {
804 /* Duh, this is ugly and might not work if sysctl_args
805 is in read-only memory, but do_sysctl does indirectly
806 a lot of uaccess in both directions and we'd have to
807 basically copy the whole sysctl.c here, and
808 glibc's __sysctl uses rw memory for the structure
810 if (get_user(oldlen, (u32 __user *)compat_ptr(tmp.oldlenp)) ||
811 put_user(oldlen, (size_t __user *)addr))
813 oldlenp = (size_t __user *)addr;
817 error = do_sysctl(compat_ptr(tmp.name), tmp.nlen, compat_ptr(tmp.oldval),
818 oldlenp, compat_ptr(tmp.newval), tmp.newlen);
822 if (get_user(oldlen, (size_t __user *)addr) ||
823 put_user(oldlen, (u32 __user *)compat_ptr(tmp.oldlenp)))
826 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
832 struct stat64_emu31 {
833 unsigned long long st_dev;
835 #define STAT64_HAS_BROKEN_ST_INO 1
837 unsigned int st_mode;
838 unsigned int st_nlink;
841 unsigned long long st_rdev;
845 unsigned char __pad4[4];
846 u32 __pad5; /* future possible st_blocks high bits */
847 u32 st_blocks; /* Number 512-byte blocks allocated. */
853 u32 __pad8; /* will be high 32 bits of ctime someday */
854 unsigned long st_ino;
857 static int cp_stat64(struct stat64_emu31 __user *ubuf, struct kstat *stat)
859 struct stat64_emu31 tmp;
861 memset(&tmp, 0, sizeof(tmp));
863 tmp.st_dev = huge_encode_dev(stat->dev);
864 tmp.st_ino = stat->ino;
865 tmp.__st_ino = (u32)stat->ino;
866 tmp.st_mode = stat->mode;
867 tmp.st_nlink = (unsigned int)stat->nlink;
868 tmp.st_uid = stat->uid;
869 tmp.st_gid = stat->gid;
870 tmp.st_rdev = huge_encode_dev(stat->rdev);
871 tmp.st_size = stat->size;
872 tmp.st_blksize = (u32)stat->blksize;
873 tmp.st_blocks = (u32)stat->blocks;
874 tmp.st_atime = (u32)stat->atime.tv_sec;
875 tmp.st_mtime = (u32)stat->mtime.tv_sec;
876 tmp.st_ctime = (u32)stat->ctime.tv_sec;
878 return copy_to_user(ubuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
881 asmlinkage long sys32_stat64(char __user * filename, struct stat64_emu31 __user * statbuf)
884 int ret = vfs_stat(filename, &stat);
886 ret = cp_stat64(statbuf, &stat);
890 asmlinkage long sys32_lstat64(char __user * filename, struct stat64_emu31 __user * statbuf)
893 int ret = vfs_lstat(filename, &stat);
895 ret = cp_stat64(statbuf, &stat);
899 asmlinkage long sys32_fstat64(unsigned long fd, struct stat64_emu31 __user * statbuf)
902 int ret = vfs_fstat(fd, &stat);
904 ret = cp_stat64(statbuf, &stat);
908 asmlinkage long sys32_fstatat64(unsigned int dfd, char __user *filename,
909 struct stat64_emu31 __user* statbuf, int flag)
914 if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
917 if (flag & AT_SYMLINK_NOFOLLOW)
918 error = vfs_lstat_fd(dfd, filename, &stat);
920 error = vfs_stat_fd(dfd, filename, &stat);
923 error = cp_stat64(statbuf, &stat);
929 * Linux/i386 didn't use to be able to handle more than
930 * 4 system call parameters, so these system calls used a memory
931 * block for parameter passing..
934 struct mmap_arg_struct_emu31 {
943 /* common code for old and new mmaps */
944 static inline long do_mmap2(
945 unsigned long addr, unsigned long len,
946 unsigned long prot, unsigned long flags,
947 unsigned long fd, unsigned long pgoff)
949 struct file * file = NULL;
950 unsigned long error = -EBADF;
952 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
953 if (!(flags & MAP_ANONYMOUS)) {
959 down_write(¤t->mm->mmap_sem);
960 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
961 if (!IS_ERR((void *) error) && error + len >= 0x80000000ULL) {
962 /* Result is out of bounds. */
963 do_munmap(current->mm, addr, len);
966 up_write(¤t->mm->mmap_sem);
975 asmlinkage unsigned long
976 old32_mmap(struct mmap_arg_struct_emu31 __user *arg)
978 struct mmap_arg_struct_emu31 a;
981 if (copy_from_user(&a, arg, sizeof(a)))
985 if (a.offset & ~PAGE_MASK)
988 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
994 sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg)
996 struct mmap_arg_struct_emu31 a;
999 if (copy_from_user(&a, arg, sizeof(a)))
1001 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
1006 asmlinkage long sys32_read(unsigned int fd, char __user * buf, size_t count)
1008 if ((compat_ssize_t) count < 0)
1011 return sys_read(fd, buf, count);
1014 asmlinkage long sys32_write(unsigned int fd, char __user * buf, size_t count)
1016 if ((compat_ssize_t) count < 0)
1019 return sys_write(fd, buf, count);
1022 asmlinkage long sys32_clone(struct pt_regs regs)
1024 unsigned long clone_flags;
1025 unsigned long newsp;
1026 int __user *parent_tidptr, *child_tidptr;
1028 clone_flags = regs.gprs[3] & 0xffffffffUL;
1029 newsp = regs.orig_gpr2 & 0x7fffffffUL;
1030 parent_tidptr = compat_ptr(regs.gprs[4]);
1031 child_tidptr = compat_ptr(regs.gprs[5]);
1033 newsp = regs.gprs[15];
1034 return do_fork(clone_flags, newsp, ®s, 0,
1035 parent_tidptr, child_tidptr);
1039 * 31 bit emulation wrapper functions for sys_fadvise64/fadvise64_64.
1040 * These need to rewrite the advise values for POSIX_FADV_{DONTNEED,NOREUSE}
1041 * because the 31 bit values differ from the 64 bit values.
1045 sys32_fadvise64(int fd, loff_t offset, size_t len, int advise)
1048 advise = POSIX_FADV_DONTNEED;
1049 else if (advise == 5)
1050 advise = POSIX_FADV_NOREUSE;
1051 return sys_fadvise64(fd, offset, len, advise);
1054 struct fadvise64_64_args {
1062 sys32_fadvise64_64(struct fadvise64_64_args __user *args)
1064 struct fadvise64_64_args a;
1066 if ( copy_from_user(&a, args, sizeof(a)) )
1069 a.advice = POSIX_FADV_DONTNEED;
1070 else if (a.advice == 5)
1071 a.advice = POSIX_FADV_NOREUSE;
1072 return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);