sys_sparc_32.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
  33. {
  34. struct vm_unmapped_area_info info;
  35. if (flags & MAP_FIXED) {
  36. /* We do not accept a shared mapping if it would violate
  37. * cache aliasing constraints.
  38. */
  39. if ((flags & MAP_SHARED) &&
  40. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  41. return -EINVAL;
  42. return addr;
  43. }
  44. /* See asm-sparc/uaccess.h */
  45. if (len > TASK_SIZE - PAGE_SIZE)
  46. return -ENOMEM;
  47. if (!addr)
  48. addr = TASK_UNMAPPED_BASE;
  49. info.flags = 0;
  50. info.length = len;
  51. info.low_limit = addr;
  52. info.high_limit = TASK_SIZE;
  53. info.align_mask = (flags & MAP_SHARED) ?
  54. (PAGE_MASK & (SHMLBA - 1)) : 0;
  55. info.align_offset = pgoff << PAGE_SHIFT;
  56. return vm_unmapped_area(&info);
  57. }
  58. /*
  59. * sys_pipe() is the normal C calling standard for creating
  60. * a pipe. It's not the way unix traditionally does this, though.
  61. */
  62. asmlinkage int sparc_pipe(struct pt_regs *regs)
  63. {
  64. int fd[2];
  65. int error;
  66. error = do_pipe_flags(fd, 0);
  67. if (error)
  68. goto out;
  69. regs->u_regs[UREG_I1] = fd[1];
  70. error = fd[0];
  71. out:
  72. return error;
  73. }
  74. int sparc_mmap_check(unsigned long addr, unsigned long len)
  75. {
  76. /* See asm-sparc/uaccess.h */
  77. if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE)
  78. return -EINVAL;
  79. return 0;
  80. }
  81. /* Linux version of mmap */
  82. asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
  83. unsigned long prot, unsigned long flags, unsigned long fd,
  84. unsigned long pgoff)
  85. {
  86. /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
  87. we have. */
  88. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  89. pgoff >> (PAGE_SHIFT - 12));
  90. }
  91. asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
  92. unsigned long prot, unsigned long flags, unsigned long fd,
  93. unsigned long off)
  94. {
  95. /* no alignment check? */
  96. return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  97. }
  98. long sparc_remap_file_pages(unsigned long start, unsigned long size,
  99. unsigned long prot, unsigned long pgoff,
  100. unsigned long flags)
  101. {
  102. /* This works on an existing mmap so we don't need to validate
  103. * the range as that was done at the original mmap call.
  104. */
  105. return sys_remap_file_pages(start, size, prot,
  106. (pgoff >> (PAGE_SHIFT - 12)), flags);
  107. }
  108. /* we come to here via sys_nis_syscall so it can setup the regs argument */
  109. asmlinkage unsigned long
  110. c_sys_nis_syscall (struct pt_regs *regs)
  111. {
  112. static int count = 0;
  113. if (count++ > 5)
  114. return -ENOSYS;
  115. printk ("%s[%d]: Unimplemented SPARC system call %d\n",
  116. current->comm, task_pid_nr(current), (int)regs->u_regs[1]);
  117. #ifdef DEBUG_UNIMP_SYSCALL
  118. show_regs (regs);
  119. #endif
  120. return -ENOSYS;
  121. }
  122. /* #define DEBUG_SPARC_BREAKPOINT */
  123. asmlinkage void
  124. sparc_breakpoint (struct pt_regs *regs)
  125. {
  126. siginfo_t info;
  127. #ifdef DEBUG_SPARC_BREAKPOINT
  128. printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs->pc, regs->npc);
  129. #endif
  130. info.si_signo = SIGTRAP;
  131. info.si_errno = 0;
  132. info.si_code = TRAP_BRKPT;
  133. info.si_addr = (void __user *)regs->pc;
  134. info.si_trapno = 0;
  135. force_sig_info(SIGTRAP, &info, current);
  136. #ifdef DEBUG_SPARC_BREAKPOINT
  137. printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs->pc, regs->npc);
  138. #endif
  139. }
  140. SYSCALL_DEFINE3(sparc_sigaction, int, sig,
  141. struct old_sigaction __user *,act,
  142. struct old_sigaction __user *,oact)
  143. {
  144. WARN_ON_ONCE(sig >= 0);
  145. return sys_sigaction(-sig, act, oact);
  146. }
  147. SYSCALL_DEFINE5(rt_sigaction, int, sig,
  148. const struct sigaction __user *, act,
  149. struct sigaction __user *, oact,
  150. void __user *, restorer,
  151. size_t, sigsetsize)
  152. {
  153. struct k_sigaction new_ka, old_ka;
  154. int ret;
  155. /* XXX: Don't preclude handling different sized sigset_t's. */
  156. if (sigsetsize != sizeof(sigset_t))
  157. return -EINVAL;
  158. if (act) {
  159. new_ka.ka_restorer = restorer;
  160. if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
  161. return -EFAULT;
  162. }
  163. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  164. if (!ret && oact) {
  165. if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
  166. return -EFAULT;
  167. }
  168. return ret;
  169. }
  170. asmlinkage int sys_getdomainname(char __user *name, int len)
  171. {
  172. int nlen, err;
  173. if (len < 0)
  174. return -EINVAL;
  175. down_read(&uts_sem);
  176. nlen = strlen(utsname()->domainname) + 1;
  177. err = -EINVAL;
  178. if (nlen > len)
  179. goto out;
  180. err = -EFAULT;
  181. if (!copy_to_user(name, utsname()->domainname, nlen))
  182. err = 0;
  183. out:
  184. up_read(&uts_sem);
  185. return err;
  186. }