blob: efaff3ee7de7c30b678fa686f88442aaa0aaeac4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/ipc/util.h
3 * Copyright (C) 1999 Christoph Rohland
4 *
Christian Kujau624dffc2006-01-15 02:43:54 +01005 * ipc helper functions (c) 1999 Manfred Spraul <manfred@colorfullife.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8#ifndef _IPC_UTIL_H
9#define _IPC_UTIL_H
10
11#define USHRT_MAX 0xffff
12#define SEQ_MULTIPLIER (IPCMNI)
13
14void sem_init (void);
15void msg_init (void);
16void shm_init (void);
17
18struct ipc_id_ary {
19 int size;
20 struct kern_ipc_perm *p[0];
21};
22
23struct 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
Mike Waychisonae781772005-09-06 15:17:09 -070033struct seq_file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034void __init ipc_init_ids(struct ipc_ids* ids, int size);
Mike Waychisonae781772005-09-06 15:17:09 -070035#ifdef CONFIG_PROC_FS
36void __init ipc_init_proc_interface(const char *path, const char *header,
37 struct ipc_ids *ids,
38 int (*show)(struct seq_file *, void *));
39#else
40#define ipc_init_proc_interface(path, header, ids, show) do {} while (0)
41#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* must be called with ids->sem acquired.*/
44int ipc_findkey(struct ipc_ids* ids, key_t key);
45int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size);
46
47/* must be called with both locks acquired. */
48struct kern_ipc_perm* ipc_rmid(struct ipc_ids* ids, int id);
49
50int ipcperms (struct kern_ipc_perm *ipcp, short flg);
51
52/* for rare, potentially huge allocations.
53 * both function can sleep
54 */
55void* ipc_alloc(int size);
56void ipc_free(void* ptr, int size);
57
58/*
59 * For allocation that need to be freed by RCU.
60 * Objects are reference counted, they start with reference count 1.
61 * getref increases the refcount, the putref call that reduces the recount
62 * to 0 schedules the rcu destruction. Caller must guarantee locking.
63 */
64void* ipc_rcu_alloc(int size);
65void ipc_rcu_getref(void *ptr);
66void ipc_rcu_putref(void *ptr);
67
68struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id);
69struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id);
70void ipc_lock_by_ptr(struct kern_ipc_perm *ipcp);
71void ipc_unlock(struct kern_ipc_perm* perm);
72int ipc_buildid(struct ipc_ids* ids, int id, int seq);
73int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid);
74
75void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
76void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out);
77
Chris Zankel813e6782005-07-12 13:58:25 -070078#if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /* On IA-64, we always use the "64-bit version" of the IPC structures. */
80# define ipc_parse_version(cmd) IPC_64
81#else
82int ipc_parse_version (int *cmd);
83#endif
84
85extern void free_msg(struct msg_msg *msg);
86extern struct msg_msg *load_msg(const void __user *src, int len);
87extern int store_msg(void __user *dest, struct msg_msg *msg, int len);
88
89#endif