sys32.c 3.6 KB

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