diff options
Diffstat (limited to 'ipc/util.h')
-rw-r--r-- | ipc/util.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/ipc/util.h b/ipc/util.h new file mode 100644 index 000000000000..07d689452363 --- /dev/null +++ b/ipc/util.h | |||
@@ -0,0 +1,81 @@ | |||
1 | /* | ||
2 | * linux/ipc/util.h | ||
3 | * Copyright (C) 1999 Christoph Rohland | ||
4 | * | ||
5 | * ipc helper functions (c) 1999 Manfred Spraul <manfreds@colorfullife.com> | ||
6 | */ | ||
7 | |||
8 | #ifndef _IPC_UTIL_H | ||
9 | #define _IPC_UTIL_H | ||
10 | |||
11 | #define USHRT_MAX 0xffff | ||
12 | #define SEQ_MULTIPLIER (IPCMNI) | ||
13 | |||
14 | void sem_init (void); | ||
15 | void msg_init (void); | ||
16 | void shm_init (void); | ||
17 | |||
18 | struct ipc_id_ary { | ||
19 | int size; | ||
20 | struct kern_ipc_perm *p[0]; | ||
21 | }; | ||
22 | |||
23 | struct ipc_ids { | ||
24 | int in_use; | ||
25 | int max_id; | ||
26 | unsigned short seq; | ||
27 | unsigned short seq_max; | ||
28 | struct semaphore sem; | ||
29 | struct ipc_id_ary nullentry; | ||
30 | struct ipc_id_ary* entries; | ||
31 | }; | ||
32 | |||
33 | void __init ipc_init_ids(struct ipc_ids* ids, int size); | ||
34 | |||
35 | /* must be called with ids->sem acquired.*/ | ||
36 | int ipc_findkey(struct ipc_ids* ids, key_t key); | ||
37 | int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size); | ||
38 | |||
39 | /* must be called with both locks acquired. */ | ||
40 | struct kern_ipc_perm* ipc_rmid(struct ipc_ids* ids, int id); | ||
41 | |||
42 | int ipcperms (struct kern_ipc_perm *ipcp, short flg); | ||
43 | |||
44 | /* for rare, potentially huge allocations. | ||
45 | * both function can sleep | ||
46 | */ | ||
47 | void* ipc_alloc(int size); | ||
48 | void ipc_free(void* ptr, int size); | ||
49 | |||
50 | /* | ||
51 | * For allocation that need to be freed by RCU. | ||
52 | * Objects are reference counted, they start with reference count 1. | ||
53 | * getref increases the refcount, the putref call that reduces the recount | ||
54 | * to 0 schedules the rcu destruction. Caller must guarantee locking. | ||
55 | */ | ||
56 | void* ipc_rcu_alloc(int size); | ||
57 | void ipc_rcu_getref(void *ptr); | ||
58 | void ipc_rcu_putref(void *ptr); | ||
59 | |||
60 | struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id); | ||
61 | struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id); | ||
62 | void ipc_lock_by_ptr(struct kern_ipc_perm *ipcp); | ||
63 | void ipc_unlock(struct kern_ipc_perm* perm); | ||
64 | int ipc_buildid(struct ipc_ids* ids, int id, int seq); | ||
65 | int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid); | ||
66 | |||
67 | void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out); | ||
68 | void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out); | ||
69 | |||
70 | #if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) | ||
71 | /* On IA-64, we always use the "64-bit version" of the IPC structures. */ | ||
72 | # define ipc_parse_version(cmd) IPC_64 | ||
73 | #else | ||
74 | int ipc_parse_version (int *cmd); | ||
75 | #endif | ||
76 | |||
77 | extern void free_msg(struct msg_msg *msg); | ||
78 | extern struct msg_msg *load_msg(const void __user *src, int len); | ||
79 | extern int store_msg(void __user *dest, struct msg_msg *msg, int len); | ||
80 | |||
81 | #endif | ||