Source code of Windows XP (NT5)
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.

135 lines
3.9 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Memory cache object.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997-2001.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef __MCACHE_HPP__
  9. #define __MCACHE_HPP__
  10. typedef struct _CACHE* PCACHE;
  11. //----------------------------------------------------------------------------
  12. //
  13. // MemoryCache.
  14. //
  15. //----------------------------------------------------------------------------
  16. class MemoryCache
  17. {
  18. public:
  19. MemoryCache(void);
  20. ~MemoryCache(void);
  21. HRESULT Read(IN ULONG64 BaseAddress,
  22. IN PVOID UserBuffer,
  23. IN ULONG TransferCount,
  24. OUT PULONG BytesRead);
  25. HRESULT Write(IN ULONG64 BaseAddress,
  26. IN PVOID UserBuffer,
  27. IN ULONG TransferCount,
  28. OUT PULONG BytesWritten);
  29. void Add(IN ULONG64 BaseAddress,
  30. IN PVOID UserBuffer,
  31. IN ULONG Length);
  32. void Remove(IN ULONG64 BaseAddress,
  33. IN ULONG Length);
  34. void Empty(void);
  35. void ParseCommands(void);
  36. //
  37. // Internal methods.
  38. //
  39. virtual HRESULT ReadUncached(IN ULONG64 BaseAddress,
  40. IN PVOID UserBuffer,
  41. IN ULONG TransferCount,
  42. OUT PULONG BytesRead) = 0;
  43. virtual HRESULT WriteUncached(IN ULONG64 BaseAddress,
  44. IN PVOID UserBuffer,
  45. IN ULONG TransferCount,
  46. OUT PULONG BytesWritten) = 0;
  47. PCACHE Lookup(ULONG64 Offset,
  48. ULONG Length,
  49. PULONG LengthUsed);
  50. void InsertNode(IN PCACHE node);
  51. PUCHAR Alloc(IN ULONG Length);
  52. VOID Free(IN PUCHAR Memory,
  53. IN ULONG Length);
  54. VOID PurgeType(ULONG type);
  55. VOID SetForceDecodePtes(BOOL Enable);
  56. void Dump(void);
  57. void DumpNode(PCACHE Node);
  58. ULONG m_MaxSize;
  59. ULONG m_UserSize;
  60. BOOL m_DecodePTEs;
  61. BOOL m_ForceDecodePTEs;
  62. BOOL m_Suspend;
  63. ULONG m_Reads, m_CachedReads, m_UncachedReads;
  64. ULONG64 m_CachedBytes, m_UncachedBytes;
  65. ULONG m_Misses;
  66. ULONG m_Size;
  67. ULONG m_NodeCount;
  68. BOOL m_PurgeOverride;
  69. PCACHE m_Root;
  70. };
  71. //----------------------------------------------------------------------------
  72. //
  73. // VirtualMemoryCache.
  74. //
  75. //----------------------------------------------------------------------------
  76. class VirtualMemoryCache : public MemoryCache
  77. {
  78. public:
  79. virtual HRESULT ReadUncached(IN ULONG64 BaseAddress,
  80. IN PVOID UserBuffer,
  81. IN ULONG TransferCount,
  82. OUT PULONG BytesRead);
  83. virtual HRESULT WriteUncached(IN ULONG64 BaseAddress,
  84. IN PVOID UserBuffer,
  85. IN ULONG TransferCount,
  86. OUT PULONG BytesWritten);
  87. };
  88. extern VirtualMemoryCache g_VirtualCache;
  89. //----------------------------------------------------------------------------
  90. //
  91. // PhysicalMemoryCache.
  92. //
  93. //----------------------------------------------------------------------------
  94. class PhysicalMemoryCache : public MemoryCache
  95. {
  96. public:
  97. virtual HRESULT ReadUncached(IN ULONG64 BaseAddress,
  98. IN PVOID UserBuffer,
  99. IN ULONG TransferCount,
  100. OUT PULONG BytesRead);
  101. virtual HRESULT WriteUncached(IN ULONG64 BaseAddress,
  102. IN PVOID UserBuffer,
  103. IN ULONG TransferCount,
  104. OUT PULONG BytesWritten);
  105. };
  106. extern PhysicalMemoryCache g_PhysicalCache;
  107. extern BOOL g_PhysicalCacheActive;
  108. #define InvalidateMemoryCaches() \
  109. ( g_VirtualCache.Empty(), g_PhysicalCache.Empty() )
  110. #endif // #ifndef __MCACHE_HPP__