sys_sparc_32.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /* linux/arch/sparc/kernel/sys_sparc.c
  2. *
  3. * This file contains various random system calls that
  4. * have a non-standard calling sequence on the Linux/sparc
  5. * platform.
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/types.h>
  9. #include <linux/sched.h>
  10. #include <linux/mm.h>
  11. #include <linux/fs.h>
  12. #include <linux/file.h>
  13. #include <linux/sem.h>
  14. #include <linux/msg.h>
  15. #include <linux/shm.h>
  16. #include <linux/stat.h>
  17. #include <linux/syscalls.h>
  18. #include <linux/mman.h>
  19. #include <linux/utsname.h>
  20. #include <linux/smp.h>
  21. #include <linux/ipc.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/unistd.h>
  24. /* #define DEBUG_UNIMP_SYSCALL */
  25. /* XXX Make this per-binary type, this way we can detect the type of
  26. * XXX a binary. Every Sparc executable calls this very early on.
  27. */
  28. asmlinkage unsigned long sys_getpagesize(void)
  29. {
  30. return PAGE_SIZE; /* Possibly older binaries want 8192 on sun4's? */
  31. }
  32. #define COLOUR_ALIGN(addr) (((addr)+SHMLBA-1)&~(SHMLBA-1))
  33. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
  34. {
  35. struct vm_area_struct * vmm;
  36. if (flags & MAP_FIXED) {
  37. /* We do not accept a shared mapping if it would violate
  38. * cache aliasing constraints.
  39. */
  40. if ((flags & MAP_SHARED) &&
  41. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  42. return -EINVAL;
  43. return addr;
  44. }
  45. /* See asm-sparc/uaccess.h */
  46. if (len > TASK_SIZE - PAGE_SIZE)
  47. return -ENOMEM;
  48. if (ARCH_SUN4C && len > 0x20000000)
  49. return -ENOMEM;
  50. if (!addr)
  51. addr = TASK_UNMAPPED_BASE;
  52. if (flags & MAP_SHARED)
  53. addr = COLOUR_ALIGN(addr);
  54. else
  55. addr = PAGE_ALIGN(addr);
  56. for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
  57. /* At this point: (!vmm || addr < vmm->vm_end). */
  58. if (ARCH_SUN4C && addr < 0xe0000000 && 0x20000000 - len < addr) {
  59. addr = PAGE_OFFSET;
  60. vmm = find_vma(current->mm, PAGE_OFFSET);
  61. }
  62. if (TASK_SIZE - PAGE_SIZE - len < addr)
  63. return -ENOMEM;
  64. if (!vmm || addr + len <= vmm->vm_start)
  65. return addr;
  66. addr = vmm->vm_end;
  67. if (flags & MAP_SHARED)
  68. addr = COLOUR_ALIGN(addr);
  69. }
  70. }
  71. /*
  72. * sys_pipe() is the normal C calling standard for creating
  73. * a pipe. It's not the way unix traditionally does this, though.
  74. */
  75. asmlinkage int sparc_pipe(struct pt_regs *regs)
  76. {
  77. int fd[2];
  78. int error;
  79. error = do_pipe_flags(fd, 0);
  80. if (error)
  81. goto out;
  82. regs->u_regs[UREG_I1] = fd[1];
  83. error = fd[0];
  84. out:
  85. return error;
  86. }
  87. int sparc_mmap_check(unsigned long addr, unsigned long len)
  88. {
  89. if (ARCH_SUN4C &&
  90. (len > 0x20000000 ||
  91. (addr < 0xe0000000 && addr + len > 0x20000000)))
  92. return -EINVAL;
  93. /* See asm-sparc/uaccess.h */
  94. if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE)
  95. return -EINVAL;
  96. return 0;
  97. }
  98. /* Linux version of mmap */
  99. asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
  100. unsigned long prot, unsigned long flags, unsigned long fd,
  101. unsigned long pgoff)
  102. {
  103. /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
  104. we have. */
  105. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  106. pgoff >> (PAGE_SHIFT - 12));
  107. }
  108. asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
  109. unsigned long prot, unsigned long flags, unsigned long fd,
  110. unsigned long off)
  111. {
  112. /* no alignment check? */
  113. return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  114. }
  115. long sparc_remap_file_pages(unsigned long start, unsigned long size,
  116. unsigned long prot, unsigned long pgoff,
  117. unsigned long flags)
  118. {
  119. /* This works on an existing mmap so we don't need to validate
  120. * the range as that was done at the original mmap call.
  121. */
  122. return sys_remap_file_pages(start, size, prot,
  123. (pgoff >> (PAGE_SHIFT - 12)), flags);
  124. }
  125. /* we come to here via sys_nis_syscall so it can setup the regs argument */
  126. asmlinkage unsigned long
  127. c_sys_nis_syscall (struct pt_regs *regs)
  128. {
  129. static int count = 0;
  130. if (count++ > 5)
  131. return -ENOSYS;
  132. printk ("%s[%d]: Unimplemented SPARC system call %d\n",
  133. current->comm, task_pid_nr(current), (int)regs->u_regs[1]);
  134. #ifdef DEBUG_UNIMP_SYSCALL
  135. show_regs (regs);
  136. #endif
  137. return -ENOSYS;
  138. }
  139. /* #define DEBUG_SPARC_BREAKPOINT */
  140. asmlinkage void
  141. sparc_breakpoint (struct pt_regs *regs)
  142. {
  143. siginfo_t info;
  144. #ifdef DEBUG_SPARC_BREAKPOINT
  145. printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs->pc, regs->npc);
  146. #endif
  147. info.si_signo = SIGTRAP;
  148. info.si_errno = 0;
  149. info.si_code = TRAP_BRKPT;
  150. info.si_addr = (void __user *)regs->pc;
  151. info.si_trapno = 0;
  152. force_sig_info(SIGTRAP, &info, current);
  153. #ifdef DEBUG_SPARC_BREAKPOINT
  154. printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs->pc, regs->npc);
  155. #endif
  156. }
  157. asmlinkage int
  158. sparc_sigaction (int sig, const struct old_sigaction __user *act,
  159. struct old_sigaction __user *oact)
  160. {
  161. struct k_sigaction new_ka, old_ka;
  162. int ret;
  163. WARN_ON_ONCE(sig >= 0);
  164. sig = -sig;
  165. if (act) {
  166. unsigned long mask;
  167. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  168. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  169. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
  170. return -EFAULT;
  171. __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  172. __get_user(mask, &act->sa_mask);
  173. siginitset(&new_ka.sa.sa_mask, mask);
  174. new_ka.ka_restorer = NULL;
  175. }
  176. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  177. if (!ret && oact) {
  178. /* In the clone() case we could copy half consistent
  179. * state to the user, however this could sleep and
  180. * deadlock us if we held the signal lock on SMP. So for
  181. * now I take the easy way out and do no locking.
  182. */
  183. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  184. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  185. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
  186. return -EFAULT;
  187. __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  188. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  189. }
  190. return ret;
  191. }
  192. asmlinkage long
  193. sys_rt_sigaction(int sig,
  194. const struct sigaction __user *act,
  195. struct sigaction __user *oact,
  196. void __user *restorer,
  197. size_t sigsetsize)
  198. {
  199. struct k_sigaction new_ka, old_ka;
  200. int ret;
  201. /* XXX: Don't preclude handling different sized sigset_t's. */
  202. if (sigsetsize != sizeof(sigset_t))
  203. return -EINVAL;
  204. if (act) {
  205. new_ka.ka_restorer = restorer;
  206. if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
  207. return -EFAULT;
  208. }
  209. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  210. if (!ret && oact) {
  211. if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
  212. return -EFAULT;
  213. }
  214. return ret;
  215. }
  216. asmlinkage int sys_getdomainname(char __user *name, int len)
  217. {
  218. int nlen, err;
  219. if (len < 0)
  220. return -EINVAL;
  221. down_read(&uts_sem);
  222. nlen = strlen(utsname()->domainname) + 1;
  223. err = -EINVAL;
  224. if (nlen > len)
  225. goto out;
  226. err = -EFAULT;
  227. if (!copy_to_user(name, utsname()->domainname, nlen))
  228. err = 0;
  229. out:
  230. up_read(&uts_sem);
  231. return err;
  232. }
  233. /*
  234. * Do a system call from kernel instead of calling sys_execve so we
  235. * end up with proper pt_regs.
  236. */
  237. int kernel_execve(const char *filename,
  238. const char *const argv[],
  239. const char *const envp[])
  240. {
  241. long __res;
  242. register long __g1 __asm__ ("g1") = __NR_execve;
  243. register long __o0 __asm__ ("o0") = (long)(filename);
  244. register long __o1 __asm__ ("o1") = (long)(argv);
  245. register long __o2 __asm__ ("o2") = (long)(envp);
  246. asm volatile ("t 0x10\n\t"
  247. "bcc 1f\n\t"
  248. "mov %%o0, %0\n\t"
  249. "sub %%g0, %%o0, %0\n\t"
  250. "1:\n\t"
  251. : "=r" (__res), "=&r" (__o0)
  252. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1)
  253. : "cc");
  254. return __res;
  255. }