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.

132 lines
2.2 KiB

  1. //***************************************************************************
  2. //
  3. // debug.CPP
  4. //
  5. // Module: CDM Provider
  6. //
  7. // Purpose: Debugging routines
  8. //
  9. // Copyright (c) 2000 Microsoft Corporation
  10. //
  11. //***************************************************************************
  12. // @@BEGIN_DDKSPLIT
  13. #ifdef HEAP_DEBUG
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #endif
  18. // @@END_DDKSPLIT
  19. #include <windows.h>
  20. #include <stdio.h>
  21. #include "debug.h"
  22. void __cdecl DebugOut(char *Format, ...)
  23. {
  24. char Buffer[1024];
  25. va_list pArg;
  26. ULONG i;
  27. va_start(pArg, Format);
  28. i = _vsnprintf(Buffer, sizeof(Buffer), Format, pArg);
  29. OutputDebugString(Buffer);
  30. }
  31. // @@BEGIN_DDKSPLIT
  32. #ifdef HEAP_DEBUG
  33. PVOID MyHeap;
  34. PVOID WmipAlloc(
  35. IN ULONG Size
  36. )
  37. /*+++
  38. Routine Description:
  39. Internal memory allocator
  40. Arguments:
  41. Size is the number of bytes to allocate
  42. Return Value:
  43. pointer to alloced memory or NULL
  44. ---*/
  45. {
  46. PVOID p;
  47. if (MyHeap == NULL)
  48. {
  49. MyHeap = RtlCreateHeap(HEAP_GROWABLE |
  50. HEAP_GENERATE_EXCEPTIONS |
  51. HEAP_TAIL_CHECKING_ENABLED |
  52. HEAP_FREE_CHECKING_ENABLED,
  53. NULL,
  54. 0,
  55. 0,
  56. NULL,
  57. NULL);
  58. if (MyHeap == NULL)
  59. {
  60. WmipDebugPrint(("CDMPROV: Could not create debug heap\n"));
  61. return(NULL);
  62. }
  63. }
  64. WmipAssert(RtlValidateHeap(MyHeap,
  65. 0,
  66. NULL));
  67. p = RtlAllocateHeap(MyHeap,
  68. 0,
  69. Size);
  70. return(p);
  71. }
  72. void WmipFree(
  73. IN PVOID Ptr
  74. )
  75. /*+++
  76. Routine Description:
  77. Internal memory deallocator
  78. Arguments:
  79. Pointer to freed memory
  80. Return Value:
  81. void
  82. ---*/
  83. {
  84. WmipAssert(Ptr != NULL);
  85. WmipAssert(MyHeap != NULL);
  86. WmipAssert(RtlValidateHeap(MyHeap,
  87. 0,
  88. NULL));
  89. RtlFreeHeap(MyHeap,
  90. 0,
  91. Ptr);
  92. }
  93. void * __cdecl ::operator new(size_t Size)
  94. {
  95. return(WmipAlloc(Size));
  96. }
  97. void __cdecl ::operator delete(void *Ptr)
  98. {
  99. WmipFree(Ptr);
  100. }
  101. #endif
  102. // @@END_DDKSPLIT