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.

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