sys32.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * arch/arm64/kernel/sys32.c
  3. *
  4. * Copyright (C) 2015 ARM Ltd.
  5. *
  6. * This program is free software(void); you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http(void);//www.gnu.org/licenses/>.
  17. */
  18. /*
  19. * Needed to avoid conflicting __NR_* macros between uapi/asm/unistd.h and
  20. * asm/unistd32.h.
  21. */
  22. #define __COMPAT_SYSCALL_NR
  23. #include <linux/compat.h>
  24. #include <linux/compiler.h>
  25. #include <linux/syscalls.h>
  26. #include <asm/syscall.h>
  27. asmlinkage long compat_sys_sigreturn(void);
  28. asmlinkage long compat_sys_rt_sigreturn(void);
  29. COMPAT_SYSCALL_DEFINE3(aarch32_statfs64, const char __user *, pathname,
  30. compat_size_t, sz, struct compat_statfs64 __user *, buf)
  31. {
  32. /*
  33. * 32-bit ARM applies an OABI compatibility fixup to statfs64 and
  34. * fstatfs64 regardless of whether OABI is in use, and therefore
  35. * arbitrary binaries may rely upon it, so we must do the same.
  36. * For more details, see commit:
  37. *
  38. * 713c481519f19df9 ("[ARM] 3108/2: old ABI compat: statfs64 and
  39. * fstatfs64")
  40. */
  41. if (sz == 88)
  42. sz = 84;
  43. return kcompat_sys_statfs64(pathname, sz, buf);
  44. }
  45. COMPAT_SYSCALL_DEFINE3(aarch32_fstatfs64, unsigned int, fd, compat_size_t, sz,
  46. struct compat_statfs64 __user *, buf)
  47. {
  48. /* see aarch32_statfs64 */
  49. if (sz == 88)
  50. sz = 84;
  51. return kcompat_sys_fstatfs64(fd, sz, buf);
  52. }
  53. /*
  54. * Note: off_4k is always in units of 4K. If we can't do the
  55. * requested offset because it is not page-aligned, we return -EINVAL.
  56. */
  57. COMPAT_SYSCALL_DEFINE6(aarch32_mmap2, unsigned long, addr, unsigned long, len,
  58. unsigned long, prot, unsigned long, flags,
  59. unsigned long, fd, unsigned long, off_4k)
  60. {
  61. if (off_4k & (~PAGE_MASK >> 12))
  62. return -EINVAL;
  63. off_4k >>= (PAGE_SHIFT - 12);
  64. return ksys_mmap_pgoff(addr, len, prot, flags, fd, off_4k);
  65. }
  66. #ifdef CONFIG_CPU_BIG_ENDIAN
  67. #define arg_u32p(name) u32, name##_hi, u32, name##_lo
  68. #else
  69. #define arg_u32p(name) u32, name##_lo, u32, name##_hi
  70. #endif
  71. #define arg_u64(name) (((u64)name##_hi << 32) | name##_lo)
  72. COMPAT_SYSCALL_DEFINE6(aarch32_pread64, unsigned int, fd, char __user *, buf,
  73. size_t, count, u32, __pad, arg_u32p(pos))
  74. {
  75. return ksys_pread64(fd, buf, count, arg_u64(pos));
  76. }
  77. COMPAT_SYSCALL_DEFINE6(aarch32_pwrite64, unsigned int, fd,
  78. const char __user *, buf, size_t, count, u32, __pad,
  79. arg_u32p(pos))
  80. {
  81. return ksys_pwrite64(fd, buf, count, arg_u64(pos));
  82. }
  83. COMPAT_SYSCALL_DEFINE4(aarch32_truncate64, const char __user *, pathname,
  84. u32, __pad, arg_u32p(length))
  85. {
  86. return ksys_truncate(pathname, arg_u64(length));
  87. }
  88. COMPAT_SYSCALL_DEFINE4(aarch32_ftruncate64, unsigned int, fd, u32, __pad,
  89. arg_u32p(length))
  90. {
  91. return ksys_ftruncate(fd, arg_u64(length));
  92. }
  93. COMPAT_SYSCALL_DEFINE5(aarch32_readahead, int, fd, u32, __pad,
  94. arg_u32p(offset), size_t, count)
  95. {
  96. return ksys_readahead(fd, arg_u64(offset), count);
  97. }
  98. COMPAT_SYSCALL_DEFINE6(aarch32_fadvise64_64, int, fd, int, advice,
  99. arg_u32p(offset), arg_u32p(len))
  100. {
  101. return ksys_fadvise64_64(fd, arg_u64(offset), arg_u64(len), advice);
  102. }
  103. COMPAT_SYSCALL_DEFINE6(aarch32_sync_file_range2, int, fd, unsigned int, flags,
  104. arg_u32p(offset), arg_u32p(nbytes))
  105. {
  106. return ksys_sync_file_range(fd, arg_u64(offset), arg_u64(nbytes),
  107. flags);
  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. asmlinkage long sys_ni_syscall(const struct pt_regs *);
  115. #define __arm64_sys_ni_syscall sys_ni_syscall
  116. #undef __SYSCALL
  117. #define __SYSCALL(nr, sym) asmlinkage long __arm64_##sym(const struct pt_regs *);
  118. #include <asm/unistd32.h>
  119. #undef __SYSCALL
  120. #define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)__arm64_##sym,
  121. const syscall_fn_t compat_sys_call_table[__NR_compat_syscalls] = {
  122. [0 ... __NR_compat_syscalls - 1] = (syscall_fn_t)sys_ni_syscall,
  123. #include <asm/unistd32.h>
  124. };