sys_compat.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. asmlinkage int compat_sys_fork(struct pt_regs *regs)
  29. {
  30. return do_fork(SIGCHLD, regs->compat_sp, regs, 0, NULL, NULL);
  31. }
  32. asmlinkage int compat_sys_clone(unsigned long clone_flags, unsigned long newsp,
  33. int __user *parent_tidptr, int tls_val,
  34. int __user *child_tidptr, struct pt_regs *regs)
  35. {
  36. if (!newsp)
  37. newsp = regs->compat_sp;
  38. return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
  39. }
  40. asmlinkage int compat_sys_vfork(struct pt_regs *regs)
  41. {
  42. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->compat_sp,
  43. regs, 0, NULL, NULL);
  44. }
  45. asmlinkage int compat_sys_execve(const char __user *filenamei,
  46. compat_uptr_t argv, compat_uptr_t envp,
  47. struct pt_regs *regs)
  48. {
  49. int error;
  50. struct filename *filename;
  51. filename = getname(filenamei);
  52. error = PTR_ERR(filename);
  53. if (IS_ERR(filename))
  54. goto out;
  55. error = compat_do_execve(filename->name, compat_ptr(argv),
  56. compat_ptr(envp), regs);
  57. putname(filename);
  58. out:
  59. return error;
  60. }
  61. asmlinkage int compat_sys_sched_rr_get_interval(compat_pid_t pid,
  62. struct compat_timespec __user *interval)
  63. {
  64. struct timespec t;
  65. int ret;
  66. mm_segment_t old_fs = get_fs();
  67. set_fs(KERNEL_DS);
  68. ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
  69. set_fs(old_fs);
  70. if (put_compat_timespec(&t, interval))
  71. return -EFAULT;
  72. return ret;
  73. }
  74. static inline void
  75. do_compat_cache_op(unsigned long start, unsigned long end, int flags)
  76. {
  77. struct mm_struct *mm = current->active_mm;
  78. struct vm_area_struct *vma;
  79. if (end < start || flags)
  80. return;
  81. down_read(&mm->mmap_sem);
  82. vma = find_vma(mm, start);
  83. if (vma && vma->vm_start < end) {
  84. if (start < vma->vm_start)
  85. start = vma->vm_start;
  86. if (end > vma->vm_end)
  87. end = vma->vm_end;
  88. up_read(&mm->mmap_sem);
  89. __flush_cache_user_range(start & PAGE_MASK, PAGE_ALIGN(end));
  90. return;
  91. }
  92. up_read(&mm->mmap_sem);
  93. }
  94. /*
  95. * Handle all unrecognised system calls.
  96. */
  97. long compat_arm_syscall(struct pt_regs *regs)
  98. {
  99. unsigned int no = regs->regs[7];
  100. switch (no) {
  101. /*
  102. * Flush a region from virtual address 'r0' to virtual address 'r1'
  103. * _exclusive_. There is no alignment requirement on either address;
  104. * user space does not need to know the hardware cache layout.
  105. *
  106. * r2 contains flags. It should ALWAYS be passed as ZERO until it
  107. * is defined to be something else. For now we ignore it, but may
  108. * the fires of hell burn in your belly if you break this rule. ;)
  109. *
  110. * (at a later date, we may want to allow this call to not flush
  111. * various aspects of the cache. Passing '0' will guarantee that
  112. * everything necessary gets flushed to maintain consistency in
  113. * the specified region).
  114. */
  115. case __ARM_NR_compat_cacheflush:
  116. do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
  117. return 0;
  118. case __ARM_NR_compat_set_tls:
  119. current->thread.tp_value = regs->regs[0];
  120. asm ("msr tpidrro_el0, %0" : : "r" (regs->regs[0]));
  121. return 0;
  122. default:
  123. return -ENOSYS;
  124. }
  125. }