sys_compat.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/slab.h>
  24. #include <linux/syscalls.h>
  25. #include <linux/uaccess.h>
  26. #include <asm/cacheflush.h>
  27. #include <asm/unistd32.h>
  28. static inline void
  29. do_compat_cache_op(unsigned long start, unsigned long end, int flags)
  30. {
  31. struct mm_struct *mm = current->active_mm;
  32. struct vm_area_struct *vma;
  33. if (end < start || flags)
  34. return;
  35. down_read(&mm->mmap_sem);
  36. vma = find_vma(mm, start);
  37. if (vma && vma->vm_start < end) {
  38. if (start < vma->vm_start)
  39. start = vma->vm_start;
  40. if (end > vma->vm_end)
  41. end = vma->vm_end;
  42. up_read(&mm->mmap_sem);
  43. __flush_cache_user_range(start & PAGE_MASK, PAGE_ALIGN(end));
  44. return;
  45. }
  46. up_read(&mm->mmap_sem);
  47. }
  48. /*
  49. * Handle all unrecognised system calls.
  50. */
  51. long compat_arm_syscall(struct pt_regs *regs)
  52. {
  53. unsigned int no = regs->regs[7];
  54. switch (no) {
  55. /*
  56. * Flush a region from virtual address 'r0' to virtual address 'r1'
  57. * _exclusive_. There is no alignment requirement on either address;
  58. * user space does not need to know the hardware cache layout.
  59. *
  60. * r2 contains flags. It should ALWAYS be passed as ZERO until it
  61. * is defined to be something else. For now we ignore it, but may
  62. * the fires of hell burn in your belly if you break this rule. ;)
  63. *
  64. * (at a later date, we may want to allow this call to not flush
  65. * various aspects of the cache. Passing '0' will guarantee that
  66. * everything necessary gets flushed to maintain consistency in
  67. * the specified region).
  68. */
  69. case __ARM_NR_compat_cacheflush:
  70. do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
  71. return 0;
  72. case __ARM_NR_compat_set_tls:
  73. current->thread.tp_value = regs->regs[0];
  74. asm ("msr tpidrro_el0, %0" : : "r" (regs->regs[0]));
  75. return 0;
  76. default:
  77. return -ENOSYS;
  78. }
  79. }