aboutsummaryrefslogtreecommitdiffstats
path: root/ipc/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'ipc/util.h')
-rw-r--r--ipc/util.h78
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);
20void msg_init (void); 19void msg_init (void);
21void shm_init (void); 20void shm_init (void);
22 21
23int sem_init_ns(struct ipc_namespace *ns); 22struct ipc_namespace;
24int msg_init_ns(struct ipc_namespace *ns); 23
25int shm_init_ns(struct ipc_namespace *ns); 24void sem_init_ns(struct ipc_namespace *ns);
25void msg_init_ns(struct ipc_namespace *ns);
26void shm_init_ns(struct ipc_namespace *ns);
26 27
27void sem_exit_ns(struct ipc_namespace *ns); 28void sem_exit_ns(struct ipc_namespace *ns);
28void msg_exit_ns(struct ipc_namespace *ns); 29void msg_exit_ns(struct ipc_namespace *ns);
29void shm_exit_ns(struct ipc_namespace *ns); 30void shm_exit_ns(struct ipc_namespace *ns);
30 31
31struct 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
68struct seq_file; 61struct seq_file;
62struct ipc_ids;
69 63
70void ipc_init_ids(struct ipc_ids *); 64void 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);
129extern void free_msg(struct msg_msg *msg); 123extern void free_msg(struct msg_msg *msg);
130extern struct msg_msg *load_msg(const void __user *src, int len); 124extern struct msg_msg *load_msg(const void __user *src, int len);
131extern int store_msg(void __user *dest, struct msg_msg *msg, int len); 125extern int store_msg(void __user *dest, struct msg_msg *msg, int len);
132extern int ipcget_new(struct ipc_namespace *, struct ipc_ids *,
133 struct ipc_ops *, struct ipc_params *);
134extern int ipcget_public(struct ipc_namespace *, struct ipc_ids *,
135 struct ipc_ops *, struct ipc_params *);
136 126
137static inline int ipc_buildid(int id, int seq) 127static 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
164static inline struct kern_ipc_perm *ipc_lock_check_down(struct ipc_ids *ids, 154struct kern_ipc_perm *ipc_lock_check_down(struct ipc_ids *ids, int id);
165 int id) 155struct kern_ipc_perm *ipc_lock_check(struct ipc_ids *ids, int id);
166{ 156int 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
181static 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 */
208static 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