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.

253 lines
8.1 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. debugmem.h
  5. Abstract:
  6. Header for debugmem.cxx
  7. Author:
  8. Richard L Firth (rfirth) 02-Feb-1995
  9. Revision History:
  10. 02-Feb-1995
  11. Created
  12. --*/
  13. #ifdef WINHTTP_FOR_MSXML
  14. #error include msxmlmem.h, not debugmem.h, for MSXML
  15. #endif
  16. #if defined(__cplusplus)
  17. extern "C" {
  18. #endif
  19. //
  20. // manifests
  21. //
  22. //
  23. // USE_PRIVATE_HEAP_IN_RETAIL - by default we use the process heap in the retail
  24. // build. Alternative is to use a private (wininet) heap (which we do in the
  25. // debug version if required)
  26. //
  27. #if !defined(USE_PRIVATE_HEAP_IN_RETAIL)
  28. #define USE_PRIVATE_HEAP_IN_RETAIL 0
  29. #endif
  30. //
  31. // prototypes
  32. //
  33. VOID
  34. InternetDebugMemInitialize(
  35. VOID
  36. );
  37. VOID
  38. InternetDebugMemTerminate(
  39. IN BOOL bReport
  40. );
  41. HLOCAL
  42. InternetDebugAllocMem(
  43. IN UINT Flags,
  44. IN UINT Size,
  45. IN LPSTR File,
  46. IN DWORD Line
  47. );
  48. HLOCAL
  49. InternetDebugFreeMem(
  50. IN HLOCAL hLocal,
  51. IN LPSTR File,
  52. IN DWORD Line
  53. );
  54. HLOCAL
  55. InternetDebugReAllocMem(
  56. IN HLOCAL hLocal,
  57. IN UINT Size,
  58. IN UINT Flags,
  59. IN LPSTR File,
  60. IN DWORD Line
  61. );
  62. SIZE_T
  63. InternetDebugSizeMem(
  64. IN HLOCAL hLocal,
  65. IN LPSTR File,
  66. IN DWORD Line
  67. );
  68. BOOL
  69. InternetDebugCheckMemFreed(
  70. IN BOOL bReport
  71. );
  72. BOOL
  73. InternetDebugMemReport(
  74. IN BOOL bTerminateSymbols,
  75. IN BOOL bCloseFile
  76. );
  77. //disable compilation with if two or more of USE_DEBUG_MEMORY, USE_ROCKALL or USE_LOWFRAGHEAP
  78. //defined at same time
  79. #if (defined(USE_DEBUG_MEMORY) && (defined(USE_ROCKALL) || defined(USE_LOWFRAGHEAP))) || (defined(USE_ROCKALL) && defined(USE_LOWFRAGHEAP))
  80. #error "Do not define USE_DEBUG_MEMORY, USE_ROCKALL or USE_LOWFRAGHEAP at same time"
  81. #endif
  82. //
  83. // macros
  84. //
  85. #if defined(USE_DEBUG_MEMORY)
  86. #define ALLOCATOR(Flags, Size) InternetDebugAllocMem(Flags, Size, __FILE__, __LINE__)
  87. #define DEALLOCATOR(hLocal) InternetDebugFreeMem(hLocal, __FILE__, __LINE__)
  88. #define REALLOCATOR(hLocal, Size, Flags) InternetDebugReAllocMem(hLocal, Size, Flags, __FILE__, __LINE__)
  89. #define MEMORYSIZER(hLocal) InternetDebugSizeMem(hLocal, __FILE__, __LINE__)
  90. #define INITIALIZE_MEMORY_MANAGER() InternetDebugMemInitialize()
  91. #define TERMINATE_MEMORY_MANAGER(bReport) InternetDebugMemTerminate(bReport)
  92. #define MEMORY_MANAGER_ON_THREAD_DETACH() /* NOTHING */
  93. #define CHECK_MEMORY_FREED(bReport) InternetDebugCheckMemFreed(bReport)
  94. #define REPORT_DEBUG_MEMORY(bTermSym, bCloseFile) InternetDebugMemReport(bTermSym, bCloseFile)
  95. #elif defined(USE_ROCKALL) //defined(USE_DEBUG_MEMORY)
  96. extern void INITIALIZE_MEMORY_MANAGER();
  97. extern void TERMINATE_MEMORY_MANAGER(BOOL bReport);
  98. extern void MEMORY_MANAGER_ON_THREAD_DETACH();
  99. extern void* ALLOCATOR(int Flags, int Size);
  100. extern void* DEALLOCATOR(void *hLocal);
  101. extern void* REALLOCATOR(void *hLocal, int Size, int Flags);
  102. extern int MEMORYSIZER(void *hLocal);
  103. #define CHECK_MEMORY_FREED(bReport) /* NOTHING */
  104. #define REPORT_DEBUG_MEMORY(bTermSym, bCloseFile) /* NOTHING */
  105. #elif defined(USE_LOWFRAGHEAP) //defined(USE_ROCKALL) //defined(USE_DEBUG_MEMORY)
  106. extern HANDLE g_hLowFragHeap;
  107. #if !INET_DEBUG && !defined(LFH_DEBUG)
  108. #define LFH_ALLOC(Flags, Size) HeapAlloc(g_hLowFragHeap, Flags, Size)
  109. #define LFH_FREE(ptr) HeapFree(g_hLowFragHeap, 0, ptr)
  110. #define LFH_REALLOC(Flags, ptr, Size) HeapReAlloc(g_hLowFragHeap, Flags, ptr, Size)
  111. #define LFH_SIZE(ptr) HeapSize(g_hLowFragHeap, 0, ptr)
  112. #else //!INET_DEBUG && !defined(LFH_DEBUG)
  113. extern PVOID LFHDebugAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T stSize);
  114. extern BOOL LFHDebugFree(HANDLE hHeap, DWORD dwFlags, PVOID ptr);
  115. extern PVOID LFHDebugReAlloc(HANDLE hHeap, DWORD dwFlags, PVOID ptr, SIZE_T stSize);
  116. extern SIZE_T LFHDebugSize(HANDLE hHeap, DWORD dwFlags, PVOID ptr);
  117. #define LFH_ALLOC(Flags, Size) LFHDebugAlloc(g_hLowFragHeap, Flags, Size)
  118. #define LFH_FREE(ptr) LFHDebugFree(g_hLowFragHeap, 0, ptr)
  119. #define LFH_REALLOC(Flags, ptr, Size) LFHDebugReAlloc(g_hLowFragHeap, Flags, ptr, Size)
  120. #define LFH_SIZE(ptr) LFHDebugSize(g_hLowFragHeap, 0, ptr)
  121. #endif //!INET_DEBUG && !defined(LFH_DEBUG)
  122. extern BOOL INITIALIZE_MEMORY_MANAGER();
  123. extern void TERMINATE_MEMORY_MANAGER(BOOL bReport);
  124. #define MEMORY_MANAGER_ON_THREAD_DETACH() /* NOTHING */
  125. #define CHECK_MEMORY_FREED(bReport) /* NOTHING */
  126. #define REPORT_DEBUG_MEMORY(bTermSym, bCloseFile) /* NOTHING */
  127. #else //defined(USE_LOWFRAGHEAP) //defined(USE_ROCKALL) //defined(USE_DEBUG_MEMORY)
  128. #define ALLOCATOR(Flags, Size) LocalAlloc(Flags, Size)
  129. #define DEALLOCATOR(hLocal) LocalFree(hLocal)
  130. #define REALLOCATOR(hLocal, Size, Flags) LocalReAlloc(hLocal, Size, Flags)
  131. #define MEMORYSIZER(hLocal) LocalSize(hLocal)
  132. #define INITIALIZE_MEMORY_MANAGER() /* NOTHING */
  133. #define TERMINATE_MEMORY_MANAGER(bReport) /* NOTHING */
  134. #define MEMORY_MANAGER_ON_THREAD_DETACH() /* NOTHING */
  135. #define CHECK_MEMORY_FREED(bReport) /* NOTHING */
  136. #define REPORT_DEBUG_MEMORY(bTermSym, bCloseFile) /* NOTHING */
  137. #endif //defined(USE_LOWFRAGHEAP) //defined(USE_ROCKALL) //defined(USE_DEBUG_MEMORY)
  138. #if defined(USE_ROCKALL)
  139. #define ALLOCATE_ZERO_MEMORY(Size) ALLOCATOR(LPTR, (UINT)(Size))
  140. #define ALLOCATE_FIXED_MEMORY(Size) ALLOCATOR(LMEM_FIXED, (UINT)(Size))
  141. #define ALLOCATE_MEMORY(Size) ALLOCATOR(LMEM_FIXED, (UINT)(Size))
  142. #define FREE_ZERO_MEMORY(hLocal) FREE_MEMORY((void*)(hLocal))
  143. #define FREE_FIXED_MEMORY(hLocal) FREE_MEMORY((void*)(hLocal))
  144. #define FREE_MEMORY(hLocal) DEALLOCATOR((void*)(hLocal))
  145. #define REALLOCATE_MEMORY(hLocal, Size) REALLOCATOR((void*)(hLocal), (UINT)(Size), LMEM_MOVEABLE)
  146. #define REALLOCATE_MEMORY_ZERO(hLocal, Size) REALLOCATOR((void*)(hLocal), (UINT)(Size), LMEM_MOVEABLE | LMEM_ZEROINIT)
  147. #define REALLOCATE_MEMORY_IN_PLACE(hLocal, Size, bZero) REALLOCATOR((void*)(hLocal), (UINT)(Size), (bZero) ? LMEM_ZEROINIT : 0)
  148. #define MEMORY_SIZE(hLocal) MEMORYSIZER((void*)(hLocal))
  149. #elif defined(USE_LOWFRAGHEAP) //defined(USE_ROCKALL)
  150. #define ALLOCATE_ZERO_MEMORY(Size) LFH_ALLOC(HEAP_ZERO_MEMORY, (SIZE_T)(Size))
  151. #define ALLOCATE_FIXED_MEMORY(Size) LFH_ALLOC(0, (SIZE_T)(Size))
  152. #define ALLOCATE_MEMORY(Size) LFH_ALLOC(0, (SIZE_T)(Size))
  153. #define FREE_ZERO_MEMORY(ptr) (LFH_FREE((PVOID)(ptr)), NULL)
  154. #define FREE_FIXED_MEMORY(ptr) (LFH_FREE((PVOID)(ptr)), NULL)
  155. #define FREE_MEMORY(ptr) (LFH_FREE((PVOID)(ptr)), NULL)
  156. #define REALLOCATE_MEMORY(ptr, Size) LFH_REALLOC(0, (PVOID)(ptr), (SIZE_T)(Size))
  157. #define REALLOCATE_MEMORY_ZERO(ptr, Size) LFH_REALLOC(HEAP_ZERO_MEMORY, (PVOID)(ptr), (SIZE_T)(Size))
  158. #define REALLOCATE_MEMORY_IN_PLACE(ptr, Size, bZero) LFH_REALLOC(HEAP_REALLOC_IN_PLACE_ONLY | ((bZero) ? HEAP_ZERO_MEMORY : 0), (PVOID)(ptr), (SIZE_T)(Size))
  159. #define MEMORY_SIZE(ptr) LFH_SIZE(0, (PVOID)ptr)
  160. #else //defined (USE_LOWFRAGHEAP) //defined(USE_ROCKALL)
  161. #define ALLOCATE_ZERO_MEMORY(Size) ALLOCATOR(LPTR, (UINT)(Size))
  162. #define ALLOCATE_FIXED_MEMORY(Size) ALLOCATOR(LMEM_FIXED, (UINT)(Size))
  163. #define ALLOCATE_MEMORY(Size) ALLOCATOR(LMEM_FIXED, (UINT)(Size))
  164. #define FREE_ZERO_MEMORY(hLocal) FREE_MEMORY((HLOCAL)(hLocal))
  165. #define FREE_FIXED_MEMORY(hLocal) FREE_MEMORY((HLOCAL)(hLocal))
  166. #define FREE_MEMORY(hLocal) DEALLOCATOR((HLOCAL)(hLocal))
  167. #define REALLOCATE_MEMORY(hLocal, Size) REALLOCATOR((HLOCAL)(hLocal), (UINT)(Size), LMEM_MOVEABLE)
  168. #define REALLOCATE_MEMORY_ZERO(hLocal, Size) REALLOCATOR((HLOCAL)(hLocal), (UINT)(Size), LMEM_MOVEABLE | LMEM_ZEROINIT)
  169. #define REALLOCATE_MEMORY_IN_PLACE(hLocal, Size, bZero) REALLOCATOR((HLOCAL)(hLocal), (UINT)(Size), (bZero) ? LMEM_ZEROINIT : 0)
  170. #define MEMORY_SIZE(hLocal) MEMORYSIZER((HLOCAL)(hLocal))
  171. #endif //defined (USE_LOWFRAGHEAP) //defined(USE_ROCKALL)
  172. #define New new
  173. #if defined(__cplusplus)
  174. }
  175. #endif
  176. //
  177. // Wininet no longer uses moveable memory
  178. //
  179. #define LOCK_MEMORY(p) (LPSTR)(p)
  180. #define UNLOCK_MEMORY(p)