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.

116 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. heapmgr.c
  5. Abstract:
  6. This module contains debugging routines for the MUP use of
  7. non-paged pool.
  8. Author:
  9. Manny Weiser (mannyw) 27-Jan-1992
  10. --*/
  11. #include "mup.h"
  12. #if MUPDBG
  13. LIST_ENTRY PagedPoolList = { &PagedPoolList, &PagedPoolList };
  14. typedef struct _POOL_HEADER {
  15. LIST_ENTRY ListEntry;
  16. ULONG RequestedSize;
  17. BLOCK_TYPE BlockType;
  18. PVOID Caller;
  19. PVOID CallersCaller;
  20. } POOL_HEADER, *PPOOL_HEADER;
  21. struct _MEMORY_STATISTICS {
  22. ULONG BytesInUse;
  23. ULONG TotalBytesAllocated;
  24. ULONG MaxBytesInUse;
  25. ULONG TotalBytesFreed;
  26. ULONG BlocksInUse;
  27. ULONG TotalBlocksAllocated;
  28. ULONG MaxBlocksInUse;
  29. ULONG TotalBlocksFreed;
  30. } MupMemoryUsage = { 0, 0, 0, 0, 0, 0, 0, 0 };
  31. #ifdef ALLOC_PRAGMA
  32. #pragma alloc_text( PAGE, MupAllocatePoolDebug )
  33. #pragma alloc_text( PAGE, MupFreePoolDebug )
  34. #endif
  35. PVOID
  36. MupAllocatePoolDebug (
  37. IN POOL_TYPE PoolType,
  38. IN CLONG BlockSize,
  39. IN BLOCK_TYPE BlockType
  40. )
  41. {
  42. PPOOL_HEADER header;
  43. KIRQL oldIrql;
  44. PAGED_CODE();
  45. header = FsRtlAllocatePool( PoolType, sizeof(POOL_HEADER) + BlockSize );
  46. header->RequestedSize = BlockSize;
  47. header->BlockType = BlockType;
  48. RtlGetCallersAddress( &header->Caller, &header->CallersCaller );
  49. ACQUIRE_LOCK( &MupDebugLock );
  50. InsertTailList( &PagedPoolList, &header->ListEntry );
  51. MupMemoryUsage.TotalBlocksAllocated += 1;
  52. MupMemoryUsage.BlocksInUse += 1;
  53. MupMemoryUsage.TotalBytesAllocated += BlockSize;
  54. MupMemoryUsage.BytesInUse += BlockSize;
  55. if ( MupMemoryUsage.BlocksInUse > MupMemoryUsage.MaxBlocksInUse ) {
  56. MupMemoryUsage.MaxBlocksInUse = MupMemoryUsage.BlocksInUse;
  57. }
  58. if ( MupMemoryUsage.BytesInUse > MupMemoryUsage.MaxBytesInUse ) {
  59. MupMemoryUsage.MaxBytesInUse = MupMemoryUsage.BytesInUse;
  60. }
  61. RELEASE_LOCK( &MupDebugLock );
  62. return (PVOID)(header + 1);
  63. } // MupAllocatePagedPoolDebug
  64. VOID
  65. MupFreePoolDebug (
  66. IN PVOID P
  67. )
  68. {
  69. PPOOL_HEADER header;
  70. KIRQL oldIrql;
  71. PAGED_CODE();
  72. header = (PPOOL_HEADER)P - 1;
  73. ACQUIRE_LOCK( &MupDebugLock );
  74. RemoveEntryList( &header->ListEntry );
  75. MupMemoryUsage.TotalBlocksFreed += 1;
  76. MupMemoryUsage.BlocksInUse -= 1;
  77. MupMemoryUsage.TotalBytesFreed += header->RequestedSize;
  78. MupMemoryUsage.BytesInUse -= header->RequestedSize;
  79. RELEASE_LOCK( &MupDebugLock );
  80. ExFreePool( header );
  81. } // MupFreePagedPoolDebug
  82. #endif // MUPDBG