sys_sh64.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * arch/sh64/kernel/sys_sh64.c
  7. *
  8. * Copyright (C) 2000, 2001 Paolo Alberelli
  9. *
  10. * This file contains various random system calls that
  11. * have a non-standard calling sequence on the Linux/SH5
  12. * platform.
  13. *
  14. * Mostly taken from i386 version.
  15. *
  16. */
  17. #include <linux/errno.h>
  18. #include <linux/rwsem.h>
  19. #include <linux/sched.h>
  20. #include <linux/mm.h>
  21. #include <linux/smp.h>
  22. #include <linux/smp_lock.h>
  23. #include <linux/sem.h>
  24. #include <linux/msg.h>
  25. #include <linux/shm.h>
  26. #include <linux/stat.h>
  27. #include <linux/mman.h>
  28. #include <linux/file.h>
  29. #include <linux/utsname.h>
  30. #include <linux/syscalls.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/ipc.h>
  33. #include <asm/ptrace.h>
  34. #define REG_3 3
  35. /*
  36. * sys_pipe() is the normal C calling standard for creating
  37. * a pipe. It's not the way Unix traditionally does this, though.
  38. */
  39. #ifdef NEW_PIPE_IMPLEMENTATION
  40. asmlinkage int sys_pipe(unsigned long * fildes,
  41. unsigned long dummy_r3,
  42. unsigned long dummy_r4,
  43. unsigned long dummy_r5,
  44. unsigned long dummy_r6,
  45. unsigned long dummy_r7,
  46. struct pt_regs * regs) /* r8 = pt_regs forced by entry.S */
  47. {
  48. int fd[2];
  49. int ret;
  50. ret = do_pipe(fd);
  51. if (ret == 0)
  52. /*
  53. ***********************************************************************
  54. * To avoid the copy_to_user we prefer to break the ABIs convention, *
  55. * packing the valid pair of file IDs into a single register (r3); *
  56. * while r2 is the return code as defined by the sh5-ABIs. *
  57. * BE CAREFUL: pipe stub, into glibc, must be aware of this solution *
  58. ***********************************************************************
  59. #ifdef __LITTLE_ENDIAN__
  60. regs->regs[REG_3] = (((unsigned long long) fd[1]) << 32) | ((unsigned long long) fd[0]);
  61. #else
  62. regs->regs[REG_3] = (((unsigned long long) fd[0]) << 32) | ((unsigned long long) fd[1]);
  63. #endif
  64. */
  65. /* although not very clever this is endianess independent */
  66. regs->regs[REG_3] = (unsigned long long) *((unsigned long long *) fd);
  67. return ret;
  68. }
  69. #else
  70. asmlinkage int sys_pipe(unsigned long * fildes)
  71. {
  72. int fd[2];
  73. int error;
  74. error = do_pipe(fd);
  75. if (!error) {
  76. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  77. error = -EFAULT;
  78. }
  79. return error;
  80. }
  81. #endif
  82. /*
  83. * To avoid cache alias, we map the shard page with same color.
  84. */
  85. #define COLOUR_ALIGN(addr) (((addr)+SHMLBA-1)&~(SHMLBA-1))
  86. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  87. unsigned long len, unsigned long pgoff, unsigned long flags)
  88. {
  89. struct vm_area_struct *vma;
  90. if (flags & MAP_FIXED) {
  91. /* We do not accept a shared mapping if it would violate
  92. * cache aliasing constraints.
  93. */
  94. if ((flags & MAP_SHARED) && (addr & (SHMLBA - 1)))
  95. return -EINVAL;
  96. return addr;
  97. }
  98. if (len > TASK_SIZE)
  99. return -ENOMEM;
  100. if (!addr)
  101. addr = TASK_UNMAPPED_BASE;
  102. if (flags & MAP_PRIVATE)
  103. addr = PAGE_ALIGN(addr);
  104. else
  105. addr = COLOUR_ALIGN(addr);
  106. for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
  107. /* At this point: (!vma || addr < vma->vm_end). */
  108. if (TASK_SIZE - len < addr)
  109. return -ENOMEM;
  110. if (!vma || addr + len <= vma->vm_start)
  111. return addr;
  112. addr = vma->vm_end;
  113. if (!(flags & MAP_PRIVATE))
  114. addr = COLOUR_ALIGN(addr);
  115. }
  116. }
  117. /* common code for old and new mmaps */
  118. static inline long do_mmap2(
  119. unsigned long addr, unsigned long len,
  120. unsigned long prot, unsigned long flags,
  121. unsigned long fd, unsigned long pgoff)
  122. {
  123. int error = -EBADF;
  124. struct file * file = NULL;
  125. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  126. if (!(flags & MAP_ANONYMOUS)) {
  127. file = fget(fd);
  128. if (!file)
  129. goto out;
  130. }
  131. down_write(&current->mm->mmap_sem);
  132. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  133. up_write(&current->mm->mmap_sem);
  134. if (file)
  135. fput(file);
  136. out:
  137. return error;
  138. }
  139. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  140. unsigned long prot, unsigned long flags,
  141. unsigned long fd, unsigned long pgoff)
  142. {
  143. return do_mmap2(addr, len, prot, flags, fd, pgoff);
  144. }
  145. asmlinkage int old_mmap(unsigned long addr, unsigned long len,
  146. unsigned long prot, unsigned long flags,
  147. int fd, unsigned long off)
  148. {
  149. if (off & ~PAGE_MASK)
  150. return -EINVAL;
  151. return do_mmap2(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
  152. }
  153. /*
  154. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  155. *
  156. * This is really horribly ugly.
  157. */
  158. asmlinkage int sys_ipc(uint call, int first, int second,
  159. int third, void __user *ptr, long fifth)
  160. {
  161. int version, ret;
  162. version = call >> 16; /* hack for backward compatibility */
  163. call &= 0xffff;
  164. if (call <= SEMCTL)
  165. switch (call) {
  166. case SEMOP:
  167. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  168. second, NULL);
  169. case SEMTIMEDOP:
  170. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  171. second,
  172. (const struct timespec __user *)fifth);
  173. case SEMGET:
  174. return sys_semget (first, second, third);
  175. case SEMCTL: {
  176. union semun fourth;
  177. if (!ptr)
  178. return -EINVAL;
  179. if (get_user(fourth.__pad, (void * __user *) ptr))
  180. return -EFAULT;
  181. return sys_semctl (first, second, third, fourth);
  182. }
  183. default:
  184. return -EINVAL;
  185. }
  186. if (call <= MSGCTL)
  187. switch (call) {
  188. case MSGSND:
  189. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  190. second, third);
  191. case MSGRCV:
  192. switch (version) {
  193. case 0: {
  194. struct ipc_kludge tmp;
  195. if (!ptr)
  196. return -EINVAL;
  197. if (copy_from_user(&tmp,
  198. (struct ipc_kludge __user *) ptr,
  199. sizeof (tmp)))
  200. return -EFAULT;
  201. return sys_msgrcv (first, tmp.msgp, second,
  202. tmp.msgtyp, third);
  203. }
  204. default:
  205. return sys_msgrcv (first,
  206. (struct msgbuf __user *) ptr,
  207. second, fifth, third);
  208. }
  209. case MSGGET:
  210. return sys_msgget ((key_t) first, second);
  211. case MSGCTL:
  212. return sys_msgctl (first, second,
  213. (struct msqid_ds __user *) ptr);
  214. default:
  215. return -EINVAL;
  216. }
  217. if (call <= SHMCTL)
  218. switch (call) {
  219. case SHMAT:
  220. switch (version) {
  221. default: {
  222. ulong raddr;
  223. ret = do_shmat (first, (char __user *) ptr,
  224. second, &raddr);
  225. if (ret)
  226. return ret;
  227. return put_user (raddr, (ulong __user *) third);
  228. }
  229. case 1: /* iBCS2 emulator entry point */
  230. if (!segment_eq(get_fs(), get_ds()))
  231. return -EINVAL;
  232. return do_shmat (first, (char __user *) ptr,
  233. second, (ulong *) third);
  234. }
  235. case SHMDT:
  236. return sys_shmdt ((char __user *)ptr);
  237. case SHMGET:
  238. return sys_shmget (first, second, third);
  239. case SHMCTL:
  240. return sys_shmctl (first, second,
  241. (struct shmid_ds __user *) ptr);
  242. default:
  243. return -EINVAL;
  244. }
  245. return -EINVAL;
  246. }
  247. asmlinkage int sys_uname(struct old_utsname * name)
  248. {
  249. int err;
  250. if (!name)
  251. return -EFAULT;
  252. down_read(&uts_sem);
  253. err=copy_to_user(name, &system_utsname, sizeof (*name));
  254. up_read(&uts_sem);
  255. return err?-EFAULT:0;
  256. }