diff options
Diffstat (limited to 'ipc/util.h')
-rw-r--r-- | ipc/util.h | 78 |
1 files changed, 10 insertions, 68 deletions
diff --git a/ipc/util.h b/ipc/util.h index 9ffea40457ce..f37d160c98fe 100644 --- a/ipc/util.h +++ b/ipc/util.h | |||
@@ -10,7 +10,6 @@ | |||
10 | #ifndef _IPC_UTIL_H | 10 | #ifndef _IPC_UTIL_H |
11 | #define _IPC_UTIL_H | 11 | #define _IPC_UTIL_H |
12 | 12 | ||
13 | #include <linux/idr.h> | ||
14 | #include <linux/err.h> | 13 | #include <linux/err.h> |
15 | 14 | ||
16 | #define USHRT_MAX 0xffff | 15 | #define USHRT_MAX 0xffff |
@@ -20,22 +19,16 @@ void sem_init (void); | |||
20 | void msg_init (void); | 19 | void msg_init (void); |
21 | void shm_init (void); | 20 | void shm_init (void); |
22 | 21 | ||
23 | int sem_init_ns(struct ipc_namespace *ns); | 22 | struct ipc_namespace; |
24 | int msg_init_ns(struct ipc_namespace *ns); | 23 | |
25 | int shm_init_ns(struct ipc_namespace *ns); | 24 | void sem_init_ns(struct ipc_namespace *ns); |
25 | void msg_init_ns(struct ipc_namespace *ns); | ||
26 | void shm_init_ns(struct ipc_namespace *ns); | ||
26 | 27 | ||
27 | void sem_exit_ns(struct ipc_namespace *ns); | 28 | void sem_exit_ns(struct ipc_namespace *ns); |
28 | void msg_exit_ns(struct ipc_namespace *ns); | 29 | void msg_exit_ns(struct ipc_namespace *ns); |
29 | void shm_exit_ns(struct ipc_namespace *ns); | 30 | void shm_exit_ns(struct ipc_namespace *ns); |
30 | 31 | ||
31 | struct ipc_ids { | ||
32 | int in_use; | ||
33 | unsigned short seq; | ||
34 | unsigned short seq_max; | ||
35 | struct rw_semaphore rw_mutex; | ||
36 | struct idr ipcs_idr; | ||
37 | }; | ||
38 | |||
39 | /* | 32 | /* |
40 | * Structure that holds the parameters needed by the ipc operations | 33 | * Structure that holds the parameters needed by the ipc operations |
41 | * (see after) | 34 | * (see after) |
@@ -66,6 +59,7 @@ struct ipc_ops { | |||
66 | }; | 59 | }; |
67 | 60 | ||
68 | struct seq_file; | 61 | struct seq_file; |
62 | struct ipc_ids; | ||
69 | 63 | ||
70 | void ipc_init_ids(struct ipc_ids *); | 64 | void ipc_init_ids(struct ipc_ids *); |
71 | #ifdef CONFIG_PROC_FS | 65 | #ifdef CONFIG_PROC_FS |
@@ -129,10 +123,6 @@ int ipc_parse_version (int *cmd); | |||
129 | extern void free_msg(struct msg_msg *msg); | 123 | extern void free_msg(struct msg_msg *msg); |
130 | extern struct msg_msg *load_msg(const void __user *src, int len); | 124 | extern struct msg_msg *load_msg(const void __user *src, int len); |
131 | extern int store_msg(void __user *dest, struct msg_msg *msg, int len); | 125 | extern int store_msg(void __user *dest, struct msg_msg *msg, int len); |
132 | extern int ipcget_new(struct ipc_namespace *, struct ipc_ids *, | ||
133 | struct ipc_ops *, struct ipc_params *); | ||
134 | extern int ipcget_public(struct ipc_namespace *, struct ipc_ids *, | ||
135 | struct ipc_ops *, struct ipc_params *); | ||
136 | 126 | ||
137 | static inline int ipc_buildid(int id, int seq) | 127 | static inline int ipc_buildid(int id, int seq) |
138 | { | 128 | { |
@@ -161,57 +151,9 @@ static inline void ipc_unlock(struct kern_ipc_perm *perm) | |||
161 | rcu_read_unlock(); | 151 | rcu_read_unlock(); |
162 | } | 152 | } |
163 | 153 | ||
164 | static inline struct kern_ipc_perm *ipc_lock_check_down(struct ipc_ids *ids, | 154 | struct kern_ipc_perm *ipc_lock_check_down(struct ipc_ids *ids, int id); |
165 | int id) | 155 | struct kern_ipc_perm *ipc_lock_check(struct ipc_ids *ids, int id); |
166 | { | 156 | int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids, |
167 | struct kern_ipc_perm *out; | 157 | struct ipc_ops *ops, struct ipc_params *params); |
168 | |||
169 | out = ipc_lock_down(ids, id); | ||
170 | if (IS_ERR(out)) | ||
171 | return out; | ||
172 | |||
173 | if (ipc_checkid(out, id)) { | ||
174 | ipc_unlock(out); | ||
175 | return ERR_PTR(-EIDRM); | ||
176 | } | ||
177 | |||
178 | return out; | ||
179 | } | ||
180 | |||
181 | static inline struct kern_ipc_perm *ipc_lock_check(struct ipc_ids *ids, | ||
182 | int id) | ||
183 | { | ||
184 | struct kern_ipc_perm *out; | ||
185 | |||
186 | out = ipc_lock(ids, id); | ||
187 | if (IS_ERR(out)) | ||
188 | return out; | ||
189 | |||
190 | if (ipc_checkid(out, id)) { | ||
191 | ipc_unlock(out); | ||
192 | return ERR_PTR(-EIDRM); | ||
193 | } | ||
194 | |||
195 | return out; | ||
196 | } | ||
197 | |||
198 | /** | ||
199 | * ipcget - Common sys_*get() code | ||
200 | * @ns : namsepace | ||
201 | * @ids : IPC identifier set | ||
202 | * @ops : operations to be called on ipc object creation, permission checks | ||
203 | * and further checks | ||
204 | * @params : the parameters needed by the previous operations. | ||
205 | * | ||
206 | * Common routine called by sys_msgget(), sys_semget() and sys_shmget(). | ||
207 | */ | ||
208 | static inline int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids, | ||
209 | struct ipc_ops *ops, struct ipc_params *params) | ||
210 | { | ||
211 | if (params->key == IPC_PRIVATE) | ||
212 | return ipcget_new(ns, ids, ops, params); | ||
213 | else | ||
214 | return ipcget_public(ns, ids, ops, params); | ||
215 | } | ||
216 | 158 | ||
217 | #endif | 159 | #endif |