3 * Copyright (C) 1999 Christoph Rohland
5 * ipc helper functions (c) 1999 Manfred Spraul <manfred@colorfullife.com>
6 * namespaces support. 2006 OpenVZ, SWsoft Inc.
7 * Pavel Emelianov <xemul@openvz.org>
13 #include <linux/idr.h>
14 #include <linux/err.h>
16 #define USHRT_MAX 0xffff
17 #define SEQ_MULTIPLIER (IPCMNI)
25 int sem_init_ns(struct ipc_namespace
*ns
);
26 int msg_init_ns(struct ipc_namespace
*ns
);
27 int shm_init_ns(struct ipc_namespace
*ns
);
29 void sem_exit_ns(struct ipc_namespace
*ns
);
30 void msg_exit_ns(struct ipc_namespace
*ns
);
31 void shm_exit_ns(struct ipc_namespace
*ns
);
36 unsigned short seq_max
;
37 struct rw_semaphore rw_mutex
;
42 * Structure that holds the parameters needed by the ipc operations
49 size_t size
; /* for shared memories */
50 int nsems
; /* for semaphores */
51 } u
; /* holds the getnew() specific param */
55 * Structure that holds some ipc operations. This structure is used to unify
56 * the calls to sys_msgget(), sys_semget(), sys_shmget()
57 * . routine to call to create a new ipc object. Can be one of newque,
59 * . routine to call to check permissions for a new ipc object.
60 * Can be one of security_msg_associate, security_sem_associate,
61 * security_shm_associate
62 * . routine to call for an extra check if needed
65 int (*getnew
) (struct ipc_namespace
*, struct ipc_params
*);
66 int (*associate
) (struct kern_ipc_perm
*, int);
67 int (*more_checks
) (struct kern_ipc_perm
*, struct ipc_params
*);
72 void ipc_init_ids(struct ipc_ids
*);
74 void __init
ipc_init_proc_interface(const char *path
, const char *header
,
75 int ids
, int (*show
)(struct seq_file
*, void *));
77 #define ipc_init_proc_interface(path, header, ids, show) do {} while (0)
84 #define ipcid_to_idx(id) ((id) % SEQ_MULTIPLIER)
86 /* must be called with ids->rw_mutex acquired for writing */
87 int ipc_addid(struct ipc_ids
*, struct kern_ipc_perm
*, int);
89 /* must be called with ids->rw_mutex acquired for reading */
90 int ipc_get_maxid(struct ipc_ids
*);
92 /* must be called with both locks acquired. */
93 void ipc_rmid(struct ipc_ids
*, struct kern_ipc_perm
*);
95 /* must be called with ipcp locked */
96 int ipcperms(struct kern_ipc_perm
*ipcp
, short flg
);
98 /* for rare, potentially huge allocations.
99 * both function can sleep
101 void* ipc_alloc(int size
);
102 void ipc_free(void* ptr
, int size
);
105 * For allocation that need to be freed by RCU.
106 * Objects are reference counted, they start with reference count 1.
107 * getref increases the refcount, the putref call that reduces the recount
108 * to 0 schedules the rcu destruction. Caller must guarantee locking.
110 void* ipc_rcu_alloc(int size
);
111 void ipc_rcu_getref(void *ptr
);
112 void ipc_rcu_putref(void *ptr
);
115 * ipc_lock_down: called with rw_mutex held
116 * ipc_lock: called without that lock held
118 struct kern_ipc_perm
*ipc_lock_down(struct ipc_ids
*, int);
119 struct kern_ipc_perm
*ipc_lock(struct ipc_ids
*, int);
121 void kernel_to_ipc64_perm(struct kern_ipc_perm
*in
, struct ipc64_perm
*out
);
122 void ipc64_perm_to_ipc_perm(struct ipc64_perm
*in
, struct ipc_perm
*out
);
124 #if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__)
125 /* On IA-64, we always use the "64-bit version" of the IPC structures. */
126 # define ipc_parse_version(cmd) IPC_64
128 int ipc_parse_version (int *cmd
);
131 extern void free_msg(struct msg_msg
*msg
);
132 extern struct msg_msg
*load_msg(const void __user
*src
, int len
);
133 extern int store_msg(void __user
*dest
, struct msg_msg
*msg
, int len
);
135 static inline int ipc_buildid(int id
, int seq
)
137 return SEQ_MULTIPLIER
* seq
+ id
;
141 * Must be called with ipcp locked
143 static inline int ipc_checkid(struct kern_ipc_perm
*ipcp
, int uid
)
145 if (uid
/ SEQ_MULTIPLIER
!= ipcp
->seq
)
150 static inline void ipc_lock_by_ptr(struct kern_ipc_perm
*perm
)
153 spin_lock(&perm
->lock
);
156 static inline void ipc_unlock(struct kern_ipc_perm
*perm
)
158 spin_unlock(&perm
->lock
);
162 struct kern_ipc_perm
*ipc_lock_check_down(struct ipc_ids
*ids
, int id
);
163 struct kern_ipc_perm
*ipc_lock_check(struct ipc_ids
*ids
, int id
);
164 int ipcget(struct ipc_namespace
*ns
, struct ipc_ids
*ids
,
165 struct ipc_ops
*ops
, struct ipc_params
*params
);
This page took 0.033432 seconds and 5 git commands to generate.