sys_sparc_32.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. asmlinkage unsigned long sys_getpagesize(void)
  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. asmlinkage long sparc_pipe(struct pt_regs *regs)
  67. {
  68. int fd[2];
  69. int error;
  70. error = do_pipe_flags(fd, 0);
  71. if (error)
  72. goto out;
  73. 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. asmlinkage long sys_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 sys_mmap_pgoff(addr, len, prot, flags, fd,
  93. pgoff >> (PAGE_SHIFT - 12));
  94. }
  95. asmlinkage long sys_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 sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  101. }
  102. long 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. /* we come to here via sys_nis_syscall so it can setup the regs argument */
  113. asmlinkage unsigned long
  114. c_sys_nis_syscall (struct pt_regs *regs)
  115. {
  116. static int count = 0;
  117. if (count++ > 5)
  118. return -ENOSYS;
  119. printk ("%s[%d]: Unimplemented SPARC system call %d\n",
  120. current->comm, task_pid_nr(current), (int)regs->u_regs[1]);
  121. #ifdef DEBUG_UNIMP_SYSCALL
  122. show_regs (regs);
  123. #endif
  124. return -ENOSYS;
  125. }
  126. /* #define DEBUG_SPARC_BREAKPOINT */
  127. asmlinkage void
  128. sparc_breakpoint (struct pt_regs *regs)
  129. {
  130. siginfo_t info;
  131. #ifdef DEBUG_SPARC_BREAKPOINT
  132. printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs->pc, regs->npc);
  133. #endif
  134. info.si_signo = SIGTRAP;
  135. info.si_errno = 0;
  136. info.si_code = TRAP_BRKPT;
  137. info.si_addr = (void __user *)regs->pc;
  138. info.si_trapno = 0;
  139. force_sig_info(SIGTRAP, &info, current);
  140. #ifdef DEBUG_SPARC_BREAKPOINT
  141. printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs->pc, regs->npc);
  142. #endif
  143. }
  144. SYSCALL_DEFINE3(sparc_sigaction, int, sig,
  145. struct old_sigaction __user *,act,
  146. struct old_sigaction __user *,oact)
  147. {
  148. WARN_ON_ONCE(sig >= 0);
  149. return sys_sigaction(-sig, act, oact);
  150. }
  151. SYSCALL_DEFINE5(rt_sigaction, int, sig,
  152. const struct sigaction __user *, act,
  153. struct sigaction __user *, oact,
  154. void __user *, restorer,
  155. size_t, sigsetsize)
  156. {
  157. struct k_sigaction new_ka, old_ka;
  158. int ret;
  159. /* XXX: Don't preclude handling different sized sigset_t's. */
  160. if (sigsetsize != sizeof(sigset_t))
  161. return -EINVAL;
  162. if (act) {
  163. new_ka.ka_restorer = restorer;
  164. if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
  165. return -EFAULT;
  166. }
  167. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  168. if (!ret && oact) {
  169. if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
  170. return -EFAULT;
  171. }
  172. return ret;
  173. }
  174. asmlinkage long sys_getdomainname(char __user *name, int len)
  175. {
  176. int nlen, err;
  177. if (len < 0)
  178. return -EINVAL;
  179. down_read(&uts_sem);
  180. nlen = strlen(utsname()->domainname) + 1;
  181. err = -EINVAL;
  182. if (nlen > len)
  183. goto out;
  184. err = -EFAULT;
  185. if (!copy_to_user(name, utsname()->domainname, nlen))
  186. err = 0;
  187. out:
  188. up_read(&uts_sem);
  189. return err;
  190. }