sys_sparc_32.c 5.2 KB

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