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.

167 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. CellHeap.hxx
  5. Abstract:
  6. The header file for the cell heap.
  7. Author:
  8. Kamen Moutafov (kamenm) Dec 99 - Feb 2000
  9. Revision History:
  10. --*/
  11. #if _MSC_VER > 1000
  12. #pragma once
  13. #endif // _MSC_VER > 1000
  14. #ifndef __CELLHEAP_HXX__
  15. #define __CELLHEAP_HXX__
  16. #include <CellDef.hxx>
  17. #include <MutexWrp.hxx>
  18. const int NumberOfPagesPerSection = 16;
  19. NEW_SDICT(CellSection);
  20. class CellHeap
  21. {
  22. public:
  23. friend CellSection;
  24. friend void RPC_ENTRY I_RpcDoCellUnitTest(IN OUT void *p);
  25. CellHeap(IN OUT RPC_STATUS *Status);
  26. ~CellHeap(void);
  27. DebugFreeCell *AllocateCell(OUT CellTag *pCellTag);
  28. void FreeCell(IN void *cell, IN OUT CellTag *pCellTag);
  29. void RelocateCellIfPossible(IN OUT void **ppCell, IN OUT CellTag *pCellTag);
  30. // notifies the cell heap that a section was created
  31. RPC_STATUS SectionCreatedNotify(IN CellSection *pCellSection, IN DWORD *pRandomNumbers,
  32. IN DebugFreeCell *pFirstCell OPTIONAL, IN DebugFreeCell *pLastCell OPTIONAL);
  33. RPC_STATUS InitializeServerSideCellHeap(void);
  34. inline SECURITY_DESCRIPTOR *GetSecurityDescriptor(void)
  35. {
  36. ASSERT(SecurityDescriptor != NULL);
  37. return SecurityDescriptor;
  38. }
  39. inline void GetDebugCellIDFromDebugCell(DebugCellUnion *Cell, CellTag *DebugCellTag, DebugCellID *CellID)
  40. {
  41. CellSection *Section;
  42. ASSERT(Cell != NULL);
  43. ASSERT(DebugCellTag != NULL);
  44. ASSERT(CellID != NULL);
  45. CellID->SectionID = (short)*DebugCellTag;
  46. Section = CellHeapSections.Find(*DebugCellTag);
  47. ASSERT(Section != NULL);
  48. ASSERT((unsigned char *)Cell >= (unsigned char *)Section);
  49. ASSERT((unsigned char *)Cell < ((unsigned char *)Section) + gPageSize * Section->LastCommittedPage);
  50. CellID->CellID = (USHORT)(Cell - (DebugCellUnion *)Section);
  51. }
  52. #if DBG
  53. void AssertValid(void);
  54. #endif
  55. private:
  56. LIST_ENTRY FreeCellsList;
  57. LIST_ENTRY SectionsList;
  58. CellSection_DICT CellHeapSections;
  59. RPC_STATUS CreateSecurityDescriptor(void);
  60. void InsertNewPageSegmentInChain(DebugFreeCell *pFirstCell, DebugFreeCell *pLastCell);
  61. RPC_STATUS AllocateCellSection(BOOL fFirstSection);
  62. #if DBG
  63. inline int GetSectionCapacity(IN CellSection *pSection)
  64. {
  65. CellHeapMutex.VerifyOwned();
  66. return (NumberOfCellsPerFirstPageInSection
  67. + (pSection->LastCommittedPage - 1) * NumberOfCellsPerPageInSection);
  68. }
  69. RPC_STATUS OpenSection(OUT HANDLE *pHandle, OUT PVOID *pSection, IN DWORD *pSectionNumbers);
  70. #endif
  71. SECURITY_DESCRIPTOR *SecurityDescriptor; // holds pre-constructed security
  72. // attributes for new sections. If construction failed,
  73. // this may be 0
  74. CellSection *pFirstSection;
  75. static MUTEX *EffectiveCellHeapMutex;
  76. MutexWrap<EffectiveCellHeapMutex> CellHeapMutex;
  77. #if DBG
  78. static int NumberOfCellsPerFirstPageInSection;
  79. static int NumberOfCellsPerPageInSection;
  80. #endif
  81. };
  82. extern CellHeap *g_pCellHeap;
  83. extern BOOL g_fServerSideCellHeapInitialized;
  84. extern BOOL g_fClientSideDebugInfoEnabled;
  85. extern BOOL g_fServerSideDebugInfoEnabled;
  86. RPC_STATUS InitializeCellHeap(void);
  87. inline RPC_STATUS InitializeServerSideCellHeapIfNecessary(void)
  88. {
  89. if (g_fServerSideCellHeapInitialized)
  90. return RPC_S_OK;
  91. if (!g_fServerSideDebugInfoEnabled && !g_fClientSideDebugInfoEnabled)
  92. return RPC_S_OK;
  93. ASSERT(g_pCellHeap);
  94. return g_pCellHeap->InitializeServerSideCellHeap();
  95. }
  96. void GenerateSectionName(OUT RPC_CHAR *Buffer, IN int BufferLength, IN DWORD *pSectionNumbers OPTIONAL);
  97. inline DebugFreeCell *AllocateCell(OUT CellTag *pCellTag)
  98. {
  99. ASSERT(g_pCellHeap != NULL);
  100. ASSERT(g_fServerSideCellHeapInitialized);
  101. return g_pCellHeap->AllocateCell(pCellTag);
  102. }
  103. inline void FreeCell(IN void *cell, IN OUT CellTag *pCellTag)
  104. {
  105. ASSERT(g_pCellHeap != NULL);
  106. ASSERT(g_fServerSideCellHeapInitialized);
  107. g_pCellHeap->FreeCell(cell, pCellTag);
  108. }
  109. inline void RelocateCellIfPossible(IN OUT void **ppCell, IN OUT CellTag *pCellTag)
  110. {
  111. ASSERT(g_pCellHeap != NULL);
  112. ASSERT(g_fServerSideCellHeapInitialized);
  113. g_pCellHeap->RelocateCellIfPossible(ppCell, pCellTag);
  114. }
  115. inline void GetDebugCellIDFromDebugCell(DebugCellUnion *Cell, CellTag *DebugCellTag, DebugCellID *CellID)
  116. {
  117. ASSERT(g_pCellHeap != NULL);
  118. ASSERT(g_fServerSideCellHeapInitialized);
  119. g_pCellHeap->GetDebugCellIDFromDebugCell(Cell, DebugCellTag, CellID);
  120. }
  121. #endif