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.

219 lines
5.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: pmmstrm.hxx
  7. //
  8. // Contents: Memory Mapped Stream protocol
  9. //
  10. // Classes: PMmStream
  11. //
  12. // History: 08-Jul-93 BartoszM Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. //+-------------------------------------------------------------------------
  17. //
  18. // Function: CommonPageRound, public
  19. //
  20. // Synopsis: Round number up to multiple of common page size
  21. //
  22. // Arguments: [cb] - number
  23. //
  24. // History: 10-Mar-93 BartoszM Created
  25. //
  26. //--------------------------------------------------------------------------
  27. inline ULONG CommonPageRound ( ULONG cb )
  28. {
  29. return ( cb + (COMMON_PAGE_SIZE-1) ) & ~(COMMON_PAGE_SIZE-1);
  30. }
  31. inline ULONG CommonPageTrunc ( ULONG cb )
  32. {
  33. return( cb & ~(COMMON_PAGE_SIZE-1));
  34. }
  35. //+-------------------------------------------------------------------------
  36. //
  37. // Function: CommonPageRound, public
  38. //
  39. // Synopsis: Round number up to multiple of common page size
  40. //
  41. // Arguments: [cbLow] - low part of the number
  42. // [cbHigh] - high part
  43. //
  44. // History: 19-Mar-93 BartoszM Created
  45. //
  46. //--------------------------------------------------------------------------
  47. inline void CommonPageRound ( ULONG& cbLow, ULONG& cbHigh )
  48. {
  49. if (cbLow > ((0xffffffff & ~(COMMON_PAGE_SIZE-1)) + 1))
  50. {
  51. cbLow = 0;
  52. cbHigh++;
  53. }
  54. else
  55. {
  56. cbLow = (cbLow + (COMMON_PAGE_SIZE-1) ) & ~(COMMON_PAGE_SIZE-1);
  57. }
  58. }
  59. inline
  60. LONGLONG
  61. llfromuls(
  62. IN const ULONG &ulLowPart,
  63. IN const ULONG &ulHighPart
  64. )
  65. {
  66. LARGE_INTEGER li = {ulLowPart, ulHighPart};
  67. return li.QuadPart;
  68. }
  69. class CMmStreamBuf;
  70. class PStorage;
  71. class CMemBuf;
  72. //+---------------------------------------------------------------------------
  73. //
  74. // Class: PMmStream
  75. //
  76. // Purpose: Memory Mapped Stream protocol
  77. //
  78. // History: 08-Jul-93 BartoszM Created
  79. //
  80. //----------------------------------------------------------------------------
  81. class PMmStream
  82. {
  83. public:
  84. virtual ~PMmStream() {}
  85. virtual BOOL Ok() = 0;
  86. virtual void Close() = 0;
  87. virtual void SetSize ( PStorage& storage,
  88. ULONG newSizeLow,
  89. ULONG newSizeHigh=0 ) = 0;
  90. virtual BOOL isEmpty() = 0;
  91. virtual LONGLONG Size() = 0;
  92. virtual ULONG SizeLow()=0;
  93. virtual ULONG SizeHigh()=0;
  94. virtual BOOL isWritable()=0;
  95. virtual void MapAll ( CMmStreamBuf& sbuf ) = 0;
  96. virtual void Map ( CMmStreamBuf& sbuf,
  97. ULONG cb = 0,
  98. ULONG offLow = 0,
  99. ULONG offHigh = 0,
  100. BOOL fMapForWrite = FALSE ) = 0;
  101. virtual void Unmap ( CMmStreamBuf& sbuf ) = 0;
  102. virtual void Flush ( CMmStreamBuf& sbuf, ULONG cb, BOOL fThrowOnFailure = TRUE ) = 0;
  103. virtual void FlushMetaData ( BOOL fThrowOnFailure = TRUE ) = 0;
  104. virtual ULONG ShrinkFromFront( ULONG firstPage, ULONG numPages ) { return 0; }
  105. virtual BOOL FStatusFileNotFound() { return FALSE; }
  106. virtual WCHAR const * GetPath() { return 0; }
  107. virtual NTSTATUS GetStatus() const
  108. {
  109. Win4Assert( !"not implemented" );
  110. return S_OK;
  111. }
  112. virtual void Read( void * pvBuffer, ULONGLONG oStart, DWORD cbToRead, DWORD & cbRead )
  113. {
  114. Win4Assert( !"not implemented" );
  115. }
  116. virtual void Write( void * pvBuffer, ULONGLONG oStart, DWORD cbToWrite )
  117. {
  118. Win4Assert( !"not implemented" );
  119. }
  120. };
  121. //+---------------------------------------------------------------------------
  122. //
  123. // Class: CMmStreamBuf
  124. //
  125. // Purpose: Memory Mapped Stream Buffer
  126. //
  127. // History: 10-Mar-93 BartoszM Created
  128. //
  129. //----------------------------------------------------------------------------
  130. class CMmStreamBuf
  131. {
  132. public:
  133. CMmStreamBuf() : _buf(0), _cb(0), _pStream(0) {}
  134. ~CMmStreamBuf()
  135. {
  136. if ( 0 != _buf && 0 != _pStream )
  137. _pStream->Unmap( *this );
  138. }
  139. void * Get() { return (void *)_buf; }
  140. ULONG Size() const { return _cb; }
  141. void SetSize( ULONG cb) { _cb = cb; }
  142. void SetBuf( void* buf ) { _buf = (BYTE *) buf; }
  143. void SetStream ( PMmStream* pStream ) { _pStream = pStream; }
  144. void PurgeFromWorkingSet( ULONG oPurge, ULONG cbPurged )
  145. {
  146. Win4Assert( 0 != _buf );
  147. // -1 for both means purge the entire stream
  148. if ( -1 == oPurge && -1 == cbPurged )
  149. {
  150. oPurge = 0;
  151. cbPurged = _cb;
  152. }
  153. //
  154. // nb: an undocumented fact is that calling VirtualUnlock on
  155. // unlocked pages will push the pages out of the working set
  156. //
  157. VirtualUnlock( _buf + oPurge, cbPurged );
  158. }
  159. PMmStream & GetStream() { return * _pStream; }
  160. void Flush( BOOL fThrowOnFailure )
  161. {
  162. _pStream->Flush( *this, _cb, fThrowOnFailure );
  163. }
  164. #ifdef CIEXTMODE
  165. void CiExtDump(void *ciExtSelf);
  166. #endif
  167. private:
  168. BYTE * _buf;
  169. ULONG _cb;
  170. PMmStream * _pStream;
  171. };