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