sys_i386_32.c 5.8 KB

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