Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * arch/arm64/kernel/sys32.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2015 ARM Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Needed to avoid conflicting __NR_* macros between uapi/asm/unistd.h and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * asm/unistd32.h.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define __COMPAT_SYSCALL_NR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/syscall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) asmlinkage long compat_sys_sigreturn(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) asmlinkage long compat_sys_rt_sigreturn(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) COMPAT_SYSCALL_DEFINE3(aarch32_statfs64, const char __user *, pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		       compat_size_t, sz, struct compat_statfs64 __user *, buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	 * 32-bit ARM applies an OABI compatibility fixup to statfs64 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	 * fstatfs64 regardless of whether OABI is in use, and therefore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	 * arbitrary binaries may rely upon it, so we must do the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	 * For more details, see commit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	 * 713c481519f19df9 ("[ARM] 3108/2: old ABI compat: statfs64 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	 * fstatfs64")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (sz == 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		sz = 84;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	return kcompat_sys_statfs64(pathname, sz, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) COMPAT_SYSCALL_DEFINE3(aarch32_fstatfs64, unsigned int, fd, compat_size_t, sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		       struct compat_statfs64 __user *, buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* see aarch32_statfs64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (sz == 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		sz = 84;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	return kcompat_sys_fstatfs64(fd, sz, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * Note: off_4k is always in units of 4K. If we can't do the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * requested offset because it is not page-aligned, we return -EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) COMPAT_SYSCALL_DEFINE6(aarch32_mmap2, unsigned long, addr, unsigned long, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		       unsigned long, prot, unsigned long, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		       unsigned long, fd, unsigned long, off_4k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (off_4k & (~PAGE_MASK >> 12))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	off_4k >>= (PAGE_SHIFT - 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return ksys_mmap_pgoff(addr, len, prot, flags, fd, off_4k);
^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) #ifdef CONFIG_CPU_BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define arg_u32p(name)	u32, name##_hi, u32, name##_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define arg_u32p(name)	u32, name##_lo, u32, name##_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define arg_u64(name)	(((u64)name##_hi << 32) | name##_lo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) COMPAT_SYSCALL_DEFINE6(aarch32_pread64, unsigned int, fd, char __user *, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		       size_t, count, u32, __pad, arg_u32p(pos))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return ksys_pread64(fd, buf, count, arg_u64(pos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) COMPAT_SYSCALL_DEFINE6(aarch32_pwrite64, unsigned int, fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		       const char __user *, buf, size_t, count, u32, __pad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		       arg_u32p(pos))
^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, arg_u64(pos));
^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) COMPAT_SYSCALL_DEFINE4(aarch32_truncate64, const char __user *, pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		       u32, __pad, arg_u32p(length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return ksys_truncate(pathname, arg_u64(length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) COMPAT_SYSCALL_DEFINE4(aarch32_ftruncate64, unsigned int, fd, u32, __pad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		       arg_u32p(length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	return ksys_ftruncate(fd, arg_u64(length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) COMPAT_SYSCALL_DEFINE5(aarch32_readahead, int, fd, u32, __pad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		       arg_u32p(offset), size_t, count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return ksys_readahead(fd, arg_u64(offset), count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) COMPAT_SYSCALL_DEFINE6(aarch32_fadvise64_64, int, fd, int, advice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		       arg_u32p(offset), arg_u32p(len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return ksys_fadvise64_64(fd, arg_u64(offset), arg_u64(len), advice);
^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) COMPAT_SYSCALL_DEFINE6(aarch32_sync_file_range2, int, fd, unsigned int, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		       arg_u32p(offset), arg_u32p(nbytes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return ksys_sync_file_range(fd, arg_u64(offset), arg_u64(nbytes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 				    flags);
^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) COMPAT_SYSCALL_DEFINE6(aarch32_fallocate, int, fd, int, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		       arg_u32p(offset), arg_u32p(len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return ksys_fallocate(fd, mode, arg_u64(offset), arg_u64(len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #undef __SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define __SYSCALL(nr, sym)	asmlinkage long __arm64_##sym(const struct pt_regs *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #include <asm/unistd32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #undef __SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #define __SYSCALL(nr, sym)	[nr] = __arm64_##sym,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) const syscall_fn_t compat_sys_call_table[__NR_compat_syscalls] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	[0 ... __NR_compat_syscalls - 1] = __arm64_sys_ni_syscall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #include <asm/unistd32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };