Blame view
ipc/util.h
5.95 KB
1da177e4c
|
1 2 3 4 |
/* * linux/ipc/util.h * Copyright (C) 1999 Christoph Rohland * |
624dffcbc
|
5 |
* ipc helper functions (c) 1999 Manfred Spraul <manfred@colorfullife.com> |
73ea41302
|
6 7 |
* namespaces support. 2006 OpenVZ, SWsoft Inc. * Pavel Emelianov <xemul@openvz.org> |
1da177e4c
|
8 9 10 11 |
*/ #ifndef _IPC_UTIL_H #define _IPC_UTIL_H |
232086b19
|
12 |
#include <linux/unistd.h> |
023a53557
|
13 |
#include <linux/err.h> |
7ca7e564e
|
14 |
|
1da177e4c
|
15 16 17 18 19 |
#define SEQ_MULTIPLIER (IPCMNI) void sem_init (void); void msg_init (void); void shm_init (void); |
ae5e1b22f
|
20 |
struct ipc_namespace; |
614b84cf4
|
21 |
#ifdef CONFIG_POSIX_MQUEUE |
7eafd7c74
|
22 23 |
extern void mq_clear_sbinfo(struct ipc_namespace *ns); extern void mq_put_mnt(struct ipc_namespace *ns); |
614b84cf4
|
24 |
#else |
7eafd7c74
|
25 26 |
static inline void mq_clear_sbinfo(struct ipc_namespace *ns) { } static inline void mq_put_mnt(struct ipc_namespace *ns) { } |
614b84cf4
|
27 28 29 |
#endif #ifdef CONFIG_SYSVIPC |
ed2ddbf88
|
30 31 32 |
void sem_init_ns(struct ipc_namespace *ns); void msg_init_ns(struct ipc_namespace *ns); void shm_init_ns(struct ipc_namespace *ns); |
73ea41302
|
33 34 35 36 |
void sem_exit_ns(struct ipc_namespace *ns); void msg_exit_ns(struct ipc_namespace *ns); void shm_exit_ns(struct ipc_namespace *ns); |
614b84cf4
|
37 38 39 40 41 42 43 44 45 |
#else static inline void sem_init_ns(struct ipc_namespace *ns) { } static inline void msg_init_ns(struct ipc_namespace *ns) { } static inline void shm_init_ns(struct ipc_namespace *ns) { } static inline void sem_exit_ns(struct ipc_namespace *ns) { } static inline void msg_exit_ns(struct ipc_namespace *ns) { } static inline void shm_exit_ns(struct ipc_namespace *ns) { } #endif |
73ea41302
|
46 |
|
7748dbfaa
|
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
/* * Structure that holds the parameters needed by the ipc operations * (see after) */ struct ipc_params { key_t key; int flg; union { size_t size; /* for shared memories */ int nsems; /* for semaphores */ } u; /* holds the getnew() specific param */ }; /* * Structure that holds some ipc operations. This structure is used to unify * the calls to sys_msgget(), sys_semget(), sys_shmget() * . routine to call to create a new ipc object. Can be one of newque, * newary, newseg |
f4566f048
|
65 |
* . routine to call to check permissions for a new ipc object. |
7748dbfaa
|
66 67 68 69 70 71 |
* Can be one of security_msg_associate, security_sem_associate, * security_shm_associate * . routine to call for an extra check if needed */ struct ipc_ops { int (*getnew) (struct ipc_namespace *, struct ipc_params *); |
03f02c765
|
72 73 |
int (*associate) (struct kern_ipc_perm *, int); int (*more_checks) (struct kern_ipc_perm *, struct ipc_params *); |
7748dbfaa
|
74 |
}; |
ae7817745
|
75 |
struct seq_file; |
ed2ddbf88
|
76 |
struct ipc_ids; |
7d69a1f4a
|
77 |
|
7ca7e564e
|
78 |
void ipc_init_ids(struct ipc_ids *); |
ae7817745
|
79 80 |
#ifdef CONFIG_PROC_FS void __init ipc_init_proc_interface(const char *path, const char *header, |
73ea41302
|
81 |
int ids, int (*show)(struct seq_file *, void *)); |
ae7817745
|
82 83 84 |
#else #define ipc_init_proc_interface(path, header, ids, show) do {} while (0) #endif |
1da177e4c
|
85 |
|
73ea41302
|
86 87 88 |
#define IPC_SEM_IDS 0 #define IPC_MSG_IDS 1 #define IPC_SHM_IDS 2 |
ce621f5ba
|
89 |
#define ipcid_to_idx(id) ((id) % SEQ_MULTIPLIER) |
03f595668
|
90 |
#define ipcid_to_seqx(id) ((id) / SEQ_MULTIPLIER) |
ce621f5ba
|
91 |
|
3e148c799
|
92 |
/* must be called with ids->rw_mutex acquired for writing */ |
7ca7e564e
|
93 |
int ipc_addid(struct ipc_ids *, struct kern_ipc_perm *, int); |
3e148c799
|
94 95 |
/* must be called with ids->rw_mutex acquired for reading */ |
7ca7e564e
|
96 |
int ipc_get_maxid(struct ipc_ids *); |
1da177e4c
|
97 98 |
/* must be called with both locks acquired. */ |
7ca7e564e
|
99 |
void ipc_rmid(struct ipc_ids *, struct kern_ipc_perm *); |
1da177e4c
|
100 |
|
f4566f048
|
101 |
/* must be called with ipcp locked */ |
b0e77598f
|
102 |
int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flg); |
1da177e4c
|
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
/* for rare, potentially huge allocations. * both function can sleep */ void* ipc_alloc(int size); void ipc_free(void* ptr, int size); /* * For allocation that need to be freed by RCU. * Objects are reference counted, they start with reference count 1. * getref increases the refcount, the putref call that reduces the recount * to 0 schedules the rcu destruction. Caller must guarantee locking. */ void* ipc_rcu_alloc(int size); |
6062a8dc0
|
117 |
int ipc_rcu_getref(void *ptr); |
1da177e4c
|
118 |
void ipc_rcu_putref(void *ptr); |
023a53557
|
119 |
struct kern_ipc_perm *ipc_lock(struct ipc_ids *, int); |
4d2bff5eb
|
120 |
struct kern_ipc_perm *ipc_obtain_object(struct ipc_ids *ids, int id); |
1da177e4c
|
121 122 123 |
void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out); void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out); |
1efdb69b0
|
124 |
int ipc_update_perm(struct ipc64_perm *in, struct kern_ipc_perm *out); |
444d0f621
|
125 126 127 |
struct kern_ipc_perm *ipcctl_pre_down_nolock(struct ipc_namespace *ns, struct ipc_ids *ids, int id, int cmd, struct ipc64_perm *perm, int extra_perm); |
b0e77598f
|
128 129 |
struct kern_ipc_perm *ipcctl_pre_down(struct ipc_namespace *ns, struct ipc_ids *ids, int id, int cmd, |
a5f75e7f2
|
130 |
struct ipc64_perm *perm, int extra_perm); |
1da177e4c
|
131 |
|
c1d7e01d7
|
132 |
#ifndef CONFIG_ARCH_WANT_IPC_PARSE_VERSION |
1da177e4c
|
133 134 135 136 137 138 139 140 |
/* On IA-64, we always use the "64-bit version" of the IPC structures. */ # define ipc_parse_version(cmd) IPC_64 #else int ipc_parse_version (int *cmd); #endif extern void free_msg(struct msg_msg *msg); extern struct msg_msg *load_msg(const void __user *src, int len); |
4a674f34b
|
141 |
extern struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst); |
1da177e4c
|
142 |
extern int store_msg(void __user *dest, struct msg_msg *msg, int len); |
7748dbfaa
|
143 |
|
b6b337ad1
|
144 |
extern void recompute_msgmni(struct ipc_namespace *); |
1b531f213
|
145 |
static inline int ipc_buildid(int id, int seq) |
280283131
|
146 147 148 |
{ return SEQ_MULTIPLIER * seq + id; } |
1b531f213
|
149 |
static inline int ipc_checkid(struct kern_ipc_perm *ipcp, int uid) |
023a53557
|
150 |
{ |
7bb4deff6
|
151 |
return uid / SEQ_MULTIPLIER != ipcp->seq; |
023a53557
|
152 |
} |
1ca7003ab
|
153 |
static inline void ipc_lock_object(struct kern_ipc_perm *perm) |
023a53557
|
154 |
{ |
023a53557
|
155 156 |
spin_lock(&perm->lock); } |
1ca7003ab
|
157 |
static inline void ipc_unlock_object(struct kern_ipc_perm *perm) |
023a53557
|
158 159 |
{ spin_unlock(&perm->lock); |
023a53557
|
160 |
} |
1ca7003ab
|
161 |
static inline void ipc_assert_locked_object(struct kern_ipc_perm *perm) |
16df3674e
|
162 |
{ |
1ca7003ab
|
163 164 165 166 167 168 |
assert_spin_locked(&perm->lock); } static inline void ipc_lock_by_ptr(struct kern_ipc_perm *perm) { rcu_read_lock(); |
cf9d5d78d
|
169 |
ipc_lock_object(perm); |
16df3674e
|
170 |
} |
1ca7003ab
|
171 172 |
static inline void ipc_unlock(struct kern_ipc_perm *perm) { |
cf9d5d78d
|
173 |
ipc_unlock_object(perm); |
1ca7003ab
|
174 175 |
rcu_read_unlock(); } |
b2d75cddc
|
176 |
struct kern_ipc_perm *ipc_lock_check(struct ipc_ids *ids, int id); |
4d2bff5eb
|
177 |
struct kern_ipc_perm *ipc_obtain_object_check(struct ipc_ids *ids, int id); |
b2d75cddc
|
178 179 |
int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids, struct ipc_ops *ops, struct ipc_params *params); |
665c7741f
|
180 181 |
void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids, void (*free)(struct ipc_namespace *, struct kern_ipc_perm *)); |
1da177e4c
|
182 |
#endif |