^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) * Conversion between 32-bit and 64-bit native system calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2000 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Written by Ulf Carlsson (ulfc@engr.sgi.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/highuid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/resource.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/times.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/filter.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/shm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/sem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/msg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/utime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/personality.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/dnotify.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/binfmts.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/ipc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <net/scm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <asm/compat-signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <asm/sim.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <asm/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #ifdef __MIPSEB__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define merge_64(r1, r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #ifdef __MIPSEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define merge_64(r1, r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) SYSCALL_DEFINE4(32_truncate64, const char __user *, path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned long, __dummy, unsigned long, a2, unsigned long, a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return ksys_truncate(path, merge_64(a2, a3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) unsigned long, a2, unsigned long, a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return ksys_ftruncate(fd, merge_64(a2, a3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) unsigned int, offset_low, loff_t __user *, result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned int, origin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return sys_llseek(fd, offset_high, offset_low, result, origin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) lseek back to original location. They fail just like lseek does on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) non-seekable files. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) unsigned long, unused, unsigned long, a4, unsigned long, a5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return ksys_pread64(fd, buf, count, merge_64(a4, a5));
^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) SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) size_t, count, u32, unused, u64, a4, u64, a5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return ksys_pwrite64(fd, buf, count, merge_64(a4, a5));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) SYSCALL_DEFINE1(32_personality, unsigned long, personality)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) unsigned int p = personality & 0xffffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (personality(current->personality) == PER_LINUX32 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) personality(p) == PER_LINUX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) p = (p & ~PER_MASK) | PER_LINUX32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ret = sys_personality(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (ret != -1 && personality(ret) == PER_LINUX32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ret = (ret & ~PER_MASK) | PER_LINUX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return ksys_readahead(fd, merge_64(a2, a3), count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) asmlinkage long sys32_sync_file_range(int fd, int __pad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned long a2, unsigned long a3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned long a4, unsigned long a5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return ksys_sync_file_range(fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) merge_64(a2, a3), merge_64(a4, a5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) asmlinkage long sys32_fadvise64_64(int fd, int __pad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned long a2, unsigned long a3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) unsigned long a4, unsigned long a5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return ksys_fadvise64_64(fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) merge_64(a2, a3), merge_64(a4, a5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned offset_a3, unsigned len_a4, unsigned len_a5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return ksys_fallocate(fd, mode, merge_64(offset_a2, offset_a3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) merge_64(len_a4, len_a5));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }