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.

190 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. move.c
  5. Abstract:
  6. This module contains code to implement the portable kernel debugger
  7. memory mover.
  8. Author:
  9. Mark Lucovsky (markl) 31-Aug-1990
  10. Revision History:
  11. --*/
  12. #include "bd.h"
  13. ULONG
  14. BdMoveMemory (
  15. IN PCHAR Destination,
  16. IN PCHAR Source,
  17. IN ULONG Length
  18. )
  19. /*++
  20. Routine Description:
  21. This routine moves data to or from the message buffer and returns the
  22. actual length of the information that was moved. As data is moved, checks
  23. are made to ensure that the data is resident in memory and a page fault
  24. will not occur. If a page fault would occur, then the move is truncated.
  25. Arguments:
  26. Destination - Supplies a pointer to destination of the move operation.
  27. Source - Supplies a pointer to the source of the move operation.
  28. Length - Supplies the length of the move operation.
  29. Return Value:
  30. The actual length of the move is returned as the fucntion value.
  31. --*/
  32. {
  33. PVOID Address1;
  34. PVOID Address2;
  35. ULONG ActualLength;
  36. //
  37. // If the length is greater than the size of the message buffer, then
  38. // reduce the length to the size of the message buffer.
  39. //
  40. if (Length > BD_MESSAGE_BUFFER_SIZE) {
  41. Length = BD_MESSAGE_BUFFER_SIZE;
  42. }
  43. //
  44. // Move the source information to the destination address.
  45. //
  46. ActualLength = Length;
  47. while (((ULONG_PTR)Source & 3) && (Length > 0)) {
  48. //
  49. // Check to determine if the move will succeed before actually performing
  50. // the operation.
  51. //
  52. Address1 = BdWriteCheck((PVOID)Destination);
  53. Address2 = BdReadCheck((PVOID)Source);
  54. if ((Address1 == NULL) || (Address2 == NULL)) {
  55. break;
  56. }
  57. *(PCHAR)Address1 = *(PCHAR)Address2;
  58. Destination += 1;
  59. Source += 1;
  60. Length -= 1;
  61. }
  62. while (Length > 3) {
  63. //
  64. // Check to determine if the move will succeed before actually performing
  65. // the operation.
  66. //
  67. Address1 = BdWriteCheck((PVOID)Destination);
  68. Address2 = BdReadCheck((PVOID)Source);
  69. if ((Address1 == NULL) || (Address2 == NULL)) {
  70. break;
  71. }
  72. *(ULONG UNALIGNED *)Address1 = *(PULONG)Address2;
  73. Destination += 4;
  74. Source += 4;
  75. Length -= 4;
  76. }
  77. while (Length > 0) {
  78. //
  79. // Check to determine if the move will succeed before actually performing
  80. // the operation.
  81. //
  82. Address1 = BdWriteCheck((PVOID)Destination);
  83. Address2 = BdReadCheck((PVOID)Source);
  84. if ((Address1 == NULL) || (Address2 == NULL)) {
  85. break;
  86. }
  87. *(PCHAR)Address1 = *(PCHAR)Address2;
  88. Destination += 1;
  89. Source += 1;
  90. Length -= 1;
  91. }
  92. //
  93. // Flush the instruction cache in case the write was into the instruction
  94. // stream.
  95. //
  96. #if defined(_ALPHA_)
  97. BdSweepIcache();
  98. #endif
  99. return ActualLength - Length;
  100. }
  101. VOID
  102. BdCopyMemory (
  103. IN PCHAR Destination,
  104. IN PCHAR Source,
  105. IN ULONG Length
  106. )
  107. /*++
  108. Routine Description:
  109. This routine duplicates the function pf RtlCopyMemory, but is private
  110. to the debugger. This allows breakpoints and watch points to be set
  111. RtlMoveMemory itself without risk of recursive debugger entry and the
  112. accompanying hang.
  113. N.B. Unlike BdMoveMemory, this routine does NOT check for accessability
  114. and may fault! Use it ONLY in the debugger and ONLY where you could
  115. use RtlMoveMemory.
  116. Arguments:
  117. Destination - Supplies a pointer to destination of the move operation.
  118. Source - Supplies a pointer to the source of the move operation.
  119. Length - Supplies the length of the move operation.
  120. Return Value:
  121. None.
  122. --*/
  123. {
  124. while (Length > 0) {
  125. *Destination = *Source;
  126. Destination += 1;
  127. Source += 1;
  128. Length -= 1;
  129. }
  130. return;
  131. }