Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
3.5 KiB

  1. //
  2. // CH.H
  3. // Cache Handler
  4. //
  5. // Copyright (c) Microsoft 1997-
  6. //
  7. #ifndef _H_CH
  8. #define _H_CH
  9. //
  10. //
  11. // DEFINES
  12. //
  13. //
  14. #define CH_NUM_EVICTION_CATEGORIES 3
  15. //
  16. // NOTES:
  17. // 64K limit on cache
  18. // CHCACHE includes one entry, so only subtract out header part
  19. //
  20. #define CH_MAX_CACHE_ENTRIES \
  21. ( (65535 - (sizeof(CHCACHE) - sizeof(CHENTRY))) / sizeof(CHENTRY) )
  22. //
  23. //
  24. // TYPEDEFS
  25. //
  26. //
  27. typedef struct tagCHCHAIN
  28. {
  29. WORD next;
  30. WORD prev;
  31. } CHCHAIN;
  32. typedef CHCHAIN * PCHCHAIN;
  33. //
  34. // There are going to be thousands of cache entries so we need to keep
  35. // the header as compact as possible. We could drop the eviction
  36. // category, but it is useful info and does round the entry to 16 bytes
  37. // which makes indexing efficient.
  38. //
  39. // Note that the 16 bit code is restricted to 4096 entries unless we take
  40. // steps to allow huge addressing of the entry array.
  41. //
  42. //
  43. // CHENTRY
  44. // Cache entry in a Cache tree
  45. //
  46. typedef struct tagCHENTRY
  47. {
  48. struct tagCHENTRY * pParent;
  49. struct tagCHENTRY * pLeft;
  50. struct tagCHENTRY * pRight;
  51. WORD lHeight;
  52. WORD rHeight;
  53. UINT cbData;
  54. LPBYTE pData;
  55. UINT checkSum;
  56. CHCHAIN chain;
  57. WORD evictionCategory;
  58. WORD free;
  59. } CHENTRY;
  60. typedef CHENTRY * PCHENTRY;
  61. //
  62. // A CACHE
  63. //
  64. // FORWARD DECLARATION
  65. typedef struct tagCHCACHE * PCHCACHE;
  66. #ifdef __cplusplus
  67. typedef void (* PFNCACHEDEL)(class ASHost * pHost, PCHCACHE pCache, UINT iEntry, LPBYTE pData);
  68. //
  69. // Each cache may have several eviction categories. These allow the caller
  70. // to define classes of data so that it can control what is evicted from
  71. // the cache. To be a candidate for eviction the eviction class of a LRU
  72. // entry must match, unless the number of entries in that category is
  73. // less than the eviction threshold, in which case any cache entry is
  74. // up for grabs.
  75. //
  76. // The EvictionThreshold() function can be used to tune eviction thresholds
  77. // which default to cEntries/cNumEvictionCategories
  78. //
  79. typedef struct tagCHCACHE
  80. {
  81. STRUCTURE_STAMP
  82. PFNCACHEDEL pfnCacheDel;
  83. UINT cEntries;
  84. UINT cNumEvictionCategories;
  85. UINT cbNotHashed;
  86. //
  87. // NOTE: CH_NUM_EVICTION_CATEGORIES is 3, so 3 words + 3 words +
  88. // 3 words == 9 words, not DWORD aligned. Hence we stick the WORD
  89. // field free after iMRUTail. If CH_NUM_EVICTION_CATEGORIES ever
  90. // changes to an even value, reshuffle this structure.
  91. //
  92. WORD cEvictThreshold[CH_NUM_EVICTION_CATEGORIES];
  93. WORD iMRUHead[CH_NUM_EVICTION_CATEGORIES];
  94. WORD iMRUTail[CH_NUM_EVICTION_CATEGORIES];
  95. WORD free;
  96. PCHENTRY pRoot;
  97. PCHENTRY pFirst;
  98. PCHENTRY pLast;
  99. CHENTRY Entry[1];
  100. }
  101. CHCACHE;
  102. typedef CHCACHE * PCHCACHE;
  103. #endif // __cplusplus
  104. //
  105. //
  106. // MACROS
  107. //
  108. //
  109. //
  110. // BOGUS LAURABU
  111. // In future, have debug signatures at front of objects to catch heap corruption
  112. //
  113. #define IsValidCache(pCache) \
  114. (!IsBadWritePtr((pCache), sizeof(CHCACHE)))
  115. #define IsValidCacheEntry(pEntry) \
  116. (!IsBadWritePtr((pEntry), sizeof(CHENTRY)))
  117. #define IsValidCacheIndex(pCache, iEntry) \
  118. ((iEntry >= 0) && (iEntry < (pCache)->cEntries))
  119. #define IsCacheEntryInTree(pEntry) \
  120. (((pEntry)->lHeight != 0xFFFF) && ((pEntry)->rHeight != 0xFFFF))
  121. #endif // _H_CH