| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * linux/ipc/util.h | 
|  | 3 | * Copyright (C) 1999 Christoph Rohland | 
|  | 4 | * | 
| Christian Kujau | 624dffc | 2006-01-15 02:43:54 +0100 | [diff] [blame] | 5 | * ipc helper functions (c) 1999 Manfred Spraul <manfred@colorfullife.com> | 
| Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 6 | * namespaces support.      2006 OpenVZ, SWsoft Inc. | 
|  | 7 | *                               Pavel Emelianov <xemul@openvz.org> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ | 
|  | 9 |  | 
|  | 10 | #ifndef _IPC_UTIL_H | 
|  | 11 | #define _IPC_UTIL_H | 
|  | 12 |  | 
|  | 13 | #define USHRT_MAX 0xffff | 
|  | 14 | #define SEQ_MULTIPLIER	(IPCMNI) | 
|  | 15 |  | 
|  | 16 | void sem_init (void); | 
|  | 17 | void msg_init (void); | 
|  | 18 | void shm_init (void); | 
|  | 19 |  | 
| Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 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); | 
|  | 23 |  | 
|  | 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); | 
|  | 27 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | struct ipc_id_ary { | 
|  | 29 | int size; | 
|  | 30 | struct kern_ipc_perm *p[0]; | 
|  | 31 | }; | 
|  | 32 |  | 
|  | 33 | struct ipc_ids { | 
|  | 34 | int in_use; | 
|  | 35 | int max_id; | 
|  | 36 | unsigned short seq; | 
|  | 37 | unsigned short seq_max; | 
| Ingo Molnar | 5f921ae | 2006-03-26 01:37:17 -0800 | [diff] [blame] | 38 | struct mutex mutex; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | struct ipc_id_ary nullentry; | 
|  | 40 | struct ipc_id_ary* entries; | 
|  | 41 | }; | 
|  | 42 |  | 
| Mike Waychison | ae78177 | 2005-09-06 15:17:09 -0700 | [diff] [blame] | 43 | struct seq_file; | 
| Cedric Le Goater | 7d69a1f | 2007-07-15 23:40:58 -0700 | [diff] [blame] | 44 |  | 
|  | 45 | void ipc_init_ids(struct ipc_ids *ids, int size); | 
| Mike Waychison | ae78177 | 2005-09-06 15:17:09 -0700 | [diff] [blame] | 46 | #ifdef CONFIG_PROC_FS | 
|  | 47 | void __init ipc_init_proc_interface(const char *path, const char *header, | 
| Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 48 | int ids, int (*show)(struct seq_file *, void *)); | 
| Mike Waychison | ae78177 | 2005-09-06 15:17:09 -0700 | [diff] [blame] | 49 | #else | 
|  | 50 | #define ipc_init_proc_interface(path, header, ids, show) do {} while (0) | 
|  | 51 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 |  | 
| Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 53 | #define IPC_SEM_IDS	0 | 
|  | 54 | #define IPC_MSG_IDS	1 | 
|  | 55 | #define IPC_SHM_IDS	2 | 
|  | 56 |  | 
| Ingo Molnar | 5f921ae | 2006-03-26 01:37:17 -0800 | [diff] [blame] | 57 | /* must be called with ids->mutex acquired.*/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | int ipc_findkey(struct ipc_ids* ids, key_t key); | 
|  | 59 | int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size); | 
|  | 60 |  | 
|  | 61 | /* must be called with both locks acquired. */ | 
|  | 62 | struct kern_ipc_perm* ipc_rmid(struct ipc_ids* ids, int id); | 
|  | 63 |  | 
|  | 64 | int ipcperms (struct kern_ipc_perm *ipcp, short flg); | 
|  | 65 |  | 
|  | 66 | /* for rare, potentially huge allocations. | 
|  | 67 | * both function can sleep | 
|  | 68 | */ | 
|  | 69 | void* ipc_alloc(int size); | 
|  | 70 | void ipc_free(void* ptr, int size); | 
|  | 71 |  | 
|  | 72 | /* | 
|  | 73 | * For allocation that need to be freed by RCU. | 
|  | 74 | * Objects are reference counted, they start with reference count 1. | 
|  | 75 | * getref increases the refcount, the putref call that reduces the recount | 
|  | 76 | * to 0 schedules the rcu destruction. Caller must guarantee locking. | 
|  | 77 | */ | 
|  | 78 | void* ipc_rcu_alloc(int size); | 
|  | 79 | void ipc_rcu_getref(void *ptr); | 
|  | 80 | void ipc_rcu_putref(void *ptr); | 
|  | 81 |  | 
| Pavel Emelianov | c7e12b8 | 2006-11-02 22:07:03 -0800 | [diff] [blame] | 82 | static inline void __ipc_fini_ids(struct ipc_ids *ids, | 
|  | 83 | struct ipc_id_ary *entries) | 
|  | 84 | { | 
|  | 85 | if (entries != &ids->nullentry) | 
|  | 86 | ipc_rcu_putref(entries); | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | static inline void ipc_fini_ids(struct ipc_ids *ids) | 
|  | 90 | { | 
|  | 91 | __ipc_fini_ids(ids, ids->entries); | 
|  | 92 | } | 
|  | 93 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id); | 
|  | 95 | struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id); | 
|  | 96 | void ipc_lock_by_ptr(struct kern_ipc_perm *ipcp); | 
|  | 97 | void ipc_unlock(struct kern_ipc_perm* perm); | 
|  | 98 | int ipc_buildid(struct ipc_ids* ids, int id, int seq); | 
|  | 99 | int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid); | 
|  | 100 |  | 
|  | 101 | void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out); | 
|  | 102 | void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out); | 
|  | 103 |  | 
| Chris Zankel | 813e678 | 2005-07-12 13:58:25 -0700 | [diff] [blame] | 104 | #if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | /* On IA-64, we always use the "64-bit version" of the IPC structures.  */ | 
|  | 106 | # define ipc_parse_version(cmd)	IPC_64 | 
|  | 107 | #else | 
|  | 108 | int ipc_parse_version (int *cmd); | 
|  | 109 | #endif | 
|  | 110 |  | 
|  | 111 | extern void free_msg(struct msg_msg *msg); | 
|  | 112 | extern struct msg_msg *load_msg(const void __user *src, int len); | 
|  | 113 | extern int store_msg(void __user *dest, struct msg_msg *msg, int len); | 
|  | 114 |  | 
|  | 115 | #endif |