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.

312 lines
8.6 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. wow64thk.h
  5. Abstract:
  6. Declarations shared between wow64.dll and the Win32 thunks in wow64win.dll
  7. Author:
  8. 29-Oct-1999 BarryBo
  9. Revision History:
  10. --*/
  11. #ifndef _WOW64THK_INCLUDE
  12. #define _WOW64THK_INCLUDE
  13. #include <setjmp.h>
  14. //
  15. // Make wow64.dll exports __declspec(dllimport) when this header is included
  16. // by non-wow64 components
  17. //
  18. #if !defined(_WOW64DLLAPI_)
  19. #define WOW64DLLAPI DECLSPEC_IMPORT
  20. #else
  21. #define WOW64DLLAPI
  22. #endif
  23. typedef enum _WOW64_API_ERROR_ACTION {
  24. ApiErrorNTSTATUS, //Return exception code as return value
  25. ApiErrorNTSTATUSTebCode, //Some as above with SetLastError on exception code
  26. ApiErrorRetval, //Return a constant parameter
  27. ApiErrorRetvalTebCode //Some as above with SetLastError on exception code
  28. } WOW64_API_ERROR_ACTION, *PWOW64_API_ERROR_ACTION;
  29. //
  30. // This structure describes what action should occure when
  31. // thunks hit an unhandled exception.
  32. //
  33. typedef struct _WOW64_SERVICE_ERROR_CASE {
  34. WOW64_API_ERROR_ACTION ErrorAction;
  35. LONG ErrorActionParam;
  36. } WOW64_SERVICE_ERROR_CASE, *PWOW64_SERVICE_ERROR_CASE;
  37. // This is an extension of KSERVICE_TABLE_DESCRIPTOR
  38. typedef struct _WOW64SERVICE_TABLE_DESCRIPTOR {
  39. PULONG_PTR Base;
  40. PULONG Count;
  41. ULONG Limit;
  42. #if defined(_IA64_)
  43. LONG TableBaseGpOffset;
  44. #endif
  45. PUCHAR Number;
  46. WOW64_API_ERROR_ACTION DefaultErrorAction; //Action if ErrorCases is NULL.
  47. LONG DefaultErrorActionParam; //Action parameter if ErrorCases is NULL.
  48. PWOW64_SERVICE_ERROR_CASE ErrorCases;
  49. } WOW64SERVICE_TABLE_DESCRIPTOR, *PWOW64SERVICE_TABLE_DESCRIPTOR;
  50. // Used to log hit counts for APIs.
  51. typedef struct _WOW64SERVICE_PROFILE_TABLE WOW64SERVICE_PROFILE_TABLE;
  52. typedef struct _WOW64SERVICE_PROFILE_TABLE *PWOW64SERVICE_PROFILE_TABLE;
  53. typedef struct _WOW64SERVICE_PROFILE_TABLE_ELEMENT {
  54. PWSTR ApiName;
  55. SIZE_T HitCount;
  56. PWOW64SERVICE_PROFILE_TABLE SubTable;
  57. BOOLEAN ApiEnabled;
  58. } WOW64SERVICE_PROFILE_TABLE_ELEMENT, *PWOW64SERVICE_PROFILE_TABLE_ELEMENT;
  59. typedef struct _WOW64SERVICE_PROFILE_TABLE {
  60. PWSTR TableName; //OPTIONAL
  61. PWSTR FriendlyTableName; //OPTIONAL
  62. CONST PWOW64SERVICE_PROFILE_TABLE_ELEMENT ProfileTableElements;
  63. SIZE_T NumberProfileTableElements;
  64. } WOW64SERVICE_PROFILE_TABLE, *PWOW64SERVICE_PROFILE_TABLE;
  65. typedef struct UserCallbackData {
  66. jmp_buf JumpBuffer;
  67. PVOID PreviousUserCallbackData;
  68. PVOID OutputBuffer;
  69. ULONG OutputLength;
  70. NTSTATUS Status;
  71. PVOID UserBuffer;
  72. } USERCALLBACKDATA, *PUSERCALLBACKDATA;
  73. ULONG
  74. WOW64DLLAPI
  75. Wow64KiUserCallbackDispatcher(
  76. PUSERCALLBACKDATA pUserCallbackData,
  77. ULONG ApiNumber,
  78. ULONG ApiArgument,
  79. ULONG ApiSize
  80. );
  81. PVOID
  82. WOW64DLLAPI
  83. Wow64AllocateTemp(
  84. SIZE_T Size
  85. );
  86. WOW64DLLAPI
  87. PVOID
  88. Wow64AllocateHeap(
  89. SIZE_T Size
  90. );
  91. WOW64DLLAPI
  92. VOID
  93. Wow64FreeHeap(
  94. PVOID BaseAddress
  95. );
  96. //
  97. // Logging mechanism. Usage:
  98. // LOGPRINT((verbosity, format, ...))
  99. //
  100. #define LOGPRINT(args) Wow64LogPrint args
  101. #define ERRORLOG LF_ERROR // Always output to debugger. Use for *unexpected*
  102. // errors only
  103. #define TRACELOG LF_TRACE // application trace information
  104. #define INFOLOG LF_TRACE // misc. informational log
  105. #define VERBOSELOG LF_NONE // practically never output to debugger
  106. #if defined DBG
  107. #define WOW64DOPROFILE
  108. #endif
  109. void
  110. WOW64DLLAPI
  111. Wow64LogPrint(
  112. UCHAR LogLevel,
  113. char *format,
  114. ...
  115. );
  116. //
  117. // WOW64 Assertion Mechanism. Usage:
  118. // - put an ASSERTNAME macro at the top of each .C file
  119. // - WOW64ASSERT(expression)
  120. // - WOW64ASSERTMSG(expression, message)
  121. //
  122. //
  123. VOID
  124. WOW64DLLAPI
  125. Wow64Assert(
  126. IN CONST PSZ exp,
  127. OPTIONAL IN CONST PSZ msg,
  128. IN CONST PSZ mod,
  129. IN LONG LINE
  130. );
  131. #if DBG
  132. #undef ASSERTNAME
  133. #define ASSERTNAME static CONST PSZ szModule = __FILE__;
  134. #define WOWASSERT(exp) \
  135. if (!(exp)) { \
  136. Wow64Assert( #exp, NULL, szModule, __LINE__); \
  137. }
  138. #define WOWASSERTMSG(exp, msg) \
  139. if (!(exp)) { \
  140. Wow64Assert( #exp, msg, szModule, __LINE__); \
  141. }
  142. #else // !DBG
  143. #define WOWASSERT(exp)
  144. #define WOWASSERTMSG(exp, msg)
  145. #endif // !DBG
  146. #define WOWASSERT_PTR32(ptr) WOWASSERT((ULONGLONG)ptr < 0xFFFFFFFF)
  147. // Defines the argsize of the emulated machine
  148. #define ARGSIZE 4
  149. // Determines if a pointer points to a item or is a special value.
  150. // If it is a special value it should be copied without dereferencing.
  151. #define WOW64_ISPTR(a) ((void *)a != NULL)
  152. //
  153. // Helper thunk functions called by all the thunks to thunk common types.
  154. //
  155. NT32SIZE_T*
  156. Wow64ShallowThunkSIZE_T64TO32(
  157. OUT NT32SIZE_T *dst,
  158. IN PSIZE_T src
  159. );
  160. PSIZE_T
  161. Wow64ShallowThunkSIZE_T32TO64(
  162. OUT PSIZE_T dst,
  163. IN NT32SIZE_T *src
  164. );
  165. #define Wow64ThunkSIZE_T32TO64(src) \
  166. (SIZE_T)(src)
  167. #define Wow64ThunkSIZE_T64TO32(src) \
  168. (NT32SIZE_T)min((src), 0xFFFFFFFF)
  169. #define Wow64ShallowThunkUnicodeString32TO64(dst, src) \
  170. ((PUNICODE_STRING)(dst))->Length = ((NT32UNICODE_STRING *)(src))->Length; \
  171. ((PUNICODE_STRING)(dst))->MaximumLength = ((NT32UNICODE_STRING *)(src))->MaximumLength; \
  172. ((PUNICODE_STRING)(dst))->Buffer = (PWSTR)((NT32UNICODE_STRING *)(src))->Buffer;
  173. #define Wow64ShallowThunkUnicodeString64TO32(dst, src) \
  174. ((NT32UNICODE_STRING *)(dst))->Length = ((PUNICODE_STRING)(src))->Length; \
  175. ((NT32UNICODE_STRING *)(dst))->MaximumLength = ((PUNICODE_STRING)(src))->MaximumLength; \
  176. ((NT32UNICODE_STRING *)(dst))->Buffer = (NT32PWSTR)((PUNICODE_STRING)(src))->Buffer;
  177. #define Wow64ShallowThunkAllocUnicodeString32TO64(src) \
  178. Wow64ShallowThunkAllocUnicodeString32TO64_FNC((NT32UNICODE_STRING *)(src))
  179. PUNICODE_STRING
  180. Wow64ShallowThunkAllocUnicodeString32TO64_FNC(
  181. IN NT32UNICODE_STRING *src
  182. );
  183. #define Wow64ShallowThunkAllocSecurityDescriptor32TO64(src) \
  184. Wow64ShallowThunkAllocSecurityDescriptor32TO64_FNC((NT32SECURITY_DESCRIPTOR *)(src))
  185. PSECURITY_DESCRIPTOR
  186. Wow64ShallowThunkAllocSecurityDescriptor32TO64_FNC(
  187. IN NT32SECURITY_DESCRIPTOR *src
  188. );
  189. #define Wow64ShallowThunkAllocSecurityTokenProxyData32TO64(src) \
  190. Wow64ShallowThunkAllocSecurityTokenProxyData32TO64_FNC((NT32SECURITY_TOKEN_PROXY_DATA *)(src))
  191. PSECURITY_TOKEN_PROXY_DATA
  192. Wow64ShallowThunkAllocSecurityTokenProxyData32TO64_FNC(
  193. IN NT32SECURITY_TOKEN_PROXY_DATA *src
  194. );
  195. #define Wow64ShallowThunkAllocSecurityQualityOfService32TO64(src, dst) \
  196. Wow64ShallowThunkAllocSecurityQualityOfService32TO64_FNC((NT32SECURITY_QUALITY_OF_SERVICE *)(src), dst)
  197. NTSTATUS
  198. Wow64ShallowThunkAllocSecurityQualityOfService32TO64_FNC(
  199. IN NT32SECURITY_QUALITY_OF_SERVICE *src,
  200. IN OUT PSECURITY_QUALITY_OF_SERVICE *dst
  201. );
  202. #define Wow64ShallowThunkAllocObjectAttributes32TO64(src, dst) \
  203. Wow64ShallowThunkAllocObjectAttributes32TO64_FNC((NT32OBJECT_ATTRIBUTES *)(src), dst)
  204. NTSTATUS
  205. Wow64ShallowThunkAllocObjectAttributes32TO64_FNC(
  206. IN NT32OBJECT_ATTRIBUTES *src,
  207. IN OUT POBJECT_ATTRIBUTES *dst
  208. );
  209. ULONG
  210. Wow64ThunkAffinityMask64TO32(
  211. IN ULONG_PTR Affinity64
  212. );
  213. ULONG_PTR
  214. Wow64ThunkAffinityMask32TO64(
  215. IN ULONG Affinity32
  216. );
  217. VOID WriteReturnLengthSilent(PULONG ReturnLength, ULONG Length);
  218. VOID WriteReturnLengthStatus(PULONG ReturnLength, NTSTATUS *pStatus, ULONG Length);
  219. //
  220. // Log flags
  221. //
  222. #define LF_NONE 0x00000000
  223. #define LF_ERROR 0x00000001
  224. #define LF_TRACE 0x00000002
  225. #define LF_NTBASE_NAME 0x00000004
  226. #define LF_NTBASE_FULL 0x00000008
  227. #define LF_WIN32_NAME 0x00000010
  228. #define LF_WIN32_FULL 0x00000020
  229. #define LF_NTCON_NAME 0x00000040
  230. #define LF_NTCON_FULL 0x00000080
  231. #define LF_ExCEPTION 0x80000000
  232. //
  233. // Supported data types for logging
  234. //
  235. #define TypeHex 0x00UI64
  236. #define TypePULongPtrInOut 0x01UI64
  237. #define TypePULongOut 0x02UI64
  238. #define TypePHandleOut 0x03UI64
  239. #define TypeUnicodeStringIn 0x04UI64
  240. #define TypeObjectAttributesIn 0x05UI64
  241. #define TypeIoStatusBlockOut 0x06UI64
  242. #define TypePwstrIn 0x07UI64
  243. #define TypePRectIn 0x08UI64
  244. #define TypePLargeIntegerIn 0x09UI64
  245. #undef WOW64DLLAPI
  246. #endif // _WOW64THK_INCLUDE