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.

182 lines
5.8 KiB

  1. /* Copyright 1996 Microsoft */
  2. #ifndef _DBGMEMORY_
  3. #define _DBGMEMORY_
  4. #ifdef DEBUG
  5. #define DBGMEM_MEMORY 0x00
  6. #define DBGMEM_STRDUP 0x01
  7. #define DBGMEM_OBJECT 0x02
  8. #define DBGMEM_TRACED 0x04
  9. #define DBGMEM_UNKNOBJ 0x08
  10. #endif // DEBUG
  11. #define DML_TYPE_MAIN 0
  12. #define DML_TYPE_THREAD 1
  13. #define DML_TYPE_FRAME 2
  14. #define DML_TYPE_DOWNLOAD 3
  15. #define DML_TYPE_NAVIGATE 4
  16. #define DML_TYPE_MASK 0x0000000f
  17. #define DML_BEGIN 0x00000000
  18. #define DML_END 0x80000000
  19. #ifdef DEBUG
  20. EXTERN_C BOOL g_bUseNewLeakDetection;
  21. STDAPI_(void) MemLeakInit(UINT wFlags, LPCTSTR pszFile, UINT iLine);
  22. #define DebugMemLeak(wFlags) MemLeakInit(wFlags, TEXT(__FILE__), __LINE__)
  23. // shdocvw memory leak tracker...
  24. // void _DumpMemLeak( DWORD dwFlags ); // call DebugMemLeak instead!
  25. // stuff used to move memory ownership from one thread to another
  26. STDAPI_(void) remove_from_thread_memlist( DWORD dwThreadId, LPVOID pv );
  27. STDAPI_(void) transfer_to_thread_memlist( DWORD dwThread, LPVOID pv );
  28. STDAPI_(UINT) mem_thread_message( void );
  29. STDAPI_(void) received_for_thread_memlist( DWORD dwFlags, void * pData );
  30. #else
  31. #define DebugMemLeak(wFlags) (0)
  32. #endif
  33. typedef struct _leakmeminfo {
  34. HMODULE hmod; // which dll was it allocated from...
  35. void* pv;
  36. UINT cb;
  37. UINT nType;
  38. // DWORD adwCaller[4]; // for future
  39. LPCSTR pszFile; // file where memory block was allocced
  40. INT_PTR iLine; // line where memory block was allocced
  41. } LEAKMEMINFO, *PLEAKMEMINFO;
  42. typedef struct _IntelliLeakDumpCBFunctions
  43. {
  44. void (STDMETHODCALLTYPE *pfnDumpLeakedMemory)(PLEAKMEMINFO pmeminfo);
  45. LPWSTR (STDMETHODCALLTYPE *pfnGetLeakSymbolicName)(PLEAKMEMINFO pmeminfo, LPWSTR pwszBuf, int cchBuf);
  46. } INTELLILEAKDUMPCBFUNCTIONS;
  47. typedef struct _LeakDetectFunctions
  48. {
  49. HLOCAL (STDMETHODCALLTYPE * pfnTrcLocalAlloc)(UINT uFlags,
  50. UINT uBytes,
  51. LPCSTR pszFile,
  52. const int iLine );
  53. HLOCAL (STDMETHODCALLTYPE * pfnTrcLocalFree )(HLOCAL hMem );
  54. LPTSTR (STDMETHODCALLTYPE * pfnTrcStrDup )(LPTSTR lpSrch,
  55. LPCSTR pszFile,
  56. const int iLine);
  57. void (STDMETHODCALLTYPE * pfnDumpMemLeak )(DWORD wFlags);
  58. void (STDMETHODCALLTYPE * pfnDebugMemLeak)(UINT wFlags, LPCTSTR pszFile, UINT iLine);
  59. void (STDMETHODCALLTYPE * pfnreceived_for_thread_memlist)( DWORD dwFlags, void * pData );
  60. void (STDMETHODCALLTYPE * pfnremove_from_thread_memlist )( DWORD dwThreadId, LPVOID pv );
  61. UINT (STDMETHODCALLTYPE * pfnmem_thread_message )();
  62. void (STDMETHODCALLTYPE * pfnremove_from_memlist )(void *pv);
  63. void (STDMETHODCALLTYPE * pfnadd_to_memlist )(HMODULE hmod, void *pv, unsigned int nSize, UINT nType, LPCSTR pszFile, const INT_PTR iLine );
  64. void (STDMETHODCALLTYPE * pfnregister_hmod_intelli_dump)(HMODULE hmod, const INTELLILEAKDUMPCBFUNCTIONS*pildf);
  65. } LEAKDETECTFUNCS;
  66. #ifdef __cplusplus
  67. extern "C" { /* Assume C declarations for C++ */
  68. #endif
  69. STDAPI_(BOOL) GetLeakDetectionFunctionTable(LEAKDETECTFUNCS *pTable);
  70. #ifdef __cplusplus
  71. }
  72. #endif /* __cplusplus */
  73. #ifdef DEBUG
  74. // use the macros below
  75. STDAPI_(HLOCAL) _TrcLocalAlloc(
  76. UINT uFlags, // flags used in LocalAlloc
  77. UINT uBytes, // number of bytes to be allocated
  78. LPCSTR pszFile, // file which allocced memory
  79. const int iLine // line which allocced memory
  80. );
  81. STDAPI_(LPTSTR) _TrcStrDup(
  82. LPTSTR lpSrch, // pointer to string to StrDup
  83. LPCSTR pszFile, // file which allocced memory
  84. const int iLine // line which allocced memory
  85. );
  86. STDAPI_(HLOCAL) _TrcLocalFree(
  87. HLOCAL hMem // memory to be freed
  88. );
  89. STDAPI_(void) add_to_memlist(
  90. HMODULE hmod, // for secondary memory allocators...
  91. void *pv, // pointer to memory block
  92. unsigned int nSize, // size of memory block
  93. unsigned int nType, // what the possible use of the memory is
  94. LPCSTR pszFile, // file name
  95. const INT_PTR iLine // line number
  96. );
  97. STDAPI_(void) remove_from_memlist(
  98. void *pv // pointer to memory block
  99. );
  100. STDAPI_(void) register_intelli_dump(
  101. HMODULE hmod,
  102. const INTELLILEAKDUMPCBFUNCTIONS *pfns
  103. );
  104. #ifndef _NO_DBGMEMORY_REDEFINITION_
  105. #ifdef __cplusplus
  106. extern void* __cdecl operator new( size_t nSize, LPCSTR pszFile, const int iLine );
  107. #define new new( __FILE__, __LINE__ )
  108. #endif
  109. #endif // _NO_DBGMEMORY_REDEFINITIONS
  110. // use these macros
  111. #define TrcLocalAlloc( _uFlags, _uBytes ) \
  112. _TrcLocalAlloc( _uFlags, _uBytes, __FILE__, __LINE__ )
  113. #define TrcStrDup( _pSrc ) \
  114. _TrcStrDup( (LPTSTR)_pSrc, (LPCSTR)__FILE__, (const int)__LINE__ )
  115. #define TrcLocalFree( _hMem ) \
  116. _TrcLocalFree( _hMem )
  117. #define DbgAddToMemList( _pv ) \
  118. { \
  119. if ( _pv ) \
  120. add_to_memlist( 0, _pv, (UINT)LocalSize( _pv ), DBGMEM_TRACED, __FILE__, __LINE__ ); \
  121. }
  122. #define DbgRemoveFromMemList( _pv ) \
  123. remove_from_memlist( _pv )
  124. #else // DEBUG
  125. #define add_to_memlist(p) (0)
  126. #define remove_from_memlist(p) (0)
  127. #define remove_from_thread_memlist(p,v) (0)
  128. #define TrcLocalAlloc( _uFlags, _uBytes ) \
  129. LocalAlloc( _uFlags, _uBytes )
  130. #define TrcStrDup( _pSrc ) \
  131. StrDup( _pSrc )
  132. #define TrcLocalFree( _hMem ) \
  133. LocalFree( _hMem )
  134. #define DbgAddToMemList( _pv ) // NOP
  135. #define DbgRemoveFromMemList( _pv ) // NOP
  136. #endif // DEBUG
  137. #endif // _DBGMEMORY_