sys_i386.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * linux/arch/i386/kernel/sys_i386.c
  3. *
  4. * This file contains various random system calls that
  5. * have a non-standard calling sequence on the Linux/i386
  6. * platform.
  7. */
  8. #include <linux/errno.h>
  9. #include <linux/sched.h>
  10. #include <linux/mm.h>
  11. #include <linux/smp.h>
  12. #include <linux/smp_lock.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/file.h>
  20. #include <linux/utsname.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/ipc.h>
  23. /*
  24. * sys_pipe() is the normal C calling standard for creating
  25. * a pipe. It's not the way Unix traditionally does this, though.
  26. */
  27. asmlinkage int sys_pipe(unsigned long __user * fildes)
  28. {
  29. int fd[2];
  30. int error;
  31. error = do_pipe(fd);
  32. if (!error) {
  33. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  34. error = -EFAULT;
  35. }
  36. return error;
  37. }
  38. /* common code for old and new mmaps */
  39. static inline long do_mmap2(
  40. unsigned long addr, unsigned long len,
  41. unsigned long prot, unsigned long flags,
  42. unsigned long fd, unsigned long pgoff)
  43. {
  44. int error = -EBADF;
  45. struct file * file = NULL;
  46. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  47. if (!(flags & MAP_ANONYMOUS)) {
  48. file = fget(fd);
  49. if (!file)
  50. goto out;
  51. }
  52. down_write(&current->mm->mmap_sem);
  53. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  54. up_write(&current->mm->mmap_sem);
  55. if (file)
  56. fput(file);
  57. out:
  58. return error;
  59. }
  60. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  61. unsigned long prot, unsigned long flags,
  62. unsigned long fd, unsigned long pgoff)
  63. {
  64. return do_mmap2(addr, len, prot, flags, fd, pgoff);
  65. }
  66. /*
  67. * Perform the select(nd, in, out, ex, tv) and mmap() system
  68. * calls. Linux/i386 didn't use to be able to handle more than
  69. * 4 system call parameters, so these system calls used a memory
  70. * block for parameter passing..
  71. */
  72. struct mmap_arg_struct {
  73. unsigned long addr;
  74. unsigned long len;
  75. unsigned long prot;
  76. unsigned long flags;
  77. unsigned long fd;
  78. unsigned long offset;
  79. };
  80. asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
  81. {
  82. struct mmap_arg_struct a;
  83. int err = -EFAULT;
  84. if (copy_from_user(&a, arg, sizeof(a)))
  85. goto out;
  86. err = -EINVAL;
  87. if (a.offset & ~PAGE_MASK)
  88. goto out;
  89. err = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
  90. out:
  91. return err;
  92. }
  93. struct sel_arg_struct {
  94. unsigned long n;
  95. fd_set __user *inp, *outp, *exp;
  96. struct timeval __user *tvp;
  97. };
  98. asmlinkage int old_select(struct sel_arg_struct __user *arg)
  99. {
  100. struct sel_arg_struct a;
  101. if (copy_from_user(&a, arg, sizeof(a)))
  102. return -EFAULT;
  103. /* sys_select() does the appropriate kernel locking */
  104. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  105. }
  106. /*
  107. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  108. *
  109. * This is really horribly ugly.
  110. */
  111. asmlinkage int sys_ipc (uint call, int first, int second,
  112. int third, void __user *ptr, long fifth)
  113. {
  114. int version, ret;
  115. version = call >> 16; /* hack for backward compatibility */
  116. call &= 0xffff;
  117. switch (call) {
  118. case SEMOP:
  119. return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
  120. case SEMTIMEDOP:
  121. return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
  122. (const struct timespec __user *)fifth);
  123. case SEMGET:
  124. return sys_semget (first, second, third);
  125. case SEMCTL: {
  126. union semun fourth;
  127. if (!ptr)
  128. return -EINVAL;
  129. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  130. return -EFAULT;
  131. return sys_semctl (first, second, third, fourth);
  132. }
  133. case MSGSND:
  134. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  135. second, third);
  136. case MSGRCV:
  137. switch (version) {
  138. case 0: {
  139. struct ipc_kludge tmp;
  140. if (!ptr)
  141. return -EINVAL;
  142. if (copy_from_user(&tmp,
  143. (struct ipc_kludge __user *) ptr,
  144. sizeof (tmp)))
  145. return -EFAULT;
  146. return sys_msgrcv (first, tmp.msgp, second,
  147. tmp.msgtyp, third);
  148. }
  149. default:
  150. return sys_msgrcv (first,
  151. (struct msgbuf __user *) ptr,
  152. second, fifth, third);
  153. }
  154. case MSGGET:
  155. return sys_msgget ((key_t) first, second);
  156. case MSGCTL:
  157. return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
  158. case SHMAT:
  159. switch (version) {
  160. default: {
  161. ulong raddr;
  162. ret = do_shmat (first, (char __user *) ptr, second, &raddr);
  163. if (ret)
  164. return ret;
  165. return put_user (raddr, (ulong __user *) third);
  166. }
  167. case 1: /* iBCS2 emulator entry point */
  168. if (!segment_eq(get_fs(), get_ds()))
  169. return -EINVAL;
  170. /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
  171. return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
  172. }
  173. case SHMDT:
  174. return sys_shmdt ((char __user *)ptr);
  175. case SHMGET:
  176. return sys_shmget (first, second, third);
  177. case SHMCTL:
  178. return sys_shmctl (first, second,
  179. (struct shmid_ds __user *) ptr);
  180. default:
  181. return -ENOSYS;
  182. }
  183. }
  184. /*
  185. * Old cruft
  186. */
  187. asmlinkage int sys_uname(struct old_utsname __user * name)
  188. {
  189. int err;
  190. if (!name)
  191. return -EFAULT;
  192. down_read(&uts_sem);
  193. err=copy_to_user(name, &system_utsname, sizeof (*name));
  194. up_read(&uts_sem);
  195. return err?-EFAULT:0;
  196. }
  197. asmlinkage int sys_olduname(struct oldold_utsname __user * name)
  198. {
  199. int error;
  200. if (!name)
  201. return -EFAULT;
  202. if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
  203. return -EFAULT;
  204. down_read(&uts_sem);
  205. error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
  206. error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
  207. error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
  208. error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
  209. error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
  210. error |= __put_user(0,name->release+__OLD_UTS_LEN);
  211. error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
  212. error |= __put_user(0,name->version+__OLD_UTS_LEN);
  213. error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
  214. error |= __put_user(0,name->machine+__OLD_UTS_LEN);
  215. up_read(&uts_sem);
  216. error = error ? -EFAULT : 0;
  217. return error;
  218. }