syscalls.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/sched.h"
  6. #include "linux/shm.h"
  7. #include "asm/ipc.h"
  8. #include "asm/mman.h"
  9. #include "asm/uaccess.h"
  10. #include "asm/unistd.h"
  11. /*
  12. * Perform the select(nd, in, out, ex, tv) and mmap() system
  13. * calls. Linux/i386 didn't use to be able to handle more than
  14. * 4 system call parameters, so these system calls used a memory
  15. * block for parameter passing..
  16. */
  17. struct mmap_arg_struct {
  18. unsigned long addr;
  19. unsigned long len;
  20. unsigned long prot;
  21. unsigned long flags;
  22. unsigned long fd;
  23. unsigned long offset;
  24. };
  25. extern int old_mmap(unsigned long addr, unsigned long len,
  26. unsigned long prot, unsigned long flags,
  27. unsigned long fd, unsigned long offset);
  28. long old_mmap_i386(struct mmap_arg_struct __user *arg)
  29. {
  30. struct mmap_arg_struct a;
  31. int err = -EFAULT;
  32. if (copy_from_user(&a, arg, sizeof(a)))
  33. goto out;
  34. err = old_mmap(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
  35. out:
  36. return err;
  37. }
  38. struct sel_arg_struct {
  39. unsigned long n;
  40. fd_set __user *inp;
  41. fd_set __user *outp;
  42. fd_set __user *exp;
  43. struct timeval __user *tvp;
  44. };
  45. long old_select(struct sel_arg_struct __user *arg)
  46. {
  47. struct sel_arg_struct a;
  48. if (copy_from_user(&a, arg, sizeof(a)))
  49. return -EFAULT;
  50. /* sys_select() does the appropriate kernel locking */
  51. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  52. }
  53. /*
  54. * The prototype on i386 is:
  55. *
  56. * int clone(int flags, void * child_stack, int * parent_tidptr, struct user_desc * newtls, int * child_tidptr)
  57. *
  58. * and the "newtls" arg. on i386 is read by copy_thread directly from the
  59. * register saved on the stack.
  60. */
  61. long sys_clone(unsigned long clone_flags, unsigned long newsp,
  62. int __user *parent_tid, void *newtls, int __user *child_tid)
  63. {
  64. long ret;
  65. if (!newsp)
  66. newsp = UPT_SP(&current->thread.regs.regs);
  67. current->thread.forking = 1;
  68. ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
  69. child_tid);
  70. current->thread.forking = 0;
  71. return ret;
  72. }
  73. /*
  74. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  75. *
  76. * This is really horribly ugly.
  77. */
  78. long sys_ipc (uint call, int first, int second,
  79. int third, void __user *ptr, long fifth)
  80. {
  81. int version, ret;
  82. version = call >> 16; /* hack for backward compatibility */
  83. call &= 0xffff;
  84. switch (call) {
  85. case SEMOP:
  86. return sys_semtimedop(first, (struct sembuf __user *) ptr,
  87. second, NULL);
  88. case SEMTIMEDOP:
  89. return sys_semtimedop(first, (struct sembuf __user *) ptr,
  90. second,
  91. (const struct timespec __user *) fifth);
  92. case SEMGET:
  93. return sys_semget (first, second, third);
  94. case SEMCTL: {
  95. union semun fourth;
  96. if (!ptr)
  97. return -EINVAL;
  98. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  99. return -EFAULT;
  100. return sys_semctl (first, second, third, fourth);
  101. }
  102. case MSGSND:
  103. return sys_msgsnd (first, (struct msgbuf *) ptr,
  104. second, third);
  105. case MSGRCV:
  106. switch (version) {
  107. case 0: {
  108. struct ipc_kludge tmp;
  109. if (!ptr)
  110. return -EINVAL;
  111. if (copy_from_user(&tmp,
  112. (struct ipc_kludge *) ptr,
  113. sizeof (tmp)))
  114. return -EFAULT;
  115. return sys_msgrcv (first, tmp.msgp, second,
  116. tmp.msgtyp, third);
  117. }
  118. default:
  119. panic("msgrcv with version != 0");
  120. return sys_msgrcv (first,
  121. (struct msgbuf *) ptr,
  122. second, fifth, third);
  123. }
  124. case MSGGET:
  125. return sys_msgget ((key_t) first, second);
  126. case MSGCTL:
  127. return sys_msgctl (first, second, (struct msqid_ds *) ptr);
  128. case SHMAT:
  129. switch (version) {
  130. default: {
  131. ulong raddr;
  132. ret = do_shmat (first, (char *) ptr, second, &raddr);
  133. if (ret)
  134. return ret;
  135. return put_user (raddr, (ulong *) third);
  136. }
  137. case 1: /* iBCS2 emulator entry point */
  138. if (!segment_eq(get_fs(), get_ds()))
  139. return -EINVAL;
  140. return do_shmat (first, (char *) ptr, second, (ulong *) third);
  141. }
  142. case SHMDT:
  143. return sys_shmdt ((char *)ptr);
  144. case SHMGET:
  145. return sys_shmget (first, second, third);
  146. case SHMCTL:
  147. return sys_shmctl (first, second,
  148. (struct shmid_ds *) ptr);
  149. default:
  150. return -ENOSYS;
  151. }
  152. }
  153. long sys_sigaction(int sig, const struct old_sigaction __user *act,
  154. struct old_sigaction __user *oact)
  155. {
  156. struct k_sigaction new_ka, old_ka;
  157. int ret;
  158. if (act) {
  159. old_sigset_t mask;
  160. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  161. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  162. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
  163. return -EFAULT;
  164. __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  165. __get_user(mask, &act->sa_mask);
  166. siginitset(&new_ka.sa.sa_mask, mask);
  167. }
  168. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  169. if (!ret && oact) {
  170. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  171. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  172. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
  173. return -EFAULT;
  174. __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  175. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  176. }
  177. return ret;
  178. }