Skip to content

Commit 55f8492

Browse files
mrutland-armwildea01
authored andcommitted
arm64: convert compat wrappers to C
In preparation for converting to pt_regs syscall wrappers, convert our existing compat wrappers to C. This will allow the pt_regs wrappers to be automatically generated, and will allow for the compat register manipulation to be folded in with the pt_regs accesses. To avoid confusion with the upcoming pt_regs wrappers and existing compat wrappers provided by core code, the C wrappers are renamed to compat_sys_aarch32_<syscall>. With the assembly wrappers gone, we can get rid of entry32.S and the associated boilerplate. Note that these must call the ksys_* syscall entry points, as the usual sys_* entry points will be modified to take a single pt_regs pointer argument. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent d3516c9 commit 55f8492

File tree

4 files changed

+115
-134
lines changed

4 files changed

+115
-134
lines changed

arch/arm64/include/asm/unistd32.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ __SYSCALL(__NR_rt_sigqueueinfo, compat_sys_rt_sigqueueinfo)
382382
#define __NR_rt_sigsuspend 179
383383
__SYSCALL(__NR_rt_sigsuspend, compat_sys_rt_sigsuspend)
384384
#define __NR_pread64 180
385-
__SYSCALL(__NR_pread64, compat_sys_pread64_wrapper)
385+
__SYSCALL(__NR_pread64, compat_sys_aarch32_pread64)
386386
#define __NR_pwrite64 181
387-
__SYSCALL(__NR_pwrite64, compat_sys_pwrite64_wrapper)
387+
__SYSCALL(__NR_pwrite64, compat_sys_aarch32_pwrite64)
388388
#define __NR_chown 182
389389
__SYSCALL(__NR_chown, sys_chown16)
390390
#define __NR_getcwd 183
@@ -406,11 +406,11 @@ __SYSCALL(__NR_vfork, sys_vfork)
406406
#define __NR_ugetrlimit 191 /* SuS compliant getrlimit */
407407
__SYSCALL(__NR_ugetrlimit, compat_sys_getrlimit) /* SuS compliant getrlimit */
408408
#define __NR_mmap2 192
409-
__SYSCALL(__NR_mmap2, compat_sys_mmap2_wrapper)
409+
__SYSCALL(__NR_mmap2, compat_sys_aarch32_mmap2)
410410
#define __NR_truncate64 193
411-
__SYSCALL(__NR_truncate64, compat_sys_truncate64_wrapper)
411+
__SYSCALL(__NR_truncate64, compat_sys_aarch32_truncate64)
412412
#define __NR_ftruncate64 194
413-
__SYSCALL(__NR_ftruncate64, compat_sys_ftruncate64_wrapper)
413+
__SYSCALL(__NR_ftruncate64, compat_sys_aarch32_ftruncate64)
414414
#define __NR_stat64 195
415415
__SYSCALL(__NR_stat64, sys_stat64)
416416
#define __NR_lstat64 196
@@ -472,7 +472,7 @@ __SYSCALL(223, sys_ni_syscall)
472472
#define __NR_gettid 224
473473
__SYSCALL(__NR_gettid, sys_gettid)
474474
#define __NR_readahead 225
475-
__SYSCALL(__NR_readahead, compat_sys_readahead_wrapper)
475+
__SYSCALL(__NR_readahead, compat_sys_aarch32_readahead)
476476
#define __NR_setxattr 226
477477
__SYSCALL(__NR_setxattr, sys_setxattr)
478478
#define __NR_lsetxattr 227
@@ -554,15 +554,15 @@ __SYSCALL(__NR_clock_getres, compat_sys_clock_getres)
554554
#define __NR_clock_nanosleep 265
555555
__SYSCALL(__NR_clock_nanosleep, compat_sys_clock_nanosleep)
556556
#define __NR_statfs64 266
557-
__SYSCALL(__NR_statfs64, compat_sys_statfs64_wrapper)
557+
__SYSCALL(__NR_statfs64, compat_sys_aarch32_statfs64)
558558
#define __NR_fstatfs64 267
559-
__SYSCALL(__NR_fstatfs64, compat_sys_fstatfs64_wrapper)
559+
__SYSCALL(__NR_fstatfs64, compat_sys_aarch32_fstatfs64)
560560
#define __NR_tgkill 268
561561
__SYSCALL(__NR_tgkill, sys_tgkill)
562562
#define __NR_utimes 269
563563
__SYSCALL(__NR_utimes, compat_sys_utimes)
564564
#define __NR_arm_fadvise64_64 270
565-
__SYSCALL(__NR_arm_fadvise64_64, compat_sys_fadvise64_64_wrapper)
565+
__SYSCALL(__NR_arm_fadvise64_64, compat_sys_aarch32_fadvise64_64)
566566
#define __NR_pciconfig_iobase 271
567567
__SYSCALL(__NR_pciconfig_iobase, sys_pciconfig_iobase)
568568
#define __NR_pciconfig_read 272
@@ -704,7 +704,7 @@ __SYSCALL(__NR_get_robust_list, compat_sys_get_robust_list)
704704
#define __NR_splice 340
705705
__SYSCALL(__NR_splice, sys_splice)
706706
#define __NR_sync_file_range2 341
707-
__SYSCALL(__NR_sync_file_range2, compat_sys_sync_file_range2_wrapper)
707+
__SYSCALL(__NR_sync_file_range2, compat_sys_aarch32_sync_file_range2)
708708
#define __NR_tee 342
709709
__SYSCALL(__NR_tee, sys_tee)
710710
#define __NR_vmsplice 343
@@ -726,7 +726,7 @@ __SYSCALL(__NR_timerfd_create, sys_timerfd_create)
726726
#define __NR_eventfd 351
727727
__SYSCALL(__NR_eventfd, sys_eventfd)
728728
#define __NR_fallocate 352
729-
__SYSCALL(__NR_fallocate, compat_sys_fallocate_wrapper)
729+
__SYSCALL(__NR_fallocate, compat_sys_aarch32_fallocate)
730730
#define __NR_timerfd_settime 353
731731
__SYSCALL(__NR_timerfd_settime, compat_sys_timerfd_settime)
732732
#define __NR_timerfd_gettime 354

arch/arm64/kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
2828
$(call if_changed,objcopy)
2929

3030
arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \
31-
sys_compat.o entry32.o
31+
sys_compat.o
3232
arm64-obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o
3333
arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o
3434
arm64-obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o

arch/arm64/kernel/entry32.S

Lines changed: 0 additions & 111 deletions
This file was deleted.

arch/arm64/kernel/sys32.c

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,116 @@
2222
*/
2323
#define __COMPAT_SYSCALL_NR
2424

25+
#include <linux/compat.h>
2526
#include <linux/compiler.h>
2627
#include <linux/syscalls.h>
2728

2829
#include <asm/syscall.h>
2930

3031
asmlinkage long compat_sys_sigreturn(void);
3132
asmlinkage long compat_sys_rt_sigreturn(void);
32-
asmlinkage long compat_sys_statfs64_wrapper(void);
33-
asmlinkage long compat_sys_fstatfs64_wrapper(void);
34-
asmlinkage long compat_sys_pread64_wrapper(void);
35-
asmlinkage long compat_sys_pwrite64_wrapper(void);
36-
asmlinkage long compat_sys_truncate64_wrapper(void);
37-
asmlinkage long compat_sys_ftruncate64_wrapper(void);
38-
asmlinkage long compat_sys_readahead_wrapper(void);
39-
asmlinkage long compat_sys_fadvise64_64_wrapper(void);
40-
asmlinkage long compat_sys_sync_file_range2_wrapper(void);
41-
asmlinkage long compat_sys_fallocate_wrapper(void);
42-
asmlinkage long compat_sys_mmap2_wrapper(void);
33+
34+
COMPAT_SYSCALL_DEFINE3(aarch32_statfs64, const char __user *, pathname,
35+
compat_size_t, sz, struct compat_statfs64 __user *, buf)
36+
{
37+
/*
38+
* 32-bit ARM applies an OABI compatibility fixup to statfs64 and
39+
* fstatfs64 regardless of whether OABI is in use, and therefore
40+
* arbitrary binaries may rely upon it, so we must do the same.
41+
* For more details, see commit:
42+
*
43+
* 713c481519f19df9 ("[ARM] 3108/2: old ABI compat: statfs64 and
44+
* fstatfs64")
45+
*/
46+
if (sz == 88)
47+
sz = 84;
48+
49+
return kcompat_sys_statfs64(pathname, sz, buf);
50+
}
51+
52+
COMPAT_SYSCALL_DEFINE3(aarch32_fstatfs64, unsigned int, fd, compat_size_t, sz,
53+
struct compat_statfs64 __user *, buf)
54+
{
55+
/* see aarch32_statfs64 */
56+
if (sz == 88)
57+
sz = 84;
58+
59+
return kcompat_sys_fstatfs64(fd, sz, buf);
60+
}
61+
62+
/*
63+
* Note: off_4k is always in units of 4K. If we can't do the
64+
* requested offset because it is not page-aligned, we return -EINVAL.
65+
*/
66+
COMPAT_SYSCALL_DEFINE6(aarch32_mmap2, unsigned long, addr, unsigned long, len,
67+
unsigned long, prot, unsigned long, flags,
68+
unsigned long, fd, unsigned long, off_4k)
69+
{
70+
if (off_4k & (~PAGE_MASK >> 12))
71+
return -EINVAL;
72+
73+
off_4k >>= (PAGE_SHIFT - 12);
74+
75+
return ksys_mmap_pgoff(addr, len, prot, flags, fd, off_4k);
76+
}
77+
78+
#ifdef CONFIG_CPU_BIG_ENDIAN
79+
#define arg_u32p(name) u32, name##_hi, u32, name##_lo
80+
#else
81+
#define arg_u32p(name) u32, name##_lo, u32, name##_hi
82+
#endif
83+
84+
#define arg_u64(name) (((u64)name##_hi << 32) | name##_lo)
85+
86+
COMPAT_SYSCALL_DEFINE6(aarch32_pread64, unsigned int, fd, char __user *, buf,
87+
size_t, count, u32, __pad, arg_u32p(pos))
88+
{
89+
return ksys_pread64(fd, buf, count, arg_u64(pos));
90+
}
91+
92+
COMPAT_SYSCALL_DEFINE6(aarch32_pwrite64, unsigned int, fd,
93+
const char __user *, buf, size_t, count, u32, __pad,
94+
arg_u32p(pos))
95+
{
96+
return ksys_pwrite64(fd, buf, count, arg_u64(pos));
97+
}
98+
99+
COMPAT_SYSCALL_DEFINE4(aarch32_truncate64, const char __user *, pathname,
100+
u32, __pad, arg_u32p(length))
101+
{
102+
return ksys_truncate(pathname, arg_u64(length));
103+
}
104+
105+
COMPAT_SYSCALL_DEFINE4(aarch32_ftruncate64, unsigned int, fd, u32, __pad,
106+
arg_u32p(length))
107+
{
108+
return ksys_ftruncate(fd, arg_u64(length));
109+
}
110+
111+
COMPAT_SYSCALL_DEFINE5(aarch32_readahead, int, fd, u32, __pad,
112+
arg_u32p(offset), size_t, count)
113+
{
114+
return ksys_readahead(fd, arg_u64(offset), count);
115+
}
116+
117+
COMPAT_SYSCALL_DEFINE6(aarch32_fadvise64_64, int, fd, int, advice,
118+
arg_u32p(offset), arg_u32p(len))
119+
{
120+
return ksys_fadvise64_64(fd, arg_u64(offset), arg_u64(len), advice);
121+
}
122+
123+
COMPAT_SYSCALL_DEFINE6(aarch32_sync_file_range2, int, fd, unsigned int, flags,
124+
arg_u32p(offset), arg_u32p(nbytes))
125+
{
126+
return ksys_sync_file_range(fd, arg_u64(offset), arg_u64(nbytes),
127+
flags);
128+
}
129+
130+
COMPAT_SYSCALL_DEFINE6(aarch32_fallocate, int, fd, int, mode,
131+
arg_u32p(offset), arg_u32p(len))
132+
{
133+
return ksys_fallocate(fd, mode, arg_u64(offset), arg_u64(len));
134+
}
43135

44136
#undef __SYSCALL
45137
#define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)sym,

0 commit comments

Comments
 (0)