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.

329 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. vdmdbg.c
  5. Abstract:
  6. This module contains the debugging support needed to debug
  7. 16-bit VDM applications
  8. Author:
  9. Bob Day (bobday) 16-Sep-1992 Wrote it
  10. Revision History:
  11. Neil Sandlin (neilsa) 1-Mar-1997 Enhanced it
  12. --*/
  13. #include <precomp.h>
  14. #pragma hdrstop
  15. VOID CopyToGlobalEntry16(
  16. LPGLOBALENTRY lpGlobalEntry,
  17. LPGLOBALENTRY16 lpGlobalEntry16
  18. ) {
  19. if ( lpGlobalEntry == NULL || lpGlobalEntry16 == NULL ) {
  20. return;
  21. }
  22. lpGlobalEntry16->dwSize = sizeof(GLOBALENTRY16);
  23. lpGlobalEntry16->dwAddress = lpGlobalEntry->dwAddress;
  24. lpGlobalEntry16->dwBlockSize = lpGlobalEntry->dwBlockSize;
  25. lpGlobalEntry16->hBlock = (WORD)lpGlobalEntry->hBlock;
  26. lpGlobalEntry16->wcLock = lpGlobalEntry->wcLock;
  27. lpGlobalEntry16->wcPageLock = lpGlobalEntry->wcPageLock;
  28. lpGlobalEntry16->wFlags = lpGlobalEntry->wFlags;
  29. lpGlobalEntry16->wHeapPresent = (BOOLEAN)lpGlobalEntry->wHeapPresent;
  30. lpGlobalEntry16->hOwner = (WORD)lpGlobalEntry->hOwner;
  31. lpGlobalEntry16->wType = lpGlobalEntry->wType;
  32. lpGlobalEntry16->wData = lpGlobalEntry->wData;
  33. lpGlobalEntry16->dwNext = lpGlobalEntry->dwNext;
  34. lpGlobalEntry16->dwNextAlt = lpGlobalEntry->dwNextAlt;
  35. }
  36. VOID CopyFromGlobalEntry16(
  37. LPGLOBALENTRY lpGlobalEntry,
  38. LPGLOBALENTRY16 lpGlobalEntry16
  39. ) {
  40. if ( lpGlobalEntry == NULL || lpGlobalEntry16 == NULL ) {
  41. return;
  42. }
  43. lpGlobalEntry->dwSize = sizeof(GLOBALENTRY);
  44. lpGlobalEntry->dwAddress = lpGlobalEntry16->dwAddress;
  45. lpGlobalEntry->dwBlockSize = lpGlobalEntry16->dwBlockSize;
  46. lpGlobalEntry->hBlock = (HANDLE)lpGlobalEntry16->hBlock;
  47. lpGlobalEntry->wcLock = lpGlobalEntry16->wcLock;
  48. lpGlobalEntry->wcPageLock = lpGlobalEntry16->wcPageLock;
  49. lpGlobalEntry->wFlags = lpGlobalEntry16->wFlags;
  50. lpGlobalEntry->wHeapPresent = lpGlobalEntry16->wHeapPresent;
  51. lpGlobalEntry->hOwner = (HANDLE)lpGlobalEntry16->hOwner;
  52. lpGlobalEntry->wType = lpGlobalEntry16->wType;
  53. lpGlobalEntry->wData = lpGlobalEntry16->wData;
  54. lpGlobalEntry->dwNext = lpGlobalEntry16->dwNext;
  55. lpGlobalEntry->dwNextAlt = lpGlobalEntry16->dwNextAlt;
  56. }
  57. BOOL
  58. WINAPI
  59. VDMGlobalFirst(
  60. HANDLE hProcess,
  61. HANDLE hUnused,
  62. LPGLOBALENTRY lpGlobalEntry,
  63. WORD wFlags,
  64. DEBUGEVENTPROC lpEventProc,
  65. LPVOID lpData
  66. ) {
  67. #define GF_SIZE 6 // 6 bytes are passed to GlobalFirst
  68. BYTE Args[GF_SIZE+sizeof(GLOBALENTRY16)];
  69. LPBYTE lpbyte;
  70. DWORD vpBuff;
  71. DWORD dwResult;
  72. BOOL b;
  73. UNREFERENCED_PARAMETER(hUnused);
  74. if ( lpGlobalEntry->dwSize != sizeof(GLOBALENTRY) ) {
  75. return( FALSE );
  76. }
  77. vpBuff = GetRemoteBlock16();
  78. vpBuff += GF_SIZE;
  79. lpbyte = Args;
  80. // Push the flags
  81. (*(LPWORD)lpbyte) = wFlags;
  82. lpbyte += sizeof(WORD);
  83. // Push the pointer to the pointer to the GLOBALENTRY16 structure
  84. (*(LPWORD)lpbyte) = LOWORD(vpBuff);
  85. lpbyte += sizeof(WORD);
  86. (*(LPWORD)lpbyte) = HIWORD(vpBuff);
  87. lpbyte += sizeof(WORD);
  88. CopyToGlobalEntry16( lpGlobalEntry, (LPGLOBALENTRY16)lpbyte );
  89. b = CallRemote16(
  90. hProcess,
  91. "TOOLHELP.DLL",
  92. "GlobalFirst",
  93. Args,
  94. GF_SIZE,
  95. sizeof(Args),
  96. &dwResult,
  97. lpEventProc,
  98. lpData );
  99. if ( !b ) {
  100. return( FALSE );
  101. }
  102. CopyFromGlobalEntry16( lpGlobalEntry, (LPGLOBALENTRY16)lpbyte );
  103. return( (BOOL)((WORD)dwResult) );
  104. }
  105. BOOL
  106. WINAPI
  107. VDMGlobalNext(
  108. HANDLE hProcess,
  109. HANDLE hUnused,
  110. LPGLOBALENTRY lpGlobalEntry,
  111. WORD wFlags,
  112. DEBUGEVENTPROC lpEventProc,
  113. LPVOID lpData
  114. ) {
  115. #define GN_SIZE 6 // 6 bytes are passed to GlobalNext
  116. BYTE Args[GN_SIZE+sizeof(GLOBALENTRY16)];
  117. LPBYTE lpbyte;
  118. DWORD vpBuff;
  119. DWORD dwResult;
  120. BOOL b;
  121. UNREFERENCED_PARAMETER(hUnused);
  122. if ( lpGlobalEntry->dwSize != sizeof(GLOBALENTRY) ) {
  123. return( FALSE );
  124. }
  125. vpBuff = GetRemoteBlock16();
  126. vpBuff += GN_SIZE;
  127. lpbyte = Args;
  128. // Push the flags
  129. (*(LPWORD)lpbyte) = wFlags;
  130. lpbyte += sizeof(WORD);
  131. // Push the pointer to the pointer to the GLOBALENTRY16 structure
  132. (*(LPWORD)lpbyte) = LOWORD(vpBuff);
  133. lpbyte += sizeof(WORD);
  134. (*(LPWORD)lpbyte) = HIWORD(vpBuff);
  135. lpbyte += sizeof(WORD);
  136. CopyToGlobalEntry16( lpGlobalEntry, (LPGLOBALENTRY16)lpbyte );
  137. b = CallRemote16(
  138. hProcess,
  139. "TOOLHELP.DLL",
  140. "GlobalNext",
  141. Args,
  142. GN_SIZE,
  143. sizeof(Args),
  144. &dwResult,
  145. lpEventProc,
  146. lpData );
  147. if ( !b ) {
  148. return( FALSE );
  149. }
  150. CopyFromGlobalEntry16( lpGlobalEntry, (LPGLOBALENTRY16)lpbyte );
  151. return( (BOOL)((WORD)dwResult) );
  152. }
  153. VOID CopyToModuleEntry16(
  154. LPMODULEENTRY lpModuleEntry,
  155. LPMODULEENTRY16 lpModuleEntry16
  156. ) {
  157. if ( lpModuleEntry == NULL || lpModuleEntry16 == NULL ) {
  158. return;
  159. }
  160. lpModuleEntry16->dwSize = sizeof(MODULEENTRY16);
  161. lpModuleEntry16->hModule = (WORD)lpModuleEntry->hModule;
  162. lpModuleEntry16->wcUsage = lpModuleEntry->wcUsage;
  163. lpModuleEntry16->wNext = lpModuleEntry->wNext;
  164. strncpy( lpModuleEntry16->szModule, lpModuleEntry->szModule, MAX_MODULE_NAME );
  165. strncpy( lpModuleEntry16->szExePath, lpModuleEntry->szExePath, MAX_PATH16 );
  166. }
  167. VOID CopyFromModuleEntry16(
  168. LPMODULEENTRY lpModuleEntry,
  169. LPMODULEENTRY16 lpModuleEntry16
  170. ) {
  171. if ( lpModuleEntry == NULL || lpModuleEntry16 == NULL ) {
  172. return;
  173. }
  174. lpModuleEntry->dwSize = sizeof(MODULEENTRY);
  175. lpModuleEntry->hModule = (HANDLE)lpModuleEntry16->hModule;
  176. lpModuleEntry->wcUsage = lpModuleEntry16->wcUsage;
  177. lpModuleEntry->wNext = lpModuleEntry16->wNext;
  178. strncpy( lpModuleEntry->szModule, lpModuleEntry16->szModule, MAX_MODULE_NAME );
  179. strncpy( lpModuleEntry->szExePath, lpModuleEntry16->szExePath, MAX_PATH16 );
  180. }
  181. BOOL
  182. WINAPI
  183. VDMModuleFirst(
  184. HANDLE hProcess,
  185. HANDLE hUnused,
  186. LPMODULEENTRY lpModuleEntry,
  187. DEBUGEVENTPROC lpEventProc,
  188. LPVOID lpData
  189. ) {
  190. #define MF_SIZE 4 // 4 bytes are passed to ModuleFirst
  191. BYTE Args[GF_SIZE+sizeof(MODULEENTRY16)];
  192. LPBYTE lpbyte;
  193. DWORD vpBuff;
  194. DWORD dwResult;
  195. BOOL b;
  196. UNREFERENCED_PARAMETER(hUnused);
  197. if ( lpModuleEntry->dwSize != sizeof(MODULEENTRY) ) {
  198. return( FALSE );
  199. }
  200. vpBuff = GetRemoteBlock16();
  201. vpBuff += MF_SIZE;
  202. lpbyte = Args;
  203. // Push the pointer to the pointer to the MODULEENTRY16 structure
  204. (*(LPWORD)lpbyte) = LOWORD(vpBuff);
  205. lpbyte += sizeof(WORD);
  206. (*(LPWORD)lpbyte) = HIWORD(vpBuff);
  207. lpbyte += sizeof(WORD);
  208. CopyToModuleEntry16( lpModuleEntry, (LPMODULEENTRY16)lpbyte );
  209. b = CallRemote16(
  210. hProcess,
  211. "TOOLHELP.DLL",
  212. "ModuleFirst",
  213. Args,
  214. MF_SIZE,
  215. sizeof(Args),
  216. &dwResult,
  217. lpEventProc,
  218. lpData );
  219. if ( !b ) {
  220. return( FALSE );
  221. }
  222. CopyFromModuleEntry16( lpModuleEntry, (LPMODULEENTRY16)lpbyte );
  223. return( (BOOL)((WORD)dwResult) );
  224. }
  225. BOOL
  226. WINAPI
  227. VDMModuleNext(
  228. HANDLE hProcess,
  229. HANDLE hUnused,
  230. LPMODULEENTRY lpModuleEntry,
  231. DEBUGEVENTPROC lpEventProc,
  232. LPVOID lpData
  233. ) {
  234. #define MN_SIZE 4 // 4 bytes are passed to ModuleNext
  235. BYTE Args[GF_SIZE+sizeof(MODULEENTRY16)];
  236. LPBYTE lpbyte;
  237. DWORD vpBuff;
  238. DWORD dwResult;
  239. BOOL b;
  240. UNREFERENCED_PARAMETER(hUnused);
  241. if ( lpModuleEntry->dwSize != sizeof(MODULEENTRY) ) {
  242. return( FALSE );
  243. }
  244. vpBuff = GetRemoteBlock16();
  245. vpBuff += MN_SIZE;
  246. lpbyte = Args;
  247. // Push the pointer to the pointer to the MODULEENTRY16 structure
  248. (*(LPWORD)lpbyte) = LOWORD(vpBuff);
  249. lpbyte += sizeof(WORD);
  250. (*(LPWORD)lpbyte) = HIWORD(vpBuff);
  251. lpbyte += sizeof(WORD);
  252. CopyToModuleEntry16( lpModuleEntry, (LPMODULEENTRY16)lpbyte );
  253. b = CallRemote16(
  254. hProcess,
  255. "TOOLHELP.DLL",
  256. "ModuleNext",
  257. Args,
  258. MN_SIZE,
  259. sizeof(Args),
  260. &dwResult,
  261. lpEventProc,
  262. lpData );
  263. if ( !b ) {
  264. return( FALSE );
  265. }
  266. CopyFromModuleEntry16( lpModuleEntry, (LPMODULEENTRY16)lpbyte );
  267. return( (BOOL)((WORD)dwResult) );
  268. }