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