ipc_namespace.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef __IPC_NAMESPACE_H__
  2. #define __IPC_NAMESPACE_H__
  3. #include <linux/err.h>
  4. #include <linux/idr.h>
  5. #include <linux/rwsem.h>
  6. #include <linux/notifier.h>
  7. /*
  8. * ipc namespace events
  9. */
  10. #define IPCNS_MEMCHANGED 0x00000001 /* Notify lowmem size changed */
  11. #define IPCNS_CREATED 0x00000002 /* Notify new ipc namespace created */
  12. #define IPCNS_REMOVED 0x00000003 /* Notify ipc namespace removed */
  13. #define IPCNS_CALLBACK_PRI 0
  14. struct ipc_ids {
  15. int in_use;
  16. unsigned short seq;
  17. unsigned short seq_max;
  18. struct rw_semaphore rw_mutex;
  19. struct idr ipcs_idr;
  20. };
  21. struct ipc_namespace {
  22. struct kref kref;
  23. struct ipc_ids ids[3];
  24. int sem_ctls[4];
  25. int used_sems;
  26. int msg_ctlmax;
  27. int msg_ctlmnb;
  28. int msg_ctlmni;
  29. atomic_t msg_bytes;
  30. atomic_t msg_hdrs;
  31. int auto_msgmni;
  32. size_t shm_ctlmax;
  33. size_t shm_ctlall;
  34. int shm_ctlmni;
  35. int shm_tot;
  36. struct notifier_block ipcns_nb;
  37. /* The kern_mount of the mqueuefs sb. We take a ref on it */
  38. struct vfsmount *mq_mnt;
  39. /* # queues in this ns, protected by mq_lock */
  40. unsigned int mq_queues_count;
  41. /* next fields are set through sysctl */
  42. unsigned int mq_queues_max; /* initialized to DFLT_QUEUESMAX */
  43. unsigned int mq_msg_max; /* initialized to DFLT_MSGMAX */
  44. unsigned int mq_msgsize_max; /* initialized to DFLT_MSGSIZEMAX */
  45. };
  46. extern struct ipc_namespace init_ipc_ns;
  47. extern atomic_t nr_ipc_ns;
  48. #if defined(CONFIG_POSIX_MQUEUE) || defined(CONFIG_SYSVIPC)
  49. #define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
  50. #else
  51. #define INIT_IPC_NS(ns)
  52. #endif
  53. #ifdef CONFIG_SYSVIPC
  54. extern int register_ipcns_notifier(struct ipc_namespace *);
  55. extern int cond_register_ipcns_notifier(struct ipc_namespace *);
  56. extern void unregister_ipcns_notifier(struct ipc_namespace *);
  57. extern int ipcns_notify(unsigned long);
  58. #else /* CONFIG_SYSVIPC */
  59. static inline int register_ipcns_notifier(struct ipc_namespace *ns)
  60. { return 0; }
  61. static inline int cond_register_ipcns_notifier(struct ipc_namespace *ns)
  62. { return 0; }
  63. static inline void unregister_ipcns_notifier(struct ipc_namespace *ns) { }
  64. static inline int ipcns_notify(unsigned long l) { return 0; }
  65. #endif /* CONFIG_SYSVIPC */
  66. #ifdef CONFIG_POSIX_MQUEUE
  67. extern void mq_init_ns(struct ipc_namespace *ns);
  68. /* default values */
  69. #define DFLT_QUEUESMAX 256 /* max number of message queues */
  70. #define DFLT_MSGMAX 10 /* max number of messages in each queue */
  71. #define HARD_MSGMAX (131072/sizeof(void *))
  72. #define DFLT_MSGSIZEMAX 8192 /* max message size */
  73. #else
  74. #define mq_init_ns(ns) ((void) 0)
  75. #endif
  76. #if defined(CONFIG_IPC_NS)
  77. extern void free_ipc_ns(struct kref *kref);
  78. extern struct ipc_namespace *copy_ipcs(unsigned long flags,
  79. struct ipc_namespace *ns);
  80. extern void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
  81. void (*free)(struct ipc_namespace *,
  82. struct kern_ipc_perm *));
  83. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  84. {
  85. if (ns)
  86. kref_get(&ns->kref);
  87. return ns;
  88. }
  89. static inline void put_ipc_ns(struct ipc_namespace *ns)
  90. {
  91. kref_put(&ns->kref, free_ipc_ns);
  92. }
  93. #else
  94. static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
  95. struct ipc_namespace *ns)
  96. {
  97. if (flags & CLONE_NEWIPC)
  98. return ERR_PTR(-EINVAL);
  99. return ns;
  100. }
  101. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  102. {
  103. return ns;
  104. }
  105. static inline void put_ipc_ns(struct ipc_namespace *ns)
  106. {
  107. }
  108. #endif
  109. #endif