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.

143 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. spmemory.c
  5. Abstract:
  6. Memory allocation routines for text setup.
  7. Author:
  8. Ted Miller (tedm) 29-July-1993
  9. Revision History:
  10. --*/
  11. #include "efinvram.h"
  12. PVOID
  13. MemAlloc(
  14. IN SIZE_T Size
  15. )
  16. /*++
  17. Routine Description:
  18. This function is guaranteed to succeed.
  19. Arguments:
  20. Return Value:
  21. --*/
  22. {
  23. PSIZE_T p;
  24. //
  25. // Add space for storing the size of the block.
  26. //
  27. p = RtlAllocateHeap( RtlProcessHeap(), 0, Size + sizeof(SIZE_T) );
  28. if ( p == NULL ) {
  29. FatalError( ERROR_NOT_ENOUGH_MEMORY, L"Insufficient memory\n" );
  30. }
  31. //
  32. // Store the size of the block, and return the address
  33. // of the user portion of the block.
  34. //
  35. *p++ = Size;
  36. return p;
  37. }
  38. PVOID
  39. MemRealloc(
  40. IN PVOID Block,
  41. IN SIZE_T NewSize
  42. )
  43. /*++
  44. Routine Description:
  45. This function is guaranteed to succeed.
  46. Arguments:
  47. Return Value:
  48. --*/
  49. {
  50. PSIZE_T NewBlock;
  51. SIZE_T OldSize;
  52. //
  53. // Get the size of the block being reallocated.
  54. //
  55. OldSize = ((PSIZE_T)Block)[-1];
  56. //
  57. // Allocate a new block of the new size.
  58. //
  59. NewBlock = MemAlloc(NewSize);
  60. ASSERT(NewBlock);
  61. //
  62. // Copy the old block to the new block.
  63. //
  64. if (NewSize < OldSize) {
  65. RtlCopyMemory(NewBlock, Block, NewSize);
  66. } else {
  67. RtlCopyMemory(NewBlock, Block, OldSize);
  68. }
  69. //
  70. // Free the old block.
  71. //
  72. MemFree(Block);
  73. //
  74. // Return the address of the new block.
  75. //
  76. return(NewBlock);
  77. }
  78. VOID
  79. MemFree(
  80. IN PVOID Block
  81. )
  82. /*++
  83. Routine Description:
  84. Arguments:
  85. Return Value:
  86. --*/
  87. {
  88. if (Block == NULL)
  89. return;
  90. //
  91. // Free the block at its real address.
  92. //
  93. RtlFreeHeap( RtlProcessHeap(), 0, (PSIZE_T)Block - 1);
  94. }