ipc.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #ifdef __KERNEL__
  43. #include <linux/kref.h>
  44. #define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */
  45. /* used by in-kernel data structures */
  46. struct kern_ipc_perm
  47. {
  48. spinlock_t lock;
  49. int deleted;
  50. key_t key;
  51. uid_t uid;
  52. gid_t gid;
  53. uid_t cuid;
  54. gid_t cgid;
  55. mode_t mode;
  56. unsigned long seq;
  57. void *security;
  58. };
  59. struct ipc_ids;
  60. struct ipc_namespace {
  61. struct kref kref;
  62. struct ipc_ids *ids[3];
  63. int sem_ctls[4];
  64. int used_sems;
  65. int msg_ctlmax;
  66. int msg_ctlmnb;
  67. int msg_ctlmni;
  68. size_t shm_ctlmax;
  69. size_t shm_ctlall;
  70. int shm_ctlmni;
  71. int shm_tot;
  72. };
  73. extern struct ipc_namespace init_ipc_ns;
  74. #ifdef CONFIG_SYSVIPC
  75. #define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
  76. extern int copy_ipcs(unsigned long flags, struct task_struct *tsk);
  77. #else
  78. #define INIT_IPC_NS(ns)
  79. static inline int copy_ipcs(unsigned long flags, struct task_struct *tsk)
  80. { return 0; }
  81. #endif
  82. #ifdef CONFIG_IPC_NS
  83. extern void free_ipc_ns(struct kref *kref);
  84. extern int unshare_ipcs(unsigned long flags, struct ipc_namespace **ns);
  85. #endif
  86. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  87. {
  88. #ifdef CONFIG_IPC_NS
  89. if (ns)
  90. kref_get(&ns->kref);
  91. #endif
  92. return ns;
  93. }
  94. static inline void put_ipc_ns(struct ipc_namespace *ns)
  95. {
  96. #ifdef CONFIG_IPC_NS
  97. kref_put(&ns->kref, free_ipc_ns);
  98. #endif
  99. }
  100. #endif /* __KERNEL__ */
  101. #endif /* _LINUX_IPC_H */