home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 8.ddi / usr / include / sys / shm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  5.5 KB  |  186 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ifndef _SYS_SHM_H
  11. #define _SYS_SHM_H
  12.  
  13. #ident    "@(#)/usr/include/sys/shm.h.sl 1.1 4.0 12/08/90 52097 AT&T-USL"
  14.  
  15. /*
  16. **    IPC Shared Memory Facility.
  17. */
  18.  
  19. /*
  20. **    Implementation Constants.
  21. */
  22.  
  23. #define SHMLBA  ctob(1)   /* segment low boundary address multiple */
  24.  
  25.             /* (SHMLBA must be a power of 2) */
  26.  
  27. /*
  28. **    Permission Definitions.
  29. */
  30.  
  31. #define    SHM_R    0400    /* read permission */
  32. #define    SHM_W    0200    /* write permission */
  33.  
  34. /*
  35. **    ipc_perm Mode Definitions.
  36. */
  37.  
  38. #define SHM_LOCKED      001000    /* shmid locked */
  39. #define SHM_LOCKWAIT    010000    /* shmid wanted */
  40.  
  41. /*
  42. **    Definitions kept for source-level compatibility only
  43. */
  44. #define    SHM_INIT    01000    /* grow segment on next attach */
  45. #define    SHM_DEST    02000    /* destroy segment when # attached = 0 */
  46.  
  47. #define PSHM    (PZERO + 1)     /* sleep priority */
  48.  
  49. /* define resource locking macros */
  50. #define SHMLOCK(sp) { \
  51.         while ((sp)->shm_perm.mode & SHM_LOCKED) { \
  52.                 (sp)->shm_perm.mode |= SHM_LOCKWAIT; \
  53.                 (void) sleep((caddr_t)(sp), PSHM); \
  54.         } \
  55.         (sp)->shm_perm.mode |= SHM_LOCKED; \
  56. }
  57.  
  58. #define SHMUNLOCK(sp) { \
  59.         (sp)->shm_perm.mode &= ~SHM_LOCKED; \
  60.         if ((sp)->shm_perm.mode & SHM_LOCKWAIT) { \
  61.                 (sp)->shm_perm.mode &= ~SHM_LOCKWAIT; \
  62.                 wakeprocs((caddr_t)(sp), PRMPT); \
  63.         } \
  64. }
  65.  
  66. /*
  67. **    Message Operation Flags.
  68. */
  69.  
  70. #define    SHM_RDONLY    010000    /* attach read-only (else read-write) */
  71. #define    SHM_RND        020000    /* round attach address to SHMLBA */
  72.  
  73. /*
  74. **    Structure Definitions.
  75. */
  76.  
  77. /*
  78. **    There is a shared mem id data structure (shmid_ds) for each 
  79. **    segment in the system.
  80. */
  81.  
  82. #if defined(_KERNEL) || defined(_KMEMUSER)
  83. struct shmid_ds {
  84.     struct ipc_perm shm_perm;    /* operation permission struct */
  85.     int        shm_segsz;    /* size of segment in bytes */
  86.     struct anon_map    *shm_amp;    /* segment anon_map pointer */
  87.     ushort        shm_lkcnt;    /* number of times it is being locked */
  88.     pid_t        shm_lpid;    /* pid of last shmop */
  89.     pid_t        shm_cpid;    /* pid of creator */
  90.     ulong        shm_nattch;    /* used only for shminfo */
  91.     ulong        shm_cnattch;    /* used only for shminfo */
  92.     time_t        shm_atime;    /* last shmat time */
  93.     long        shm_pad1;    /* reserved for time_t expansion */
  94.     time_t        shm_dtime;    /* last shmdt time */
  95.     long        shm_pad2;    /* reserved for time_t expansion */
  96.     time_t        shm_ctime;    /* last change time */
  97.     long        shm_pad3;    /* reserved for time_t expansion */
  98.     long        shm_pad4[4];    /* reserve area  */
  99. };
  100.  
  101. /* SVR3 structure */
  102. struct o_shmid_ds {
  103.     struct o_ipc_perm    shm_perm;    /* operation permission struct */
  104.     int        shm_segsz;    /* size of segment in bytes */
  105.     struct anon_map    *shm_amp;    /* segment anon_map pointer */
  106.     ushort        shm_lkcnt;    /* number of times it is being locked */
  107.     char         pad[2];        
  108.     o_pid_t        shm_lpid;    /* pid of last shmop */
  109.     o_pid_t        shm_cpid;    /* pid of creator */
  110.     ushort        shm_nattch;    /* used only for shminfo */
  111.     ushort        shm_cnattch;    /* used only for shminfo */
  112.     time_t        shm_atime;    /* last shmat time */
  113.     time_t        shm_dtime;    /* last shmdt time */
  114.     time_t        shm_ctime;    /* last change time */
  115. };
  116. #else    /* user definition */
  117. #if !defined(_STYPES)
  118. /* this maps to the kernel struct shmid_ds */
  119. struct shmid_ds {
  120.     struct ipc_perm    shm_perm;    /* operation permission struct */
  121.     int        shm_segsz;    /* size of segment in bytes */
  122.     struct anon_map    *shm_amp;    /* segment anon_map pointer */
  123.     ushort        shm_lkcnt;    /* number of times it is being locked */
  124.     pid_t        shm_lpid;    /* pid of last shmop */
  125.     pid_t        shm_cpid;    /* pid of creator */
  126.     ulong        shm_nattch;    /* used only for shminfo */
  127.     ulong        shm_cnattch;    /* used only for shminfo */
  128.     time_t        shm_atime;    /* last shmat time */
  129.     long        shm_pad1;    /* reserved for time_t expansion */
  130.     time_t        shm_dtime;    /* last shmdt time */
  131.     long        shm_pad2;    /* reserved for time_t expansion */
  132.     time_t        shm_ctime;    /* last change time */
  133.     long        shm_pad3;    /* reserved for time_t expansion */
  134.     long        shm_pad4[4];    /* reserve area  */
  135. };
  136. #else    /* NON EFT */
  137. /* old struct for compatibility */
  138. struct shmid_ds {
  139.     struct ipc_perm    shm_perm;    /* operation permission struct */
  140.     int        shm_segsz;    /* size of segment in bytes */
  141.     struct anon_map    *shm_amp;    /* segment anon_map pointer */
  142.     ushort        shm_lkcnt;    /* number of times it is being locked */
  143.     char         pad[2];        
  144.     o_pid_t        shm_lpid;    /* pid of last shmop */
  145.     o_pid_t        shm_cpid;    /* pid of creator */
  146.     ushort        shm_nattch;    /* used only for shminfo */
  147.     ushort        shm_cnattch;    /* used only for shminfo */
  148.     time_t        shm_atime;    /* last shmat time */
  149.     time_t        shm_dtime;    /* last shmdt time */
  150.     time_t        shm_ctime;    /* last change time */
  151. };
  152. #endif    /* end defined(_LTYPES) */
  153. #endif    /* end defined(_KERNEL */
  154.  
  155. struct    shminfo {
  156.     int    shmmax,        /* max shared memory segment size */
  157.         shmmin,        /* min shared memory segment size */
  158.         shmmni,        /* # of shared memory identifiers */
  159.         shmseg;        /* max attached shared memory      */
  160.                 /* segments per process          */
  161. };
  162.  
  163.  
  164. /*
  165.  * Shared memory control operations
  166.  */
  167.  
  168. #define SHM_LOCK    3    /* Lock segment in core */
  169. #define SHM_UNLOCK    4    /* Unlock segment */
  170.  
  171. #if defined(__STDC__) && !defined(_KERNEL)
  172. int shmctl(int, int, ...);
  173. int shmget(key_t, int, int);
  174. void *shmat(int, void *, int);
  175. int shmdt(void *);
  176. #endif
  177.  
  178. typedef struct segacct {
  179.     struct segacct    *sa_next;
  180.     caddr_t         sa_addr;
  181.     size_t         sa_len;
  182.     struct anon_map *sa_amp;
  183. } segacct_t;
  184.  
  185. #endif    /* _SYS_SHM_H */
  186.