ipc_namespace.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. size_t shm_ctlmax;
  32. size_t shm_ctlall;
  33. int shm_ctlmni;
  34. int shm_tot;
  35. struct notifier_block ipcns_nb;
  36. };
  37. extern struct ipc_namespace init_ipc_ns;
  38. extern atomic_t nr_ipc_ns;
  39. #ifdef CONFIG_SYSVIPC
  40. #define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
  41. extern int register_ipcns_notifier(struct ipc_namespace *);
  42. extern int unregister_ipcns_notifier(struct ipc_namespace *);
  43. extern int ipcns_notify(unsigned long);
  44. #else /* CONFIG_SYSVIPC */
  45. #define INIT_IPC_NS(ns)
  46. #endif /* CONFIG_SYSVIPC */
  47. #if defined(CONFIG_SYSVIPC) && defined(CONFIG_IPC_NS)
  48. extern void free_ipc_ns(struct kref *kref);
  49. extern struct ipc_namespace *copy_ipcs(unsigned long flags,
  50. struct ipc_namespace *ns);
  51. extern void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
  52. void (*free)(struct ipc_namespace *,
  53. struct kern_ipc_perm *));
  54. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  55. {
  56. if (ns)
  57. kref_get(&ns->kref);
  58. return ns;
  59. }
  60. static inline void put_ipc_ns(struct ipc_namespace *ns)
  61. {
  62. kref_put(&ns->kref, free_ipc_ns);
  63. }
  64. #else
  65. static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
  66. struct ipc_namespace *ns)
  67. {
  68. if (flags & CLONE_NEWIPC)
  69. return ERR_PTR(-EINVAL);
  70. return ns;
  71. }
  72. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  73. {
  74. return ns;
  75. }
  76. static inline void put_ipc_ns(struct ipc_namespace *ns)
  77. {
  78. }
  79. #endif
  80. #endif