sys_compat.c 4.3 KB

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