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.

906 lines
23 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT Security
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: lru.cpp
  7. //
  8. // Contents: LRU cache implementation
  9. //
  10. // History: 24-Dec-97 kirtd Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <global.hxx>
  14. //+---------------------------------------------------------------------------
  15. //
  16. // Member: CLruEntry::CLruEntry, public
  17. //
  18. // Synopsis: Constructor
  19. //
  20. //----------------------------------------------------------------------------
  21. CLruEntry::CLruEntry (
  22. IN PCLRUCACHE pCache,
  23. IN PCRYPT_DATA_BLOB pIdentifier,
  24. IN LPVOID pvData,
  25. OUT BOOL& rfResult
  26. )
  27. {
  28. rfResult = TRUE;
  29. m_cRefs = 1;
  30. m_pPrevEntry = NULL;
  31. m_pNextEntry = NULL;
  32. m_Usage = 0;
  33. m_pCache = pCache;
  34. m_pvData = pvData;
  35. m_pBucket = pCache->BucketFromIdentifier( pIdentifier );
  36. if ( pCache->Flags() & LRU_CACHE_NO_COPY_IDENTIFIER )
  37. {
  38. m_Identifier = *pIdentifier;
  39. }
  40. else
  41. {
  42. m_Identifier.cbData = pIdentifier->cbData;
  43. m_Identifier.pbData = new BYTE [ pIdentifier->cbData ];
  44. if ( m_Identifier.pbData != NULL )
  45. {
  46. memcpy(
  47. m_Identifier.pbData,
  48. pIdentifier->pbData,
  49. pIdentifier->cbData
  50. );
  51. }
  52. else
  53. {
  54. rfResult = FALSE;
  55. SetLastError( (DWORD) E_OUTOFMEMORY );
  56. return;
  57. }
  58. }
  59. assert( m_pBucket != NULL );
  60. assert( m_Identifier.pbData != NULL );
  61. }
  62. //+---------------------------------------------------------------------------
  63. //
  64. // Member: CLruEntry::~CLruEntry, public
  65. //
  66. // Synopsis: Destructor
  67. //
  68. //----------------------------------------------------------------------------
  69. CLruEntry::~CLruEntry ()
  70. {
  71. m_pCache->FreeEntryData( m_pvData );
  72. if ( !( m_pCache->Flags() & LRU_CACHE_NO_COPY_IDENTIFIER ) )
  73. {
  74. delete m_Identifier.pbData;
  75. }
  76. }
  77. //+---------------------------------------------------------------------------
  78. //
  79. // Member: CLruCache::CLruCache, public
  80. //
  81. // Synopsis: Constructor
  82. //
  83. //----------------------------------------------------------------------------
  84. CLruCache::CLruCache (
  85. IN PLRU_CACHE_CONFIG pConfig,
  86. OUT BOOL& rfResult
  87. )
  88. {
  89. rfResult = TRUE;
  90. m_Config.dwFlags = LRU_CACHE_NO_SERIALIZE;
  91. m_cEntries = 0;
  92. m_aBucket = new LRU_CACHE_BUCKET [ pConfig->cBuckets ];
  93. if ( m_aBucket == NULL )
  94. {
  95. rfResult = FALSE;
  96. SetLastError( (DWORD) E_OUTOFMEMORY );
  97. return;
  98. }
  99. memset( m_aBucket, 0, sizeof( LRU_CACHE_BUCKET ) * pConfig->cBuckets );
  100. if ( !( pConfig->dwFlags & LRU_CACHE_NO_SERIALIZE ) )
  101. {
  102. if (! Pki_InitializeCriticalSection( &m_Lock ))
  103. {
  104. rfResult = FALSE;
  105. return;
  106. }
  107. }
  108. m_Config = *pConfig;
  109. m_UsageClock = 0;
  110. m_cLruDisabled = 0;
  111. }
  112. //+---------------------------------------------------------------------------
  113. //
  114. // Member: CLruCache::~CLruCache, public
  115. //
  116. // Synopsis: Destructor
  117. //
  118. //----------------------------------------------------------------------------
  119. CLruCache::~CLruCache ()
  120. {
  121. if ( m_cEntries > 0 )
  122. {
  123. PurgeAllEntries( 0, NULL );
  124. }
  125. if ( !( m_Config.dwFlags & LRU_CACHE_NO_SERIALIZE ) )
  126. {
  127. DeleteCriticalSection( &m_Lock );
  128. }
  129. delete m_aBucket;
  130. }
  131. //+---------------------------------------------------------------------------
  132. //
  133. // Member: CLruCache::EnableLruOfEntries, public
  134. //
  135. // Synopsis: enable LRU of entries and purge anything over the watermark
  136. //
  137. //----------------------------------------------------------------------------
  138. VOID
  139. CLruCache::EnableLruOfEntries (IN OPTIONAL LPVOID pvLruRemovalContext)
  140. {
  141. LockCache();
  142. assert( m_cLruDisabled > 0 );
  143. if ( m_cLruDisabled == 0 )
  144. {
  145. return;
  146. }
  147. m_cLruDisabled -= 1;
  148. if ( m_cLruDisabled == 0 )
  149. {
  150. while ( m_cEntries > m_Config.MaxEntries )
  151. {
  152. PurgeLeastRecentlyUsed( pvLruRemovalContext );
  153. }
  154. }
  155. UnlockCache();
  156. }
  157. //+---------------------------------------------------------------------------
  158. //
  159. // Member: CLruCache::DisableLruOfEntries, public
  160. //
  161. // Synopsis: disable LRU of entries
  162. //
  163. //----------------------------------------------------------------------------
  164. VOID
  165. CLruCache::DisableLruOfEntries ()
  166. {
  167. LockCache();
  168. m_cLruDisabled += 1;
  169. UnlockCache();
  170. }
  171. //+---------------------------------------------------------------------------
  172. //
  173. // Member: CLruCache::InsertEntry, public
  174. //
  175. // Synopsis: insert an entry into the cache
  176. //
  177. //----------------------------------------------------------------------------
  178. VOID
  179. CLruCache::InsertEntry (
  180. IN PCLRUENTRY pEntry,
  181. IN OPTIONAL LPVOID pvLruRemovalContext
  182. )
  183. {
  184. assert( pEntry->PrevPointer() == NULL );
  185. assert( pEntry->NextPointer() == NULL );
  186. pEntry->AddRef();
  187. LockCache();
  188. if ( ( m_cEntries == m_Config.MaxEntries ) &&
  189. ( m_Config.MaxEntries != 0 ) &&
  190. ( m_cLruDisabled == 0 ) )
  191. {
  192. PurgeLeastRecentlyUsed( pvLruRemovalContext );
  193. }
  194. assert( ( m_cEntries < m_Config.MaxEntries ) ||
  195. ( m_Config.MaxEntries == 0 ) ||
  196. ( m_cLruDisabled > 0 ) );
  197. pEntry->SetNextPointer( pEntry->Bucket()->pList );
  198. if ( pEntry->Bucket()->pList != NULL )
  199. {
  200. pEntry->Bucket()->pList->SetPrevPointer( pEntry );
  201. }
  202. pEntry->Bucket()->pList = pEntry;
  203. m_cEntries += 1;
  204. TouchEntryNoLock( pEntry, 0 );
  205. UnlockCache();
  206. }
  207. //+---------------------------------------------------------------------------
  208. //
  209. // Member: CLruCache::RemoveEntry, public
  210. //
  211. // Synopsis: remove an entry from the cache
  212. //
  213. //----------------------------------------------------------------------------
  214. VOID
  215. CLruCache::RemoveEntry (
  216. IN PCLRUENTRY pEntry,
  217. IN DWORD dwFlags,
  218. IN OPTIONAL LPVOID pvRemovalContext
  219. )
  220. {
  221. LockCache();
  222. RemoveEntryFromBucket(
  223. pEntry->Bucket(),
  224. pEntry,
  225. dwFlags,
  226. pvRemovalContext
  227. );
  228. UnlockCache();
  229. }
  230. //+---------------------------------------------------------------------------
  231. //
  232. // Member: CLruCache::TouchEntry, public
  233. //
  234. // Synopsis: touch the entry
  235. //
  236. //----------------------------------------------------------------------------
  237. VOID
  238. CLruCache::TouchEntry (IN PCLRUENTRY pEntry, IN DWORD dwFlags)
  239. {
  240. LockCache();
  241. TouchEntryNoLock( pEntry, dwFlags );
  242. UnlockCache();
  243. }
  244. //+---------------------------------------------------------------------------
  245. //
  246. // Member: CLruCache::FindEntry, public
  247. //
  248. // Synopsis: find the entry matching the given identifier
  249. //
  250. //----------------------------------------------------------------------------
  251. PCLRUENTRY
  252. CLruCache::FindEntry (IN PCRYPT_DATA_BLOB pIdentifier, IN BOOL fTouchEntry)
  253. {
  254. PLRU_CACHE_BUCKET pBucket;
  255. pBucket = BucketFromIdentifier( pIdentifier );
  256. assert( pBucket != NULL );
  257. return( FindNextMatchingEntryInBucket(
  258. pBucket,
  259. NULL,
  260. pIdentifier,
  261. fTouchEntry
  262. ) );
  263. }
  264. //+---------------------------------------------------------------------------
  265. //
  266. // Member: CLruCache::NextMatchingEntry, public
  267. //
  268. // Synopsis: find the next matching entry to pPrevEntry
  269. //
  270. //----------------------------------------------------------------------------
  271. PCLRUENTRY
  272. CLruCache::NextMatchingEntry (IN PCLRUENTRY pPrevEntry, IN BOOL fTouchEntry)
  273. {
  274. PCLRUENTRY pNextEntry;
  275. pNextEntry = FindNextMatchingEntryInBucket(
  276. NULL,
  277. pPrevEntry,
  278. NULL,
  279. fTouchEntry
  280. );
  281. pPrevEntry->Release();
  282. return( pNextEntry );
  283. }
  284. //+---------------------------------------------------------------------------
  285. //
  286. // Member: CLruCache::WalkEntries, public
  287. //
  288. // Synopsis: walk the entries
  289. //
  290. //----------------------------------------------------------------------------
  291. VOID
  292. CLruCache::WalkEntries (IN PFN_WALK_ENTRIES pfnWalk, IN LPVOID pvParameter)
  293. {
  294. DWORD cCount;
  295. PCLRUENTRY pEntry;
  296. PCLRUENTRY pNextEntry;
  297. for ( cCount = 0; cCount < m_Config.cBuckets; cCount++ )
  298. {
  299. pEntry = m_aBucket[ cCount ].pList;
  300. while ( pEntry != NULL )
  301. {
  302. pNextEntry = pEntry->NextPointer();
  303. if ( ( *pfnWalk )( pvParameter, pEntry ) == FALSE )
  304. {
  305. return;
  306. }
  307. pEntry = pNextEntry;
  308. }
  309. }
  310. }
  311. //+---------------------------------------------------------------------------
  312. //
  313. // Member: CLruCache::RemoveEntryFromBucket, public
  314. //
  315. // Synopsis: remove entry from bucket
  316. //
  317. //----------------------------------------------------------------------------
  318. VOID
  319. CLruCache::RemoveEntryFromBucket (
  320. IN PLRU_CACHE_BUCKET pBucket,
  321. IN PCLRUENTRY pEntry,
  322. IN DWORD dwFlags,
  323. IN OPTIONAL LPVOID pvRemovalContext
  324. )
  325. {
  326. if ( pEntry->PrevPointer() != NULL )
  327. {
  328. pEntry->PrevPointer()->SetNextPointer( pEntry->NextPointer() );
  329. }
  330. else
  331. {
  332. assert( pBucket->pList == pEntry );
  333. pBucket->pList = pEntry->NextPointer();
  334. }
  335. if ( pEntry->NextPointer() != NULL )
  336. {
  337. pEntry->NextPointer()->SetPrevPointer( pEntry->PrevPointer() );
  338. }
  339. pEntry->SetPrevPointer( NULL );
  340. pEntry->SetNextPointer( NULL );
  341. m_cEntries -= 1;
  342. if ( ( m_Config.pfnOnRemoval != NULL ) &&
  343. !( dwFlags & LRU_SUPPRESS_REMOVAL_NOTIFICATION ) )
  344. {
  345. ( *m_Config.pfnOnRemoval )( pEntry->Data(), pvRemovalContext );
  346. }
  347. pEntry->Release();
  348. }
  349. //+---------------------------------------------------------------------------
  350. //
  351. // Member: CLruCache::FindNextMatchingEntryInBucket, public
  352. //
  353. // Synopsis: find the next matching entry in the given bucket. If pCurrent
  354. // is non NULL then start from there, the bucket is not needed and
  355. // pIdentifier is ignored. If pCurrent is NULL then pIdentifier
  356. // and the bucket must both be non NULL
  357. //
  358. //----------------------------------------------------------------------------
  359. PCLRUENTRY
  360. CLruCache::FindNextMatchingEntryInBucket (
  361. IN PLRU_CACHE_BUCKET pBucket,
  362. IN PCLRUENTRY pCurrent,
  363. IN PCRYPT_DATA_BLOB pIdentifier,
  364. IN BOOL fTouchEntry
  365. )
  366. {
  367. LockCache();
  368. if ( pCurrent == NULL )
  369. {
  370. pCurrent = pBucket->pList;
  371. }
  372. else
  373. {
  374. pIdentifier = pCurrent->Identifier();
  375. pCurrent = pCurrent->NextPointer();
  376. }
  377. while ( pCurrent != NULL )
  378. {
  379. if ( ( pIdentifier->cbData == pCurrent->Identifier()->cbData ) &&
  380. ( memcmp(
  381. pIdentifier->pbData,
  382. pCurrent->Identifier()->pbData,
  383. pIdentifier->cbData
  384. ) == 0 ) )
  385. {
  386. break;
  387. }
  388. pCurrent = pCurrent->NextPointer();
  389. }
  390. if ( pCurrent != NULL )
  391. {
  392. pCurrent->AddRef();
  393. if ( fTouchEntry == TRUE )
  394. {
  395. TouchEntryNoLock( pCurrent, 0 );
  396. }
  397. }
  398. UnlockCache();
  399. return( pCurrent );
  400. }
  401. //+---------------------------------------------------------------------------
  402. //
  403. // Member: CLruCache::PurgeLeastRecentlyUsed, public
  404. //
  405. // Synopsis: find and remove the least recently used entry
  406. //
  407. //----------------------------------------------------------------------------
  408. VOID
  409. CLruCache::PurgeLeastRecentlyUsed (IN OPTIONAL LPVOID pvLruRemovalContext)
  410. {
  411. DWORD cCount;
  412. PLRU_CACHE_BUCKET pBucket;
  413. PCLRUENTRY pEntry;
  414. PCLRUENTRY pLRU;
  415. assert( m_cEntries > 0 );
  416. for ( cCount = 0; cCount < m_Config.cBuckets; cCount++ )
  417. {
  418. if ( m_aBucket[cCount].pList != NULL )
  419. {
  420. break;
  421. }
  422. }
  423. pBucket = &m_aBucket[cCount];
  424. cCount += 1;
  425. for ( ; cCount < m_Config.cBuckets; cCount++ )
  426. {
  427. if ( ( m_aBucket[cCount].pList != NULL ) &&
  428. ( m_aBucket[cCount].Usage < pBucket->Usage ) )
  429. {
  430. pBucket = &m_aBucket[cCount];
  431. }
  432. }
  433. assert( pBucket != NULL );
  434. assert( pBucket->pList != NULL );
  435. pLRU = pBucket->pList;
  436. pEntry = pLRU->NextPointer();
  437. while ( pEntry != NULL )
  438. {
  439. if ( pEntry->Usage() < pLRU->Usage() )
  440. {
  441. pLRU = pEntry;
  442. }
  443. pEntry = pEntry->NextPointer();
  444. }
  445. RemoveEntryFromBucket( pBucket, pLRU, 0, pvLruRemovalContext );
  446. }
  447. //+---------------------------------------------------------------------------
  448. //
  449. // Member: CLruCache::PurgeAllEntries, public
  450. //
  451. // Synopsis: remove all entries from the cache
  452. //
  453. //----------------------------------------------------------------------------
  454. VOID
  455. CLruCache::PurgeAllEntries (
  456. IN DWORD dwFlags,
  457. IN OPTIONAL LPVOID pvRemovalContext
  458. )
  459. {
  460. DWORD cCount;
  461. for ( cCount = 0; cCount < m_Config.cBuckets; cCount++ )
  462. {
  463. while ( m_aBucket[cCount].pList != NULL )
  464. {
  465. RemoveEntryFromBucket(
  466. &m_aBucket[cCount],
  467. m_aBucket[cCount].pList,
  468. dwFlags,
  469. pvRemovalContext
  470. );
  471. }
  472. }
  473. assert( m_cEntries == 0 );
  474. }
  475. //+---------------------------------------------------------------------------
  476. //
  477. // Function: I_CryptCreateLruCache
  478. //
  479. // Synopsis: create an LRU cache area
  480. //
  481. //----------------------------------------------------------------------------
  482. BOOL WINAPI
  483. I_CryptCreateLruCache (
  484. IN PLRU_CACHE_CONFIG pConfig,
  485. OUT HLRUCACHE* phCache
  486. )
  487. {
  488. BOOL fResult = FALSE;
  489. PCLRUCACHE pCache;
  490. pCache = new CLruCache( pConfig, fResult );
  491. if ( pCache == NULL )
  492. {
  493. SetLastError( (DWORD) E_OUTOFMEMORY );
  494. return( FALSE );
  495. }
  496. if ( fResult == FALSE )
  497. {
  498. delete pCache;
  499. return( FALSE );
  500. }
  501. *phCache = (HLRUCACHE)pCache;
  502. return( TRUE );
  503. }
  504. //+---------------------------------------------------------------------------
  505. //
  506. // Function: I_CryptFlushLruCache
  507. //
  508. // Synopsis: flush the cache
  509. //
  510. //----------------------------------------------------------------------------
  511. VOID WINAPI
  512. I_CryptFlushLruCache (
  513. IN HLRUCACHE hCache,
  514. IN OPTIONAL DWORD dwFlags,
  515. IN OPTIONAL LPVOID pvRemovalContext
  516. )
  517. {
  518. ( (PCLRUCACHE)hCache )->LockCache();
  519. ( (PCLRUCACHE)hCache )->PurgeAllEntries( dwFlags, pvRemovalContext );
  520. ( (PCLRUCACHE)hCache )->UnlockCache();
  521. }
  522. //+---------------------------------------------------------------------------
  523. //
  524. // Function: I_CryptFreeLruCache
  525. //
  526. // Synopsis: free the LRU cache area
  527. //
  528. //----------------------------------------------------------------------------
  529. VOID WINAPI
  530. I_CryptFreeLruCache (
  531. IN HLRUCACHE hCache,
  532. IN DWORD dwFlags,
  533. IN OPTIONAL LPVOID pvRemovalContext
  534. )
  535. {
  536. if ( hCache == NULL )
  537. {
  538. return;
  539. }
  540. if ( dwFlags != 0 )
  541. {
  542. ( (PCLRUCACHE)hCache )->PurgeAllEntries( dwFlags, pvRemovalContext );
  543. }
  544. delete (PCLRUCACHE)hCache;
  545. }
  546. //+---------------------------------------------------------------------------
  547. //
  548. // Function: I_CryptCreateLruEntry
  549. //
  550. // Synopsis: create an LRU entry
  551. //
  552. //----------------------------------------------------------------------------
  553. BOOL WINAPI
  554. I_CryptCreateLruEntry (
  555. IN HLRUCACHE hCache,
  556. IN PCRYPT_DATA_BLOB pIdentifier,
  557. IN LPVOID pvData,
  558. OUT HLRUENTRY* phEntry
  559. )
  560. {
  561. BOOL fResult = FALSE;
  562. PCLRUENTRY pEntry;
  563. pEntry = new CLruEntry(
  564. (PCLRUCACHE)hCache,
  565. pIdentifier,
  566. pvData,
  567. fResult
  568. );
  569. if ( pEntry == NULL )
  570. {
  571. SetLastError( (DWORD) E_OUTOFMEMORY );
  572. return( FALSE );
  573. }
  574. if ( fResult == FALSE )
  575. {
  576. delete pEntry;
  577. return( FALSE );
  578. }
  579. *phEntry = (HLRUENTRY)pEntry;
  580. return( TRUE );
  581. }
  582. //+---------------------------------------------------------------------------
  583. //
  584. // Function: I_CryptGetLruEntryIdentifier
  585. //
  586. // Synopsis: return the identifier for the entry
  587. //
  588. //----------------------------------------------------------------------------
  589. PCRYPT_DATA_BLOB WINAPI
  590. I_CryptGetLruEntryIdentifier (
  591. IN HLRUENTRY hEntry
  592. )
  593. {
  594. return( ( (PCLRUENTRY)hEntry )->Identifier() );
  595. }
  596. //+---------------------------------------------------------------------------
  597. //
  598. // Function: I_CryptGetLruEntryData
  599. //
  600. // Synopsis: get the data associated with the entry
  601. //
  602. //----------------------------------------------------------------------------
  603. LPVOID WINAPI
  604. I_CryptGetLruEntryData (
  605. IN HLRUENTRY hEntry
  606. )
  607. {
  608. return( ( (PCLRUENTRY)hEntry )->Data() );
  609. }
  610. //+---------------------------------------------------------------------------
  611. //
  612. // Function: I_CryptAddRefLruEntry
  613. //
  614. // Synopsis: add a reference to the entry
  615. //
  616. //----------------------------------------------------------------------------
  617. VOID WINAPI
  618. I_CryptAddRefLruEntry (
  619. IN HLRUENTRY hEntry
  620. )
  621. {
  622. ( (PCLRUENTRY)hEntry )->AddRef();
  623. }
  624. //+---------------------------------------------------------------------------
  625. //
  626. // Function: I_CryptReleaseLruEntry
  627. //
  628. // Synopsis: remove a reference from the entry
  629. //
  630. //----------------------------------------------------------------------------
  631. VOID WINAPI
  632. I_CryptReleaseLruEntry (
  633. IN HLRUENTRY hEntry
  634. )
  635. {
  636. ( (PCLRUENTRY)hEntry )->Release();
  637. }
  638. //+---------------------------------------------------------------------------
  639. //
  640. // Function: I_CryptInsertLruEntry
  641. //
  642. // Synopsis: insert the entry into its associated cache
  643. //
  644. //----------------------------------------------------------------------------
  645. VOID WINAPI
  646. I_CryptInsertLruEntry (
  647. IN HLRUENTRY hEntry,
  648. IN OPTIONAL LPVOID pvLruRemovalContext
  649. )
  650. {
  651. PCLRUENTRY pEntry = (PCLRUENTRY)hEntry;
  652. pEntry->Cache()->InsertEntry( pEntry, pvLruRemovalContext );
  653. }
  654. //+---------------------------------------------------------------------------
  655. //
  656. // Function: I_CryptRemoveLruEntry
  657. //
  658. // Synopsis: remove the entry from its associated cache
  659. //
  660. //----------------------------------------------------------------------------
  661. VOID WINAPI
  662. I_CryptRemoveLruEntry (
  663. IN HLRUENTRY hEntry,
  664. IN DWORD dwFlags,
  665. IN LPVOID pvLruRemovalContext
  666. )
  667. {
  668. PCLRUENTRY pEntry = (PCLRUENTRY)hEntry;
  669. pEntry->Cache()->RemoveEntry( pEntry, dwFlags, pvLruRemovalContext );
  670. }
  671. //+---------------------------------------------------------------------------
  672. //
  673. // Function: I_CryptTouchLruEntry
  674. //
  675. // Synopsis: touch the entry
  676. //
  677. //----------------------------------------------------------------------------
  678. VOID WINAPI
  679. I_CryptTouchLruEntry (
  680. IN HLRUENTRY hEntry,
  681. IN DWORD dwFlags
  682. )
  683. {
  684. PCLRUENTRY pEntry = (PCLRUENTRY)hEntry;
  685. pEntry->Cache()->TouchEntry( pEntry, dwFlags );
  686. }
  687. //+---------------------------------------------------------------------------
  688. //
  689. // Function: I_CryptFindLruEntry
  690. //
  691. // Synopsis: find the entry with the given identifier
  692. //
  693. //----------------------------------------------------------------------------
  694. HLRUENTRY WINAPI
  695. I_CryptFindLruEntry (
  696. IN HLRUCACHE hCache,
  697. IN PCRYPT_DATA_BLOB pIdentifier
  698. )
  699. {
  700. PCLRUCACHE pCache = (PCLRUCACHE)hCache;
  701. return( pCache->FindEntry( pIdentifier, FALSE ) );
  702. }
  703. //+---------------------------------------------------------------------------
  704. //
  705. // Function: I_CryptFindLruEntryData
  706. //
  707. // Synopsis: find the entry with the given identifier
  708. //
  709. //----------------------------------------------------------------------------
  710. LPVOID WINAPI
  711. I_CryptFindLruEntryData (
  712. IN HLRUCACHE hCache,
  713. IN PCRYPT_DATA_BLOB pIdentifier,
  714. OUT HLRUENTRY* phEntry
  715. )
  716. {
  717. PCLRUCACHE pCache = (PCLRUCACHE)hCache;
  718. PCLRUENTRY pEntry;
  719. pEntry = pCache->FindEntry( pIdentifier, TRUE );
  720. *phEntry = (HLRUENTRY)pEntry;
  721. if ( pEntry != NULL )
  722. {
  723. return( pEntry->Data() );
  724. }
  725. return( NULL );
  726. }
  727. //+---------------------------------------------------------------------------
  728. //
  729. // Function: I_CryptEnumMatchingLruEntries
  730. //
  731. // Synopsis: get the next matching entry
  732. //
  733. //----------------------------------------------------------------------------
  734. HLRUENTRY WINAPI
  735. I_CryptEnumMatchingLruEntries (
  736. IN HLRUENTRY hPrevEntry
  737. )
  738. {
  739. PCLRUCACHE pCache = ( (PCLRUENTRY)hPrevEntry )->Cache();
  740. PCLRUENTRY pNextEntry;
  741. pNextEntry = pCache->NextMatchingEntry( (PCLRUENTRY)hPrevEntry, FALSE );
  742. return( (HLRUENTRY)pNextEntry );
  743. }
  744. //+---------------------------------------------------------------------------
  745. //
  746. // Function: I_CryptEnableLruOfEntries
  747. //
  748. // Synopsis: enable LRU of entries
  749. //
  750. //----------------------------------------------------------------------------
  751. VOID WINAPI
  752. I_CryptEnableLruOfEntries (
  753. IN HLRUCACHE hCache,
  754. IN OPTIONAL LPVOID pvLruRemovalContext
  755. )
  756. {
  757. ( (PCLRUCACHE)hCache )->EnableLruOfEntries( pvLruRemovalContext);
  758. }
  759. //+---------------------------------------------------------------------------
  760. //
  761. // Function: I_CryptDisableLruOfEntries
  762. //
  763. // Synopsis: disable LRU of entries
  764. //
  765. //----------------------------------------------------------------------------
  766. VOID WINAPI
  767. I_CryptDisableLruOfEntries (
  768. IN HLRUCACHE hCache
  769. )
  770. {
  771. ( (PCLRUCACHE)hCache )->DisableLruOfEntries();
  772. }
  773. //+---------------------------------------------------------------------------
  774. //
  775. // Function: I_CryptWalkAllLruCacheEntries
  776. //
  777. // Synopsis: walk the LRU cache entries
  778. //
  779. //----------------------------------------------------------------------------
  780. VOID WINAPI
  781. I_CryptWalkAllLruCacheEntries (
  782. IN HLRUCACHE hCache,
  783. IN PFN_WALK_ENTRIES pfnWalk,
  784. IN LPVOID pvParameter
  785. )
  786. {
  787. ( (PCLRUCACHE)hCache )->WalkEntries( pfnWalk, pvParameter );
  788. }