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