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.

84 lines
2.6 KiB

  1. //-----------------------------------------------------------------------------
  2. // Microsoft OLE DB TABLECOPY Sample
  3. // Copyright (C) 1996 By Microsoft Corporation.
  4. //
  5. // @doc
  6. //
  7. // @module SPY.HXX
  8. //
  9. //-----------------------------------------------------------------------------
  10. #pragma once
  11. static const ALLOC_SIGNATURE = 'A';
  12. static const FREE_SIGNATURE = 'F';
  13. //ROUNDUP on all platforms pointers must be aligned properly
  14. #define ROUNDUP_AMOUNT 8
  15. #define ROUNDUP_(size,amount) (((ULONG)(size)+((amount)-1))&~((amount)-1))
  16. #define ROUNDUP(size) ROUNDUP_(size, ROUNDUP_AMOUNT)
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CMallocSpy
  19. //
  20. /////////////////////////////////////////////////////////////////////////////
  21. class CMallocSpy : public IMallocSpy
  22. {
  23. public:
  24. CMallocSpy(void);
  25. virtual ~CMallocSpy(void);
  26. //Interface
  27. virtual BOOL Add(void* pv);
  28. virtual BOOL Remove(void* pv);
  29. virtual BOOL DumpLeaks();
  30. // IUnknown methods
  31. virtual STDMETHODIMP QueryInterface(REFIID riid, void** ppIUnknown);
  32. virtual STDMETHODIMP_(ULONG) AddRef();
  33. virtual STDMETHODIMP_(ULONG) Release();
  34. // IMallocSpy methods
  35. //Alloc
  36. virtual STDMETHODIMP_(SIZE_T) PreAlloc(SIZE_T cbRequest);
  37. virtual STDMETHODIMP_(void*) PostAlloc(void *pActual);
  38. //Free
  39. virtual STDMETHODIMP_(void*) PreFree(void *pRequest, BOOL fSpyed);
  40. virtual STDMETHODIMP_(void ) PostFree(BOOL fSpyed);
  41. //Realloc
  42. virtual STDMETHODIMP_(SIZE_T) PreRealloc(void *pRequest, SIZE_T cbRequest, void **ppNewRequest, BOOL fSpyed);
  43. virtual STDMETHODIMP_(void*) PostRealloc(void *pActual, BOOL fSpyed);
  44. //GetSize
  45. virtual STDMETHODIMP_(void*) PreGetSize(void *pRequest, BOOL fSpyed);
  46. virtual STDMETHODIMP_(SIZE_T) PostGetSize(SIZE_T cbActual, BOOL fSpyed);
  47. //DidAlloc
  48. virtual STDMETHODIMP_(void*) PreDidAlloc(void *pRequest, BOOL fSpyed);
  49. virtual STDMETHODIMP_(BOOL) PostDidAlloc(void *pRequest, BOOL fSpyed, BOOL fActual);
  50. //HeapMinimize
  51. virtual STDMETHODIMP_(void ) PreHeapMinimize();
  52. virtual STDMETHODIMP_(void ) PostHeapMinimize();
  53. private:
  54. ULONG m_cRef; //Reference count
  55. SIZE_T m_cbRequest; //Bytes requested
  56. };
  57. /////////////////////////////////////////////////////////////////////////////
  58. // Registration
  59. //
  60. /////////////////////////////////////////////////////////////////////////////
  61. void MallocSpyRegister(CMallocSpy** ppCMallocSpy);
  62. void MallocSpyUnRegister(CMallocSpy* pCMallocSpy);
  63. void MallocSpyDump(CMallocSpy* pCMallocSpy);