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.

807 lines
28 KiB

  1. /*++ BUILD Version: 0003
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * WOW32.H
  8. * WOW32 16-bit API support
  9. *
  10. * History:
  11. * Created 27-Jan-1991 by Jeff Parsons (jeffpar)
  12. * Changed 12-May-1992 by Mike Tricker (MikeTri) Added MultiMedia header includes
  13. * Changed 30-Jul-1992 by Mike Tricker (MikeTri) Removed all Multimedia includes
  14. --*/
  15. #ifndef _DEF_WOW32_ // if this hasn't already been included
  16. #define _DEF_WOW32_
  17. #define HACK32
  18. #if DBG
  19. #define DEBUG 1
  20. #endif
  21. #ifdef i386
  22. #define PMODE32
  23. #define FASTCALL _fastcall
  24. #else
  25. #define FASTCALL
  26. #endif
  27. #include <stdarg.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <process.h>
  32. #include <nt.h>
  33. #include <ntrtl.h>
  34. #include <nturtl.h>
  35. #include <vdm.h>
  36. #include <windows.h>
  37. #include <winuserp.h>
  38. #include <shellapi.h>
  39. #include <tsappcmp.h>
  40. /***** ifdef( DEBUG || WOWPROFILE ) *****/
  41. #ifdef DEBUG
  42. #ifndef WOWPROFILE
  43. #define WOWPROFILE // DEBUG => WOWPROFILE
  44. #endif // !WOWPROFILE
  45. #endif // DEBUG
  46. #ifdef WOWPROFILE
  47. #ifndef DEBUG_OR_WOWPROFILE
  48. #define DEBUG_OR_WOWPROFILE
  49. #endif
  50. #endif // WOWPROFILE
  51. #include <wow.h>
  52. #include "walias.h"
  53. #include "wstruc.h"
  54. #include "wheap.h"
  55. #include "wowcmpat.h"
  56. //
  57. // Enable warnings that are turned off by sdk\inc\warning.h but we want on
  58. //
  59. #pragma warning(error:4101) // Unreferenced local variable
  60. /* Constants
  61. */
  62. #define CIRC_BUFFERS 100 // Number of Saved in Circular Buffer for debug logging only
  63. #define TMP_LINE_LEN 200 // maxlen of Circular Buffer strings
  64. #define FILTER_FUNCTION_MAX 10 // Number of Calls you can filter on
  65. #define WOWPRIVATEMSG 0x00010000 // this gets OR'd into certain 16-bit msg's
  66. // for handling special message cases
  67. #define CLR_BLACK 0x00000000
  68. #define CLR_RED 0x007F0000
  69. #define CLR_GREEN 0x00007F00
  70. #define CLR_BROWN 0x007F7F00
  71. #define CLR_BLUE 0x0000007F
  72. #define CLR_MAGENTA 0x007F007F
  73. #define CLR_CYAN 0x00007F7F
  74. #define CLR_LT_GRAY 0x00BFBFBF
  75. #define CLR_DK_GRAY 0x007F7F7F
  76. #define CLR_BR_RED 0x00FF0000
  77. #define CLR_BR_GREEN 0x0000FF00
  78. #define CLR_YELLOW 0x00FFFF00
  79. #define CLR_BR_BLUE 0x000000FF
  80. #define CLR_BR_MAGENTA 0x00FF00FF
  81. #define CLR_BR_CYAN 0x0000FFFF
  82. #define CLR_WHITE 0x00FFFFFF
  83. #define WM_CTLCOLOR 0x0019
  84. #define WM_WOWDESTROYCLIPBOARD 0x0
  85. #define WM_WOWSETCBDATA 0x0
  86. #define WOWVDM TRUE
  87. /* DO NOT CHANGE THE SIZES OF THESE TABLES WITHOUT
  88. ** CHANGING I386\FASTWOW.ASM!
  89. */
  90. typedef struct _PA32 {
  91. PW32 lpfnA32; // Array Address
  92. #ifdef DEBUG_OR_WOWPROFILE
  93. LPSZ lpszW32; // Table Name (DEBUG version only)
  94. INT *lpiFunMax; // Pointer # of table entries (DEBUG version only)
  95. #endif // DEBUG_OR_WOWPROFILE
  96. } PA32, *PPA32;
  97. #ifdef DEBUG_OR_WOWPROFILE
  98. #define W32FUN(fn,name,mod,size) fn,name,size,0L,0L
  99. #define W32MSGFUN(fn,name) fn,name,0L,0L
  100. #else // non-profile RETAIL
  101. #define W32FUN(fn,name,mod,size) fn
  102. #define W32MSGFUN(fn,name) fn
  103. #endif
  104. #ifdef DEBUG_OR_WOWPROFILE
  105. #define W32TAB(fn,name,size) fn,name,&size
  106. #else // RETAIL ONLY
  107. #define W32TAB(fn,name,size) fn
  108. #endif
  109. /* Per-thread data
  110. */
  111. #define CURRENTPTD() ((PTD)(NtCurrentTeb()->WOW32Reserved))
  112. #define PTEBTOPTD(pteb) ((PTD)((pteb)->WOW32Reserved))
  113. //
  114. // Internal flags used in the COMMDLGTD Flags element
  115. //
  116. #define WOWCD_ISCHOOSEFONT 1
  117. #define WOWCD_ISOPENFILE 2
  118. #define WOWCD_NOSSYNC 4
  119. //
  120. // Used for COMMDLG thunk support
  121. //
  122. typedef struct _COMMDLGTD {
  123. HWND16 hdlg; // hwnd of dialog & hwndOwner for Find/Replace
  124. VPVOID vpData; // vp to 16-bit struct passed to ComDlg API
  125. PVOID pData32; // ptr to 32-bit ANSI version of above struct
  126. VPVOID vpfnHook; // vp to 16-bit hook proc specified by app
  127. union {
  128. VPVOID vpfnSetupHook; // vp to 16-bit hook proc (print setup only)
  129. PVOID pRes; // ptr to 16-bit template resource
  130. };
  131. HWND16 SetupHwnd; // for Print Setup Dialogs only
  132. struct _COMMDLGTD *Previous; // for Find/Replace & nested dlg situations
  133. ULONG Flags;
  134. } COMMDLGTD, *PCOMMDLGTD;
  135. //
  136. // WOAINST
  137. //
  138. typedef struct _WOAINST {
  139. struct _WOAINST *pNext;
  140. struct _TD *ptdWOA; // TD of associated WinOldAp task
  141. DWORD dwChildProcessID;
  142. HANDLE hChildProcess;
  143. CHAR szModuleName[1]; // As provided to LoadModule
  144. } WOAINST, *PWOAINST;
  145. //
  146. // Structure to reflect WOW environment values
  147. //
  148. typedef struct tagWOWENVDATA {
  149. PSZ pszCompatLayer; // fully-formed compat layer variable
  150. PSZ pszCompatLayerVal; // pointer to the value part
  151. PSZ pszProcessHistory; // fully-formed process history variable
  152. PSZ pszProcessHistoryVal; // pointer to the value part
  153. PSZ pszShimFileLog; // file log variable
  154. PSZ pszShimFileLogVal;
  155. //
  156. // buffer that we use for the accomulated process history,
  157. // this buffer contains just the values from cumulative use of process history
  158. // in wow chain
  159. //
  160. PSZ pszCurrentProcessHistory;
  161. } WOWENVDATA, *PWOWENVDATA;
  162. //
  163. // TD.dwFlags bit definitions
  164. //
  165. // #define TDF_INITCALLBACKSTACK 0x00000001 // no longer needed
  166. #define TDF_EATDEVMODEMSG 0x00000001
  167. #define TDF_IGNOREINPUT 0x00000002
  168. #define TDF_FORCETASKEXIT 0x00000004
  169. #define TDF_TASKCLEANUPDONE 0x00000008
  170. // NOTE: vpCBStack must not be referenced outside of CallBack16(),
  171. // stackalloc16(), & stackfree16()!!!!
  172. // See NOTES in walloc16.c\stackalloc16()
  173. typedef struct _TD { /* td */
  174. VPVOID vpStack; // 16-bit stack MUST BE FIRST!!!
  175. VPVOID vpCBStack; // 16-bit callback frame (see NOTE above)
  176. DWORD FastWowEsp; // offset must match private\inc\vdmtib.inc
  177. PCOMMDLGTD CommDlgTd; // offset must match mvdm\inc\wowtd.h
  178. struct _TD *ptdNext; // Pointer to Next PTD
  179. DWORD dwFlags; // TDF_ values above
  180. INT VDMInfoiTaskID; // SCS Task ID != 0 if task Exec'd form 32 bit program
  181. DWORD dwWOWCompatFlags; // WOW Compatibility flags
  182. DWORD dwWOWCompatFlagsEx; // Extended WOW Compatibility flags
  183. DWORD dwUserWOWCompatFlags; // Extra User specific WOW Compatibility flags
  184. DWORD dwWOWCompatFlags2; // Extra WOW Compatibility flags
  185. #ifdef FE_SB
  186. DWORD dwWOWCompatFlagsFE; // Extended WOW Compatibility flags2
  187. #endif // FE_SB
  188. DWORD dwThreadID; // ID of the thread
  189. HANDLE hThread; // Thread Handle
  190. HHOOK hIdleHook; // Hook handle for USER idle notification
  191. HRGN hrgnClip; // used by GetClipRgn()
  192. ULONG ulLastDesktophDC; // remembers last desktop DC for GetDC(0)
  193. INT cStackAlloc16; // for tracking stackalloc16() memory alloc's
  194. PWOAINST pWOAList; // One per active winoldap child
  195. HAND16 htask16; // 16-bit kernel task handle - unique across VDMs
  196. HAND16 hInst16; // 16-bit instance handle for this task
  197. HAND16 hMod16; // 16-bit module handle for this task
  198. //
  199. // these "interesting" variables are set for the current task
  200. //
  201. PWOWENVDATA pWowEnvData; // pointer to wow environment data
  202. //
  203. // Variable is used to pass information from parent task (during pass_environment)
  204. // to the child (in W32Thread) - normally should be NULL after init phase
  205. //
  206. PWOWENVDATA pWowEnvDataChild;
  207. CRITICAL_SECTION csTD; // protects this particular TD, esp. WOA list
  208. } TD, *PTD;
  209. /* Options (for flOptions)
  210. *
  211. * Bits 0-15 are RESERVED for use by x86,
  212. * so it must match the x86 definition, if any! -JTP
  213. */
  214. #define OPT_DEBUG 0x00008 // shadow all log output on debug terminal (/d)
  215. #define OPT_BREAKONNEWTASK 0x00010 // breakpoint on new task start
  216. #define OPT_DONTPATCHCODE 0x00020 // doesnt patch wcallid with lpfnw32
  217. #define OPT_DEBUGRETURN 0x10000 // convert next WOW16 return to debug return
  218. #define OPT_FAKESUCCESS 0x20000 // convert selected failures into successes
  219. /* Logging Filtering Options (fLogFilter)
  220. *
  221. * To Log all output set fLogFilter = -1
  222. */
  223. #define FILTER_KERNEL 0x00000001
  224. #define FILTER_USER 0x00000002
  225. #define FILTER_GDI 0x00000004
  226. #define FILTER_KEYBOARD 0x00000008
  227. #define FILTER_SOUND 0x00000010
  228. #define FILTER_KERNEL16 0X00000020
  229. #define FILTER_MMEDIA 0x00000040
  230. #define FILTER_WINSOCK 0x00000080
  231. #define FILTER_VERBOSE 0x00000100
  232. #define FILTER_COMMDLG 0x00000200
  233. #ifdef FE_IME
  234. #define FILTER_WINNLS 0x00000400
  235. #endif
  236. #ifdef FE_SB
  237. #define FILTER_WIFEMAN 0x00000800
  238. #endif
  239. /* Global data
  240. */
  241. #ifdef DEBUG
  242. extern UCHAR gszAssert[256]; // Buffer for assertion text (could be eliminated with restructuring)
  243. int _cdecl sprintf_gszAssert(PSZ pszFmt, ...);
  244. extern HANDLE hfLog; // log file handle, if any
  245. #endif
  246. extern INT flOptions; // command-line options (see OPT_*)
  247. #ifdef DEBUG
  248. extern INT iLogLevel; // logging level; 0 implies none
  249. extern INT fDebugWait; // Single Step; 0 = No Single Step
  250. #endif
  251. extern HANDLE hHostInstance;
  252. #ifdef DEBUG
  253. extern INT fLogFilter; // Filter Catagories of Functions
  254. extern WORD fLogTaskFilter; // Filter Specific TaskID only
  255. #endif
  256. #ifdef DEBUG
  257. extern INT iReqLogLevel; // Current Output LogLevel
  258. extern INT iCircBuffer; // Current Buffer
  259. extern CHAR achTmp[CIRC_BUFFERS][TMP_LINE_LEN]; // Circular Buffer
  260. extern WORD awfLogFunctionFilter[FILTER_FUNCTION_MAX]; // Specific Filter API Array
  261. extern INT iLogFuncFiltIndex; // Index Into Specific Array for Debugger Extensions
  262. #endif
  263. /* WOW global data
  264. */
  265. extern UINT iW32ExecTaskId; // Base Task ID of Task Being Exec'd
  266. extern UINT nWOWTasks; // # of WOW tasks running
  267. extern BOOL fBoot; // TRUE During Boot Process
  268. extern HANDLE ghevWaitCreatorThread; // Used to Syncronize creation of a new thread
  269. extern BOOL fWowMode; // see comment in wow32.c
  270. extern HANDLE hWOWHeap;
  271. extern DECLSPEC_IMPORT BOOL fSeparateWow; // imported from ntvdm, FALSE if shared WOW VDM.
  272. extern HANDLE ghProcess; // WOW Process Handle
  273. extern PFNWOWHANDLERSOUT pfnOut; // USER secret API pointers
  274. extern DECLSPEC_IMPORT DWORD FlatAddress[]; // Base address of each selector in LDT
  275. extern DECLSPEC_IMPORT LPDWORD SelectorLimit; // Limit of each selector in LDT (x86 only)
  276. extern PTD * pptdWOA;
  277. extern PTD gptdShell;
  278. extern char szWINFAX[];
  279. extern char szINSTALL[];
  280. extern char szModem[];
  281. extern char szWINFAXCOMx[];
  282. extern BOOL gbWinFaxHack;
  283. extern char szEmbedding[];
  284. extern char szServerKey[];
  285. extern char szPicture[];
  286. extern char szPostscript[];
  287. extern char szZapfDingbats[];
  288. extern char szZapf_Dingbats[];
  289. extern char szSymbol[];
  290. extern char szTmsRmn[];
  291. extern char szHelv[];
  292. extern char szMavisCourier[];
  293. extern char szDevices[];
  294. extern char szBoot[];
  295. extern char szShell[];
  296. extern char szWinDotIni[];
  297. extern char szSystemDotIni[];
  298. extern char szExplorerDotExe[];
  299. extern PSTR pszWinIniFullPath;
  300. extern PSTR pszWindowsDirectory;
  301. extern PSTR pszSystemDirectory;
  302. extern BOOL gfIgnoreInputAssertGiven;
  303. #ifdef FE_SB
  304. extern char szSystemMincho[];
  305. extern char szMsMincho[];
  306. #endif
  307. extern DWORD dwSharedWowTimeout;
  308. extern DWORD gpfn16GetProcModule;
  309. #ifndef _X86_
  310. extern PUCHAR IntelMemoryBase; // Start of emulated CPU's memory
  311. #define pNtVDMState ((ULONG *)(IntelMemoryBase+FIXED_NTVDMSTATE_LINEAR))
  312. #endif
  313. /* WOW32 assertion/warning macros
  314. *
  315. * Take care where you put ASSERTs and where you put VERIFYs; ASSERT
  316. * expressions go away in the retail product, VERIFYs don't, so if an essential
  317. * calculation or function call is taking place, put it in WOW32VERIFY().
  318. *
  319. * WOW32ASSERT(exp) - prints module and line number and breakpoints
  320. * WOW32VERIFY(exp) - like WOW32ASSERT but expression evaluated on free build
  321. * WOW32ASSERTMSG(exp, msg) - print the string and breakpoint
  322. * WOW32ASSERTMSGF(exp, (fmt, args...)) - print the formatted string and
  323. * breakpoint
  324. * WOW32WARNMSG(exp, msg) - print the string but don't breakpoint
  325. * WOW32WARNMSGF(exp, (fmt, args, ...)) - print the formatted string but don't
  326. * breakpoint
  327. * WOW32APIWARN(exp, msg) - specific to API thunks, msg must be API name,
  328. * does not breakpoint at all.
  329. */
  330. #define EXCEPTION_WOW32_ASSERTION 0x9898
  331. #ifdef DEBUG
  332. #undef MODNAME
  333. #define MODNAME(module) static char szModule[] = __FILE__
  334. int DoAssert(PSZ szAssert, PSZ szModule, UINT line, UINT loglevel);
  335. #define WOW32ASSERT(exp) \
  336. { \
  337. if (!(exp)) \
  338. { \
  339. DoAssert(NULL, szModule, __LINE__, LOG_ALWAYS); \
  340. } \
  341. }
  342. #define WOW32VERIFY(exp) WOW32ASSERT(exp)
  343. #define WOW32ASSERTMSG(exp,msg) \
  344. { \
  345. if (!(exp)) { \
  346. DoAssert(msg, szModule, __LINE__, LOG_ALWAYS); \
  347. } \
  348. }
  349. #define WOW32ASSERTMSGF(exp, printf_args) \
  350. ( \
  351. (!(exp)) ? ( \
  352. sprintf_gszAssert printf_args, \
  353. DoAssert(gszAssert, szModule, __LINE__, LOG_ALWAYS) \
  354. ) : 0 \
  355. )
  356. #define WOW32WARNMSG(exp,msg) \
  357. { \
  358. if (!(exp)) { \
  359. LOGDEBUG(LOG_ALWAYS, ("%s", (msg))); \
  360. } \
  361. }
  362. #define WOW32WARNMSGF(exp, printf_args) \
  363. { \
  364. if (!(exp)) { \
  365. LOGDEBUG(LOG_ALWAYS, printf_args); \
  366. } \
  367. }
  368. #define WOW32APIWARN(exp,msg) \
  369. { \
  370. if (!(exp)) { \
  371. LOGDEBUG(1,(" WOW32 WARNING: %s failed", (msg))); \
  372. if (flOptions & OPT_FAKESUCCESS) { \
  373. LOGDEBUG(1,(" (but returning fake success)\n")); \
  374. (ULONG)exp = TRUE; \
  375. } \
  376. else { \
  377. LOGDEBUG(1,("\n")); \
  378. } \
  379. } \
  380. }
  381. #else
  382. #undef MODNAME
  383. #define MODNAME(module)
  384. #define WOW32ASSERT(exp)
  385. #define WOW32VERIFY(exp) (exp)
  386. #define WOW32ASSERTMSG(exp,msg)
  387. #define WOW32ASSERTMSGF(exp,msg)
  388. #define WOW32WARNMSG(exp,msg)
  389. #define WOW32WARNMSGF(exp,msg)
  390. #define WOW32APIWARN(exp,msg)
  391. #endif
  392. #ifdef DEBUG
  393. #define LOGARGS(l,v) logargs(l,v)
  394. #else
  395. #define LOGARGS(l,v)
  396. #endif
  397. #ifdef DEBUG
  398. #define LOGRETURN(l,v,r) logreturn(l,v,r)
  399. #else
  400. #define LOGRETURN(l,v,r)
  401. #endif
  402. //
  403. // Macros used to eliminate compiler warning generated when formal
  404. // parameters or local variables are not declared.
  405. //
  406. // Use DBG_UNREFERENCED_PARAMETER() when a parameter is not yet
  407. // referenced but will be once the module is completely developed.
  408. //
  409. // Use DBG_UNREFERENCED_LOCAL_VARIABLE() when a local variable is not yet
  410. // referenced but will be once the module is completely developed.
  411. //
  412. // Use UNREFERENCED_PARAMETER() if a parameter will never be referenced.
  413. //
  414. // DBG_UNREFERENCED_PARAMETER and DBG_UNREFERENCED_LOCAL_VARIABLE will
  415. // eventually be made into a null macro to help determine whether there
  416. // is unfinished work.
  417. //
  418. #ifndef UNREFERENCED_PARAMETER
  419. #define UNREFERENCED_PARAMETER(P) (P)
  420. #define DBG_UNREFERENCED_PARAMETER(P) (P)
  421. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) (V)
  422. #endif
  423. #define SIZE_BOGUS 256
  424. #define SIZETO64K(s) (s?(INT)s:(INT)(64*K)) // return 64K if zero
  425. #define CHAR32(b) ((CHAR)(b))
  426. #define BYTE32(b) ((BYTE)(b))
  427. #define INT32(i) ((INT)(INT16)(i))
  428. #define UINT32(i) ((unsigned int)(i))
  429. #define BOOL32(f) ((BOOL)(f))
  430. #define WORD32(w) ((WORD)(w))
  431. #define LONG32(l) FETCHLONG(l)
  432. #define DWORD32(dw) FETCHDWORD(dw)
  433. #define VPFN32(fn) FETCHDWORD(fn)
  434. #define INT32DEFAULT(i) ((WORD)i==(WORD)CW_USEDEFAULT16?(UINT)(WORD)i:INT32(i))
  435. #define GETBYTE16(v) (v)
  436. #define GETINT16(v) ((INT16)(v))
  437. #define GETBOOL16(v) ((BOOL16)(v))
  438. #define GETWORD16(v) (v)
  439. #define GETLONG16(v) (v)
  440. #define GETDWORD16(v) (v)
  441. #define GETUINT16(v) ((WORD)(v))
  442. #define ATOM32(a16) (a16) // bogus
  443. #define PROC32(vpfn16) ((PROC)FETCHDWORD(vpfn16))
  444. #define NPSTR32(np16) ((NPSTR)(np16)) // bogus
  445. #define GETATOM16(v) (v) // bogus
  446. #define GETPROC16(v) ((ULONG)(v)) // bogus
  447. #define GETWNDPROC16(v) ((ULONG)(v)) // bogus
  448. #define GETNPSTRBOGUS(v) ((ULONG)(INT)(v)) // bogus
  449. #define GETLPSTRBOGUS(v) ((ULONG)(v)) // bogus
  450. #define GETLPWORDBOGUS(v) ((ULONG)(v)) // bogus
  451. /* Simulator wrapper macros
  452. */
  453. #ifndef _X86_ // emulated CPU
  454. #define VDMSTACK() (((ULONG)getSS()<<16)|getSP())
  455. #define SETVDMSTACK(vp) {setSS(HIW(vp)); setSP(LOW(vp));}
  456. #else // X86
  457. #define VDMSTACK() ((USHORT)((PVDM_TIB)(NtCurrentTeb()->Vdm))->VdmContext.SegSs << 16 | (USHORT)((PVDM_TIB)(NtCurrentTeb()->Vdm))->VdmContext.Esp)
  458. #define SETVDMSTACK(vp) ((PVDM_TIB)(NtCurrentTeb()->Vdm))->VdmContext.SegSs = HIW(vp); ((PVDM_TIB)(NtCurrentTeb()->Vdm))->VdmContext.Esp = LOW(vp);
  459. #endif
  460. // Use FlatAddress array exported by ntvdm instead of Sim32GetVDMPointer.
  461. #ifndef _X86_
  462. #define INTEL_MEMORY_BASE ((DWORD)IntelMemoryBase)
  463. #else
  464. #define INTEL_MEMORY_BASE (0)
  465. #endif
  466. #define GetPModeVDMPointerMacro(Address, Count) \
  467. ( \
  468. FlatAddress[(Address) >> 19] \
  469. ? (void *)(FlatAddress[(Address) >> 19] + ((Address) & 0xFFFF)) \
  470. : NULL \
  471. )
  472. #define SetPModeVDMPointerBase(Selector, Base) \
  473. { \
  474. FlatAddress[Selector >> 3] = Base; \
  475. } \
  476. #define GetRModeVDMPointer(Address) \
  477. (void *)(INTEL_MEMORY_BASE + (((Address) & 0xFFFF0000) >> 12) + \
  478. ((Address) & 0xFFFF))
  479. #ifdef DEBUG
  480. PVOID FASTCALL GetPModeVDMPointerAssert(DWORD Address, DWORD Count);
  481. #define GetPModeVDMPointer(vp, count) GetPModeVDMPointerAssert((vp), (count))
  482. #else
  483. PVOID FASTCALL GetPModeVDMPointerAssert(DWORD Address);
  484. #define GetPModeVDMPointer(vp, count) GetPModeVDMPointerAssert((vp))
  485. #endif
  486. #define SEGPTR(seg,off) GetPModeVDMPointer(((ULONG)seg<<16)|off, 0)
  487. #define FRAMEPTR(vp) ((PVDMFRAME)GetPModeVDMPointer(vp, 0))
  488. #define CBFRAMEPTR(vp) ((PCBVDMFRAME)GetPModeVDMPointer(vp, 0))
  489. #define GETFRAMEPTR(vp,p) {p=FRAMEPTR(vp); }
  490. #define GETARGPTR(p,cb,parg) parg=(PVOID)((ULONG)p+OFFSETOF(VDMFRAME,bArgs));
  491. #define VDMPTR(vp,cb) (PVOID)GetPModeVDMPointer(FETCHDWORD(vp),(cb))
  492. #define GETVDMPTR(vp,cb,p) ((p)=VDMPTR((vp),(cb)))
  493. #define GETOPTPTR(vp,cb,p) {(p)=NULL; if (FETCHDWORD(vp)) GETVDMPTR(vp,cb,p);}
  494. #define GETSTRPTR(vp,cb,p) {GETVDMPTR(vp,cb,p); LOGDEBUG(11,(" String @%08lx: \"%.*s\"\n",vp,min((cb),80),(p)));}
  495. #define GETVARSTRPTR(vp,cb,p) {GETVDMPTR(vp,(((cb)==-1)?1:(cb)),p); LOGDEBUG(11,(" String @%08lx: \"%.*s\"\n",(vp),min(((cb)==-1)?strlen(p):(cb),80),(p)));}
  496. #define GETPSZPTR(vp,p) {GETOPTPTR(vp,1,p); LOGDEBUG(11,(" String @%08lx: \"%.80s\"\n",(FETCHDWORD(vp)),(p)));}
  497. #define GETPSZPTRNOLOG(vp,p) GETOPTPTR(vp,1,p)
  498. #define GETPSZIDPTR(vp,p) {p=(LPSZ)FETCHDWORD(vp); if (HIW16(vp)) GETPSZPTR(vp,p);}
  499. #define GETMISCPTR(vp,p) GETOPTPTR(vp,1,p) // intended for non-string variable-length pointers
  500. #define ALLOCVDMPTR(vp,cb,p) GETVDMPTR(vp,cb,p) // intended for output-only pointers
  501. //
  502. // Macros to "flush" VDM pointers after modifying 16-bit memory.
  503. // Use FLUSHVDMCODEPTR when the 16-bit memory contains x86 code.
  504. // Use FLUSHVDMPTR when the 16-bit memory does not contain x86 code.
  505. //
  506. // On x86, these macros are NOPs. On RISC, FLUSHVDMPTR is a NOP, while
  507. // FLUSHVDMCODEPTR actually calls the emulator so it can recompile any
  508. // code affected.
  509. //
  510. #define FLUSHVDMCODEPTR(vp,cb,p) Sim32FlushVDMPointer( (vp), (USHORT)(cb), (PBYTE)(p), (fWowMode))
  511. //#define FLUSHVDMPTR(vp,cb,p) TRUE // BUGBUG! davehart
  512. #define FLUSHVDMPTR(vp,cb,p) FLUSHVDMCODEPTR(vp,cb,p)
  513. #define LOG_ALWAYS 0x00
  514. #define LOG_ERROR 0x01
  515. #define LOG_IMPORTANT LOG_ERROR
  516. #define LOG_WARNING 0x02
  517. #define LOG_TRACE 0x04
  518. #define LOG_PRIVATE 0x08
  519. #define LOG_API 0x10
  520. #define LOG_MSG 0x20
  521. #define LOG_CALLBACK 0x40
  522. #define LOG_STRING 0x80
  523. #ifndef i386
  524. #ifdef DEBUG
  525. static CHAR *pszLogNull = "<null>";
  526. #undef GETPSZPTR
  527. #define GETPSZPTR(vp,p) {GETOPTPTR(vp,0,p); LOGDEBUG(11,(" String @%08lx: \"%.80s\"\n",(FETCHDWORD(vp)),p ? p : pszLogNull));}
  528. #endif
  529. #endif
  530. #ifndef DEBUG
  531. #define FREEARGPTR(p)
  532. #define FREEOPTPTR(p)
  533. #define FREESTRPTR(p)
  534. #define FREEPSZPTR(p)
  535. #define FREEPSZIDPTR(p)
  536. #define FREEMISCPTR(p)
  537. #define FREEVDMPTR(p)
  538. #define FREEOPTPTR(p)
  539. #else
  540. #define FREEARGPTR(p) p=NULL
  541. #define FREEOPTPTR(p) p=NULL
  542. #define FREESTRPTR(p) p=NULL
  543. #define FREEPSZPTR(p) p=NULL
  544. #define FREEPSZIDPTR(p) p=NULL
  545. #define FREEMISCPTR(p) p=NULL
  546. #define FREEVDMPTR(p) p=NULL
  547. #define FREEOPTPTR(p) p=NULL
  548. #endif
  549. #define RETURN(ul) return ul
  550. #ifdef DBCS // MUST fix for FE NT
  551. #define FIX_318197_NOW
  552. #endif
  553. #ifdef FIX_318197_NOW
  554. #define WOW32_strupr(psz) CharUpperA(psz)
  555. #define WOW32_strlwr(psz) CharLowerA(psz)
  556. #define WOW32_strcmp(psz1, psz2) lstrcmpA(psz1, psz2)
  557. #define WOW32_stricmp(psz1, psz2) lstrcmpiA(psz1, psz2)
  558. #define WOW32_strncpy(psz1, psz2, n) lstrcpyn(psz1, psz2, n)
  559. char* WOW32_strchr(const char* psz, int c);
  560. char* WOW32_strrchr(const char* psz, int c);
  561. char* WOW32_strstr(const char* str1, const char* str2);
  562. int WOW32_strncmp(const char* str1, const char* str2, size_t n);
  563. int WOW32_strnicmp(const char* str1, const char* str2, size_t n);
  564. #else
  565. #define WOW32_strupr(psz) _strupr(psz)
  566. #define WOW32_strlwr(psz) _strlwr(psz)
  567. #define WOW32_strcmp(psz1, psz2) strcmp(psz1, psz2)
  568. #define WOW32_stricmp(psz1, psz2) _stricmp(psz1, psz2)
  569. #define WOW32_strncpy(psz1, psz2, n) strncpy(psz1, psz2, n)
  570. #define WOW32_strchr(psz,c) strchr(psz,c)
  571. #define WOW32_strrchr(psz,c) strrchr(psz,c)
  572. #define WOW32_strstr(psz1, psz2) strstr(psz1, psz2)
  573. #define WOW32_strncmp(psz1, psz2, n) strncmp(psz1, psz2, n)
  574. #define WOW32_strnicmp(psz1, psz2, n) _strnicmp(psz1, psz2, n)
  575. #endif
  576. /* Function prototypes
  577. */
  578. BOOL W32Init(BOOL fMEoW);
  579. VOID W32Dispatch(VOID);
  580. INT W32Exception(DWORD dwException, PEXCEPTION_POINTERS pexi);
  581. BOOLEAN W32DllInitialize(PVOID DllHandle,ULONG Reason,PCONTEXT Context);
  582. BOOL IsDebuggerAttached(VOID);
  583. ULONG FASTCALL WK32WOWGetFastAddress( PVDMFRAME pFrame );
  584. ULONG FASTCALL WK32WOWGetFastCbRetAddress( PVDMFRAME pFrame );
  585. ULONG FASTCALL WK32WOWGetTableOffsets( PVDMFRAME pFrame );
  586. ULONG FASTCALL WK32WOWGetFlatAddressArray( PVDMFRAME pFrame );
  587. PTD ThreadProcID32toPTD(DWORD ThreadID, DWORD dwProcessID);
  588. PTD Htask16toPTD( HAND16 );
  589. HTASK16 ThreadID32toHtask16(DWORD ThreadID32);
  590. PVOID WOWStartupFailed(VOID);
  591. LPSTR ThunkStr16toStr32(LPSTR pdst32, VPVOID vpsrc16, int cChars, BOOL bMulti);
  592. #ifdef DEBUG
  593. VOID logprintf(PSZ psz, ...);
  594. VOID logargs(INT iLog, PVDMFRAME pFrame);
  595. VOID logreturn(INT iLog, PVDMFRAME pFrame, ULONG ulReturn);
  596. BOOL checkloging(register PVDMFRAME pFrame);
  597. #endif
  598. #ifdef DEBUG_OR_WOWPROFILE
  599. DWORD GetWOWTicDiff(DWORD dwPrevCount);
  600. INT GetFuncId(DWORD iFun);
  601. #endif
  602. BOOL IsDebuggerAttached(VOID);
  603. //
  604. // Thunk table stub functions and aliases.
  605. //
  606. ULONG FASTCALL WOW32UnimplementedAPI(PVDMFRAME pFrame);
  607. ULONG FASTCALL WOW32Unimplemented95API(PVDMFRAME pFrame);
  608. // for tracking memory leaks
  609. #ifdef DEBUG
  610. #define DEBUG_MEMLEAK 1
  611. #else // non-DEBUG
  612. #ifdef MEMLEAK
  613. #define DEBUG_MEMLEAK 1
  614. #endif // MEMLEAK
  615. #endif // DEBUG
  616. #ifdef DEBUG_MEMLEAK
  617. VOID WOW32DebugMemLeak(PVOID lp, ULONG size, DWORD fHow);
  618. VOID WOW32DebugReMemLeak(PVOID lpNew, PVOID lpOrig, ULONG size, DWORD fHow);
  619. VOID WOW32DebugFreeMem(PVOID lp);
  620. VOID WOW32DebugCorruptionCheck(PVOID lp, DWORD size);
  621. DWORD WOW32DebugGetMemSize(PVOID lp);
  622. HGLOBAL WOW32DebugGlobalAlloc(UINT flags, DWORD dwSize);
  623. HGLOBAL WOW32DebugGlobalReAlloc(HGLOBAL h32, DWORD dwSize, UINT flags);
  624. HGLOBAL WOW32DebugGlobalFree(HGLOBAL h32);
  625. #define WOWGLOBALALLOC(f,s) WOW32DebugGlobalAlloc(f,(s))
  626. #define WOWGLOBALREALLOC(h,s,f) WOW32DebugGlobalReAlloc(h,(s),f)
  627. #define WOWGLOBALFREE(h) WOW32DebugGlobalFree(h)
  628. #define ML_MALLOC_W 0x00000001
  629. #define ML_MALLOC_W_ZERO 0x00000002
  630. #define ML_REALLOC_W 0x00000004
  631. #define ML_MALLOC_WTYPE (ML_MALLOC_W | ML_MALLOC_W_ZERO | ML_REALLOC_W)
  632. #define ML_GLOBALALLOC 0x00000010
  633. #define ML_GLOBALREALLOC 0x00000020
  634. #define ML_GLOBALTYPE (ML_GLOBALREALLOC | ML_GLOBALALLOC)
  635. #define TAILCHECK (4 * sizeof(CHAR)) // for heap tail corruption check
  636. typedef struct _tagMEMLEAK {
  637. struct _tagMEMLEAK *lpmlNext;
  638. PVOID lp;
  639. DWORD size;
  640. UINT fHow;
  641. ULONG Count;
  642. PVOID CallersAddress;
  643. } MEMLEAK, *LPMEMLEAK;
  644. #else // non-DEBUG_MEMLEAK
  645. #define TAILCHECK 0
  646. #define WOWGLOBALALLOC(f,s) GlobalAlloc(f,(s))
  647. #define WOWGLOBALREALLOC(h,f,s) GlobalReAlloc(h, f,(s))
  648. #define WOWGLOBALFREE(h) GlobalFree(h)
  649. #endif // DEBUG_MEMLEAK
  650. #ifdef DEBUG
  651. ULONG FASTCALL WOW32NopAPI(PVDMFRAME pFrame);
  652. ULONG FASTCALL WOW32LocalAPI(PVDMFRAME pFrame);
  653. ULONG FASTCALL WK32WowPartyByNumber(PVDMFRAME pFrame);
  654. #define LOCALAPI WOW32LocalAPI
  655. #define NOPAPI WOW32NopAPI
  656. #define UNIMPLEMENTEDAPI WOW32UnimplementedAPI
  657. #define UNIMPLEMENTED95API WOW32Unimplemented95API
  658. #define WK32WOWPARTYBYNUMBER WK32WowPartyByNumber
  659. #else
  660. #define LOCALAPI WOW32UnimplementedAPI
  661. #define NOPAPI WOW32UnimplementedAPI
  662. #define UNIMPLEMENTEDAPI WOW32UnimplementedAPI
  663. #define UNIMPLEMENTED95API WOW32UnimplementedAPI
  664. #define WK32WOWPARTYBYNUMBER UNIMPLEMENTEDAPI
  665. #endif
  666. //Terminal Server
  667. PTERMSRVCORINIFILE gpfnTermsrvCORIniFile;
  668. #endif // ifndef _DEF_WOW32_ THIS SHOULD BE THE LAST LINE IN THIS FILE