syscall.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * sys_ipc() is the old de-multiplexer for the SysV IPC calls.
  3. *
  4. * This is really horribly ugly, and new architectures should just wire up
  5. * the individual syscalls instead.
  6. */
  7. #include <linux/unistd.h>
  8. #ifdef __ARCH_WANT_SYS_IPC
  9. #include <linux/errno.h>
  10. #include <linux/ipc.h>
  11. #include <linux/shm.h>
  12. #include <linux/syscalls.h>
  13. #include <linux/uaccess.h>
  14. SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
  15. unsigned long, third, void __user *, ptr, long, fifth)
  16. {
  17. int version, ret;
  18. version = call >> 16; /* hack for backward compatibility */
  19. call &= 0xffff;
  20. switch (call) {
  21. case SEMOP:
  22. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  23. second, NULL);
  24. case SEMTIMEDOP:
  25. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  26. second,
  27. (const struct timespec __user *)fifth);
  28. case SEMGET:
  29. return sys_semget(first, second, third);
  30. case SEMCTL: {
  31. unsigned long arg;
  32. if (!ptr)
  33. return -EINVAL;
  34. if (get_user(arg, (unsigned long __user *) ptr))
  35. return -EFAULT;
  36. return sys_semctl(first, second, third, arg);
  37. }
  38. case MSGSND:
  39. return sys_msgsnd(first, (struct msgbuf __user *) ptr,
  40. second, third);
  41. case MSGRCV:
  42. switch (version) {
  43. case 0: {
  44. struct ipc_kludge tmp;
  45. if (!ptr)
  46. return -EINVAL;
  47. if (copy_from_user(&tmp,
  48. (struct ipc_kludge __user *) ptr,
  49. sizeof(tmp)))
  50. return -EFAULT;
  51. return sys_msgrcv(first, tmp.msgp, second,
  52. tmp.msgtyp, third);
  53. }
  54. default:
  55. return sys_msgrcv(first,
  56. (struct msgbuf __user *) ptr,
  57. second, fifth, third);
  58. }
  59. case MSGGET:
  60. return sys_msgget((key_t) first, second);
  61. case MSGCTL:
  62. return sys_msgctl(first, second, (struct msqid_ds __user *)ptr);
  63. case SHMAT:
  64. switch (version) {
  65. default: {
  66. unsigned long raddr;
  67. ret = do_shmat(first, (char __user *)ptr,
  68. second, &raddr, SHMLBA);
  69. if (ret)
  70. return ret;
  71. return put_user(raddr, (unsigned long __user *) third);
  72. }
  73. case 1:
  74. /*
  75. * This was the entry point for kernel-originating calls
  76. * from iBCS2 in 2.2 days.
  77. */
  78. return -EINVAL;
  79. }
  80. case SHMDT:
  81. return sys_shmdt((char __user *)ptr);
  82. case SHMGET:
  83. return sys_shmget(first, second, third);
  84. case SHMCTL:
  85. return sys_shmctl(first, second,
  86. (struct shmid_ds __user *) ptr);
  87. default:
  88. return -ENOSYS;
  89. }
  90. }
  91. #endif