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.

175 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. memory.c
  5. Abstract:
  6. DNS Resolver Service
  7. Memory management.
  8. Author:
  9. James Gilroy (jamesg) March 2000
  10. Revision History:
  11. --*/
  12. #include "local.h"
  13. //
  14. // Note: most records are created by dnsapi heap -- from
  15. // query or hosts file routines. However, we do create
  16. // name error caching records ourselves using dnslib routines.
  17. //
  18. // This means -- until we either
  19. // - extend query or dnslib record creation interfaces to
  20. // include heap parameter
  21. // - explicitly free and recreate
  22. // - tag records (dnsapi\not) somehow (flags field)
  23. // that
  24. // dnsapi and dnslib heaps MUST be the same.
  25. // With dnsapi now potentially having it's own heap, this means
  26. // dnslib should use dnsapi heap.
  27. //
  28. // So we'll put off using the debug heap for dnslib.
  29. //
  30. //
  31. // Note the ideal solution:
  32. // - dnsapi (query and hosts file) creates records in
  33. // the cache heap (by passed heap handle)
  34. // - we create our NAME_ERROR records locally in that
  35. // heap also (our functionalize to dnsapi)
  36. // - copy for RPC can be in separate heap used only by MIDL
  37. // - we have a separate heap for other random crap in the process
  38. //
  39. //
  40. // Counters for heap debugging
  41. //
  42. DWORD g_ResAllocCount = 0;
  43. DWORD g_ResAllocMemory = 0;
  44. DWORD g_ResFreeCount = 0;
  45. DWORD g_MidlAllocCount = 0;
  46. DWORD g_MidlAllocMemory = 0;
  47. DWORD g_MidlFreeCount = 0;
  48. //
  49. // RPC memory routines
  50. //
  51. // These are called by the stub code generated by MIDL.
  52. //
  53. PVOID
  54. WINAPI
  55. MIDL_user_allocate(
  56. IN size_t Size
  57. )
  58. {
  59. DNSDBG( HEAP, (
  60. "MIDL_user_allocate( %d )\n",
  61. Size ));
  62. g_MidlAllocCount++;
  63. g_MidlAllocMemory += Size;
  64. // return( ALLOCATE_HEAP( Size ) );
  65. // return DnsApiAlloc( Size );
  66. return Dns_Alloc( Size );
  67. }
  68. VOID
  69. WINAPI
  70. MIDL_user_free(
  71. IN OUT PVOID pMem
  72. )
  73. {
  74. DNSDBG( HEAP, (
  75. "MIDL_user_free( %p )\n",
  76. pMem ));
  77. g_MidlFreeCount++;
  78. // FREE_HEAP( pMem );
  79. // DnsApiFree( pMem );
  80. Dns_Free( pMem );
  81. }
  82. //
  83. // Resolver heap routines
  84. //
  85. // Currently (see note above) everything RPC, record allocs
  86. // and general allocs are in the same heap.
  87. // However the Tag field sets us up to dispatch to different
  88. // heaps. The file and line info allow us to later use
  89. // debug heap routines.
  90. //
  91. PVOID
  92. Res_Alloc(
  93. IN DWORD Length,
  94. IN DWORD Tag,
  95. IN PSTR pszFile,
  96. IN DWORD LineNo
  97. )
  98. {
  99. DNSDBG( HEAP, (
  100. "Res_Alloc( %d, tag=%d )\n",
  101. Length,
  102. Tag ));
  103. g_ResAllocCount++;
  104. g_ResAllocMemory += Length;
  105. return Dns_Alloc( Length );
  106. }
  107. PVOID
  108. Res_AllocZero(
  109. IN DWORD Length,
  110. IN DWORD Tag,
  111. IN PSTR pszFile,
  112. IN DWORD LineNo
  113. )
  114. {
  115. return Dns_AllocZero( Length );
  116. }
  117. VOID
  118. Res_Free(
  119. IN OUT PVOID pMemory,
  120. IN DWORD Tag
  121. )
  122. {
  123. DNSDBG( HEAP, (
  124. "Res_Free( %p, tag=%d )\n",
  125. pMemory,
  126. Tag ));
  127. g_ResFreeCount++;
  128. Dns_Free( pMemory );
  129. }
  130. //
  131. // End memory.c
  132. //