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.

174 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1990-1999 Microsoft Corporation
  3. Module Name:
  4. newdel.cxx
  5. Abstract:
  6. This module implements the C++ new and delete operators for
  7. the Setup-Loader environment. In other environments, the utilities
  8. use the standard C++ new and delete.
  9. Environment:
  10. ULIB, User Mode
  11. --*/
  12. #include <pch.cxx>
  13. #define _ULIB_MEMBER_
  14. #include "ulib.hxx"
  15. #ifdef _EFICHECK_
  16. extern "C" {
  17. #include <efi.h>
  18. #include <efilib.h>
  19. }
  20. #endif
  21. extern "C"
  22. int _cdecl
  23. _purecall( );
  24. int _cdecl
  25. _purecall( )
  26. {
  27. DebugAbort( "Pure virtual function called.\n" );
  28. return 0;
  29. }
  30. // When the utilities are running the Setup Loader
  31. // or Autocheck environments, they can't use the C-Run-
  32. // Time new and delete; instead, these functions are
  33. // provided.
  34. //
  35. PVOID _cdecl
  36. operator new (
  37. IN size_t bytes
  38. )
  39. /*++
  40. Routine Description:
  41. This routine allocates 'bytes' bytes of memory.
  42. Arguments:
  43. bytes - Supplies the number of bytes requested.
  44. Return Value:
  45. A pointer to 'bytes' bytes or NULL.
  46. --*/
  47. {
  48. void * ptr;
  49. ptr = AllocatePool(bytes);
  50. return ptr;
  51. }
  52. VOID _cdecl
  53. operator delete (
  54. IN PVOID pointer
  55. )
  56. /*++
  57. Routine Description:
  58. This routine frees the memory pointed to by 'pointer'.
  59. Arguments:
  60. pointer - Supplies a pointer to the memoery to be freed.
  61. Return Value:
  62. None.
  63. --*/
  64. {
  65. if (pointer) {
  66. FreePool(pointer);
  67. }
  68. }
  69. typedef void (*PF)(PVOID);
  70. typedef void (*PFI)(PVOID, int);
  71. PVOID
  72. __vec_new(
  73. IN OUT PVOID op,
  74. IN int number,
  75. IN int size,
  76. IN PVOID f)
  77. /*
  78. allocate a vector of "number" elements of size "size"
  79. and initialize each by a call of "f"
  80. */
  81. {
  82. if (op == 0) {
  83. op = AllocatePool( number * size );
  84. }
  85. if (op && f) {
  86. register char* p = (char*) op;
  87. register char* lim = p + number*size;
  88. register PF fp = PF(f);
  89. while (p < lim) {
  90. (*fp) (PVOID(p));
  91. p += size;
  92. }
  93. }
  94. return op;
  95. }
  96. void
  97. __vec_delete(
  98. PVOID op,
  99. int n,
  100. int sz,
  101. PVOID f,
  102. int del,
  103. int x)
  104. /*
  105. destroy a vector of "n" elements of size "sz"
  106. */
  107. {
  108. // unreferenced parameters
  109. // I wonder what it does
  110. (void)(x);
  111. if (op) {
  112. if (f) {
  113. register char* cp = (char*) op;
  114. register char* p = cp;
  115. register PFI fp = PFI(f);
  116. p += n*sz;
  117. while (p > cp) {
  118. p -= sz;
  119. (*fp)(PVOID(p), 2); // destroy VBC, don't delete
  120. }
  121. }
  122. if (del) {
  123. FreePool(op);
  124. }
  125. }
  126. }