3 * Copyright (C) 1999 Christoph Rohland
5 * ipc helper functions (c) 1999 Manfred Spraul <manfreds@colorfullife.com>
8 #define USHRT_MAX 0xffff
9 #define SEQ_MULTIPLIER (IPCMNI)
20 unsigned short seq_max;
23 struct ipc_id* entries;
27 struct kern_ipc_perm* p;
31 void __init ipc_init_ids(struct ipc_ids* ids, int size);
33 /* must be called with ids->sem acquired.*/
34 int ipc_findkey(struct ipc_ids* ids, key_t key);
35 int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size);
37 /* must be called with both locks acquired. */
38 struct kern_ipc_perm* ipc_rmid(struct ipc_ids* ids, int id);
40 int ipcperms (struct kern_ipc_perm *ipcp, short flg);
42 /* for rare, potentially huge allocations.
43 * both function can sleep
45 void* ipc_alloc(int size);
46 void ipc_free(void* ptr, int size);
48 extern inline void ipc_lockall(struct ipc_ids* ids)
53 extern inline struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id)
55 struct kern_ipc_perm* out;
56 int lid = id % SEQ_MULTIPLIER;
60 out = ids->entries[lid].p;
64 extern inline void ipc_unlockall(struct ipc_ids* ids)
66 spin_unlock(&ids->ary);
68 extern inline struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)
70 struct kern_ipc_perm* out;
71 int lid = id % SEQ_MULTIPLIER;
76 out = ids->entries[lid].p;
78 spin_unlock(&ids->ary);
82 extern inline void ipc_unlock(struct ipc_ids* ids, int id)
84 spin_unlock(&ids->ary);
87 extern inline int ipc_buildid(struct ipc_ids* ids, int id, int seq)
89 return SEQ_MULTIPLIER*seq + id;
92 extern inline int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid)
94 if(uid/SEQ_MULTIPLIER != ipcp->seq)
99 void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
100 void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out);
102 #if defined(__ia64__) || defined(__hppa__)
103 /* On IA-64 and PA-RISC, we always use the "64-bit version" of the IPC structures. */
104 # define ipc_parse_version(cmd) IPC_64
106 int ipc_parse_version (int *cmd);