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.

117 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 1995-1996 Microsoft Corporation
  3. Module Name:
  4. PXDebug.c
  5. Abstract:
  6. This module contains all debug-related code.
  7. Revision History:
  8. Who When What
  9. -------- -------- ----------------------------------------------
  10. rmachin 11-01-96 stolen from ArvindM's cmadebug file
  11. TonyBe 02-21-99 re-work/re-write
  12. Notes:
  13. --*/
  14. #include <precomp.h>
  15. #define MODULE_NUMBER MODULE_DEBUG
  16. #define _FILENUMBER 'BDXP'
  17. #if DBG
  18. ULONG PXDebugLevel = PXD_ERROR;
  19. ULONG PXDebugMask = PXM_ALL;
  20. LIST_ENTRY PxdMemoryList;
  21. ULONG PxdAllocCount = 0; // how many allocated so far (unfreed)
  22. NDIS_SPIN_LOCK PxdMemoryLock;
  23. BOOLEAN PxdInitDone = FALSE;
  24. PVOID
  25. PxAuditAllocMem(
  26. PVOID pPointer,
  27. ULONG Size,
  28. ULONG Tag,
  29. ULONG FileNumber,
  30. ULONG LineNumber
  31. )
  32. {
  33. PVOID pBuffer = NULL;
  34. PPXD_ALLOCATION pAllocInfo;
  35. NDIS_STATUS Status;
  36. if(!PxdInitDone) {
  37. NdisAllocateSpinLock(&(PxdMemoryLock));
  38. InitializeListHead(&PxdMemoryList);
  39. PxdInitDone = TRUE;
  40. }
  41. pAllocInfo = ExAllocatePoolWithTag(NonPagedPool,
  42. Size+sizeof(PXD_ALLOCATION),
  43. Tag);
  44. if (pAllocInfo != NULL) {
  45. pBuffer = (PVOID)&(pAllocInfo->UserData);
  46. NdisFillMemory(pBuffer, Size, 0xAF);
  47. pAllocInfo->Signature = PXD_MEMORY_SIGNATURE;
  48. pAllocInfo->FileNumber = FileNumber;
  49. pAllocInfo->LineNumber = LineNumber;
  50. pAllocInfo->Size = Size;
  51. pAllocInfo->Location = (ULONG_PTR)pPointer;
  52. NdisAcquireSpinLock(&(PxdMemoryLock));
  53. InsertTailList(&PxdMemoryList, &pAllocInfo->Linkage);
  54. PxdAllocCount++;
  55. NdisReleaseSpinLock(&(PxdMemoryLock));
  56. }
  57. return (pBuffer);
  58. }
  59. VOID
  60. PxAuditFreeMem(
  61. PVOID Pointer
  62. )
  63. {
  64. PPXD_ALLOCATION pAllocInfo;
  65. pAllocInfo = CONTAINING_RECORD(Pointer, PXD_ALLOCATION, UserData);
  66. if(pAllocInfo->Signature != PXD_MEMORY_SIGNATURE)
  67. {
  68. DbgPrint("PxAuditFreeMem: unknown buffer 0x%x!\n", Pointer);
  69. DbgBreakPoint();
  70. return;
  71. }
  72. NdisAcquireSpinLock(&(PxdMemoryLock));
  73. pAllocInfo->Signature = (ULONG)'DEAD';
  74. RemoveEntryList(&pAllocInfo->Linkage);
  75. PxdAllocCount--;
  76. NdisReleaseSpinLock(&(PxdMemoryLock));
  77. ExFreePool(pAllocInfo);
  78. }
  79. #endif // DBG