syscalls.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * arch/ppc/kernel/sys_ppc.c
  3. *
  4. * PowerPC version
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * Derived from "arch/i386/kernel/sys_i386.c"
  8. * Adapted from the i386 version by Gary Thomas
  9. * Modified by Cort Dougan (cort@cs.nmt.edu)
  10. * and Paul Mackerras (paulus@cs.anu.edu.au).
  11. *
  12. * This file contains various random system calls that
  13. * have a non-standard calling sequence on the Linux/PPC
  14. * platform.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License
  18. * as published by the Free Software Foundation; either version
  19. * 2 of the License, or (at your option) any later version.
  20. *
  21. */
  22. #include <linux/errno.h>
  23. #include <linux/sched.h>
  24. #include <linux/mm.h>
  25. #include <linux/smp.h>
  26. #include <linux/smp_lock.h>
  27. #include <linux/sem.h>
  28. #include <linux/msg.h>
  29. #include <linux/shm.h>
  30. #include <linux/stat.h>
  31. #include <linux/syscalls.h>
  32. #include <linux/mman.h>
  33. #include <linux/sys.h>
  34. #include <linux/ipc.h>
  35. #include <linux/utsname.h>
  36. #include <linux/file.h>
  37. #include <linux/unistd.h>
  38. #include <asm/uaccess.h>
  39. #include <asm/ipc.h>
  40. #include <asm/semaphore.h>
  41. void
  42. check_bugs(void)
  43. {
  44. }
  45. /*
  46. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  47. *
  48. * This is really horribly ugly.
  49. */
  50. int
  51. sys_ipc (uint call, int first, int second, int third, void __user *ptr, long fifth)
  52. {
  53. int version, ret;
  54. version = call >> 16; /* hack for backward compatibility */
  55. call &= 0xffff;
  56. ret = -ENOSYS;
  57. switch (call) {
  58. case SEMOP:
  59. ret = sys_semtimedop (first, (struct sembuf __user *)ptr,
  60. second, NULL);
  61. break;
  62. case SEMTIMEDOP:
  63. ret = sys_semtimedop (first, (struct sembuf __user *)ptr,
  64. second, (const struct timespec __user *) fifth);
  65. break;
  66. case SEMGET:
  67. ret = sys_semget (first, second, third);
  68. break;
  69. case SEMCTL: {
  70. union semun fourth;
  71. if (!ptr)
  72. break;
  73. if ((ret = access_ok(VERIFY_READ, ptr, sizeof(long)) ? 0 : -EFAULT)
  74. || (ret = get_user(fourth.__pad, (void __user *__user *)ptr)))
  75. break;
  76. ret = sys_semctl (first, second, third, fourth);
  77. break;
  78. }
  79. case MSGSND:
  80. ret = sys_msgsnd (first, (struct msgbuf __user *) ptr, second, third);
  81. break;
  82. case MSGRCV:
  83. switch (version) {
  84. case 0: {
  85. struct ipc_kludge tmp;
  86. if (!ptr)
  87. break;
  88. if ((ret = access_ok(VERIFY_READ, ptr, sizeof(tmp)) ? 0 : -EFAULT)
  89. || (ret = copy_from_user(&tmp,
  90. (struct ipc_kludge __user *) ptr,
  91. sizeof (tmp)) ? -EFAULT : 0))
  92. break;
  93. ret = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp,
  94. third);
  95. break;
  96. }
  97. default:
  98. ret = sys_msgrcv (first, (struct msgbuf __user *) ptr,
  99. second, fifth, third);
  100. break;
  101. }
  102. break;
  103. case MSGGET:
  104. ret = sys_msgget ((key_t) first, second);
  105. break;
  106. case MSGCTL:
  107. ret = sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
  108. break;
  109. case SHMAT: {
  110. ulong raddr;
  111. if ((ret = access_ok(VERIFY_WRITE, (ulong __user *) third,
  112. sizeof(ulong)) ? 0 : -EFAULT))
  113. break;
  114. ret = do_shmat (first, (char __user *) ptr, second, &raddr);
  115. if (ret)
  116. break;
  117. ret = put_user (raddr, (ulong __user *) third);
  118. break;
  119. }
  120. case SHMDT:
  121. ret = sys_shmdt ((char __user *)ptr);
  122. break;
  123. case SHMGET:
  124. ret = sys_shmget (first, second, third);
  125. break;
  126. case SHMCTL:
  127. ret = sys_shmctl (first, second, (struct shmid_ds __user *) ptr);
  128. break;
  129. }
  130. return ret;
  131. }
  132. /*
  133. * sys_pipe() is the normal C calling standard for creating
  134. * a pipe. It's not the way unix traditionally does this, though.
  135. */
  136. int sys_pipe(int __user *fildes)
  137. {
  138. int fd[2];
  139. int error;
  140. error = do_pipe(fd);
  141. if (!error) {
  142. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  143. error = -EFAULT;
  144. }
  145. return error;
  146. }
  147. static inline unsigned long
  148. do_mmap2(unsigned long addr, size_t len,
  149. unsigned long prot, unsigned long flags,
  150. unsigned long fd, unsigned long pgoff)
  151. {
  152. struct file * file = NULL;
  153. int ret = -EBADF;
  154. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  155. if (!(flags & MAP_ANONYMOUS)) {
  156. if (!(file = fget(fd)))
  157. goto out;
  158. }
  159. down_write(&current->mm->mmap_sem);
  160. ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  161. up_write(&current->mm->mmap_sem);
  162. if (file)
  163. fput(file);
  164. out:
  165. return ret;
  166. }
  167. unsigned long sys_mmap2(unsigned long addr, size_t len,
  168. unsigned long prot, unsigned long flags,
  169. unsigned long fd, unsigned long pgoff)
  170. {
  171. return do_mmap2(addr, len, prot, flags, fd, pgoff);
  172. }
  173. unsigned long sys_mmap(unsigned long addr, size_t len,
  174. unsigned long prot, unsigned long flags,
  175. unsigned long fd, off_t offset)
  176. {
  177. int err = -EINVAL;
  178. if (offset & ~PAGE_MASK)
  179. goto out;
  180. err = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  181. out:
  182. return err;
  183. }
  184. /*
  185. * Due to some executables calling the wrong select we sometimes
  186. * get wrong args. This determines how the args are being passed
  187. * (a single ptr to them all args passed) then calls
  188. * sys_select() with the appropriate args. -- Cort
  189. */
  190. int
  191. ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timeval __user *tvp)
  192. {
  193. if ( (unsigned long)n >= 4096 )
  194. {
  195. unsigned long __user *buffer = (unsigned long __user *)n;
  196. if (!access_ok(VERIFY_READ, buffer, 5*sizeof(unsigned long))
  197. || __get_user(n, buffer)
  198. || __get_user(inp, ((fd_set __user * __user *)(buffer+1)))
  199. || __get_user(outp, ((fd_set __user * __user *)(buffer+2)))
  200. || __get_user(exp, ((fd_set __user * __user *)(buffer+3)))
  201. || __get_user(tvp, ((struct timeval __user * __user *)(buffer+4))))
  202. return -EFAULT;
  203. }
  204. return sys_select(n, inp, outp, exp, tvp);
  205. }
  206. int sys_uname(struct old_utsname __user * name)
  207. {
  208. int err = -EFAULT;
  209. down_read(&uts_sem);
  210. if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
  211. err = 0;
  212. up_read(&uts_sem);
  213. return err;
  214. }
  215. int sys_olduname(struct oldold_utsname __user * name)
  216. {
  217. int error;
  218. if (!name)
  219. return -EFAULT;
  220. if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
  221. return -EFAULT;
  222. down_read(&uts_sem);
  223. error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
  224. error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
  225. error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
  226. error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
  227. error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
  228. error -= __put_user(0,name->release+__OLD_UTS_LEN);
  229. error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
  230. error -= __put_user(0,name->version+__OLD_UTS_LEN);
  231. error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
  232. error = __put_user(0,name->machine+__OLD_UTS_LEN);
  233. up_read(&uts_sem);
  234. error = error ? -EFAULT : 0;
  235. return error;
  236. }
  237. /*
  238. * We put the arguments in a different order so we only use 6
  239. * registers for arguments, rather than 7 as sys_fadvise64_64 needs
  240. * (because `offset' goes in r5/r6).
  241. */
  242. long ppc_fadvise64_64(int fd, int advice, loff_t offset, loff_t len)
  243. {
  244. return sys_fadvise64_64(fd, offset, len, advice);
  245. }