sys_compat.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Based on arch/arm/kernel/sys_arm.c
  3. *
  4. * Copyright (C) People who wrote linux/arch/i386/kernel/sys_i386.c
  5. * Copyright (C) 1995, 1996 Russell King.
  6. * Copyright (C) 2012 ARM Ltd.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <linux/compat.h>
  21. #include <linux/personality.h>
  22. #include <linux/sched.h>
  23. #include <linux/sched/signal.h>
  24. #include <linux/slab.h>
  25. #include <linux/syscalls.h>
  26. #include <linux/uaccess.h>
  27. #include <asm/cacheflush.h>
  28. #include <asm/system_misc.h>
  29. #include <asm/unistd.h>
  30. static long
  31. __do_compat_cache_op(unsigned long start, unsigned long end)
  32. {
  33. long ret;
  34. do {
  35. unsigned long chunk = min(PAGE_SIZE, end - start);
  36. if (fatal_signal_pending(current))
  37. return 0;
  38. ret = __flush_cache_user_range(start, start + chunk);
  39. if (ret)
  40. return ret;
  41. cond_resched();
  42. start += chunk;
  43. } while (start < end);
  44. return 0;
  45. }
  46. static inline long
  47. do_compat_cache_op(unsigned long start, unsigned long end, int flags)
  48. {
  49. if (end < start || flags)
  50. return -EINVAL;
  51. if (!access_ok(VERIFY_READ, (const void __user *)start, end - start))
  52. return -EFAULT;
  53. return __do_compat_cache_op(start, end);
  54. }
  55. /*
  56. * Handle all unrecognised system calls.
  57. */
  58. long compat_arm_syscall(struct pt_regs *regs, int scno)
  59. {
  60. siginfo_t info;
  61. switch (scno) {
  62. /*
  63. * Flush a region from virtual address 'r0' to virtual address 'r1'
  64. * _exclusive_. There is no alignment requirement on either address;
  65. * user space does not need to know the hardware cache layout.
  66. *
  67. * r2 contains flags. It should ALWAYS be passed as ZERO until it
  68. * is defined to be something else. For now we ignore it, but may
  69. * the fires of hell burn in your belly if you break this rule. ;)
  70. *
  71. * (at a later date, we may want to allow this call to not flush
  72. * various aspects of the cache. Passing '0' will guarantee that
  73. * everything necessary gets flushed to maintain consistency in
  74. * the specified region).
  75. */
  76. case __ARM_NR_compat_cacheflush:
  77. return do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
  78. case __ARM_NR_compat_set_tls:
  79. current->thread.uw.tp_value = regs->regs[0];
  80. /*
  81. * Protect against register corruption from context switch.
  82. * See comment in tls_thread_flush.
  83. */
  84. barrier();
  85. write_sysreg(regs->regs[0], tpidrro_el0);
  86. return 0;
  87. default:
  88. /*
  89. * Calls 0xf0xxx..0xf07ff are defined to return -ENOSYS
  90. * if not implemented, rather than raising SIGILL. This
  91. * way the calling program can gracefully determine whether
  92. * a feature is supported.
  93. */
  94. if (scno < __ARM_NR_COMPAT_END)
  95. return -ENOSYS;
  96. break;
  97. }
  98. clear_siginfo(&info);
  99. info.si_signo = SIGILL;
  100. info.si_errno = 0;
  101. info.si_code = ILL_ILLTRP;
  102. info.si_addr = (void __user *)instruction_pointer(regs) -
  103. (compat_thumb_mode(regs) ? 2 : 4);
  104. arm64_notify_die("Oops - bad compat syscall(2)", regs, &info, scno);
  105. return 0;
  106. }