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.

121 lines
2.8 KiB

  1. #include "ctlspriv.h"
  2. // Define some things for debug.h
  3. //
  4. #define SZ_DEBUGINI "ccshell.ini"
  5. #define SZ_DEBUGSECTION "comctlv6"
  6. #define SZ_MODULE "comctlv6"
  7. #define DECLARE_DEBUG
  8. #include <debug.h>
  9. //========== Memory Management =============================================
  10. //----------------------------------------------------------------------------
  11. // Define a Global Shared Heap that we use allocate memory out of that we
  12. // Need to share between multiple instances.
  13. void * WINAPI Alloc(long cb)
  14. {
  15. // I will assume that this is the only one that needs the checks to
  16. // see if the heap has been previously created or not
  17. return (void *)LocalAlloc(LPTR, cb);
  18. }
  19. void * WINAPI ReAlloc(void * pb, long cb)
  20. {
  21. if (pb == NULL)
  22. return Alloc(cb);
  23. return (void *)LocalReAlloc((HLOCAL)pb, cb, LMEM_ZEROINIT | LMEM_MOVEABLE);
  24. }
  25. BOOL WINAPI Free(void * pb)
  26. {
  27. return (LocalFree((HLOCAL)pb) == NULL);
  28. }
  29. DWORD_PTR WINAPI GetSize(void * pb)
  30. {
  31. return LocalSize((HLOCAL)pb);
  32. }
  33. //----------------------------------------------------------------------------
  34. // The following functions are for debug only and are used to try to
  35. // calculate memory usage.
  36. //
  37. #ifdef DEBUG
  38. typedef struct _HEAPTRACE
  39. {
  40. DWORD cAlloc;
  41. DWORD cFailure;
  42. DWORD cReAlloc;
  43. ULONG_PTR cbMaxTotal;
  44. DWORD cCurAlloc;
  45. ULONG_PTR cbCurTotal;
  46. } HEAPTRACE;
  47. HEAPTRACE g_htShell = {0}; // Start of zero...
  48. LPVOID WINAPI ControlAlloc(HANDLE hheap, DWORD cb)
  49. {
  50. LPVOID lp = HeapAlloc(hheap, HEAP_ZERO_MEMORY, cb);;
  51. if (lp == NULL)
  52. {
  53. g_htShell.cFailure++;
  54. return NULL;
  55. }
  56. // Update counts.
  57. g_htShell.cAlloc++;
  58. g_htShell.cCurAlloc++;
  59. g_htShell.cbCurTotal += cb;
  60. if (g_htShell.cbCurTotal > g_htShell.cbMaxTotal)
  61. g_htShell.cbMaxTotal = g_htShell.cbCurTotal;
  62. return lp;
  63. }
  64. LPVOID WINAPI ControlReAlloc(HANDLE hheap, LPVOID pb, DWORD cb)
  65. {
  66. LPVOID lp;
  67. SIZE_T cbOld;
  68. cbOld = HeapSize(hheap, 0, pb);
  69. lp = HeapReAlloc(hheap, HEAP_ZERO_MEMORY, pb,cb);
  70. if (lp == NULL)
  71. {
  72. g_htShell.cFailure++;
  73. return NULL;
  74. }
  75. // Update counts.
  76. g_htShell.cReAlloc++;
  77. g_htShell.cbCurTotal += cb - cbOld;
  78. if (g_htShell.cbCurTotal > g_htShell.cbMaxTotal)
  79. g_htShell.cbMaxTotal = g_htShell.cbCurTotal;
  80. return lp;
  81. }
  82. BOOL WINAPI ControlFree(HANDLE hheap, LPVOID pb)
  83. {
  84. SIZE_T cbOld = HeapSize(hheap, 0, pb);
  85. BOOL fRet = HeapFree(hheap, 0, pb);
  86. if (fRet)
  87. {
  88. // Update counts.
  89. g_htShell.cCurAlloc--;
  90. g_htShell.cbCurTotal -= cbOld;
  91. }
  92. return(fRet);
  93. }
  94. SIZE_T WINAPI ControlSize(HANDLE hheap, LPVOID pb)
  95. {
  96. return (DWORD) HeapSize(hheap, 0, pb);
  97. }
  98. #endif // DEBUG