syscalls.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 *) ptr, second,
  87. NULL);
  88. case SEMTIMEDOP:
  89. return sys_semtimedop(first, (struct sembuf *) ptr, second,
  90. (const struct timespec *) fifth);
  91. case SEMGET:
  92. return sys_semget (first, second, third);
  93. case SEMCTL: {
  94. union semun fourth;
  95. if (!ptr)
  96. return -EINVAL;
  97. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  98. return -EFAULT;
  99. return sys_semctl (first, second, third, fourth);
  100. }
  101. case MSGSND:
  102. return sys_msgsnd (first, (struct msgbuf *) ptr,
  103. second, third);
  104. case MSGRCV:
  105. switch (version) {
  106. case 0: {
  107. struct ipc_kludge tmp;
  108. if (!ptr)
  109. return -EINVAL;
  110. if (copy_from_user(&tmp,
  111. (struct ipc_kludge *) ptr,
  112. sizeof (tmp)))
  113. return -EFAULT;
  114. return sys_msgrcv (first, tmp.msgp, second,
  115. tmp.msgtyp, third);
  116. }
  117. default:
  118. panic("msgrcv with version != 0");
  119. return sys_msgrcv (first,
  120. (struct msgbuf *) ptr,
  121. second, fifth, third);
  122. }
  123. case MSGGET:
  124. return sys_msgget ((key_t) first, second);
  125. case MSGCTL:
  126. return sys_msgctl (first, second, (struct msqid_ds *) ptr);
  127. case SHMAT:
  128. switch (version) {
  129. default: {
  130. ulong raddr;
  131. ret = do_shmat (first, (char *) ptr, second, &raddr);
  132. if (ret)
  133. return ret;
  134. return put_user (raddr, (ulong *) third);
  135. }
  136. case 1: /* iBCS2 emulator entry point */
  137. if (!segment_eq(get_fs(), get_ds()))
  138. return -EINVAL;
  139. return do_shmat (first, (char *) ptr, second, (ulong *) third);
  140. }
  141. case SHMDT:
  142. return sys_shmdt ((char *)ptr);
  143. case SHMGET:
  144. return sys_shmget (first, second, third);
  145. case SHMCTL:
  146. return sys_shmctl (first, second,
  147. (struct shmid_ds *) ptr);
  148. default:
  149. return -ENOSYS;
  150. }
  151. }
  152. long sys_sigaction(int sig, const struct old_sigaction __user *act,
  153. struct old_sigaction __user *oact)
  154. {
  155. struct k_sigaction new_ka, old_ka;
  156. int ret;
  157. if (act) {
  158. old_sigset_t mask;
  159. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  160. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  161. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
  162. return -EFAULT;
  163. __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  164. __get_user(mask, &act->sa_mask);
  165. siginitset(&new_ka.sa.sa_mask, mask);
  166. }
  167. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  168. if (!ret && oact) {
  169. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  170. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  171. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
  172. return -EFAULT;
  173. __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  174. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  175. }
  176. return ret;
  177. }