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.

290 lines
9.2 KiB

  1. #ifndef _ROCKALL_FRONT_END_HPP_
  2. #define _ROCKALL_FRONT_END_HPP_
  3. // Ruler
  4. // 1 2 3 4 5 6 7 8
  5. //345678901234567890123456789012345678901234567890123456789012345678901234567890
  6. /********************************************************************/
  7. /* */
  8. /* The standard layout. */
  9. /* */
  10. /* The standard layout for 'hpp' files for this code is as */
  11. /* follows: */
  12. /* */
  13. /* 1. Include files. */
  14. /* 2. Constants exported from the class. */
  15. /* 3. Data structures exported from the class. */
  16. /* 4. Forward references to other data structures. */
  17. /* 5. Class specifications (including inline functions). */
  18. /* 6. Additional large inline functions. */
  19. /* */
  20. /* Any portion that is not required is simply omitted. */
  21. /* */
  22. /********************************************************************/
  23. #include <stddef.h>
  24. /********************************************************************/
  25. /* */
  26. /* Memory allocation constants. */
  27. /* */
  28. /* The memory allocation constants are denote special situations */
  29. /* where optimizations are possible or failures have cccured. */
  30. /* */
  31. /********************************************************************/
  32. const int AllocationFailure = 0;
  33. const int GuardMask = (sizeof(void*)-1);
  34. const int GuardSize = sizeof(void*);
  35. const int GuardValue = 0xDeadBeef;
  36. const int HalfMegabyte = (512 * 1024);
  37. const int NoSize = -1;
  38. /********************************************************************/
  39. /* */
  40. /* Class forward references. */
  41. /* */
  42. /* We need to refer to the following classes before they are */
  43. /* fully specified so here we list them as forward references. */
  44. /* */
  45. /********************************************************************/
  46. class CACHE;
  47. class FIND;
  48. class HEAP;
  49. class NEW_PAGE;
  50. class ROCKALL_BACK_END;
  51. class THREAD_SAFE;
  52. /********************************************************************/
  53. /* */
  54. /* Linkage to the DLL. */
  55. /* */
  56. /* We need to compile the class specification slightly */
  57. /* differently if we are creating the heap DLL. */
  58. /* */
  59. /********************************************************************/
  60. #ifdef COMPILING_ROCKALL_DLL
  61. #define ROCKALL_DLL_LINKAGE __declspec(dllexport)
  62. #else
  63. #ifdef COMPILING_ROCKALL_LIBRARY
  64. #define ROCKALL_DLL_LINKAGE
  65. #else
  66. #define ROCKALL_DLL_LINKAGE __declspec(dllimport)
  67. #endif
  68. #endif
  69. /********************************************************************/
  70. /* */
  71. /* The memory allocation interface. */
  72. /* */
  73. /* The memory allocator can be configured in a wide variety */
  74. /* of ways to closely match the needs of specific programs. */
  75. /* The interface outlined here can be overloaded to support */
  76. /* whatever customization is necessary. */
  77. /* */
  78. /********************************************************************/
  79. class ROCKALL_DLL_LINKAGE ROCKALL_FRONT_END
  80. {
  81. public:
  82. //
  83. // Public types.
  84. //
  85. // A heap is constructed of a collection of
  86. // fixed sized buckets each with an associated
  87. // cache. The details of these buckets are
  88. // supplied to the heap using the following
  89. // structure.
  90. //
  91. typedef struct
  92. {
  93. int AllocationSize;
  94. int CacheSize;
  95. int ChunkSize;
  96. int PageSize;
  97. }
  98. CACHE_DETAILS;
  99. //
  100. // Public data.
  101. //
  102. // The internals linkages in a heap are built
  103. // dynamically during the execution of a heaps
  104. // constructor. The member that follow relate
  105. // to key internal classes.
  106. //
  107. CACHE **Array;
  108. CACHE *Caches;
  109. HEAP *Heap;
  110. NEW_PAGE *NewPage;
  111. FIND *PrivateFind;
  112. FIND *PublicFind;
  113. ROCKALL_BACK_END *RockallBackEnd;
  114. THREAD_SAFE *ThreadSafe;
  115. //
  116. // A heap constructor is required to preserve
  117. // a small amount of information for the heap
  118. // destructor.
  119. //
  120. bool GlobalDelete;
  121. int GuardWord;
  122. int NumberOfCaches;
  123. int TotalSize;
  124. //
  125. // Public functions.
  126. //
  127. // A heaps public interface consists of a number
  128. // of groups of related APIs.
  129. //
  130. ROCKALL_FRONT_END
  131. (
  132. CACHE_DETAILS *Caches1,
  133. CACHE_DETAILS *Caches2,
  134. int FindCacheSize,
  135. int FindCacheThreshold,
  136. int FindSize,
  137. int MaxFreeSpace,
  138. int *NewPageSizes,
  139. ROCKALL_BACK_END *NewRockallBackEnd,
  140. bool Recycle,
  141. bool SingleImage,
  142. int Stride1,
  143. int Stride2,
  144. bool ThreadSafeFlag
  145. );
  146. //
  147. // Manipulate allocations.
  148. //
  149. // The first group of functions manipulate
  150. // single or small arrays of allocations.
  151. //
  152. virtual bool Delete
  153. (
  154. void *Address,
  155. int Size = NoSize
  156. );
  157. virtual bool Details
  158. (
  159. void *Address,
  160. int *Space = NULL
  161. );
  162. virtual bool KnownArea( void *Address );
  163. virtual bool MultipleDelete
  164. (
  165. int Actual,
  166. void *Array[],
  167. int Size = NoSize
  168. );
  169. virtual bool MultipleNew
  170. (
  171. int *Actual,
  172. void *Array[],
  173. int Requested,
  174. int Size,
  175. int *Space = NULL,
  176. bool Zero = false
  177. );
  178. virtual void *New
  179. (
  180. int Size,
  181. int *Space = NULL,
  182. bool Zero = false
  183. );
  184. virtual void *Resize
  185. (
  186. void *Address,
  187. int NewSize,
  188. int Move = -64,
  189. int *Space = NULL,
  190. bool NoDelete = false,
  191. bool Zero = false
  192. );
  193. virtual bool Verify
  194. (
  195. void *Address = NULL,
  196. int *Space = NULL
  197. );
  198. //
  199. // Manipulate the heap.
  200. //
  201. // The second group of functions act upon a heap
  202. // as a whole.
  203. //
  204. virtual void DeleteAll( bool Recycle = true );
  205. virtual void LockAll( void );
  206. virtual bool Truncate( int MaxFreeSpace = 0 );
  207. virtual void UnlockAll( void );
  208. virtual bool Walk
  209. (
  210. bool *Active,
  211. void **Address,
  212. int *Space = NULL
  213. );
  214. virtual ~ROCKALL_FRONT_END( void );
  215. //
  216. // Public inline functions.
  217. //
  218. inline bool Available( void )
  219. { return (GuardWord == GuardValue); }
  220. inline bool Corrupt( void )
  221. { return (GuardWord != GuardValue); }
  222. protected:
  223. //
  224. // Protected inline functions.
  225. //
  226. // A heap needs to compute the size of certain
  227. // user supplied structures. This task is
  228. // performed by the following function.
  229. //
  230. int ComputeSize( char *Array,int Stride );
  231. //
  232. // Execptional situations.
  233. //
  234. // The third group of functions are called in
  235. // exceptional situations.
  236. //
  237. virtual void Exception( char *Message );
  238. //
  239. // We would like to allow access to the internal
  240. // heap allocation function from classes that
  241. // inherit from the heap. The memory supplied by
  242. // this function survies all heap operations and
  243. // is cleaned up as poart of heap deletion.
  244. //
  245. virtual void *SpecialNew( int Size );
  246. private:
  247. //
  248. // Disabled operations.
  249. //
  250. // All copy constructors and class assignment
  251. // operations are disabled.
  252. //
  253. ROCKALL_FRONT_END( const ROCKALL_FRONT_END & Copy );
  254. void operator=( const ROCKALL_FRONT_END & Copy );
  255. };
  256. #endif