linux-old/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#define USHRT_MAX 0xffff
   9#define SEQ_MULTIPLIER  (IPCMNI)
  10
  11void sem_init (void);
  12void msg_init (void);
  13void shm_init (void);
  14
  15struct ipc_ids {
  16        int size;
  17        int in_use;
  18        int max_id;
  19        unsigned short seq;
  20        unsigned short seq_max;
  21        struct semaphore sem;   
  22        spinlock_t ary;
  23        struct ipc_id* entries;
  24};
  25
  26struct ipc_id {
  27        struct kern_ipc_perm* p;
  28};
  29
  30
  31void __init ipc_init_ids(struct ipc_ids* ids, int size);
  32
  33/* must be called with ids->sem acquired.*/
  34int ipc_findkey(struct ipc_ids* ids, key_t key);
  35int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size);
  36
  37/* must be called with both locks acquired. */
  38struct kern_ipc_perm* ipc_rmid(struct ipc_ids* ids, int id);
  39
  40int ipcperms (struct kern_ipc_perm *ipcp, short flg);
  41
  42/* for rare, potentially huge allocations.
  43 * both function can sleep
  44 */
  45void* ipc_alloc(int size);
  46void ipc_free(void* ptr, int size);
  47
  48extern inline void ipc_lockall(struct ipc_ids* ids)
  49{
  50        spin_lock(&ids->ary);
  51}
  52
  53extern inline struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id)
  54{
  55        struct kern_ipc_perm* out;
  56        int lid = id % SEQ_MULTIPLIER;
  57        if(lid >= ids->size)
  58                return NULL;
  59
  60        out = ids->entries[lid].p;
  61        return out;
  62}
  63
  64extern inline void ipc_unlockall(struct ipc_ids* ids)
  65{
  66        spin_unlock(&ids->ary);
  67}
  68extern inline struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)
  69{
  70        struct kern_ipc_perm* out;
  71        int lid = id % SEQ_MULTIPLIER;
  72        if(lid >= ids->size)
  73                return NULL;
  74
  75        spin_lock(&ids->ary);
  76        out = ids->entries[lid].p;
  77        if(out==NULL)
  78                spin_unlock(&ids->ary);
  79        return out;
  80}
  81
  82extern inline void ipc_unlock(struct ipc_ids* ids, int id)
  83{
  84        spin_unlock(&ids->ary);
  85}
  86
  87extern inline int ipc_buildid(struct ipc_ids* ids, int id, int seq)
  88{
  89        return SEQ_MULTIPLIER*seq + id;
  90}
  91
  92extern inline int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid)
  93{
  94        if(uid/SEQ_MULTIPLIER != ipcp->seq)
  95                return 1;
  96        return 0;
  97}
  98
  99void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
 100void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out);
 101
 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
 105#else
 106int ipc_parse_version (int *cmd);
 107#endif
 108
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.