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