ipc_namespace.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. struct ipc_ids {
  7. int in_use;
  8. unsigned short seq;
  9. unsigned short seq_max;
  10. struct rw_semaphore rw_mutex;
  11. struct idr ipcs_idr;
  12. };
  13. struct ipc_namespace {
  14. struct kref kref;
  15. struct ipc_ids ids[3];
  16. int sem_ctls[4];
  17. int used_sems;
  18. int msg_ctlmax;
  19. int msg_ctlmnb;
  20. int msg_ctlmni;
  21. atomic_t msg_bytes;
  22. atomic_t msg_hdrs;
  23. size_t shm_ctlmax;
  24. size_t shm_ctlall;
  25. int shm_ctlmni;
  26. int shm_tot;
  27. };
  28. extern struct ipc_namespace init_ipc_ns;
  29. #ifdef CONFIG_SYSVIPC
  30. #define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
  31. #else
  32. #define INIT_IPC_NS(ns)
  33. #endif
  34. #if defined(CONFIG_SYSVIPC) && defined(CONFIG_IPC_NS)
  35. extern void free_ipc_ns(struct kref *kref);
  36. extern struct ipc_namespace *copy_ipcs(unsigned long flags,
  37. struct ipc_namespace *ns);
  38. extern void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
  39. void (*free)(struct ipc_namespace *,
  40. struct kern_ipc_perm *));
  41. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  42. {
  43. if (ns)
  44. kref_get(&ns->kref);
  45. return ns;
  46. }
  47. static inline void put_ipc_ns(struct ipc_namespace *ns)
  48. {
  49. kref_put(&ns->kref, free_ipc_ns);
  50. }
  51. #else
  52. static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
  53. struct ipc_namespace *ns)
  54. {
  55. if (flags & CLONE_NEWIPC)
  56. return ERR_PTR(-EINVAL);
  57. return ns;
  58. }
  59. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  60. {
  61. return ns;
  62. }
  63. static inline void put_ipc_ns(struct ipc_namespace *ns)
  64. {
  65. }
  66. #endif
  67. #endif