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.

138 lines
3.2 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: dbgfns.c
  3. *
  4. * Debugger extensions helper routines
  5. *
  6. * Created: 26-Jan-95
  7. * Author: Drew Bliss
  8. *
  9. * Copyright (c) 1995 Microsoft Corporation
  10. \**************************************************************************/
  11. #include "precomp.c"
  12. #pragma hdrstop
  13. /******************************Public*Routine******************************\
  14. *
  15. * GetMemory
  16. *
  17. * Reads a value from debuggee memory
  18. *
  19. * History:
  20. * Tue Jan 17 14:35:24 1995 -by- Drew Bliss [drewb]
  21. * Created
  22. *
  23. \**************************************************************************/
  24. BOOL GetMemory(PWINDBG_EXTENSION_APIS pwea,
  25. HANDLE hCurrentProcess,
  26. DWORD dwSrc, PVOID pvDst, DWORD cb)
  27. {
  28. BOOL fRet;
  29. try
  30. {
  31. if (pwea->nSize >= sizeof(WINDBG_EXTENSION_APIS))
  32. {
  33. fRet = (BOOL)pwea->lpReadProcessMemoryRoutine(dwSrc, pvDst,
  34. cb, NULL);
  35. }
  36. else
  37. {
  38. fRet = NT_SUCCESS(NtReadVirtualMemory(hCurrentProcess,
  39. (LPVOID)dwSrc,
  40. pvDst, cb, NULL));
  41. }
  42. }
  43. except(EXCEPTION_EXECUTE_HANDLER)
  44. {
  45. PRINT("Invalid address %p\n", dwSrc);
  46. return FALSE;
  47. }
  48. if (!fRet)
  49. {
  50. PRINT("Unable to read memory at address %p\n", dwSrc);
  51. }
  52. return fRet;
  53. }
  54. /******************************Public*Routine******************************\
  55. *
  56. * GetTeb
  57. *
  58. * Retrieves the TEB pointer for the given thread
  59. * Returns a pointer to a static TEB so subsequent calls
  60. * will overwrite TEB information
  61. *
  62. * History:
  63. * Thu Jan 26 13:47:20 1995 -by- Drew Bliss [drewb]
  64. * Created
  65. *
  66. \**************************************************************************/
  67. PTEB GetTeb(PWINDBG_EXTENSION_APIS pwea,
  68. HANDLE hCurrentProcess,
  69. HANDLE hThread)
  70. {
  71. static TEB tebLocal;
  72. NTSTATUS nts;
  73. THREAD_BASIC_INFORMATION tbi;
  74. nts = NtQueryInformationThread(hThread, ThreadBasicInformation,
  75. &tbi, sizeof(tbi), NULL);
  76. if (NT_SUCCESS(nts))
  77. {
  78. if (!GM_OBJ((DWORD)tbi.TebBaseAddress, tebLocal))
  79. {
  80. return NULL;
  81. }
  82. else
  83. {
  84. return &tebLocal;
  85. }
  86. }
  87. else
  88. {
  89. PRINT("Unable to retrieve thread information for %p\n", hThread);
  90. return NULL;
  91. }
  92. }
  93. /******************************Public*Routine******************************\
  94. *
  95. * IsCsrServerThread
  96. *
  97. * Determines whether the given thread is a CSR server thread or not
  98. * Consider - Is this reliable?
  99. *
  100. * History:
  101. * Tue Jan 31 13:38:50 1995 -by- Drew Bliss [drewb]
  102. * Created
  103. *
  104. \**************************************************************************/
  105. BOOL IsCsrServerThread(PWINDBG_EXTENSION_APIS pwea,
  106. HANDLE hCurrentProcess,
  107. HANDLE hThread)
  108. {
  109. PTEB pteb;
  110. PCSR_QLPC_TEB pqteb;
  111. pteb = GetTeb(pwea, hCurrentProcess, hThread);
  112. if (pteb == NULL)
  113. {
  114. return FALSE;
  115. }
  116. pqteb = (PCSR_QLPC_TEB)&pteb->CsrQlpcTeb;
  117. if (pqteb->ClientThread != NULL)
  118. {
  119. return TRUE;
  120. }
  121. else
  122. {
  123. return FALSE;
  124. }
  125. }