syscall.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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/branch.h>
  32. #include <asm/cachectl.h>
  33. #include <asm/cacheflush.h>
  34. #include <asm/asm-offsets.h>
  35. #include <asm/signal.h>
  36. #include <asm/sim.h>
  37. #include <asm/shmparam.h>
  38. #include <asm/sysmips.h>
  39. #include <asm/switch_to.h>
  40. /*
  41. * For historic reasons the pipe(2) syscall on MIPS has an unusual calling
  42. * convention. It returns results in registers $v0 / $v1 which means there
  43. * is no need for it to do verify the validity of a userspace pointer
  44. * argument. Historically that used to be expensive in Linux. These days
  45. * the performance advantage is negligible.
  46. */
  47. asmlinkage int sysm_pipe(void)
  48. {
  49. int fd[2];
  50. int error = do_pipe_flags(fd, 0);
  51. if (error)
  52. return error;
  53. current_pt_regs()->regs[3] = fd[1];
  54. return fd[0];
  55. }
  56. SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
  57. unsigned long, prot, unsigned long, flags, unsigned long,
  58. fd, off_t, offset)
  59. {
  60. if (offset & ~PAGE_MASK)
  61. return -EINVAL;
  62. return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  63. }
  64. SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
  65. unsigned long, prot, unsigned long, flags, unsigned long, fd,
  66. unsigned long, pgoff)
  67. {
  68. if (pgoff & (~PAGE_MASK >> 12))
  69. return -EINVAL;
  70. return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
  71. }
  72. save_static_function(sys_fork);
  73. save_static_function(sys_clone);
  74. SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
  75. {
  76. struct thread_info *ti = task_thread_info(current);
  77. ti->tp_value = addr;
  78. if (cpu_has_userlocal)
  79. write_c0_userlocal(addr);
  80. return 0;
  81. }
  82. static inline int mips_atomic_set(unsigned long addr, unsigned long new)
  83. {
  84. unsigned long old, tmp;
  85. struct pt_regs *regs;
  86. unsigned int err;
  87. if (unlikely(addr & 3))
  88. return -EINVAL;
  89. if (unlikely(!access_ok(VERIFY_WRITE, (const void __user *)addr, 4)))
  90. return -EINVAL;
  91. if (cpu_has_llsc && R10000_LLSC_WAR) {
  92. __asm__ __volatile__ (
  93. " .set arch=r4000 \n"
  94. " li %[err], 0 \n"
  95. "1: ll %[old], (%[addr]) \n"
  96. " move %[tmp], %[new] \n"
  97. "2: sc %[tmp], (%[addr]) \n"
  98. " beqzl %[tmp], 1b \n"
  99. "3: \n"
  100. " .insn \n"
  101. " .section .fixup,\"ax\" \n"
  102. "4: li %[err], %[efault] \n"
  103. " j 3b \n"
  104. " .previous \n"
  105. " .section __ex_table,\"a\" \n"
  106. " "STR(PTR)" 1b, 4b \n"
  107. " "STR(PTR)" 2b, 4b \n"
  108. " .previous \n"
  109. " .set mips0 \n"
  110. : [old] "=&r" (old),
  111. [err] "=&r" (err),
  112. [tmp] "=&r" (tmp)
  113. : [addr] "r" (addr),
  114. [new] "r" (new),
  115. [efault] "i" (-EFAULT)
  116. : "memory");
  117. } else if (cpu_has_llsc) {
  118. __asm__ __volatile__ (
  119. " .set "MIPS_ISA_ARCH_LEVEL" \n"
  120. " li %[err], 0 \n"
  121. "1: ll %[old], (%[addr]) \n"
  122. " move %[tmp], %[new] \n"
  123. "2: sc %[tmp], (%[addr]) \n"
  124. " bnez %[tmp], 4f \n"
  125. "3: \n"
  126. " .insn \n"
  127. " .subsection 2 \n"
  128. "4: b 1b \n"
  129. " .previous \n"
  130. " \n"
  131. " .section .fixup,\"ax\" \n"
  132. "5: li %[err], %[efault] \n"
  133. " j 3b \n"
  134. " .previous \n"
  135. " .section __ex_table,\"a\" \n"
  136. " "STR(PTR)" 1b, 5b \n"
  137. " "STR(PTR)" 2b, 5b \n"
  138. " .previous \n"
  139. " .set mips0 \n"
  140. : [old] "=&r" (old),
  141. [err] "=&r" (err),
  142. [tmp] "=&r" (tmp)
  143. : [addr] "r" (addr),
  144. [new] "r" (new),
  145. [efault] "i" (-EFAULT)
  146. : "memory");
  147. } else {
  148. do {
  149. preempt_disable();
  150. ll_bit = 1;
  151. ll_task = current;
  152. preempt_enable();
  153. err = __get_user(old, (unsigned int *) addr);
  154. err |= __put_user(new, (unsigned int *) addr);
  155. if (err)
  156. break;
  157. rmb();
  158. } while (!ll_bit);
  159. }
  160. if (unlikely(err))
  161. return err;
  162. regs = current_pt_regs();
  163. regs->regs[2] = old;
  164. regs->regs[7] = 0; /* No error */
  165. /*
  166. * Don't let your children do this ...
  167. */
  168. __asm__ __volatile__(
  169. " move $29, %0 \n"
  170. " j syscall_exit \n"
  171. : /* no outputs */
  172. : "r" (regs));
  173. /* unreached. Honestly. */
  174. unreachable();
  175. }
  176. SYSCALL_DEFINE3(sysmips, long, cmd, long, arg1, long, arg2)
  177. {
  178. switch (cmd) {
  179. case MIPS_ATOMIC_SET:
  180. return mips_atomic_set(arg1, arg2);
  181. case MIPS_FIXADE:
  182. if (arg1 & ~3)
  183. return -EINVAL;
  184. if (arg1 & 1)
  185. set_thread_flag(TIF_FIXADE);
  186. else
  187. clear_thread_flag(TIF_FIXADE);
  188. if (arg1 & 2)
  189. set_thread_flag(TIF_LOGADE);
  190. else
  191. clear_thread_flag(TIF_LOGADE);
  192. return 0;
  193. case FLUSH_CACHE:
  194. __flush_cache_all();
  195. return 0;
  196. }
  197. return -EINVAL;
  198. }
  199. /*
  200. * No implemented yet ...
  201. */
  202. SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op)
  203. {
  204. return -ENOSYS;
  205. }
  206. /*
  207. * If we ever come here the user sp is bad. Zap the process right away.
  208. * Due to the bad stack signaling wouldn't work.
  209. */
  210. asmlinkage void bad_stack(void)
  211. {
  212. do_exit(SIGSEGV);
  213. }