Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/ipc/util.h | |
3 | * Copyright (C) 1999 Christoph Rohland | |
4 | * | |
624dffcb | 5 | * ipc helper functions (c) 1999 Manfred Spraul <manfred@colorfullife.com> |
73ea4130 KK |
6 | * namespaces support. 2006 OpenVZ, SWsoft Inc. |
7 | * Pavel Emelianov <xemul@openvz.org> | |
1da177e4 LT |
8 | */ |
9 | ||
10 | #ifndef _IPC_UTIL_H | |
11 | #define _IPC_UTIL_H | |
12 | ||
7ca7e564 ND |
13 | #include <linux/idr.h> |
14 | ||
1da177e4 LT |
15 | #define USHRT_MAX 0xffff |
16 | #define SEQ_MULTIPLIER (IPCMNI) | |
17 | ||
18 | void sem_init (void); | |
19 | void msg_init (void); | |
20 | void shm_init (void); | |
21 | ||
73ea4130 KK |
22 | int sem_init_ns(struct ipc_namespace *ns); |
23 | int msg_init_ns(struct ipc_namespace *ns); | |
24 | int shm_init_ns(struct ipc_namespace *ns); | |
25 | ||
26 | void sem_exit_ns(struct ipc_namespace *ns); | |
27 | void msg_exit_ns(struct ipc_namespace *ns); | |
28 | void shm_exit_ns(struct ipc_namespace *ns); | |
29 | ||
1da177e4 LT |
30 | struct ipc_ids { |
31 | int in_use; | |
1da177e4 LT |
32 | unsigned short seq; |
33 | unsigned short seq_max; | |
5f921ae9 | 34 | struct mutex mutex; |
7ca7e564 | 35 | struct idr ipcs_idr; |
1da177e4 LT |
36 | }; |
37 | ||
ae781774 | 38 | struct seq_file; |
7d69a1f4 | 39 | |
7ca7e564 | 40 | void ipc_init_ids(struct ipc_ids *); |
ae781774 MW |
41 | #ifdef CONFIG_PROC_FS |
42 | void __init ipc_init_proc_interface(const char *path, const char *header, | |
73ea4130 | 43 | int ids, int (*show)(struct seq_file *, void *)); |
ae781774 MW |
44 | #else |
45 | #define ipc_init_proc_interface(path, header, ids, show) do {} while (0) | |
46 | #endif | |
1da177e4 | 47 | |
73ea4130 KK |
48 | #define IPC_SEM_IDS 0 |
49 | #define IPC_MSG_IDS 1 | |
50 | #define IPC_SHM_IDS 2 | |
51 | ||
5f921ae9 | 52 | /* must be called with ids->mutex acquired.*/ |
7ca7e564 ND |
53 | struct kern_ipc_perm *ipc_findkey(struct ipc_ids *ids, key_t key); |
54 | int ipc_addid(struct ipc_ids *, struct kern_ipc_perm *, int); | |
55 | int ipc_get_maxid(struct ipc_ids *); | |
1da177e4 LT |
56 | |
57 | /* must be called with both locks acquired. */ | |
7ca7e564 | 58 | void ipc_rmid(struct ipc_ids *, struct kern_ipc_perm *); |
1da177e4 LT |
59 | |
60 | int ipcperms (struct kern_ipc_perm *ipcp, short flg); | |
61 | ||
62 | /* for rare, potentially huge allocations. | |
63 | * both function can sleep | |
64 | */ | |
65 | void* ipc_alloc(int size); | |
66 | void ipc_free(void* ptr, int size); | |
67 | ||
68 | /* | |
69 | * For allocation that need to be freed by RCU. | |
70 | * Objects are reference counted, they start with reference count 1. | |
71 | * getref increases the refcount, the putref call that reduces the recount | |
72 | * to 0 schedules the rcu destruction. Caller must guarantee locking. | |
73 | */ | |
74 | void* ipc_rcu_alloc(int size); | |
75 | void ipc_rcu_getref(void *ptr); | |
76 | void ipc_rcu_putref(void *ptr); | |
77 | ||
78 | struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id); | |
79 | struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id); | |
80 | void ipc_lock_by_ptr(struct kern_ipc_perm *ipcp); | |
81 | void ipc_unlock(struct kern_ipc_perm* perm); | |
82 | int ipc_buildid(struct ipc_ids* ids, int id, int seq); | |
83 | int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid); | |
84 | ||
85 | void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out); | |
86 | void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out); | |
87 | ||
813e6783 | 88 | #if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__) |
1da177e4 LT |
89 | /* On IA-64, we always use the "64-bit version" of the IPC structures. */ |
90 | # define ipc_parse_version(cmd) IPC_64 | |
91 | #else | |
92 | int ipc_parse_version (int *cmd); | |
93 | #endif | |
94 | ||
95 | extern void free_msg(struct msg_msg *msg); | |
96 | extern struct msg_msg *load_msg(const void __user *src, int len); | |
97 | extern int store_msg(void __user *dest, struct msg_msg *msg, int len); | |
98 | ||
99 | #endif |