sys32.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. * Needed to avoid conflicting __NR_* macros between uapi/asm/unistd.h and
  9. * asm/unistd32.h.
  10. */
  11. #define __COMPAT_SYSCALL_NR
  12. #include <linux/compat.h>
  13. #include <linux/compiler.h>
  14. #include <linux/syscalls.h>
  15. #include <asm/syscall.h>
  16. asmlinkage long compat_sys_sigreturn(void);
  17. asmlinkage long compat_sys_rt_sigreturn(void);
  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. return kcompat_sys_statfs64(pathname, sz, buf);
  33. }
  34. COMPAT_SYSCALL_DEFINE3(aarch32_fstatfs64, unsigned int, fd, compat_size_t, sz,
  35. struct compat_statfs64 __user *, buf)
  36. {
  37. /* see aarch32_statfs64 */
  38. if (sz == 88)
  39. sz = 84;
  40. return kcompat_sys_fstatfs64(fd, sz, buf);
  41. }
  42. /*
  43. * Note: off_4k is always in units of 4K. If we can't do the
  44. * requested offset because it is not page-aligned, we return -EINVAL.
  45. */
  46. COMPAT_SYSCALL_DEFINE6(aarch32_mmap2, unsigned long, addr, unsigned long, len,
  47. unsigned long, prot, unsigned long, flags,
  48. unsigned long, fd, unsigned long, off_4k)
  49. {
  50. if (off_4k & (~PAGE_MASK >> 12))
  51. return -EINVAL;
  52. off_4k >>= (PAGE_SHIFT - 12);
  53. return ksys_mmap_pgoff(addr, len, prot, flags, fd, off_4k);
  54. }
  55. #ifdef CONFIG_CPU_BIG_ENDIAN
  56. #define arg_u32p(name) u32, name##_hi, u32, name##_lo
  57. #else
  58. #define arg_u32p(name) u32, name##_lo, u32, name##_hi
  59. #endif
  60. #define arg_u64(name) (((u64)name##_hi << 32) | name##_lo)
  61. COMPAT_SYSCALL_DEFINE6(aarch32_pread64, unsigned int, fd, char __user *, buf,
  62. size_t, count, u32, __pad, arg_u32p(pos))
  63. {
  64. return ksys_pread64(fd, buf, count, arg_u64(pos));
  65. }
  66. COMPAT_SYSCALL_DEFINE6(aarch32_pwrite64, unsigned int, fd,
  67. const char __user *, buf, size_t, count, u32, __pad,
  68. arg_u32p(pos))
  69. {
  70. return ksys_pwrite64(fd, buf, count, arg_u64(pos));
  71. }
  72. COMPAT_SYSCALL_DEFINE4(aarch32_truncate64, const char __user *, pathname,
  73. u32, __pad, arg_u32p(length))
  74. {
  75. return ksys_truncate(pathname, arg_u64(length));
  76. }
  77. COMPAT_SYSCALL_DEFINE4(aarch32_ftruncate64, unsigned int, fd, u32, __pad,
  78. arg_u32p(length))
  79. {
  80. return ksys_ftruncate(fd, arg_u64(length));
  81. }
  82. COMPAT_SYSCALL_DEFINE5(aarch32_readahead, int, fd, u32, __pad,
  83. arg_u32p(offset), size_t, count)
  84. {
  85. return ksys_readahead(fd, arg_u64(offset), count);
  86. }
  87. COMPAT_SYSCALL_DEFINE6(aarch32_fadvise64_64, int, fd, int, advice,
  88. arg_u32p(offset), arg_u32p(len))
  89. {
  90. return ksys_fadvise64_64(fd, arg_u64(offset), arg_u64(len), advice);
  91. }
  92. COMPAT_SYSCALL_DEFINE6(aarch32_sync_file_range2, int, fd, unsigned int, flags,
  93. arg_u32p(offset), arg_u32p(nbytes))
  94. {
  95. return ksys_sync_file_range(fd, arg_u64(offset), arg_u64(nbytes),
  96. flags);
  97. }
  98. COMPAT_SYSCALL_DEFINE6(aarch32_fallocate, int, fd, int, mode,
  99. arg_u32p(offset), arg_u32p(len))
  100. {
  101. return ksys_fallocate(fd, mode, arg_u64(offset), arg_u64(len));
  102. }
  103. #undef __SYSCALL
  104. #define __SYSCALL(nr, sym) asmlinkage long __arm64_##sym(const struct pt_regs *);
  105. #include <asm/unistd32.h>
  106. #undef __SYSCALL
  107. #define __SYSCALL(nr, sym) [nr] = __arm64_##sym,
  108. const syscall_fn_t compat_sys_call_table[__NR_compat_syscalls] = {
  109. [0 ... __NR_compat_syscalls - 1] = __arm64_sys_ni_syscall,
  110. #include <asm/unistd32.h>
  111. };