home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 9.ddi / usr / include / vm / seg_map.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  4.9 KB  |  159 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. /*
  11.  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12.  *         PROPRIETARY NOTICE (Combined)
  13.  * 
  14.  * This source code is unpublished proprietary information
  15.  * constituting, or derived under license from AT&T's UNIX(r) System V.
  16.  * In addition, portions of such source code were derived from Berkeley
  17.  * 4.3 BSD under license from the Regents of the University of
  18.  * California.
  19.  * 
  20.  * 
  21.  * 
  22.  *         Copyright Notice 
  23.  * 
  24.  * Notice of copyright on this source code product does not indicate 
  25.  * publication.
  26.  * 
  27.  *     (c) 1986,1987,1988,1989  Sun Microsystems, Inc
  28.  *     (c) 1983,1984,1985,1986,1987,1988,1989  AT&T.
  29.  *               All rights reserved.
  30.  *  
  31.  */
  32.  
  33. #ifndef _VM_SEG_MAP_H
  34. #define _VM_SEG_MAP_H
  35.  
  36. #ident  "@(#)/usr/include/vm/seg_map.h.sl 1.1 4.0 12/08/90 42283 AT&T-USL"
  37.  
  38. #ifndef _SYS_PARAM_H
  39. #include <sys/param.h>
  40. #endif
  41.  
  42. struct segmap_crargs {
  43.     u_int    prot;
  44. };
  45.  
  46. /* The following computes the number of pages covered by an smap (see below).
  47.  * Also, PGARRAYSIZE is computed, which is the length of an array of shorts
  48.  * needed to hold enough bits to use one bit per page.
  49.  */
  50.  
  51. #define PGPERSMAP    (MAXBSIZE / PAGESIZE)
  52. #define NBPS        (NBBY * 2 /* sizeof(u_short) */)
  53. #define PGARRAYSIZE    ((PGPERSMAP + NBPS - 1) / NBPS)
  54.  
  55. /*
  56.  * Each smap struct represents a MAXBSIZE sized mapping to the
  57.  * <sm_vp, sm_off> given in the structure.  The location of the
  58.  * the structure in the array gives the virtual address of the
  59.  * mapping.
  60.  */
  61. struct    smap {
  62.     struct    vnode *sm_vp;        /* vnode pointer (if mapped) */
  63.     u_int    sm_off;            /* file offset for mapping */
  64.     u_short    sm_refcnt;        /* reference count for uses */
  65.     u_short    sm_pgflag[PGARRAYSIZE];    /* per-page flags */
  66.     /*
  67.      * These next 3 entries could be coded as
  68.      * u_shorts if we are tight on memory.
  69.      */
  70.     struct    smap *sm_hash;        /* hash pointer */
  71.     struct    smap *sm_next;        /* next pointer */
  72.     struct    smap *sm_prev;        /* previous pointer */
  73.     u_int    sm_pgowner;    /* owner (proc ptr) of uninitialized pages */
  74.     u_short    sm_pgowncnt;    /* nesting count for getmaps while owned */
  75. };
  76.  
  77. #if PGARRAYSIZE > 1
  78. #define SMPGIDX(pg)    ((pg) / NBPS)
  79. #define SMPGOFF(pg)    ((pg) % NBPS)
  80. #else
  81. #define SMPGIDX(pg)    0
  82. #define SMPGOFF(pg)    (pg)
  83. #endif
  84.  
  85. #define SM_PG_UNINIT(sm, pg)      /* get uninitialized-page flag */ \
  86.         ((sm)->sm_pgflag[SMPGIDX(pg)] & (1 << SMPGOFF(pg)))
  87.  
  88. #define SM_SET_PG_UNINIT(sm, pg)  /* set uninitialized-page flag */ \
  89.         ((sm)->sm_pgflag[SMPGIDX(pg)] |= (1 << SMPGOFF(pg)))
  90.  
  91. #define SM_CLR_PG_UNINIT(sm, pg)  /* clear uninitialized-page flag */ \
  92.         ((sm)->sm_pgflag[SMPGIDX(pg)] &= ~(1 << SMPGOFF(pg)))
  93.  
  94. /*
  95.  * (Semi) private data maintained by the segmap driver per SEGMENT mapping
  96.  */
  97. struct    segmap_data {
  98.     struct    smap *smd_sm;        /* array of smap structures */
  99.     struct    smap *smd_free;        /* free list head pointer */
  100.     u_char    smd_prot;        /* protections for all smap's */
  101.     u_char    smd_want;        /* smap want flag */
  102.     u_int    smd_hashsz;        /* power-of-two hash table size */
  103.     struct    smap **smd_hash;    /* pointer to hash table */
  104. };
  105.  
  106. /*
  107.  * These are flags used on release.  Some of these might get handled
  108.  * by segment operations needed for msync (when we figure them out).
  109.  * SM_ASYNC modifies SM_WRITE.  SM_DONTNEED modifies SM_FREE.  SM_FREE
  110.  * and SM_INVAL are mutually exclusive.
  111.  */
  112. #define    SM_WRITE    0x01        /* write back the pages upon release */
  113. #define    SM_ASYNC    0x02        /* do the write asynchronously */
  114. #define    SM_FREE        0x04        /* put pages back on free list */
  115. #define    SM_INVAL    0x08        /* invalidate page (no caching) */
  116. #define    SM_DONTNEED    0x10        /* less likely to be needed soon */
  117.  
  118. #define MAXBSHIFT    13        /* log2(MAXBSIZE) */
  119.  
  120. #define MAXBOFFSET    (MAXBSIZE - 1)
  121. #define MAXBMASK    (~MAXBOFFSET)
  122.  
  123. /*
  124.  * SMAP_HASHAVELEN is the average length desired for this chain, from
  125.  * which the size of the smd_hash table is derived at segment create time.
  126.  * SMAP_HASHVPSHIFT is defined so that 1 << SMAP_HASHVPSHIFT is the
  127.  * approximate size of a vnode struct.
  128.  */
  129. #define    SMAP_HASHAVELEN        4
  130. #define    SMAP_HASHVPSHIFT    6
  131.  
  132. #define    SMAP_HASHFUNC(smd, vp, off) \
  133.     ((((off) >> MAXBSHIFT) + ((int)(vp) >> SMAP_HASHVPSHIFT)) & \
  134.         ((smd)->smd_hashsz - 1))
  135.  
  136. #ifdef _KERNEL
  137.  
  138. /* the kernel generic mapping segment */
  139. extern struct seg *segkmap;
  140.  
  141. #if defined(__STDC__)
  142.  
  143. extern int segmap_create(struct seg *, void *);
  144. extern void segmap_pagecreate(struct seg *, addr_t, u_int, int);
  145. extern addr_t segmap_getmap(struct seg *, struct vnode *, u_int);
  146. extern int segmap_release(struct seg *, addr_t, u_int);
  147.  
  148. #else
  149.  
  150. extern int segmap_create();
  151. extern void segmap_pagecreate();
  152. extern addr_t segmap_getmap();
  153. extern int segmap_release();
  154.  
  155. #endif
  156. #endif /* _KERNEL */
  157.  
  158. #endif    /* _VM_SEG_MAP_H */
  159.