^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * sys_sparc32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 VA Linux Co
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (C) 2000 Hewlett-Packard Co.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Copyright (C) 2000,2001,2002 Andi Kleen, SuSE Labs (x86-64 port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * These routines maintain argument size conversion between 32bit and 64bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * environment. In 2.5 most of this should be moved to a generic directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * This file assumes that there is a hole at the end of user address space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Some of the functions are LE specific currently. These are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * hopefully all marked. This should be fixed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/times.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/personality.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/rwsem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/highuid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <asm/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <asm/vgtod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <asm/ia32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define AA(__x) ((unsigned long)(__x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) SYSCALL_DEFINE3(ia32_truncate64, const char __user *, filename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) unsigned long, offset_low, unsigned long, offset_high)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return ksys_truncate(filename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ((loff_t) offset_high << 32) | offset_low);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) SYSCALL_DEFINE3(ia32_ftruncate64, unsigned int, fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) unsigned long, offset_low, unsigned long, offset_high)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return ksys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* warning: next two assume little endian */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) SYSCALL_DEFINE5(ia32_pread64, unsigned int, fd, char __user *, ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u32, count, u32, poslo, u32, poshi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return ksys_pread64(fd, ubuf, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ((loff_t)AA(poshi) << 32) | AA(poslo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) SYSCALL_DEFINE5(ia32_pwrite64, unsigned int, fd, const char __user *, ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u32, count, u32, poslo, u32, poshi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return ksys_pwrite64(fd, ubuf, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ((loff_t)AA(poshi) << 32) | AA(poslo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * Some system calls that need sign extended arguments. This could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * done by a generic wrapper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) SYSCALL_DEFINE6(ia32_fadvise64_64, int, fd, __u32, offset_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) __u32, offset_high, __u32, len_low, __u32, len_high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int, advice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return ksys_fadvise64_64(fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) (((u64)offset_high)<<32) | offset_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) (((u64)len_high)<<32) | len_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) advice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) SYSCALL_DEFINE4(ia32_readahead, int, fd, unsigned int, off_lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) unsigned int, off_hi, size_t, count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return ksys_readahead(fd, ((u64)off_hi << 32) | off_lo, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) SYSCALL_DEFINE6(ia32_sync_file_range, int, fd, unsigned int, off_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) unsigned int, off_hi, unsigned int, n_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned int, n_hi, int, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return ksys_sync_file_range(fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ((u64)off_hi << 32) | off_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) ((u64)n_hi << 32) | n_low, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) SYSCALL_DEFINE5(ia32_fadvise64, int, fd, unsigned int, offset_lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) unsigned int, offset_hi, size_t, len, int, advice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return ksys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) len, advice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) SYSCALL_DEFINE6(ia32_fallocate, int, fd, int, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) unsigned int, offset_lo, unsigned int, offset_hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned int, len_lo, unsigned int, len_hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return ksys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ((u64)len_hi << 32) | len_lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #ifdef CONFIG_IA32_EMULATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * Another set for IA32/LFS -- x86_64 struct stat is different due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * support for 64bit inode numbers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) typeof(ubuf->st_uid) uid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) typeof(ubuf->st_gid) gid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!user_write_access_begin(ubuf, sizeof(struct stat64)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) unsafe_put_user(huge_encode_dev(stat->dev), &ubuf->st_dev, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) unsafe_put_user(stat->ino, &ubuf->__st_ino, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) unsafe_put_user(stat->ino, &ubuf->st_ino, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) unsafe_put_user(stat->mode, &ubuf->st_mode, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) unsafe_put_user(stat->nlink, &ubuf->st_nlink, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) unsafe_put_user(uid, &ubuf->st_uid, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) unsafe_put_user(gid, &ubuf->st_gid, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) unsafe_put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) unsafe_put_user(stat->size, &ubuf->st_size, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) unsafe_put_user(stat->atime.tv_sec, &ubuf->st_atime, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) unsafe_put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) unsafe_put_user(stat->mtime.tv_sec, &ubuf->st_mtime, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) unsafe_put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) unsafe_put_user(stat->ctime.tv_sec, &ubuf->st_ctime, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) unsafe_put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) unsafe_put_user(stat->blksize, &ubuf->st_blksize, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) unsafe_put_user(stat->blocks, &ubuf->st_blocks, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) user_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) Efault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) user_write_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) COMPAT_SYSCALL_DEFINE2(ia32_stat64, const char __user *, filename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct stat64 __user *, statbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct kstat stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int ret = vfs_stat(filename, &stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ret = cp_stat64(statbuf, &stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) COMPAT_SYSCALL_DEFINE2(ia32_lstat64, const char __user *, filename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct stat64 __user *, statbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct kstat stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int ret = vfs_lstat(filename, &stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ret = cp_stat64(statbuf, &stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) COMPAT_SYSCALL_DEFINE2(ia32_fstat64, unsigned int, fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct stat64 __user *, statbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct kstat stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int ret = vfs_fstat(fd, &stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ret = cp_stat64(statbuf, &stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) COMPAT_SYSCALL_DEFINE4(ia32_fstatat64, unsigned int, dfd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) const char __user *, filename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct stat64 __user *, statbuf, int, flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct kstat stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) error = vfs_fstatat(dfd, filename, &stat, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return cp_stat64(statbuf, &stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * Linux/i386 didn't use to be able to handle more than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * 4 system call parameters, so these system calls used a memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * block for parameter passing..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct mmap_arg_struct32 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) unsigned int addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) unsigned int prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) unsigned int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) unsigned int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) COMPAT_SYSCALL_DEFINE1(ia32_mmap, struct mmap_arg_struct32 __user *, arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct mmap_arg_struct32 a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (copy_from_user(&a, arg, sizeof(a)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (a.offset & ~PAGE_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) a.offset>>PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * The 32-bit clone ABI is CONFIG_CLONE_BACKWARDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) COMPAT_SYSCALL_DEFINE5(ia32_clone, unsigned long, clone_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) unsigned long, newsp, int __user *, parent_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) unsigned long, tls_val, int __user *, child_tidptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct kernel_clone_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .flags = (clone_flags & ~CSIGNAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .pidfd = parent_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .child_tid = child_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .parent_tid = parent_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .exit_signal = (clone_flags & CSIGNAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .stack = newsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .tls = tls_val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return kernel_clone(&args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #endif /* CONFIG_IA32_EMULATION */