syscalls.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. /* The i386 version skips reading from %esi, the fourth argument. So we must do
  54. * this, too.
  55. */
  56. long sys_clone(unsigned long clone_flags, unsigned long newsp,
  57. int __user *parent_tid, int unused, int __user *child_tid)
  58. {
  59. long ret;
  60. if (!newsp)
  61. newsp = UPT_SP(&current->thread.regs.regs);
  62. current->thread.forking = 1;
  63. ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
  64. child_tid);
  65. current->thread.forking = 0;
  66. return(ret);
  67. }
  68. /*
  69. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  70. *
  71. * This is really horribly ugly.
  72. */
  73. long sys_ipc (uint call, int first, int second,
  74. int third, void __user *ptr, long fifth)
  75. {
  76. int version, ret;
  77. version = call >> 16; /* hack for backward compatibility */
  78. call &= 0xffff;
  79. switch (call) {
  80. case SEMOP:
  81. return sys_semtimedop(first, (struct sembuf *) ptr, second,
  82. NULL);
  83. case SEMTIMEDOP:
  84. return sys_semtimedop(first, (struct sembuf *) ptr, second,
  85. (const struct timespec *) fifth);
  86. case SEMGET:
  87. return sys_semget (first, second, third);
  88. case SEMCTL: {
  89. union semun fourth;
  90. if (!ptr)
  91. return -EINVAL;
  92. if (get_user(fourth.__pad, (void **) ptr))
  93. return -EFAULT;
  94. return sys_semctl (first, second, third, fourth);
  95. }
  96. case MSGSND:
  97. return sys_msgsnd (first, (struct msgbuf *) ptr,
  98. second, third);
  99. case MSGRCV:
  100. switch (version) {
  101. case 0: {
  102. struct ipc_kludge tmp;
  103. if (!ptr)
  104. return -EINVAL;
  105. if (copy_from_user(&tmp,
  106. (struct ipc_kludge *) ptr,
  107. sizeof (tmp)))
  108. return -EFAULT;
  109. return sys_msgrcv (first, tmp.msgp, second,
  110. tmp.msgtyp, third);
  111. }
  112. default:
  113. panic("msgrcv with version != 0");
  114. return sys_msgrcv (first,
  115. (struct msgbuf *) ptr,
  116. second, fifth, third);
  117. }
  118. case MSGGET:
  119. return sys_msgget ((key_t) first, second);
  120. case MSGCTL:
  121. return sys_msgctl (first, second, (struct msqid_ds *) ptr);
  122. case SHMAT:
  123. switch (version) {
  124. default: {
  125. ulong raddr;
  126. ret = do_shmat (first, (char *) ptr, second, &raddr);
  127. if (ret)
  128. return ret;
  129. return put_user (raddr, (ulong *) third);
  130. }
  131. case 1: /* iBCS2 emulator entry point */
  132. if (!segment_eq(get_fs(), get_ds()))
  133. return -EINVAL;
  134. return do_shmat (first, (char *) ptr, second, (ulong *) third);
  135. }
  136. case SHMDT:
  137. return sys_shmdt ((char *)ptr);
  138. case SHMGET:
  139. return sys_shmget (first, second, third);
  140. case SHMCTL:
  141. return sys_shmctl (first, second,
  142. (struct shmid_ds *) ptr);
  143. default:
  144. return -ENOSYS;
  145. }
  146. }
  147. long sys_sigaction(int sig, const struct old_sigaction __user *act,
  148. struct old_sigaction __user *oact)
  149. {
  150. struct k_sigaction new_ka, old_ka;
  151. int ret;
  152. if (act) {
  153. old_sigset_t mask;
  154. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  155. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  156. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
  157. return -EFAULT;
  158. __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  159. __get_user(mask, &act->sa_mask);
  160. siginitset(&new_ka.sa.sa_mask, mask);
  161. }
  162. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  163. if (!ret && oact) {
  164. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  165. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  166. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
  167. return -EFAULT;
  168. __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  169. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  170. }
  171. return ret;
  172. }