RHEL4/ipc/util.h
<<
>>
Prefs
   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
  14void sem_init (void);
  15void msg_init (void);
  16void shm_init (void);
  17
  18struct ipc_ids {
  19        int size;
  20        int in_use;
  21        int max_id;
  22        unsigned short seq;
  23        unsigned short seq_max;
  24        struct semaphore sem;   
  25        struct ipc_id* entries;
  26};
  27
  28struct ipc_id {
  29        struct kern_ipc_perm* p;
  30};
  31
  32void __init ipc_init_ids(struct ipc_ids* ids, int size);
  33
  34/* must be called with ids->sem acquired.*/
  35int ipc_findkey(struct ipc_ids* ids, key_t key);
  36int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size);
  37
  38/* must be called with both locks acquired. */
  39struct kern_ipc_perm* ipc_rmid(struct ipc_ids* ids, int id);
  40
  41int ipcperms (struct kern_ipc_perm *ipcp, short flg);
  42
  43/* for rare, potentially huge allocations.
  44 * both function can sleep
  45 */
  46void* ipc_alloc(int size);
  47void ipc_free(void* ptr, int size);
  48
  49/*
  50 * For allocation that need to be freed by RCU.
  51 * Objects are reference counted, they start with reference count 1.
  52 * getref increases the refcount, the putref call that reduces the recount
  53 * to 0 schedules the rcu destruction. Caller must guarantee locking.
  54 */
  55void* ipc_rcu_alloc(int size);
  56void ipc_rcu_getref(void *ptr);
  57void ipc_rcu_putref(void *ptr);
  58
  59struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id);
  60struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id);
  61void ipc_lock_by_ptr(struct kern_ipc_perm *ipcp);
  62void ipc_unlock(struct kern_ipc_perm* perm);
  63int ipc_buildid(struct ipc_ids* ids, int id, int seq);
  64int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid);
  65
  66void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
  67void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out);
  68
  69#if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__)
  70  /* On IA-64, we always use the "64-bit version" of the IPC structures.  */ 
  71# define ipc_parse_version(cmd) IPC_64
  72#else
  73int ipc_parse_version (int *cmd);
  74#endif
  75
  76extern void free_msg(struct msg_msg *msg);
  77extern struct msg_msg *load_msg(const void __user *src, int len);
  78extern int store_msg(void __user *dest, struct msg_msg *msg, int len);
  79
  80#endif
  81