The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/ipc/util.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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 
   11 void sem_init (void);
   12 void msg_init (void);
   13 void shm_init (void);
   14 
   15 struct 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 
   26 struct ipc_id {
   27         struct kern_ipc_perm* p;
   28 };
   29 
   30 
   31 void __init ipc_init_ids(struct ipc_ids* ids, int size);
   32 
   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);
   36 
   37 /* must be called with both locks acquired. */
   38 struct kern_ipc_perm* ipc_rmid(struct ipc_ids* ids, int id);
   39 
   40 int ipcperms (struct kern_ipc_perm *ipcp, short flg);
   41 
   42 /* for rare, potentially huge allocations.
   43  * both function can sleep
   44  */
   45 void* ipc_alloc(int size);
   46 void ipc_free(void* ptr, int size);
   47 
   48 extern inline void ipc_lockall(struct ipc_ids* ids)
   49 {
   50         spin_lock(&ids->ary);
   51 }
   52 
   53 extern 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 
   64 extern inline void ipc_unlockall(struct ipc_ids* ids)
   65 {
   66         spin_unlock(&ids->ary);
   67 }
   68 extern 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 
   82 extern inline void ipc_unlock(struct ipc_ids* ids, int id)
   83 {
   84         spin_unlock(&ids->ary);
   85 }
   86 
   87 extern inline int ipc_buildid(struct ipc_ids* ids, int id, int seq)
   88 {
   89         return SEQ_MULTIPLIER*seq + id;
   90 }
   91 
   92 extern 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 
   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);
  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
  106 int ipc_parse_version (int *cmd);
  107 #endif

Cache object: 2caf6cb56aa80af987f2d5138759f07d


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.