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.

420 lines
12 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. wow64t.h
  5. Abstract:
  6. 32-bit structure definitions for 64-bit NT.
  7. Author:
  8. Barry Bond (barrybo) 20-Jun-1998
  9. Revision History:
  10. --*/
  11. #ifndef _WOW64T_
  12. #define _WOW64T_
  13. #if _MSC_VER > 1000
  14. #pragma once
  15. #endif
  16. //
  17. // Page size on x86 NT
  18. //
  19. #define PAGE_SIZE_X86NT 0x1000
  20. #define PAGE_SHIFT_X86NT 12L
  21. //
  22. // Convert the number of native pages to sub x86-pages
  23. //
  24. #define Wow64GetNumberOfX86Pages(NativePages) \
  25. (NativePages * (PAGE_SIZE >> PAGE_SHIFT_X86NT))
  26. //
  27. // Macro to round to the nearest page size
  28. //
  29. #define WOW64_ROUND_TO_PAGES(Size) \
  30. (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  31. //
  32. // Get number of native pages
  33. //
  34. #define WOW64_BYTES_TO_PAGES(Size) (((ULONG)(Size) >> PAGE_SHIFT) + \
  35. (((ULONG)(Size) & (PAGE_SIZE - 1)) != 0))
  36. //
  37. // The name of the 32-bit system directory, which is a child of %SystemRoot%
  38. //
  39. #define WOW64_SYSTEM_DIRECTORY "syswow64"
  40. #define WOW64_SYSTEM_DIRECTORY_U L"syswow64"
  41. // Length in bytes of the new system directory, not counting a
  42. // null terminator
  43. //
  44. #define WOW64_SYSTEM_DIRECTORY_SIZE (sizeof(WOW64_SYSTEM_DIRECTORY)-sizeof(CHAR))
  45. #define WOW64_SYSTEM_DIRECTORY_U_SIZE (sizeof(WOW64_SYSTEM_DIRECTORY_U)-sizeof(WCHAR))
  46. //
  47. // Wow64 Registry Configuration
  48. //
  49. #define WOW64_REGISTRY_CONFIG_ROOT L"\\REGISTRY\\MACHINE\\SOFTWARE\\Microsoft\\WOW64"
  50. #define WOW64_REGISTRY_CONFIG_EXECUTE_OPTIONS L"ExecuteOptions"
  51. #define WOW64_X86_TAG " (x86)"
  52. #define WOW64_X86_TAG_U L" (x86)"
  53. //
  54. // File system redirection values
  55. //
  56. #define WOW64_FILE_SYSTEM_ENABLE_REDIRECT (UlongToPtr(0x00)) // enable file-system redirection for the currently executing thread
  57. #define WOW64_FILE_SYSTEM_DISABLE_REDIRECT (UlongToPtr(0x01)) // disable file-system redirection for the currently executing thread
  58. #define WOW64_FILE_SYSTEM_DISABLE_REDIRECT_LEGACY ((PVOID)L"[<__wow64_disable_redirect_all__]>")
  59. #define TYPE32(x) ULONG
  60. #define TYPE64(x) ULONGLONG
  61. #if !_WIN64
  62. __inline
  63. void *
  64. ULonglongToPtr(
  65. const ULONGLONG ull
  66. )
  67. {
  68. #pragma warning (push)
  69. #pragma warning (disable : 4305)
  70. return((void *) ull );
  71. #pragma warning (pop)
  72. }
  73. #endif
  74. //
  75. // Wow64Info structure is shared between 32-bit and 64-bit modules inside a Wow64 process.
  76. // NOTE : This structure shouldn't contain any pointer-dependent data, as
  77. // it is viewed from 32-bit and 64-bit code.
  78. //
  79. typedef struct _WOW64INFO {
  80. ULONG NativeSystemPageSize; // Page size of the native system the emulator is running on.
  81. ULONG CpuFlags;
  82. } WOW64INFO, *PWOW64INFO;
  83. typedef struct _PEB_LDR_DATA32 {
  84. ULONG Length;
  85. BOOLEAN Initialized;
  86. TYPE32(HANDLE) SsHandle;
  87. LIST_ENTRY32 InLoadOrderModuleList;
  88. LIST_ENTRY32 InMemoryOrderModuleList;
  89. LIST_ENTRY32 InInitializationOrderModuleList;
  90. TYPE32(PVOID) EntryInProgress;
  91. } PEB_LDR_DATA32, *PPEB_LDR_DATA32;
  92. typedef struct _GDI_TEB_BATCH32 {
  93. ULONG Offset;
  94. TYPE32(ULONG_PTR) HDC;
  95. ULONG Buffer[GDI_BATCH_BUFFER_SIZE];
  96. } GDI_TEB_BATCH32,*PGDI_TEB_BATCH32;
  97. typedef struct _GDI_TEB_BATCH64 {
  98. ULONG Offset;
  99. TYPE64(ULONG_PTR) HDC;
  100. ULONG Buffer[GDI_BATCH_BUFFER_SIZE];
  101. } GDI_TEB_BATCH64,*PGDI_TEB_BATCH64;
  102. typedef struct _Wx86ThreadState32 {
  103. TYPE32(PULONG) CallBx86Eip;
  104. TYPE32(PVOID) DeallocationCpu;
  105. BOOLEAN UseKnownWx86Dll;
  106. char OleStubInvoked;
  107. } WX86THREAD32, *PWX86THREAD32;
  108. typedef struct _Wx86ThreadState64 {
  109. TYPE64(PULONG) CallBx86Eip;
  110. TYPE64(PVOID) DeallocationCpu;
  111. BOOLEAN UseKnownWx86Dll;
  112. char OleStubInvoked;
  113. } WX86THREAD64, *PWX86THREAD64;
  114. typedef struct _CLIENT_ID32 {
  115. TYPE32(HANDLE) UniqueProcess;
  116. TYPE32(HANDLE) UniqueThread;
  117. } CLIENT_ID32;
  118. typedef CLIENT_ID32 *PCLIENT_ID32;
  119. #if !defined(CLIENT_ID64_DEFINED)
  120. typedef struct _CLIENT_ID64 {
  121. TYPE64(HANDLE) UniqueProcess;
  122. TYPE64(HANDLE) UniqueThread;
  123. } CLIENT_ID64;
  124. typedef CLIENT_ID64 *PCLIENT_ID64;
  125. #define CLIENT_ID64_DEFINED
  126. #endif
  127. typedef ULONG GDI_HANDLE_BUFFER32[GDI_HANDLE_BUFFER_SIZE32];
  128. typedef ULONG GDI_HANDLE_BUFFER64[GDI_HANDLE_BUFFER_SIZE64];
  129. #define PEBTEB_BITS 32
  130. #include "pebteb.h"
  131. #undef PEBTEB_BITS
  132. #define PEBTEB_BITS 64
  133. #include "pebteb.h"
  134. #undef PEBTEB_BITS
  135. typedef struct _RTL_DRIVE_LETTER_CURDIR32 {
  136. USHORT Flags;
  137. USHORT Length;
  138. ULONG TimeStamp;
  139. STRING32 DosPath;
  140. } RTL_DRIVE_LETTER_CURDIR32, *PRTL_DRIVE_LETTER_CURDIR32;
  141. typedef struct _CURDIR32 {
  142. UNICODE_STRING32 DosPath;
  143. TYPE32(HANDLE) Handle;
  144. } CURDIR32, *PCURDIR32;
  145. typedef struct _RTL_USER_PROCESS_PARAMETERS32 {
  146. ULONG MaximumLength;
  147. ULONG Length;
  148. ULONG Flags;
  149. ULONG DebugFlags;
  150. TYPE32(HANDLE) ConsoleHandle;
  151. ULONG ConsoleFlags;
  152. TYPE32(HANDLE) StandardInput;
  153. TYPE32(HANDLE) StandardOutput;
  154. TYPE32(HANDLE) StandardError;
  155. CURDIR32 CurrentDirectory; // ProcessParameters
  156. UNICODE_STRING32 DllPath; // ProcessParameters
  157. UNICODE_STRING32 ImagePathName; // ProcessParameters
  158. UNICODE_STRING32 CommandLine; // ProcessParameters
  159. TYPE32(PVOID) Environment; // NtAllocateVirtualMemory
  160. ULONG StartingX;
  161. ULONG StartingY;
  162. ULONG CountX;
  163. ULONG CountY;
  164. ULONG CountCharsX;
  165. ULONG CountCharsY;
  166. ULONG FillAttribute;
  167. ULONG WindowFlags;
  168. ULONG ShowWindowFlags;
  169. UNICODE_STRING32 WindowTitle; // ProcessParameters
  170. UNICODE_STRING32 DesktopInfo; // ProcessParameters
  171. UNICODE_STRING32 ShellInfo; // ProcessParameters
  172. UNICODE_STRING32 RuntimeData; // ProcessParameters
  173. RTL_DRIVE_LETTER_CURDIR32 CurrentDirectores[ RTL_MAX_DRIVE_LETTERS ];
  174. } RTL_USER_PROCESS_PARAMETERS32, *PRTL_USER_PROCESS_PARAMETERS32;
  175. #if !defined(BUILD_WOW6432)
  176. //
  177. // Get the 32-bit TEB without doing a memory reference.
  178. //
  179. #define WOW64_GET_TEB32_SAFE(teb64) \
  180. ((PTEB32) ((ULONGLONG)teb64 + WOW64_ROUND_TO_PAGES (sizeof (TEB))))
  181. #define WOW64_GET_TEB32(teb64) \
  182. WOW64_GET_TEB32_SAFE(teb64)
  183. //
  184. // Update the first qword in the 64-bit TEB. The 32-bit rdteb instruction
  185. // reads the TEB32 pointer value directly from this field.
  186. //
  187. #define WOW64_SET_TEB32(teb64, teb32) \
  188. (teb64)->NtTib.ExceptionList = (struct _EXCEPTION_REGISTRATION_RECORD *)(teb32);
  189. #define WOW64_TEB32_POINTER_ADDRESS(teb64) \
  190. (PVOID)&((teb64)->NtTib.ExceptionList)
  191. #endif
  192. //
  193. // Thunk macros
  194. #define UStr32ToUStr(dst, src) { (dst)->Length = (src)->Length; \
  195. (dst)->MaximumLength = (src)->MaximumLength; \
  196. (dst)->Buffer = (PWSTR) ((src)->Buffer); }
  197. #define UStrToUStr32(dst, src) { (dst)->Length = (src)->Length; \
  198. (dst)->MaximumLength = (src)->MaximumLength; \
  199. (dst)->Buffer = (ULONG) ((src)->Buffer); }
  200. #define NtCurrentTeb32() ((PTEB32) WOW64_GET_TEB32_SAFE (NtCurrentTeb ()))
  201. #define NtCurrentPeb32() ((PPEB32) UlongToPtr ((NtCurrentTeb32()->ProcessEnvironmentBlock)) )
  202. // This is currently defined in windows\core\w32inc\w32wow64.h:
  203. #define NtCurrentTeb64() ((PTEB64)((PTEB32)NtCurrentTeb())->GdiBatchCount)
  204. // This is currently defined in base\wow64\inc\wow64.h:
  205. #define WOW64_TLS_FILESYSREDIR 8 // Used to enable/disable the filesystem
  206. #define WOW64_TLS_WOW64INFO 10 // Used to access native system information for wow64 processes.
  207. #define WOW64_TLS_INITIAL_TEB32 11 // A pointer to the 32-bit initial TEB
  208. #define WOW64_TLS_MAX_NUMBER 12 // Maximum number of TLS slot entries to allocate.
  209. // These should only be called from Win32 code known to be running on Win64.
  210. #if !_WIN64
  211. #define Wow64EnableFilesystemRedirector() \
  212. NtCurrentTeb64()->TlsSlots[WOW64_TLS_FILESYSREDIR] = 0;
  213. #define Wow64DisableFilesystemRedirector(filename) \
  214. NtCurrentTeb64()->TlsSlots[WOW64_TLS_FILESYSREDIR] = (ULONGLONG)PtrToUlong(filename);
  215. __inline
  216. PVOID
  217. Wow64SetFilesystemRedirectorEx (
  218. PVOID NewValue
  219. )
  220. /*++
  221. Routine Description:
  222. This routine allows a thread running inside Wow64 to disable file-system
  223. redirection for all calls happening in the context of this thread.
  224. NOTE: This routine should only called from a wow64 process, and is only available
  225. when running on .NET server platforms and beyond. If you component will
  226. run on downlevel platforms (XP 2600 for example), you shouldn't use WOW64_FILE_SYSTEM_DISABLE_REDIRECT (see below).
  227. Example (Enumerating files under c:\windows\system32):
  228. {
  229. HANDLE File;
  230. WIN32_FIND_DATA FindData;
  231. #ifndef _WIN64
  232. BOOL bWow64Process = FALSE;
  233. PVOID Wow64RedirectionOld;
  234. #endif
  235. //
  236. // Disable Wow64 file system redirection
  237. //
  238. #ifndef _WIN64
  239. IsWow64Process (GetCurrentProcess (), &bWow64Process);
  240. if (bWow64Process == TRUE) {
  241. Wow64RedirectionOld = Wow64SetFilesystemRedirectorEx (WOW64_FILE_SYSTEM_DISABLE_REDIRECT);
  242. }
  243. #endif
  244. File = FindFirstFileA ("c:\\windows\\system32\\*.*", &FindData);
  245. do {
  246. .
  247. .
  248. } while (FindNextFileA (File, &FindData) != 0);
  249. FindClose (File);
  250. //
  251. // Enable Wow64 file-system redirection
  252. //
  253. #ifndef _WIN64
  254. if (bWow64Process == TRUE) {
  255. Wow64SetFilesystemRedirectorEx (Wow64RedirectionOld);
  256. }
  257. #endif
  258. }
  259. Arguments:
  260. NewValue - New Wow64 file-system redirection value. This can either be:
  261. a- pointer to a unicode string with a fully-qualified path name (e.g. L"c:\\windows\\notepad.exe").
  262. b- any of the following predefined values :
  263. * WOW64_FILE_SYSTEM_ENABLE_REDIRECT : Enables file-system redirection (default)
  264. * WOW64_FILE_SYSTEM_DISABLE_REDIRECT : Disables file-system redirection on all
  265. file I/O operations happening within the context of the current thread.
  266. * WOW64_FILE_SYSTEM_DISABLE_REDIRECT_LEGACY: Use this only if you want to run on
  267. download level platforms (for example XP 2600), as it will have no effect
  268. and prevents your program from malfunctioning.
  269. Return:
  270. Old Wow64 file-system redirection value
  271. --*/
  272. {
  273. NtCurrentTeb64()->TlsSlots[WOW64_TLS_FILESYSREDIR] = (ULONGLONG)PtrToUlong(NewValue);
  274. return UlongToPtr ((ULONG)NtCurrentTeb64()->TlsSlots[WOW64_TLS_FILESYSREDIR]);
  275. }
  276. //
  277. // Wow64Info is accessed only from compiled code for x86 on win64.
  278. // NOTE: Only Wow64 processes are allowed to call these macros.
  279. //
  280. #define Wow64GetSharedInfo() ((PWOW64INFO)NtCurrentTeb64()->TlsSlots[WOW64_TLS_WOW64INFO])
  281. #define Wow64GetSystemNativePageSize() \
  282. ((PWOW64INFO)ULonglongToPtr((NtCurrentTeb64()->TlsSlots[WOW64_TLS_WOW64INFO])))->NativeSystemPageSize
  283. #else
  284. #define Wow64GetSharedInfo() ((PWOW64INFO)NtCurrentTeb()->TlsSlots[WOW64_TLS_WOW64INFO])
  285. #define Wow64GetInitialTeb32() ((PINITIAL_TEB)NtCurrentTeb()->TlsSlots[WOW64_TLS_INITIAL_TEB32])
  286. #endif
  287. typedef ULONGLONG SIZE_T64, *PSIZE_T64;
  288. #if defined(BUILD_WOW6432)
  289. typedef VOID * __ptr64 NATIVE_PVOID;
  290. typedef ULONG64 NATIVE_ULONG_PTR;
  291. typedef SIZE_T64 NATIVE_SIZE_T;
  292. typedef PSIZE_T64 PNATIVE_SIZE_T;
  293. typedef struct _PEB64 NATIVE_PEB;
  294. typedef struct _PROCESS_BASIC_INFORMATION64 NATIVE_PROCESS_BASIC_INFORMATION;
  295. typedef struct _MEMORY_BASIC_INFORMATION64 NATIVE_MEMORY_BASIC_INFORMATION;
  296. #else
  297. typedef ULONG_PTR NATIVE_ULONG_PTR;
  298. typedef SIZE_T NATIVE_SIZE_T;
  299. typedef PSIZE_T PNATIVE_SIZE_T;
  300. typedef PVOID NATIVE_PVOID;
  301. typedef struct _PEB NATIVE_PEB;
  302. typedef struct _PROCESS_BASIC_INFORMATION NATIVE_PROCESS_BASIC_INFORMATION;
  303. typedef struct _MEMORY_BASIC_INFORMATION NATIVE_MEMORY_BASIC_INFORMATION;
  304. #endif
  305. #endif // _WOW64T_