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.

163 lines
4.5 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Memory cache object.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997-2002.
  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(ULONG MaxSize);
  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, TargetInfo* Target);
  56. void Dump(void);
  57. void DumpNode(PCACHE Node);
  58. BOOL ChangeSuspend(BOOL Active)
  59. {
  60. if (Active)
  61. {
  62. if (m_Suspend > 0)
  63. {
  64. m_Suspend--;
  65. return TRUE;
  66. }
  67. }
  68. else if (m_Suspend < 0xffffffff)
  69. {
  70. m_Suspend++;
  71. return TRUE;
  72. }
  73. return FALSE;
  74. }
  75. TargetInfo* m_Target;
  76. ULONG m_MaxSize;
  77. ULONG m_UserSize;
  78. BOOL m_DecodePTEs;
  79. BOOL m_ForceDecodePTEs;
  80. ULONG m_Suspend;
  81. ULONG m_Reads, m_CachedReads, m_UncachedReads;
  82. ULONG64 m_CachedBytes, m_UncachedBytes;
  83. ULONG m_Misses;
  84. ULONG m_Size;
  85. ULONG m_NodeCount;
  86. BOOL m_PurgeOverride;
  87. PCACHE m_Root;
  88. };
  89. //----------------------------------------------------------------------------
  90. //
  91. // VirtualMemoryCache.
  92. //
  93. //----------------------------------------------------------------------------
  94. class VirtualMemoryCache : public MemoryCache
  95. {
  96. public:
  97. VirtualMemoryCache(void)
  98. : MemoryCache(1000 * 1024)
  99. {
  100. m_Process = NULL;
  101. }
  102. void SetProcess(ProcessInfo* Process);
  103. virtual HRESULT ReadUncached(IN ULONG64 BaseAddress,
  104. IN PVOID UserBuffer,
  105. IN ULONG TransferCount,
  106. OUT PULONG BytesRead);
  107. virtual HRESULT WriteUncached(IN ULONG64 BaseAddress,
  108. IN PVOID UserBuffer,
  109. IN ULONG TransferCount,
  110. OUT PULONG BytesWritten);
  111. ProcessInfo* m_Process;
  112. };
  113. //----------------------------------------------------------------------------
  114. //
  115. // PhysicalMemoryCache.
  116. //
  117. //----------------------------------------------------------------------------
  118. class PhysicalMemoryCache : public MemoryCache
  119. {
  120. public:
  121. PhysicalMemoryCache(void)
  122. : MemoryCache(1000 * 1024) {}
  123. void SetTarget(TargetInfo* Target);
  124. virtual HRESULT ReadUncached(IN ULONG64 BaseAddress,
  125. IN PVOID UserBuffer,
  126. IN ULONG TransferCount,
  127. OUT PULONG BytesRead);
  128. virtual HRESULT WriteUncached(IN ULONG64 BaseAddress,
  129. IN PVOID UserBuffer,
  130. IN ULONG TransferCount,
  131. OUT PULONG BytesWritten);
  132. };
  133. #endif // #ifndef __MCACHE_HPP__