sys_sparc_32.c 5.2 KB

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