blob: f6decf817d1ab2c924aa0bd188041f82adfe2e6d [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001#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
16struct user_namespace;
17
18struct 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
26struct 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
63extern struct ipc_namespace init_ipc_ns;
64extern atomic_t nr_ipc_ns;
65
66extern spinlock_t mq_lock;
67
68#ifdef CONFIG_SYSVIPC
69extern int register_ipcns_notifier(struct ipc_namespace *);
70extern int cond_register_ipcns_notifier(struct ipc_namespace *);
71extern void unregister_ipcns_notifier(struct ipc_namespace *);
72extern int ipcns_notify(unsigned long);
73extern void shm_destroy_orphaned(struct ipc_namespace *ns);
74#else
75static inline int register_ipcns_notifier(struct ipc_namespace *ns)
76{ return 0; }
77static inline int cond_register_ipcns_notifier(struct ipc_namespace *ns)
78{ return 0; }
79static inline void unregister_ipcns_notifier(struct ipc_namespace *ns) { }
80static inline int ipcns_notify(unsigned long l) { return 0; }
81static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {}
82#endif
83
84#ifdef CONFIG_POSIX_MQUEUE
85extern 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
91static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }
92#endif
93
94#if defined(CONFIG_IPC_NS)
95extern struct ipc_namespace *copy_ipcs(unsigned long flags,
96 struct task_struct *tsk);
97static 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
104extern void put_ipc_ns(struct ipc_namespace *ns);
105#else
106static 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
115static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
116{
117 return ns;
118}
119
120static inline void put_ipc_ns(struct ipc_namespace *ns)
121{
122}
123#endif
124
125#ifdef CONFIG_POSIX_MQUEUE_SYSCTL
126
127struct ctl_table_header;
128extern struct ctl_table_header *mq_register_sysctl_table(void);
129
130#else
131
132static inline struct ctl_table_header *mq_register_sysctl_table(void)
133{
134 return NULL;
135}
136
137#endif
138#endif