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.

108 lines
3.2 KiB

  1. //+---------------------------------------------------------------------------
  2. // File: alocdbg.h
  3. //
  4. // Contents: Heap debugging structures and routines for the heap code
  5. // in commnot
  6. //
  7. // History: 28-Oct-92 IsaacHe Created
  8. // 23-Jan-95 KevinRo Moved into cairole\ih and renamed
  9. //
  10. //----------------------------------------------------------------------------
  11. //
  12. // We keep a stack backtrace for each allocated block of memory. DEPTHTRACE
  13. // is the number of frames that we record
  14. //
  15. #define DEPTHTRACE 26 // depth of stack backtraces
  16. //
  17. // The AllocArena structure has this signature at its front. We put a
  18. // signature on the structure to allow external processes to snapshot the
  19. // debug information and do some minimal check to see they are looking at the
  20. // right stuff
  21. //
  22. const char HEAPSIG[] = { 'H', 'E', 'P', DEPTHTRACE };
  23. // We keep track of the stack backtraces of allocation calls
  24. // in these structues.
  25. struct HeapAllocRec {
  26. DWORD sum; // checksum of stack backtrace
  27. void *fTrace[ DEPTHTRACE ]; // stack backtrace
  28. DWORD count; // # of un-freed allocs from this place
  29. size_t bytes; // # of un-freed bytes from this place
  30. struct AllocArena *paa; // points back to the beginning...
  31. struct {
  32. DWORD count; // # of allocs from this place
  33. size_t bytes; // # of bytes from this place
  34. } total;
  35. union {
  36. struct HeapAllocRec *next; // next bucket in the hash list
  37. void *ImageBase; // base addr of containing module
  38. } u;
  39. };
  40. struct AllocArena {
  41. char Signature [ sizeof(HEAPSIG) ];
  42. char comment[ 32 ];
  43. CRITICAL_SECTION csExclusive; // ensures single writer
  44. struct {
  45. int KeepStackTrace:1; // are stack records being kept?
  46. } flags;
  47. ULONG cAllocs; // # of non zero Alloc calls
  48. ULONG czAllocs; // # of Alloc calls w/zero count
  49. ULONG cFrees; // # of Free calls
  50. ULONG cReAllocs; // # of realloc calls
  51. ULONG cMissed; // # of missed stack backtraces
  52. ULONG cRecords; // index of next free AllocRec entry
  53. size_t cBytesNow; // # of bytes currently allocated
  54. size_t cBytesTotal; // # of bytes ever allocated
  55. ULONG cTotalRecords; // Total # of AllocRecs
  56. ULONG cPaths; // # of distinct allocation paths
  57. struct {
  58. ULONG total[ 32 ]; // total number of allocations
  59. ULONG now[ 32 ]; // current # of simul allocs
  60. ULONG simul[ 32 ]; // highest # of simul allocs
  61. } Histogram;
  62. struct HeapAllocRec AllocRec[1]; // vector of records starts here..
  63. };
  64. /*
  65. * Allocators may want to associate one of these structures with every
  66. * allocation...
  67. */
  68. struct AHeader {
  69. struct HeapAllocRec FAR *p;
  70. size_t size;
  71. };
  72. STDAPI_(struct AllocArena ** )
  73. AllocArenaAddr( void );
  74. STDAPI_( struct AllocArena * )
  75. AllocArenaCreate( DWORD memctx, char FAR *comment );
  76. STDAPI_( struct HeapAllocRec FAR * )
  77. AllocArenaRecordAlloc( struct AllocArena *paa, size_t bytes );
  78. STDAPI_(void)
  79. AllocArenaRecordReAlloc( struct HeapAllocRec FAR *vp,
  80. size_t oldbytes, size_t newbytes );
  81. STDAPI_(void)
  82. AllocArenaRecordFree( struct HeapAllocRec FAR *vp, size_t bytes );
  83. STDAPI_(void)
  84. AllocArenaDump( struct AllocArena *paa, BOOL fDumpSymbols );
  85. STDAPI_( void )
  86. AllocArenaDumpRecord( struct HeapAllocRec FAR *bp, BOOL fDumpSymbols );
  87. // This is our interface to symhelp for address translation
  88. ULONG RealTranslate ( ULONG address, LPSTR name, ULONG maxNameLength);