sys_sparc_32.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 (!addr)
  49. addr = TASK_UNMAPPED_BASE;
  50. if (flags & MAP_SHARED)
  51. addr = COLOUR_ALIGN(addr);
  52. else
  53. addr = PAGE_ALIGN(addr);
  54. for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
  55. /* At this point: (!vmm || addr < vmm->vm_end). */
  56. if (TASK_SIZE - PAGE_SIZE - len < addr)
  57. return -ENOMEM;
  58. if (!vmm || addr + len <= vmm->vm_start)
  59. return addr;
  60. addr = vmm->vm_end;
  61. if (flags & MAP_SHARED)
  62. addr = COLOUR_ALIGN(addr);
  63. }
  64. }
  65. /*
  66. * sys_pipe() is the normal C calling standard for creating
  67. * a pipe. It's not the way unix traditionally does this, though.
  68. */
  69. asmlinkage int sparc_pipe(struct pt_regs *regs)
  70. {
  71. int fd[2];
  72. int error;
  73. error = do_pipe_flags(fd, 0);
  74. if (error)
  75. goto out;
  76. regs->u_regs[UREG_I1] = fd[1];
  77. error = fd[0];
  78. out:
  79. return error;
  80. }
  81. int sparc_mmap_check(unsigned long addr, unsigned long len)
  82. {
  83. /* See asm-sparc/uaccess.h */
  84. if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE)
  85. return -EINVAL;
  86. return 0;
  87. }
  88. /* Linux version of mmap */
  89. asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
  90. unsigned long prot, unsigned long flags, unsigned long fd,
  91. unsigned long pgoff)
  92. {
  93. /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
  94. we have. */
  95. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  96. pgoff >> (PAGE_SHIFT - 12));
  97. }
  98. asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
  99. unsigned long prot, unsigned long flags, unsigned long fd,
  100. unsigned long off)
  101. {
  102. /* no alignment check? */
  103. return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  104. }
  105. long sparc_remap_file_pages(unsigned long start, unsigned long size,
  106. unsigned long prot, unsigned long pgoff,
  107. unsigned long flags)
  108. {
  109. /* This works on an existing mmap so we don't need to validate
  110. * the range as that was done at the original mmap call.
  111. */
  112. return sys_remap_file_pages(start, size, prot,
  113. (pgoff >> (PAGE_SHIFT - 12)), flags);
  114. }
  115. /* we come to here via sys_nis_syscall so it can setup the regs argument */
  116. asmlinkage unsigned long
  117. c_sys_nis_syscall (struct pt_regs *regs)
  118. {
  119. static int count = 0;
  120. if (count++ > 5)
  121. return -ENOSYS;
  122. printk ("%s[%d]: Unimplemented SPARC system call %d\n",
  123. current->comm, task_pid_nr(current), (int)regs->u_regs[1]);
  124. #ifdef DEBUG_UNIMP_SYSCALL
  125. show_regs (regs);
  126. #endif
  127. return -ENOSYS;
  128. }
  129. /* #define DEBUG_SPARC_BREAKPOINT */
  130. asmlinkage void
  131. sparc_breakpoint (struct pt_regs *regs)
  132. {
  133. siginfo_t info;
  134. #ifdef DEBUG_SPARC_BREAKPOINT
  135. printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs->pc, regs->npc);
  136. #endif
  137. info.si_signo = SIGTRAP;
  138. info.si_errno = 0;
  139. info.si_code = TRAP_BRKPT;
  140. info.si_addr = (void __user *)regs->pc;
  141. info.si_trapno = 0;
  142. force_sig_info(SIGTRAP, &info, current);
  143. #ifdef DEBUG_SPARC_BREAKPOINT
  144. printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs->pc, regs->npc);
  145. #endif
  146. }
  147. asmlinkage int
  148. sparc_sigaction (int sig, const struct old_sigaction __user *act,
  149. struct old_sigaction __user *oact)
  150. {
  151. struct k_sigaction new_ka, old_ka;
  152. int ret;
  153. WARN_ON_ONCE(sig >= 0);
  154. sig = -sig;
  155. if (act) {
  156. unsigned long mask;
  157. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  158. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  159. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
  160. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  161. __get_user(mask, &act->sa_mask))
  162. return -EFAULT;
  163. siginitset(&new_ka.sa.sa_mask, mask);
  164. new_ka.ka_restorer = NULL;
  165. }
  166. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  167. if (!ret && oact) {
  168. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  169. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  170. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
  171. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  172. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
  173. return -EFAULT;
  174. }
  175. return ret;
  176. }
  177. asmlinkage long
  178. sys_rt_sigaction(int sig,
  179. const struct sigaction __user *act,
  180. struct sigaction __user *oact,
  181. void __user *restorer,
  182. size_t sigsetsize)
  183. {
  184. struct k_sigaction new_ka, old_ka;
  185. int ret;
  186. /* XXX: Don't preclude handling different sized sigset_t's. */
  187. if (sigsetsize != sizeof(sigset_t))
  188. return -EINVAL;
  189. if (act) {
  190. new_ka.ka_restorer = restorer;
  191. if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
  192. return -EFAULT;
  193. }
  194. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  195. if (!ret && oact) {
  196. if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
  197. return -EFAULT;
  198. }
  199. return ret;
  200. }
  201. asmlinkage int sys_getdomainname(char __user *name, int len)
  202. {
  203. int nlen, err;
  204. if (len < 0)
  205. return -EINVAL;
  206. down_read(&uts_sem);
  207. nlen = strlen(utsname()->domainname) + 1;
  208. err = -EINVAL;
  209. if (nlen > len)
  210. goto out;
  211. err = -EFAULT;
  212. if (!copy_to_user(name, utsname()->domainname, nlen))
  213. err = 0;
  214. out:
  215. up_read(&uts_sem);
  216. return err;
  217. }
  218. /*
  219. * Do a system call from kernel instead of calling sys_execve so we
  220. * end up with proper pt_regs.
  221. */
  222. int kernel_execve(const char *filename,
  223. const char *const argv[],
  224. const char *const envp[])
  225. {
  226. long __res;
  227. register long __g1 __asm__ ("g1") = __NR_execve;
  228. register long __o0 __asm__ ("o0") = (long)(filename);
  229. register long __o1 __asm__ ("o1") = (long)(argv);
  230. register long __o2 __asm__ ("o2") = (long)(envp);
  231. asm volatile ("t 0x10\n\t"
  232. "bcc 1f\n\t"
  233. "mov %%o0, %0\n\t"
  234. "sub %%g0, %%o0, %0\n\t"
  235. "1:\n\t"
  236. : "=r" (__res), "=&r" (__o0)
  237. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1)
  238. : "cc");
  239. return __res;
  240. }