Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 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 | #include <linux/notifier.h> |
| 8 | #include <linux/nsproxy.h> |
| 9 | |
| 10 | #define IPCNS_MEMCHANGED 0x00000001 |
| 11 | #define IPCNS_CREATED 0x00000002 |
| 12 | #define IPCNS_REMOVED 0x00000003 |
| 13 | |
| 14 | #define IPCNS_CALLBACK_PRI 0 |
| 15 | |
| 16 | struct user_namespace; |
| 17 | |
| 18 | struct ipc_ids { |
| 19 | int in_use; |
| 20 | unsigned short seq; |
| 21 | unsigned short seq_max; |
| 22 | struct rw_semaphore rw_mutex; |
| 23 | struct idr ipcs_idr; |
| 24 | }; |
| 25 | |
| 26 | struct ipc_namespace { |
| 27 | atomic_t count; |
| 28 | struct ipc_ids ids[3]; |
| 29 | |
| 30 | int sem_ctls[4]; |
| 31 | int used_sems; |
| 32 | |
| 33 | int msg_ctlmax; |
| 34 | int msg_ctlmnb; |
| 35 | int msg_ctlmni; |
| 36 | atomic_t msg_bytes; |
| 37 | atomic_t msg_hdrs; |
| 38 | int auto_msgmni; |
| 39 | |
| 40 | size_t shm_ctlmax; |
| 41 | size_t shm_ctlall; |
| 42 | int shm_ctlmni; |
| 43 | int shm_tot; |
| 44 | int shm_rmid_forced; |
| 45 | |
| 46 | struct notifier_block ipcns_nb; |
| 47 | |
| 48 | |
| 49 | struct vfsmount *mq_mnt; |
| 50 | |
| 51 | |
| 52 | unsigned int mq_queues_count; |
| 53 | |
| 54 | |
| 55 | unsigned int mq_queues_max; |
| 56 | unsigned int mq_msg_max; |
| 57 | unsigned int mq_msgsize_max; |
| 58 | |
| 59 | |
| 60 | struct user_namespace *user_ns; |
| 61 | }; |
| 62 | |
| 63 | extern struct ipc_namespace init_ipc_ns; |
| 64 | extern atomic_t nr_ipc_ns; |
| 65 | |
| 66 | extern spinlock_t mq_lock; |
| 67 | |
| 68 | #ifdef CONFIG_SYSVIPC |
| 69 | extern int register_ipcns_notifier(struct ipc_namespace *); |
| 70 | extern int cond_register_ipcns_notifier(struct ipc_namespace *); |
| 71 | extern void unregister_ipcns_notifier(struct ipc_namespace *); |
| 72 | extern int ipcns_notify(unsigned long); |
| 73 | extern void shm_destroy_orphaned(struct ipc_namespace *ns); |
| 74 | #else |
| 75 | static inline int register_ipcns_notifier(struct ipc_namespace *ns) |
| 76 | { return 0; } |
| 77 | static inline int cond_register_ipcns_notifier(struct ipc_namespace *ns) |
| 78 | { return 0; } |
| 79 | static inline void unregister_ipcns_notifier(struct ipc_namespace *ns) { } |
| 80 | static inline int ipcns_notify(unsigned long l) { return 0; } |
| 81 | static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {} |
| 82 | #endif |
| 83 | |
| 84 | #ifdef CONFIG_POSIX_MQUEUE |
| 85 | extern int mq_init_ns(struct ipc_namespace *ns); |
| 86 | #define DFLT_QUEUESMAX 256 |
| 87 | #define DFLT_MSGMAX 10 |
| 88 | #define HARD_MSGMAX (32768*sizeof(void *)/4) |
| 89 | #define DFLT_MSGSIZEMAX 8192 |
| 90 | #else |
| 91 | static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; } |
| 92 | #endif |
| 93 | |
| 94 | #if defined(CONFIG_IPC_NS) |
| 95 | extern struct ipc_namespace *copy_ipcs(unsigned long flags, |
| 96 | struct task_struct *tsk); |
| 97 | static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns) |
| 98 | { |
| 99 | if (ns) |
| 100 | atomic_inc(&ns->count); |
| 101 | return ns; |
| 102 | } |
| 103 | |
| 104 | extern void put_ipc_ns(struct ipc_namespace *ns); |
| 105 | #else |
| 106 | static inline struct ipc_namespace *copy_ipcs(unsigned long flags, |
| 107 | struct task_struct *tsk) |
| 108 | { |
| 109 | if (flags & CLONE_NEWIPC) |
| 110 | return ERR_PTR(-EINVAL); |
| 111 | |
| 112 | return tsk->nsproxy->ipc_ns; |
| 113 | } |
| 114 | |
| 115 | static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns) |
| 116 | { |
| 117 | return ns; |
| 118 | } |
| 119 | |
| 120 | static inline void put_ipc_ns(struct ipc_namespace *ns) |
| 121 | { |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | #ifdef CONFIG_POSIX_MQUEUE_SYSCTL |
| 126 | |
| 127 | struct ctl_table_header; |
| 128 | extern struct ctl_table_header *mq_register_sysctl_table(void); |
| 129 | |
| 130 | #else |
| 131 | |
| 132 | static inline struct ctl_table_header *mq_register_sysctl_table(void) |
| 133 | { |
| 134 | return NULL; |
| 135 | } |
| 136 | |
| 137 | #endif |
| 138 | #endif |