syscall.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1995, 1996, 1997, 2000, 2001, 05 by Ralf Baechle
  7. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8. * Copyright (C) 2001 MIPS Technologies, Inc.
  9. */
  10. #include <linux/capability.h>
  11. #include <linux/errno.h>
  12. #include <linux/linkage.h>
  13. #include <linux/fs.h>
  14. #include <linux/smp.h>
  15. #include <linux/ptrace.h>
  16. #include <linux/string.h>
  17. #include <linux/syscalls.h>
  18. #include <linux/file.h>
  19. #include <linux/utsname.h>
  20. #include <linux/unistd.h>
  21. #include <linux/sem.h>
  22. #include <linux/msg.h>
  23. #include <linux/shm.h>
  24. #include <linux/compiler.h>
  25. #include <linux/ipc.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/slab.h>
  28. #include <linux/elf.h>
  29. #include <linux/sched/task_stack.h>
  30. #include <asm/asm.h>
  31. #include <asm/asm-eva.h>
  32. #include <asm/branch.h>
  33. #include <asm/cachectl.h>
  34. #include <asm/cacheflush.h>
  35. #include <asm/asm-offsets.h>
  36. #include <asm/signal.h>
  37. #include <asm/sim.h>
  38. #include <asm/shmparam.h>
  39. #include <asm/sync.h>
  40. #include <asm/sysmips.h>
  41. #include <asm/switch_to.h>
  42. /*
  43. * For historic reasons the pipe(2) syscall on MIPS has an unusual calling
  44. * convention. It returns results in registers $v0 / $v1 which means there
  45. * is no need for it to do verify the validity of a userspace pointer
  46. * argument. Historically that used to be expensive in Linux. These days
  47. * the performance advantage is negligible.
  48. */
  49. asmlinkage int sysm_pipe(void)
  50. {
  51. int fd[2];
  52. int error = do_pipe_flags(fd, 0);
  53. if (error)
  54. return error;
  55. current_pt_regs()->regs[3] = fd[1];
  56. return fd[0];
  57. }
  58. SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
  59. unsigned long, prot, unsigned long, flags, unsigned long,
  60. fd, off_t, offset)
  61. {
  62. if (offset & ~PAGE_MASK)
  63. return -EINVAL;
  64. return ksys_mmap_pgoff(addr, len, prot, flags, fd,
  65. offset >> PAGE_SHIFT);
  66. }
  67. SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
  68. unsigned long, prot, unsigned long, flags, unsigned long, fd,
  69. unsigned long, pgoff)
  70. {
  71. if (pgoff & (~PAGE_MASK >> 12))
  72. return -EINVAL;
  73. return ksys_mmap_pgoff(addr, len, prot, flags, fd,
  74. pgoff >> (PAGE_SHIFT - 12));
  75. }
  76. save_static_function(sys_fork);
  77. save_static_function(sys_clone);
  78. save_static_function(sys_clone3);
  79. SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
  80. {
  81. struct thread_info *ti = task_thread_info(current);
  82. ti->tp_value = addr;
  83. if (cpu_has_userlocal)
  84. write_c0_userlocal(addr);
  85. return 0;
  86. }
  87. static inline int mips_atomic_set(unsigned long addr, unsigned long new)
  88. {
  89. unsigned long old, tmp;
  90. struct pt_regs *regs;
  91. unsigned int err;
  92. if (unlikely(addr & 3))
  93. return -EINVAL;
  94. if (unlikely(!access_ok((const void __user *)addr, 4)))
  95. return -EINVAL;
  96. if (cpu_has_llsc && IS_ENABLED(CONFIG_WAR_R10000_LLSC)) {
  97. __asm__ __volatile__ (
  98. " .set push \n"
  99. " .set arch=r4000 \n"
  100. " li %[err], 0 \n"
  101. "1: ll %[old], (%[addr]) \n"
  102. " move %[tmp], %[new] \n"
  103. "2: sc %[tmp], (%[addr]) \n"
  104. " beqzl %[tmp], 1b \n"
  105. "3: \n"
  106. " .insn \n"
  107. " .section .fixup,\"ax\" \n"
  108. "4: li %[err], %[efault] \n"
  109. " j 3b \n"
  110. " .previous \n"
  111. " .section __ex_table,\"a\" \n"
  112. " "STR(PTR_WD)" 1b, 4b \n"
  113. " "STR(PTR_WD)" 2b, 4b \n"
  114. " .previous \n"
  115. " .set pop \n"
  116. : [old] "=&r" (old),
  117. [err] "=&r" (err),
  118. [tmp] "=&r" (tmp)
  119. : [addr] "r" (addr),
  120. [new] "r" (new),
  121. [efault] "i" (-EFAULT)
  122. : "memory");
  123. } else if (cpu_has_llsc) {
  124. __asm__ __volatile__ (
  125. " .set push \n"
  126. " .set "MIPS_ISA_ARCH_LEVEL" \n"
  127. " li %[err], 0 \n"
  128. "1: \n"
  129. " " __SYNC(full, loongson3_war) " \n"
  130. user_ll("%[old]", "(%[addr])")
  131. " move %[tmp], %[new] \n"
  132. "2: \n"
  133. user_sc("%[tmp]", "(%[addr])")
  134. " beqz %[tmp], 1b \n"
  135. "3: \n"
  136. " .insn \n"
  137. " .section .fixup,\"ax\" \n"
  138. "5: li %[err], %[efault] \n"
  139. " j 3b \n"
  140. " .previous \n"
  141. " .section __ex_table,\"a\" \n"
  142. " "STR(PTR_WD)" 1b, 5b \n"
  143. " "STR(PTR_WD)" 2b, 5b \n"
  144. " .previous \n"
  145. " .set pop \n"
  146. : [old] "=&r" (old),
  147. [err] "=&r" (err),
  148. [tmp] "=&r" (tmp)
  149. : [addr] "r" (addr),
  150. [new] "r" (new),
  151. [efault] "i" (-EFAULT)
  152. : "memory");
  153. } else {
  154. do {
  155. preempt_disable();
  156. ll_bit = 1;
  157. ll_task = current;
  158. preempt_enable();
  159. err = __get_user(old, (unsigned int *) addr);
  160. err |= __put_user(new, (unsigned int *) addr);
  161. if (err)
  162. break;
  163. rmb();
  164. } while (!ll_bit);
  165. }
  166. if (unlikely(err))
  167. return err;
  168. regs = current_pt_regs();
  169. regs->regs[2] = old;
  170. regs->regs[7] = 0; /* No error */
  171. /*
  172. * Don't let your children do this ...
  173. */
  174. __asm__ __volatile__(
  175. " move $29, %0 \n"
  176. " j syscall_exit \n"
  177. : /* no outputs */
  178. : "r" (regs));
  179. /* unreached. Honestly. */
  180. unreachable();
  181. }
  182. /*
  183. * mips_atomic_set() normally returns directly via syscall_exit potentially
  184. * clobbering static registers, so be sure to preserve them.
  185. */
  186. save_static_function(sys_sysmips);
  187. SYSCALL_DEFINE3(sysmips, long, cmd, long, arg1, long, arg2)
  188. {
  189. switch (cmd) {
  190. case MIPS_ATOMIC_SET:
  191. return mips_atomic_set(arg1, arg2);
  192. case MIPS_FIXADE:
  193. if (arg1 & ~3)
  194. return -EINVAL;
  195. if (arg1 & 1)
  196. set_thread_flag(TIF_FIXADE);
  197. else
  198. clear_thread_flag(TIF_FIXADE);
  199. if (arg1 & 2)
  200. set_thread_flag(TIF_LOGADE);
  201. else
  202. clear_thread_flag(TIF_LOGADE);
  203. return 0;
  204. case FLUSH_CACHE:
  205. __flush_cache_all();
  206. return 0;
  207. }
  208. return -EINVAL;
  209. }
  210. /*
  211. * No implemented yet ...
  212. */
  213. SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op)
  214. {
  215. return -ENOSYS;
  216. }