Source code of Windows XP (NT5)
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.

175 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. dbgnew.cxx
  6. Abstract:
  7. Debug new
  8. Author:
  9. Steve Kiraly (SteveKi) 23-June-1998
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "dbgnewp.hxx"
  15. namespace
  16. {
  17. TDebugNewAllocator DebugNew;
  18. UINT DebugNewCrtEnabled;
  19. }
  20. extern "C"
  21. BOOL
  22. TDebugNew_CrtMemoryInitalize(
  23. VOID
  24. )
  25. {
  26. //
  27. // Indicated that debugging memory support is enabled.
  28. //
  29. return DebugNewCrtEnabled++;
  30. }
  31. extern "C"
  32. BOOL
  33. TDebugNew_IsCrtMemoryInitalized(
  34. VOID
  35. )
  36. {
  37. //
  38. // Is debugging memory support is enabled.
  39. //
  40. return DebugNewCrtEnabled > 0;
  41. }
  42. extern "C"
  43. BOOL
  44. TDebugNew_Initalize(
  45. IN UINT uHeapSizeHint
  46. )
  47. {
  48. //
  49. // Initialize the debug library, it not already initialized.
  50. //
  51. DebugLibraryInitialize();
  52. //
  53. // Hold the critical section while we access the heap.
  54. //
  55. TDebugCriticalSection::TLock CS( GlobalCriticalSection );
  56. //
  57. // Create the debug new class.
  58. //
  59. DebugNew.Initialize( uHeapSizeHint );
  60. //
  61. // Check if the Debug new class was initialize correctly.
  62. //
  63. return DebugNew.bValid();
  64. }
  65. extern "C"
  66. VOID
  67. TDebugNew_Destroy(
  68. VOID
  69. )
  70. {
  71. //
  72. // Initialize the debug library, it not already initialized.
  73. //
  74. DebugLibraryInitialize();
  75. //
  76. // Hold the critical section while we access the heap.
  77. //
  78. TDebugCriticalSection::TLock CS( GlobalCriticalSection );
  79. //
  80. // Destroy the debug new class.
  81. //
  82. DebugNew.Destroy();
  83. }
  84. extern "C"
  85. PVOID
  86. TDebugNew_New(
  87. IN SIZE_T Size,
  88. IN PVOID pVoid,
  89. IN LPCTSTR pszFile,
  90. IN UINT uLine
  91. )
  92. {
  93. //
  94. // Initialize the debug library, it not already initialized.
  95. //
  96. DebugLibraryInitialize();
  97. //
  98. // Hold the critical section while we access the heap.
  99. //
  100. TDebugCriticalSection::TLock CS( GlobalCriticalSection );
  101. //
  102. // Return the allocated memory.
  103. //
  104. return DebugNew.Allocate( Size, pVoid, pszFile, uLine );
  105. }
  106. extern "C"
  107. VOID
  108. TDebugNew_Delete(
  109. IN PVOID pVoid
  110. )
  111. {
  112. //
  113. // Initialize the debug library, it not already initialized.
  114. //
  115. DebugLibraryInitialize();
  116. //
  117. // Hold the critical section while we access the heap.
  118. //
  119. TDebugCriticalSection::TLock CS( GlobalCriticalSection );
  120. //
  121. // Return the allocated memory.
  122. //
  123. DebugNew.Release( pVoid );
  124. }
  125. extern "C"
  126. VOID
  127. TDebugNew_Report(
  128. VOID
  129. )
  130. {
  131. //
  132. // Initialize the debug library, it not already initialized.
  133. //
  134. DebugLibraryInitialize();
  135. //
  136. // Hold the critical section while we access the heap.
  137. //
  138. TDebugCriticalSection::TLock CS( GlobalCriticalSection );
  139. //
  140. // Return the allocated memory.
  141. //
  142. DebugNew.Report( 0, NULL );
  143. }