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.

109 lines
3.6 KiB

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