sys_sparc_32.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* linux/arch/sparc/kernel/sys_sparc.c
  3. *
  4. * This file contains various random system calls that
  5. * have a non-standard calling sequence on the Linux/sparc
  6. * platform.
  7. */
  8. #include <linux/errno.h>
  9. #include <linux/types.h>
  10. #include <linux/sched/signal.h>
  11. #include <linux/sched/mm.h>
  12. #include <linux/sched/debug.h>
  13. #include <linux/mm.h>
  14. #include <linux/fs.h>
  15. #include <linux/file.h>
  16. #include <linux/sem.h>
  17. #include <linux/msg.h>
  18. #include <linux/shm.h>
  19. #include <linux/stat.h>
  20. #include <linux/syscalls.h>
  21. #include <linux/mman.h>
  22. #include <linux/utsname.h>
  23. #include <linux/smp.h>
  24. #include <linux/ipc.h>
  25. #include <linux/uaccess.h>
  26. #include <asm/unistd.h>
  27. #include "systbls.h"
  28. /* #define DEBUG_UNIMP_SYSCALL */
  29. /* XXX Make this per-binary type, this way we can detect the type of
  30. * XXX a binary. Every Sparc executable calls this very early on.
  31. */
  32. SYSCALL_DEFINE0(getpagesize)
  33. {
  34. return PAGE_SIZE; /* Possibly older binaries want 8192 on sun4's? */
  35. }
  36. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
  37. {
  38. struct vm_unmapped_area_info info;
  39. if (flags & MAP_FIXED) {
  40. /* We do not accept a shared mapping if it would violate
  41. * cache aliasing constraints.
  42. */
  43. if ((flags & MAP_SHARED) &&
  44. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  45. return -EINVAL;
  46. return addr;
  47. }
  48. /* See asm-sparc/uaccess.h */
  49. if (len > TASK_SIZE - PAGE_SIZE)
  50. return -ENOMEM;
  51. if (!addr)
  52. addr = TASK_UNMAPPED_BASE;
  53. info.flags = 0;
  54. info.length = len;
  55. info.low_limit = addr;
  56. info.high_limit = TASK_SIZE;
  57. info.align_mask = (flags & MAP_SHARED) ?
  58. (PAGE_MASK & (SHMLBA - 1)) : 0;
  59. info.align_offset = pgoff << PAGE_SHIFT;
  60. return vm_unmapped_area(&info);
  61. }
  62. /*
  63. * sys_pipe() is the normal C calling standard for creating
  64. * a pipe. It's not the way unix traditionally does this, though.
  65. */
  66. SYSCALL_DEFINE0(sparc_pipe)
  67. {
  68. int fd[2];
  69. int error;
  70. error = do_pipe_flags(fd, 0);
  71. if (error)
  72. goto out;
  73. current_pt_regs()->u_regs[UREG_I1] = fd[1];
  74. error = fd[0];
  75. out:
  76. return error;
  77. }
  78. int sparc_mmap_check(unsigned long addr, unsigned long len)
  79. {
  80. /* See asm-sparc/uaccess.h */
  81. if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE)
  82. return -EINVAL;
  83. return 0;
  84. }
  85. /* Linux version of mmap */
  86. SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
  87. unsigned long, prot, unsigned long, flags, unsigned long, fd,
  88. unsigned long, pgoff)
  89. {
  90. /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
  91. we have. */
  92. return ksys_mmap_pgoff(addr, len, prot, flags, fd,
  93. pgoff >> (PAGE_SHIFT - 12));
  94. }
  95. SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
  96. unsigned long, prot, unsigned long, flags, unsigned long, fd,
  97. unsigned long, off)
  98. {
  99. /* no alignment check? */
  100. return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  101. }
  102. SYSCALL_DEFINE5(sparc_remap_file_pages, unsigned long, start, unsigned long, size,
  103. unsigned long, prot, unsigned long, pgoff,
  104. unsigned long, flags)
  105. {
  106. /* This works on an existing mmap so we don't need to validate
  107. * the range as that was done at the original mmap call.
  108. */
  109. return sys_remap_file_pages(start, size, prot,
  110. (pgoff >> (PAGE_SHIFT - 12)), flags);
  111. }
  112. SYSCALL_DEFINE0(nis_syscall)
  113. {
  114. static int count = 0;
  115. struct pt_regs *regs = current_pt_regs();
  116. if (count++ > 5)
  117. return -ENOSYS;
  118. printk ("%s[%d]: Unimplemented SPARC system call %d\n",
  119. current->comm, task_pid_nr(current), (int)regs->u_regs[1]);
  120. #ifdef DEBUG_UNIMP_SYSCALL
  121. show_regs (regs);
  122. #endif
  123. return -ENOSYS;
  124. }
  125. /* #define DEBUG_SPARC_BREAKPOINT */
  126. asmlinkage void
  127. sparc_breakpoint (struct pt_regs *regs)
  128. {
  129. #ifdef DEBUG_SPARC_BREAKPOINT
  130. printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs->pc, regs->npc);
  131. #endif
  132. force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)regs->pc);
  133. #ifdef DEBUG_SPARC_BREAKPOINT
  134. printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs->pc, regs->npc);
  135. #endif
  136. }
  137. SYSCALL_DEFINE3(sparc_sigaction, int, sig,
  138. struct old_sigaction __user *,act,
  139. struct old_sigaction __user *,oact)
  140. {
  141. WARN_ON_ONCE(sig >= 0);
  142. return sys_sigaction(-sig, act, oact);
  143. }
  144. SYSCALL_DEFINE5(rt_sigaction, int, sig,
  145. const struct sigaction __user *, act,
  146. struct sigaction __user *, oact,
  147. void __user *, restorer,
  148. size_t, sigsetsize)
  149. {
  150. struct k_sigaction new_ka, old_ka;
  151. int ret;
  152. /* XXX: Don't preclude handling different sized sigset_t's. */
  153. if (sigsetsize != sizeof(sigset_t))
  154. return -EINVAL;
  155. if (act) {
  156. new_ka.ka_restorer = restorer;
  157. if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
  158. return -EFAULT;
  159. }
  160. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  161. if (!ret && oact) {
  162. if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
  163. return -EFAULT;
  164. }
  165. return ret;
  166. }
  167. SYSCALL_DEFINE2(getdomainname, char __user *, name, int, len)
  168. {
  169. int nlen, err;
  170. char tmp[__NEW_UTS_LEN + 1];
  171. if (len < 0)
  172. return -EINVAL;
  173. down_read(&uts_sem);
  174. nlen = strlen(utsname()->domainname) + 1;
  175. err = -EINVAL;
  176. if (nlen > len)
  177. goto out_unlock;
  178. memcpy(tmp, utsname()->domainname, nlen);
  179. up_read(&uts_sem);
  180. if (copy_to_user(name, tmp, nlen))
  181. return -EFAULT;
  182. return 0;
  183. out_unlock:
  184. up_read(&uts_sem);
  185. return err;
  186. }