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