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 #define USHRT_MAX 0xffff
14 #define SEQ_MULTIPLIER (IPCMNI)
20 int sem_init_ns(struct ipc_namespace
*ns
);
21 int msg_init_ns(struct ipc_namespace
*ns
);
22 int shm_init_ns(struct ipc_namespace
*ns
);
24 void sem_exit_ns(struct ipc_namespace
*ns
);
25 void msg_exit_ns(struct ipc_namespace
*ns
);
26 void shm_exit_ns(struct ipc_namespace
*ns
);
30 struct kern_ipc_perm
*p
[0];
37 unsigned short seq_max
;
39 struct ipc_id_ary nullentry
;
40 struct ipc_id_ary
* entries
;
47 #define __ipc_init __init
49 void __ipc_init
ipc_init_ids(struct ipc_ids
*ids
, int size
);
51 void __init
ipc_init_proc_interface(const char *path
, const char *header
,
52 int ids
, int (*show
)(struct seq_file
*, void *));
54 #define ipc_init_proc_interface(path, header, ids, show) do {} while (0)
61 /* must be called with ids->mutex acquired.*/
62 int ipc_findkey(struct ipc_ids
* ids
, key_t key
);
63 int ipc_addid(struct ipc_ids
* ids
, struct kern_ipc_perm
* new, int size
);
65 /* must be called with both locks acquired. */
66 struct kern_ipc_perm
* ipc_rmid(struct ipc_ids
* ids
, int id
);
68 int ipcperms (struct kern_ipc_perm
*ipcp
, short flg
);
70 /* for rare, potentially huge allocations.
71 * both function can sleep
73 void* ipc_alloc(int size
);
74 void ipc_free(void* ptr
, int size
);
77 * For allocation that need to be freed by RCU.
78 * Objects are reference counted, they start with reference count 1.
79 * getref increases the refcount, the putref call that reduces the recount
80 * to 0 schedules the rcu destruction. Caller must guarantee locking.
82 void* ipc_rcu_alloc(int size
);
83 void ipc_rcu_getref(void *ptr
);
84 void ipc_rcu_putref(void *ptr
);
86 static inline void __ipc_fini_ids(struct ipc_ids
*ids
,
87 struct ipc_id_ary
*entries
)
89 if (entries
!= &ids
->nullentry
)
90 ipc_rcu_putref(entries
);
93 static inline void ipc_fini_ids(struct ipc_ids
*ids
)
95 __ipc_fini_ids(ids
, ids
->entries
);
98 struct kern_ipc_perm
* ipc_get(struct ipc_ids
* ids
, int id
);
99 struct kern_ipc_perm
* ipc_lock(struct ipc_ids
* ids
, int id
);
100 void ipc_lock_by_ptr(struct kern_ipc_perm
*ipcp
);
101 void ipc_unlock(struct kern_ipc_perm
* perm
);
102 int ipc_buildid(struct ipc_ids
* ids
, int id
, int seq
);
103 int ipc_checkid(struct ipc_ids
* ids
, struct kern_ipc_perm
* ipcp
, int uid
);
105 void kernel_to_ipc64_perm(struct kern_ipc_perm
*in
, struct ipc64_perm
*out
);
106 void ipc64_perm_to_ipc_perm(struct ipc64_perm
*in
, struct ipc_perm
*out
);
108 #if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__)
109 /* On IA-64, we always use the "64-bit version" of the IPC structures. */
110 # define ipc_parse_version(cmd) IPC_64
112 int ipc_parse_version (int *cmd
);
115 extern void free_msg(struct msg_msg
*msg
);
116 extern struct msg_msg
*load_msg(const void __user
*src
, int len
);
117 extern int store_msg(void __user
*dest
, struct msg_msg
*msg
, int len
);