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.

228 lines
5.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT Security
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: lrucache.h
  7. //
  8. // Contents: LRU Cache API
  9. //
  10. // History: 16-Dec-97 kirtd Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #if !defined(__LRUCACHE_H__)
  14. #define __LRUCACHE_H__
  15. #if defined(__cplusplus)
  16. extern "C" {
  17. #endif
  18. //
  19. // These API allow creation and manipulation of an LRU based cache area. The
  20. // identifier used for the cache area is a stream of bytes of which some set
  21. // of bytes are used for the hash index. In order to get optimal caching
  22. // the identifiers used should be unique and the bytes sufficiently random.
  23. //
  24. typedef HANDLE HLRUCACHE;
  25. typedef HANDLE HLRUENTRY;
  26. //
  27. // Configuration flags
  28. //
  29. #define LRU_CACHE_NO_SERIALIZE 0x00000001
  30. #define LRU_CACHE_NO_COPY_IDENTIFIER 0x00000002
  31. //
  32. // Entry removal and cache freeing flags
  33. //
  34. #define LRU_SUPPRESS_REMOVAL_NOTIFICATION 0x00000004
  35. //
  36. // Entry touching flags
  37. //
  38. #define LRU_SUPPRESS_CLOCK_UPDATE 0x00000008
  39. typedef VOID (WINAPI *LRU_DATA_FREE_FN) (LPVOID pvData);
  40. typedef DWORD (WINAPI *LRU_HASH_IDENTIFIER_FN) (PCRYPT_DATA_BLOB pIdentifier);
  41. typedef VOID (WINAPI *LRU_ON_REMOVAL_NOTIFY_FN) (LPVOID pvData, LPVOID pvRemovalContext);
  42. //
  43. // Configuration NOTE: If MaxEntries is zero then no LRU is applied to the
  44. // cache entries, i.e. the cache is not bounded.
  45. //
  46. typedef struct _LRU_CACHE_CONFIG {
  47. DWORD dwFlags;
  48. LRU_DATA_FREE_FN pfnFree;
  49. LRU_HASH_IDENTIFIER_FN pfnHash;
  50. LRU_ON_REMOVAL_NOTIFY_FN pfnOnRemoval;
  51. DWORD cBuckets;
  52. DWORD MaxEntries;
  53. } LRU_CACHE_CONFIG, *PLRU_CACHE_CONFIG;
  54. BOOL
  55. WINAPI
  56. I_CryptCreateLruCache (
  57. IN PLRU_CACHE_CONFIG pConfig,
  58. OUT HLRUCACHE* phCache
  59. );
  60. VOID
  61. WINAPI
  62. I_CryptFlushLruCache (
  63. IN HLRUCACHE hCache,
  64. IN OPTIONAL DWORD dwFlags,
  65. IN OPTIONAL LPVOID pvRemovalContext
  66. );
  67. VOID
  68. WINAPI
  69. I_CryptFreeLruCache (
  70. IN HLRUCACHE hCache,
  71. IN OPTIONAL DWORD dwFlags,
  72. IN OPTIONAL LPVOID pvRemovalContext
  73. );
  74. BOOL
  75. WINAPI
  76. I_CryptCreateLruEntry (
  77. IN HLRUCACHE hCache,
  78. IN PCRYPT_DATA_BLOB pIdentifier,
  79. IN LPVOID pvData,
  80. OUT HLRUENTRY* phEntry
  81. );
  82. PCRYPT_DATA_BLOB
  83. WINAPI
  84. I_CryptGetLruEntryIdentifier (
  85. IN HLRUENTRY hEntry
  86. );
  87. LPVOID
  88. WINAPI
  89. I_CryptGetLruEntryData (
  90. IN HLRUENTRY hEntry
  91. );
  92. VOID
  93. WINAPI
  94. I_CryptAddRefLruEntry (
  95. IN HLRUENTRY hEntry
  96. );
  97. VOID
  98. WINAPI
  99. I_CryptReleaseLruEntry (
  100. IN HLRUENTRY hEntry
  101. );
  102. VOID
  103. WINAPI
  104. I_CryptInsertLruEntry (
  105. IN HLRUENTRY hEntry,
  106. IN OPTIONAL LPVOID pvLruRemovalContext
  107. );
  108. VOID
  109. WINAPI
  110. I_CryptRemoveLruEntry (
  111. IN HLRUENTRY hEntry,
  112. IN OPTIONAL DWORD dwFlags,
  113. IN OPTIONAL LPVOID pvRemovalContext
  114. );
  115. VOID
  116. WINAPI
  117. I_CryptTouchLruEntry (
  118. IN HLRUENTRY hEntry,
  119. IN OPTIONAL DWORD dwFlags
  120. );
  121. // NOTE: The following find does NOT touch the cache entry
  122. HLRUENTRY
  123. WINAPI
  124. I_CryptFindLruEntry (
  125. IN HLRUCACHE hCache,
  126. IN PCRYPT_DATA_BLOB pIdentifier
  127. );
  128. // NOTE: The following find touches the cache entry
  129. LPVOID
  130. WINAPI
  131. I_CryptFindLruEntryData (
  132. IN HLRUCACHE hCache,
  133. IN PCRYPT_DATA_BLOB pIdentifier,
  134. OUT HLRUENTRY* phEntry
  135. );
  136. //
  137. // If you cache contains multiple entries with the same identifier, then
  138. // this function can be used to enumerate them after finding the first with
  139. // I_CryptFindLruEntry
  140. //
  141. // NOTE: hPrevEntry is released
  142. //
  143. // NOTE: This does NOT touch the cache entries
  144. //
  145. // NOTE: The only way to safely use this function is if the serialization
  146. // is done outside of the cache handle and you use the
  147. // LRU_CACHE_NO_SERIALIZE flag. If not, then you will get undefined
  148. // results if hPrevEntry is removed or inserted (after removal) in
  149. // between calls
  150. //
  151. HLRUENTRY
  152. WINAPI
  153. I_CryptEnumMatchingLruEntries (
  154. IN HLRUENTRY hPrevEntry
  155. );
  156. //
  157. // Temporary disabling of LRU behavior. When it is re-enabled then entries
  158. // are purged until the watermark is again met
  159. //
  160. VOID
  161. WINAPI
  162. I_CryptEnableLruOfEntries (
  163. IN HLRUCACHE hCache,
  164. IN OPTIONAL LPVOID pvLruRemovalContext
  165. );
  166. VOID
  167. WINAPI
  168. I_CryptDisableLruOfEntries (
  169. IN HLRUCACHE hCache
  170. );
  171. //
  172. // Walk all entries function
  173. //
  174. typedef BOOL (WINAPI *PFN_WALK_ENTRIES) (
  175. IN LPVOID pvParameter,
  176. IN HLRUENTRY hEntry
  177. );
  178. VOID
  179. WINAPI
  180. I_CryptWalkAllLruCacheEntries (
  181. IN HLRUCACHE hCache,
  182. IN PFN_WALK_ENTRIES pfnWalk,
  183. IN LPVOID pvParameter
  184. );
  185. #if defined(__cplusplus)
  186. }
  187. #endif
  188. #endif