ipc.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef _LINUX_IPC_H
  2. #define _LINUX_IPC_H
  3. #include <linux/types.h>
  4. #define IPC_PRIVATE ((__kernel_key_t) 0)
  5. /* Obsolete, used only for backwards compatibility and libc5 compiles */
  6. struct ipc_perm
  7. {
  8. __kernel_key_t key;
  9. __kernel_uid_t uid;
  10. __kernel_gid_t gid;
  11. __kernel_uid_t cuid;
  12. __kernel_gid_t cgid;
  13. __kernel_mode_t mode;
  14. unsigned short seq;
  15. };
  16. /* Include the definition of ipc64_perm */
  17. #include <asm/ipcbuf.h>
  18. /* resource get request flags */
  19. #define IPC_CREAT 00001000 /* create if key is nonexistent */
  20. #define IPC_EXCL 00002000 /* fail if key exists */
  21. #define IPC_NOWAIT 00004000 /* return error on wait */
  22. /* these fields are used by the DIPC package so the kernel as standard
  23. should avoid using them if possible */
  24. #define IPC_DIPC 00010000 /* make it distributed */
  25. #define IPC_OWN 00020000 /* this machine is the DIPC owner */
  26. /*
  27. * Control commands used with semctl, msgctl and shmctl
  28. * see also specific commands in sem.h, msg.h and shm.h
  29. */
  30. #define IPC_RMID 0 /* remove resource */
  31. #define IPC_SET 1 /* set ipc_perm options */
  32. #define IPC_STAT 2 /* get ipc_perm options */
  33. #define IPC_INFO 3 /* see ipcs */
  34. /*
  35. * Version flags for semctl, msgctl, and shmctl commands
  36. * These are passed as bitflags or-ed with the actual command
  37. */
  38. #define IPC_OLD 0 /* Old version (no 32-bit UID support on many
  39. architectures) */
  40. #define IPC_64 0x0100 /* New version (support 32-bit UIDs, bigger
  41. message sizes, etc. */
  42. /*
  43. * These are used to wrap system calls.
  44. *
  45. * See architecture code for ugly details..
  46. */
  47. struct ipc_kludge {
  48. struct msgbuf __user *msgp;
  49. long msgtyp;
  50. };
  51. #define SEMOP 1
  52. #define SEMGET 2
  53. #define SEMCTL 3
  54. #define SEMTIMEDOP 4
  55. #define MSGSND 11
  56. #define MSGRCV 12
  57. #define MSGGET 13
  58. #define MSGCTL 14
  59. #define SHMAT 21
  60. #define SHMDT 22
  61. #define SHMGET 23
  62. #define SHMCTL 24
  63. /* Used by the DIPC package, try and avoid reusing it */
  64. #define DIPC 25
  65. #define IPCCALL(version,op) ((version)<<16 | (op))
  66. #ifdef __KERNEL__
  67. #include <linux/kref.h>
  68. #include <linux/spinlock.h>
  69. #define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */
  70. /* used by in-kernel data structures */
  71. struct kern_ipc_perm
  72. {
  73. spinlock_t lock;
  74. int deleted;
  75. int id;
  76. key_t key;
  77. uid_t uid;
  78. gid_t gid;
  79. uid_t cuid;
  80. gid_t cgid;
  81. mode_t mode;
  82. unsigned long seq;
  83. void *security;
  84. };
  85. struct ipc_ids;
  86. struct ipc_namespace {
  87. struct kref kref;
  88. struct ipc_ids *ids[3];
  89. int sem_ctls[4];
  90. int used_sems;
  91. int msg_ctlmax;
  92. int msg_ctlmnb;
  93. int msg_ctlmni;
  94. size_t shm_ctlmax;
  95. size_t shm_ctlall;
  96. int shm_ctlmni;
  97. int shm_tot;
  98. };
  99. extern struct ipc_namespace init_ipc_ns;
  100. #ifdef CONFIG_SYSVIPC
  101. #define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
  102. extern void free_ipc_ns(struct kref *kref);
  103. extern struct ipc_namespace *copy_ipcs(unsigned long flags,
  104. struct ipc_namespace *ns);
  105. #else
  106. #define INIT_IPC_NS(ns)
  107. static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
  108. struct ipc_namespace *ns)
  109. {
  110. return ns;
  111. }
  112. #endif
  113. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  114. {
  115. #ifdef CONFIG_SYSVIPC
  116. if (ns)
  117. kref_get(&ns->kref);
  118. #endif
  119. return ns;
  120. }
  121. static inline void put_ipc_ns(struct ipc_namespace *ns)
  122. {
  123. #ifdef CONFIG_SYSVIPC
  124. kref_put(&ns->kref, free_ipc_ns);
  125. #endif
  126. }
  127. #endif /* __KERNEL__ */
  128. #endif /* _LINUX_IPC_H */