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.

186 lines
3.0 KiB

  1. #ifndef __Allocator_H
  2. #define __Allocator_H
  3. /*
  4. * Class:
  5. *
  6. * WmiAllocator
  7. *
  8. * Description:
  9. *
  10. * Provides abstraction above heap allocation functions
  11. *
  12. * Version:
  13. *
  14. * Initial
  15. *
  16. * Last Changed:
  17. *
  18. * See Source Depot for change history
  19. *
  20. */
  21. enum WmiStatusCode
  22. {
  23. e_StatusCode_Success = 0 ,
  24. e_StatusCode_Success_Timeout ,
  25. e_StatusCode_EnQueue,
  26. e_StatusCode_OutOfMemory = 0x80000000 ,
  27. e_StatusCode_OutOfResources ,
  28. e_StatusCode_NotInitialized ,
  29. e_StatusCode_AlreadyInitialized ,
  30. e_StatusCode_InvalidArgs ,
  31. e_StatusCode_OutOfBounds ,
  32. e_StatusCode_OutOfQuota ,
  33. e_StatusCode_Unknown ,
  34. e_StatusCode_NotFound ,
  35. e_StatusCode_AlreadyExists ,
  36. e_StatusCode_Failed ,
  37. e_StatusCode_ServicingThreadTerminated ,
  38. e_StatusCode_HostingThreadTerminated ,
  39. e_StatusCode_Change ,
  40. e_StatusCode_InvalidHeap
  41. } ;
  42. /*
  43. * Class:
  44. *
  45. * WmiAllocator
  46. *
  47. * Description:
  48. *
  49. * Provides abstraction above heap allocation functions
  50. *
  51. * Version:
  52. *
  53. * Initial
  54. *
  55. * Last Changed:
  56. *
  57. * See Source Depot for change history
  58. *
  59. */
  60. #ifndef __PLACEMENT_NEW_INLINE
  61. #define __PLACEMENT_NEW_INLINE
  62. inline void *__cdecl operator new ( size_t a_Size , void *a_Ptr ) { return a_Ptr ; }
  63. inline void __cdecl operator delete ( void * , void * ) { ; }
  64. #endif
  65. /*
  66. * Class:
  67. *
  68. * WmiAllocator
  69. *
  70. * Description:
  71. *
  72. * Provides abstraction above heap allocation functions
  73. *
  74. * Version:
  75. *
  76. * Initial
  77. *
  78. * Last Changed:
  79. *
  80. * See Source Depot for change history
  81. *
  82. */
  83. class WmiAllocator
  84. {
  85. public:
  86. enum AllocationOptions
  87. {
  88. e_GenerateException = HEAP_GENERATE_EXCEPTIONS ,
  89. e_NoSerialize = HEAP_NO_SERIALIZE ,
  90. e_ZeroMemory = HEAP_ZERO_MEMORY ,
  91. e_ReallocInPlace = HEAP_REALLOC_IN_PLACE_ONLY ,
  92. e_DefaultAllocation = 0
  93. } ;
  94. private:
  95. LONG m_ReferenceCount ;
  96. HANDLE m_Heap ;
  97. AllocationOptions m_Options ;
  98. size_t m_InitialSize ;
  99. size_t m_MaximumSize ;
  100. WmiStatusCode Win32ToApi () ;
  101. public:
  102. WmiAllocator () ;
  103. WmiAllocator (
  104. AllocationOptions a_Option ,
  105. size_t a_InitialSize ,
  106. size_t a_MaximumSize
  107. ) ;
  108. ~WmiAllocator () ;
  109. ULONG AddRef () ;
  110. ULONG Release () ;
  111. WmiStatusCode Initialize () ;
  112. WmiStatusCode UnInitialize () ;
  113. WmiStatusCode New (
  114. void **a_Allocation ,
  115. size_t a_Size
  116. ) ;
  117. WmiStatusCode New (
  118. AllocationOptions a_Option ,
  119. void **a_Allocation ,
  120. size_t a_Size
  121. ) ;
  122. WmiStatusCode ReAlloc (
  123. void *a_Allocation ,
  124. void **a_ReAllocation ,
  125. size_t a_Size
  126. ) ;
  127. WmiStatusCode ReAlloc (
  128. AllocationOptions a_Option ,
  129. void *a_Allocation ,
  130. void **a_ReAllocation ,
  131. size_t a_Size
  132. ) ;
  133. WmiStatusCode Delete (
  134. void *a_Allocation
  135. ) ;
  136. WmiStatusCode Size (
  137. void *a_Allocation ,
  138. size_t &a_Size
  139. ) ;
  140. WmiStatusCode Compact (
  141. size_t &a_LargestFreeBlock
  142. ) ;
  143. WmiStatusCode Validate (
  144. LPCVOID a_Location = NULL
  145. ) ;
  146. } ;
  147. #endif // __Allocator_H