syscall.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 <asm/asm.h>
  30. #include <asm/branch.h>
  31. #include <asm/cachectl.h>
  32. #include <asm/cacheflush.h>
  33. #include <asm/asm-offsets.h>
  34. #include <asm/signal.h>
  35. #include <asm/sim.h>
  36. #include <asm/shmparam.h>
  37. #include <asm/sysmips.h>
  38. #include <asm/uaccess.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. unsigned long result;
  61. result = -EINVAL;
  62. if (offset & ~PAGE_MASK)
  63. goto out;
  64. result = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  65. out:
  66. return result;
  67. }
  68. SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
  69. unsigned long, prot, unsigned long, flags, unsigned long, fd,
  70. unsigned long, pgoff)
  71. {
  72. if (pgoff & (~PAGE_MASK >> 12))
  73. return -EINVAL;
  74. return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
  75. }
  76. save_static_function(sys_fork);
  77. static int __used noinline
  78. _sys_fork(nabi_no_regargs struct pt_regs regs)
  79. {
  80. return do_fork(SIGCHLD, 0, 0, NULL, NULL);
  81. }
  82. save_static_function(sys_clone);
  83. static int __used noinline
  84. _sys_clone(nabi_no_regargs struct pt_regs regs)
  85. {
  86. unsigned long clone_flags;
  87. unsigned long newsp;
  88. int __user *parent_tidptr, *child_tidptr;
  89. clone_flags = regs.regs[4];
  90. newsp = regs.regs[5];
  91. parent_tidptr = (int __user *) regs.regs[6];
  92. #ifdef CONFIG_32BIT
  93. /* We need to fetch the fifth argument off the stack. */
  94. child_tidptr = NULL;
  95. if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) {
  96. int __user *__user *usp = (int __user *__user *) regs.regs[29];
  97. if (regs.regs[2] == __NR_syscall) {
  98. if (get_user (child_tidptr, &usp[5]))
  99. return -EFAULT;
  100. }
  101. else if (get_user (child_tidptr, &usp[4]))
  102. return -EFAULT;
  103. }
  104. #else
  105. child_tidptr = (int __user *) regs.regs[8];
  106. #endif
  107. return do_fork(clone_flags, newsp, 0,
  108. parent_tidptr, child_tidptr);
  109. }
  110. SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
  111. {
  112. struct thread_info *ti = task_thread_info(current);
  113. ti->tp_value = addr;
  114. if (cpu_has_userlocal)
  115. write_c0_userlocal(addr);
  116. return 0;
  117. }
  118. static inline int mips_atomic_set(unsigned long addr, unsigned long new)
  119. {
  120. unsigned long old, tmp;
  121. struct pt_regs *regs;
  122. unsigned int err;
  123. if (unlikely(addr & 3))
  124. return -EINVAL;
  125. if (unlikely(!access_ok(VERIFY_WRITE, addr, 4)))
  126. return -EINVAL;
  127. if (cpu_has_llsc && R10000_LLSC_WAR) {
  128. __asm__ __volatile__ (
  129. " .set mips3 \n"
  130. " li %[err], 0 \n"
  131. "1: ll %[old], (%[addr]) \n"
  132. " move %[tmp], %[new] \n"
  133. "2: sc %[tmp], (%[addr]) \n"
  134. " beqzl %[tmp], 1b \n"
  135. "3: \n"
  136. " .section .fixup,\"ax\" \n"
  137. "4: li %[err], %[efault] \n"
  138. " j 3b \n"
  139. " .previous \n"
  140. " .section __ex_table,\"a\" \n"
  141. " "STR(PTR)" 1b, 4b \n"
  142. " "STR(PTR)" 2b, 4b \n"
  143. " .previous \n"
  144. " .set mips0 \n"
  145. : [old] "=&r" (old),
  146. [err] "=&r" (err),
  147. [tmp] "=&r" (tmp)
  148. : [addr] "r" (addr),
  149. [new] "r" (new),
  150. [efault] "i" (-EFAULT)
  151. : "memory");
  152. } else if (cpu_has_llsc) {
  153. __asm__ __volatile__ (
  154. " .set mips3 \n"
  155. " li %[err], 0 \n"
  156. "1: ll %[old], (%[addr]) \n"
  157. " move %[tmp], %[new] \n"
  158. "2: sc %[tmp], (%[addr]) \n"
  159. " bnez %[tmp], 4f \n"
  160. "3: \n"
  161. " .subsection 2 \n"
  162. "4: b 1b \n"
  163. " .previous \n"
  164. " \n"
  165. " .section .fixup,\"ax\" \n"
  166. "5: li %[err], %[efault] \n"
  167. " j 3b \n"
  168. " .previous \n"
  169. " .section __ex_table,\"a\" \n"
  170. " "STR(PTR)" 1b, 5b \n"
  171. " "STR(PTR)" 2b, 5b \n"
  172. " .previous \n"
  173. " .set mips0 \n"
  174. : [old] "=&r" (old),
  175. [err] "=&r" (err),
  176. [tmp] "=&r" (tmp)
  177. : [addr] "r" (addr),
  178. [new] "r" (new),
  179. [efault] "i" (-EFAULT)
  180. : "memory");
  181. } else {
  182. do {
  183. preempt_disable();
  184. ll_bit = 1;
  185. ll_task = current;
  186. preempt_enable();
  187. err = __get_user(old, (unsigned int *) addr);
  188. err |= __put_user(new, (unsigned int *) addr);
  189. if (err)
  190. break;
  191. rmb();
  192. } while (!ll_bit);
  193. }
  194. if (unlikely(err))
  195. return err;
  196. regs = current_pt_regs();
  197. regs->regs[2] = old;
  198. regs->regs[7] = 0; /* No error */
  199. /*
  200. * Don't let your children do this ...
  201. */
  202. __asm__ __volatile__(
  203. " move $29, %0 \n"
  204. " j syscall_exit \n"
  205. : /* no outputs */
  206. : "r" (regs));
  207. /* unreached. Honestly. */
  208. unreachable();
  209. }
  210. SYSCALL_DEFINE3(sysmips, long, cmd, long, arg1, long, arg2)
  211. {
  212. switch (cmd) {
  213. case MIPS_ATOMIC_SET:
  214. return mips_atomic_set(arg1, arg2);
  215. case MIPS_FIXADE:
  216. if (arg1 & ~3)
  217. return -EINVAL;
  218. if (arg1 & 1)
  219. set_thread_flag(TIF_FIXADE);
  220. else
  221. clear_thread_flag(TIF_FIXADE);
  222. if (arg1 & 2)
  223. set_thread_flag(TIF_LOGADE);
  224. else
  225. clear_thread_flag(TIF_LOGADE);
  226. return 0;
  227. case FLUSH_CACHE:
  228. __flush_cache_all();
  229. return 0;
  230. }
  231. return -EINVAL;
  232. }
  233. /*
  234. * No implemented yet ...
  235. */
  236. SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op)
  237. {
  238. return -ENOSYS;
  239. }
  240. /*
  241. * If we ever come here the user sp is bad. Zap the process right away.
  242. * Due to the bad stack signaling wouldn't work.
  243. */
  244. asmlinkage void bad_stack(void)
  245. {
  246. do_exit(SIGSEGV);
  247. }