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.

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