sys_sparc_32.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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/smp_lock.h>
  22. #include <linux/ipc.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/unistd.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. #define COLOUR_ALIGN(addr) (((addr)+SHMLBA-1)&~(SHMLBA-1))
  34. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
  35. {
  36. struct vm_area_struct * vmm;
  37. if (flags & MAP_FIXED) {
  38. /* We do not accept a shared mapping if it would violate
  39. * cache aliasing constraints.
  40. */
  41. if ((flags & MAP_SHARED) &&
  42. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  43. return -EINVAL;
  44. return addr;
  45. }
  46. /* See asm-sparc/uaccess.h */
  47. if (len > TASK_SIZE - PAGE_SIZE)
  48. return -ENOMEM;
  49. if (ARCH_SUN4C && len > 0x20000000)
  50. return -ENOMEM;
  51. if (!addr)
  52. addr = TASK_UNMAPPED_BASE;
  53. if (flags & MAP_SHARED)
  54. addr = COLOUR_ALIGN(addr);
  55. else
  56. addr = PAGE_ALIGN(addr);
  57. for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
  58. /* At this point: (!vmm || addr < vmm->vm_end). */
  59. if (ARCH_SUN4C && addr < 0xe0000000 && 0x20000000 - len < addr) {
  60. addr = PAGE_OFFSET;
  61. vmm = find_vma(current->mm, PAGE_OFFSET);
  62. }
  63. if (TASK_SIZE - PAGE_SIZE - len < addr)
  64. return -ENOMEM;
  65. if (!vmm || addr + len <= vmm->vm_start)
  66. return addr;
  67. addr = vmm->vm_end;
  68. if (flags & MAP_SHARED)
  69. addr = COLOUR_ALIGN(addr);
  70. }
  71. }
  72. /*
  73. * sys_pipe() is the normal C calling standard for creating
  74. * a pipe. It's not the way unix traditionally does this, though.
  75. */
  76. asmlinkage int sparc_pipe(struct pt_regs *regs)
  77. {
  78. int fd[2];
  79. int error;
  80. error = do_pipe_flags(fd, 0);
  81. if (error)
  82. goto out;
  83. regs->u_regs[UREG_I1] = fd[1];
  84. error = fd[0];
  85. out:
  86. return error;
  87. }
  88. /*
  89. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  90. *
  91. * This is really horribly ugly.
  92. */
  93. asmlinkage int sys_ipc (uint call, int first, int second, int third, void __user *ptr, long fifth)
  94. {
  95. int version, err;
  96. version = call >> 16; /* hack for backward compatibility */
  97. call &= 0xffff;
  98. if (call <= SEMCTL)
  99. switch (call) {
  100. case SEMOP:
  101. err = sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
  102. goto out;
  103. case SEMTIMEDOP:
  104. err = sys_semtimedop (first, (struct sembuf __user *)ptr, second, (const struct timespec __user *) fifth);
  105. goto out;
  106. case SEMGET:
  107. err = sys_semget (first, second, third);
  108. goto out;
  109. case SEMCTL: {
  110. union semun fourth;
  111. err = -EINVAL;
  112. if (!ptr)
  113. goto out;
  114. err = -EFAULT;
  115. if (get_user(fourth.__pad,
  116. (void __user * __user *)ptr))
  117. goto out;
  118. err = sys_semctl (first, second, third, fourth);
  119. goto out;
  120. }
  121. default:
  122. err = -ENOSYS;
  123. goto out;
  124. }
  125. if (call <= MSGCTL)
  126. switch (call) {
  127. case MSGSND:
  128. err = sys_msgsnd (first, (struct msgbuf __user *) ptr,
  129. second, third);
  130. goto out;
  131. case MSGRCV:
  132. switch (version) {
  133. case 0: {
  134. struct ipc_kludge tmp;
  135. err = -EINVAL;
  136. if (!ptr)
  137. goto out;
  138. err = -EFAULT;
  139. if (copy_from_user(&tmp, (struct ipc_kludge __user *) ptr, sizeof (tmp)))
  140. goto out;
  141. err = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, third);
  142. goto out;
  143. }
  144. case 1: default:
  145. err = sys_msgrcv (first,
  146. (struct msgbuf __user *) ptr,
  147. second, fifth, third);
  148. goto out;
  149. }
  150. case MSGGET:
  151. err = sys_msgget ((key_t) first, second);
  152. goto out;
  153. case MSGCTL:
  154. err = sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
  155. goto out;
  156. default:
  157. err = -ENOSYS;
  158. goto out;
  159. }
  160. if (call <= SHMCTL)
  161. switch (call) {
  162. case SHMAT:
  163. switch (version) {
  164. case 0: default: {
  165. ulong raddr;
  166. err = do_shmat (first, (char __user *) ptr, second, &raddr);
  167. if (err)
  168. goto out;
  169. err = -EFAULT;
  170. if (put_user (raddr, (ulong __user *) third))
  171. goto out;
  172. err = 0;
  173. goto out;
  174. }
  175. case 1: /* iBCS2 emulator entry point */
  176. err = -EINVAL;
  177. goto out;
  178. }
  179. case SHMDT:
  180. err = sys_shmdt ((char __user *)ptr);
  181. goto out;
  182. case SHMGET:
  183. err = sys_shmget (first, second, third);
  184. goto out;
  185. case SHMCTL:
  186. err = sys_shmctl (first, second, (struct shmid_ds __user *) ptr);
  187. goto out;
  188. default:
  189. err = -ENOSYS;
  190. goto out;
  191. }
  192. else
  193. err = -ENOSYS;
  194. out:
  195. return err;
  196. }
  197. int sparc_mmap_check(unsigned long addr, unsigned long len)
  198. {
  199. if (ARCH_SUN4C &&
  200. (len > 0x20000000 ||
  201. (addr < 0xe0000000 && addr + len > 0x20000000)))
  202. return -EINVAL;
  203. /* See asm-sparc/uaccess.h */
  204. if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE)
  205. return -EINVAL;
  206. return 0;
  207. }
  208. /* Linux version of mmap */
  209. asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
  210. unsigned long prot, unsigned long flags, unsigned long fd,
  211. unsigned long pgoff)
  212. {
  213. /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
  214. we have. */
  215. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  216. pgoff >> (PAGE_SHIFT - 12));
  217. }
  218. asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
  219. unsigned long prot, unsigned long flags, unsigned long fd,
  220. unsigned long off)
  221. {
  222. /* no alignment check? */
  223. return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  224. }
  225. long sparc_remap_file_pages(unsigned long start, unsigned long size,
  226. unsigned long prot, unsigned long pgoff,
  227. unsigned long flags)
  228. {
  229. /* This works on an existing mmap so we don't need to validate
  230. * the range as that was done at the original mmap call.
  231. */
  232. return sys_remap_file_pages(start, size, prot,
  233. (pgoff >> (PAGE_SHIFT - 12)), flags);
  234. }
  235. /* we come to here via sys_nis_syscall so it can setup the regs argument */
  236. asmlinkage unsigned long
  237. c_sys_nis_syscall (struct pt_regs *regs)
  238. {
  239. static int count = 0;
  240. if (count++ > 5)
  241. return -ENOSYS;
  242. printk ("%s[%d]: Unimplemented SPARC system call %d\n",
  243. current->comm, task_pid_nr(current), (int)regs->u_regs[1]);
  244. #ifdef DEBUG_UNIMP_SYSCALL
  245. show_regs (regs);
  246. #endif
  247. return -ENOSYS;
  248. }
  249. /* #define DEBUG_SPARC_BREAKPOINT */
  250. asmlinkage void
  251. sparc_breakpoint (struct pt_regs *regs)
  252. {
  253. siginfo_t info;
  254. lock_kernel();
  255. #ifdef DEBUG_SPARC_BREAKPOINT
  256. printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs->pc, regs->npc);
  257. #endif
  258. info.si_signo = SIGTRAP;
  259. info.si_errno = 0;
  260. info.si_code = TRAP_BRKPT;
  261. info.si_addr = (void __user *)regs->pc;
  262. info.si_trapno = 0;
  263. force_sig_info(SIGTRAP, &info, current);
  264. #ifdef DEBUG_SPARC_BREAKPOINT
  265. printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs->pc, regs->npc);
  266. #endif
  267. unlock_kernel();
  268. }
  269. asmlinkage int
  270. sparc_sigaction (int sig, const struct old_sigaction __user *act,
  271. struct old_sigaction __user *oact)
  272. {
  273. struct k_sigaction new_ka, old_ka;
  274. int ret;
  275. WARN_ON_ONCE(sig >= 0);
  276. sig = -sig;
  277. if (act) {
  278. unsigned long mask;
  279. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  280. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  281. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
  282. return -EFAULT;
  283. __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  284. __get_user(mask, &act->sa_mask);
  285. siginitset(&new_ka.sa.sa_mask, mask);
  286. new_ka.ka_restorer = NULL;
  287. }
  288. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  289. if (!ret && oact) {
  290. /* In the clone() case we could copy half consistent
  291. * state to the user, however this could sleep and
  292. * deadlock us if we held the signal lock on SMP. So for
  293. * now I take the easy way out and do no locking.
  294. */
  295. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  296. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  297. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
  298. return -EFAULT;
  299. __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  300. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  301. }
  302. return ret;
  303. }
  304. asmlinkage long
  305. sys_rt_sigaction(int sig,
  306. const struct sigaction __user *act,
  307. struct sigaction __user *oact,
  308. void __user *restorer,
  309. size_t sigsetsize)
  310. {
  311. struct k_sigaction new_ka, old_ka;
  312. int ret;
  313. /* XXX: Don't preclude handling different sized sigset_t's. */
  314. if (sigsetsize != sizeof(sigset_t))
  315. return -EINVAL;
  316. if (act) {
  317. new_ka.ka_restorer = restorer;
  318. if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
  319. return -EFAULT;
  320. }
  321. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  322. if (!ret && oact) {
  323. if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
  324. return -EFAULT;
  325. }
  326. return ret;
  327. }
  328. asmlinkage int sys_getdomainname(char __user *name, int len)
  329. {
  330. int nlen, err;
  331. if (len < 0)
  332. return -EINVAL;
  333. down_read(&uts_sem);
  334. nlen = strlen(utsname()->domainname) + 1;
  335. err = -EINVAL;
  336. if (nlen > len)
  337. goto out;
  338. err = -EFAULT;
  339. if (!copy_to_user(name, utsname()->domainname, nlen))
  340. err = 0;
  341. out:
  342. up_read(&uts_sem);
  343. return err;
  344. }
  345. /*
  346. * Do a system call from kernel instead of calling sys_execve so we
  347. * end up with proper pt_regs.
  348. */
  349. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  350. {
  351. long __res;
  352. register long __g1 __asm__ ("g1") = __NR_execve;
  353. register long __o0 __asm__ ("o0") = (long)(filename);
  354. register long __o1 __asm__ ("o1") = (long)(argv);
  355. register long __o2 __asm__ ("o2") = (long)(envp);
  356. asm volatile ("t 0x10\n\t"
  357. "bcc 1f\n\t"
  358. "mov %%o0, %0\n\t"
  359. "sub %%g0, %%o0, %0\n\t"
  360. "1:\n\t"
  361. : "=r" (__res), "=&r" (__o0)
  362. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1)
  363. : "cc");
  364. return __res;
  365. }