ipc_namespace.h 2.2 KB

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