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.

815 lines
29 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; // Ptr to the TD that owns the common dlg
  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. PVOID pWOWCompatFlagsEx_Info; // Compat flag parameters if any
  189. PVOID pWOWCompatFlags2_Info; //
  190. DWORD dwThreadID; // ID of the thread
  191. HANDLE hThread; // Thread Handle
  192. HHOOK hIdleHook; // Hook handle for USER idle notification
  193. HRGN hrgnClip; // used by GetClipRgn()
  194. ULONG ulLastDesktophDC; // remembers last desktop DC for GetDC(0)
  195. INT cStackAlloc16; // for tracking stackalloc16() memory alloc's
  196. PWOAINST pWOAList; // One per active winoldap child
  197. HAND16 htask16; // 16-bit kernel task handle - unique across VDMs
  198. HAND16 hInst16; // 16-bit instance handle for this task
  199. HAND16 hMod16; // 16-bit module handle for this task
  200. //
  201. // these "interesting" variables are set for the current task
  202. //
  203. PWOWENVDATA pWowEnvData; // pointer to wow environment data
  204. //
  205. // Variable is used to pass information from parent task (during pass_environment)
  206. // to the child (in W32Thread) - normally should be NULL after init phase
  207. //
  208. PWOWENVDATA pWowEnvDataChild;
  209. CRITICAL_SECTION csTD; // protects this particular TD, esp. WOA list
  210. } TD, *PTD;
  211. /* Options (for flOptions)
  212. *
  213. * Bits 0-15 are RESERVED for use by x86,
  214. * so it must match the x86 definition, if any! -JTP
  215. */
  216. #define OPT_DEBUG 0x00008 // shadow all log output on debug terminal (/d)
  217. #define OPT_BREAKONNEWTASK 0x00010 // breakpoint on new task start
  218. #define OPT_DONTPATCHCODE 0x00020 // doesnt patch wcallid with lpfnw32
  219. #define OPT_DEBUGRETURN 0x10000 // convert next WOW16 return to debug return
  220. #define OPT_FAKESUCCESS 0x20000 // convert selected failures into successes
  221. /* Logging Filtering Options (fLogFilter)
  222. *
  223. * To Log all output set fLogFilter = -1
  224. */
  225. #define FILTER_KERNEL 0x00000001
  226. #define FILTER_USER 0x00000002
  227. #define FILTER_GDI 0x00000004
  228. #define FILTER_KEYBOARD 0x00000008
  229. #define FILTER_SOUND 0x00000010
  230. #define FILTER_KERNEL16 0X00000020
  231. #define FILTER_MMEDIA 0x00000040
  232. #define FILTER_WINSOCK 0x00000080
  233. #define FILTER_VERBOSE 0x00000100
  234. #define FILTER_COMMDLG 0x00000200
  235. #ifdef FE_IME
  236. #define FILTER_WINNLS 0x00000400
  237. #endif
  238. #ifdef FE_SB
  239. #define FILTER_WIFEMAN 0x00000800
  240. #endif
  241. /* Global data
  242. */
  243. #ifdef DEBUG
  244. extern UCHAR gszAssert[256]; // Buffer for assertion text (could be eliminated with restructuring)
  245. int _cdecl sprintf_gszAssert(PSZ pszFmt, ...);
  246. extern HANDLE hfLog; // log file handle, if any
  247. #endif
  248. extern INT flOptions; // command-line options (see OPT_*)
  249. #ifdef DEBUG
  250. extern INT iLogLevel; // logging level; 0 implies none
  251. extern INT fDebugWait; // Single Step; 0 = No Single Step
  252. #endif
  253. extern HANDLE hHostInstance;
  254. #ifdef DEBUG
  255. extern INT fLogFilter; // Filter Catagories of Functions
  256. extern WORD fLogTaskFilter; // Filter Specific TaskID only
  257. #endif
  258. #ifdef DEBUG
  259. extern INT iReqLogLevel; // Current Output LogLevel
  260. extern INT iCircBuffer; // Current Buffer
  261. extern CHAR achTmp[CIRC_BUFFERS][TMP_LINE_LEN]; // Circular Buffer
  262. extern WORD awfLogFunctionFilter[FILTER_FUNCTION_MAX]; // Specific Filter API Array
  263. extern INT iLogFuncFiltIndex; // Index Into Specific Array for Debugger Extensions
  264. #endif
  265. /* WOW global data
  266. */
  267. extern UINT iW32ExecTaskId; // Base Task ID of Task Being Exec'd
  268. extern UINT nWOWTasks; // # of WOW tasks running
  269. extern BOOL fBoot; // TRUE During Boot Process
  270. extern HANDLE ghevWaitCreatorThread; // Used to Syncronize creation of a new thread
  271. extern BOOL fWowMode; // see comment in wow32.c
  272. extern HANDLE hWOWHeap;
  273. extern DECLSPEC_IMPORT BOOL fSeparateWow; // imported from ntvdm, FALSE if shared WOW VDM.
  274. extern HANDLE ghProcess; // WOW Process Handle
  275. extern PFNWOWHANDLERSOUT pfnOut; // USER secret API pointers
  276. extern DECLSPEC_IMPORT DWORD FlatAddress[]; // Base address of each selector in LDT
  277. extern DECLSPEC_IMPORT LPDWORD SelectorLimit; // Limit of each selector in LDT (x86 only)
  278. extern DECLSPEC_IMPORT PBYTE Dos_Flag_Addr; // ntdos.sys DOS_FLAG address
  279. extern PTD * pptdWOA;
  280. extern PTD gptdShell;
  281. extern char szWINFAX[];
  282. extern char szINSTALL[];
  283. extern char szModem[];
  284. extern char szWINFAXCOMx[];
  285. extern BOOL gbWinFaxHack;
  286. extern char szEmbedding[];
  287. extern char szServerKey[];
  288. extern char szPicture[];
  289. extern char szPostscript[];
  290. extern char szZapfDingbats[];
  291. extern char szZapf_Dingbats[];
  292. extern char szSymbol[];
  293. extern char szTmsRmn[];
  294. extern char szHelv[];
  295. extern char szMavisCourier[];
  296. extern char szDevices[];
  297. extern char szBoot[];
  298. extern char szShell[];
  299. extern char szWinDotIni[];
  300. extern char szSystemDotIni[];
  301. extern char szExplorerDotExe[];
  302. extern PSTR pszWinIniFullPath;
  303. extern PSTR pszWindowsDirectory;
  304. extern PSTR pszSystemDirectory;
  305. extern PWSTR pszSystemDirectoryW;
  306. extern BOOL gfIgnoreInputAssertGiven;
  307. extern DWORD cbWinIniFullPathLen;
  308. extern DWORD cbWindowsDirLen;
  309. extern DWORD cbSystemDirLen;
  310. extern DWORD cbSystemDirLenW;
  311. #ifdef FE_SB
  312. extern char szSystemMincho[];
  313. extern char szMsMincho[];
  314. #endif
  315. extern DWORD dwSharedWowTimeout;
  316. extern DWORD gpfn16GetProcModule;
  317. #ifndef _X86_
  318. extern PUCHAR IntelMemoryBase; // Start of emulated CPU's memory
  319. #define pNtVDMState ((ULONG *)(IntelMemoryBase+FIXED_NTVDMSTATE_LINEAR))
  320. #endif
  321. /* WOW32 assertion/warning macros
  322. *
  323. * Take care where you put ASSERTs and where you put VERIFYs; ASSERT
  324. * expressions go away in the retail product, VERIFYs don't, so if an essential
  325. * calculation or function call is taking place, put it in WOW32VERIFY().
  326. *
  327. * WOW32ASSERT(exp) - prints module and line number and breakpoints
  328. * WOW32VERIFY(exp) - like WOW32ASSERT but expression evaluated on free build
  329. * WOW32ASSERTMSG(exp, msg) - print the string and breakpoint
  330. * WOW32ASSERTMSGF(exp, (fmt, args...)) - print the formatted string and
  331. * breakpoint
  332. * WOW32WARNMSG(exp, msg) - print the string but don't breakpoint
  333. * WOW32WARNMSGF(exp, (fmt, args, ...)) - print the formatted string but don't
  334. * breakpoint
  335. * WOW32APIWARN(exp, msg) - specific to API thunks, msg must be API name,
  336. * does not breakpoint at all.
  337. */
  338. #define EXCEPTION_WOW32_ASSERTION 0x9898
  339. #ifdef DEBUG
  340. #undef MODNAME
  341. #define MODNAME(module) static char szModule[] = __FILE__
  342. int DoAssert(PSZ szAssert, PSZ szModule, UINT line, UINT loglevel);
  343. #define WOW32ASSERT(exp) \
  344. { \
  345. if (!(exp)) \
  346. { \
  347. DoAssert(NULL, szModule, __LINE__, LOG_ALWAYS); \
  348. } \
  349. }
  350. #define WOW32VERIFY(exp) WOW32ASSERT(exp)
  351. #define WOW32ASSERTMSG(exp,msg) \
  352. { \
  353. if (!(exp)) { \
  354. DoAssert(msg, szModule, __LINE__, LOG_ALWAYS); \
  355. } \
  356. }
  357. #define WOW32ASSERTMSGF(exp, printf_args) \
  358. ( \
  359. (!(exp)) ? ( \
  360. sprintf_gszAssert printf_args, \
  361. DoAssert(gszAssert, szModule, __LINE__, LOG_ALWAYS) \
  362. ) : 0 \
  363. )
  364. #define WOW32WARNMSG(exp,msg) \
  365. { \
  366. if (!(exp)) { \
  367. LOGDEBUG(LOG_ALWAYS, ("%s", (msg))); \
  368. } \
  369. }
  370. #define WOW32WARNMSGF(exp, printf_args) \
  371. { \
  372. if (!(exp)) { \
  373. LOGDEBUG(LOG_ALWAYS, printf_args); \
  374. } \
  375. }
  376. #define WOW32APIWARN(exp,msg) \
  377. { \
  378. if (!(exp)) { \
  379. LOGDEBUG(1,(" WOW32 WARNING: %s failed", (msg))); \
  380. if (flOptions & OPT_FAKESUCCESS) { \
  381. LOGDEBUG(1,(" (but returning fake success)\n")); \
  382. (ULONG)exp = TRUE; \
  383. } \
  384. else { \
  385. LOGDEBUG(1,("\n")); \
  386. } \
  387. } \
  388. }
  389. #else
  390. #undef MODNAME
  391. #define MODNAME(module)
  392. #define WOW32ASSERT(exp)
  393. #define WOW32VERIFY(exp) (exp)
  394. #define WOW32ASSERTMSG(exp,msg)
  395. #define WOW32ASSERTMSGF(exp,msg)
  396. #define WOW32WARNMSG(exp,msg)
  397. #define WOW32WARNMSGF(exp,msg)
  398. #define WOW32APIWARN(exp,msg)
  399. #endif
  400. #ifdef DEBUG
  401. #define LOGARGS(l,v) logargs(l,v)
  402. #else
  403. #define LOGARGS(l,v)
  404. #endif
  405. #ifdef DEBUG
  406. #define LOGRETURN(l,v,r) logreturn(l,v,r)
  407. #else
  408. #define LOGRETURN(l,v,r)
  409. #endif
  410. //
  411. // Macros used to eliminate compiler warning generated when formal
  412. // parameters or local variables are not declared.
  413. //
  414. // Use DBG_UNREFERENCED_PARAMETER() when a parameter is not yet
  415. // referenced but will be once the module is completely developed.
  416. //
  417. // Use DBG_UNREFERENCED_LOCAL_VARIABLE() when a local variable is not yet
  418. // referenced but will be once the module is completely developed.
  419. //
  420. // Use UNREFERENCED_PARAMETER() if a parameter will never be referenced.
  421. //
  422. // DBG_UNREFERENCED_PARAMETER and DBG_UNREFERENCED_LOCAL_VARIABLE will
  423. // eventually be made into a null macro to help determine whether there
  424. // is unfinished work.
  425. //
  426. #ifndef UNREFERENCED_PARAMETER
  427. #define UNREFERENCED_PARAMETER(P) (P)
  428. #define DBG_UNREFERENCED_PARAMETER(P) (P)
  429. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) (V)
  430. #endif
  431. #define SIZE_BOGUS 256
  432. #define SIZETO64K(s) (s?(INT)s:(INT)(64*K)) // return 64K if zero
  433. #define CHAR32(b) ((CHAR)(b))
  434. #define BYTE32(b) ((BYTE)(b))
  435. #define INT32(i) ((INT)(INT16)(i))
  436. #define UINT32(i) ((unsigned int)(i))
  437. #define BOOL32(f) ((BOOL)(f))
  438. #define WORD32(w) ((WORD)(w))
  439. #define LONG32(l) FETCHLONG(l)
  440. #define DWORD32(dw) FETCHDWORD(dw)
  441. #define VPFN32(fn) FETCHDWORD(fn)
  442. #define INT32DEFAULT(i) ((WORD)i==(WORD)CW_USEDEFAULT16?(UINT)(WORD)i:INT32(i))
  443. #define GETBYTE16(v) (v)
  444. #define GETINT16(v) ((INT16)(v))
  445. #define GETBOOL16(v) ((BOOL16)(v))
  446. #define GETWORD16(v) (v)
  447. #define GETLONG16(v) (v)
  448. #define GETDWORD16(v) (v)
  449. #define GETUINT16(v) ((WORD)(v))
  450. #define ATOM32(a16) (a16) // bogus
  451. #define PROC32(vpfn16) ((PROC)FETCHDWORD(vpfn16))
  452. #define NPSTR32(np16) ((NPSTR)(np16)) // bogus
  453. #define GETATOM16(v) (v) // bogus
  454. #define GETPROC16(v) ((ULONG)(v)) // bogus
  455. #define GETWNDPROC16(v) ((ULONG)(v)) // bogus
  456. #define GETNPSTRBOGUS(v) ((ULONG)(INT)(v)) // bogus
  457. #define GETLPSTRBOGUS(v) ((ULONG)(v)) // bogus
  458. #define GETLPWORDBOGUS(v) ((ULONG)(v)) // bogus
  459. /* Simulator wrapper macros
  460. */
  461. #ifndef _X86_ // emulated CPU
  462. #define VDMSTACK() (((ULONG)getSS()<<16)|getSP())
  463. #define SETVDMSTACK(vp) {setSS(HIW(vp)); setSP(LOW(vp));}
  464. #else // X86
  465. #define VDMSTACK() ((USHORT)((PVDM_TIB)(NtCurrentTeb()->Vdm))->VdmContext.SegSs << 16 | (USHORT)((PVDM_TIB)(NtCurrentTeb()->Vdm))->VdmContext.Esp)
  466. #define SETVDMSTACK(vp) ((PVDM_TIB)(NtCurrentTeb()->Vdm))->VdmContext.SegSs = HIW(vp); ((PVDM_TIB)(NtCurrentTeb()->Vdm))->VdmContext.Esp = LOW(vp);
  467. #endif
  468. // Use FlatAddress array exported by ntvdm instead of Sim32GetVDMPointer.
  469. #ifndef _X86_
  470. #define INTEL_MEMORY_BASE ((DWORD)IntelMemoryBase)
  471. #else
  472. #define INTEL_MEMORY_BASE (0)
  473. #endif
  474. #define GetPModeVDMPointerMacro(Address, Count) \
  475. ( \
  476. FlatAddress[(Address) >> 19] \
  477. ? (void *)(FlatAddress[(Address) >> 19] + ((Address) & 0xFFFF)) \
  478. : NULL \
  479. )
  480. #define SetPModeVDMPointerBase(Selector, Base) \
  481. { \
  482. FlatAddress[Selector >> 3] = Base; \
  483. } \
  484. #define GetRModeVDMPointer(Address) \
  485. (void *)(INTEL_MEMORY_BASE + (((Address) & 0xFFFF0000) >> 12) + \
  486. ((Address) & 0xFFFF))
  487. #ifdef DEBUG
  488. PVOID FASTCALL GetPModeVDMPointerAssert(DWORD Address, DWORD Count);
  489. #define GetPModeVDMPointer(vp, count) GetPModeVDMPointerAssert((vp), (count))
  490. #else
  491. PVOID FASTCALL GetPModeVDMPointerAssert(DWORD Address);
  492. #define GetPModeVDMPointer(vp, count) GetPModeVDMPointerAssert((vp))
  493. #endif
  494. #define SEGPTR(seg,off) GetPModeVDMPointer(((ULONG)seg<<16)|off, 0)
  495. #define FRAMEPTR(vp) ((PVDMFRAME)GetPModeVDMPointer(vp, 0))
  496. #define CBFRAMEPTR(vp) ((PCBVDMFRAME)GetPModeVDMPointer(vp, 0))
  497. #define GETFRAMEPTR(vp,p) {p=FRAMEPTR(vp); }
  498. #define GETARGPTR(p,cb,parg) parg=(PVOID)((ULONG)p+OFFSETOF(VDMFRAME,bArgs));
  499. #define VDMPTR(vp,cb) (PVOID)GetPModeVDMPointer(FETCHDWORD(vp),(cb))
  500. #define GETVDMPTR(vp,cb,p) ((p)=VDMPTR((vp),(cb)))
  501. #define GETOPTPTR(vp,cb,p) {(p)=NULL; if (FETCHDWORD(vp)) GETVDMPTR(vp,cb,p);}
  502. #define GETSTRPTR(vp,cb,p) {GETVDMPTR(vp,cb,p); LOGDEBUG(11,(" String @%08lx: \"%.*s\"\n",vp,min((cb),80),(p)));}
  503. #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)));}
  504. #define GETPSZPTR(vp,p) {GETOPTPTR(vp,1,p); LOGDEBUG(11,(" String @%08lx: \"%.80s\"\n",(FETCHDWORD(vp)),(p)));}
  505. #define GETPSZPTRNOLOG(vp,p) GETOPTPTR(vp,1,p)
  506. #define GETPSZIDPTR(vp,p) {p=(LPSZ)FETCHDWORD(vp); if (HIW16(vp)) GETPSZPTR(vp,p);}
  507. #define GETMISCPTR(vp,p) GETOPTPTR(vp,1,p) // intended for non-string variable-length pointers
  508. #define ALLOCVDMPTR(vp,cb,p) GETVDMPTR(vp,cb,p) // intended for output-only pointers
  509. //
  510. // Macros to "flush" VDM pointers after modifying 16-bit memory.
  511. // Use FLUSHVDMCODEPTR when the 16-bit memory contains x86 code.
  512. // Use FLUSHVDMPTR when the 16-bit memory does not contain x86 code.
  513. //
  514. // On x86, these macros are NOPs. On RISC, FLUSHVDMPTR is a NOP, while
  515. // FLUSHVDMCODEPTR actually calls the emulator so it can recompile any
  516. // code affected.
  517. //
  518. #define FLUSHVDMCODEPTR(vp,cb,p) Sim32FlushVDMPointer( (vp), (USHORT)(cb), (PBYTE)(p), (fWowMode))
  519. //#define FLUSHVDMPTR(vp,cb,p) TRUE // BUGBUG! davehart
  520. #define FLUSHVDMPTR(vp,cb,p) FLUSHVDMCODEPTR(vp,cb,p)
  521. #define LOG_ALWAYS 0x00
  522. #define LOG_ERROR 0x01
  523. #define LOG_IMPORTANT LOG_ERROR
  524. #define LOG_WARNING 0x02
  525. #define LOG_TRACE 0x04
  526. #define LOG_PRIVATE 0x08
  527. #define LOG_API 0x10
  528. #define LOG_MSG 0x20
  529. #define LOG_CALLBACK 0x40
  530. #define LOG_STRING 0x80
  531. #ifndef i386
  532. #ifdef DEBUG
  533. static CHAR *pszLogNull = "<null>";
  534. #undef GETPSZPTR
  535. #define GETPSZPTR(vp,p) {GETOPTPTR(vp,0,p); LOGDEBUG(11,(" String @%08lx: \"%.80s\"\n",(FETCHDWORD(vp)),p ? p : pszLogNull));}
  536. #endif
  537. #endif
  538. #ifndef DEBUG
  539. #define FREEARGPTR(p)
  540. #define FREEOPTPTR(p)
  541. #define FREESTRPTR(p)
  542. #define FREEPSZPTR(p)
  543. #define FREEPSZIDPTR(p)
  544. #define FREEMISCPTR(p)
  545. #define FREEVDMPTR(p)
  546. #define FREEOPTPTR(p)
  547. #else
  548. #define FREEARGPTR(p) p=NULL
  549. #define FREEOPTPTR(p) p=NULL
  550. #define FREESTRPTR(p) p=NULL
  551. #define FREEPSZPTR(p) p=NULL
  552. #define FREEPSZIDPTR(p) p=NULL
  553. #define FREEMISCPTR(p) p=NULL
  554. #define FREEVDMPTR(p) p=NULL
  555. #define FREEOPTPTR(p) p=NULL
  556. #endif
  557. #define RETURN(ul) return ul
  558. #ifdef DBCS // MUST fix for FE NT
  559. #define FIX_318197_NOW
  560. #endif
  561. #ifdef FIX_318197_NOW
  562. #define WOW32_strupr(psz) CharUpperA(psz)
  563. #define WOW32_strlwr(psz) CharLowerA(psz)
  564. #define WOW32_strcmp(psz1, psz2) lstrcmpA(psz1, psz2)
  565. #define WOW32_stricmp(psz1, psz2) lstrcmpiA(psz1, psz2)
  566. #define WOW32_strncpy(psz1, psz2, n) lstrcpyn(psz1, psz2, n)
  567. char* WOW32_strchr(const char* psz, int c);
  568. char* WOW32_strrchr(const char* psz, int c);
  569. char* WOW32_strstr(const char* str1, const char* str2);
  570. int WOW32_strncmp(const char* str1, const char* str2, size_t n);
  571. int WOW32_strnicmp(const char* str1, const char* str2, size_t n);
  572. #else
  573. #define WOW32_strupr(psz) _strupr(psz)
  574. #define WOW32_strlwr(psz) _strlwr(psz)
  575. #define WOW32_strcmp(psz1, psz2) strcmp(psz1, psz2)
  576. #define WOW32_stricmp(psz1, psz2) _stricmp(psz1, psz2)
  577. #define WOW32_strncpy(psz1, psz2, n) strncpy(psz1, psz2, n)
  578. #define WOW32_strchr(psz,c) strchr(psz,c)
  579. #define WOW32_strrchr(psz,c) strrchr(psz,c)
  580. #define WOW32_strstr(psz1, psz2) strstr(psz1, psz2)
  581. #define WOW32_strncmp(psz1, psz2, n) strncmp(psz1, psz2, n)
  582. #define WOW32_strnicmp(psz1, psz2, n) _strnicmp(psz1, psz2, n)
  583. #endif
  584. /* Function prototypes
  585. */
  586. BOOL W32Init(VOID);
  587. VOID W32Dispatch(VOID);
  588. INT W32Exception(DWORD dwException, PEXCEPTION_POINTERS pexi);
  589. BOOLEAN W32DllInitialize(PVOID DllHandle,ULONG Reason,PCONTEXT Context);
  590. BOOL IsDebuggerAttached(VOID);
  591. ULONG FASTCALL WK32WOWGetFastAddress( PVDMFRAME pFrame );
  592. ULONG FASTCALL WK32WOWGetFastCbRetAddress( PVDMFRAME pFrame );
  593. ULONG FASTCALL WK32WOWGetTableOffsets( PVDMFRAME pFrame );
  594. ULONG FASTCALL WK32WOWGetFlatAddressArray( PVDMFRAME pFrame );
  595. PTD ThreadProcID32toPTD(DWORD ThreadID, DWORD dwProcessID);
  596. PTD Htask16toPTD( HAND16 );
  597. HTASK16 ThreadID32toHtask16(DWORD ThreadID32);
  598. PVOID WOWStartupFailed(VOID);
  599. LPSTR ThunkStr16toStr32(LPSTR pdst32, VPVOID vpsrc16, int cChars, BOOL bMulti);
  600. #ifdef DEBUG
  601. VOID logprintf(PSZ psz, ...);
  602. VOID logargs(INT iLog, PVDMFRAME pFrame);
  603. VOID logreturn(INT iLog, PVDMFRAME pFrame, ULONG ulReturn);
  604. BOOL checkloging(register PVDMFRAME pFrame);
  605. #endif
  606. #ifdef DEBUG_OR_WOWPROFILE
  607. LONGLONG GetWOWTicDiff(LONGLONG dwPrevCount);
  608. INT GetFuncId(DWORD iFun);
  609. #endif
  610. BOOL IsDebuggerAttached(VOID);
  611. //
  612. // Thunk table stub functions and aliases.
  613. //
  614. ULONG FASTCALL WOW32UnimplementedAPI(PVDMFRAME pFrame);
  615. ULONG FASTCALL WOW32Unimplemented95API(PVDMFRAME pFrame);
  616. // for tracking memory leaks
  617. #ifdef DEBUG
  618. #define DEBUG_MEMLEAK 1
  619. #else // non-DEBUG
  620. #ifdef MEMLEAK
  621. #define DEBUG_MEMLEAK 1
  622. #endif // MEMLEAK
  623. #endif // DEBUG
  624. #ifdef DEBUG_MEMLEAK
  625. VOID WOW32DebugMemLeak(PVOID lp, ULONG size, DWORD fHow);
  626. VOID WOW32DebugReMemLeak(PVOID lpNew, PVOID lpOrig, ULONG size, DWORD fHow);
  627. VOID WOW32DebugFreeMem(PVOID lp);
  628. VOID WOW32DebugCorruptionCheck(PVOID lp, DWORD size);
  629. DWORD WOW32DebugGetMemSize(PVOID lp);
  630. HGLOBAL WOW32DebugGlobalAlloc(UINT flags, DWORD dwSize);
  631. HGLOBAL WOW32DebugGlobalReAlloc(HGLOBAL h32, DWORD dwSize, UINT flags);
  632. HGLOBAL WOW32DebugGlobalFree(HGLOBAL h32);
  633. #define WOWGLOBALALLOC(f,s) WOW32DebugGlobalAlloc(f,(s))
  634. #define WOWGLOBALREALLOC(h,s,f) WOW32DebugGlobalReAlloc(h,(s),f)
  635. #define WOWGLOBALFREE(h) WOW32DebugGlobalFree(h)
  636. #define ML_MALLOC_W 0x00000001
  637. #define ML_MALLOC_W_ZERO 0x00000002
  638. #define ML_REALLOC_W 0x00000004
  639. #define ML_MALLOC_WTYPE (ML_MALLOC_W | ML_MALLOC_W_ZERO | ML_REALLOC_W)
  640. #define ML_GLOBALALLOC 0x00000010
  641. #define ML_GLOBALREALLOC 0x00000020
  642. #define ML_GLOBALTYPE (ML_GLOBALREALLOC | ML_GLOBALALLOC)
  643. #define TAILCHECK (4 * sizeof(CHAR)) // for heap tail corruption check
  644. typedef struct _tagMEMLEAK {
  645. struct _tagMEMLEAK *lpmlNext;
  646. PVOID lp;
  647. DWORD size;
  648. UINT fHow;
  649. ULONG Count;
  650. PVOID CallersAddress;
  651. } MEMLEAK, *LPMEMLEAK;
  652. #else // non-DEBUG_MEMLEAK
  653. #define TAILCHECK 0
  654. #define WOWGLOBALALLOC(f,s) GlobalAlloc(f,(s))
  655. #define WOWGLOBALREALLOC(h,f,s) GlobalReAlloc(h, f,(s))
  656. #define WOWGLOBALFREE(h) GlobalFree(h)
  657. #endif // DEBUG_MEMLEAK
  658. #ifdef DEBUG
  659. ULONG FASTCALL WOW32NopAPI(PVDMFRAME pFrame);
  660. ULONG FASTCALL WOW32LocalAPI(PVDMFRAME pFrame);
  661. ULONG FASTCALL WK32WowPartyByNumber(PVDMFRAME pFrame);
  662. #define LOCALAPI WOW32LocalAPI
  663. #define NOPAPI WOW32NopAPI
  664. #define UNIMPLEMENTEDAPI WOW32UnimplementedAPI
  665. #define UNIMPLEMENTED95API WOW32Unimplemented95API
  666. #define WK32WOWPARTYBYNUMBER WK32WowPartyByNumber
  667. #else
  668. #define LOCALAPI WOW32UnimplementedAPI
  669. #define NOPAPI WOW32UnimplementedAPI
  670. #define UNIMPLEMENTEDAPI WOW32UnimplementedAPI
  671. #define UNIMPLEMENTED95API WOW32UnimplementedAPI
  672. #define WK32WOWPARTYBYNUMBER UNIMPLEMENTEDAPI
  673. #endif
  674. //Terminal Server
  675. PTERMSRVCORINIFILE gpfnTermsrvCORIniFile;
  676. #define REGISTRY_BUFFER_SIZE 512
  677. #endif // ifndef _DEF_WOW32_ THIS SHOULD BE THE LAST LINE IN THIS FILE