ipc_namespace.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  39. {
  40. if (ns)
  41. kref_get(&ns->kref);
  42. return ns;
  43. }
  44. static inline void put_ipc_ns(struct ipc_namespace *ns)
  45. {
  46. kref_put(&ns->kref, free_ipc_ns);
  47. }
  48. #else
  49. static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
  50. struct ipc_namespace *ns)
  51. {
  52. if (flags & CLONE_NEWIPC)
  53. return ERR_PTR(-EINVAL);
  54. return ns;
  55. }
  56. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  57. {
  58. return ns;
  59. }
  60. static inline void put_ipc_ns(struct ipc_namespace *ns)
  61. {
  62. }
  63. #endif
  64. #endif