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.

105 lines
3.7 KiB

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