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.

224 lines
5.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: reserved.hxx
  7. //
  8. // Contents: Definition for class to handle reserved memory for
  9. // property operation.
  10. //
  11. // Classes: CWin32ReservedMemory
  12. // CWin31ReservedMemory
  13. //
  14. // History: 07-Jun-92 BillMo Created.
  15. // 29-Aug-96 MikeHill Split CReservedMemory into CWin31 & CWin32
  16. //
  17. //--------------------------------------------------------------------------
  18. #ifndef _RESERVED_HXX_
  19. #define _RESERVED_HXX_
  20. #include <ole.hxx>
  21. #include <df32.hxx> // for SIZEOF_ACL
  22. //+-------------------------------------------------------------------------
  23. //
  24. // Class: CReservedMemory
  25. //
  26. // Purpose: Provide a memory reservation mechanism. Once initialized,
  27. // a pointer to the memory can be retrieved with the Lock
  28. // which obviously locks the buffer as well.
  29. //
  30. //--------------------------------------------------------------------------
  31. class CReservedMemory
  32. {
  33. public:
  34. virtual ~CReservedMemory() {};
  35. public:
  36. virtual HRESULT Init(VOID) = 0;
  37. virtual BYTE * LockMemory(VOID) = 0;
  38. virtual VOID UnlockMemory(VOID) = 0;
  39. };
  40. //+----------------------------------------------------------------------------
  41. //
  42. // Class: CWin32ReservedMemory
  43. //
  44. // Purpose: Defines a derivation of CReservedMemory which can be
  45. // used in a Win32 environment.
  46. //
  47. // History: In win 3.1, it was vitally important that docfile
  48. // be able to save to the same or a new file without requiring
  49. // any new memory allocations. This can't be guaranteed any longer
  50. // in NT, since other parts of the system don't adhere to it, but
  51. // the docfile code still sticks to the guarantee within itself.
  52. // The property set code tries to follow this requirement as well.
  53. // When a property set is grown, the implementation needs to realloc
  54. // a larger buffer. If it cannot, it falls back on the "reserved"
  55. // memory represented by this class. That memory comes from a
  56. // temporary file which is created when necessary.
  57. //
  58. //+----------------------------------------------------------------------------
  59. #ifndef _MAC
  60. class CWin32ReservedMemory : public CReservedMemory
  61. {
  62. // Constructors.
  63. public:
  64. CWin32ReservedMemory()
  65. {
  66. _hFile = INVALID_HANDLE_VALUE;
  67. _hMapping = NULL;
  68. _pb = NULL;
  69. _fInitialized = FALSE;
  70. _pCreatorOwner = NULL;
  71. _cInits = 0;
  72. }
  73. ~CWin32ReservedMemory();
  74. // Public overrides
  75. public:
  76. HRESULT Init(VOID)
  77. {
  78. if (!_fInitialized)
  79. return(_Init());
  80. else
  81. return(S_OK);
  82. }
  83. BYTE * LockMemory(VOID);
  84. VOID UnlockMemory(VOID);
  85. // Internal methods
  86. private:
  87. HRESULT _Init(VOID);
  88. void FreeResources();
  89. // Internal data
  90. private:
  91. // The temporary file
  92. HANDLE _hFile;
  93. // A mapping of the temporary file
  94. HANDLE _hMapping;
  95. // A view of the mapping.
  96. BYTE * _pb;
  97. // A critsec and a flag to show if it's initialized.
  98. BOOL _fInitialized;
  99. CRITICAL_SECTION _critsec;
  100. // A counter to guarantee that this (global) class is
  101. // only initialized once.
  102. LONG _cInits;
  103. // The DACL to set on the temporary file.
  104. struct
  105. {
  106. ACL acl;
  107. BYTE rgb[ SIZEOF_ACL - sizeof(ACL) ];
  108. } _DaclBuffer;
  109. // Other structures necessary to put a DACL on the temp file.
  110. PSID _pCreatorOwner;
  111. SECURITY_ATTRIBUTES _secattr;
  112. SECURITY_DESCRIPTOR _sd;
  113. };
  114. #endif // #ifndef _MAC
  115. //+----------------------------------------------------------------------------
  116. //
  117. // Class: CWin31ReservedMemory
  118. //
  119. // Purpose: This derivation of CReservedMemory assumes the Win 3.1
  120. // architecture of shared-memory DLLs and cooperative multi-threading.
  121. //
  122. // This class assumes that the g_pbPropSetReserved extern is a
  123. // large enough buffer for the largest property set.
  124. // Note that on the Mac, g_pbPropSetReserved should exist in
  125. // a shared-data library, so that there need not be one
  126. // Reserved buffer per instance of the property set library.
  127. //
  128. //+----------------------------------------------------------------------------
  129. #ifdef _MAC
  130. class CWin31ReservedMemory : public CReservedMemory
  131. {
  132. // Constructors
  133. public:
  134. CWin31ReservedMemory()
  135. {
  136. #if DBG==1
  137. _fLocked = FALSE;
  138. #endif
  139. }
  140. ~CWin31ReservedMemory()
  141. {
  142. DfpAssert( !_fLocked );
  143. }
  144. // Public overrides
  145. public:
  146. HRESULT Init(VOID)
  147. {
  148. return(S_OK);
  149. }
  150. BYTE * LockMemory(VOID);
  151. VOID UnlockMemory(VOID);
  152. // Private data
  153. private:
  154. #if DBG==1
  155. BOOL _fLocked;
  156. #endif
  157. };
  158. #endif // #ifdef _MAC
  159. //
  160. // Provide an extern for the instantiation of CReservedMemory.
  161. // We use the CWin31 class on the Mac, and the CWin32 everywhere
  162. // else. Also, along with the CWin31 extern, we must extern
  163. // the global reserved memory buffer.
  164. //
  165. #ifdef _MAC
  166. EXTERN_C long g_pbPropSetReserved[];
  167. extern CWin31ReservedMemory g_ReservedMemory;
  168. #else
  169. extern CWin32ReservedMemory g_ReservedMemory;
  170. #endif
  171. #endif // #ifndef _RESERVED_HXX_