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.

162 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. MEMORY.C
  5. Abstract:
  6. This file contains the routines that deal with memory management.
  7. Author:
  8. Rajen Shah (rajens) 12-Jul-1991
  9. [Environment:]
  10. User Mode - Win32, except for NTSTATUS returned by some functions.
  11. Revision History:
  12. Jonathan Schwartz (jschwart) 10-Dec-1999
  13. Have the Eventlog use its own heap
  14. --*/
  15. //
  16. // INCLUDES
  17. //
  18. #include <eventp.h>
  19. //
  20. // GLOBALS
  21. //
  22. PVOID g_pElfHeap;
  23. VOID
  24. ElfpCreateHeap(
  25. VOID
  26. )
  27. {
  28. DWORD dwHeapFlags;
  29. #if DBG
  30. //
  31. // Turn on tail and free checking on debug builds.
  32. //
  33. dwHeapFlags = HEAP_GROWABLE
  34. | HEAP_FREE_CHECKING_ENABLED
  35. | HEAP_TAIL_CHECKING_ENABLED;
  36. #else // ndef DBG
  37. dwHeapFlags = HEAP_GROWABLE;
  38. #endif // DBG
  39. //
  40. // Create the heap
  41. //
  42. g_pElfHeap = RtlCreateHeap(dwHeapFlags, // Flags
  43. NULL, // HeapBase
  44. 32 * 1024, // ReserveSize (32K)
  45. 4096, // CommitSize (4K)
  46. NULL, // HeapLock
  47. NULL); // GrowthThreshhold
  48. if (g_pElfHeap == NULL)
  49. {
  50. ELF_LOG0(ERROR,
  51. "ElfpCreateHeap: RtlCreateHeap failed -- using process heap\n");
  52. g_pElfHeap = RtlProcessHeap();
  53. }
  54. return;
  55. }
  56. PVOID
  57. ElfpAllocateBuffer(
  58. ULONG Size
  59. )
  60. /*++
  61. Routine Description:
  62. Allocate a buffer of the given size
  63. Arguments:
  64. Number of bytes to allocate
  65. Return Value:
  66. Pointer to allocated buffer (or NULL).
  67. --*/
  68. {
  69. return RtlAllocateHeap(g_pElfHeap, 0, Size);
  70. }
  71. BOOLEAN
  72. ElfpFreeBuffer(
  73. PVOID Address
  74. )
  75. /*++
  76. Routine Description:
  77. Frees a buffer previously allocated by ElfpAllocateBuffer.
  78. Arguments:
  79. Pointer to buffer.
  80. Return Value:
  81. TRUE if the block was properly freed, FALSE if not
  82. Note:
  83. --*/
  84. {
  85. //
  86. // Note that RtlFreeHeap handles NULL
  87. //
  88. return RtlFreeHeap(g_pElfHeap, 0, Address);
  89. }
  90. PVOID
  91. MIDL_user_allocate (
  92. size_t Size
  93. )
  94. {
  95. //
  96. // The server-side RPC calls in the Eventlog expect any
  97. // UNICODE_STRINGs passed in either to have a length equal
  98. // to the max length or to be NULL-terminated. We need to
  99. // zero the memory here to supply that NULL-termination.
  100. //
  101. return RtlAllocateHeap(g_pElfHeap, HEAP_ZERO_MEMORY, Size);
  102. }
  103. VOID
  104. MIDL_user_free (
  105. PVOID Address
  106. )
  107. {
  108. ElfpFreeBuffer(Address);
  109. }