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.

125 lines
2.6 KiB

  1. /****************************************************************************/
  2. // dbg.c
  3. //
  4. // RDPDR debug code
  5. //
  6. // Copyright (C) 1998-2000 Microsoft Corp.
  7. /****************************************************************************/
  8. #include "precomp.hxx"
  9. #define TRC_FILE "dbg"
  10. #include "trc.h"
  11. #if DBG
  12. ULONG DebugBreakOnEntry = FALSE;
  13. //DWORD RefCount::_dwReferenceTraceIndex = 0xFFFFFFFF;
  14. //ReferenceTraceRecord RefCount::_TraceRecordList[kReferenceTraceMask + 1];
  15. typedef struct tagRDPDR_MEMHDR
  16. {
  17. ULONG magicNo;
  18. ULONG subTag;
  19. ULONG size;
  20. ULONG pad;
  21. } RDPDR_MEMHDR, *PRDPDR_MEMHDR;
  22. void *
  23. DrAllocatePool(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes, IN ULONG Tag)
  24. /*++
  25. Routine Description:
  26. Allocate from pool memory and add a tag.
  27. Arguments:
  28. size - Number of bytes to allocate.
  29. poolType - Type of pool memory being allocated.
  30. subTag - Subtag of DR_POOLTAG.
  31. Return Value:
  32. Pointer to allocated memory on success. Otherwise, NULL is returned.
  33. --*/
  34. {
  35. PRDPDR_MEMHDR hdr;
  36. PBYTE p;
  37. BEGIN_FN("DrAllocatePool");
  38. ASSERT(
  39. PoolType == NonPagedPool ||
  40. PoolType == NonPagedPoolMustSucceed ||
  41. PoolType == NonPagedPoolCacheAligned ||
  42. PoolType == NonPagedPoolCacheAlignedMustS ||
  43. PoolType == PagedPool ||
  44. PoolType == PagedPoolCacheAligned
  45. );
  46. hdr = (PRDPDR_MEMHDR)ExAllocatePoolWithTag(
  47. PoolType, NumberOfBytes + sizeof(RDPDR_MEMHDR),
  48. DR_POOLTAG
  49. );
  50. if (hdr != NULL) {
  51. hdr->magicNo = GOODMEMMAGICNUMBER;
  52. hdr->subTag = Tag;
  53. hdr->size = (ULONG)NumberOfBytes;
  54. p = (PBYTE)(hdr + 1);
  55. memset(p, UNITIALIZEDMEM, NumberOfBytes);
  56. return (void *)p;
  57. }
  58. else {
  59. return NULL;
  60. }
  61. }
  62. void
  63. DrFreePool(
  64. IN void *ptr
  65. )
  66. /*++
  67. Routine Description:
  68. Release memory allocated by a call to DrAllocatePool.
  69. Arguments:
  70. ptr - Block of memory allocated by a call to DrAllocatePool.
  71. Return Value:
  72. NA
  73. --*/
  74. {
  75. BEGIN_FN("DrFreePool");
  76. ASSERT(ptr != NULL);
  77. PRDPDR_MEMHDR hdr;
  78. //
  79. // Get a pointer to the header to the memory block.
  80. //
  81. hdr = (PRDPDR_MEMHDR)ptr;
  82. hdr--;
  83. //
  84. // Make sure the block is valid.
  85. //
  86. ASSERT(hdr->magicNo == GOODMEMMAGICNUMBER);
  87. //
  88. // Mark it as freed.
  89. //
  90. hdr->magicNo = FREEDMEMMAGICNUMBER;
  91. //
  92. // Scramble and free the memory.
  93. //
  94. memset(ptr, BADMEM, hdr->size);
  95. ExFreePool(hdr);
  96. }
  97. #endif