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.

195 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. memcheck
  5. Abstract:
  6. This header file provides access to the memory allocation debugging
  7. utilities.
  8. Author:
  9. Doug Barlow (dbarlow) 9/29/1995
  10. Environment:
  11. Win32
  12. Notes:
  13. --*/
  14. #ifndef _MEMCHECK_H_
  15. #define _MEMCHECK_H_
  16. #if DBG
  17. #if ((!defined (OS_WINCE)) || (_WIN32_WCE > 300))
  18. #ifdef __cplusplus
  19. #include <iostream.h> // Just in case it's not anywhere else.
  20. extern "C" {
  21. #else // __cplusplus
  22. #include <stdio.h> // Just in case it's not anywhere else.
  23. #endif // __cplusplus
  24. #else
  25. #include <stdio.h>
  26. #endif
  27. //-----------------------------------------------------------------------------
  28. //
  29. // Function prototype
  30. //
  31. //-----------------------------------------------------------------------------
  32. extern BOOL
  33. debugGbl; // Whether or not to print breakpoint status.
  34. extern void
  35. Breakpoint( // A convienient spot for a breakpoint.
  36. void);
  37. extern LPVOID
  38. AllocateMemory( // Memory manipulation routines.
  39. DWORD bytes,
  40. LPCTSTR allocator);
  41. extern LPVOID
  42. ReallocateMemory(
  43. LPVOID mem,
  44. DWORD bytes);
  45. extern LPVOID
  46. FreeMemory(
  47. LPVOID mem);
  48. LPCTSTR
  49. typeMemory( // Show the reason for allocation.
  50. LPVOID mem);
  51. extern void
  52. DisplayMemory( // Report statistics on allocated memory.
  53. void);
  54. BOOL
  55. ValidateMemory( // Check out the allocations
  56. void);
  57. #if ((!defined (OS_WINCE)) || (_WIN32_WCE > 300))
  58. #ifdef __cplusplus
  59. }
  60. #ifdef _MSVC
  61. extern void
  62. SetReason(
  63. LPCTSTR szWhy);
  64. extern void *
  65. ::operator new(
  66. size_t size);
  67. extern void
  68. ::operator delete(
  69. void *obj);
  70. #endif
  71. #endif __cplusplus
  72. #endif
  73. #else // _DEBUG
  74. #ifdef __cplusplus
  75. extern "C" {
  76. #endif // __cplusplus
  77. extern LPVOID
  78. AllocateMemory(
  79. DWORD bytes);
  80. extern LPVOID
  81. ReallocateMemory(
  82. LPVOID mem,
  83. DWORD bytes);
  84. extern LPVOID
  85. FreeMemory(
  86. LPVOID mem);
  87. #ifdef __cplusplus
  88. }
  89. #endif // __cplusplus
  90. #endif // _DEBUG
  91. #ifdef TRACE
  92. #undef TRACE // Get rid of any conflicting definitions.
  93. #endif
  94. #ifdef ASSERT
  95. #undef ASSERT
  96. #endif
  97. #if defined(_DEBUG) && defined (_MSVC)
  98. #define breakpoint Breakpoint()
  99. #ifdef __cplusplus
  100. #define TRACE(aMessage) cout << aMessage << endl;
  101. #define ASSERT(aTruism) if (!(aTruism)) { \
  102. TRACE("Assertion failed:\n " << #aTruism << "\n module " << __FILE__ << " line " << __LINE__) \
  103. breakpoint; }
  104. #define NEWReason(x) SetReason(x);
  105. #define DECLARE_NEW \
  106. void *operator new(size_t size); \
  107. void operator delete(void *obj);
  108. #define IMPLEMENT_NEW(cls) \
  109. void * cls::operator new(size_t size) { \
  110. return (cls *)AllocateMemory(size, #cls " Object"); } \
  111. void cls::operator delete(void *obj) { \
  112. FreeMemory(obj); }
  113. #define IMPLEMENT_INLINE_NEW(cls) \
  114. inline void * cls::operator new(size_t size) { \
  115. return (cls *)AllocateMemory(size, #cls " Object"); } \
  116. inline void cls::operator delete(void *obj) { \
  117. FreeMemory(obj); }
  118. #else
  119. #define TRACE(aMessage) (void)printf aMessage, fflush(stdout);
  120. #define ASSERT(aTruism) if (!(aTruism)) { \
  121. TRACE(("Assertion failed:\n %s\n module %s, line %d\n", #aTruism, __FILE__, __LINE__)) \
  122. breakpoint; }
  123. #endif
  124. #define allocateMemory(aLocation, aType, aSize, aReason) \
  125. aLocation = (aType)AllocateMemory(aSize, aReason)
  126. #define reallocateMemory(aLocation, aType, aSize) \
  127. aLocation = (aType)ReallocateMemory(aLocation, aSize)
  128. #define freeMemory(aLocation, aType) \
  129. aLocation = (aType)FreeMemory(aLocation)
  130. #define displayMemory DisplayMemory()
  131. #else
  132. #define breakpoint
  133. #define TRACE(aMessage)
  134. #define ASSERT(aTruism)
  135. #ifdef __cplusplus
  136. #define NEWReason(x)
  137. #define DECLARE_NEW
  138. #define IMPLEMENT_NEW(cls)
  139. #endif
  140. #define allocateMemory(aLocation, aType, aSize, aReason) \
  141. aLocation = (aType)GlobalAlloc(GMEM_FIXED, aSize)
  142. #define reallocateMemory(aLocation, aType, aSize) \
  143. aLocation = (aType)GlobalReAlloc(aLocation, aSize, 0)
  144. #define freeMemory(aLocation, aType) \
  145. aLocation = (aType)GlobalFree(aLocation)
  146. #define displayMemory
  147. #endif // _DEBUG
  148. #endif // _MEMCHECK_H_
  149. // End memcheck.h