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.

289 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1996 Intel Corporation
  3. Copyright (c) 1990 Microsoft Corporation
  4. Module Name:
  5. miscc.c
  6. Abstract:
  7. This module implements the functions that get the memory stack
  8. and backing store limits.
  9. Author:
  10. William K. Cheung (wcheung) 09-Aug-1996
  11. Environment:
  12. Any mode.
  13. Revision History:
  14. --*/
  15. #include "ntrtlp.h"
  16. VOID
  17. DebugLoadImageSymbols(
  18. IN PSTRING FileName,
  19. IN PKD_SYMBOLS_INFO SymbolInfo
  20. );
  21. VOID
  22. DebugUnLoadImageSymbols(
  23. IN PSTRING FileName,
  24. IN PKD_SYMBOLS_INFO SymbolInfo
  25. );
  26. VOID
  27. DebugCommandString(
  28. IN PSTRING Name,
  29. IN PSTRING Command
  30. );
  31. VOID
  32. RtlpFlushRSE (
  33. OUT PULONGLONG BackingStore,
  34. OUT PULONGLONG RNat
  35. );
  36. VOID
  37. RtlpCaptureRnats (
  38. IN OUT PCONTEXT ContextRecord
  39. )
  40. /*++
  41. Routine Description:
  42. This function captures Nat bits of all the stacked registers in
  43. the RSE frame specified in the context record.
  44. --*/
  45. {
  46. SHORT BsFrameSize; // in 8-byte units
  47. SHORT TempFrameSize; // in 8-byte units
  48. SHORT RNatSaveIndex;
  49. ULONGLONG Rnat;
  50. ULONGLONG Bsp;
  51. ULONGLONG TopRnatAddress;
  52. RtlpFlushRSE(&Bsp, &Rnat);
  53. BsFrameSize = (SHORT)ContextRecord->StIFS & PFS_SIZE_MASK;
  54. RNatSaveIndex = (SHORT)(ContextRecord->RsBSP >> 3) & NAT_BITS_PER_RNAT_REG;
  55. TempFrameSize = RNatSaveIndex + BsFrameSize - NAT_BITS_PER_RNAT_REG;
  56. while (TempFrameSize >= 0) {
  57. BsFrameSize++;
  58. TempFrameSize -= NAT_BITS_PER_RNAT_REG;
  59. }
  60. TopRnatAddress = (ContextRecord->RsBSP + (BsFrameSize * 8) - sizeof(ULONGLONG)) | RNAT_ALIGNMENT;
  61. if (TopRnatAddress < Bsp) {
  62. ContextRecord->RsRNAT = *(PULONGLONG)TopRnatAddress;
  63. } else {
  64. ContextRecord->RsRNAT = Rnat;
  65. }
  66. }
  67. VOID
  68. Rtlp64GetBStoreLimits (
  69. OUT PULONGLONG LowBStoreLimit,
  70. OUT PULONGLONG HighBStoreLimit
  71. )
  72. /*++
  73. Routine Description:
  74. This function returns the current backing store limits based on the
  75. current processor mode.
  76. Arguments:
  77. LowBStoreLimit - Supplies a pointer to a variable that is to receive
  78. the low limit of the backing store.
  79. HighBStoreLimit - Supplies a pointer to a variable that is to receive
  80. the high limit of the backing store.
  81. Return Value:
  82. None.
  83. --*/
  84. {
  85. #if defined(NTOS_KERNEL_RUNTIME)
  86. //
  87. // Kernel Mode
  88. //
  89. *LowBStoreLimit = (ULONGLONG)(PCR->InitialBStore);
  90. *HighBStoreLimit = (ULONGLONG)(PCR->BStoreLimit);
  91. #else
  92. //
  93. // User Mode
  94. //
  95. PTEB CurrentTeb = NtCurrentTeb();
  96. *HighBStoreLimit = (ULONGLONG)CurrentTeb->BStoreLimit;
  97. *LowBStoreLimit = (ULONGLONG)CurrentTeb->NtTib.StackBase;
  98. #endif // defined(NTOS_KERNEL_RUNTIME)
  99. }
  100. VOID
  101. RtlpGetStackLimits (
  102. OUT PULONG_PTR LowStackLimit,
  103. OUT PULONG_PTR HighStackLimit
  104. )
  105. /*++
  106. Routine Description:
  107. This function returns the current memory stack limits based on the
  108. current processor mode.
  109. Arguments:
  110. LowStackLimit - Supplies a pointer to a variable that is to receive
  111. the low limit of the memory stack.
  112. HighStackLimit - Supplies a pointer to a variable that is to receive
  113. the high limit of the memory stack.
  114. Return Value:
  115. None.
  116. --*/
  117. {
  118. #if defined(NTOS_KERNEL_RUNTIME)
  119. //
  120. // Kernel Mode
  121. //
  122. *HighStackLimit = (ULONG_PTR)PCR->InitialStack;
  123. *LowStackLimit = (ULONG_PTR)PCR->StackLimit;
  124. #else
  125. //
  126. // User Mode
  127. //
  128. PTEB CurrentTeb = NtCurrentTeb();
  129. *HighStackLimit = (ULONG_PTR)CurrentTeb->NtTib.StackBase;
  130. *LowStackLimit = (ULONG_PTR)CurrentTeb->NtTib.StackLimit;
  131. #endif // defined(NTOS_KERNEL_RUNTIME)
  132. }
  133. VOID
  134. Rtlp64GetStackLimits (
  135. OUT PULONGLONG LowStackLimit,
  136. OUT PULONGLONG HighStackLimit
  137. )
  138. /*++
  139. Routine Description:
  140. This function returns the current memory stack limits based on the
  141. current processor mode.
  142. Arguments:
  143. LowStackLimit - Supplies a pointer to a variable that is to receive
  144. the low limit of the memory stack.
  145. HighStackLimit - Supplies a pointer to a variable that is to receive
  146. the high limit of the memory stack.
  147. Return Value:
  148. None.
  149. --*/
  150. {
  151. #if defined(NTOS_KERNEL_RUNTIME)
  152. //
  153. // Kernel Mode
  154. //
  155. *HighStackLimit = (ULONG_PTR)PCR->InitialStack;
  156. *LowStackLimit = (ULONG_PTR)PCR->StackLimit;
  157. #else
  158. //
  159. // User Mode
  160. //
  161. PTEB CurrentTeb = NtCurrentTeb();
  162. *HighStackLimit = (ULONGLONG)CurrentTeb->NtTib.StackBase;
  163. *LowStackLimit = (ULONGLONG)CurrentTeb->NtTib.StackLimit;
  164. #endif // defined(NTOS_KERNEL_RUNTIME)
  165. }
  166. VOID
  167. DebugService2(
  168. PVOID Arg1,
  169. PVOID Arg2,
  170. ULONG ServiceClass
  171. )
  172. //++
  173. //
  174. // Routine Description:
  175. //
  176. // Generic exception dispatcher for the debugger
  177. //
  178. // Arguments:
  179. // Arg1 - generic first argument
  180. // Arg2 - generic second argument
  181. // ServiceClass - which call is to be performed
  182. //
  183. // Returns:
  184. // Whatever the exception returns in eax
  185. //
  186. //--
  187. {
  188. switch (ServiceClass)
  189. {
  190. case BREAKPOINT_COMMAND_STRING:
  191. DebugCommandString(Arg1, Arg2);
  192. return;
  193. case BREAKPOINT_LOAD_SYMBOLS:
  194. DebugLoadImageSymbols(Arg1, Arg2);
  195. return;
  196. case BREAKPOINT_UNLOAD_SYMBOLS:
  197. DebugUnLoadImageSymbols(Arg1, Arg2);
  198. return;
  199. default:
  200. return;
  201. }
  202. return;
  203. }