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.

319 lines
7.5 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. wow.c
  5. Abstract:
  6. This module contains the WOW vdmdbg functions
  7. Revision History:
  8. --*/
  9. #include <precomp.h>
  10. #pragma hdrstop
  11. typedef WORD HAND16;
  12. #define SHAREWOW_MAIN
  13. #include <vdmapi.h>
  14. #include <vdm.h>
  15. //----------------------------------------------------------------------------
  16. // VDMKillWOW()
  17. //
  18. // Interface to kill the wow sub-system. This may not be needed and is
  19. // certainly not needed now. We are going to look into fixing the
  20. // debugging interface so this is not necessary.
  21. //
  22. //----------------------------------------------------------------------------
  23. BOOL
  24. WINAPI
  25. VDMKillWOW(
  26. VOID
  27. ) {
  28. return( FALSE );
  29. }
  30. //----------------------------------------------------------------------------
  31. // VDMDetectWOW()
  32. //
  33. // Interface to detect whether the wow sub-system has already been started.
  34. // This may not be needed and is certainly not needed now. We are going
  35. // to look into fixing the debugging interface so this is not necessary.
  36. //
  37. //----------------------------------------------------------------------------
  38. BOOL
  39. WINAPI
  40. VDMDetectWOW(
  41. VOID
  42. ) {
  43. return( FALSE );
  44. }
  45. INT
  46. WINAPI
  47. VDMEnumProcessWOW(
  48. PROCESSENUMPROC fp,
  49. LPARAM lparam
  50. ) {
  51. SHAREDPROCESS SharedProcess[16];
  52. LPSHAREDPROCESS lpsp;
  53. INT count = 0;
  54. BOOL fRet;
  55. VDMINFO VdmInfo;
  56. DWORD cbProcArray;
  57. BOOL fRetry = FALSE;
  58. RtlZeroMemory(&VdmInfo, sizeof(VDMINFO));
  59. VdmInfo.iTask = 0;
  60. VdmInfo.VDMState = ASKING_FOR_WOWPROCLIST;
  61. VdmInfo.Enviornment = SharedProcess;
  62. VdmInfo.EnviornmentSize = sizeof(SharedProcess);
  63. cbProcArray = sizeof(SharedProcess);
  64. VDMEnumProcessRetry:
  65. if(GetNextVDMCommand(&VdmInfo)) {
  66. if (cbProcArray < VdmInfo.EnviornmentSize &&
  67. !fRetry)
  68. {
  69. lpsp = MALLOC(VdmInfo.EnviornmentSize);
  70. if(!lpsp) {
  71. return 0;
  72. }
  73. VdmInfo.Enviornment = lpsp;
  74. cbProcArray = VdmInfo.EnviornmentSize;
  75. fRetry = TRUE;
  76. goto VDMEnumProcessRetry;
  77. }
  78. count = 0;
  79. lpsp = (LPSHAREDPROCESS) VdmInfo.Enviornment;
  80. cbProcArray = cbProcArray > VdmInfo.EnviornmentSize ? VdmInfo.EnviornmentSize : cbProcArray;
  81. while (cbProcArray) {
  82. cbProcArray -= sizeof(SHAREDPROCESS);
  83. count++;
  84. if ( fp ) {
  85. fRet = (*fp)( lpsp->dwProcessId, lpsp->dwAttributes, lparam );
  86. if ( fRet ) {
  87. break;
  88. }
  89. }
  90. lpsp++;
  91. }
  92. }
  93. if (fRetry) {
  94. FREE(VdmInfo.Enviornment);
  95. }
  96. return( count );
  97. }
  98. INT
  99. WINAPI
  100. VDMEnumTaskWOWWorker(
  101. DWORD dwProcessId,
  102. void * fp,
  103. LPARAM lparam,
  104. BOOL fEx
  105. ) {
  106. SHAREDTASK SharedTask[16];
  107. LPSHAREDTASK lpst;
  108. INT count = 0;
  109. BOOL fRet;
  110. VDMINFO VdmInfo;
  111. DWORD cbTaskArray;
  112. BOOL fRetry = FALSE;
  113. RtlZeroMemory(&VdmInfo, sizeof(VDMINFO));
  114. VdmInfo.VDMState = ASKING_FOR_WOWTASKLIST;
  115. VdmInfo.Enviornment = SharedTask;
  116. VdmInfo.EnviornmentSize = sizeof(SharedTask);
  117. VdmInfo.iTask = dwProcessId;
  118. cbTaskArray = sizeof(SharedTask);
  119. VDMEnumTaskRetry:
  120. if(GetNextVDMCommand(&VdmInfo)) {
  121. if(cbTaskArray < VdmInfo.EnviornmentSize &&
  122. !fRetry)
  123. {
  124. lpst = MALLOC(VdmInfo.EnviornmentSize);
  125. if(!lpst) {
  126. return 0;
  127. }
  128. VdmInfo.Enviornment = lpst;
  129. cbTaskArray = VdmInfo.EnviornmentSize;
  130. fRetry = TRUE;
  131. goto VDMEnumTaskRetry;
  132. }
  133. lpst = (LPSHAREDTASK) VdmInfo.Enviornment;
  134. cbTaskArray = cbTaskArray > VdmInfo.EnviornmentSize ? VdmInfo.EnviornmentSize : cbTaskArray;
  135. count = 0;
  136. while(cbTaskArray) {
  137. cbTaskArray -= sizeof(SHAREDTASK);
  138. count++;
  139. if ( fp && lpst->hMod16 ) {
  140. if (fEx) {
  141. fRet = ((TASKENUMPROCEX)fp)( lpst->dwThreadId, lpst->hMod16, lpst->hTask16,
  142. lpst->szModName, lpst->szFilePath, lparam );
  143. } else {
  144. fRet = ((TASKENUMPROC)fp)( lpst->dwThreadId, lpst->hMod16, lpst->hTask16, lparam );
  145. }
  146. if ( fRet ) {
  147. break;
  148. }
  149. }
  150. lpst++;
  151. }
  152. }
  153. if (fRetry) {
  154. FREE(VdmInfo.Enviornment);
  155. }
  156. return( count );
  157. }
  158. INT
  159. WINAPI
  160. VDMEnumTaskWOW(
  161. DWORD dwProcessId,
  162. TASKENUMPROC fp,
  163. LPARAM lparam
  164. ) {
  165. return VDMEnumTaskWOWWorker(dwProcessId, (void *)fp, lparam, 0);
  166. }
  167. INT
  168. WINAPI
  169. VDMEnumTaskWOWEx(
  170. DWORD dwProcessId,
  171. TASKENUMPROCEX fp,
  172. LPARAM lparam
  173. ) {
  174. return VDMEnumTaskWOWWorker(dwProcessId, (void *)fp, lparam, 1);
  175. }
  176. BOOL
  177. WINAPI
  178. VDMTerminateTaskWOW(
  179. DWORD dwProcessId,
  180. WORD htask
  181. )
  182. {
  183. SHAREDPROCESS SharedProcess;
  184. BOOL fRet = FALSE;
  185. HANDLE hProcess;
  186. HANDLE hRemoteThread;
  187. DWORD dwThreadId;
  188. VDMINFO VdmInfo;
  189. RtlZeroMemory(&VdmInfo, sizeof(VDMINFO));
  190. VdmInfo.iTask = dwProcessId;
  191. VdmInfo.VDMState = ASKING_FOR_WOWPROCLIST;
  192. VdmInfo.Enviornment = (LPVOID)&SharedProcess;
  193. VdmInfo.EnviornmentSize = sizeof(SHAREDPROCESS);
  194. if(GetNextVDMCommand(&VdmInfo)) {
  195. //
  196. // Get a handle to the process and start W32HungAppNotifyThread
  197. // running with htask as the parameter.
  198. //
  199. hProcess = OpenProcess(
  200. PROCESS_ALL_ACCESS,
  201. FALSE,
  202. SharedProcess.dwProcessId
  203. );
  204. if (hProcess) {
  205. hRemoteThread = CreateRemoteThread(
  206. hProcess,
  207. NULL,
  208. 0,
  209. SharedProcess.pfnW32HungAppNotifyThread,
  210. (LPVOID) htask,
  211. 0,
  212. &dwThreadId
  213. );
  214. if (hRemoteThread) {
  215. fRet = TRUE;
  216. CloseHandle(hRemoteThread);
  217. }
  218. CloseHandle(hProcess);
  219. }
  220. }
  221. return fRet;
  222. }
  223. BOOL
  224. VDMStartTaskInWOW(
  225. DWORD pidTarget,
  226. LPSTR lpCommandLine,
  227. WORD wShow
  228. )
  229. {
  230. HWND hwnd = NULL;
  231. DWORD pid;
  232. BOOL fRet;
  233. do {
  234. hwnd = FindWindowEx(NULL, hwnd, TEXT("WowExecClass"), NULL);
  235. if (hwnd) {
  236. pid = 0;
  237. GetWindowThreadProcessId(hwnd, &pid);
  238. }
  239. } while (hwnd && pid != pidTarget);
  240. if (hwnd && pid == pidTarget) {
  241. #define WM_WOWEXEC_START_TASK (WM_USER+2)
  242. PostMessage(hwnd, WM_WOWEXEC_START_TASK, GlobalAddAtom(lpCommandLine), wShow);
  243. fRet = TRUE;
  244. } else {
  245. fRet = FALSE;
  246. }
  247. return fRet;
  248. }