WinNT.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:293k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /*++ BUILD Version: 0082     Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4.     winnt.h
  5. Abstract:
  6.     This module defines the 32-Bit Windows types and constants that are
  7.     defined by NT, but exposed through the Win32 API.
  8. Revision History:
  9. --*/
  10. #ifndef _WINNT_
  11. #define _WINNT_
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include <ctype.h>  
  16. #define ANYSIZE_ARRAY 1       
  17. #if defined(_M_MRX000) && !(defined(MIDL_PASS) || defined(RC_INVOKED)) && defined(ENABLE_RESTRICTED)
  18. #define RESTRICTED_POINTER __restrict
  19. #else
  20. #define RESTRICTED_POINTER
  21. #endif
  22. #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64) || defined(_M_AMD64)
  23. #define UNALIGNED __unaligned
  24. #if defined(_WIN64)
  25. #define UNALIGNED64 __unaligned
  26. #else
  27. #define UNALIGNED64
  28. #endif
  29. #else
  30. #define UNALIGNED
  31. #define UNALIGNED64
  32. #endif
  33. #if defined(_WIN64) || defined(_M_ALPHA)
  34. #define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG)
  35. #define MEMORY_ALLOCATION_ALIGNMENT 16
  36. #else
  37. #define MAX_NATURAL_ALIGNMENT sizeof(DWORD)
  38. #define MEMORY_ALLOCATION_ALIGNMENT 8
  39. #endif
  40. //
  41. // TYPE_ALIGNMENT will return the alignment requirements of a given type for
  42. // the current platform.
  43. //
  44. #ifdef __cplusplus
  45. #if _MSC_VER >= 1300
  46. #define TYPE_ALIGNMENT( t ) __alignof(t)
  47. #endif
  48. #else
  49. #define TYPE_ALIGNMENT( t ) 
  50.     FIELD_OFFSET( struct { char x; t test; }, test )
  51. #endif
  52. #if defined(_WIN64)
  53. #define PROBE_ALIGNMENT( _s ) (TYPE_ALIGNMENT( _s ) > TYPE_ALIGNMENT( DWORD ) ? 
  54.                                TYPE_ALIGNMENT( _s ) : TYPE_ALIGNMENT( DWORD ))
  55. #define PROBE_ALIGNMENT32( _s ) TYPE_ALIGNMENT( DWORD )
  56. #else
  57. #define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( DWORD )
  58. #endif
  59. //
  60. // C_ASSERT() can be used to perform many compile-time assertions:
  61. //            type sizes, field offsets, etc.
  62. //
  63. // An assertion failure results in error C2118: negative subscript.
  64. //
  65. #define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
  66. #if !defined(_MAC) && (defined(_M_MRX000) || defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_VER >= 1100) && !(defined(MIDL_PASS) || defined(RC_INVOKED))
  67. #define POINTER_64 __ptr64
  68. typedef unsigned __int64 POINTER_64_INT;
  69. #if defined(_WIN64)
  70. #define POINTER_32 __ptr32
  71. #else
  72. #define POINTER_32
  73. #endif
  74. #else
  75. #if defined(_MAC) && defined(_MAC_INT_64)
  76. #define POINTER_64 __ptr64
  77. typedef unsigned __int64 POINTER_64_INT;
  78. #else
  79. #define POINTER_64
  80. typedef unsigned long POINTER_64_INT;
  81. #endif
  82. #define POINTER_32
  83. #endif
  84. #if defined(_IA64_) || defined(_AMD64_)
  85. #define FIRMWARE_PTR
  86. #else
  87. #define FIRMWARE_PTR POINTER_32
  88. #endif
  89. #include <basetsd.h>
  90. #if (defined(_M_IX86) || defined(_M_IA64) || defined(_M_AMD64)) && !defined(MIDL_PASS)
  91. #define DECLSPEC_IMPORT __declspec(dllimport)
  92. #else
  93. #define DECLSPEC_IMPORT
  94. #endif
  95. #ifndef DECLSPEC_NORETURN
  96. #if (_MSC_VER >= 1200) && !defined(MIDL_PASS)
  97. #define DECLSPEC_NORETURN   __declspec(noreturn)
  98. #else
  99. #define DECLSPEC_NORETURN
  100. #endif
  101. #endif
  102. #ifndef DECLSPEC_ALIGN
  103. #if (_MSC_VER >= 1300) && !defined(MIDL_PASS)
  104. #define DECLSPEC_ALIGN(x)   __declspec(align(x))
  105. #else
  106. #define DECLSPEC_ALIGN(x)
  107. #endif
  108. #endif
  109. #ifndef DECLSPEC_CACHEALIGN
  110. #define DECLSPEC_CACHEALIGN DECLSPEC_ALIGN(128)
  111. #endif
  112. #ifndef DECLSPEC_UUID
  113. #if (_MSC_VER >= 1100) && defined (__cplusplus)
  114. #define DECLSPEC_UUID(x)    __declspec(uuid(x))
  115. #else
  116. #define DECLSPEC_UUID(x)
  117. #endif
  118. #endif
  119. #ifndef DECLSPEC_NOVTABLE
  120. #if (_MSC_VER >= 1100) && defined(__cplusplus)
  121. #define DECLSPEC_NOVTABLE   __declspec(novtable)
  122. #else
  123. #define DECLSPEC_NOVTABLE
  124. #endif
  125. #endif
  126. #ifndef DECLSPEC_SELECTANY
  127. #if (_MSC_VER >= 1100)
  128. #define DECLSPEC_SELECTANY  __declspec(selectany)
  129. #else
  130. #define DECLSPEC_SELECTANY
  131. #endif
  132. #endif
  133. #ifndef NOP_FUNCTION
  134. #if (_MSC_VER >= 1210)
  135. #define NOP_FUNCTION __noop
  136. #else
  137. #define NOP_FUNCTION (void)0
  138. #endif
  139. #endif
  140. #ifndef DECLSPEC_ADDRSAFE
  141. #if (_MSC_VER >= 1200) && (defined(_M_ALPHA) || defined(_M_AXP64))
  142. #define DECLSPEC_ADDRSAFE  __declspec(address_safe)
  143. #else
  144. #define DECLSPEC_ADDRSAFE
  145. #endif
  146. #endif
  147. #ifndef FORCEINLINE
  148. #if (_MSC_VER >= 1200)
  149. #define FORCEINLINE __forceinline
  150. #else
  151. #define FORCEINLINE __inline
  152. #endif
  153. #endif
  154. #ifndef DECLSPEC_DEPRECATED
  155. #if (_MSC_VER >= 1300) && !defined(MIDL_PASS)
  156. #define DECLSPEC_DEPRECATED   __declspec(deprecated)
  157. #define DEPRECATE_SUPPORTED
  158. #else
  159. #define DECLSPEC_DEPRECATED
  160. #undef  DEPRECATE_SUPPORTED
  161. #endif
  162. #endif
  163. typedef void *PVOID;
  164. typedef void * POINTER_64 PVOID64;
  165. #if ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)) && !defined(_M_AMD64)
  166. #define NTAPI __stdcall
  167. #else
  168. #define _cdecl
  169. #define NTAPI
  170. #endif
  171. //
  172. // Define API decoration for direct importing system DLL references.
  173. //
  174. #if !defined(_NTSYSTEM_)
  175. #define NTSYSAPI     DECLSPEC_IMPORT
  176. #define NTSYSCALLAPI DECLSPEC_IMPORT
  177. #else
  178. #define NTSYSAPI
  179. #if defined(_NTDLLBUILD_)
  180. #define NTSYSCALLAPI
  181. #else
  182. #define NTSYSCALLAPI DECLSPEC_ADDRSAFE
  183. #endif
  184. #endif
  185. //
  186. // Basics
  187. //
  188. #ifndef VOID
  189. #define VOID void
  190. typedef char CHAR;
  191. typedef short SHORT;
  192. typedef long LONG;
  193. #endif
  194. //
  195. // UNICODE (Wide Character) types
  196. //
  197. #ifndef _MAC
  198. typedef wchar_t WCHAR;    // wc,   16-bit UNICODE character
  199. #else
  200. // some Macintosh compilers don't define wchar_t in a convenient location, or define it as a char
  201. typedef unsigned short WCHAR;    // wc,   16-bit UNICODE character
  202. #endif
  203. typedef WCHAR *PWCHAR;
  204. typedef WCHAR *LPWCH, *PWCH;
  205. typedef CONST WCHAR *LPCWCH, *PCWCH;
  206. typedef WCHAR *NWPSTR;
  207. typedef WCHAR *LPWSTR, *PWSTR;
  208. typedef WCHAR UNALIGNED *LPUWSTR, *PUWSTR;
  209. typedef CONST WCHAR *LPCWSTR, *PCWSTR;
  210. typedef CONST WCHAR UNALIGNED *LPCUWSTR, *PCUWSTR;
  211. //
  212. // ANSI (Multi-byte Character) types
  213. //
  214. typedef CHAR *PCHAR;
  215. typedef CHAR *LPCH, *PCH;
  216. typedef CONST CHAR *LPCCH, *PCCH;
  217. typedef CHAR *NPSTR;
  218. typedef CHAR *LPSTR, *PSTR;
  219. typedef CONST CHAR *LPCSTR, *PCSTR;
  220. //
  221. // Neutral ANSI/UNICODE types and macros
  222. //
  223. #ifdef  UNICODE                     // r_winnt
  224. #ifndef _TCHAR_DEFINED
  225. typedef WCHAR TCHAR, *PTCHAR;
  226. typedef WCHAR TBYTE , *PTBYTE ;
  227. #define _TCHAR_DEFINED
  228. #endif /* !_TCHAR_DEFINED */
  229. typedef LPWSTR LPTCH, PTCH;
  230. typedef LPWSTR PTSTR, LPTSTR;
  231. typedef LPCWSTR PCTSTR, LPCTSTR;
  232. typedef LPUWSTR PUTSTR, LPUTSTR;
  233. typedef LPCUWSTR PCUTSTR, LPCUTSTR;
  234. typedef LPWSTR LP;
  235. #define __TEXT(quote) L##quote      // r_winnt
  236. #else   /* UNICODE */               // r_winnt
  237. #ifndef _TCHAR_DEFINED
  238. typedef char TCHAR, *PTCHAR;
  239. typedef unsigned char TBYTE , *PTBYTE ;
  240. #define _TCHAR_DEFINED
  241. #endif /* !_TCHAR_DEFINED */
  242. typedef LPSTR LPTCH, PTCH;
  243. typedef LPSTR PTSTR, LPTSTR, PUTSTR, LPUTSTR;
  244. typedef LPCSTR PCTSTR, LPCTSTR, PCUTSTR, LPCUTSTR;
  245. #define __TEXT(quote) quote         // r_winnt
  246. #endif /* UNICODE */                // r_winnt
  247. #define TEXT(quote) __TEXT(quote)   // r_winnt
  248. typedef SHORT *PSHORT;  
  249. typedef LONG *PLONG;    
  250. #ifdef STRICT
  251. typedef void *HANDLE;
  252. #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
  253. #else
  254. typedef PVOID HANDLE;
  255. #define DECLARE_HANDLE(name) typedef HANDLE name
  256. #endif
  257. typedef HANDLE *PHANDLE;
  258. //
  259. // Flag (bit) fields
  260. //
  261. typedef BYTE   FCHAR;
  262. typedef WORD   FSHORT;
  263. typedef DWORD  FLONG;
  264. // Component Object Model defines, and macros
  265. #ifndef _HRESULT_DEFINED
  266. #define _HRESULT_DEFINED
  267. typedef LONG HRESULT;
  268. #endif // !_HRESULT_DEFINED
  269. #ifdef __cplusplus
  270.     #define EXTERN_C    extern "C"
  271. #else
  272.     #define EXTERN_C    extern
  273. #endif
  274. #if defined(_WIN32) || defined(_MPPC_)
  275. // Win32 doesn't support __export
  276. #ifdef _68K_
  277. #define STDMETHODCALLTYPE       __cdecl
  278. #else
  279. #define STDMETHODCALLTYPE       __stdcall
  280. #endif
  281. #define STDMETHODVCALLTYPE      __cdecl
  282. #define STDAPICALLTYPE          __stdcall
  283. #define STDAPIVCALLTYPE         __cdecl
  284. #else
  285. #define STDMETHODCALLTYPE       __export __stdcall
  286. #define STDMETHODVCALLTYPE      __export __cdecl
  287. #define STDAPICALLTYPE          __export __stdcall
  288. #define STDAPIVCALLTYPE         __export __cdecl
  289. #endif
  290. #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
  291. #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
  292. #define STDMETHODIMP            HRESULT STDMETHODCALLTYPE
  293. #define STDMETHODIMP_(type)     type STDMETHODCALLTYPE
  294. // The 'V' versions allow Variable Argument lists.
  295. #define STDAPIV                 EXTERN_C HRESULT STDAPIVCALLTYPE
  296. #define STDAPIV_(type)          EXTERN_C type STDAPIVCALLTYPE
  297. #define STDMETHODIMPV           HRESULT STDMETHODVCALLTYPE
  298. #define STDMETHODIMPV_(type)    type STDMETHODVCALLTYPE
  299. typedef char CCHAR;          
  300. typedef DWORD LCID;         
  301. typedef PDWORD PLCID;       
  302. typedef WORD   LANGID;      
  303. #define APPLICATION_ERROR_MASK       0x20000000
  304. #define ERROR_SEVERITY_SUCCESS       0x00000000
  305. #define ERROR_SEVERITY_INFORMATIONAL 0x40000000
  306. #define ERROR_SEVERITY_WARNING       0x80000000
  307. #define ERROR_SEVERITY_ERROR         0xC0000000
  308. //
  309. // _M_IX86 included so that EM CONTEXT structure compiles with
  310. // x86 programs. *** TBD should this be for all architectures?
  311. //
  312. //
  313. // 16 byte aligned type for 128 bit floats
  314. //
  315. //
  316. // For we define a 128 bit structure and use __declspec(align(16)) pragma to
  317. // align to 128 bits.
  318. //
  319. #if defined(_M_IA64) && !defined(MIDL_PASS)
  320. __declspec(align(16))
  321. #endif
  322. typedef struct _FLOAT128 {
  323.     __int64 LowPart;
  324.     __int64 HighPart;
  325. } FLOAT128;
  326. typedef FLOAT128 *PFLOAT128;
  327. //
  328. // __int64 is only supported by 2.0 and later midl.
  329. // __midl is set by the 2.0 midl and not by 1.0 midl.
  330. //
  331. #define _ULONGLONG_
  332. #if (!defined (_MAC) && (!defined(MIDL_PASS) || defined(__midl)) && (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64)))
  333. typedef __int64 LONGLONG;
  334. typedef unsigned __int64 ULONGLONG;
  335. #define MAXLONGLONG                      (0x7fffffffffffffff)
  336. #else
  337. #if defined(_MAC) && defined(_MAC_INT_64)
  338. typedef __int64 LONGLONG;
  339. typedef unsigned __int64 ULONGLONG;
  340. #define MAXLONGLONG                      (0x7fffffffffffffff)
  341. #else
  342. typedef double LONGLONG;
  343. typedef double ULONGLONG;
  344. #endif //_MAC and int64
  345. #endif
  346. typedef LONGLONG *PLONGLONG;
  347. typedef ULONGLONG *PULONGLONG;
  348. // Update Sequence Number
  349. typedef LONGLONG USN;
  350. #if defined(MIDL_PASS)
  351. typedef struct _LARGE_INTEGER {
  352. #else // MIDL_PASS
  353. typedef union _LARGE_INTEGER {
  354.     struct {
  355.         DWORD LowPart;
  356.         LONG HighPart;
  357.     };
  358.     struct {
  359.         DWORD LowPart;
  360.         LONG HighPart;
  361.     } u;
  362. #endif //MIDL_PASS
  363.     LONGLONG QuadPart;
  364. } LARGE_INTEGER;
  365. typedef LARGE_INTEGER *PLARGE_INTEGER;
  366. #if defined(MIDL_PASS)
  367. typedef struct _ULARGE_INTEGER {
  368. #else // MIDL_PASS
  369. typedef union _ULARGE_INTEGER {
  370.     struct {
  371.         DWORD LowPart;
  372.         DWORD HighPart;
  373.     };
  374.     struct {
  375.         DWORD LowPart;
  376.         DWORD HighPart;
  377.     } u;
  378. #endif //MIDL_PASS
  379.     ULONGLONG QuadPart;
  380. } ULARGE_INTEGER;
  381. typedef ULARGE_INTEGER *PULARGE_INTEGER;
  382. // end_ntminiport end_ntndis end_ntminitape
  383. //
  384. // Locally Unique Identifier
  385. //
  386. typedef struct _LUID {
  387.     DWORD LowPart;
  388.     LONG HighPart;
  389. } LUID, *PLUID;
  390. #define _DWORDLONG_
  391. typedef ULONGLONG  DWORDLONG;
  392. typedef DWORDLONG *PDWORDLONG;
  393. //
  394. // Define operations to logically shift an int64 by 0..31 bits and to multiply
  395. // 32-bits by 32-bits to form a 64-bit product.
  396. //
  397. #if defined(MIDL_PASS) || defined(RC_INVOKED)
  398. //
  399. // Midl does not understand inline assembler. Therefore, the Rtl functions
  400. // are used for shifts by 0.31 and multiplies of 32-bits times 32-bits to
  401. // form a 64-bit product.
  402. //
  403. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  404. #define UInt32x32To64(a, b) ((ULONGLONG)((DWORD)(a)) * (ULONGLONG)((DWORD)(b)))
  405. #define Int64ShllMod32(a, b) ((ULONGLONG)(a) << (b))
  406. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  407. #define Int64ShrlMod32(a, b) ((ULONGLONG)(a) >> (b))
  408. #elif defined(_M_MRX000)
  409. //
  410. // MIPS uses intrinsic functions to perform shifts by 0..31 and multiplies of
  411. // 32-bits times 32-bits to 64-bits.
  412. //
  413. #define Int32x32To64 __emul
  414. #define UInt32x32To64 __emulu
  415. #define Int64ShllMod32 __ll_lshift
  416. #define Int64ShraMod32 __ll_rshift
  417. #define Int64ShrlMod32 __ull_rshift
  418. #if defined (__cplusplus)
  419. extern "C" {
  420. #endif
  421. LONGLONG
  422. NTAPI
  423. Int32x32To64 (
  424.     LONG Multiplier,
  425.     LONG Multiplicand
  426.     );
  427. ULONGLONG
  428. NTAPI
  429. UInt32x32To64 (
  430.     DWORD Multiplier,
  431.     DWORD Multiplicand
  432.     );
  433. ULONGLONG
  434. NTAPI
  435. Int64ShllMod32 (
  436.     ULONGLONG Value,
  437.     DWORD ShiftCount
  438.     );
  439. LONGLONG
  440. NTAPI
  441. Int64ShraMod32 (
  442.     LONGLONG Value,
  443.     DWORD ShiftCount
  444.     );
  445. ULONGLONG
  446. NTAPI
  447. Int64ShrlMod32 (
  448.     ULONGLONG Value,
  449.     DWORD ShiftCount
  450.     );
  451. #if defined (__cplusplus)
  452. };
  453. #endif
  454. #pragma intrinsic(__emul)
  455. #pragma intrinsic(__emulu)
  456. #pragma intrinsic(__ll_lshift)
  457. #pragma intrinsic(__ll_rshift)
  458. #pragma intrinsic(__ull_rshift)
  459. #elif defined(_M_IX86)
  460. //
  461. // The x86 C compiler understands inline assembler. Therefore, inline functions
  462. // that employ inline assembler are used for shifts of 0..31.  The multiplies
  463. // rely on the compiler recognizing the cast of the multiplicand to int64 to
  464. // generate the optimal code inline.
  465. //
  466. #define Int32x32To64( a, b ) (LONGLONG)((LONGLONG)(LONG)(a) * (LONG)(b))
  467. #define UInt32x32To64( a, b ) (ULONGLONG)((ULONGLONG)(DWORD)(a) * (DWORD)(b))
  468. ULONGLONG
  469. NTAPI
  470. Int64ShllMod32 (
  471.     ULONGLONG Value,
  472.     DWORD ShiftCount
  473.     );
  474. LONGLONG
  475. NTAPI
  476. Int64ShraMod32 (
  477.     LONGLONG Value,
  478.     DWORD ShiftCount
  479.     );
  480. ULONGLONG
  481. NTAPI
  482. Int64ShrlMod32 (
  483.     ULONGLONG Value,
  484.     DWORD ShiftCount
  485.     );
  486. #if _MSC_VER >= 1200
  487. #pragma warning(push)
  488. #endif
  489. #pragma warning(disable:4035)               // re-enable below
  490. __inline ULONGLONG
  491. NTAPI
  492. Int64ShllMod32 (
  493.     ULONGLONG Value,
  494.     DWORD ShiftCount
  495.     )
  496. {
  497.     __asm    {
  498.         mov     ecx, ShiftCount
  499.         mov     eax, dword ptr [Value]
  500.         mov     edx, dword ptr [Value+4]
  501.         shld    edx, eax, cl
  502.         shl     eax, cl
  503.     }
  504. }
  505. __inline LONGLONG
  506. NTAPI
  507. Int64ShraMod32 (
  508.     LONGLONG Value,
  509.     DWORD ShiftCount
  510.     )
  511. {
  512.     __asm {
  513.         mov     ecx, ShiftCount
  514.         mov     eax, dword ptr [Value]
  515.         mov     edx, dword ptr [Value+4]
  516.         shrd    eax, edx, cl
  517.         sar     edx, cl
  518.     }
  519. }
  520. __inline ULONGLONG
  521. NTAPI
  522. Int64ShrlMod32 (
  523.     ULONGLONG Value,
  524.     DWORD ShiftCount
  525.     )
  526. {
  527.     __asm    {
  528.         mov     ecx, ShiftCount
  529.         mov     eax, dword ptr [Value]
  530.         mov     edx, dword ptr [Value+4]
  531.         shrd    eax, edx, cl
  532.         shr     edx, cl
  533.     }
  534. }
  535. #if _MSC_VER >= 1200
  536. #pragma warning(pop)
  537. #else
  538. #pragma warning(default:4035)
  539. #endif
  540. #elif defined(_M_ALPHA)
  541. //
  542. // Alpha has native 64-bit operations that are just as fast as their 32-bit
  543. // counter parts. Therefore, the int64 data type is used directly to form
  544. // shifts of 0..31 and multiplies of 32-bits times 32-bits to form a 64-bit
  545. // product.
  546. //
  547. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  548. #define UInt32x32To64(a, b) ((ULONGLONG)((DWORD)(a)) * (ULONGLONG)((DWORD)(b)))
  549. #define Int64ShllMod32(a, b) ((ULONGLONG)(a) << (b))
  550. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  551. #define Int64ShrlMod32(a, b) ((ULONGLONG)(a) >> (b))
  552. #elif defined(_M_PPC)
  553. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  554. #define UInt32x32To64(a, b) ((ULONGLONG)((DWORD)(a)) * (ULONGLONG)((DWORD)(b)))
  555. #define Int64ShllMod32(a, b) ((ULONGLONG)(a) << (b))
  556. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  557. #define Int64ShrlMod32(a, b) ((ULONGLONG)(a) >> (b))
  558. #elif defined(_68K_) || defined(_MPPC_)
  559. //
  560. // The Macintosh 68K and PowerPC compilers do not currently support int64.
  561. //
  562. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  563. #define UInt32x32To64(a, b) ((DWORDLONG)((DWORD)(a)) * (DWORDLONG)((DWORD)(b)))
  564. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  565. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  566. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  567. #elif defined(_M_IA64) || defined(_M_AMD64)
  568. //
  569. // IA64 has native 64-bit operations that are just as fast as their 32-bit
  570. // counter parts. Therefore, the int64 data type is used directly to form
  571. // shifts of 0..31 and multiplies of 32-bits times 32-bits to form a 64-bit
  572. // product.
  573. //
  574. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  575. #define UInt32x32To64(a, b) ((ULONGLONG)((DWORD)(a)) * (ULONGLONG)((DWORD)(b)))
  576. #define Int64ShllMod32(a, b) ((ULONGLONG)(a) << (b))
  577. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  578. #define Int64ShrlMod32(a, b) ((ULONGLONG)(a) >> (b))
  579. #else
  580. #error Must define a target architecture.
  581. #endif
  582. #define ANSI_NULL ((CHAR)0)     
  583. #define UNICODE_NULL ((WCHAR)0) 
  584. #define UNICODE_STRING_MAX_BYTES ((WORD  ) 65534) 
  585. #define UNICODE_STRING_MAX_CHARS (32767) 
  586. typedef BYTE  BOOLEAN;           
  587. typedef BOOLEAN *PBOOLEAN;       
  588. //
  589. //  Doubly linked list structure.  Can be used as either a list head, or
  590. //  as link words.
  591. //
  592. typedef struct _LIST_ENTRY {
  593.    struct _LIST_ENTRY *Flink;
  594.    struct _LIST_ENTRY *Blink;
  595. } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;
  596. //
  597. //  Singly linked list structure. Can be used as either a list head, or
  598. //  as link words.
  599. //
  600. typedef struct _SINGLE_LIST_ENTRY {
  601.     struct _SINGLE_LIST_ENTRY *Next;
  602. } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
  603. //
  604. // These are needed for portable debugger support.
  605. //
  606. typedef struct LIST_ENTRY32 {
  607.     DWORD Flink;
  608.     DWORD Blink;
  609. } LIST_ENTRY32;
  610. typedef LIST_ENTRY32 *PLIST_ENTRY32;
  611. typedef struct LIST_ENTRY64 {
  612.     ULONGLONG Flink;
  613.     ULONGLONG Blink;
  614. } LIST_ENTRY64;
  615. typedef LIST_ENTRY64 *PLIST_ENTRY64;
  616. #include <guiddef.h>
  617. #ifndef __OBJECTID_DEFINED
  618. #define __OBJECTID_DEFINED
  619. typedef struct  _OBJECTID {     // size is 20
  620.     GUID Lineage;
  621.     DWORD Uniquifier;
  622. } OBJECTID;
  623. #endif // !_OBJECTID_DEFINED
  624. #define MINCHAR     0x80        
  625. #define MAXCHAR     0x7f        
  626. #define MINSHORT    0x8000      
  627. #define MAXSHORT    0x7fff      
  628. #define MINLONG     0x80000000  
  629. #define MAXLONG     0x7fffffff  
  630. #define MAXBYTE     0xff        
  631. #define MAXWORD     0xffff      
  632. #define MAXDWORD    0xffffffff  
  633. //
  634. // Calculate the byte offset of a field in a structure of type type.
  635. //
  636. #define FIELD_OFFSET(type, field)    ((LONG)(LONG_PTR)&(((type *)0)->field))
  637. #if(_WIN32_WINNT > 0x0500)
  638. //
  639. // Calculate the size of a field in a structure of type type, without
  640. // knowing or stating the type of the field.
  641. //
  642. #define RTL_FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
  643. //
  644. // Calculate the size of a structure of type type up through and
  645. // including a field.
  646. //
  647. #define RTL_SIZEOF_THROUGH_FIELD(type, field) 
  648.     (FIELD_OFFSET(type, field) + RTL_FIELD_SIZE(type, field))
  649. //
  650. //  RTL_CONTAINS_FIELD usage:
  651. //
  652. //      if (RTL_CONTAINS_FIELD(pBlock, pBlock->cbSize, dwMumble)) { // safe to use pBlock->dwMumble
  653. //
  654. #define RTL_CONTAINS_FIELD(Struct, Size, Field) 
  655.     ( (((PCHAR)(&(Struct)->Field)) + sizeof((Struct)->Field)) <= (((PCHAR)(Struct))+(Size)) )
  656. //
  657. // Return the number of elements in a statically sized array.
  658. //   DWORD Buffer[100];
  659. //   RTL_NUMBER_OF(Buffer) == 100
  660. // This is also popularly known as: NUMBER_OF, ARRSIZE, _countof, NELEM, etc.
  661. //
  662. #define RTL_NUMBER_OF(A) (sizeof(A)/sizeof((A)[0]))
  663. //
  664. // An expression that yields the type of a field in a struct.
  665. //
  666. #define RTL_FIELD_TYPE(type, field) (((type*)0)->field)
  667. // RTL_ to avoid collisions in the global namespace.
  668. //
  669. // Given typedef struct _FOO { BYTE Bar[123]; } FOO;
  670. // RTL_NUMBER_OF_FIELD(FOO, Bar) == 123
  671. //
  672. #define RTL_NUMBER_OF_FIELD(type, field) (RTL_NUMBER_OF(RTL_FIELD_TYPE(type, field)))
  673. //
  674. // eg:
  675. // typedef struct FOO {
  676. //   DWORD Integer;
  677. //   PVOID Pointer;
  678. // } FOO;
  679. //
  680. // RTL_PADDING_BETWEEN_FIELDS(FOO, Integer, Pointer) == 0 for Win32, 4 for Win64
  681. //
  682. #define RTL_PADDING_BETWEEN_FIELDS(T, F1, F2) 
  683.     ((FIELD_OFFSET(T, F2) > FIELD_OFFSET(T, F1)) 
  684.         ? (FIELD_OFFSET(T, F2) - FIELD_OFFSET(T, F1) - RTL_FIELD_SIZE(T, F1)) 
  685.         : (FIELD_OFFSET(T, F1) - FIELD_OFFSET(T, F2) - RTL_FIELD_SIZE(T, F2)))
  686. // RTL_ to avoid collisions in the global namespace.
  687. #if defined(__cplusplus)
  688. #define RTL_CONST_CAST(type) const_cast<type>
  689. #else
  690. #define RTL_CONST_CAST(type) (type)
  691. #endif
  692. // like sizeof
  693. // usually this would be * CHAR_BIT, but we don't necessarily have #include <limits.h>
  694. #define RTL_BITS_OF(sizeOfArg) (sizeof(sizeOfArg) * 8)
  695. #define RTL_BITS_OF_FIELD(type, field) (RTL_BITS_OF(RTL_FIELD_TYPE(type, field)))
  696. #endif /* _WIN32_WINNT > 0x0500 */
  697. //
  698. // Calculate the address of the base of the structure given its type, and an
  699. // address of a field within the structure.
  700. //
  701. #define CONTAINING_RECORD(address, type, field) ((type *)( 
  702.                                                   (PCHAR)(address) - 
  703.                                                   (ULONG_PTR)(&((type *)0)->field)))
  704. #define VER_SERVER_NT                       0x80000000
  705. #define VER_WORKSTATION_NT                  0x40000000
  706. #define VER_SUITE_SMALLBUSINESS             0x00000001
  707. #define VER_SUITE_ENTERPRISE                0x00000002
  708. #define VER_SUITE_BACKOFFICE                0x00000004
  709. #define VER_SUITE_COMMUNICATIONS            0x00000008
  710. #define VER_SUITE_TERMINAL                  0x00000010
  711. #define VER_SUITE_SMALLBUSINESS_RESTRICTED  0x00000020
  712. #define VER_SUITE_EMBEDDEDNT                0x00000040
  713. #define VER_SUITE_DATACENTER                0x00000080
  714. #define VER_SUITE_SINGLEUSERTS              0x00000100
  715. #define VER_SUITE_PERSONAL                  0x00000200
  716. #define VER_SUITE_BLADE                     0x00000400
  717. //
  718. //  Language IDs.
  719. //
  720. //  The following two combinations of primary language ID and
  721. //  sublanguage ID have special semantics:
  722. //
  723. //    Primary Language ID   Sublanguage ID      Result
  724. //    -------------------   ---------------     ------------------------
  725. //    LANG_NEUTRAL          SUBLANG_NEUTRAL     Language neutral
  726. //    LANG_NEUTRAL          SUBLANG_DEFAULT     User default language
  727. //    LANG_NEUTRAL          SUBLANG_SYS_DEFAULT System default language
  728. //    LANG_INVARIANT        SUBLANG_NEUTRAL     Invariant locale
  729. //
  730. //
  731. //  Primary language IDs.
  732. //
  733. #define LANG_NEUTRAL                     0x00
  734. #define LANG_INVARIANT                   0x7f
  735. #define LANG_AFRIKAANS                   0x36
  736. #define LANG_ALBANIAN                    0x1c
  737. #define LANG_ARABIC                      0x01
  738. #define LANG_ARMENIAN                    0x2b
  739. #define LANG_ASSAMESE                    0x4d
  740. #define LANG_AZERI                       0x2c
  741. #define LANG_BASQUE                      0x2d
  742. #define LANG_BELARUSIAN                  0x23
  743. #define LANG_BENGALI                     0x45
  744. #define LANG_BULGARIAN                   0x02
  745. #define LANG_CATALAN                     0x03
  746. #define LANG_CHINESE                     0x04
  747. #define LANG_CROATIAN                    0x1a
  748. #define LANG_CZECH                       0x05
  749. #define LANG_DANISH                      0x06
  750. #define LANG_DIVEHI                      0x65
  751. #define LANG_DUTCH                       0x13
  752. #define LANG_ENGLISH                     0x09
  753. #define LANG_ESTONIAN                    0x25
  754. #define LANG_FAEROESE                    0x38
  755. #define LANG_FARSI                       0x29
  756. #define LANG_FINNISH                     0x0b
  757. #define LANG_FRENCH                      0x0c
  758. #define LANG_GALICIAN                    0x56
  759. #define LANG_GEORGIAN                    0x37
  760. #define LANG_GERMAN                      0x07
  761. #define LANG_GREEK                       0x08
  762. #define LANG_GUJARATI                    0x47
  763. #define LANG_HEBREW                      0x0d
  764. #define LANG_HINDI                       0x39
  765. #define LANG_HUNGARIAN                   0x0e
  766. #define LANG_ICELANDIC                   0x0f
  767. #define LANG_INDONESIAN                  0x21
  768. #define LANG_ITALIAN                     0x10
  769. #define LANG_JAPANESE                    0x11
  770. #define LANG_KANNADA                     0x4b
  771. #define LANG_KASHMIRI                    0x60
  772. #define LANG_KAZAK                       0x3f
  773. #define LANG_KONKANI                     0x57
  774. #define LANG_KOREAN                      0x12
  775. #define LANG_KYRGYZ                      0x40
  776. #define LANG_LATVIAN                     0x26
  777. #define LANG_LITHUANIAN                  0x27
  778. #define LANG_MACEDONIAN                  0x2f   // the Former Yugoslav Republic of Macedonia
  779. #define LANG_MALAY                       0x3e
  780. #define LANG_MALAYALAM                   0x4c
  781. #define LANG_MANIPURI                    0x58
  782. #define LANG_MARATHI                     0x4e
  783. #define LANG_MONGOLIAN                   0x50
  784. #define LANG_NEPALI                      0x61
  785. #define LANG_NORWEGIAN                   0x14
  786. #define LANG_ORIYA                       0x48
  787. #define LANG_POLISH                      0x15
  788. #define LANG_PORTUGUESE                  0x16
  789. #define LANG_PUNJABI                     0x46
  790. #define LANG_ROMANIAN                    0x18
  791. #define LANG_RUSSIAN                     0x19
  792. #define LANG_SANSKRIT                    0x4f
  793. #define LANG_SERBIAN                     0x1a
  794. #define LANG_SINDHI                      0x59
  795. #define LANG_SLOVAK                      0x1b
  796. #define LANG_SLOVENIAN                   0x24
  797. #define LANG_SPANISH                     0x0a
  798. #define LANG_SWAHILI                     0x41
  799. #define LANG_SWEDISH                     0x1d
  800. #define LANG_SYRIAC                      0x5a
  801. #define LANG_TAMIL                       0x49
  802. #define LANG_TATAR                       0x44
  803. #define LANG_TELUGU                      0x4a
  804. #define LANG_THAI                        0x1e
  805. #define LANG_TURKISH                     0x1f
  806. #define LANG_UKRAINIAN                   0x22
  807. #define LANG_URDU                        0x20
  808. #define LANG_UZBEK                       0x43
  809. #define LANG_VIETNAMESE                  0x2a
  810. //
  811. //  Sublanguage IDs.
  812. //
  813. //  The name immediately following SUBLANG_ dictates which primary
  814. //  language ID that sublanguage ID can be combined with to form a
  815. //  valid language ID.
  816. //
  817. #define SUBLANG_NEUTRAL                  0x00    // language neutral
  818. #define SUBLANG_DEFAULT                  0x01    // user default
  819. #define SUBLANG_SYS_DEFAULT              0x02    // system default
  820. #define SUBLANG_ARABIC_SAUDI_ARABIA      0x01    // Arabic (Saudi Arabia)
  821. #define SUBLANG_ARABIC_IRAQ              0x02    // Arabic (Iraq)
  822. #define SUBLANG_ARABIC_EGYPT             0x03    // Arabic (Egypt)
  823. #define SUBLANG_ARABIC_LIBYA             0x04    // Arabic (Libya)
  824. #define SUBLANG_ARABIC_ALGERIA           0x05    // Arabic (Algeria)
  825. #define SUBLANG_ARABIC_MOROCCO           0x06    // Arabic (Morocco)
  826. #define SUBLANG_ARABIC_TUNISIA           0x07    // Arabic (Tunisia)
  827. #define SUBLANG_ARABIC_OMAN              0x08    // Arabic (Oman)
  828. #define SUBLANG_ARABIC_YEMEN             0x09    // Arabic (Yemen)
  829. #define SUBLANG_ARABIC_SYRIA             0x0a    // Arabic (Syria)
  830. #define SUBLANG_ARABIC_JORDAN            0x0b    // Arabic (Jordan)
  831. #define SUBLANG_ARABIC_LEBANON           0x0c    // Arabic (Lebanon)
  832. #define SUBLANG_ARABIC_KUWAIT            0x0d    // Arabic (Kuwait)
  833. #define SUBLANG_ARABIC_UAE               0x0e    // Arabic (U.A.E)
  834. #define SUBLANG_ARABIC_BAHRAIN           0x0f    // Arabic (Bahrain)
  835. #define SUBLANG_ARABIC_QATAR             0x10    // Arabic (Qatar)
  836. #define SUBLANG_AZERI_LATIN              0x01    // Azeri (Latin)
  837. #define SUBLANG_AZERI_CYRILLIC           0x02    // Azeri (Cyrillic)
  838. #define SUBLANG_CHINESE_TRADITIONAL      0x01    // Chinese (Taiwan)
  839. #define SUBLANG_CHINESE_SIMPLIFIED       0x02    // Chinese (PR China)
  840. #define SUBLANG_CHINESE_HONGKONG         0x03    // Chinese (Hong Kong S.A.R., P.R.C.)
  841. #define SUBLANG_CHINESE_SINGAPORE        0x04    // Chinese (Singapore)
  842. #define SUBLANG_CHINESE_MACAU            0x05    // Chinese (Macau S.A.R.)
  843. #define SUBLANG_DUTCH                    0x01    // Dutch
  844. #define SUBLANG_DUTCH_BELGIAN            0x02    // Dutch (Belgian)
  845. #define SUBLANG_ENGLISH_US               0x01    // English (USA)
  846. #define SUBLANG_ENGLISH_UK               0x02    // English (UK)
  847. #define SUBLANG_ENGLISH_AUS              0x03    // English (Australian)
  848. #define SUBLANG_ENGLISH_CAN              0x04    // English (Canadian)
  849. #define SUBLANG_ENGLISH_NZ               0x05    // English (New Zealand)
  850. #define SUBLANG_ENGLISH_EIRE             0x06    // English (Irish)
  851. #define SUBLANG_ENGLISH_SOUTH_AFRICA     0x07    // English (South Africa)
  852. #define SUBLANG_ENGLISH_JAMAICA          0x08    // English (Jamaica)
  853. #define SUBLANG_ENGLISH_CARIBBEAN        0x09    // English (Caribbean)
  854. #define SUBLANG_ENGLISH_BELIZE           0x0a    // English (Belize)
  855. #define SUBLANG_ENGLISH_TRINIDAD         0x0b    // English (Trinidad)
  856. #define SUBLANG_ENGLISH_ZIMBABWE         0x0c    // English (Zimbabwe)
  857. #define SUBLANG_ENGLISH_PHILIPPINES      0x0d    // English (Philippines)
  858. #define SUBLANG_FRENCH                   0x01    // French
  859. #define SUBLANG_FRENCH_BELGIAN           0x02    // French (Belgian)
  860. #define SUBLANG_FRENCH_CANADIAN          0x03    // French (Canadian)
  861. #define SUBLANG_FRENCH_SWISS             0x04    // French (Swiss)
  862. #define SUBLANG_FRENCH_LUXEMBOURG        0x05    // French (Luxembourg)
  863. #define SUBLANG_FRENCH_MONACO            0x06    // French (Monaco)
  864. #define SUBLANG_GERMAN                   0x01    // German
  865. #define SUBLANG_GERMAN_SWISS             0x02    // German (Swiss)
  866. #define SUBLANG_GERMAN_AUSTRIAN          0x03    // German (Austrian)
  867. #define SUBLANG_GERMAN_LUXEMBOURG        0x04    // German (Luxembourg)
  868. #define SUBLANG_GERMAN_LIECHTENSTEIN     0x05    // German (Liechtenstein)
  869. #define SUBLANG_ITALIAN                  0x01    // Italian
  870. #define SUBLANG_ITALIAN_SWISS            0x02    // Italian (Swiss)
  871. #if _WIN32_WINNT >= 0x0501
  872. #define SUBLANG_KASHMIRI_SASIA           0x02    // Kashmiri (South Asia)
  873. #endif
  874. #define SUBLANG_KASHMIRI_INDIA           0x02    // For app compatibility only
  875. #define SUBLANG_KOREAN                   0x01    // Korean (Extended Wansung)
  876. #define SUBLANG_LITHUANIAN               0x01    // Lithuanian
  877. #define SUBLANG_MALAY_MALAYSIA           0x01    // Malay (Malaysia)
  878. #define SUBLANG_MALAY_BRUNEI_DARUSSALAM  0x02    // Malay (Brunei Darussalam)
  879. #define SUBLANG_NEPALI_INDIA             0x02    // Nepali (India)
  880. #define SUBLANG_NORWEGIAN_BOKMAL         0x01    // Norwegian (Bokmal)
  881. #define SUBLANG_NORWEGIAN_NYNORSK        0x02    // Norwegian (Nynorsk)
  882. #define SUBLANG_PORTUGUESE               0x02    // Portuguese
  883. #define SUBLANG_PORTUGUESE_BRAZILIAN     0x01    // Portuguese (Brazilian)
  884. #define SUBLANG_SERBIAN_LATIN            0x02    // Serbian (Latin)
  885. #define SUBLANG_SERBIAN_CYRILLIC         0x03    // Serbian (Cyrillic)
  886. #define SUBLANG_SPANISH                  0x01    // Spanish (Castilian)
  887. #define SUBLANG_SPANISH_MEXICAN          0x02    // Spanish (Mexican)
  888. #define SUBLANG_SPANISH_MODERN           0x03    // Spanish (Modern)
  889. #define SUBLANG_SPANISH_GUATEMALA        0x04    // Spanish (Guatemala)
  890. #define SUBLANG_SPANISH_COSTA_RICA       0x05    // Spanish (Costa Rica)
  891. #define SUBLANG_SPANISH_PANAMA           0x06    // Spanish (Panama)
  892. #define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07  // Spanish (Dominican Republic)
  893. #define SUBLANG_SPANISH_VENEZUELA        0x08    // Spanish (Venezuela)
  894. #define SUBLANG_SPANISH_COLOMBIA         0x09    // Spanish (Colombia)
  895. #define SUBLANG_SPANISH_PERU             0x0a    // Spanish (Peru)
  896. #define SUBLANG_SPANISH_ARGENTINA        0x0b    // Spanish (Argentina)
  897. #define SUBLANG_SPANISH_ECUADOR          0x0c    // Spanish (Ecuador)
  898. #define SUBLANG_SPANISH_CHILE            0x0d    // Spanish (Chile)
  899. #define SUBLANG_SPANISH_URUGUAY          0x0e    // Spanish (Uruguay)
  900. #define SUBLANG_SPANISH_PARAGUAY         0x0f    // Spanish (Paraguay)
  901. #define SUBLANG_SPANISH_BOLIVIA          0x10    // Spanish (Bolivia)
  902. #define SUBLANG_SPANISH_EL_SALVADOR      0x11    // Spanish (El Salvador)
  903. #define SUBLANG_SPANISH_HONDURAS         0x12    // Spanish (Honduras)
  904. #define SUBLANG_SPANISH_NICARAGUA        0x13    // Spanish (Nicaragua)
  905. #define SUBLANG_SPANISH_PUERTO_RICO      0x14    // Spanish (Puerto Rico)
  906. #define SUBLANG_SWEDISH                  0x01    // Swedish
  907. #define SUBLANG_SWEDISH_FINLAND          0x02    // Swedish (Finland)
  908. #define SUBLANG_URDU_PAKISTAN            0x01    // Urdu (Pakistan)
  909. #define SUBLANG_URDU_INDIA               0x02    // Urdu (India)
  910. #define SUBLANG_UZBEK_LATIN              0x01    // Uzbek (Latin)
  911. #define SUBLANG_UZBEK_CYRILLIC           0x02    // Uzbek (Cyrillic)
  912. //
  913. //  Sorting IDs.
  914. //
  915. #define SORT_DEFAULT                     0x0     // sorting default
  916. #define SORT_JAPANESE_XJIS               0x0     // Japanese XJIS order
  917. #define SORT_JAPANESE_UNICODE            0x1     // Japanese Unicode order
  918. #define SORT_CHINESE_BIG5                0x0     // Chinese BIG5 order
  919. #define SORT_CHINESE_PRCP                0x0     // PRC Chinese Phonetic order
  920. #define SORT_CHINESE_UNICODE             0x1     // Chinese Unicode order
  921. #define SORT_CHINESE_PRC                 0x2     // PRC Chinese Stroke Count order
  922. #define SORT_CHINESE_BOPOMOFO            0x3     // Traditional Chinese Bopomofo order
  923. #define SORT_KOREAN_KSC                  0x0     // Korean KSC order
  924. #define SORT_KOREAN_UNICODE              0x1     // Korean Unicode order
  925. #define SORT_GERMAN_PHONE_BOOK           0x1     // German Phone Book order
  926. #define SORT_HUNGARIAN_DEFAULT           0x0     // Hungarian Default order
  927. #define SORT_HUNGARIAN_TECHNICAL         0x1     // Hungarian Technical order
  928. #define SORT_GEORGIAN_TRADITIONAL        0x0     // Georgian Traditional order
  929. #define SORT_GEORGIAN_MODERN             0x1     // Georgian Modern order
  930. // end_r_winnt
  931. //
  932. //  A language ID is a 16 bit value which is the combination of a
  933. //  primary language ID and a secondary language ID.  The bits are
  934. //  allocated as follows:
  935. //
  936. //       +-----------------------+-------------------------+
  937. //       |     Sublanguage ID    |   Primary Language ID   |
  938. //       +-----------------------+-------------------------+
  939. //        15                   10 9                       0   bit
  940. //
  941. //
  942. //  Language ID creation/extraction macros:
  943. //
  944. //    MAKELANGID    - construct language id from a primary language id and
  945. //                    a sublanguage id.
  946. //    PRIMARYLANGID - extract primary language id from a language id.
  947. //    SUBLANGID     - extract sublanguage id from a language id.
  948. //
  949. #define MAKELANGID(p, s)       ((((WORD  )(s)) << 10) | (WORD  )(p))
  950. #define PRIMARYLANGID(lgid)    ((WORD  )(lgid) & 0x3ff)
  951. #define SUBLANGID(lgid)        ((WORD  )(lgid) >> 10)
  952. //
  953. //  A locale ID is a 32 bit value which is the combination of a
  954. //  language ID, a sort ID, and a reserved area.  The bits are
  955. //  allocated as follows:
  956. //
  957. //       +-------------+---------+-------------------------+
  958. //       |   Reserved  | Sort ID |      Language ID        |
  959. //       +-------------+---------+-------------------------+
  960. //        31         20 19     16 15                      0   bit
  961. //
  962. //
  963. //  Locale ID creation/extraction macros:
  964. //
  965. //    MAKELCID            - construct the locale id from a language id and a sort id.
  966. //    MAKESORTLCID        - construct the locale id from a language id, sort id, and sort version.
  967. //    LANGIDFROMLCID      - extract the language id from a locale id.
  968. //    SORTIDFROMLCID      - extract the sort id from a locale id.
  969. //    SORTVERSIONFROMLCID - extract the sort version from a locale id.
  970. //
  971. #define NLS_VALID_LOCALE_MASK  0x000fffff
  972. #define MAKELCID(lgid, srtid)  ((DWORD)((((DWORD)((WORD  )(srtid))) << 16) |  
  973.                                          ((DWORD)((WORD  )(lgid)))))
  974. #define MAKESORTLCID(lgid, srtid, ver)                                            
  975.                                ((DWORD)((MAKELCID(lgid, srtid)) |             
  976.                                     (((DWORD)((WORD  )(ver))) << 20)))
  977. #define LANGIDFROMLCID(lcid)   ((WORD  )(lcid))
  978. #define SORTIDFROMLCID(lcid)   ((WORD  )((((DWORD)(lcid)) >> 16) & 0xf))
  979. #define SORTVERSIONFROMLCID(lcid)  ((WORD  )((((DWORD)(lcid)) >> 20) & 0xf))
  980. //
  981. //  Default System and User IDs for language and locale.
  982. //
  983. #define LANG_SYSTEM_DEFAULT    (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
  984. #define LANG_USER_DEFAULT      (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
  985. #define LOCALE_SYSTEM_DEFAULT  (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
  986. #define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT))
  987. #define LOCALE_NEUTRAL                                                        
  988.           (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT))
  989. #define LOCALE_INVARIANT                                                      
  990.           (MAKELCID(MAKELANGID(LANG_INVARIANT, SUBLANG_NEUTRAL), SORT_DEFAULT))
  991. // begin_ntminiport begin_ntndis begin_ntminitape
  992. //
  993. // Macros used to eliminate compiler warning generated when formal
  994. // parameters or local variables are not declared.
  995. //
  996. // Use DBG_UNREFERENCED_PARAMETER() when a parameter is not yet
  997. // referenced but will be once the module is completely developed.
  998. //
  999. // Use DBG_UNREFERENCED_LOCAL_VARIABLE() when a local variable is not yet
  1000. // referenced but will be once the module is completely developed.
  1001. //
  1002. // Use UNREFERENCED_PARAMETER() if a parameter will never be referenced.
  1003. //
  1004. // DBG_UNREFERENCED_PARAMETER and DBG_UNREFERENCED_LOCAL_VARIABLE will
  1005. // eventually be made into a null macro to help determine whether there
  1006. // is unfinished work.
  1007. //
  1008. #if ! defined(lint)
  1009. #define UNREFERENCED_PARAMETER(P)          (P)
  1010. #define DBG_UNREFERENCED_PARAMETER(P)      (P)
  1011. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) (V)
  1012. #else // lint
  1013. // Note: lint -e530 says don't complain about uninitialized variables for
  1014. // this varible.  Error 527 has to do with unreachable code.
  1015. // -restore restores checking to the -save state
  1016. #define UNREFERENCED_PARAMETER(P)          
  1017.     /*lint -save -e527 -e530 */ 
  1018.     { 
  1019.         (P) = (P); 
  1020.     } 
  1021.     /*lint -restore */
  1022. #define DBG_UNREFERENCED_PARAMETER(P)      
  1023.     /*lint -save -e527 -e530 */ 
  1024.     { 
  1025.         (P) = (P); 
  1026.     } 
  1027.     /*lint -restore */
  1028. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) 
  1029.     /*lint -save -e527 -e530 */ 
  1030.     { 
  1031.         (V) = (V); 
  1032.     } 
  1033.     /*lint -restore */
  1034. #endif // lint
  1035. //
  1036. // Macro used to eliminate compiler warning 4715 within a switch statement
  1037. // when all possible cases have already been accounted for.
  1038. //
  1039. // switch (a & 3) {
  1040. //     case 0: return 1;
  1041. //     case 1: return Foo();
  1042. //     case 2: return Bar();
  1043. //     case 3: return 1;
  1044. //     DEFAULT_UNREACHABLE;
  1045. //
  1046. #if (_MSC_VER > 1200)
  1047. #define DEFAULT_UNREACHABLE default: __assume(0)
  1048. #else
  1049. //
  1050. // Older compilers do not support __assume(), and there is no other free
  1051. // method of eliminating the warning.
  1052. //
  1053. #define DEFAULT_UNREACHABLE
  1054. #endif
  1055. #ifndef WIN32_NO_STATUS 
  1056. /*lint -save -e767 */  
  1057. #define STATUS_WAIT_0                    ((DWORD   )0x00000000L)    
  1058. #define STATUS_ABANDONED_WAIT_0          ((DWORD   )0x00000080L)    
  1059. #define STATUS_USER_APC                  ((DWORD   )0x000000C0L)    
  1060. #define STATUS_TIMEOUT                   ((DWORD   )0x00000102L)    
  1061. #define STATUS_PENDING                   ((DWORD   )0x00000103L)    
  1062. #define DBG_EXCEPTION_HANDLED            ((DWORD   )0x00010001L)    
  1063. #define DBG_CONTINUE                     ((DWORD   )0x00010002L)    
  1064. #define STATUS_SEGMENT_NOTIFICATION      ((DWORD   )0x40000005L)    
  1065. #define DBG_TERMINATE_THREAD             ((DWORD   )0x40010003L)    
  1066. #define DBG_TERMINATE_PROCESS            ((DWORD   )0x40010004L)    
  1067. #define DBG_CONTROL_C                    ((DWORD   )0x40010005L)    
  1068. #define DBG_CONTROL_BREAK                ((DWORD   )0x40010008L)    
  1069. #define STATUS_GUARD_PAGE_VIOLATION      ((DWORD   )0x80000001L)    
  1070. #define STATUS_DATATYPE_MISALIGNMENT     ((DWORD   )0x80000002L)    
  1071. #define STATUS_BREAKPOINT                ((DWORD   )0x80000003L)    
  1072. #define STATUS_SINGLE_STEP               ((DWORD   )0x80000004L)    
  1073. #define DBG_EXCEPTION_NOT_HANDLED        ((DWORD   )0x80010001L)    
  1074. #define STATUS_ACCESS_VIOLATION          ((DWORD   )0xC0000005L)    
  1075. #define STATUS_IN_PAGE_ERROR             ((DWORD   )0xC0000006L)    
  1076. #define STATUS_INVALID_HANDLE            ((DWORD   )0xC0000008L)    
  1077. #define STATUS_NO_MEMORY                 ((DWORD   )0xC0000017L)    
  1078. #define STATUS_ILLEGAL_INSTRUCTION       ((DWORD   )0xC000001DL)    
  1079. #define STATUS_NONCONTINUABLE_EXCEPTION  ((DWORD   )0xC0000025L)    
  1080. #define STATUS_INVALID_DISPOSITION       ((DWORD   )0xC0000026L)    
  1081. #define STATUS_ARRAY_BOUNDS_EXCEEDED     ((DWORD   )0xC000008CL)    
  1082. #define STATUS_FLOAT_DENORMAL_OPERAND    ((DWORD   )0xC000008DL)    
  1083. #define STATUS_FLOAT_DIVIDE_BY_ZERO      ((DWORD   )0xC000008EL)    
  1084. #define STATUS_FLOAT_INEXACT_RESULT      ((DWORD   )0xC000008FL)    
  1085. #define STATUS_FLOAT_INVALID_OPERATION   ((DWORD   )0xC0000090L)    
  1086. #define STATUS_FLOAT_OVERFLOW            ((DWORD   )0xC0000091L)    
  1087. #define STATUS_FLOAT_STACK_CHECK         ((DWORD   )0xC0000092L)    
  1088. #define STATUS_FLOAT_UNDERFLOW           ((DWORD   )0xC0000093L)    
  1089. #define STATUS_INTEGER_DIVIDE_BY_ZERO    ((DWORD   )0xC0000094L)    
  1090. #define STATUS_INTEGER_OVERFLOW          ((DWORD   )0xC0000095L)    
  1091. #define STATUS_PRIVILEGED_INSTRUCTION    ((DWORD   )0xC0000096L)    
  1092. #define STATUS_STACK_OVERFLOW            ((DWORD   )0xC00000FDL)    
  1093. #define STATUS_CONTROL_C_EXIT            ((DWORD   )0xC000013AL)    
  1094. #define STATUS_FLOAT_MULTIPLE_FAULTS     ((DWORD   )0xC00002B4L)    
  1095. #define STATUS_FLOAT_MULTIPLE_TRAPS      ((DWORD   )0xC00002B5L)    
  1096. #define STATUS_REG_NAT_CONSUMPTION       ((DWORD   )0xC00002C9L)    
  1097. #if defined(STATUS_SUCCESS) || (_WIN32_WINNT > 0x0500) || (_WIN32_FUSION >= 0x0100) 
  1098. #define STATUS_SXS_EARLY_DEACTIVATION    ((DWORD   )0xC015000FL)    
  1099. #define STATUS_SXS_INVALID_DEACTIVATION  ((DWORD   )0xC0150010L)    
  1100. #endif 
  1101. /*lint -restore */  
  1102. #endif 
  1103. #define MAXIMUM_WAIT_OBJECTS 64     // Maximum number of wait objects
  1104. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  1105. typedef ULONG_PTR KSPIN_LOCK;
  1106. typedef KSPIN_LOCK *PKSPIN_LOCK;
  1107. #if defined(_AMD64_)
  1108. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  1109. //
  1110. // Define function to get the caller's EFLAGs value.
  1111. //
  1112. #define GetCallersEflags() __getcallerseflags()
  1113. unsigned __int32
  1114. __getcallerseflags (
  1115.     VOID
  1116.     );
  1117. #pragma intrinsic(__getcallerseflags)
  1118. //
  1119. // Define function to read the value of the time stamp counter
  1120. //
  1121. #define ReadTimeStampCounter() __rdtsc()
  1122. DWORD64
  1123. __rdtsc (
  1124.     VOID
  1125.     );
  1126. #pragma intrinsic(__rdtsc)
  1127. //
  1128. // Define functions to move strings or bytes, words, dwords, and qwords.
  1129. //
  1130. VOID
  1131. __movsb (
  1132.     IN PBYTE  Destination,
  1133.     IN PBYTE  Source,
  1134.     IN DWORD Count
  1135.     );
  1136. VOID
  1137. __movsw (
  1138.     IN PWORD   Destination,
  1139.     IN PWORD   Source,
  1140.     IN DWORD Count
  1141.     );
  1142. VOID
  1143. __movsd (
  1144.     IN PDWORD Destination,
  1145.     IN PDWORD Source,
  1146.     IN DWORD Count
  1147.     );
  1148. VOID
  1149. __movsq (
  1150.     IN PULONGLONG Destination,
  1151.     IN PULONGLONG Source,
  1152.     IN DWORD Count
  1153.     );
  1154. #pragma intrinsic(__movsb)
  1155. #pragma intrinsic(__movsw)
  1156. #pragma intrinsic(__movsd)
  1157. #pragma intrinsic(__movsq)
  1158. //
  1159. // Define functions to capture the high 64-bits of a 128-bit multiply.
  1160. //
  1161. #define MultiplyHigh __mulh
  1162. #define UnsignedMultiplyHigh __umulh
  1163. LONGLONG
  1164. MultiplyHigh (
  1165.     IN LONGLONG Multiplier,
  1166.     IN LONGLONG Multiplicand
  1167.     );
  1168. ULONGLONG
  1169. UnsignedMultiplyHigh (
  1170.     IN ULONGLONG Multiplier,
  1171.     IN ULONGLONG Multiplicand
  1172.     );
  1173. #pragma intrinsic(__mulh)
  1174. #pragma intrinsic(__umulh)
  1175. //
  1176. // Define functions to read and write the uer TEB and the system PCR/PRCB.
  1177. //
  1178. BYTE 
  1179. __readgsbyte (
  1180.     IN DWORD Offset
  1181.     );
  1182. WORD  
  1183. __readgsword (
  1184.     IN DWORD Offset
  1185.     );
  1186. DWORD
  1187. __readgsdword (
  1188.     IN DWORD Offset
  1189.     );
  1190. DWORD64
  1191. __readgsqword (
  1192.     IN DWORD Offset
  1193.     );
  1194. VOID
  1195. __writegsbyte (
  1196.     IN DWORD Offset,
  1197.     IN BYTE  Data
  1198.     );
  1199. VOID
  1200. __writegsword (
  1201.     IN DWORD Offset,
  1202.     IN WORD   Data
  1203.     );
  1204. VOID
  1205. __writegsdword (
  1206.     IN DWORD Offset,
  1207.     IN DWORD Data
  1208.     );
  1209. VOID
  1210. __writegsqword (
  1211.     IN DWORD Offset,
  1212.     IN DWORD64 Data
  1213.     );
  1214. #pragma intrinsic(__readgsbyte)
  1215. #pragma intrinsic(__readgsword)
  1216. #pragma intrinsic(__readgsdword)
  1217. #pragma intrinsic(__readgsqword)
  1218. #pragma intrinsic(__writegsbyte)
  1219. #pragma intrinsic(__writegsword)
  1220. #pragma intrinsic(__writegsdword)
  1221. #pragma intrinsic(__writegsqword)
  1222. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  1223. //
  1224. // The following flags control the contents of the CONTEXT structure.
  1225. //
  1226. #if !defined(RC_INVOKED)
  1227. #define CONTEXT_AMD64   0x100000
  1228. // end_wx86
  1229. #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
  1230. #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
  1231. #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
  1232. #define CONTEXT_FLOATING_POINT  (CONTEXT_AMD64 | 0x8L)
  1233. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
  1234. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  1235. // begin_wx86
  1236. #endif // !defined(RC_INVOKED)
  1237. //
  1238. // Define 128-bit 16-byte aligned xmm register type.
  1239. //
  1240. typedef struct DECLSPEC_ALIGN(16) _M128 {
  1241.     ULONGLONG Low;
  1242.     LONGLONG High;
  1243. } M128, *PM128;
  1244. //
  1245. // Format of data for fnsave/frstor instructions.
  1246. //
  1247. // This structure is used to store the legacy floating point state.
  1248. //
  1249. typedef struct _LEGACY_SAVE_AREA {
  1250.     WORD   ControlWord;
  1251.     WORD   Reserved0;
  1252.     WORD   StatusWord;
  1253.     WORD   Reserved1;
  1254.     WORD   TagWord;
  1255.     WORD   Reserved2;
  1256.     DWORD ErrorOffset;
  1257.     WORD   ErrorSelector;
  1258.     WORD   ErrorOpcode;
  1259.     DWORD DataOffset;
  1260.     WORD   DataSelector;
  1261.     WORD   Reserved3;
  1262.     BYTE  FloatRegisters[8 * 10];
  1263. } LEGACY_SAVE_AREA, *PLEGACY_SAVE_AREA;
  1264. #define LEGACY_SAVE_AREA_LENGTH  ((sizeof(LEGACY_SAVE_AREA) + 15) & ~15)
  1265. //
  1266. // Context Frame
  1267. //
  1268. //  This frame has a several purposes: 1) it is used as an argument to
  1269. //  NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1270. //  and 3) it is used in the user level thread creation routines.
  1271. //
  1272. //
  1273. // The flags field within this record controls the contents of a CONTEXT
  1274. // record.
  1275. //
  1276. // If the context record is used as an input parameter, then for each
  1277. // portion of the context record controlled by a flag whose value is
  1278. // set, it is assumed that that portion of the context record contains
  1279. // valid context. If the context record is being used to modify a threads
  1280. // context, then only that portion of the threads context is modified.
  1281. //
  1282. // If the context record is used as an output parameter to capture the
  1283. // context of a thread, then only those portions of the thread's context
  1284. // corresponding to set flags will be returned.
  1285. //
  1286. // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
  1287. //
  1288. // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
  1289. //
  1290. // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
  1291. //
  1292. // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
  1293. //
  1294. // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
  1295. //     Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
  1296. //
  1297. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
  1298.     //
  1299.     // Register parameter home addresses.
  1300.     //
  1301.     DWORD64 P1Home;
  1302.     DWORD64 P2Home;
  1303.     DWORD64 P3Home;
  1304.     DWORD64 P4Home;
  1305.     DWORD64 P5Home;
  1306.     DWORD64 P6Home;
  1307.     //
  1308.     // Control flags.
  1309.     //
  1310.     DWORD ContextFlags;
  1311.     DWORD MxCsr;
  1312.     //
  1313.     // Segment Registers and processor flags.
  1314.     //
  1315.     WORD   SegCs;
  1316.     WORD   SegDs;
  1317.     WORD   SegEs;
  1318.     WORD   SegFs;
  1319.     WORD   SegGs;
  1320.     WORD   SegSs;
  1321.     DWORD EFlags;
  1322.     //
  1323.     // Debug registers
  1324.     //
  1325.     DWORD64 Dr0;
  1326.     DWORD64 Dr1;
  1327.     DWORD64 Dr2;
  1328.     DWORD64 Dr3;
  1329.     DWORD64 Dr6;
  1330.     DWORD64 Dr7;
  1331.     //
  1332.     // Integer registers.
  1333.     //
  1334.     DWORD64 Rax;
  1335.     DWORD64 Rcx;
  1336.     DWORD64 Rdx;
  1337.     DWORD64 Rbx;
  1338.     DWORD64 Rsp;
  1339.     DWORD64 Rbp;
  1340.     DWORD64 Rsi;
  1341.     DWORD64 Rdi;
  1342.     DWORD64 R8;
  1343.     DWORD64 R9;
  1344.     DWORD64 R10;
  1345.     DWORD64 R11;
  1346.     DWORD64 R12;
  1347.     DWORD64 R13;
  1348.     DWORD64 R14;
  1349.     DWORD64 R15;
  1350.     //
  1351.     // Program counter.
  1352.     //
  1353.     DWORD64 Rip;
  1354.     //
  1355.     // MMX/floating point state.
  1356.     //
  1357.     M128 Xmm0;
  1358.     M128 Xmm1;
  1359.     M128 Xmm2;
  1360.     M128 Xmm3;
  1361.     M128 Xmm4;
  1362.     M128 Xmm5;
  1363.     M128 Xmm6;
  1364.     M128 Xmm7;
  1365.     M128 Xmm8;
  1366.     M128 Xmm9;
  1367.     M128 Xmm10;
  1368.     M128 Xmm11;
  1369.     M128 Xmm12;
  1370.     M128 Xmm13;
  1371.     M128 Xmm14;
  1372.     M128 Xmm15;
  1373.     //
  1374.     // Legacy floating point state.
  1375.     //
  1376.     LEGACY_SAVE_AREA FltSave;
  1377.     DWORD Fill;
  1378. } CONTEXT, *PCONTEXT;
  1379. #endif // _AMD64_
  1380. //
  1381. // Define function to return the current Thread Environment Block
  1382. //
  1383. #ifdef _ALPHA_                          // winnt
  1384. void *_rdteb(void);                     // winnt
  1385. #if defined(_M_ALPHA)                   // winnt
  1386. #pragma intrinsic(_rdteb)               // winnt
  1387. #endif                                  // winnt
  1388. #endif                                  // winnt
  1389. #if defined(_M_ALPHA)
  1390. #define NtCurrentTeb() ((struct _TEB *)_rdteb())
  1391. #else
  1392. struct _TEB *
  1393. NtCurrentTeb(void);
  1394. #endif
  1395. //
  1396. // Define functions to get the address of the current fiber and the
  1397. // current fiber data.
  1398. //
  1399. #ifdef _ALPHA_
  1400. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  1401. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  1402. // begin_ntddk begin_nthal
  1403. //
  1404. // The following flags control the contents of the CONTEXT structure.
  1405. //
  1406. #if !defined(RC_INVOKED)
  1407. #define CONTEXT_ALPHA              0x00020000
  1408. #define CONTEXT_CONTROL         (CONTEXT_ALPHA | 0x00000001L)
  1409. #define CONTEXT_FLOATING_POINT  (CONTEXT_ALPHA | 0x00000002L)
  1410. #define CONTEXT_INTEGER         (CONTEXT_ALPHA | 0x00000004L)
  1411. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  1412. #endif
  1413. #ifndef _PORTABLE_32BIT_CONTEXT
  1414. //
  1415. // Context Frame
  1416. //
  1417. //  This frame has a several purposes: 1) it is used as an argument to
  1418. //  NtContinue, 2) it is used to construct a call frame for APC delivery,
  1419. //  3) it is used to construct a call frame for exception dispatching
  1420. //  in user mode, 4) it is used in the user level thread creation
  1421. //  routines, and 5) it is used to to pass thread state to debuggers.
  1422. //
  1423. //  N.B. Because this record is used as a call frame, it must be EXACTLY
  1424. //  a multiple of 16 bytes in length.
  1425. //
  1426. //  There are two variations of the context structure. This is the real one.
  1427. //
  1428. typedef struct _CONTEXT {
  1429.     //
  1430.     // This section is specified/returned if the ContextFlags word contains
  1431.     // the flag CONTEXT_FLOATING_POINT.
  1432.     //
  1433.     ULONGLONG FltF0;
  1434.     ULONGLONG FltF1;
  1435.     ULONGLONG FltF2;
  1436.     ULONGLONG FltF3;
  1437.     ULONGLONG FltF4;
  1438.     ULONGLONG FltF5;
  1439.     ULONGLONG FltF6;
  1440.     ULONGLONG FltF7;
  1441.     ULONGLONG FltF8;
  1442.     ULONGLONG FltF9;
  1443.     ULONGLONG FltF10;
  1444.     ULONGLONG FltF11;
  1445.     ULONGLONG FltF12;
  1446.     ULONGLONG FltF13;
  1447.     ULONGLONG FltF14;
  1448.     ULONGLONG FltF15;
  1449.     ULONGLONG FltF16;
  1450.     ULONGLONG FltF17;
  1451.     ULONGLONG FltF18;
  1452.     ULONGLONG FltF19;
  1453.     ULONGLONG FltF20;
  1454.     ULONGLONG FltF21;
  1455.     ULONGLONG FltF22;
  1456.     ULONGLONG FltF23;
  1457.     ULONGLONG FltF24;
  1458.     ULONGLONG FltF25;
  1459.     ULONGLONG FltF26;
  1460.     ULONGLONG FltF27;
  1461.     ULONGLONG FltF28;
  1462.     ULONGLONG FltF29;
  1463.     ULONGLONG FltF30;
  1464.     ULONGLONG FltF31;
  1465.     //
  1466.     // This section is specified/returned if the ContextFlags word contains
  1467.     // the flag CONTEXT_INTEGER.
  1468.     //
  1469.     // N.B. The registers gp, sp, and ra are defined in this section, but are
  1470.     //  considered part of the control context rather than part of the integer
  1471.     //  context.
  1472.     //
  1473.     ULONGLONG IntV0;    //  $0: return value register, v0
  1474.     ULONGLONG IntT0;    //  $1: temporary registers, t0 - t7
  1475.     ULONGLONG IntT1;    //  $2:
  1476.     ULONGLONG IntT2;    //  $3:
  1477.     ULONGLONG IntT3;    //  $4:
  1478.     ULONGLONG IntT4;    //  $5:
  1479.     ULONGLONG IntT5;    //  $6:
  1480.     ULONGLONG IntT6;    //  $7:
  1481.     ULONGLONG IntT7;    //  $8:
  1482.     ULONGLONG IntS0;    //  $9: nonvolatile registers, s0 - s5
  1483.     ULONGLONG IntS1;    // $10:
  1484.     ULONGLONG IntS2;    // $11:
  1485.     ULONGLONG IntS3;    // $12:
  1486.     ULONGLONG IntS4;    // $13:
  1487.     ULONGLONG IntS5;    // $14:
  1488.     ULONGLONG IntFp;    // $15: frame pointer register, fp/s6
  1489.     ULONGLONG IntA0;    // $16: argument registers, a0 - a5
  1490.     ULONGLONG IntA1;    // $17:
  1491.     ULONGLONG IntA2;    // $18:
  1492.     ULONGLONG IntA3;    // $19:
  1493.     ULONGLONG IntA4;    // $20:
  1494.     ULONGLONG IntA5;    // $21:
  1495.     ULONGLONG IntT8;    // $22: temporary registers, t8 - t11
  1496.     ULONGLONG IntT9;    // $23:
  1497.     ULONGLONG IntT10;   // $24:
  1498.     ULONGLONG IntT11;   // $25:
  1499.     ULONGLONG IntRa;    // $26: return address register, ra
  1500.     ULONGLONG IntT12;   // $27: temporary register, t12
  1501.     ULONGLONG IntAt;    // $28: assembler temp register, at
  1502.     ULONGLONG IntGp;    // $29: global pointer register, gp
  1503.     ULONGLONG IntSp;    // $30: stack pointer register, sp
  1504.     ULONGLONG IntZero;  // $31: zero register, zero
  1505.     //
  1506.     // This section is specified/returned if the ContextFlags word contains
  1507.     // the flag CONTEXT_FLOATING_POINT.
  1508.     //
  1509.     ULONGLONG Fpcr;     // floating point control register
  1510.     ULONGLONG SoftFpcr; // software extension to FPCR
  1511.     //
  1512.     // This section is specified/returned if the ContextFlags word contains
  1513.     // the flag CONTEXT_CONTROL.
  1514.     //
  1515.     // N.B. The registers gp, sp, and ra are defined in the integer section,
  1516.     //   but are considered part of the control context rather than part of
  1517.     //   the integer context.
  1518.     //
  1519.     ULONGLONG Fir;      // (fault instruction) continuation address
  1520.     DWORD Psr;          // processor status
  1521.     //
  1522.     // The flags values within this flag control the contents of
  1523.     // a CONTEXT record.
  1524.     //
  1525.     // If the context record is used as an input parameter, then
  1526.     // for each portion of the context record controlled by a flag
  1527.     // whose value is set, it is assumed that that portion of the
  1528.     // context record contains valid context. If the context record
  1529.     // is being used to modify a thread's context, then only that
  1530.     // portion of the threads context will be modified.
  1531.     //
  1532.     // If the context record is used as an IN OUT parameter to capture
  1533.     // the context of a thread, then only those portions of the thread's
  1534.     // context corresponding to set flags will be returned.
  1535.     //
  1536.     // The context record is never used as an OUT only parameter.
  1537.     //
  1538.     DWORD ContextFlags;
  1539.     DWORD Fill[4];      // padding for 16-byte stack frame alignment
  1540. } CONTEXT, *PCONTEXT;
  1541. #else
  1542. #error _PORTABLE_32BIT_CONTEXT no longer supported on Alpha.
  1543. #endif // _PORTABLE_32BIT_CONTEXT
  1544. // end_ntddk end_nthal
  1545. #endif // _ALPHA_
  1546. #ifdef _ALPHA_
  1547. VOID
  1548. __jump_unwind (
  1549.     PVOID VirtualFramePointer,
  1550.     PVOID TargetPc
  1551.     );
  1552. #endif // _ALPHA_
  1553. #ifdef _X86_
  1554. //
  1555. // Disable these two pragmas that evaluate to "sti" "cli" on x86 so that driver
  1556. // writers to not leave them inadvertantly in their code.
  1557. //
  1558. #if !defined(MIDL_PASS)
  1559. #if !defined(RC_INVOKED)
  1560. #if _MSC_VER >= 1200
  1561. #pragma warning(push)
  1562. #endif
  1563. #pragma warning(disable:4164)   // disable C4164 warning so that apps that
  1564.                                 // build with /Od don't get weird errors !
  1565. #ifdef _M_IX86
  1566. #pragma function(_enable)
  1567. #pragma function(_disable)
  1568. #endif
  1569. #if _MSC_VER >= 1200
  1570. #pragma warning(pop)
  1571. #else
  1572. #pragma warning(default:4164)   // reenable C4164 warning
  1573. #endif
  1574. #endif
  1575. #endif
  1576. #if !defined(MIDL_PASS) && defined(_M_IX86)
  1577. #if _MSC_VER >= 1200
  1578. #pragma warning(push)
  1579. #endif
  1580. #pragma warning (disable:4035)        // disable 4035 (function must return something)
  1581. _inline PVOID GetFiberData( void ) { __asm {
  1582.                                         mov eax, fs:[0x10]
  1583.                                         mov eax,[eax]
  1584.                                         }
  1585.                                      }
  1586. _inline PVOID GetCurrentFiber( void ) { __asm mov eax, fs:[0x10] }
  1587. #if _MSC_VER >= 1200
  1588. #pragma warning(pop)
  1589. #else
  1590. #pragma warning (default:4035)        // Reenable it
  1591. #endif
  1592. #endif
  1593. // begin_ntddk begin_wx86
  1594. //
  1595. //  Define the size of the 80387 save area, which is in the context frame.
  1596. //
  1597. #define SIZE_OF_80387_REGISTERS      80
  1598. //
  1599. // The following flags control the contents of the CONTEXT structure.
  1600. //
  1601. #if !defined(RC_INVOKED)
  1602. #define CONTEXT_i386    0x00010000    // this assumes that i386 and
  1603. #define CONTEXT_i486    0x00010000    // i486 have identical context records
  1604. // end_wx86
  1605. #define CONTEXT_CONTROL         (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  1606. #define CONTEXT_INTEGER         (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  1607. #define CONTEXT_SEGMENTS        (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  1608. #define CONTEXT_FLOATING_POINT  (CONTEXT_i386 | 0x00000008L) // 387 state
  1609. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  1610. #define CONTEXT_EXTENDED_REGISTERS  (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
  1611. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |
  1612.                       CONTEXT_SEGMENTS)
  1613. // begin_wx86
  1614. #endif
  1615. #define MAXIMUM_SUPPORTED_EXTENSION     512
  1616. typedef struct _FLOATING_SAVE_AREA {
  1617.     DWORD   ControlWord;
  1618.     DWORD   StatusWord;
  1619.     DWORD   TagWord;
  1620.     DWORD   ErrorOffset;
  1621.     DWORD   ErrorSelector;
  1622.     DWORD   DataOffset;
  1623.     DWORD   DataSelector;
  1624.     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
  1625.     DWORD   Cr0NpxState;
  1626. } FLOATING_SAVE_AREA;
  1627. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  1628. //
  1629. // Context Frame
  1630. //
  1631. //  This frame has a several purposes: 1) it is used as an argument to
  1632. //  NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1633. //  and 3) it is used in the user level thread creation routines.
  1634. //
  1635. //  The layout of the record conforms to a standard call frame.
  1636. //
  1637. typedef struct _CONTEXT {
  1638.     //
  1639.     // The flags values within this flag control the contents of
  1640.     // a CONTEXT record.
  1641.     //
  1642.     // If the context record is used as an input parameter, then
  1643.     // for each portion of the context record controlled by a flag
  1644.     // whose value is set, it is assumed that that portion of the
  1645.     // context record contains valid context. If the context record
  1646.     // is being used to modify a threads context, then only that
  1647.     // portion of the threads context will be modified.
  1648.     //
  1649.     // If the context record is used as an IN OUT parameter to capture
  1650.     // the context of a thread, then only those portions of the thread's
  1651.     // context corresponding to set flags will be returned.
  1652.     //
  1653.     // The context record is never used as an OUT only parameter.
  1654.     //
  1655.     DWORD ContextFlags;
  1656.     //
  1657.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  1658.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  1659.     // included in CONTEXT_FULL.
  1660.     //
  1661.     DWORD   Dr0;
  1662.     DWORD   Dr1;
  1663.     DWORD   Dr2;
  1664.     DWORD   Dr3;
  1665.     DWORD   Dr6;
  1666.     DWORD   Dr7;
  1667.     //
  1668.     // This section is specified/returned if the
  1669.     // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  1670.     //
  1671.     FLOATING_SAVE_AREA FloatSave;
  1672.     //
  1673.     // This section is specified/returned if the
  1674.     // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  1675.     //
  1676.     DWORD   SegGs;
  1677.     DWORD   SegFs;
  1678.     DWORD   SegEs;
  1679.     DWORD   SegDs;
  1680.     //
  1681.     // This section is specified/returned if the
  1682.     // ContextFlags word contians the flag CONTEXT_INTEGER.
  1683.     //
  1684.     DWORD   Edi;
  1685.     DWORD   Esi;
  1686.     DWORD   Ebx;
  1687.     DWORD   Edx;
  1688.     DWORD   Ecx;
  1689.     DWORD   Eax;
  1690.     //
  1691.     // This section is specified/returned if the
  1692.     // ContextFlags word contians the flag CONTEXT_CONTROL.
  1693.     //
  1694.     DWORD   Ebp;
  1695.     DWORD   Eip;
  1696.     DWORD   SegCs;              // MUST BE SANITIZED
  1697.     DWORD   EFlags;             // MUST BE SANITIZED
  1698.     DWORD   Esp;
  1699.     DWORD   SegSs;
  1700.     //
  1701.     // This section is specified/returned if the ContextFlags word
  1702.     // contains the flag CONTEXT_EXTENDED_REGISTERS.
  1703.     // The format and contexts are processor specific
  1704.     //
  1705.     BYTE    ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  1706. } CONTEXT;
  1707. typedef CONTEXT *PCONTEXT;
  1708. // begin_ntminiport
  1709. #endif //_X86_
  1710. #ifndef _LDT_ENTRY_DEFINED
  1711. #define _LDT_ENTRY_DEFINED
  1712. typedef struct _LDT_ENTRY {
  1713.     WORD    LimitLow;
  1714.     WORD    BaseLow;
  1715.     union {
  1716.         struct {
  1717.             BYTE    BaseMid;
  1718.             BYTE    Flags1;     // Declare as bytes to avoid alignment
  1719.             BYTE    Flags2;     // Problems.
  1720.             BYTE    BaseHi;
  1721.         } Bytes;
  1722.         struct {
  1723.             DWORD   BaseMid : 8;
  1724.             DWORD   Type : 5;
  1725.             DWORD   Dpl : 2;
  1726.             DWORD   Pres : 1;
  1727.             DWORD   LimitHi : 4;
  1728.             DWORD   Sys : 1;
  1729.             DWORD   Reserved_0 : 1;
  1730.             DWORD   Default_Big : 1;
  1731.             DWORD   Granularity : 1;
  1732.             DWORD   BaseHi : 8;
  1733.         } Bits;
  1734.     } HighWord;
  1735. } LDT_ENTRY, *PLDT_ENTRY;
  1736. #endif
  1737. #if defined(_MIPS_)
  1738. //
  1739. // Define functions to get the address of the current fiber and the
  1740. // current fiber data.
  1741. //
  1742. #define GetCurrentFiber() ((*(PNT_TIB *)0x7ffff4a8)->FiberData)
  1743. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  1744. // begin_ntddk begin_nthal
  1745. //
  1746. // The following flags control the contents of the CONTEXT structure.
  1747. //
  1748. #if !defined(RC_INVOKED)
  1749. #define CONTEXT_R4000   0x00010000    // r4000 context
  1750. #define CONTEXT_CONTROL          (CONTEXT_R4000 | 0x00000001)
  1751. #define CONTEXT_FLOATING_POINT   (CONTEXT_R4000 | 0x00000002)
  1752. #define CONTEXT_INTEGER          (CONTEXT_R4000 | 0x00000004)
  1753. #define CONTEXT_EXTENDED_FLOAT   (CONTEXT_FLOATING_POINT | 0x00000008)
  1754. #define CONTEXT_EXTENDED_INTEGER (CONTEXT_INTEGER | 0x00000010)
  1755. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | 
  1756.                       CONTEXT_INTEGER | CONTEXT_EXTENDED_INTEGER)
  1757. #endif
  1758. //
  1759. // Context Frame
  1760. //
  1761. //  N.B. This frame must be exactly a multiple of 16 bytes in length.
  1762. //
  1763. //  This frame has a several purposes: 1) it is used as an argument to
  1764. //  NtContinue, 2) it is used to constuct a call frame for APC delivery,
  1765. //  3) it is used to construct a call frame for exception dispatching
  1766. //  in user mode, and 4) it is used in the user level thread creation
  1767. //  routines.
  1768. //
  1769. //  The layout of the record conforms to a standard call frame.
  1770. //
  1771. typedef struct _CONTEXT {
  1772.     //
  1773.     // This section is always present and is used as an argument build
  1774.     // area.
  1775.     //
  1776.     // N.B. Context records are 0 mod 8 aligned starting with NT 4.0.
  1777.     //
  1778.     union {
  1779.         DWORD Argument[4];
  1780.         ULONGLONG Alignment;
  1781.     };
  1782.     //
  1783.     // The following union defines the 32-bit and 64-bit register context.
  1784.     //
  1785.     union {
  1786.         //
  1787.         // 32-bit context.
  1788.         //
  1789.         struct {
  1790.             //
  1791.             // This section is specified/returned if the ContextFlags contains
  1792.             // the flag CONTEXT_FLOATING_POINT.
  1793.             //
  1794.             // N.B. This section contains the 16 double floating registers f0,
  1795.             //      f2, ..., f30.
  1796.             //
  1797.             DWORD FltF0;
  1798.             DWORD FltF1;
  1799.             DWORD FltF2;
  1800.             DWORD FltF3;
  1801.             DWORD FltF4;
  1802.             DWORD FltF5;
  1803.             DWORD FltF6;
  1804.             DWORD FltF7;
  1805.             DWORD FltF8;
  1806.             DWORD FltF9;
  1807.             DWORD FltF10;
  1808.             DWORD FltF11;
  1809.             DWORD FltF12;
  1810.             DWORD FltF13;
  1811.             DWORD FltF14;
  1812.             DWORD FltF15;
  1813.             DWORD FltF16;
  1814.             DWORD FltF17;
  1815.             DWORD FltF18;
  1816.             DWORD FltF19;
  1817.             DWORD FltF20;
  1818.             DWORD FltF21;
  1819.             DWORD FltF22;
  1820.             DWORD FltF23;
  1821.             DWORD FltF24;
  1822.             DWORD FltF25;
  1823.             DWORD FltF26;
  1824.             DWORD FltF27;
  1825.             DWORD FltF28;
  1826.             DWORD FltF29;
  1827.             DWORD FltF30;
  1828.             DWORD FltF31;
  1829.             //
  1830.             // This section is specified/returned if the ContextFlags contains
  1831.             // the flag CONTEXT_INTEGER.
  1832.             //
  1833.             // N.B. The registers gp, sp, and ra are defined in this section,
  1834.             //      but are considered part of the control context rather than
  1835.             //      part of the integer context.
  1836.             //
  1837.             // N.B. Register zero is not stored in the frame.
  1838.             //
  1839.             DWORD IntZero;
  1840.             DWORD IntAt;
  1841.             DWORD IntV0;
  1842.             DWORD IntV1;
  1843.             DWORD IntA0;
  1844.             DWORD IntA1;
  1845.             DWORD IntA2;
  1846.             DWORD IntA3;
  1847.             DWORD IntT0;
  1848.             DWORD IntT1;
  1849.             DWORD IntT2;
  1850.             DWORD IntT3;
  1851.             DWORD IntT4;
  1852.             DWORD IntT5;
  1853.             DWORD IntT6;
  1854.             DWORD IntT7;
  1855.             DWORD IntS0;
  1856.             DWORD IntS1;
  1857.             DWORD IntS2;
  1858.             DWORD IntS3;
  1859.             DWORD IntS4;
  1860.             DWORD IntS5;
  1861.             DWORD IntS6;
  1862.             DWORD IntS7;
  1863.             DWORD IntT8;
  1864.             DWORD IntT9;
  1865.             DWORD IntK0;
  1866.             DWORD IntK1;
  1867.             DWORD IntGp;
  1868.             DWORD IntSp;
  1869.             DWORD IntS8;
  1870.             DWORD IntRa;
  1871.             DWORD IntLo;
  1872.             DWORD IntHi;
  1873.             //
  1874.             // This section is specified/returned if the ContextFlags word contains
  1875.             // the flag CONTEXT_FLOATING_POINT.
  1876.             //
  1877.             DWORD Fsr;
  1878.             //
  1879.             // This section is specified/returned if the ContextFlags word contains
  1880.             // the flag CONTEXT_CONTROL.
  1881.             //
  1882.             // N.B. The registers gp, sp, and ra are defined in the integer section,
  1883.             //   but are considered part of the control context rather than part of
  1884.             //   the integer context.
  1885.             //
  1886.             DWORD Fir;
  1887.             DWORD Psr;
  1888.             //
  1889.             // The flags values within this flag control the contents of
  1890.             // a CONTEXT record.
  1891.             //
  1892.             // If the context record is used as an input parameter, then
  1893.             // for each portion of the context record controlled by a flag
  1894.             // whose value is set, it is assumed that that portion of the
  1895.             // context record contains valid context. If the context record
  1896.             // is being used to modify a thread's context, then only that
  1897.             // portion of the threads context will be modified.
  1898.             //
  1899.             // If the context record is used as an IN OUT parameter to capture
  1900.             // the context of a thread, then only those portions of the thread's
  1901.             // context corresponding to set flags will be returned.
  1902.             //
  1903.             // The context record is never used as an OUT only parameter.
  1904.             //
  1905.             DWORD ContextFlags;
  1906.         };
  1907.         //
  1908.         // 64-bit context.
  1909.         //
  1910.         struct {
  1911.             //
  1912.             // This section is specified/returned if the ContextFlags contains
  1913.             // the flag CONTEXT_EXTENDED_FLOAT.
  1914.             //
  1915.             // N.B. This section contains the 32 double floating registers f0,
  1916.             //      f1, ..., f31.
  1917.             //
  1918.             ULONGLONG XFltF0;
  1919.             ULONGLONG XFltF1;
  1920.             ULONGLONG XFltF2;
  1921.             ULONGLONG XFltF3;
  1922.             ULONGLONG XFltF4;
  1923.             ULONGLONG XFltF5;
  1924.             ULONGLONG XFltF6;
  1925.             ULONGLONG XFltF7;
  1926.             ULONGLONG XFltF8;
  1927.             ULONGLONG XFltF9;
  1928.             ULONGLONG XFltF10;
  1929.             ULONGLONG XFltF11;
  1930.             ULONGLONG XFltF12;
  1931.             ULONGLONG XFltF13;
  1932.             ULONGLONG XFltF14;
  1933.             ULONGLONG XFltF15;
  1934.             ULONGLONG XFltF16;
  1935.             ULONGLONG XFltF17;
  1936.             ULONGLONG XFltF18;
  1937.             ULONGLONG XFltF19;
  1938.             ULONGLONG XFltF20;
  1939.             ULONGLONG XFltF21;
  1940.             ULONGLONG XFltF22;
  1941.             ULONGLONG XFltF23;
  1942.             ULONGLONG XFltF24;
  1943.             ULONGLONG XFltF25;
  1944.             ULONGLONG XFltF26;
  1945.             ULONGLONG XFltF27;
  1946.             ULONGLONG XFltF28;
  1947.             ULONGLONG XFltF29;
  1948.             ULONGLONG XFltF30;
  1949.             ULONGLONG XFltF31;
  1950.             //
  1951.             // The following sections must exactly overlay the 32-bit context.
  1952.             //
  1953.             DWORD Fill1;
  1954.             DWORD Fill2;
  1955.             //
  1956.             // This section is specified/returned if the ContextFlags contains
  1957.             // the flag CONTEXT_FLOATING_POINT.
  1958.             //
  1959.             DWORD XFsr;
  1960.             //
  1961.             // This section is specified/returned if the ContextFlags contains
  1962.             // the flag CONTEXT_CONTROL.
  1963.             //
  1964.             // N.B. The registers gp, sp, and ra are defined in the integer
  1965.             //      section, but are considered part of the control context
  1966.             //      rather than part of the integer context.
  1967.             //
  1968.             DWORD XFir;
  1969.             DWORD XPsr;
  1970.             //
  1971.             // The flags values within this flag control the contents of
  1972.             // a CONTEXT record.
  1973.             //
  1974.             // If the context record is used as an input parameter, then
  1975.             // for each portion of the context record controlled by a flag
  1976.             // whose value is set, it is assumed that that portion of the
  1977.             // context record contains valid context. If the context record
  1978.             // is being used to modify a thread's context, then only that
  1979.             // portion of the threads context will be modified.
  1980.             //
  1981.             // If the context record is used as an IN OUT parameter to capture
  1982.             // the context of a thread, then only those portions of the thread's
  1983.             // context corresponding to set flags will be returned.
  1984.             //
  1985.             // The context record is never used as an OUT only parameter.
  1986.             //
  1987.             DWORD XContextFlags;
  1988.             //
  1989.             // This section is specified/returned if the ContextFlags contains
  1990.             // the flag CONTEXT_EXTENDED_INTEGER.
  1991.             //
  1992.             // N.B. The registers gp, sp, and ra are defined in this section,
  1993.             //      but are considered part of the control context rather than
  1994.             //      part of the integer  context.
  1995.             //
  1996.             // N.B. Register zero is not stored in the frame.
  1997.             //
  1998.             ULONGLONG XIntZero;
  1999.             ULONGLONG XIntAt;
  2000.             ULONGLONG XIntV0;
  2001.             ULONGLONG XIntV1;
  2002.             ULONGLONG XIntA0;
  2003.             ULONGLONG XIntA1;
  2004.             ULONGLONG XIntA2;
  2005.             ULONGLONG XIntA3;
  2006.             ULONGLONG XIntT0;
  2007.             ULONGLONG XIntT1;
  2008.             ULONGLONG XIntT2;
  2009.             ULONGLONG XIntT3;
  2010.             ULONGLONG XIntT4;
  2011.             ULONGLONG XIntT5;
  2012.             ULONGLONG XIntT6;
  2013.             ULONGLONG XIntT7;
  2014.             ULONGLONG XIntS0;
  2015.             ULONGLONG XIntS1;
  2016.             ULONGLONG XIntS2;
  2017.             ULONGLONG XIntS3;
  2018.             ULONGLONG XIntS4;
  2019.             ULONGLONG XIntS5;
  2020.             ULONGLONG XIntS6;
  2021.             ULONGLONG XIntS7;
  2022.             ULONGLONG XIntT8;
  2023.             ULONGLONG XIntT9;
  2024.             ULONGLONG XIntK0;
  2025.             ULONGLONG XIntK1;
  2026.             ULONGLONG XIntGp;
  2027.             ULONGLONG XIntSp;
  2028.             ULONGLONG XIntS8;
  2029.             ULONGLONG XIntRa;
  2030.             ULONGLONG XIntLo;
  2031.             ULONGLONG XIntHi;
  2032.         };
  2033.     };
  2034. } CONTEXT, *PCONTEXT;
  2035. // end_ntddk end_nthal
  2036. #define CONTEXT32_LENGTH 0x130          // The original 32-bit Context length (pre NT 4.0)
  2037. #endif // MIPS
  2038. #if defined(_MIPS_)
  2039. VOID
  2040. __jump_unwind (
  2041.     PVOID Fp,
  2042.     PVOID TargetPc
  2043.     );
  2044. #endif // MIPS
  2045. #if defined(_PPC_)
  2046. //
  2047. // The address of the TEB is placed into GPR 13 at context switch time
  2048. // and should never be destroyed.  To get the address of the TEB use
  2049. // the compiler intrinsic to access it directly from GPR 13.
  2050. //
  2051. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  2052. unsigned __gregister_get( unsigned const regnum );
  2053. #define NtCurrentTeb() ((struct _TEB *)__gregister_get(13))
  2054. #elif defined(_M_PPC)
  2055. struct _TEB * __builtin_get_gpr13(VOID);
  2056. #define NtCurrentTeb() ((struct _TEB *)__builtin_get_gpr13())
  2057. #endif
  2058. //
  2059. // Define functions to get the address of the current fiber and the
  2060. // current fiber data.
  2061. //
  2062. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  2063. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  2064. // begin_ntddk begin_nthal
  2065. //
  2066. // The following flags control the contents of the CONTEXT structure.
  2067. //
  2068. #if !defined(RC_INVOKED)
  2069. #define CONTEXT_CONTROL         0x00000001L
  2070. #define CONTEXT_FLOATING_POINT  0x00000002L
  2071. #define CONTEXT_INTEGER         0x00000004L
  2072. #define CONTEXT_DEBUG_REGISTERS 0x00000008L
  2073. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  2074. #endif
  2075. //
  2076. // Context Frame
  2077. //
  2078. //  N.B. This frame must be exactly a multiple of 16 bytes in length.
  2079. //
  2080. //  This frame has a several purposes: 1) it is used as an argument to
  2081. //  NtContinue, 2) it is used to constuct a call frame for APC delivery,
  2082. //  3) it is used to construct a call frame for exception dispatching
  2083. //  in user mode, and 4) it is used in the user level thread creation
  2084. //  routines.
  2085. //
  2086. //  Requires at least 8-byte alignment (double)
  2087. //
  2088. typedef struct _CONTEXT {
  2089.     //
  2090.     // This section is specified/returned if the ContextFlags word contains
  2091.     // the flag CONTEXT_FLOATING_POINT.
  2092.     //
  2093.     double Fpr0;                        // Floating registers 0..31
  2094.     double Fpr1;
  2095.     double Fpr2;
  2096.     double Fpr3;
  2097.     double Fpr4;
  2098.     double Fpr5;
  2099.     double Fpr6;
  2100.     double Fpr7;
  2101.     double Fpr8;
  2102.     double Fpr9;
  2103.     double Fpr10;
  2104.     double Fpr11;
  2105.     double Fpr12;
  2106.     double Fpr13;
  2107.     double Fpr14;
  2108.     double Fpr15;
  2109.     double Fpr16;
  2110.     double Fpr17;
  2111.     double Fpr18;
  2112.     double Fpr19;
  2113.     double Fpr20;
  2114.     double Fpr21;
  2115.     double Fpr22;
  2116.     double Fpr23;
  2117.     double Fpr24;
  2118.     double Fpr25;
  2119.     double Fpr26;
  2120.     double Fpr27;
  2121.     double Fpr28;
  2122.     double Fpr29;
  2123.     double Fpr30;
  2124.     double Fpr31;
  2125.     double Fpscr;                       // Floating point status/control reg
  2126.     //
  2127.     // This section is specified/returned if the ContextFlags word contains
  2128.     // the flag CONTEXT_INTEGER.
  2129.     //
  2130.     DWORD Gpr0;                         // General registers 0..31
  2131.     DWORD Gpr1;
  2132.     DWORD Gpr2;
  2133.     DWORD Gpr3;
  2134.     DWORD Gpr4;
  2135.     DWORD Gpr5;
  2136.     DWORD Gpr6;
  2137.     DWORD Gpr7;
  2138.     DWORD Gpr8;
  2139.     DWORD Gpr9;
  2140.     DWORD Gpr10;
  2141.     DWORD Gpr11;
  2142.     DWORD Gpr12;
  2143.     DWORD Gpr13;
  2144.     DWORD Gpr14;
  2145.     DWORD Gpr15;
  2146.     DWORD Gpr16;
  2147.     DWORD Gpr17;
  2148.     DWORD Gpr18;
  2149.     DWORD Gpr19;
  2150.     DWORD Gpr20;
  2151.     DWORD Gpr21;
  2152.     DWORD Gpr22;
  2153.     DWORD Gpr23;
  2154.     DWORD Gpr24;
  2155.     DWORD Gpr25;
  2156.     DWORD Gpr26;
  2157.     DWORD Gpr27;
  2158.     DWORD Gpr28;
  2159.     DWORD Gpr29;
  2160.     DWORD Gpr30;
  2161.     DWORD Gpr31;
  2162.     DWORD Cr;                           // Condition register
  2163.     DWORD Xer;                          // Fixed point exception register
  2164.     //
  2165.     // This section is specified/returned if the ContextFlags word contains
  2166.     // the flag CONTEXT_CONTROL.
  2167.     //
  2168.     DWORD Msr;                          // Machine status register
  2169.     DWORD Iar;                          // Instruction address register
  2170.     DWORD Lr;                           // Link register
  2171.     DWORD Ctr;                          // Count register
  2172.     //
  2173.     // The flags values within this flag control the contents of
  2174.     // a CONTEXT record.
  2175.     //
  2176.     // If the context record is used as an input parameter, then
  2177.     // for each portion of the context record controlled by a flag
  2178.     // whose value is set, it is assumed that that portion of the
  2179.     // context record contains valid context. If the context record
  2180.     // is being used to modify a thread's context, then only that
  2181.     // portion of the threads context will be modified.
  2182.     //
  2183.     // If the context record is used as an IN OUT parameter to capture
  2184.     // the context of a thread, then only those portions of the thread's
  2185.     // context corresponding to set flags will be returned.
  2186.     //
  2187.     // The context record is never used as an OUT only parameter.
  2188.     //
  2189.     DWORD ContextFlags;
  2190.     DWORD Fill[3];                      // Pad out to multiple of 16 bytes
  2191.     //
  2192.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  2193.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  2194.     // included in CONTEXT_FULL.
  2195.     //
  2196.     DWORD Dr0;                          // Breakpoint Register 1
  2197.     DWORD Dr1;                          // Breakpoint Register 2
  2198.     DWORD Dr2;                          // Breakpoint Register 3
  2199.     DWORD Dr3;                          // Breakpoint Register 4
  2200.     DWORD Dr4;                          // Breakpoint Register 5
  2201.     DWORD Dr5;                          // Breakpoint Register 6
  2202.     DWORD Dr6;                          // Debug Status Register
  2203.     DWORD Dr7;                          // Debug Control Register
  2204. } CONTEXT, *PCONTEXT;
  2205. // end_ntddk end_nthal
  2206. //
  2207. // Stack frame header
  2208. //
  2209. //   Order of appearance in stack frame:
  2210. //      Header (six words)
  2211. //      Parameters (at least eight words)
  2212. //      Local variables
  2213. //      Saved GPRs
  2214. //      Saved FPRs
  2215. //
  2216. //   Minimum alignment is 8 bytes
  2217. typedef struct _STACK_FRAME_HEADER {    // GPR 1 points here
  2218.     DWORD BackChain;                    // Addr of previous frame
  2219.     DWORD GlueSaved1;                   // Used by glue code
  2220.     DWORD GlueSaved2;
  2221.     DWORD Reserved1;                    // Reserved
  2222.     DWORD Spare1;                       // Used by tracing, profiling, ...
  2223.     DWORD Spare2;
  2224.     DWORD Parameter0;                   // First 8 parameter words are
  2225.     DWORD Parameter1;                   //   always present
  2226.     DWORD Parameter2;
  2227.     DWORD Parameter3;
  2228.     DWORD Parameter4;
  2229.     DWORD Parameter5;
  2230.     DWORD Parameter6;
  2231.     DWORD Parameter7;
  2232. } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
  2233. VOID
  2234. __jump_unwind (
  2235.     PVOID Fp,
  2236.     PVOID TargetPc
  2237.     );
  2238. #endif // defined(_PPC_)
  2239. #if defined(_MPPC_)
  2240. //
  2241. // The address of the TEB is placed into GPR 13 at context switch time
  2242. // and should never be destroyed.  To get the address of the TEB use
  2243. // the compiler intrinsic to access it directly from GPR 13.
  2244. //
  2245. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  2246. unsigned __gregister_get( unsigned const regnum );
  2247. #define NtCurrentTeb() ((struct _TEB *)__gregister_get(13))
  2248. #elif defined(_M_PPC)
  2249. struct _TEB * __builtin_get_gpr13(VOID);
  2250. #define NtCurrentTeb() ((struct _TEB *)__builtin_get_gpr13())
  2251. #endif
  2252. //
  2253. // Define functions to get the address of the current fiber and the
  2254. // current fiber data.
  2255. //
  2256. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  2257. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  2258. // begin_ntddk begin_nthal
  2259. //
  2260. // The following flags control the contents of the CONTEXT structure.
  2261. //
  2262. #if !defined(RC_INVOKED)
  2263. #define CONTEXT_CONTROL         0x00000001L
  2264. #define CONTEXT_FLOATING_POINT  0x00000002L
  2265. #define CONTEXT_INTEGER         0x00000004L
  2266. #define CONTEXT_DEBUG_REGISTERS 0x00000008L
  2267. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  2268. #endif
  2269. //
  2270. // Context Frame
  2271. //
  2272. //  N.B. This frame must be exactly a multiple of 16 bytes in length.
  2273. //
  2274. //  This frame has a several purposes: 1) it is used as an argument to
  2275. //  NtContinue, 2) it is used to constuct a call frame for APC delivery,
  2276. //  3) it is used to construct a call frame for exception dispatching
  2277. //  in user mode, and 4) it is used in the user level thread creation
  2278. //  routines.
  2279. //
  2280. //  Requires at least 8-byte alignment (double)
  2281. //
  2282. typedef struct _CONTEXT {
  2283.     //
  2284.     // This section is specified/returned if the ContextFlags word contains
  2285.     // the flag CONTEXT_FLOATING_POINT.
  2286.     //
  2287.     double Fpr0;                        // Floating registers 0..31
  2288.     double Fpr1;
  2289.     double Fpr2;
  2290.     double Fpr3;
  2291.     double Fpr4;
  2292.     double Fpr5;
  2293.     double Fpr6;
  2294.     double Fpr7;
  2295.     double Fpr8;
  2296.     double Fpr9;
  2297.     double Fpr10;
  2298.     double Fpr11;
  2299.     double Fpr12;
  2300.     double Fpr13;
  2301.     double Fpr14;
  2302.     double Fpr15;
  2303.     double Fpr16;
  2304.     double Fpr17;
  2305.     double Fpr18;
  2306.     double Fpr19;
  2307.     double Fpr20;
  2308.     double Fpr21;
  2309.     double Fpr22;
  2310.     double Fpr23;
  2311.     double Fpr24;
  2312.     double Fpr25;
  2313.     double Fpr26;
  2314.     double Fpr27;
  2315.     double Fpr28;
  2316.     double Fpr29;
  2317.     double Fpr30;
  2318.     double Fpr31;
  2319.     double Fpscr;                       // Floating point status/control reg
  2320.     //
  2321.     // This section is specified/returned if the ContextFlags word contains
  2322.     // the flag CONTEXT_INTEGER.
  2323.     //
  2324.     DWORD Gpr0;                         // General registers 0..31
  2325.     DWORD Gpr1;
  2326.     DWORD Gpr2;
  2327.     DWORD Gpr3;
  2328.     DWORD Gpr4;
  2329.     DWORD Gpr5;
  2330.     DWORD Gpr6;
  2331.     DWORD Gpr7;
  2332.     DWORD Gpr8;
  2333.     DWORD Gpr9;
  2334.     DWORD Gpr10;
  2335.     DWORD Gpr11;
  2336.     DWORD Gpr12;
  2337.     DWORD Gpr13;
  2338.     DWORD Gpr14;
  2339.     DWORD Gpr15;
  2340.     DWORD Gpr16;
  2341.     DWORD Gpr17;
  2342.     DWORD Gpr18;
  2343.     DWORD Gpr19;
  2344.     DWORD Gpr20;
  2345.     DWORD Gpr21;
  2346.     DWORD Gpr22;
  2347.     DWORD Gpr23;
  2348.     DWORD Gpr24;
  2349.     DWORD Gpr25;
  2350.     DWORD Gpr26;
  2351.     DWORD Gpr27;
  2352.     DWORD Gpr28;
  2353.     DWORD Gpr29;
  2354.     DWORD Gpr30;
  2355.     DWORD Gpr31;
  2356.     DWORD Cr;                           // Condition register
  2357.     DWORD Xer;                          // Fixed point exception register
  2358.     //
  2359.     // This section is specified/returned if the ContextFlags word contains
  2360.     // the flag CONTEXT_CONTROL.
  2361.     //
  2362.     DWORD Msr;                          // Machine status register
  2363.     DWORD Iar;                          // Instruction address register
  2364.     DWORD Lr;                           // Link register
  2365.     DWORD Ctr;                          // Count register
  2366.     //
  2367.     // The flags values within this flag control the contents of
  2368.     // a CONTEXT record.
  2369.     //
  2370.     // If the context record is used as an input parameter, then
  2371.     // for each portion of the context record controlled by a flag
  2372.     // whose value is set, it is assumed that that portion of the
  2373.     // context record contains valid context. If the context record
  2374.     // is being used to modify a thread's context, then only that
  2375.     // portion of the threads context will be modified.
  2376.     //
  2377.     // If the context record is used as an IN OUT parameter to capture
  2378.     // the context of a thread, then only those portions of the thread's
  2379.     // context corresponding to set flags will be returned.
  2380.     //
  2381.     // The context record is never used as an OUT only parameter.
  2382.     //
  2383.     DWORD ContextFlags;
  2384.     DWORD Fill[3];                      // Pad out to multiple of 16 bytes
  2385.     //
  2386.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  2387.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  2388.     // included in CONTEXT_FULL.
  2389.     //
  2390.     DWORD Dr0;                          // Breakpoint Register 1
  2391.     DWORD Dr1;                          // Breakpoint Register 2
  2392.     DWORD Dr2;                          // Breakpoint Register 3
  2393.     DWORD Dr3;                          // Breakpoint Register 4
  2394.     DWORD Dr4;                          // Breakpoint Register 5
  2395.     DWORD Dr5;                          // Breakpoint Register 6
  2396.     DWORD Dr6;                          // Debug Status Register
  2397.     DWORD Dr7;                          // Debug Control Register
  2398. } CONTEXT, *PCONTEXT;