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.

359 lines
8.3 KiB

  1. #ifndef _WIN2KPROPAGATELAYER_H
  2. #define _WIN2KPROPAGATELAYER_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "nt.h"
  7. #include "ntrtl.h"
  8. #include "nturtl.h"
  9. #include "zwapi.h"
  10. #ifdef __cplusplus
  11. }
  12. #endif
  13. #define SHIM_LIB_BUILD_FLAG
  14. #include "vdmdbg.h"
  15. #include "stddef.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include "wownt32.h"
  20. #ifdef __cplusplus
  21. }
  22. #endif
  23. //
  24. // WINUSERP defines TAG type which conflicts
  25. // with the definition available in shimdb.h
  26. // we define it inside the separate namespace
  27. // avoiding any conflicts
  28. //
  29. namespace NSWOWUSERP {
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #include "winuserp.h"
  34. #include "wowuserp2k.h"
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. }
  39. typedef ULONG_PTR (WINAPI *_pfn_UserRegisterWowHandlers)(NSWOWUSERP::APFNWOWHANDLERSIN apfnWowIn,
  40. NSWOWUSERP::APFNWOWHANDLERSOUT apfnWowOut);
  41. /////////////////////////////////////////////////////////////////////////////
  42. //
  43. // 16-bit TDB structure, stolen from base\mvdm\inc\tdb16.h
  44. // Keep this in-sync
  45. //
  46. /*
  47. * Task Data Block - 16 Bit Kernel Data Structure
  48. *
  49. * Contains all 16 bit task specific data.
  50. *
  51. */
  52. #define numTaskInts 7
  53. #define THUNKELEM 8 // (62*8) = 512-16 (low arena overhead)
  54. #define THUNKSIZE 8
  55. #pragma pack(2)
  56. typedef struct TDB { /* tdb16 */
  57. WORD TDB_next ; // next task in dispatch queue
  58. WORD TDB_taskSP ; // Saved SS:SP for this task
  59. WORD TDB_taskSS ; //
  60. WORD TDB_nEvents ; // Task event counter
  61. BYTE TDB_priority ; // Task priority (0 is highest)
  62. BYTE TDB_thread_ordinal ; // ordinal number of this thread
  63. WORD TDB_thread_next ; // next thread
  64. WORD TDB_thread_tdb ; // the real TDB for this task
  65. WORD TDB_thread_list ; // list of allocated thread structures
  66. WORD TDB_thread_free ; // free list of availble thread structures
  67. WORD TDB_thread_count ; // total count of tread structures
  68. WORD TDB_FCW ; // Floating point control word
  69. BYTE TDB_flags ; // Task flags
  70. BYTE TDB_filler ; // keep word aligned
  71. WORD TDB_ErrMode ; // Error mode for this task
  72. WORD TDB_ExpWinVer ; // Expected Windows version for this task
  73. WORD TDB_Module ; // Task module handle to free in killtask
  74. WORD TDB_pModule ; // Pointer to the module database.
  75. WORD TDB_Queue ; // Task Event Queue pointer
  76. WORD TDB_Parent ; // TDB of the task that started this up
  77. WORD TDB_SigAction ; // Action for app task signal
  78. DWORD TDB_ASignalProc ; // App's Task Signal procedure address
  79. DWORD TDB_USignalProc ; // User's Task Signal procedure address
  80. DWORD TDB_GNotifyProc ; // Task global discard notify proc.
  81. DWORD TDB_INTVECS[numTaskInts] ; // Task specfic harare interrupts
  82. WORD TDB_CompatFlags ; // Compatibility flags
  83. WORD TDB_CompatFlags2 ; // Upper 16 bits
  84. WORD TDB_CompatHandle ; // for dBase bug
  85. WORD TDB_WOWCompatFlagsEx ; // More WOW Compatibility flags
  86. WORD TDB_WOWCompatFlagsEx2 ; // Upper 16 bits
  87. BYTE TDB_Free[3] ; // Filler to keep TDB size unchanged
  88. BYTE TDB_cLibrary ; // tracks add/del of ALL libs in system EMS
  89. DWORD TDB_PHT ; // (HANDLE:OFFSET) to private handle table
  90. WORD TDB_PDB ; // MSDOS Process Data Block (PDB)
  91. DWORD TDB_DTA ; // MSDOS Disk Transfer Address
  92. BYTE TDB_Drive ; // MSDOS current drive
  93. BYTE TDB_Directory[65] ; // *** not used starting with win95
  94. WORD TDB_Validity ; // initial AX to be passed to a task
  95. WORD TDB_Yield_to ; // DirectedYield arg stored here
  96. WORD TDB_LibInitSeg ; // segment address of libraries to init
  97. WORD TDB_LibInitOff ; // MakeProcInstance thunks live here.
  98. WORD TDB_MPI_Sel ; // Code selector for thunks
  99. WORD TDB_MPI_Thunks[((THUNKELEM*THUNKSIZE)/2)]; //
  100. BYTE TDB_ModName[8] ; // Name of Module.
  101. WORD TDB_sig ; // Signature word to detect bogus code
  102. DWORD TDB_ThreadID ; // 32-Bit Thread ID for this Task (use TDB_Filler Above)
  103. DWORD TDB_hThread ; // 32-bit Thread Handle for this task
  104. WORD TDB_WOWCompatFlags; // WOW Compatibility flags
  105. WORD TDB_WOWCompatFlags2; // WOW Compatibility flags
  106. #ifdef FE_SB
  107. WORD TDB_WOWCompatFlagsJPN; // WOW Compatibility flags for JAPAN
  108. WORD TDB_WOWCompatFlagsJPN2; // WOW Compatibility flags for JAPAN
  109. #endif // FE_SB
  110. DWORD TDB_vpfnAbortProc; // printer AbortProc
  111. BYTE TDB_LFNDirectory[260]; // Long directory name
  112. } TDB;
  113. typedef TDB UNALIGNED *PTDB;
  114. // This bit is defined for the TDB_Drive field
  115. #define TDB_DIR_VALID 0x80
  116. #define TDB_SIGNATURE 0x4454
  117. #define TDBF_OS2APP 0x8
  118. #define TDBF_WINOLDAP 0x1
  119. // NOTE TDB_ThreadID MUST be DWORD aligned or else it will fail on MIPS
  120. #pragma pack()
  121. /////////////////////////////////////////////////////////////////////////////
  122. //
  123. // DOSPDB structure, stolen from base\mvdm\inc\doswow.h
  124. //
  125. //
  126. #pragma pack(1)
  127. typedef struct _DOSPDB { // DOS Process Data Block
  128. CHAR PDB_Not_Interested[44]; // Fields we are not interested in
  129. USHORT PDB_environ; // segment of environment
  130. DWORD PDB_User_stack;
  131. USHORT PDB_JFN_Length; // JFT length
  132. ULONG PDB_JFN_Pointer; // JFT pointer
  133. } DOSPDB, *PDOSPDB;
  134. #pragma pack()
  135. ///////////////////////////////////////////////////////////////////////////////
  136. //
  137. //
  138. // Variables and functions that are local to this project
  139. //
  140. //
  141. // defined in wowprocesshistory.cpp
  142. //
  143. extern CHAR g_szCompatLayerVar[];
  144. extern CHAR g_szProcessHistoryVar[];
  145. extern CHAR g_szShimFileLogVar[];
  146. extern WCHAR g_wszCompatLayerVar[];
  147. extern BOOL g_bIsNTVDM;
  148. extern BOOL g_bIsExplorer;
  149. extern WCHAR* g_pwszCompatLayer;
  150. //
  151. // Function in Win2kPropagateLayer that allows us to create env from wow data
  152. //
  153. LPVOID
  154. ShimCreateWowEnvironment_U(
  155. LPVOID lpEnvironment, // pointer to the existing environment
  156. DWORD* lpdwFlags, // process creation flags
  157. BOOL bNewEnvironment // when set, forces us to clone environment ptr
  158. );
  159. //
  160. // functions in environment.cpp
  161. //
  162. PSZ
  163. ShimFindEnvironmentVar(
  164. PSZ pszName,
  165. PSZ pszEnv,
  166. PSZ* ppszVal
  167. );
  168. DWORD
  169. ShimGetEnvironmentSize(
  170. PSZ pszEnv,
  171. LPDWORD pStrCount
  172. );
  173. DWORD
  174. ShimGetEnvironmentSize(
  175. WCHAR* pwszEnv,
  176. LPDWORD pStrCount
  177. );
  178. NTSTATUS
  179. ShimCloneEnvironment(
  180. LPVOID* ppEnvOut,
  181. LPVOID lpEnvironment,
  182. BOOL bUnicode
  183. );
  184. NTSTATUS
  185. ShimFreeEnvironment(
  186. LPVOID lpEnvironment
  187. );
  188. NTSTATUS
  189. ShimSetEnvironmentVar(
  190. LPVOID* ppEnvironment,
  191. WCHAR* pwszVarName,
  192. WCHAR* pwszVarValue
  193. );
  194. //
  195. // stuff in wowtask.cpp
  196. //
  197. //
  198. // Structure to reflect WOW environment values
  199. //
  200. typedef struct tagWOWENVDATA {
  201. PSZ pszCompatLayer; // fully-formed compat layer variable
  202. PSZ pszCompatLayerVal;
  203. PSZ pszProcessHistory; // fully-formed process history variable
  204. PSZ pszProcessHistoryVal;
  205. PSZ pszShimFileLog; // file log variable
  206. PSZ pszShimFileLogVal;
  207. // buffer that we use for the accomulated process history,
  208. PSZ pszCurrentProcessHistory;
  209. } WOWENVDATA, *PWOWENVDATA;
  210. //
  211. // function to retrieve all the "interesting" things out of wow environment
  212. //
  213. BOOL
  214. ShimRetrieveVariablesEx(
  215. PWOWENVDATA pData
  216. );
  217. //
  218. // Store information about wow task
  219. //
  220. BOOL
  221. UpdateWowTaskList(
  222. WORD hTask16
  223. );
  224. //
  225. // wow task exits, cleanup the list
  226. //
  227. BOOL
  228. CleanupWowTaskList(
  229. WORD hTask16
  230. );
  231. //
  232. // Functions in cleanup.cpp
  233. //
  234. BOOL
  235. CleanupRegistryForCurrentExe(
  236. void
  237. );
  238. //
  239. // functions in win2kpropagatelayer.cpp
  240. //
  241. void
  242. InitLayerStorage(
  243. BOOL bDelete
  244. );
  245. BOOL
  246. AddSupport(
  247. LPCWSTR lpCommandLine,
  248. LPVOID* ppEnvironment,
  249. LPDWORD lpdwCreationFlags
  250. );
  251. BOOL
  252. CheckAndShimNTVDM(
  253. WORD hTask16
  254. );
  255. //
  256. // Exception filter, proto for the function in WowProcessHistory.cpp
  257. //
  258. //
  259. ULONG
  260. Win2kPropagateLayerExceptionHandler(
  261. PEXCEPTION_POINTERS pexi,
  262. char * szFile,
  263. DWORD dwLine
  264. );
  265. //
  266. // Exception filter to use with our hooks
  267. //
  268. #define WOWPROCESSHISTORYEXCEPTIONFILTER \
  269. Win2kPropagateLayerExceptionHandler(GetExceptionInformation(), __FILE__, __LINE__)
  270. #endif // _WIN2KPROPAGATELAYER_H