home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2000 May / MICD_2000_05.iso / CBuilder5 / INSTALL / DATA1.CAB / Program_Built_Files / Include / winnt.h < prev    next >
C/C++ Source or Header  |  2000-02-01  |  248KB  |  7,354 lines

  1. /*++ BUILD Version: 0087     Increment this if a change has global effects
  2.  
  3. Copyright (c) 1990-1999  Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     winnt.h
  8.  
  9. Abstract:
  10.  
  11.     This module defines the 32-Bit Windows types and constants that are
  12.     defined by NT, but exposed through the Win32 API.
  13.  
  14. Revision History:
  15.  
  16. --*/
  17.  
  18. #ifndef _WINNT_
  19. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  20. #define _WINNT_
  21.  
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25.  
  26. #include <ctype.h>  
  27. #define ANYSIZE_ARRAY 1       
  28.  
  29. #if defined(_M_MRX000) && !(defined(MIDL_PASS) || defined(RC_INVOKED)) && defined(ENABLE_RESTRICTED)
  30. #define RESTRICTED_POINTER __restrict
  31. #else
  32. #define RESTRICTED_POINTER
  33. #endif
  34.  
  35. #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64)
  36. #define UNALIGNED __unaligned
  37. #if defined(_WIN64)
  38. #define UNALIGNED64 __unaligned
  39. #else
  40. #define UNALIGNED64
  41. #endif
  42. #else
  43. #define UNALIGNED
  44. #define UNALIGNED64
  45. #endif
  46.  
  47.  
  48. #if defined(_WIN64) || defined(_M_ALPHA)
  49. #define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG)
  50. #else
  51. #define MAX_NATURAL_ALIGNMENT sizeof(DWORD)
  52. #endif
  53.  
  54. //
  55. // TYPE_ALIGNMENT will return the alignment requirements of a given type for
  56. // the current platform.
  57. //
  58.  
  59. #ifndef __cplusplus
  60. #define TYPE_ALIGNMENT( t ) \
  61.     FIELD_OFFSET( struct { char x; t test; }, test )
  62. #endif
  63.  
  64. #if defined(_WIN64)
  65.  
  66. #define PROBE_ALIGNMENT( _s ) (TYPE_ALIGNMENT( _s ) > TYPE_ALIGNMENT( DWORD ) ? \
  67.                                TYPE_ALIGNMENT( _s ) : TYPE_ALIGNMENT( DWORD ))
  68.  
  69. #else
  70.  
  71. #define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( DWORD )
  72.  
  73. #endif
  74.  
  75. //
  76. // C_ASSERT() can be used to perform many compile-time assertions:
  77. //            type sizes, field offsets, etc.
  78. //
  79. // An assertion failure results in error C2118: negative subscript.
  80. //
  81.  
  82. #define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
  83.  
  84. #if !defined(_MAC) && (defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_IA64)) && (_MSC_VER >= 1100) && !(defined(MIDL_PASS) || defined(RC_INVOKED))
  85. #define POINTER_64 __ptr64
  86. typedef unsigned __int64 POINTER_64_INT;
  87. #if defined(_WIN64)
  88. #define POINTER_32 __ptr32
  89. #else
  90. #define POINTER_32
  91. #endif
  92. #else
  93. #if defined(_MAC) && defined(_MAC_INT_64)
  94. #define POINTER_64 __ptr64
  95. typedef unsigned __int64 POINTER_64_INT;
  96. #else
  97. #define POINTER_64
  98. typedef unsigned long POINTER_64_INT;
  99. #endif
  100. #define POINTER_32
  101. #endif
  102.  
  103. #if defined(_IA64_)
  104. #define FIRMWARE_PTR
  105. #else
  106. #define FIRMWARE_PTR POINTER_32
  107. #endif
  108.  
  109. #include <basetsd.h>
  110.  
  111.  
  112. #if (defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_IA64)) && !defined(MIDL_PASS)
  113. #define DECLSPEC_IMPORT     __declspec(dllimport)
  114. #else
  115. #define DECLSPEC_IMPORT
  116. #endif
  117.  
  118. #ifndef DECLSPEC_NORETURN
  119. #if (_MSC_VER >= 1200) && !defined(MIDL_PASS) && !defined(__BORLANDC__)
  120. #define DECLSPEC_NORETURN   __declspec(noreturn)
  121. #else
  122. #define DECLSPEC_NORETURN
  123. #endif
  124. #endif
  125.  
  126. #ifndef DECLSPEC_ALIGN
  127. #if (_MSC_VER >= 1300) && !defined(MIDL_PASS) && !defined(__BORLANDC__)
  128. #define DECLSPEC_ALIGN(x)   __declspec(align(x))
  129. #else
  130. #define DECLSPEC_ALIGN(x)
  131. #endif
  132. #endif
  133.  
  134. #ifndef DECLSPEC_UUID
  135. #if ((_MSC_VER >= 1100) || (__BORLANDC__ >= 0x0550)) && defined(__cplusplus)
  136. #define DECLSPEC_UUID(x)    __declspec(uuid(x))
  137. #else
  138. #define DECLSPEC_UUID(x)
  139. #endif
  140. #endif
  141.  
  142. #ifndef DECLSPEC_NOVTABLE
  143. #if ((_MSC_VER >= 1100) || (__BORLANDC__ >= 0x0550)) && defined(__cplusplus)
  144. #define DECLSPEC_NOVTABLE   __declspec(novtable)
  145. #else
  146. #define DECLSPEC_NOVTABLE
  147. #endif
  148. #endif
  149.  
  150. #ifndef DECLSPEC_SELECTANY
  151. #if (_MSC_VER >= 1100) || (__BORLANDC__ >= 0x0550)
  152. #define DECLSPEC_SELECTANY  __declspec(selectany)
  153. #else
  154. #define DECLSPEC_SELECTANY
  155. #endif
  156. #endif
  157.  
  158. #ifndef NOP_FUNCTION
  159. #if (_MSC_VER >= 1210)
  160. #define NOP_FUNCTION __noop
  161. #else
  162. #define NOP_FUNCTION (void)0
  163. #endif
  164. #endif
  165.  
  166. #ifndef DECLSPEC_ADDRSAFE
  167. #if (_MSC_VER >= 1200) && (defined(_M_ALPHA) || defined(_M_AXP64))
  168. #define DECLSPEC_ADDRSAFE  __declspec(address_safe)
  169. #else
  170. #define DECLSPEC_ADDRSAFE
  171. #endif
  172. #endif
  173.  
  174.  
  175. typedef void *PVOID;
  176. typedef void * POINTER_64 PVOID64;
  177.  
  178.  
  179. #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
  180. #define NTAPI __stdcall
  181. #else
  182. #define _cdecl
  183. #define NTAPI
  184. #endif
  185.  
  186. //
  187. // Define API decoration for direct importing system DLL references.
  188. //
  189.  
  190. #if !defined(_NTSYSTEM_)
  191. #define NTSYSAPI     DECLSPEC_IMPORT
  192. #define NTSYSCALLAPI DECLSPEC_IMPORT
  193. #else
  194. #define NTSYSAPI
  195. #if defined(_NTDLLBUILD_)
  196. #define NTSYSCALLAPI
  197. #else
  198. #define NTSYSCALLAPI DECLSPEC_ADDRSAFE
  199. #endif
  200.  
  201. #endif
  202.  
  203.  
  204. //
  205. // Basics
  206. //
  207.  
  208. #ifndef VOID
  209. #define VOID void
  210. typedef char CHAR;
  211. typedef short SHORT;
  212. typedef long LONG;
  213. #endif
  214.  
  215. //
  216. // UNICODE (Wide Character) types
  217. //
  218.  
  219. #ifndef _MAC
  220. typedef wchar_t WCHAR;    // wc,   16-bit UNICODE character
  221. #else
  222. // some Macintosh compilers don't define wchar_t in a convenient location, or define it as a char
  223. typedef unsigned short WCHAR;    // wc,   16-bit UNICODE character
  224. #endif
  225.  
  226. typedef WCHAR *PWCHAR;
  227. typedef WCHAR *LPWCH, *PWCH;
  228. typedef CONST WCHAR *LPCWCH, *PCWCH;
  229. typedef WCHAR *NWPSTR;
  230. typedef WCHAR *LPWSTR, *PWSTR;
  231.  
  232. typedef CONST WCHAR *LPCWSTR, *PCWSTR;
  233.  
  234. //
  235. // ANSI (Multi-byte Character) types
  236. //
  237. typedef CHAR *PCHAR;
  238. typedef CHAR *LPCH, *PCH;
  239.  
  240. typedef CONST CHAR *LPCCH, *PCCH;
  241. typedef CHAR *NPSTR;
  242. typedef CHAR *LPSTR, *PSTR;
  243. typedef CONST CHAR *LPCSTR, *PCSTR;
  244.  
  245. //
  246. // Neutral ANSI/UNICODE types and macros
  247. //
  248. #ifdef  UNICODE                     // r_winnt
  249.  
  250. #ifndef _TCHAR_DEFINED
  251. typedef WCHAR TCHAR, *PTCHAR;
  252. typedef WCHAR TBYTE , *PTBYTE ;
  253. #define _TCHAR_DEFINED
  254. #endif /* !_TCHAR_DEFINED */
  255.  
  256. typedef LPWSTR LPTCH, PTCH;
  257. typedef LPWSTR PTSTR, LPTSTR;
  258. typedef LPCWSTR PCTSTR, LPCTSTR;
  259. typedef LPWSTR LP;
  260. #define __TEXT(quote) L##quote      // r_winnt
  261.  
  262. #else   /* UNICODE */               // r_winnt
  263.  
  264. #ifndef _TCHAR_DEFINED
  265. typedef char TCHAR, *PTCHAR;
  266. typedef unsigned char TBYTE , *PTBYTE ;
  267. #define _TCHAR_DEFINED
  268. #endif /* !_TCHAR_DEFINED */
  269.  
  270. typedef LPSTR LPTCH, PTCH;
  271. typedef LPSTR PTSTR, LPTSTR;
  272. typedef LPCSTR PCTSTR, LPCTSTR;
  273. #define __TEXT(quote) quote         // r_winnt
  274.  
  275. #endif /* UNICODE */                // r_winnt
  276. #define TEXT(quote) __TEXT(quote)   // r_winnt
  277.  
  278.  
  279. typedef SHORT *PSHORT;  
  280. typedef LONG *PLONG;    
  281.  
  282. #ifdef STRICT
  283. typedef void *HANDLE;
  284. #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
  285. #else
  286. typedef PVOID HANDLE;
  287. #define DECLARE_HANDLE(name) typedef HANDLE name
  288. #endif
  289. typedef HANDLE *PHANDLE;
  290.  
  291. //
  292. // Flag (bit) fields
  293. //
  294.  
  295. typedef BYTE   FCHAR;
  296. typedef WORD   FSHORT;
  297. typedef DWORD  FLONG;
  298.  
  299. // Component Object Model defines, and macros
  300.  
  301. #ifndef _HRESULT_DEFINED
  302. #define _HRESULT_DEFINED
  303. typedef LONG HRESULT;
  304.  
  305. #endif // !_HRESULT_DEFINED
  306.  
  307. #ifdef __cplusplus
  308.     #define EXTERN_C    extern "C"
  309. #else
  310.     #define EXTERN_C    extern
  311. #endif
  312.  
  313. #if defined(_WIN32) || defined(_MPPC_)
  314.  
  315. // Win32 doesn't support __export
  316.  
  317. #ifdef _68K_
  318. #define STDMETHODCALLTYPE       __cdecl
  319. #else
  320. #define STDMETHODCALLTYPE       __stdcall
  321. #endif
  322. #define STDMETHODVCALLTYPE      __cdecl
  323.  
  324. #define STDAPICALLTYPE          __stdcall
  325. #define STDAPIVCALLTYPE         __cdecl
  326.  
  327. #else
  328.  
  329. #define STDMETHODCALLTYPE       __export __stdcall
  330. #define STDMETHODVCALLTYPE      __export __cdecl
  331.  
  332. #define STDAPICALLTYPE          __export __stdcall
  333. #define STDAPIVCALLTYPE         __export __cdecl
  334.  
  335. #endif
  336.  
  337.  
  338. #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
  339. #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
  340.  
  341. #define STDMETHODIMP            HRESULT STDMETHODCALLTYPE
  342. #define STDMETHODIMP_(type)     type STDMETHODCALLTYPE
  343.  
  344. // The 'V' versions allow Variable Argument lists.
  345.  
  346. #define STDAPIV                 EXTERN_C HRESULT STDAPIVCALLTYPE
  347. #define STDAPIV_(type)          EXTERN_C type STDAPIVCALLTYPE
  348.  
  349. #define STDMETHODIMPV           HRESULT STDMETHODVCALLTYPE
  350. #define STDMETHODIMPV_(type)    type STDMETHODVCALLTYPE
  351.  
  352. typedef char CCHAR;          
  353. typedef DWORD LCID;         
  354. typedef PDWORD PLCID;       
  355. typedef WORD   LANGID;      
  356. #define APPLICATION_ERROR_MASK       0x20000000
  357. #define ERROR_SEVERITY_SUCCESS       0x00000000
  358. #define ERROR_SEVERITY_INFORMATIONAL 0x40000000
  359. #define ERROR_SEVERITY_WARNING       0x80000000
  360. #define ERROR_SEVERITY_ERROR         0xC0000000
  361.  
  362. //
  363. // _M_IX86 included so that EM CONTEXT structure compiles with
  364. // x86 programs. *** TBD should this be for all architectures?
  365. //
  366.  
  367. //
  368. // 16 byte aligned type for 128 bit floats
  369. //
  370.  
  371. //
  372. // For we define a 128 bit structure and use __declspec(align(16)) pragma to
  373. // align to 128 bits.
  374. //
  375.  
  376. #if defined(_M_IA64) && !defined(MIDL_PASS)
  377. __declspec(align(16))
  378. #endif
  379. typedef struct _FLOAT128 {
  380.     __int64 LowPart;
  381.     __int64 HighPart;
  382. } FLOAT128;
  383.  
  384. typedef FLOAT128 *PFLOAT128;
  385.  
  386.  
  387. //
  388. // __int64 is only supported by 2.0 and later midl.
  389. // __midl is set by the 2.0 midl and not by 1.0 midl.
  390. //
  391.  
  392. #define _ULONGLONG_
  393. #if (!defined (_MAC) && (!defined(MIDL_PASS) || defined(__midl)) && (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64)))
  394. typedef __int64 LONGLONG;
  395. typedef unsigned __int64 ULONGLONG;
  396.  
  397. #define MAXLONGLONG                      (0x7fffffffffffffff)
  398. #else
  399.  
  400. #if defined(_MAC) && defined(_MAC_INT_64)
  401. typedef __int64 LONGLONG;
  402. typedef unsigned __int64 ULONGLONG;
  403.  
  404. #define MAXLONGLONG                      (0x7fffffffffffffff)
  405. #else
  406. typedef double LONGLONG;
  407. typedef double ULONGLONG;
  408. #endif //_MAC and int64
  409.  
  410. #endif
  411.  
  412. typedef LONGLONG *PLONGLONG;
  413. typedef ULONGLONG *PULONGLONG;
  414.  
  415. // Update Sequence Number
  416.  
  417. typedef LONGLONG USN;
  418.  
  419. #if defined(MIDL_PASS)
  420. typedef struct _LARGE_INTEGER {
  421. #else // MIDL_PASS
  422. typedef union _LARGE_INTEGER {
  423.     struct {
  424.         DWORD LowPart;
  425.         LONG HighPart;
  426.     };
  427.     struct {
  428.         DWORD LowPart;
  429.         LONG HighPart;
  430.     } u;
  431. #endif //MIDL_PASS
  432.     LONGLONG QuadPart;
  433. } LARGE_INTEGER;
  434.  
  435. typedef LARGE_INTEGER *PLARGE_INTEGER;
  436.  
  437.  
  438. #if defined(MIDL_PASS)
  439. typedef struct _ULARGE_INTEGER {
  440. #else // MIDL_PASS
  441. typedef union _ULARGE_INTEGER {
  442.     struct {
  443.         DWORD LowPart;
  444.         DWORD HighPart;
  445.     };
  446.     struct {
  447.         DWORD LowPart;
  448.         DWORD HighPart;
  449.     } u;
  450. #endif //MIDL_PASS
  451.     ULONGLONG QuadPart;
  452. } ULARGE_INTEGER;
  453.  
  454. typedef ULARGE_INTEGER *PULARGE_INTEGER;
  455.  
  456. // end_ntminiport end_ntndis end_ntminitape
  457.  
  458.  
  459. //
  460. // Locally Unique Identifier
  461. //
  462.  
  463. typedef struct _LUID {
  464.     DWORD LowPart;
  465.     LONG HighPart;
  466. } LUID, *PLUID;
  467.  
  468. #define _DWORDLONG_
  469. typedef ULONGLONG  DWORDLONG;
  470. typedef DWORDLONG *PDWORDLONG;
  471.  
  472.  
  473. //
  474. // Define operations to logically shift an int64 by 0..31 bits and to multiply
  475. // 32-bits by 32-bits to form a 64-bit product.
  476. //
  477.  
  478. #if defined(MIDL_PASS) || defined(RC_INVOKED)
  479.  
  480. //
  481. // Midl does not understand inline assembler. Therefore, the Rtl functions
  482. // are used for shifts by 0.31 and multiplies of 32-bits times 32-bits to
  483. // form a 64-bit product.
  484. //
  485.  
  486. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  487. #define UInt32x32To64(a, b) ((ULONGLONG)((DWORD)(a)) * (ULONGLONG)((DWORD)(b)))
  488.  
  489. #define Int64ShllMod32(a, b) ((ULONGLONG)(a) << (b))
  490. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  491. #define Int64ShrlMod32(a, b) ((ULONGLONG)(a) >> (b))
  492.  
  493. #elif defined(_M_MRX000)
  494.  
  495. //
  496. // MIPS uses intrinsic functions to perform shifts by 0..31 and multiplies of
  497. // 32-bits times 32-bits to 64-bits.
  498. //
  499.  
  500. #define Int32x32To64 __emul
  501. #define UInt32x32To64 __emulu
  502.  
  503. #define Int64ShllMod32 __ll_lshift
  504. #define Int64ShraMod32 __ll_rshift
  505. #define Int64ShrlMod32 __ull_rshift
  506.  
  507. #if defined (__cplusplus)
  508. extern "C" {
  509. #endif
  510.  
  511. LONGLONG
  512. NTAPI
  513. Int32x32To64 (
  514.     LONG Multiplier,
  515.     LONG Multiplicand
  516.     );
  517.  
  518. ULONGLONG
  519. NTAPI
  520. UInt32x32To64 (
  521.     DWORD Multiplier,
  522.     DWORD Multiplicand
  523.     );
  524.  
  525. ULONGLONG
  526. NTAPI
  527. Int64ShllMod32 (
  528.     ULONGLONG Value,
  529.     DWORD ShiftCount
  530.     );
  531.  
  532. LONGLONG
  533. NTAPI
  534. Int64ShraMod32 (
  535.     LONGLONG Value,
  536.     DWORD ShiftCount
  537.     );
  538.  
  539. ULONGLONG
  540. NTAPI
  541. Int64ShrlMod32 (
  542.     ULONGLONG Value,
  543.     DWORD ShiftCount
  544.     );
  545.  
  546. #if defined (__cplusplus)
  547. };
  548. #endif
  549.  
  550. #pragma intrinsic(__emul)
  551. #pragma intrinsic(__emulu)
  552.  
  553. #pragma intrinsic(__ll_lshift)
  554. #pragma intrinsic(__ll_rshift)
  555. #pragma intrinsic(__ull_rshift)
  556.  
  557. #elif defined(_M_IX86)
  558.  
  559. //
  560. // The x86 C compiler understands inline assembler. Therefore, inline functions
  561. // that employ inline assembler are used for shifts of 0..31.  The multiplies
  562. // rely on the compiler recognizing the cast of the multiplicand to int64 to
  563. // generate the optimal code inline.
  564. //
  565.  
  566. #define Int32x32To64( a, b ) (LONGLONG)((LONGLONG)(LONG)(a) * (LONG)(b))
  567. #define UInt32x32To64( a, b ) (ULONGLONG)((ULONGLONG)(DWORD)(a) * (DWORD)(b))
  568.  
  569. #if !defined (__BORLANDC__)
  570.  
  571. ULONGLONG
  572. NTAPI
  573. Int64ShllMod32 (
  574.     ULONGLONG Value,
  575.     DWORD ShiftCount
  576.     );
  577.  
  578. LONGLONG
  579. NTAPI
  580. Int64ShraMod32 (
  581.     LONGLONG Value,
  582.     DWORD ShiftCount
  583.     );
  584.  
  585. ULONGLONG
  586. NTAPI
  587. Int64ShrlMod32 (
  588.     ULONGLONG Value,
  589.     DWORD ShiftCount
  590.     );
  591.  
  592. #if _MSC_VER >= 1200
  593. #pragma warning(push)
  594. #endif
  595. #pragma warning(disable:4035)               // re-enable below
  596.  
  597. __inline ULONGLONG
  598. NTAPI
  599. Int64ShllMod32 (
  600.     ULONGLONG Value,
  601.     DWORD ShiftCount
  602.     )
  603. {
  604.     __asm    {
  605.         mov     ecx, ShiftCount
  606.         mov     eax, dword ptr [Value]
  607.         mov     edx, dword ptr [Value+4]
  608.         shld    edx, eax, cl
  609.         shl     eax, cl
  610.     }
  611. }
  612.  
  613. __inline LONGLONG
  614. NTAPI
  615. Int64ShraMod32 (
  616.     LONGLONG Value,
  617.     DWORD ShiftCount
  618.     )
  619. {
  620.     __asm {
  621.         mov     ecx, ShiftCount
  622.         mov     eax, dword ptr [Value]
  623.         mov     edx, dword ptr [Value+4]
  624.         shrd    eax, edx, cl
  625.         sar     edx, cl
  626.     }
  627. }
  628.  
  629. __inline ULONGLONG
  630. NTAPI
  631. Int64ShrlMod32 (
  632.     ULONGLONG Value,
  633.     DWORD ShiftCount
  634.     )
  635. {
  636.     __asm    {
  637.         mov     ecx, ShiftCount
  638.         mov     eax, dword ptr [Value]
  639.         mov     edx, dword ptr [Value+4]
  640.         shrd    eax, edx, cl
  641.         shr     edx, cl
  642.     }
  643. }
  644.  
  645. #if _MSC_VER >= 1200
  646. #pragma warning(pop)
  647. #else
  648. #pragma warning(default:4035)
  649. #endif
  650.  
  651. #else
  652. /* For Borland, let the compiler generate calls to __int64 helper functions */
  653.  
  654. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  655. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  656. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  657.  
  658. #endif /* !defined (__BORLANDC__) */
  659.  
  660. #elif defined(_M_ALPHA)
  661.  
  662. //
  663. // Alpha has native 64-bit operations that are just as fast as their 32-bit
  664. // counter parts. Therefore, the int64 data type is used directly to form
  665. // shifts of 0..31 and multiplies of 32-bits times 32-bits to form a 64-bit
  666. // product.
  667. //
  668.  
  669. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  670. #define UInt32x32To64(a, b) ((ULONGLONG)((DWORD)(a)) * (ULONGLONG)((DWORD)(b)))
  671.  
  672. #define Int64ShllMod32(a, b) ((ULONGLONG)(a) << (b))
  673. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  674. #define Int64ShrlMod32(a, b) ((ULONGLONG)(a) >> (b))
  675.  
  676.  
  677. #elif defined(_M_PPC)
  678.  
  679. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  680. #define UInt32x32To64(a, b) ((ULONGLONG)((DWORD)(a)) * (ULONGLONG)((DWORD)(b)))
  681.  
  682. #define Int64ShllMod32(a, b) ((ULONGLONG)(a) << (b))
  683. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  684. #define Int64ShrlMod32(a, b) ((ULONGLONG)(a) >> (b))
  685.  
  686. #elif defined(_68K_) || defined(_MPPC_)
  687.  
  688. //
  689. // The Macintosh 68K and PowerPC compilers do not currently support int64.
  690. //
  691.  
  692. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  693. #define UInt32x32To64(a, b) ((DWORDLONG)((DWORD)(a)) * (DWORDLONG)((DWORD)(b)))
  694.  
  695. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  696. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  697. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  698.  
  699. #elif defined(_M_IA64)
  700.  
  701. //
  702. // IA64 has native 64-bit operations that are just as fast as their 32-bit
  703. // counter parts. Therefore, the int64 data type is used directly to form
  704. // shifts of 0..31 and multiplies of 32-bits times 32-bits to form a 64-bit
  705. // product.
  706. //
  707.  
  708. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  709. #define UInt32x32To64(a, b) ((ULONGLONG)((DWORD)(a)) * (ULONGLONG)((DWORD)(b)))
  710.  
  711. #define Int64ShllMod32(a, b) ((ULONGLONG)(a) << (b))
  712. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  713. #define Int64ShrlMod32(a, b) ((ULONGLONG)(a) >> (b))
  714.  
  715. #else
  716.  
  717. #error Must define a target architecture.
  718.  
  719. #endif
  720.  
  721. #define ANSI_NULL ((CHAR)0)     
  722. #define UNICODE_NULL ((WCHAR)0) 
  723. typedef BYTE  BOOLEAN;           
  724. typedef BOOLEAN *PBOOLEAN;       
  725. //
  726. //  Doubly linked list structure.  Can be used as either a list head, or
  727. //  as link words.
  728. //
  729.  
  730. typedef struct _LIST_ENTRY {
  731.    struct _LIST_ENTRY *Flink;
  732.    struct _LIST_ENTRY *Blink;
  733. } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;
  734.  
  735. //
  736. //  Singly linked list structure. Can be used as either a list head, or
  737. //  as link words.
  738. //
  739.  
  740. typedef struct _SINGLE_LIST_ENTRY {
  741.     struct _SINGLE_LIST_ENTRY *Next;
  742. } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
  743.  
  744. //
  745. // These are needed for portable debugger support.
  746. //
  747.  
  748. typedef struct LIST_ENTRY32 {
  749.     DWORD Flink;
  750.     DWORD Blink;
  751. } LIST_ENTRY32;
  752. typedef LIST_ENTRY32 *PLIST_ENTRY32;
  753.  
  754. typedef struct LIST_ENTRY64 {
  755.     ULONGLONG Flink;
  756.     ULONGLONG Blink;
  757. } LIST_ENTRY64;
  758. typedef LIST_ENTRY64 *PLIST_ENTRY64;
  759.  
  760.  
  761. #include <guiddef.h>
  762.  
  763. #ifndef __OBJECTID_DEFINED
  764. #define __OBJECTID_DEFINED
  765.  
  766. typedef struct  _OBJECTID {     // size is 20
  767.     GUID Lineage;
  768.     DWORD Uniquifier;
  769. } OBJECTID;
  770. #endif // !_OBJECTID_DEFINED
  771.  
  772. #define MINCHAR     0x80        
  773. #define MAXCHAR     0x7f        
  774. #define MINSHORT    0x8000      
  775. #define MAXSHORT    0x7fff      
  776. #define MINLONG     0x80000000  
  777. #define MAXLONG     0x7fffffff  
  778. #define MAXBYTE     0xff        
  779. #define MAXWORD     0xffff      
  780. #define MAXDWORD    0xffffffff  
  781. //
  782. // Calculate the byte offset of a field in a structure of type type.
  783. //
  784.  
  785. #define FIELD_OFFSET(type, field)    ((LONG)(LONG_PTR)&(((type *)0)->field))
  786.  
  787.  
  788. //
  789. // Calculate the address of the base of the structure given its type, and an
  790. // address of a field within the structure.
  791. //
  792.  
  793. #define CONTAINING_RECORD(address, type, field) ((type *)( \
  794.                                                   (PCHAR)(address) - \
  795.                                                   (ULONG_PTR)(&((type *)0)->field)))
  796.  
  797.  
  798. #define VER_SERVER_NT                       0x80000000
  799. #define VER_WORKSTATION_NT                  0x40000000
  800. #define VER_SUITE_SMALLBUSINESS             0x00000001
  801. #define VER_SUITE_ENTERPRISE                0x00000002
  802. #define VER_SUITE_BACKOFFICE                0x00000004
  803. #define VER_SUITE_COMMUNICATIONS            0x00000008
  804. #define VER_SUITE_TERMINAL                  0x00000010
  805. #define VER_SUITE_SMALLBUSINESS_RESTRICTED  0x00000020
  806. #define VER_SUITE_EMBEDDEDNT                0x00000040
  807. #define VER_SUITE_DATACENTER                0x00000080
  808. #define VER_SUITE_SINGLEUSERTS              0x00000100
  809.  
  810.  
  811. //
  812. //  Language IDs.
  813. //
  814. //  The following two combinations of primary language ID and
  815. //  sublanguage ID have special semantics:
  816. //
  817. //    Primary Language ID   Sublanguage ID      Result
  818. //    -------------------   ---------------     ------------------------
  819. //    LANG_NEUTRAL          SUBLANG_NEUTRAL     Language neutral
  820. //    LANG_NEUTRAL          SUBLANG_DEFAULT     User default language
  821. //    LANG_NEUTRAL          SUBLANG_SYS_DEFAULT System default language
  822. //
  823.  
  824. //
  825. //  Primary language IDs.
  826. //
  827.  
  828. #define LANG_NEUTRAL                     0x00
  829.  
  830. #define LANG_AFRIKAANS                   0x36
  831. #define LANG_ALBANIAN                    0x1c
  832. #define LANG_ARABIC                      0x01
  833. #define LANG_ARMENIAN                    0x2b
  834. #define LANG_ASSAMESE                    0x4d
  835. #define LANG_AZERI                       0x2c
  836. #define LANG_BASQUE                      0x2d
  837. #define LANG_BELARUSIAN                  0x23
  838. #define LANG_BENGALI                     0x45
  839. #define LANG_BULGARIAN                   0x02
  840. #define LANG_CATALAN                     0x03
  841. #define LANG_CHINESE                     0x04
  842. #define LANG_CROATIAN                    0x1a
  843. #define LANG_CZECH                       0x05
  844. #define LANG_DANISH                      0x06
  845. #define LANG_DUTCH                       0x13
  846. #define LANG_ENGLISH                     0x09
  847. #define LANG_ESTONIAN                    0x25
  848. #define LANG_FAEROESE                    0x38
  849. #define LANG_FARSI                       0x29
  850. #define LANG_FINNISH                     0x0b
  851. #define LANG_FRENCH                      0x0c
  852. #define LANG_GEORGIAN                    0x37
  853. #define LANG_GERMAN                      0x07
  854. #define LANG_GREEK                       0x08
  855. #define LANG_GUJARATI                    0x47
  856. #define LANG_HEBREW                      0x0d
  857. #define LANG_HINDI                       0x39
  858. #define LANG_HUNGARIAN                   0x0e
  859. #define LANG_ICELANDIC                   0x0f
  860. #define LANG_INDONESIAN                  0x21
  861. #define LANG_ITALIAN                     0x10
  862. #define LANG_JAPANESE                    0x11
  863. #define LANG_KANNADA                     0x4b
  864. #define LANG_KASHMIRI                    0x60
  865. #define LANG_KAZAK                       0x3f
  866. #define LANG_KONKANI                     0x57
  867. #define LANG_KOREAN                      0x12
  868. #define LANG_LATVIAN                     0x26
  869. #define LANG_LITHUANIAN                  0x27
  870. #define LANG_MACEDONIAN                  0x2f   // the Former Yugoslav Republic of Macedonia
  871. #define LANG_MALAY                       0x3e
  872. #define LANG_MALAYALAM                   0x4c
  873. #define LANG_MANIPURI                    0x58
  874. #define LANG_MARATHI                     0x4e
  875. #define LANG_NEPALI                      0x61
  876. #define LANG_NORWEGIAN                   0x14
  877. #define LANG_ORIYA                       0x48
  878. #define LANG_POLISH                      0x15
  879. #define LANG_PORTUGUESE                  0x16
  880. #define LANG_PUNJABI                     0x46
  881. #define LANG_ROMANIAN                    0x18
  882. #define LANG_RUSSIAN                     0x19
  883. #define LANG_SANSKRIT                    0x4f
  884. #define LANG_SERBIAN                     0x1a
  885. #define LANG_SINDHI                      0x59
  886. #define LANG_SLOVAK                      0x1b
  887. #define LANG_SLOVENIAN                   0x24
  888. #define LANG_SPANISH                     0x0a
  889. #define LANG_SWAHILI                     0x41
  890. #define LANG_SWEDISH                     0x1d
  891. #define LANG_TAMIL                       0x49
  892. #define LANG_TATAR                       0x44
  893. #define LANG_TELUGU                      0x4a
  894. #define LANG_THAI                        0x1e
  895. #define LANG_TURKISH                     0x1f
  896. #define LANG_UKRAINIAN                   0x22
  897. #define LANG_URDU                        0x20
  898. #define LANG_UZBEK                       0x43
  899. #define LANG_VIETNAMESE                  0x2a
  900.  
  901. //
  902. //  Sublanguage IDs.
  903. //
  904. //  The name immediately following SUBLANG_ dictates which primary
  905. //  language ID that sublanguage ID can be combined with to form a
  906. //  valid language ID.
  907. //
  908.  
  909. #define SUBLANG_NEUTRAL                  0x00    // language neutral
  910. #define SUBLANG_DEFAULT                  0x01    // user default
  911. #define SUBLANG_SYS_DEFAULT              0x02    // system default
  912.  
  913. #define SUBLANG_ARABIC_SAUDI_ARABIA      0x01    // Arabic (Saudi Arabia)
  914. #define SUBLANG_ARABIC_IRAQ              0x02    // Arabic (Iraq)
  915. #define SUBLANG_ARABIC_EGYPT             0x03    // Arabic (Egypt)
  916. #define SUBLANG_ARABIC_LIBYA             0x04    // Arabic (Libya)
  917. #define SUBLANG_ARABIC_ALGERIA           0x05    // Arabic (Algeria)
  918. #define SUBLANG_ARABIC_MOROCCO           0x06    // Arabic (Morocco)
  919. #define SUBLANG_ARABIC_TUNISIA           0x07    // Arabic (Tunisia)
  920. #define SUBLANG_ARABIC_OMAN              0x08    // Arabic (Oman)
  921. #define SUBLANG_ARABIC_YEMEN             0x09    // Arabic (Yemen)
  922. #define SUBLANG_ARABIC_SYRIA             0x0a    // Arabic (Syria)
  923. #define SUBLANG_ARABIC_JORDAN            0x0b    // Arabic (Jordan)
  924. #define SUBLANG_ARABIC_LEBANON           0x0c    // Arabic (Lebanon)
  925. #define SUBLANG_ARABIC_KUWAIT            0x0d    // Arabic (Kuwait)
  926. #define SUBLANG_ARABIC_UAE               0x0e    // Arabic (U.A.E)
  927. #define SUBLANG_ARABIC_BAHRAIN           0x0f    // Arabic (Bahrain)
  928. #define SUBLANG_ARABIC_QATAR             0x10    // Arabic (Qatar)
  929. #define SUBLANG_AZERI_LATIN              0x01    // Azeri (Latin)
  930. #define SUBLANG_AZERI_CYRILLIC           0x02    // Azeri (Cyrillic)
  931. #define SUBLANG_CHINESE_TRADITIONAL      0x01    // Chinese (Taiwan)
  932. #define SUBLANG_CHINESE_SIMPLIFIED       0x02    // Chinese (PR China)
  933. #define SUBLANG_CHINESE_HONGKONG         0x03    // Chinese (Hong Kong S.A.R., P.R.C.)
  934. #define SUBLANG_CHINESE_SINGAPORE        0x04    // Chinese (Singapore)
  935. #define SUBLANG_CHINESE_MACAU            0x05    // Chinese (Macau)
  936. #define SUBLANG_DUTCH                    0x01    // Dutch
  937. #define SUBLANG_DUTCH_BELGIAN            0x02    // Dutch (Belgian)
  938. #define SUBLANG_ENGLISH_US               0x01    // English (USA)
  939. #define SUBLANG_ENGLISH_UK               0x02    // English (UK)
  940. #define SUBLANG_ENGLISH_AUS              0x03    // English (Australian)
  941. #define SUBLANG_ENGLISH_CAN              0x04    // English (Canadian)
  942. #define SUBLANG_ENGLISH_NZ               0x05    // English (New Zealand)
  943. #define SUBLANG_ENGLISH_EIRE             0x06    // English (Irish)
  944. #define SUBLANG_ENGLISH_SOUTH_AFRICA     0x07    // English (South Africa)
  945. #define SUBLANG_ENGLISH_JAMAICA          0x08    // English (Jamaica)
  946. #define SUBLANG_ENGLISH_CARIBBEAN        0x09    // English (Caribbean)
  947. #define SUBLANG_ENGLISH_BELIZE           0x0a    // English (Belize)
  948. #define SUBLANG_ENGLISH_TRINIDAD         0x0b    // English (Trinidad)
  949. #define SUBLANG_ENGLISH_ZIMBABWE         0x0c    // English (Zimbabwe)
  950. #define SUBLANG_ENGLISH_PHILIPPINES      0x0d    // English (Philippines)
  951. #define SUBLANG_FRENCH                   0x01    // French
  952. #define SUBLANG_FRENCH_BELGIAN           0x02    // French (Belgian)
  953. #define SUBLANG_FRENCH_CANADIAN          0x03    // French (Canadian)
  954. #define SUBLANG_FRENCH_SWISS             0x04    // French (Swiss)
  955. #define SUBLANG_FRENCH_LUXEMBOURG        0x05    // French (Luxembourg)
  956. #define SUBLANG_FRENCH_MONACO            0x06    // French (Monaco)
  957. #define SUBLANG_GERMAN                   0x01    // German
  958. #define SUBLANG_GERMAN_SWISS             0x02    // German (Swiss)
  959. #define SUBLANG_GERMAN_AUSTRIAN          0x03    // German (Austrian)
  960. #define SUBLANG_GERMAN_LUXEMBOURG        0x04    // German (Luxembourg)
  961. #define SUBLANG_GERMAN_LIECHTENSTEIN     0x05    // German (Liechtenstein)
  962. #define SUBLANG_ITALIAN                  0x01    // Italian
  963. #define SUBLANG_ITALIAN_SWISS            0x02    // Italian (Swiss)
  964. #define SUBLANG_KASHMIRI_INDIA           0x02    // Kashmiri (India)
  965. #define SUBLANG_KOREAN                   0x01    // Korean (Extended Wansung)
  966. #define SUBLANG_LITHUANIAN               0x01    // Lithuanian
  967. #define SUBLANG_MALAY_MALAYSIA           0x01    // Malay (Malaysia)
  968. #define SUBLANG_MALAY_BRUNEI_DARUSSALAM  0x02    // Malay (Brunei Darussalam)
  969. #define SUBLANG_NEPALI_INDIA             0x02    // Nepali (India)
  970. #define SUBLANG_NORWEGIAN_BOKMAL         0x01    // Norwegian (Bokmal)
  971. #define SUBLANG_NORWEGIAN_NYNORSK        0x02    // Norwegian (Nynorsk)
  972. #define SUBLANG_PORTUGUESE               0x02    // Portuguese
  973. #define SUBLANG_PORTUGUESE_BRAZILIAN     0x01    // Portuguese (Brazilian)
  974. #define SUBLANG_SERBIAN_LATIN            0x02    // Serbian (Latin)
  975. #define SUBLANG_SERBIAN_CYRILLIC         0x03    // Serbian (Cyrillic)
  976. #define SUBLANG_SPANISH                  0x01    // Spanish (Castilian)
  977. #define SUBLANG_SPANISH_MEXICAN          0x02    // Spanish (Mexican)
  978. #define SUBLANG_SPANISH_MODERN           0x03    // Spanish (Modern)
  979. #define SUBLANG_SPANISH_GUATEMALA        0x04    // Spanish (Guatemala)
  980. #define SUBLANG_SPANISH_COSTA_RICA       0x05    // Spanish (Costa Rica)
  981. #define SUBLANG_SPANISH_PANAMA           0x06    // Spanish (Panama)
  982. #define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07  // Spanish (Dominican Republic)
  983. #define SUBLANG_SPANISH_VENEZUELA        0x08    // Spanish (Venezuela)
  984. #define SUBLANG_SPANISH_COLOMBIA         0x09    // Spanish (Colombia)
  985. #define SUBLANG_SPANISH_PERU             0x0a    // Spanish (Peru)
  986. #define SUBLANG_SPANISH_ARGENTINA        0x0b    // Spanish (Argentina)
  987. #define SUBLANG_SPANISH_ECUADOR          0x0c    // Spanish (Ecuador)
  988. #define SUBLANG_SPANISH_CHILE            0x0d    // Spanish (Chile)
  989. #define SUBLANG_SPANISH_URUGUAY          0x0e    // Spanish (Uruguay)
  990. #define SUBLANG_SPANISH_PARAGUAY         0x0f    // Spanish (Paraguay)
  991. #define SUBLANG_SPANISH_BOLIVIA          0x10    // Spanish (Bolivia)
  992. #define SUBLANG_SPANISH_EL_SALVADOR      0x11    // Spanish (El Salvador)
  993. #define SUBLANG_SPANISH_HONDURAS         0x12    // Spanish (Honduras)
  994. #define SUBLANG_SPANISH_NICARAGUA        0x13    // Spanish (Nicaragua)
  995. #define SUBLANG_SPANISH_PUERTO_RICO      0x14    // Spanish (Puerto Rico)
  996. #define SUBLANG_SWEDISH                  0x01    // Swedish
  997. #define SUBLANG_SWEDISH_FINLAND          0x02    // Swedish (Finland)
  998. #define SUBLANG_URDU_PAKISTAN            0x01    // Urdu (Pakistan)
  999. #define SUBLANG_URDU_INDIA               0x02    // Urdu (India)
  1000. #define SUBLANG_UZBEK_LATIN              0x01    // Uzbek (Latin)
  1001. #define SUBLANG_UZBEK_CYRILLIC           0x02    // Uzbek (Cyrillic)
  1002.  
  1003. //
  1004. //  Sorting IDs.
  1005. //
  1006.  
  1007. #define SORT_DEFAULT                     0x0     // sorting default
  1008.  
  1009. #define SORT_JAPANESE_XJIS               0x0     // Japanese XJIS order
  1010. #define SORT_JAPANESE_UNICODE            0x1     // Japanese Unicode order
  1011.  
  1012. #define SORT_CHINESE_BIG5                0x0     // Chinese BIG5 order
  1013. #define SORT_CHINESE_PRCP                0x0     // PRC Chinese Phonetic order
  1014. #define SORT_CHINESE_UNICODE             0x1     // Chinese Unicode order
  1015. #define SORT_CHINESE_PRC                 0x2     // PRC Chinese Stroke Count order
  1016. #define SORT_CHINESE_BOPOMOFO            0x3     // Traditional Chinese Bopomofo order
  1017.  
  1018. #define SORT_KOREAN_KSC                  0x0     // Korean KSC order
  1019. #define SORT_KOREAN_UNICODE              0x1     // Korean Unicode order
  1020.  
  1021. #define SORT_GERMAN_PHONE_BOOK           0x1     // German Phone Book order
  1022.  
  1023. #define SORT_HUNGARIAN_DEFAULT           0x0     // Hungarian Default order
  1024. #define SORT_HUNGARIAN_TECHNICAL         0x1     // Hungarian Technical order
  1025.  
  1026. #define SORT_GEORGIAN_TRADITIONAL        0x0     // Georgian Traditional order
  1027. #define SORT_GEORGIAN_MODERN             0x1     // Georgian Modern order
  1028.  
  1029. // end_r_winnt
  1030.  
  1031. //
  1032. //  A language ID is a 16 bit value which is the combination of a
  1033. //  primary language ID and a secondary language ID.  The bits are
  1034. //  allocated as follows:
  1035. //
  1036. //       +-----------------------+-------------------------+
  1037. //       |     Sublanguage ID    |   Primary Language ID   |
  1038. //       +-----------------------+-------------------------+
  1039. //        15                   10 9                       0   bit
  1040. //
  1041. //
  1042. //  Language ID creation/extraction macros:
  1043. //
  1044. //    MAKELANGID    - construct language id from a primary language id and
  1045. //                    a sublanguage id.
  1046. //    PRIMARYLANGID - extract primary language id from a language id.
  1047. //    SUBLANGID     - extract sublanguage id from a language id.
  1048. //
  1049.  
  1050. #define MAKELANGID(p, s)       ((((WORD  )(s)) << 10) | (WORD  )(p))
  1051. #define PRIMARYLANGID(lgid)    ((WORD  )(lgid) & 0x3ff)
  1052. #define SUBLANGID(lgid)        ((WORD  )(lgid) >> 10)
  1053.  
  1054.  
  1055. //
  1056. //  A locale ID is a 32 bit value which is the combination of a
  1057. //  language ID, a sort ID, and a reserved area.  The bits are
  1058. //  allocated as follows:
  1059. //
  1060. //       +-------------+---------+-------------------------+
  1061. //       |   Reserved  | Sort ID |      Language ID        |
  1062. //       +-------------+---------+-------------------------+
  1063. //        31         20 19     16 15                      0   bit
  1064. //
  1065. //
  1066. //  Locale ID creation/extraction macros:
  1067. //
  1068. //    MAKELCID            - construct the locale id from a language id and a sort id.
  1069. //    MAKESORTLCID        - construct the locale id from a language id, sort id, and sort version.
  1070. //    LANGIDFROMLCID      - extract the language id from a locale id.
  1071. //    SORTIDFROMLCID      - extract the sort id from a locale id.
  1072. //    SORTVERSIONFROMLCID - extract the sort version from a locale id.
  1073. //
  1074.  
  1075. #define NLS_VALID_LOCALE_MASK  0x000fffff
  1076.  
  1077. #define MAKELCID(lgid, srtid)  ((DWORD)((((DWORD)((WORD  )(srtid))) << 16) |  \
  1078.                                          ((DWORD)((WORD  )(lgid)))))
  1079. #define MAKESORTLCID(lgid, srtid, ver)                                            \
  1080.                                ((DWORD)((MAKELCID(lgid, srtid)) |             \
  1081.                                     (((DWORD)((WORD  )(ver))) << 20)))
  1082. #define LANGIDFROMLCID(lcid)   ((WORD  )(lcid))
  1083. #define SORTIDFROMLCID(lcid)   ((WORD  )((((DWORD)(lcid)) >> 16) & 0xf))
  1084. #define SORTVERSIONFROMLCID(lcid)  ((WORD  )((((DWORD)(lcid)) >> 20) & 0xf))
  1085.  
  1086.  
  1087. //
  1088. //  Default System and User IDs for language and locale.
  1089. //
  1090.  
  1091. #define LANG_SYSTEM_DEFAULT    (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
  1092. #define LANG_USER_DEFAULT      (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
  1093.  
  1094. #define LOCALE_SYSTEM_DEFAULT  (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
  1095. #define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT))
  1096.  
  1097. #define LOCALE_NEUTRAL                                                        \
  1098.           (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT))
  1099.  
  1100.  
  1101. // begin_ntminiport begin_ntndis begin_ntminitape
  1102.  
  1103. //
  1104. // Macros used to eliminate compiler warning generated when formal
  1105. // parameters or local variables are not declared.
  1106. //
  1107. // Use DBG_UNREFERENCED_PARAMETER() when a parameter is not yet
  1108. // referenced but will be once the module is completely developed.
  1109. //
  1110. // Use DBG_UNREFERENCED_LOCAL_VARIABLE() when a local variable is not yet
  1111. // referenced but will be once the module is completely developed.
  1112. //
  1113. // Use UNREFERENCED_PARAMETER() if a parameter will never be referenced.
  1114. //
  1115. // DBG_UNREFERENCED_PARAMETER and DBG_UNREFERENCED_LOCAL_VARIABLE will
  1116. // eventually be made into a null macro to help determine whether there
  1117. // is unfinished work.
  1118. //
  1119.  
  1120. #if ! defined(lint)
  1121. #define UNREFERENCED_PARAMETER(P)          (P)
  1122. #define DBG_UNREFERENCED_PARAMETER(P)      (P)
  1123. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) (V)
  1124.  
  1125. #else // lint
  1126.  
  1127. // Note: lint -e530 says don't complain about uninitialized variables for
  1128. // this varible.  Error 527 has to do with unreachable code.
  1129. // -restore restores checking to the -save state
  1130.  
  1131. #define UNREFERENCED_PARAMETER(P)          \
  1132.     /*lint -save -e527 -e530 */ \
  1133.     { \
  1134.         (P) = (P); \
  1135.     } \
  1136.     /*lint -restore */
  1137. #define DBG_UNREFERENCED_PARAMETER(P)      \
  1138.     /*lint -save -e527 -e530 */ \
  1139.     { \
  1140.         (P) = (P); \
  1141.     } \
  1142.     /*lint -restore */
  1143. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) \
  1144.     /*lint -save -e527 -e530 */ \
  1145.     { \
  1146.         (V) = (V); \
  1147.     } \
  1148.     /*lint -restore */
  1149.  
  1150. #endif // lint
  1151.  
  1152. //
  1153. // Macro used to eliminate compiler warning 4715 within a switch statement
  1154. // when all possible cases have already been accounted for.
  1155. //
  1156. // switch (a & 3) {
  1157. //     case 0: return 1;
  1158. //     case 1: return Foo();
  1159. //     case 2: return Bar();
  1160. //     case 3: return 1;
  1161. //     DEFAULT_UNREACHABLE;
  1162. //
  1163.  
  1164. #if (_MSC_VER > 1200)
  1165. #define DEFAULT_UNREACHABLE default: __assume(0)
  1166. #else
  1167.  
  1168. //
  1169. // Older compilers do not support __assume(), and there is no other free
  1170. // method of eliminating the warning.
  1171. //
  1172.  
  1173. #define DEFAULT_UNREACHABLE
  1174.  
  1175. #endif
  1176.  
  1177. #ifndef WIN32_NO_STATUS 
  1178. /*lint -save -e767 */  
  1179. #define STATUS_WAIT_0                    ((DWORD   )0x00000000L)    
  1180. #define STATUS_ABANDONED_WAIT_0          ((DWORD   )0x00000080L)    
  1181. #define STATUS_USER_APC                  ((DWORD   )0x000000C0L)    
  1182. #define STATUS_TIMEOUT                   ((DWORD   )0x00000102L)    
  1183. #define STATUS_PENDING                   ((DWORD   )0x00000103L)    
  1184. #define DBG_CONTINUE                     ((DWORD   )0x00010002L)    
  1185. #define STATUS_SEGMENT_NOTIFICATION      ((DWORD   )0x40000005L)    
  1186. #define DBG_TERMINATE_THREAD             ((DWORD   )0x40010003L)    
  1187. #define DBG_TERMINATE_PROCESS            ((DWORD   )0x40010004L)    
  1188. #define DBG_CONTROL_C                    ((DWORD   )0x40010005L)    
  1189. #define DBG_CONTROL_BREAK                ((DWORD   )0x40010008L)    
  1190. #define STATUS_GUARD_PAGE_VIOLATION      ((DWORD   )0x80000001L)    
  1191. #define STATUS_DATATYPE_MISALIGNMENT     ((DWORD   )0x80000002L)    
  1192. #define STATUS_BREAKPOINT                ((DWORD   )0x80000003L)    
  1193. #define STATUS_SINGLE_STEP               ((DWORD   )0x80000004L)    
  1194. #define DBG_EXCEPTION_NOT_HANDLED        ((DWORD   )0x80010001L)    
  1195. #define STATUS_ACCESS_VIOLATION          ((DWORD   )0xC0000005L)    
  1196. #define STATUS_IN_PAGE_ERROR             ((DWORD   )0xC0000006L)    
  1197. #define STATUS_INVALID_HANDLE            ((DWORD   )0xC0000008L)    
  1198. #define STATUS_NO_MEMORY                 ((DWORD   )0xC0000017L)    
  1199. #define STATUS_ILLEGAL_INSTRUCTION       ((DWORD   )0xC000001DL)    
  1200. #define STATUS_NONCONTINUABLE_EXCEPTION  ((DWORD   )0xC0000025L)    
  1201. #define STATUS_INVALID_DISPOSITION       ((DWORD   )0xC0000026L)    
  1202. #define STATUS_ARRAY_BOUNDS_EXCEEDED     ((DWORD   )0xC000008CL)    
  1203. #define STATUS_FLOAT_DENORMAL_OPERAND    ((DWORD   )0xC000008DL)    
  1204. #define STATUS_FLOAT_DIVIDE_BY_ZERO      ((DWORD   )0xC000008EL)    
  1205. #define STATUS_FLOAT_INEXACT_RESULT      ((DWORD   )0xC000008FL)    
  1206. #define STATUS_FLOAT_INVALID_OPERATION   ((DWORD   )0xC0000090L)    
  1207. #define STATUS_FLOAT_OVERFLOW            ((DWORD   )0xC0000091L)    
  1208. #define STATUS_FLOAT_STACK_CHECK         ((DWORD   )0xC0000092L)    
  1209. #define STATUS_FLOAT_UNDERFLOW           ((DWORD   )0xC0000093L)    
  1210. #define STATUS_INTEGER_DIVIDE_BY_ZERO    ((DWORD   )0xC0000094L)    
  1211. #define STATUS_INTEGER_OVERFLOW          ((DWORD   )0xC0000095L)    
  1212. #define STATUS_PRIVILEGED_INSTRUCTION    ((DWORD   )0xC0000096L)    
  1213. #define STATUS_STACK_OVERFLOW            ((DWORD   )0xC00000FDL)    
  1214. #define STATUS_CONTROL_C_EXIT            ((DWORD   )0xC000013AL)    
  1215. #define STATUS_FLOAT_MULTIPLE_FAULTS     ((DWORD   )0xC00002B4L)    
  1216. #define STATUS_FLOAT_MULTIPLE_TRAPS      ((DWORD   )0xC00002B5L)    
  1217. #define STATUS_ILLEGAL_VLM_REFERENCE     ((DWORD   )0xC00002C0L)     
  1218. #define STATUS_REG_NAT_CONSUMPTION       ((DWORD   )0xC00002C9L)    
  1219. /*lint -restore */  
  1220. #endif 
  1221. #define MAXIMUM_WAIT_OBJECTS 64     // Maximum number of wait objects
  1222.  
  1223. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  1224.  
  1225. typedef ULONG_PTR KSPIN_LOCK;
  1226. typedef KSPIN_LOCK *PKSPIN_LOCK;
  1227.  
  1228. //
  1229. // Define function to return the current Thread Environment Block
  1230. //
  1231.  
  1232. #ifdef _ALPHA_                          // winnt
  1233. void *_rdteb(void);                     // winnt
  1234. #if defined(_M_ALPHA)                   // winnt
  1235. #pragma intrinsic(_rdteb)               // winnt
  1236. #endif                                  // winnt
  1237. #endif                                  // winnt
  1238.  
  1239. #if defined(_M_ALPHA)
  1240. #define NtCurrentTeb() ((struct _TEB *)_rdteb())
  1241. #else
  1242. struct _TEB *
  1243. NtCurrentTeb(void);
  1244. #endif
  1245.  
  1246. //
  1247. // Define functions to get the address of the current fiber and the
  1248. // current fiber data.
  1249. //
  1250.  
  1251. #ifdef _ALPHA_
  1252.  
  1253. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  1254. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  1255.  
  1256. // begin_ntddk begin_nthal
  1257. //
  1258. // The following flags control the contents of the CONTEXT structure.
  1259. //
  1260.  
  1261. #if !defined(RC_INVOKED)
  1262.  
  1263. #define CONTEXT_ALPHA              0x00020000
  1264.  
  1265. #define CONTEXT_CONTROL         (CONTEXT_ALPHA | 0x00000001L)
  1266. #define CONTEXT_FLOATING_POINT  (CONTEXT_ALPHA | 0x00000002L)
  1267. #define CONTEXT_INTEGER         (CONTEXT_ALPHA | 0x00000004L)
  1268.  
  1269. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  1270.  
  1271. #endif
  1272.  
  1273. #ifndef _PORTABLE_32BIT_CONTEXT
  1274.  
  1275. //
  1276. // Context Frame
  1277. //
  1278. //  This frame has a several purposes: 1) it is used as an argument to
  1279. //  NtContinue, 2) it is used to construct a call frame for APC delivery,
  1280. //  3) it is used to construct a call frame for exception dispatching
  1281. //  in user mode, 4) it is used in the user level thread creation
  1282. //  routines, and 5) it is used to to pass thread state to debuggers.
  1283. //
  1284. //  N.B. Because this record is used as a call frame, it must be EXACTLY
  1285. //  a multiple of 16 bytes in length.
  1286. //
  1287. //  There are two variations of the context structure. This is the real one.
  1288. //
  1289.  
  1290. typedef struct _CONTEXT {
  1291.  
  1292.     //
  1293.     // This section is specified/returned if the ContextFlags word contains
  1294.     // the flag CONTEXT_FLOATING_POINT.
  1295.     //
  1296.  
  1297.     ULONGLONG FltF0;
  1298.     ULONGLONG FltF1;
  1299.     ULONGLONG FltF2;
  1300.     ULONGLONG FltF3;
  1301.     ULONGLONG FltF4;
  1302.     ULONGLONG FltF5;
  1303.     ULONGLONG FltF6;
  1304.     ULONGLONG FltF7;
  1305.     ULONGLONG FltF8;
  1306.     ULONGLONG FltF9;
  1307.     ULONGLONG FltF10;
  1308.     ULONGLONG FltF11;
  1309.     ULONGLONG FltF12;
  1310.     ULONGLONG FltF13;
  1311.     ULONGLONG FltF14;
  1312.     ULONGLONG FltF15;
  1313.     ULONGLONG FltF16;
  1314.     ULONGLONG FltF17;
  1315.     ULONGLONG FltF18;
  1316.     ULONGLONG FltF19;
  1317.     ULONGLONG FltF20;
  1318.     ULONGLONG FltF21;
  1319.     ULONGLONG FltF22;
  1320.     ULONGLONG FltF23;
  1321.     ULONGLONG FltF24;
  1322.     ULONGLONG FltF25;
  1323.     ULONGLONG FltF26;
  1324.     ULONGLONG FltF27;
  1325.     ULONGLONG FltF28;
  1326.     ULONGLONG FltF29;
  1327.     ULONGLONG FltF30;
  1328.     ULONGLONG FltF31;
  1329.  
  1330.     //
  1331.     // This section is specified/returned if the ContextFlags word contains
  1332.     // the flag CONTEXT_INTEGER.
  1333.     //
  1334.     // N.B. The registers gp, sp, and ra are defined in this section, but are
  1335.     //  considered part of the control context rather than part of the integer
  1336.     //  context.
  1337.     //
  1338.  
  1339.     ULONGLONG IntV0;    //  $0: return value register, v0
  1340.     ULONGLONG IntT0;    //  $1: temporary registers, t0 - t7
  1341.     ULONGLONG IntT1;    //  $2:
  1342.     ULONGLONG IntT2;    //  $3:
  1343.     ULONGLONG IntT3;    //  $4:
  1344.     ULONGLONG IntT4;    //  $5:
  1345.     ULONGLONG IntT5;    //  $6:
  1346.     ULONGLONG IntT6;    //  $7:
  1347.     ULONGLONG IntT7;    //  $8:
  1348.     ULONGLONG IntS0;    //  $9: nonvolatile registers, s0 - s5
  1349.     ULONGLONG IntS1;    // $10:
  1350.     ULONGLONG IntS2;    // $11:
  1351.     ULONGLONG IntS3;    // $12:
  1352.     ULONGLONG IntS4;    // $13:
  1353.     ULONGLONG IntS5;    // $14:
  1354.     ULONGLONG IntFp;    // $15: frame pointer register, fp/s6
  1355.     ULONGLONG IntA0;    // $16: argument registers, a0 - a5
  1356.     ULONGLONG IntA1;    // $17:
  1357.     ULONGLONG IntA2;    // $18:
  1358.     ULONGLONG IntA3;    // $19:
  1359.     ULONGLONG IntA4;    // $20:
  1360.     ULONGLONG IntA5;    // $21:
  1361.     ULONGLONG IntT8;    // $22: temporary registers, t8 - t11
  1362.     ULONGLONG IntT9;    // $23:
  1363.     ULONGLONG IntT10;   // $24:
  1364.     ULONGLONG IntT11;   // $25:
  1365.     ULONGLONG IntRa;    // $26: return address register, ra
  1366.     ULONGLONG IntT12;   // $27: temporary register, t12
  1367.     ULONGLONG IntAt;    // $28: assembler temp register, at
  1368.     ULONGLONG IntGp;    // $29: global pointer register, gp
  1369.     ULONGLONG IntSp;    // $30: stack pointer register, sp
  1370.     ULONGLONG IntZero;  // $31: zero register, zero
  1371.  
  1372.     //
  1373.     // This section is specified/returned if the ContextFlags word contains
  1374.     // the flag CONTEXT_FLOATING_POINT.
  1375.     //
  1376.  
  1377.     ULONGLONG Fpcr;     // floating point control register
  1378.     ULONGLONG SoftFpcr; // software extension to FPCR
  1379.  
  1380.     //
  1381.     // This section is specified/returned if the ContextFlags word contains
  1382.     // the flag CONTEXT_CONTROL.
  1383.     //
  1384.     // N.B. The registers gp, sp, and ra are defined in the integer section,
  1385.     //   but are considered part of the control context rather than part of
  1386.     //   the integer context.
  1387.     //
  1388.  
  1389.     ULONGLONG Fir;      // (fault instruction) continuation address
  1390.     DWORD Psr;          // processor status
  1391.  
  1392.     //
  1393.     // The flags values within this flag control the contents of
  1394.     // a CONTEXT record.
  1395.     //
  1396.     // If the context record is used as an input parameter, then
  1397.     // for each portion of the context record controlled by a flag
  1398.     // whose value is set, it is assumed that that portion of the
  1399.     // context record contains valid context. If the context record
  1400.     // is being used to modify a thread's context, then only that
  1401.     // portion of the threads context will be modified.
  1402.     //
  1403.     // If the context record is used as an IN OUT parameter to capture
  1404.     // the context of a thread, then only those portions of the thread's
  1405.     // context corresponding to set flags will be returned.
  1406.     //
  1407.     // The context record is never used as an OUT only parameter.
  1408.     //
  1409.  
  1410.     DWORD ContextFlags;
  1411.     DWORD Fill[4];      // padding for 16-byte stack frame alignment
  1412.  
  1413. } CONTEXT, *PCONTEXT;
  1414.  
  1415. #else
  1416.  
  1417. #error _PORTABLE_32BIT_CONTEXT no longer supported on Alpha.
  1418.  
  1419. #endif // _PORTABLE_32BIT_CONTEXT
  1420.  
  1421. // end_ntddk end_nthal
  1422.  
  1423. #endif // _ALPHA_
  1424.  
  1425.  
  1426. #ifdef _ALPHA_
  1427.  
  1428. VOID
  1429. __jump_unwind (
  1430.     PVOID VirtualFramePointer,
  1431.     PVOID TargetPc
  1432.     );
  1433.  
  1434. #endif // _ALPHA_
  1435.  
  1436.  
  1437. #ifdef _X86_
  1438.  
  1439. //
  1440. // Disable these two pramas that evaluate to "sti" "cli" on x86 so that driver
  1441. // writers to not leave them inadvertantly in their code.
  1442. //
  1443.  
  1444. #if !defined(MIDL_PASS)
  1445. #if !defined(RC_INVOKED)
  1446.  
  1447. #if _MSC_VER >= 1200
  1448. #pragma warning(push)
  1449. #endif
  1450. #pragma warning(disable:4164)   // disable C4164 warning so that apps that
  1451.                                 // build with /Od don't get weird errors !
  1452. #ifdef _M_IX86
  1453. #pragma function(_enable)
  1454. #pragma function(_disable)
  1455. #endif
  1456.  
  1457. #if _MSC_VER >= 1200
  1458. #pragma warning(pop)
  1459. #else
  1460. #pragma warning(default:4164)   // reenable C4164 warning
  1461. #endif
  1462.  
  1463. #endif
  1464. #endif
  1465.  
  1466.  
  1467. #if !defined(MIDL_PASS) && defined(_M_IX86)
  1468. #ifdef __BORLANDC__
  1469. /* Microsoft wants these to be inline functions containing inline assembly.
  1470.    Borland C has trouble with this combination, so we've added simple
  1471.    prototypes here and moved the real functions into the RTL.
  1472.    At least until we support inline assembly from within inline functions.
  1473. */
  1474. #ifdef __MT__ /* Force no prototype unless in MT mode */
  1475. PVOID GetFiberData( void );
  1476. PVOID GetCurrentFiber( void );
  1477. #endif /* __MT__ */
  1478. #else  /* __BORLANDC__ */
  1479. #if _MSC_VER >= 1200
  1480. #pragma warning(push)
  1481. #endif
  1482. #pragma warning (disable:4035)        // disable 4035 (function must return something)
  1483. _inline PVOID GetFiberData( void ) { __asm {
  1484.                                         mov eax, fs:[0x10]
  1485.                                         mov eax,[eax]
  1486.                                         }
  1487.                                      }
  1488. _inline PVOID GetCurrentFiber( void ) { __asm mov eax, fs:[0x10] }
  1489.  
  1490. #if _MSC_VER >= 1200
  1491. #pragma warning(pop)
  1492. #else
  1493. #pragma warning (default:4035)        // Reenable it
  1494. #endif
  1495. #endif /* __BORLANDC__ */
  1496. #endif
  1497.  
  1498. // begin_ntddk begin_wx86
  1499.  
  1500. //
  1501. //  Define the size of the 80387 save area, which is in the context frame.
  1502. //
  1503.  
  1504. #define SIZE_OF_80387_REGISTERS      80
  1505.  
  1506. //
  1507. // The following flags control the contents of the CONTEXT structure.
  1508. //
  1509.  
  1510. #if !defined(RC_INVOKED)
  1511.  
  1512. #define CONTEXT_i386    0x00010000    // this assumes that i386 and
  1513. #define CONTEXT_i486    0x00010000    // i486 have identical context records
  1514.  
  1515. // end_wx86
  1516.  
  1517. #define CONTEXT_CONTROL         (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  1518. #define CONTEXT_INTEGER         (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  1519. #define CONTEXT_SEGMENTS        (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  1520. #define CONTEXT_FLOATING_POINT  (CONTEXT_i386 | 0x00000008L) // 387 state
  1521. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  1522. #define CONTEXT_EXTENDED_REGISTERS  (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
  1523.  
  1524. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  1525.                       CONTEXT_SEGMENTS)
  1526.  
  1527. // begin_wx86
  1528.  
  1529. #endif
  1530.  
  1531. #define MAXIMUM_SUPPORTED_EXTENSION     512
  1532.  
  1533. typedef struct _FLOATING_SAVE_AREA {
  1534.     DWORD   ControlWord;
  1535.     DWORD   StatusWord;
  1536.     DWORD   TagWord;
  1537.     DWORD   ErrorOffset;
  1538.     DWORD   ErrorSelector;
  1539.     DWORD   DataOffset;
  1540.     DWORD   DataSelector;
  1541.     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
  1542.     DWORD   Cr0NpxState;
  1543. } FLOATING_SAVE_AREA;
  1544.  
  1545. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  1546.  
  1547. //
  1548. // Context Frame
  1549. //
  1550. //  This frame has a several purposes: 1) it is used as an argument to
  1551. //  NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1552. //  and 3) it is used in the user level thread creation routines.
  1553. //
  1554. //  The layout of the record conforms to a standard call frame.
  1555. //
  1556.  
  1557. typedef struct _CONTEXT {
  1558.  
  1559.     //
  1560.     // The flags values within this flag control the contents of
  1561.     // a CONTEXT record.
  1562.     //
  1563.     // If the context record is used as an input parameter, then
  1564.     // for each portion of the context record controlled by a flag
  1565.     // whose value is set, it is assumed that that portion of the
  1566.     // context record contains valid context. If the context record
  1567.     // is being used to modify a threads context, then only that
  1568.     // portion of the threads context will be modified.
  1569.     //
  1570.     // If the context record is used as an IN OUT parameter to capture
  1571.     // the context of a thread, then only those portions of the thread's
  1572.     // context corresponding to set flags will be returned.
  1573.     //
  1574.     // The context record is never used as an OUT only parameter.
  1575.     //
  1576.  
  1577.     DWORD ContextFlags;
  1578.  
  1579.     //
  1580.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  1581.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  1582.     // included in CONTEXT_FULL.
  1583.     //
  1584.  
  1585.     DWORD   Dr0;
  1586.     DWORD   Dr1;
  1587.     DWORD   Dr2;
  1588.     DWORD   Dr3;
  1589.     DWORD   Dr6;
  1590.     DWORD   Dr7;
  1591.  
  1592.     //
  1593.     // This section is specified/returned if the
  1594.     // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  1595.     //
  1596.  
  1597.     FLOATING_SAVE_AREA FloatSave;
  1598.  
  1599.     //
  1600.     // This section is specified/returned if the
  1601.     // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  1602.     //
  1603.  
  1604.     DWORD   SegGs;
  1605.     DWORD   SegFs;
  1606.     DWORD   SegEs;
  1607.     DWORD   SegDs;
  1608.  
  1609.     //
  1610.     // This section is specified/returned if the
  1611.     // ContextFlags word contians the flag CONTEXT_INTEGER.
  1612.     //
  1613.  
  1614.     DWORD   Edi;
  1615.     DWORD   Esi;
  1616.     DWORD   Ebx;
  1617.     DWORD   Edx;
  1618.     DWORD   Ecx;
  1619.     DWORD   Eax;
  1620.  
  1621.     //
  1622.     // This section is specified/returned if the
  1623.     // ContextFlags word contians the flag CONTEXT_CONTROL.
  1624.     //
  1625.  
  1626.     DWORD   Ebp;
  1627.     DWORD   Eip;
  1628.     DWORD   SegCs;              // MUST BE SANITIZED
  1629.     DWORD   EFlags;             // MUST BE SANITIZED
  1630.     DWORD   Esp;
  1631.     DWORD   SegSs;
  1632.  
  1633.     //
  1634.     // This section is specified/returned if the ContextFlags word
  1635.     // contains the flag CONTEXT_EXTENDED_REGISTERS.
  1636.     // The format and contexts are processor specific
  1637.     //
  1638.  
  1639.     BYTE    ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  1640.  
  1641. } CONTEXT;
  1642.  
  1643.  
  1644.  
  1645. typedef CONTEXT *PCONTEXT;
  1646.  
  1647. // begin_ntminiport
  1648.  
  1649. #endif //_X86_
  1650.  
  1651.  
  1652. #ifndef _LDT_ENTRY_DEFINED
  1653. #define _LDT_ENTRY_DEFINED
  1654.  
  1655. typedef struct _LDT_ENTRY {
  1656.     WORD    LimitLow;
  1657.     WORD    BaseLow;
  1658.     union {
  1659.         struct {
  1660.             BYTE    BaseMid;
  1661.             BYTE    Flags1;     // Declare as bytes to avoid alignment
  1662.             BYTE    Flags2;     // Problems.
  1663.             BYTE    BaseHi;
  1664.         } Bytes;
  1665.         struct {
  1666.             DWORD   BaseMid : 8;
  1667.             DWORD   Type : 5;
  1668.             DWORD   Dpl : 2;
  1669.             DWORD   Pres : 1;
  1670.             DWORD   LimitHi : 4;
  1671.             DWORD   Sys : 1;
  1672.             DWORD   Reserved_0 : 1;
  1673.             DWORD   Default_Big : 1;
  1674.             DWORD   Granularity : 1;
  1675.             DWORD   BaseHi : 8;
  1676.         } Bits;
  1677.     } HighWord;
  1678. } LDT_ENTRY, *PLDT_ENTRY;
  1679.  
  1680. #endif
  1681.  
  1682.  
  1683. #if defined(_MIPS_)
  1684.  
  1685. //
  1686. // Define functions to get the address of the current fiber and the
  1687. // current fiber data.
  1688. //
  1689.  
  1690. #define GetCurrentFiber() ((*(PNT_TIB *)0x7ffff4a8)->FiberData)
  1691. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  1692.  
  1693. // begin_ntddk begin_nthal
  1694. //
  1695. // The following flags control the contents of the CONTEXT structure.
  1696. //
  1697.  
  1698. #if !defined(RC_INVOKED)
  1699.  
  1700. #define CONTEXT_R4000   0x00010000    // r4000 context
  1701.  
  1702. #define CONTEXT_CONTROL          (CONTEXT_R4000 | 0x00000001)
  1703. #define CONTEXT_FLOATING_POINT   (CONTEXT_R4000 | 0x00000002)
  1704. #define CONTEXT_INTEGER          (CONTEXT_R4000 | 0x00000004)
  1705. #define CONTEXT_EXTENDED_FLOAT   (CONTEXT_FLOATING_POINT | 0x00000008)
  1706. #define CONTEXT_EXTENDED_INTEGER (CONTEXT_INTEGER | 0x00000010)
  1707.  
  1708. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | \
  1709.                       CONTEXT_INTEGER | CONTEXT_EXTENDED_INTEGER)
  1710.  
  1711. #endif
  1712.  
  1713. //
  1714. // Context Frame
  1715. //
  1716. //  N.B. This frame must be exactly a multiple of 16 bytes in length.
  1717. //
  1718. //  This frame has a several purposes: 1) it is used as an argument to
  1719. //  NtContinue, 2) it is used to constuct a call frame for APC delivery,
  1720. //  3) it is used to construct a call frame for exception dispatching
  1721. //  in user mode, and 4) it is used in the user level thread creation
  1722. //  routines.
  1723. //
  1724. //  The layout of the record conforms to a standard call frame.
  1725. //
  1726.  
  1727. typedef struct _CONTEXT {
  1728.  
  1729.     //
  1730.     // This section is always present and is used as an argument build
  1731.     // area.
  1732.     //
  1733.     // N.B. Context records are 0 mod 8 aligned starting with NT 4.0.
  1734.     //
  1735.  
  1736.     union {
  1737.         DWORD Argument[4];
  1738.         ULONGLONG Alignment;
  1739.     };
  1740.  
  1741.     //
  1742.     // The following union defines the 32-bit and 64-bit register context.
  1743.     //
  1744.  
  1745.     union {
  1746.  
  1747.         //
  1748.         // 32-bit context.
  1749.         //
  1750.  
  1751.         struct {
  1752.  
  1753.             //
  1754.             // This section is specified/returned if the ContextFlags contains
  1755.             // the flag CONTEXT_FLOATING_POINT.
  1756.             //
  1757.             // N.B. This section contains the 16 double floating registers f0,
  1758.             //      f2, ..., f30.
  1759.             //
  1760.  
  1761.             DWORD FltF0;
  1762.             DWORD FltF1;
  1763.             DWORD FltF2;
  1764.             DWORD FltF3;
  1765.             DWORD FltF4;
  1766.             DWORD FltF5;
  1767.             DWORD FltF6;
  1768.             DWORD FltF7;
  1769.             DWORD FltF8;
  1770.             DWORD FltF9;
  1771.             DWORD FltF10;
  1772.             DWORD FltF11;
  1773.             DWORD FltF12;
  1774.             DWORD FltF13;
  1775.             DWORD FltF14;
  1776.             DWORD FltF15;
  1777.             DWORD FltF16;
  1778.             DWORD FltF17;
  1779.             DWORD FltF18;
  1780.             DWORD FltF19;
  1781.             DWORD FltF20;
  1782.             DWORD FltF21;
  1783.             DWORD FltF22;
  1784.             DWORD FltF23;
  1785.             DWORD FltF24;
  1786.             DWORD FltF25;
  1787.             DWORD FltF26;
  1788.             DWORD FltF27;
  1789.             DWORD FltF28;
  1790.             DWORD FltF29;
  1791.             DWORD FltF30;
  1792.             DWORD FltF31;
  1793.  
  1794.             //
  1795.             // This section is specified/returned if the ContextFlags contains
  1796.             // the flag CONTEXT_INTEGER.
  1797.             //
  1798.             // N.B. The registers gp, sp, and ra are defined in this section,
  1799.             //      but are considered part of the control context rather than
  1800.             //      part of the integer context.
  1801.             //
  1802.             // N.B. Register zero is not stored in the frame.
  1803.             //
  1804.  
  1805.             DWORD IntZero;
  1806.             DWORD IntAt;
  1807.             DWORD IntV0;
  1808.             DWORD IntV1;
  1809.             DWORD IntA0;
  1810.             DWORD IntA1;
  1811.             DWORD IntA2;
  1812.             DWORD IntA3;
  1813.             DWORD IntT0;
  1814.             DWORD IntT1;
  1815.             DWORD IntT2;
  1816.             DWORD IntT3;
  1817.             DWORD IntT4;
  1818.             DWORD IntT5;
  1819.             DWORD IntT6;
  1820.             DWORD IntT7;
  1821.             DWORD IntS0;
  1822.             DWORD IntS1;
  1823.             DWORD IntS2;
  1824.             DWORD IntS3;
  1825.             DWORD IntS4;
  1826.             DWORD IntS5;
  1827.             DWORD IntS6;
  1828.             DWORD IntS7;
  1829.             DWORD IntT8;
  1830.             DWORD IntT9;
  1831.             DWORD IntK0;
  1832.             DWORD IntK1;
  1833.             DWORD IntGp;
  1834.             DWORD IntSp;
  1835.             DWORD IntS8;
  1836.             DWORD IntRa;
  1837.             DWORD IntLo;
  1838.             DWORD IntHi;
  1839.  
  1840.             //
  1841.             // This section is specified/returned if the ContextFlags word contains
  1842.             // the flag CONTEXT_FLOATING_POINT.
  1843.             //
  1844.  
  1845.             DWORD Fsr;
  1846.  
  1847.             //
  1848.             // This section is specified/returned if the ContextFlags word contains
  1849.             // the flag CONTEXT_CONTROL.
  1850.             //
  1851.             // N.B. The registers gp, sp, and ra are defined in the integer section,
  1852.             //   but are considered part of the control context rather than part of
  1853.             //   the integer context.
  1854.             //
  1855.  
  1856.             DWORD Fir;
  1857.             DWORD Psr;
  1858.  
  1859.             //
  1860.             // The flags values within this flag control the contents of
  1861.             // a CONTEXT record.
  1862.             //
  1863.             // If the context record is used as an input parameter, then
  1864.             // for each portion of the context record controlled by a flag
  1865.             // whose value is set, it is assumed that that portion of the
  1866.             // context record contains valid context. If the context record
  1867.             // is being used to modify a thread's context, then only that
  1868.             // portion of the threads context will be modified.
  1869.             //
  1870.             // If the context record is used as an IN OUT parameter to capture
  1871.             // the context of a thread, then only those portions of the thread's
  1872.             // context corresponding to set flags will be returned.
  1873.             //
  1874.             // The context record is never used as an OUT only parameter.
  1875.             //
  1876.  
  1877.             DWORD ContextFlags;
  1878.         };
  1879.  
  1880.         //
  1881.         // 64-bit context.
  1882.         //
  1883.  
  1884.         struct {
  1885.  
  1886.             //
  1887.             // This section is specified/returned if the ContextFlags contains
  1888.             // the flag CONTEXT_EXTENDED_FLOAT.
  1889.             //
  1890.             // N.B. This section contains the 32 double floating registers f0,
  1891.             //      f1, ..., f31.
  1892.             //
  1893.  
  1894.             ULONGLONG XFltF0;
  1895.             ULONGLONG XFltF1;
  1896.             ULONGLONG XFltF2;
  1897.             ULONGLONG XFltF3;
  1898.             ULONGLONG XFltF4;
  1899.             ULONGLONG XFltF5;
  1900.             ULONGLONG XFltF6;
  1901.             ULONGLONG XFltF7;
  1902.             ULONGLONG XFltF8;
  1903.             ULONGLONG XFltF9;
  1904.             ULONGLONG XFltF10;
  1905.             ULONGLONG XFltF11;
  1906.             ULONGLONG XFltF12;
  1907.             ULONGLONG XFltF13;
  1908.             ULONGLONG XFltF14;
  1909.             ULONGLONG XFltF15;
  1910.             ULONGLONG XFltF16;
  1911.             ULONGLONG XFltF17;
  1912.             ULONGLONG XFltF18;
  1913.             ULONGLONG XFltF19;
  1914.             ULONGLONG XFltF20;
  1915.             ULONGLONG XFltF21;
  1916.             ULONGLONG XFltF22;
  1917.             ULONGLONG XFltF23;
  1918.             ULONGLONG XFltF24;
  1919.             ULONGLONG XFltF25;
  1920.             ULONGLONG XFltF26;
  1921.             ULONGLONG XFltF27;
  1922.             ULONGLONG XFltF28;
  1923.             ULONGLONG XFltF29;
  1924.             ULONGLONG XFltF30;
  1925.             ULONGLONG XFltF31;
  1926.  
  1927.             //
  1928.             // The following sections must exactly overlay the 32-bit context.
  1929.             //
  1930.  
  1931.             DWORD Fill1;
  1932.             DWORD Fill2;
  1933.  
  1934.             //
  1935.             // This section is specified/returned if the ContextFlags contains
  1936.             // the flag CONTEXT_FLOATING_POINT.
  1937.             //
  1938.  
  1939.             DWORD XFsr;
  1940.  
  1941.             //
  1942.             // This section is specified/returned if the ContextFlags contains
  1943.             // the flag CONTEXT_CONTROL.
  1944.             //
  1945.             // N.B. The registers gp, sp, and ra are defined in the integer
  1946.             //      section, but are considered part of the control context
  1947.             //      rather than part of the integer context.
  1948.             //
  1949.  
  1950.             DWORD XFir;
  1951.             DWORD XPsr;
  1952.  
  1953.             //
  1954.             // The flags values within this flag control the contents of
  1955.             // a CONTEXT record.
  1956.             //
  1957.             // If the context record is used as an input parameter, then
  1958.             // for each portion of the context record controlled by a flag
  1959.             // whose value is set, it is assumed that that portion of the
  1960.             // context record contains valid context. If the context record
  1961.             // is being used to modify a thread's context, then only that
  1962.             // portion of the threads context will be modified.
  1963.             //
  1964.             // If the context record is used as an IN OUT parameter to capture
  1965.             // the context of a thread, then only those portions of the thread's
  1966.             // context corresponding to set flags will be returned.
  1967.             //
  1968.             // The context record is never used as an OUT only parameter.
  1969.             //
  1970.  
  1971.             DWORD XContextFlags;
  1972.  
  1973.             //
  1974.             // This section is specified/returned if the ContextFlags contains
  1975.             // the flag CONTEXT_EXTENDED_INTEGER.
  1976.             //
  1977.             // N.B. The registers gp, sp, and ra are defined in this section,
  1978.             //      but are considered part of the control context rather than
  1979.             //      part of the integer  context.
  1980.             //
  1981.             // N.B. Register zero is not stored in the frame.
  1982.             //
  1983.  
  1984.             ULONGLONG XIntZero;
  1985.             ULONGLONG XIntAt;
  1986.             ULONGLONG XIntV0;
  1987.             ULONGLONG XIntV1;
  1988.             ULONGLONG XIntA0;
  1989.             ULONGLONG XIntA1;
  1990.             ULONGLONG XIntA2;
  1991.             ULONGLONG XIntA3;
  1992.             ULONGLONG XIntT0;
  1993.             ULONGLONG XIntT1;
  1994.             ULONGLONG XIntT2;
  1995.             ULONGLONG XIntT3;
  1996.             ULONGLONG XIntT4;
  1997.             ULONGLONG XIntT5;
  1998.             ULONGLONG XIntT6;
  1999.             ULONGLONG XIntT7;
  2000.             ULONGLONG XIntS0;
  2001.             ULONGLONG XIntS1;
  2002.             ULONGLONG XIntS2;
  2003.             ULONGLONG XIntS3;
  2004.             ULONGLONG XIntS4;
  2005.             ULONGLONG XIntS5;
  2006.             ULONGLONG XIntS6;
  2007.             ULONGLONG XIntS7;
  2008.             ULONGLONG XIntT8;
  2009.             ULONGLONG XIntT9;
  2010.             ULONGLONG XIntK0;
  2011.             ULONGLONG XIntK1;
  2012.             ULONGLONG XIntGp;
  2013.             ULONGLONG XIntSp;
  2014.             ULONGLONG XIntS8;
  2015.             ULONGLONG XIntRa;
  2016.             ULONGLONG XIntLo;
  2017.             ULONGLONG XIntHi;
  2018.         };
  2019.     };
  2020. } CONTEXT, *PCONTEXT;
  2021.  
  2022. // end_ntddk end_nthal
  2023.  
  2024. #define CONTEXT32_LENGTH 0x130          // The original 32-bit Context length (pre NT 4.0)
  2025.  
  2026. #endif // MIPS
  2027.  
  2028.  
  2029. #if defined(_MIPS_)
  2030.  
  2031. VOID
  2032. __jump_unwind (
  2033.     PVOID Fp,
  2034.     PVOID TargetPc
  2035.     );
  2036.  
  2037. #endif // MIPS
  2038.  
  2039.  
  2040. #if defined(_PPC_)
  2041.  
  2042.  
  2043. //
  2044. // The address of the TEB is placed into GPR 13 at context switch time
  2045. // and should never be destroyed.  To get the address of the TEB use
  2046. // the compiler intrinsic to access it directly from GPR 13.
  2047. //
  2048.  
  2049. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  2050. unsigned __gregister_get( unsigned const regnum );
  2051. #define NtCurrentTeb() ((struct _TEB *)__gregister_get(13))
  2052. #elif defined(_M_PPC)
  2053. struct _TEB * __builtin_get_gpr13(VOID);
  2054. #define NtCurrentTeb() ((struct _TEB *)__builtin_get_gpr13())
  2055. #endif
  2056.  
  2057.  
  2058. //
  2059. // Define functions to get the address of the current fiber and the
  2060. // current fiber data.
  2061. //
  2062.  
  2063. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  2064. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  2065.  
  2066. // begin_ntddk begin_nthal
  2067. //
  2068. // The following flags control the contents of the CONTEXT structure.
  2069. //
  2070.  
  2071. #if !defined(RC_INVOKED)
  2072.  
  2073. #define CONTEXT_CONTROL         0x00000001L
  2074. #define CONTEXT_FLOATING_POINT  0x00000002L
  2075. #define CONTEXT_INTEGER         0x00000004L
  2076. #define CONTEXT_DEBUG_REGISTERS 0x00000008L
  2077.  
  2078. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  2079.  
  2080. #endif
  2081.  
  2082. //
  2083. // Context Frame
  2084. //
  2085. //  N.B. This frame must be exactly a multiple of 16 bytes in length.
  2086. //
  2087. //  This frame has a several purposes: 1) it is used as an argument to
  2088. //  NtContinue, 2) it is used to constuct a call frame for APC delivery,
  2089. //  3) it is used to construct a call frame for exception dispatching
  2090. //  in user mode, and 4) it is used in the user level thread creation
  2091. //  routines.
  2092. //
  2093. //  Requires at least 8-byte alignment (double)
  2094. //
  2095.  
  2096. typedef struct _CONTEXT {
  2097.  
  2098.     //
  2099.     // This section is specified/returned if the ContextFlags word contains
  2100.     // the flag CONTEXT_FLOATING_POINT.
  2101.     //
  2102.  
  2103.     double Fpr0;                        // Floating registers 0..31
  2104.     double Fpr1;
  2105.     double Fpr2;
  2106.     double Fpr3;
  2107.     double Fpr4;
  2108.     double Fpr5;
  2109.     double Fpr6;
  2110.     double Fpr7;
  2111.     double Fpr8;
  2112.     double Fpr9;
  2113.     double Fpr10;
  2114.     double Fpr11;
  2115.     double Fpr12;
  2116.     double Fpr13;
  2117.     double Fpr14;
  2118.     double Fpr15;
  2119.     double Fpr16;
  2120.     double Fpr17;
  2121.     double Fpr18;
  2122.     double Fpr19;
  2123.     double Fpr20;
  2124.     double Fpr21;
  2125.     double Fpr22;
  2126.     double Fpr23;
  2127.     double Fpr24;
  2128.     double Fpr25;
  2129.     double Fpr26;
  2130.     double Fpr27;
  2131.     double Fpr28;
  2132.     double Fpr29;
  2133.     double Fpr30;
  2134.     double Fpr31;
  2135.     double Fpscr;                       // Floating point status/control reg
  2136.  
  2137.     //
  2138.     // This section is specified/returned if the ContextFlags word contains
  2139.     // the flag CONTEXT_INTEGER.
  2140.     //
  2141.  
  2142.     DWORD Gpr0;                         // General registers 0..31
  2143.     DWORD Gpr1;
  2144.     DWORD Gpr2;
  2145.     DWORD Gpr3;
  2146.     DWORD Gpr4;
  2147.     DWORD Gpr5;
  2148.     DWORD Gpr6;
  2149.     DWORD Gpr7;
  2150.     DWORD Gpr8;
  2151.     DWORD Gpr9;
  2152.     DWORD Gpr10;
  2153.     DWORD Gpr11;
  2154.     DWORD Gpr12;
  2155.     DWORD Gpr13;
  2156.     DWORD Gpr14;
  2157.     DWORD Gpr15;
  2158.     DWORD Gpr16;
  2159.     DWORD Gpr17;
  2160.     DWORD Gpr18;
  2161.     DWORD Gpr19;
  2162.     DWORD Gpr20;
  2163.     DWORD Gpr21;
  2164.     DWORD Gpr22;
  2165.     DWORD Gpr23;
  2166.     DWORD Gpr24;
  2167.     DWORD Gpr25;
  2168.     DWORD Gpr26;
  2169.     DWORD Gpr27;
  2170.     DWORD Gpr28;
  2171.     DWORD Gpr29;
  2172.     DWORD Gpr30;
  2173.     DWORD Gpr31;
  2174.  
  2175.     DWORD Cr;                           // Condition register
  2176.     DWORD Xer;                          // Fixed point exception register
  2177.  
  2178.     //
  2179.     // This section is specified/returned if the ContextFlags word contains
  2180.     // the flag CONTEXT_CONTROL.
  2181.     //
  2182.  
  2183.     DWORD Msr;                          // Machine status register
  2184.     DWORD Iar;                          // Instruction address register
  2185.     DWORD Lr;                           // Link register
  2186.     DWORD Ctr;                          // Count register
  2187.  
  2188.     //
  2189.     // The flags values within this flag control the contents of
  2190.     // a CONTEXT record.
  2191.     //
  2192.     // If the context record is used as an input parameter, then
  2193.     // for each portion of the context record controlled by a flag
  2194.     // whose value is set, it is assumed that that portion of the
  2195.     // context record contains valid context. If the context record
  2196.     // is being used to modify a thread's context, then only that
  2197.     // portion of the threads context will be modified.
  2198.     //
  2199.     // If the context record is used as an IN OUT parameter to capture
  2200.     // the context of a thread, then only those portions of the thread's
  2201.     // context corresponding to set flags will be returned.
  2202.     //
  2203.     // The context record is never used as an OUT only parameter.
  2204.     //
  2205.  
  2206.     DWORD ContextFlags;
  2207.  
  2208.     DWORD Fill[3];                      // Pad out to multiple of 16 bytes
  2209.  
  2210.     //
  2211.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  2212.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  2213.     // included in CONTEXT_FULL.
  2214.     //
  2215.     DWORD Dr0;                          // Breakpoint Register 1
  2216.     DWORD Dr1;                          // Breakpoint Register 2
  2217.     DWORD Dr2;                          // Breakpoint Register 3
  2218.     DWORD Dr3;                          // Breakpoint Register 4
  2219.     DWORD Dr4;                          // Breakpoint Register 5
  2220.     DWORD Dr5;                          // Breakpoint Register 6
  2221.     DWORD Dr6;                          // Debug Status Register
  2222.     DWORD Dr7;                          // Debug Control Register
  2223.  
  2224. } CONTEXT, *PCONTEXT;
  2225.  
  2226. // end_ntddk end_nthal
  2227.  
  2228.  
  2229. //
  2230. // Stack frame header
  2231. //
  2232. //   Order of appearance in stack frame:
  2233. //      Header (six words)
  2234. //      Parameters (at least eight words)
  2235. //      Local variables
  2236. //      Saved GPRs
  2237. //      Saved FPRs
  2238. //
  2239. //   Minimum alignment is 8 bytes
  2240.  
  2241. typedef struct _STACK_FRAME_HEADER {    // GPR 1 points here
  2242.     DWORD BackChain;                    // Addr of previous frame
  2243.     DWORD GlueSaved1;                   // Used by glue code
  2244.     DWORD GlueSaved2;
  2245.     DWORD Reserved1;                    // Reserved
  2246.     DWORD Spare1;                       // Used by tracing, profiling, ...
  2247.     DWORD Spare2;
  2248.  
  2249.     DWORD Parameter0;                   // First 8 parameter words are
  2250.     DWORD Parameter1;                   //   always present
  2251.     DWORD Parameter2;
  2252.     DWORD Parameter3;
  2253.     DWORD Parameter4;
  2254.     DWORD Parameter5;
  2255.     DWORD Parameter6;
  2256.     DWORD Parameter7;
  2257.  
  2258. } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
  2259.  
  2260.  
  2261. VOID
  2262. __jump_unwind (
  2263.     PVOID Fp,
  2264.     PVOID TargetPc
  2265.     );
  2266.  
  2267. #endif // defined(_PPC_)
  2268.  
  2269. #if defined(_MPPC_)
  2270.  
  2271.  
  2272. //
  2273. // The address of the TEB is placed into GPR 13 at context switch time
  2274. // and should never be destroyed.  To get the address of the TEB use
  2275. // the compiler intrinsic to access it directly from GPR 13.
  2276. //
  2277.  
  2278. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  2279. unsigned __gregister_get( unsigned const regnum );
  2280. #define NtCurrentTeb() ((struct _TEB *)__gregister_get(13))
  2281. #elif defined(_M_PPC)
  2282. struct _TEB * __builtin_get_gpr13(VOID);
  2283. #define NtCurrentTeb() ((struct _TEB *)__builtin_get_gpr13())
  2284. #endif
  2285.  
  2286.  
  2287. //
  2288. // Define functions to get the address of the current fiber and the
  2289. // current fiber data.
  2290. //
  2291.  
  2292. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  2293. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  2294.  
  2295. // begin_ntddk begin_nthal
  2296. //
  2297. // The following flags control the contents of the CONTEXT structure.
  2298. //
  2299.  
  2300. #if !defined(RC_INVOKED)
  2301.  
  2302. #define CONTEXT_CONTROL         0x00000001L
  2303. #define CONTEXT_FLOATING_POINT  0x00000002L
  2304. #define CONTEXT_INTEGER         0x00000004L
  2305. #define CONTEXT_DEBUG_REGISTERS 0x00000008L
  2306.  
  2307. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  2308.  
  2309. #endif
  2310.  
  2311. //
  2312. // Context Frame
  2313. //
  2314. //  N.B. This frame must be exactly a multiple of 16 bytes in length.
  2315. //
  2316. //  This frame has a several purposes: 1) it is used as an argument to
  2317. //  NtContinue, 2) it is used to constuct a call frame for APC delivery,
  2318. //  3) it is used to construct a call frame for exception dispatching
  2319. //  in user mode, and 4) it is used in the user level thread creation
  2320. //  routines.
  2321. //
  2322. //  Requires at least 8-byte alignment (double)
  2323. //
  2324.  
  2325. typedef struct _CONTEXT {
  2326.  
  2327.     //
  2328.     // This section is specified/returned if the ContextFlags word contains
  2329.     // the flag CONTEXT_FLOATING_POINT.
  2330.     //
  2331.  
  2332.     double Fpr0;                        // Floating registers 0..31
  2333.     double Fpr1;
  2334.     double Fpr2;
  2335.     double Fpr3;
  2336.     double Fpr4;
  2337.     double Fpr5;
  2338.     double Fpr6;
  2339.     double Fpr7;
  2340.     double Fpr8;
  2341.     double Fpr9;
  2342.     double Fpr10;
  2343.     double Fpr11;
  2344.     double Fpr12;
  2345.     double Fpr13;
  2346.     double Fpr14;
  2347.     double Fpr15;
  2348.     double Fpr16;
  2349.     double Fpr17;
  2350.     double Fpr18;
  2351.     double Fpr19;
  2352.     double Fpr20;
  2353.     double Fpr21;
  2354.     double Fpr22;
  2355.     double Fpr23;
  2356.     double Fpr24;
  2357.     double Fpr25;
  2358.     double Fpr26;
  2359.     double Fpr27;
  2360.     double Fpr28;
  2361.     double Fpr29;
  2362.     double Fpr30;
  2363.     double Fpr31;
  2364.     double Fpscr;                       // Floating point status/control reg
  2365.  
  2366.     //
  2367.     // This section is specified/returned if the ContextFlags word contains
  2368.     // the flag CONTEXT_INTEGER.
  2369.     //
  2370.  
  2371.     DWORD Gpr0;                         // General registers 0..31
  2372.     DWORD Gpr1;
  2373.     DWORD Gpr2;
  2374.     DWORD Gpr3;
  2375.     DWORD Gpr4;
  2376.     DWORD Gpr5;
  2377.     DWORD Gpr6;
  2378.     DWORD Gpr7;
  2379.     DWORD Gpr8;
  2380.     DWORD Gpr9;
  2381.     DWORD Gpr10;
  2382.     DWORD Gpr11;
  2383.     DWORD Gpr12;
  2384.     DWORD Gpr13;
  2385.     DWORD Gpr14;
  2386.     DWORD Gpr15;
  2387.     DWORD Gpr16;
  2388.     DWORD Gpr17;
  2389.     DWORD Gpr18;
  2390.     DWORD Gpr19;
  2391.     DWORD Gpr20;
  2392.     DWORD Gpr21;
  2393.     DWORD Gpr22;
  2394.     DWORD Gpr23;
  2395.     DWORD Gpr24;
  2396.     DWORD Gpr25;
  2397.     DWORD Gpr26;
  2398.     DWORD Gpr27;
  2399.     DWORD Gpr28;
  2400.     DWORD Gpr29;
  2401.     DWORD Gpr30;
  2402.     DWORD Gpr31;
  2403.  
  2404.     DWORD Cr;                           // Condition register
  2405.     DWORD Xer;                          // Fixed point exception register
  2406.  
  2407.     //
  2408.     // This section is specified/returned if the ContextFlags word contains
  2409.     // the flag CONTEXT_CONTROL.
  2410.     //
  2411.  
  2412.     DWORD Msr;                          // Machine status register
  2413.     DWORD Iar;                          // Instruction address register
  2414.     DWORD Lr;                           // Link register
  2415.     DWORD Ctr;                          // Count register
  2416.  
  2417.     //
  2418.     // The flags values within this flag control the contents of
  2419.     // a CONTEXT record.
  2420.     //
  2421.     // If the context record is used as an input parameter, then
  2422.     // for each portion of the context record controlled by a flag
  2423.     // whose value is set, it is assumed that that portion of the
  2424.     // context record contains valid context. If the context record
  2425.     // is being used to modify a thread's context, then only that
  2426.     // portion of the threads context will be modified.
  2427.     //
  2428.     // If the context record is used as an IN OUT parameter to capture
  2429.     // the context of a thread, then only those portions of the thread's
  2430.     // context corresponding to set flags will be returned.
  2431.     //
  2432.     // The context record is never used as an OUT only parameter.
  2433.     //
  2434.  
  2435.     DWORD ContextFlags;
  2436.  
  2437.     DWORD Fill[3];                      // Pad out to multiple of 16 bytes
  2438.  
  2439.     //
  2440.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  2441.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  2442.     // included in CONTEXT_FULL.
  2443.     //
  2444.     DWORD Dr0;                          // Breakpoint Register 1
  2445.     DWORD Dr1;                          // Breakpoint Register 2
  2446.     DWORD Dr2;                          // Breakpoint Register 3
  2447.     DWORD Dr3;                          // Breakpoint Register 4
  2448.     DWORD Dr4;                          // Breakpoint Register 5
  2449.     DWORD Dr5;                          // Breakpoint Register 6
  2450.     DWORD Dr6;                          // Debug Status Register
  2451.     DWORD Dr7;                          // Debug Control Register
  2452.  
  2453. } CONTEXT, *PCONTEXT;
  2454.  
  2455. // end_ntddk end_nthal
  2456.  
  2457.  
  2458. //
  2459. // Stack frame header
  2460. //
  2461. //   Order of appearance in stack frame:
  2462. //      Header (six words)
  2463. //      Parameters (at least eight words)
  2464. //      Local variables
  2465. //      Saved GPRs
  2466. //      Saved FPRs
  2467. //
  2468. //   Minimum alignment is 8 bytes
  2469.  
  2470. typedef struct _STACK_FRAME_HEADER {    // GPR 1 points here
  2471.     DWORD BackChain;                    // Addr of previous frame
  2472.     DWORD GlueSaved1;                   // Used by glue code
  2473.     DWORD GlueSaved2;
  2474.     DWORD Reserved1;                    // Reserved
  2475.     DWORD Spare1;                       // Used by tracing, profiling, ...
  2476.     DWORD Spare2;
  2477.  
  2478.     DWORD Parameter0;                   // First 8 parameter words are
  2479.     DWORD Parameter1;                   //   always present
  2480.     DWORD Parameter2;
  2481.     DWORD Parameter3;
  2482.     DWORD Parameter4;
  2483.     DWORD Parameter5;
  2484.     DWORD Parameter6;
  2485.     DWORD Parameter7;
  2486.  
  2487. } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
  2488.  
  2489.  
  2490. VOID
  2491. __jump_unwind (
  2492.     PVOID Fp,
  2493.     PVOID TargetPc
  2494.     );
  2495.  
  2496. #endif // defined(_MPPC_)
  2497.  
  2498. #if !defined(__midl) && !defined(GENUTIL) && !defined(_GENIA64_) && defined(_IA64_)
  2499.  
  2500. // Please contact INTEL to get IA64-specific information
  2501. // @@BEGIN_DDKSPLIT
  2502. void * _cdecl _rdteb(void);
  2503. #if defined(_M_IA64)                    // winnt
  2504. #pragma intrinsic(_rdteb)               // winnt
  2505. #endif                                  // winnt
  2506. #define NtCurrentTeb()      ((struct _TEB *)_rdteb())
  2507. // @@END_DDKSPLIT
  2508.  
  2509. //
  2510. // Define functions to get the address of the current fiber and the
  2511. // current fiber data.
  2512. //
  2513.  
  2514. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  2515. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  2516.  
  2517. #endif  // !defined(__midl) && !defined(GENUTIL) && !defined(_GENIA64_) && defined(_M_IA64)
  2518.  
  2519. #ifdef _IA64_
  2520.  
  2521. // begin_ntddk begin_nthal
  2522.  
  2523. //
  2524. // The following flags control the contents of the CONTEXT structure.
  2525. //
  2526.  
  2527. #if !defined(RC_INVOKED)
  2528.  
  2529. // Please contact INTEL to get IA64-specific information
  2530. // @@BEGIN_DDKSPLIT
  2531.  
  2532.  
  2533.  
  2534.  
  2535.  
  2536.  
  2537.  
  2538.  
  2539.  
  2540.  
  2541. // @@END_DDKSPLIT
  2542.  
  2543. #endif // !defined(RC_INVOKED)
  2544.  
  2545. //
  2546. // Context Frame
  2547. //
  2548. //  This frame has a several purposes: 1) it is used as an argument to
  2549. //  NtContinue, 2) it is used to construct a call frame for APC delivery,
  2550. //  3) it is used to construct a call frame for exception dispatching
  2551. //  in user mode, 4) it is used in the user level thread creation
  2552. //  routines, and 5) it is used to to pass thread state to debuggers.
  2553. //
  2554. //  N.B. Because this record is used as a call frame, it must be EXACTLY
  2555. //  a multiple of 16 bytes in length and aligned on a 16-byte boundary.
  2556. //
  2557.  
  2558. typedef struct _CONTEXT {
  2559.  
  2560.     //
  2561.     // The flags values within this flag control the contents of
  2562.     // a CONTEXT record.
  2563.     //
  2564.     // If the context record is used as an input parameter, then
  2565.     // for each portion of the context record controlled by a flag
  2566.     // whose value is set, it is assumed that that portion of the
  2567.     // context record contains valid context. If the context record
  2568.     // is being used to modify a thread's context, then only that
  2569.     // portion of the threads context will be modified.
  2570.     //
  2571.     // If the context record is used as an IN OUT parameter to capture
  2572.     // the context of a thread, then only those portions of the thread's
  2573.     // context corresponding to set flags will be returned.
  2574.     //
  2575.     // The context record is never used as an OUT only parameter.
  2576.     //
  2577.  
  2578.     DWORD ContextFlags;
  2579.     DWORD Fill1[3];         // for alignment of following on 16-byte boundary
  2580.  
  2581.     //
  2582.     // This section is specified/returned if the ContextFlags word contains
  2583.     // the flag CONTEXT_DEBUG.
  2584.     //
  2585.     // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
  2586.     //
  2587.  
  2588. // Please contact INTEL to get IA64-specific information
  2589. // @@BEGIN_DDKSPLIT
  2590.  
  2591.  
  2592.  
  2593.  
  2594.  
  2595.  
  2596.  
  2597.  
  2598.  
  2599.  
  2600.  
  2601.  
  2602.  
  2603.  
  2604.  
  2605.  
  2606.  
  2607.  
  2608.     //
  2609.     // This section is specified/returned if the ContextFlags word contains
  2610.     // the flag CONTEXT_LOWER_FLOATING_POINT.
  2611.     //
  2612.  
  2613.  
  2614.  
  2615.  
  2616.  
  2617.  
  2618.  
  2619.  
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.     //
  2629.     // This section is specified/returned if the ContextFlags word contains
  2630.     // the flag CONTEXT_HIGHER_FLOATING_POINT.
  2631.     //
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  
  2645.  
  2646.  
  2647.  
  2648.  
  2649.  
  2650.  
  2651.  
  2652.  
  2653.  
  2654.  
  2655.  
  2656.  
  2657.  
  2658.  
  2659.  
  2660.  
  2661.  
  2662.  
  2663.  
  2664.  
  2665.  
  2666.  
  2667.  
  2668.  
  2669.  
  2670.  
  2671.  
  2672.  
  2673.  
  2674.  
  2675.  
  2676.  
  2677.  
  2678.  
  2679.  
  2680.  
  2681.  
  2682.  
  2683.  
  2684.  
  2685.  
  2686.  
  2687.  
  2688.  
  2689.  
  2690.  
  2691.  
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.  
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.  
  2711.  
  2712.  
  2713.  
  2714.  
  2715.  
  2716.  
  2717.  
  2718.  
  2719.  
  2720.  
  2721.  
  2722.  
  2723.  
  2724.  
  2725.  
  2726.  
  2727.  
  2728.  
  2729.  
  2730.  
  2731.  
  2732.  
  2733.  
  2734.  
  2735.  
  2736.  
  2737.  
  2738.  
  2739.  
  2740.  
  2741.  
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.     //
  2757.     // This section is specified/returned if the ContextFlags word contains
  2758.     // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
  2759.     //
  2760.  
  2761.  
  2762.  
  2763.     //
  2764.     // This section is specified/returned if the ContextFlags word contains
  2765.     // the flag CONTEXT_INTEGER.
  2766.     //
  2767.     // N.B. The registers gp, sp, rp are part of the control context
  2768.     //
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778.  
  2779.  
  2780.  
  2781.  
  2782.  
  2783.  
  2784.  
  2785.  
  2786.  
  2787.  
  2788.  
  2789.  
  2790.  
  2791.  
  2792.  
  2793.  
  2794.  
  2795.  
  2796.  
  2797.  
  2798.  
  2799.  
  2800.  
  2801.  
  2802.  
  2803.  
  2804.  
  2805.  
  2806.  
  2807.  
  2808.  
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.     //
  2816.     // This section is specified/returned if the ContextFlags word contains
  2817.     // the flag CONTEXT_CONTROL.
  2818.     //
  2819.  
  2820.     // Other application registers
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.     // Register stack info
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.     // Trap Status Information
  2835.  
  2836.  
  2837.  
  2838.  
  2839.     // iA32 related control registers
  2840.  
  2841.  
  2842.  
  2843.  
  2844.  
  2845.  
  2846.  
  2847.  
  2848.  
  2849.  
  2850. // @@END_DDKSPLIT
  2851.  
  2852. } CONTEXT, *PCONTEXT;
  2853.  
  2854. //
  2855. // Followings are the data structures that required to support Legacy x86
  2856. //
  2857.  
  2858.  
  2859. //
  2860. //  Define the size of the 80387 save area, which is in the context frame.
  2861. //
  2862.  
  2863. #define SIZE_OF_80387_REGISTERS      80
  2864.  
  2865. //
  2866. // The following flags control the contents of the CONTEXT structure.
  2867. //
  2868.  
  2869. #if !defined(RC_INVOKED)
  2870.  
  2871. #define CONTEXT_i386    0x00010000    // this assumes that i386 and
  2872. #define CONTEXT_i486    0x00010000    // i486 have identical context records
  2873. #define CONTEXT_X86     0x00010000    // X86 have identical context records
  2874.  
  2875. #define CONTEXT86_CONTROL         (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  2876. #define CONTEXT86_INTEGER         (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  2877. #define CONTEXT86_SEGMENTS        (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  2878. #define CONTEXT86_FLOATING_POINT  (CONTEXT_i386 | 0x00000008L) // 387 state
  2879. #define CONTEXT86_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  2880.  
  2881. #define CONTEXT86_FULL (CONTEXT86_CONTROL | CONTEXT86_INTEGER |\
  2882.                       CONTEXT86_SEGMENTS)    // context corresponding to set flags will be returned.
  2883.  
  2884. #endif // !defined(RC_INVOKED)
  2885.  
  2886. typedef struct _FLOATING_SAVE_AREA {
  2887.     DWORD   ControlWord;
  2888.     DWORD   StatusWord;
  2889.     DWORD   TagWord;
  2890.     DWORD   ErrorOffset;
  2891.     DWORD   ErrorSelector;
  2892.     DWORD   DataOffset;
  2893.     DWORD   DataSelector;
  2894.     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
  2895.     DWORD   Cr0NpxState;
  2896. } FLOATING_SAVE_AREA;
  2897.  
  2898. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  2899.  
  2900. //
  2901. // Context Frame
  2902. //
  2903. //  This frame has a several purposes: 1) it is used as an argument to
  2904. //  NtContinue, 2) is is used to constuct a call frame for APC delivery,
  2905. //  and 3) it is used in the user level thread creation routines.
  2906. //
  2907. //  The layout of the record conforms to a standard call frame.
  2908. //
  2909.  
  2910. typedef struct _CONTEXT86 {
  2911.  
  2912.     //
  2913.     // The flags values within this flag control the contents of
  2914.     // a CONTEXT record.
  2915.     //
  2916.     // If the context record is used as an input parameter, then
  2917.     // for each portion of the context record controlled by a flag
  2918.     // whose value is set, it is assumed that that portion of the
  2919.     // context record contains valid context. If the context record
  2920.     // is being used to modify a threads context, then only that
  2921.     // portion of the threads context will be modified.
  2922.     //
  2923.     // If the context record is used as an IN OUT parameter to capture
  2924.     // the context of a thread, then only those portions of the thread's
  2925.     // context corresponding to set flags will be returned.
  2926.     //
  2927.     // The context record is never used as an OUT only parameter.
  2928.     //
  2929.  
  2930.     DWORD ContextFlags;
  2931.  
  2932.     //
  2933.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  2934.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  2935.     // included in CONTEXT_FULL.
  2936.     //
  2937.  
  2938.     DWORD   Dr0;
  2939.     DWORD   Dr1;
  2940.     DWORD   Dr2;
  2941.     DWORD   Dr3;
  2942.     DWORD   Dr6;
  2943.     DWORD   Dr7;
  2944.  
  2945.     //
  2946.     // This section is specified/returned if the
  2947.     // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  2948.     //
  2949.  
  2950.     FLOATING_SAVE_AREA FloatSave;
  2951.  
  2952.     //
  2953.     // This section is specified/returned if the
  2954.     // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  2955.     //
  2956.  
  2957.     DWORD   SegGs;
  2958.     DWORD   SegFs;
  2959.     DWORD   SegEs;
  2960.     DWORD   SegDs;
  2961.  
  2962.     //
  2963.     // This section is specified/returned if the
  2964.     // ContextFlags word contians the flag CONTEXT_INTEGER.
  2965.     //
  2966.     //
  2967.  
  2968.     DWORD   Edi;
  2969.     DWORD   Esi;
  2970.     DWORD   Ebx;
  2971.     DWORD   Edx;
  2972.     DWORD   Ecx;
  2973.     DWORD   Eax;
  2974.  
  2975.     //
  2976.     // This section is specified/returned if the
  2977.     // ContextFlags word contians the flag CONTEXT_CONTROL.
  2978.     //
  2979.  
  2980.     DWORD   Ebp;
  2981.     DWORD   Eip;
  2982.     DWORD   SegCs;              // MUST BE SANITIZED
  2983.     DWORD   EFlags;             // MUST BE SANITIZED
  2984.     DWORD   Esp;
  2985.     DWORD   SegSs;
  2986.  
  2987. } CONTEXT86;
  2988.  
  2989.  
  2990. #ifndef _LDT_ENTRY_DEFINED
  2991. #define _LDT_ENTRY_DEFINED
  2992.  
  2993. //
  2994. //  LDT descriptor entry
  2995. //
  2996.  
  2997. typedef struct _LDT_ENTRY {
  2998.     WORD    LimitLow;
  2999.     WORD    BaseLow;
  3000.     union {
  3001.         struct {
  3002.             BYTE    BaseMid;
  3003.             BYTE    Flags1;     // Declare as bytes to avoid alignment
  3004.             BYTE    Flags2;     // Problems.
  3005.             BYTE    BaseHi;
  3006.         } Bytes;
  3007.         struct {
  3008.             DWORD   BaseMid : 8;
  3009.             DWORD   Type : 5;
  3010.             DWORD   Dpl : 2;
  3011.             DWORD   Pres : 1;
  3012.             DWORD   LimitHi : 4;
  3013.             DWORD   Sys : 1;
  3014.             DWORD   Reserved_0 : 1;
  3015.             DWORD   Default_Big : 1;
  3016.             DWORD   Granularity : 1;
  3017.             DWORD   BaseHi : 8;
  3018.         } Bits;
  3019.     } HighWord;
  3020. } LDT_ENTRY, *PLDT_ENTRY;
  3021.  
  3022. #endif // _LDT_ENTRY_DEFINED
  3023.  
  3024.  
  3025. //
  3026. // Plabel descriptor structure definition
  3027. //
  3028.  
  3029. // Please contact INTEL to get IA64-specific information
  3030. // @@BEGIN_DDKSPLIT
  3031.  
  3032.  
  3033.  
  3034.  
  3035. // @@END_DDKSPLIT
  3036.  
  3037.  
  3038. #endif // _IA64_
  3039.  
  3040.  
  3041. #ifdef _IA64_
  3042.  
  3043. // Please contact INTEL to get IA64-specific information
  3044. // @@BEGIN_DDKSPLIT
  3045.  
  3046.  
  3047.  
  3048.  
  3049.  
  3050.  
  3051. // @@END_DDKSPLIT
  3052.  
  3053. #endif // _IA64_
  3054.  
  3055. #define EXCEPTION_NONCONTINUABLE 0x1    // Noncontinuable exception
  3056. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  3057.  
  3058. //
  3059. // Exception record definition.
  3060. //
  3061.  
  3062. typedef struct _EXCEPTION_RECORD {
  3063.     DWORD    ExceptionCode;
  3064.     DWORD ExceptionFlags;
  3065.     struct _EXCEPTION_RECORD *ExceptionRecord;
  3066.     PVOID ExceptionAddress;
  3067.     DWORD NumberParameters;
  3068.     ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  3069.     } EXCEPTION_RECORD;
  3070.  
  3071. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  3072.  
  3073. typedef struct _EXCEPTION_RECORD32 {
  3074.     DWORD    ExceptionCode;
  3075.     DWORD ExceptionFlags;
  3076.     DWORD ExceptionRecord;
  3077.     DWORD ExceptionAddress;
  3078.     DWORD NumberParameters;
  3079.     DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  3080. } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
  3081.  
  3082. typedef struct _EXCEPTION_RECORD64 {
  3083.     DWORD    ExceptionCode;
  3084.     DWORD ExceptionFlags;
  3085.     DWORD64 ExceptionRecord;
  3086.     DWORD64 ExceptionAddress;
  3087.     DWORD NumberParameters;
  3088.     DWORD __unusedAlignment;
  3089.     DWORD64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  3090. } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
  3091.  
  3092. //
  3093. // Typedef for pointer returned by exception_info()
  3094. //
  3095.  
  3096. typedef struct _EXCEPTION_POINTERS {
  3097.     PEXCEPTION_RECORD ExceptionRecord;
  3098.     PCONTEXT ContextRecord;
  3099. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  3100. typedef PVOID PACCESS_TOKEN;            
  3101. typedef PVOID PSECURITY_DESCRIPTOR;     
  3102. typedef PVOID PSID;     
  3103. ////////////////////////////////////////////////////////////////////////
  3104. //                                                                    //
  3105. //                             ACCESS MASK                            //
  3106. //                                                                    //
  3107. ////////////////////////////////////////////////////////////////////////
  3108.  
  3109. //
  3110. //  Define the access mask as a longword sized structure divided up as
  3111. //  follows:
  3112. //
  3113. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  3114. //       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  3115. //      +---------------+---------------+-------------------------------+
  3116. //      |G|G|G|G|Res'd|A| StandardRights|         SpecificRights        |
  3117. //      |R|W|E|A|     |S|               |                               |
  3118. //      +-+-------------+---------------+-------------------------------+
  3119. //
  3120. //      typedef struct _ACCESS_MASK {
  3121. //          WORD   SpecificRights;
  3122. //          BYTE  StandardRights;
  3123. //          BYTE  AccessSystemAcl : 1;
  3124. //          BYTE  Reserved : 3;
  3125. //          BYTE  GenericAll : 1;
  3126. //          BYTE  GenericExecute : 1;
  3127. //          BYTE  GenericWrite : 1;
  3128. //          BYTE  GenericRead : 1;
  3129. //      } ACCESS_MASK;
  3130. //      typedef ACCESS_MASK *PACCESS_MASK;
  3131. //
  3132. //  but to make life simple for programmer's we'll allow them to specify
  3133. //  a desired access mask by simply OR'ing together mulitple single rights
  3134. //  and treat an access mask as a DWORD.  For example
  3135. //
  3136. //      DesiredAccess = DELETE | READ_CONTROL
  3137. //
  3138. //  So we'll declare ACCESS_MASK as DWORD
  3139. //
  3140.  
  3141. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  3142. typedef DWORD ACCESS_MASK;
  3143. typedef ACCESS_MASK *PACCESS_MASK;
  3144.  
  3145. ////////////////////////////////////////////////////////////////////////
  3146. //                                                                    //
  3147. //                             ACCESS TYPES                           //
  3148. //                                                                    //
  3149. ////////////////////////////////////////////////////////////////////////
  3150.  
  3151.  
  3152. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  3153. //
  3154. //  The following are masks for the predefined standard access types
  3155. //
  3156.  
  3157. #define DELETE                           (0x00010000L)
  3158. #define READ_CONTROL                     (0x00020000L)
  3159. #define WRITE_DAC                        (0x00040000L)
  3160. #define WRITE_OWNER                      (0x00080000L)
  3161. #define SYNCHRONIZE                      (0x00100000L)
  3162.  
  3163. #define STANDARD_RIGHTS_REQUIRED         (0x000F0000L)
  3164.  
  3165. #define STANDARD_RIGHTS_READ             (READ_CONTROL)
  3166. #define STANDARD_RIGHTS_WRITE            (READ_CONTROL)
  3167. #define STANDARD_RIGHTS_EXECUTE          (READ_CONTROL)
  3168.  
  3169. #define STANDARD_RIGHTS_ALL              (0x001F0000L)
  3170.  
  3171. #define SPECIFIC_RIGHTS_ALL              (0x0000FFFFL)
  3172.  
  3173. //
  3174. // AccessSystemAcl access type
  3175. //
  3176.  
  3177. #define ACCESS_SYSTEM_SECURITY           (0x01000000L)
  3178.  
  3179. //
  3180. // MaximumAllowed access type
  3181. //
  3182.  
  3183. #define MAXIMUM_ALLOWED                  (0x02000000L)
  3184.  
  3185. //
  3186. //  These are the generic rights.
  3187. //
  3188.  
  3189. #define GENERIC_READ                     (0x80000000L)
  3190. #define GENERIC_WRITE                    (0x40000000L)
  3191. #define GENERIC_EXECUTE                  (0x20000000L)
  3192. #define GENERIC_ALL                      (0x10000000L)
  3193.  
  3194.  
  3195. //
  3196. //  Define the generic mapping array.  This is used to denote the
  3197. //  mapping of each generic access right to a specific access mask.
  3198. //
  3199.  
  3200. typedef struct _GENERIC_MAPPING {
  3201.     ACCESS_MASK GenericRead;
  3202.     ACCESS_MASK GenericWrite;
  3203.     ACCESS_MASK GenericExecute;
  3204.     ACCESS_MASK GenericAll;
  3205. } GENERIC_MAPPING;
  3206. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  3207.  
  3208.  
  3209.  
  3210. ////////////////////////////////////////////////////////////////////////
  3211. //                                                                    //
  3212. //                        LUID_AND_ATTRIBUTES                         //
  3213. //                                                                    //
  3214. ////////////////////////////////////////////////////////////////////////
  3215. //
  3216. //
  3217.  
  3218.  
  3219. #include <pshpack4.h>
  3220.  
  3221. typedef struct _LUID_AND_ATTRIBUTES {
  3222.     LUID Luid;
  3223.     DWORD Attributes;
  3224.     } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  3225. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  3226. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  3227.  
  3228. #include <poppack.h>
  3229.  
  3230.  
  3231. ////////////////////////////////////////////////////////////////////////
  3232. //                                                                    //
  3233. //              Security Id     (SID)                                 //
  3234. //                                                                    //
  3235. ////////////////////////////////////////////////////////////////////////
  3236. //
  3237. //
  3238. // Pictorially the structure of an SID is as follows:
  3239. //
  3240. //         1   1   1   1   1   1
  3241. //         5   4   3   2   1   0   9   8   7   6   5   4   3   2   1   0
  3242. //      +---------------------------------------------------------------+
  3243. //      |      SubAuthorityCount        |Reserved1 (SBZ)|   Revision    |
  3244. //      +---------------------------------------------------------------+
  3245. //      |                   IdentifierAuthority[0]                      |
  3246. //      +---------------------------------------------------------------+
  3247. //      |                   IdentifierAuthority[1]                      |
  3248. //      +---------------------------------------------------------------+
  3249. //      |                   IdentifierAuthority[2]                      |
  3250. //      +---------------------------------------------------------------+
  3251. //      |                                                               |
  3252. //      +- -  -  -  -  -  -  -  SubAuthority[]  -  -  -  -  -  -  -  - -+
  3253. //      |                                                               |
  3254. //      +---------------------------------------------------------------+
  3255. //
  3256. //
  3257.  
  3258.  
  3259. // begin_ntifs
  3260.  
  3261. #ifndef SID_IDENTIFIER_AUTHORITY_DEFINED
  3262. #define SID_IDENTIFIER_AUTHORITY_DEFINED
  3263. typedef struct _SID_IDENTIFIER_AUTHORITY {
  3264.     BYTE  Value[6];
  3265. } SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY;
  3266. #endif
  3267.  
  3268.  
  3269. #ifndef SID_DEFINED
  3270. #define SID_DEFINED
  3271. typedef struct _SID {
  3272.    BYTE  Revision;
  3273.    BYTE  SubAuthorityCount;
  3274.    SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
  3275. #ifdef MIDL_PASS
  3276.    [size_is(SubAuthorityCount)] DWORD SubAuthority[*];
  3277. #else // MIDL_PASS
  3278.    DWORD SubAuthority[ANYSIZE_ARRAY];
  3279. #endif // MIDL_PASS
  3280. } SID, *PISID;
  3281. #endif
  3282.  
  3283. #define SID_REVISION                     (1)    // Current revision level
  3284. #define SID_MAX_SUB_AUTHORITIES          (15)
  3285. #define SID_RECOMMENDED_SUB_AUTHORITIES  (1)    // Will change to around 6
  3286.                                                 // in a future release.
  3287.  
  3288. typedef enum _SID_NAME_USE {
  3289.     SidTypeUser = 1,
  3290.     SidTypeGroup,
  3291.     SidTypeDomain,
  3292.     SidTypeAlias,
  3293.     SidTypeWellKnownGroup,
  3294.     SidTypeDeletedAccount,
  3295.     SidTypeInvalid,
  3296.     SidTypeUnknown,
  3297.     SidTypeComputer
  3298. } SID_NAME_USE, *PSID_NAME_USE;
  3299.  
  3300. typedef struct _SID_AND_ATTRIBUTES {
  3301.     PSID Sid;
  3302.     DWORD Attributes;
  3303.     } SID_AND_ATTRIBUTES, * PSID_AND_ATTRIBUTES;
  3304.  
  3305. typedef SID_AND_ATTRIBUTES SID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  3306. typedef SID_AND_ATTRIBUTES_ARRAY *PSID_AND_ATTRIBUTES_ARRAY;
  3307.  
  3308.  
  3309.  
  3310. /////////////////////////////////////////////////////////////////////////////
  3311. //                                                                         //
  3312. // Universal well-known SIDs                                               //
  3313. //                                                                         //
  3314. //     Null SID                     S-1-0-0                                //
  3315. //     World                        S-1-1-0                                //
  3316. //     Local                        S-1-2-0                                //
  3317. //     Creator Owner ID             S-1-3-0                                //
  3318. //     Creator Group ID             S-1-3-1                                //
  3319. //     Creator Owner Server ID      S-1-3-2                                //
  3320. //     Creator Group Server ID      S-1-3-3                                //
  3321. //                                                                         //
  3322. //     (Non-unique IDs)             S-1-4                                  //
  3323. //                                                                         //
  3324. /////////////////////////////////////////////////////////////////////////////
  3325.  
  3326. #define SECURITY_NULL_SID_AUTHORITY       {0,0,0,0,0,0}
  3327. #define SECURITY_WORLD_SID_AUTHORITY      {0,0,0,0,0,1}
  3328. #define SECURITY_LOCAL_SID_AUTHORITY      {0,0,0,0,0,2}
  3329. #define SECURITY_CREATOR_SID_AUTHORITY    {0,0,0,0,0,3}
  3330. #define SECURITY_NON_UNIQUE_AUTHORITY     {0,0,0,0,0,4}
  3331.  
  3332. #define SECURITY_NULL_RID                 (0x00000000L)
  3333. #define SECURITY_WORLD_RID                (0x00000000L)
  3334. #define SECURITY_LOCAL_RID                (0X00000000L)
  3335.  
  3336. #define SECURITY_CREATOR_OWNER_RID        (0x00000000L)
  3337. #define SECURITY_CREATOR_GROUP_RID        (0x00000001L)
  3338.  
  3339. #define SECURITY_CREATOR_OWNER_SERVER_RID (0x00000002L)
  3340. #define SECURITY_CREATOR_GROUP_SERVER_RID (0x00000003L)
  3341.  
  3342.  
  3343. /////////////////////////////////////////////////////////////////////////////
  3344. //                                                                         //
  3345. // NT well-known SIDs                                                      //
  3346. //                                                                         //
  3347. //     NT Authority          S-1-5                                         //
  3348. //     Dialup                S-1-5-1                                       //
  3349. //                                                                         //
  3350. //     Network               S-1-5-2                                       //
  3351. //     Batch                 S-1-5-3                                       //
  3352. //     Interactive           S-1-5-4                                       //
  3353. //     Service               S-1-5-6                                       //
  3354. //     AnonymousLogon        S-1-5-7       (aka null logon session)        //
  3355. //     Proxy                 S-1-5-8                                       //
  3356. //     ServerLogon           S-1-5-9       (aka domain controller account) //
  3357. //     Self                  S-1-5-10      (self RID)                      //
  3358. //     Authenticated User    S-1-5-11      (Authenticated user somewhere)  //
  3359. //     Restricted Code       S-1-5-12      (Running restricted code)       //
  3360. //     Terminal Server       S-1-5-13      (Running on Terminal Server)    //
  3361. //                                                                         //
  3362. //     (Logon IDs)           S-1-5-5-X-Y                                   //
  3363. //                                                                         //
  3364. //     (NT non-unique IDs)   S-1-5-0x15-...                                //
  3365. //                                                                         //
  3366. //     (Built-in domain)     s-1-5-0x20                                    //
  3367. //                                                                         //
  3368. /////////////////////////////////////////////////////////////////////////////
  3369.  
  3370.  
  3371. #define SECURITY_NT_AUTHORITY           {0,0,0,0,0,5}   // ntifs
  3372.  
  3373. #define SECURITY_DIALUP_RID             (0x00000001L)
  3374. #define SECURITY_NETWORK_RID            (0x00000002L)
  3375. #define SECURITY_BATCH_RID              (0x00000003L)
  3376. #define SECURITY_INTERACTIVE_RID        (0x00000004L)
  3377. #define SECURITY_SERVICE_RID            (0x00000006L)
  3378. #define SECURITY_ANONYMOUS_LOGON_RID    (0x00000007L)
  3379. #define SECURITY_PROXY_RID              (0x00000008L)
  3380. #define SECURITY_ENTERPRISE_CONTROLLERS_RID (0x00000009L)
  3381. #define SECURITY_SERVER_LOGON_RID       SECURITY_ENTERPRISE_CONTROLLERS_RID
  3382. #define SECURITY_PRINCIPAL_SELF_RID     (0x0000000AL)
  3383. #define SECURITY_AUTHENTICATED_USER_RID (0x0000000BL)
  3384. #define SECURITY_RESTRICTED_CODE_RID    (0x0000000CL)
  3385. #define SECURITY_TERMINAL_SERVER_RID    (0x0000000DL)
  3386.  
  3387.  
  3388. #define SECURITY_LOGON_IDS_RID          (0x00000005L)
  3389. #define SECURITY_LOGON_IDS_RID_COUNT    (3L)
  3390.  
  3391. #define SECURITY_LOCAL_SYSTEM_RID       (0x00000012L)
  3392.  
  3393. #define SECURITY_NT_NON_UNIQUE          (0x00000015L)
  3394.  
  3395. #define SECURITY_BUILTIN_DOMAIN_RID     (0x00000020L)
  3396.  
  3397.  
  3398.  
  3399.  
  3400.  
  3401. /////////////////////////////////////////////////////////////////////////////
  3402. //                                                                         //
  3403. // well-known domain relative sub-authority values (RIDs)...               //
  3404. //                                                                         //
  3405. /////////////////////////////////////////////////////////////////////////////
  3406.  
  3407. // Well-known users ...
  3408.  
  3409. #define DOMAIN_USER_RID_ADMIN          (0x000001F4L)
  3410. #define DOMAIN_USER_RID_GUEST          (0x000001F5L)
  3411. #define DOMAIN_USER_RID_KRBTGT         (0x000001F6L)
  3412.  
  3413.  
  3414.  
  3415. // well-known groups ...
  3416.  
  3417. #define DOMAIN_GROUP_RID_ADMINS        (0x00000200L)
  3418. #define DOMAIN_GROUP_RID_USERS         (0x00000201L)
  3419. #define DOMAIN_GROUP_RID_GUESTS        (0x00000202L)
  3420. #define DOMAIN_GROUP_RID_COMPUTERS     (0x00000203L)
  3421. #define DOMAIN_GROUP_RID_CONTROLLERS   (0x00000204L)
  3422. #define DOMAIN_GROUP_RID_CERT_ADMINS   (0x00000205L)
  3423. #define DOMAIN_GROUP_RID_SCHEMA_ADMINS (0x00000206L)
  3424. #define DOMAIN_GROUP_RID_ENTERPRISE_ADMINS (0x00000207L)
  3425. #define DOMAIN_GROUP_RID_POLICY_ADMINS (0x00000208L)
  3426.  
  3427.  
  3428.  
  3429.  
  3430. // well-known aliases ...
  3431.  
  3432. #define DOMAIN_ALIAS_RID_ADMINS        (0x00000220L)
  3433. #define DOMAIN_ALIAS_RID_USERS         (0x00000221L)
  3434. #define DOMAIN_ALIAS_RID_GUESTS        (0x00000222L)
  3435. #define DOMAIN_ALIAS_RID_POWER_USERS   (0x00000223L)
  3436.  
  3437. #define DOMAIN_ALIAS_RID_ACCOUNT_OPS   (0x00000224L)
  3438. #define DOMAIN_ALIAS_RID_SYSTEM_OPS    (0x00000225L)
  3439. #define DOMAIN_ALIAS_RID_PRINT_OPS     (0x00000226L)
  3440. #define DOMAIN_ALIAS_RID_BACKUP_OPS    (0x00000227L)
  3441.  
  3442. #define DOMAIN_ALIAS_RID_REPLICATOR    (0x00000228L)
  3443. #define DOMAIN_ALIAS_RID_RAS_SERVERS   (0x00000229L)
  3444. #define DOMAIN_ALIAS_RID_PREW2KCOMPACCESS (0x0000022AL)
  3445.  
  3446.  
  3447. //
  3448. // Allocate the System Luid.  The first 1000 LUIDs are reserved.
  3449. // Use #999 here (0x3E7 = 999)
  3450. //
  3451.  
  3452. #define SYSTEM_LUID                     { 0x3E7, 0x0 }
  3453. #define ANONYMOUS_LOGON_LUID            { 0x3e6, 0x0 }
  3454.  
  3455. // end_ntifs
  3456.  
  3457. ////////////////////////////////////////////////////////////////////////
  3458. //                                                                    //
  3459. //                          User and Group related SID attributes     //
  3460. //                                                                    //
  3461. ////////////////////////////////////////////////////////////////////////
  3462.  
  3463. //
  3464. // Group attributes
  3465. //
  3466.  
  3467. #define SE_GROUP_MANDATORY              (0x00000001L)
  3468. #define SE_GROUP_ENABLED_BY_DEFAULT     (0x00000002L)
  3469. #define SE_GROUP_ENABLED                (0x00000004L)
  3470. #define SE_GROUP_OWNER                  (0x00000008L)
  3471. #define SE_GROUP_USE_FOR_DENY_ONLY      (0x00000010L)
  3472. #define SE_GROUP_LOGON_ID               (0xC0000000L)
  3473. #define SE_GROUP_RESOURCE               (0x20000000L)
  3474.  
  3475.  
  3476.  
  3477. //
  3478. // User attributes
  3479. //
  3480.  
  3481. // (None yet defined.)
  3482.  
  3483.  
  3484.  
  3485.  
  3486. ////////////////////////////////////////////////////////////////////////
  3487. //                                                                    //
  3488. //                         ACL  and  ACE                              //
  3489. //                                                                    //
  3490. ////////////////////////////////////////////////////////////////////////
  3491.  
  3492. //
  3493. //  Define an ACL and the ACE format.  The structure of an ACL header
  3494. //  followed by one or more ACEs.  Pictorally the structure of an ACL header
  3495. //  is as follows:
  3496. //
  3497. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  3498. //       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  3499. //      +-------------------------------+---------------+---------------+
  3500. //      |            AclSize            |      Sbz1     |  AclRevision  |
  3501. //      +-------------------------------+---------------+---------------+
  3502. //      |              Sbz2             |           AceCount            |
  3503. //      +-------------------------------+-------------------------------+
  3504. //
  3505. //  The current AclRevision is defined to be ACL_REVISION.
  3506. //
  3507. //  AclSize is the size, in bytes, allocated for the ACL.  This includes
  3508. //  the ACL header, ACES, and remaining free space in the buffer.
  3509. //
  3510. //  AceCount is the number of ACES in the ACL.
  3511. //
  3512.  
  3513. // begin_ntddk begin_ntifs
  3514. // This is the *current* ACL revision
  3515.  
  3516. #define ACL_REVISION     (2)
  3517. #define ACL_REVISION_DS  (4)
  3518.  
  3519. // This is the history of ACL revisions.  Add a new one whenever
  3520. // ACL_REVISION is updated
  3521.  
  3522. #define ACL_REVISION1   (1)
  3523. #define MIN_ACL_REVISION ACL_REVISION2
  3524. #define ACL_REVISION2   (2)
  3525. #define ACL_REVISION3   (3)
  3526. #define ACL_REVISION4   (4)
  3527. #define MAX_ACL_REVISION ACL_REVISION4
  3528.  
  3529. typedef struct _ACL {
  3530.     BYTE  AclRevision;
  3531.     BYTE  Sbz1;
  3532.     WORD   AclSize;
  3533.     WORD   AceCount;
  3534.     WORD   Sbz2;
  3535. } ACL;
  3536. typedef ACL *PACL;
  3537.  
  3538. // end_ntddk
  3539.  
  3540. //
  3541. //  The structure of an ACE is a common ace header followed by ace type
  3542. //  specific data.  Pictorally the structure of the common ace header is
  3543. //  as follows:
  3544. //
  3545. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  3546. //       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  3547. //      +---------------+-------+-------+---------------+---------------+
  3548. //      |            AceSize            |    AceFlags   |     AceType   |
  3549. //      +---------------+-------+-------+---------------+---------------+
  3550. //
  3551. //  AceType denotes the type of the ace, there are some predefined ace
  3552. //  types
  3553. //
  3554. //  AceSize is the size, in bytes, of ace.
  3555. //
  3556. //  AceFlags are the Ace flags for audit and inheritance, defined shortly.
  3557.  
  3558. typedef struct _ACE_HEADER {
  3559.     BYTE  AceType;
  3560.     BYTE  AceFlags;
  3561.     WORD   AceSize;
  3562. } ACE_HEADER;
  3563. typedef ACE_HEADER *PACE_HEADER;
  3564.  
  3565. //
  3566. //  The following are the predefined ace types that go into the AceType
  3567. //  field of an Ace header.
  3568. //
  3569.  
  3570. #define ACCESS_MIN_MS_ACE_TYPE                  (0x0)
  3571. #define ACCESS_ALLOWED_ACE_TYPE                 (0x0)
  3572. #define ACCESS_DENIED_ACE_TYPE                  (0x1)
  3573. #define SYSTEM_AUDIT_ACE_TYPE                   (0x2)
  3574. #define SYSTEM_ALARM_ACE_TYPE                   (0x3)
  3575. #define ACCESS_MAX_MS_V2_ACE_TYPE               (0x3)
  3576.  
  3577. #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE        (0x4)
  3578. #define ACCESS_MAX_MS_V3_ACE_TYPE               (0x4)
  3579.  
  3580. #define ACCESS_MIN_MS_OBJECT_ACE_TYPE           (0x5)
  3581. #define ACCESS_ALLOWED_OBJECT_ACE_TYPE          (0x5)
  3582. #define ACCESS_DENIED_OBJECT_ACE_TYPE           (0x6)
  3583. #define SYSTEM_AUDIT_OBJECT_ACE_TYPE            (0x7)
  3584. #define SYSTEM_ALARM_OBJECT_ACE_TYPE            (0x8)
  3585. #define ACCESS_MAX_MS_OBJECT_ACE_TYPE           (0x8)
  3586.  
  3587. #define ACCESS_MAX_MS_V4_ACE_TYPE               (0x8)
  3588. #define ACCESS_MAX_MS_ACE_TYPE                  (0x8)
  3589.  
  3590. //
  3591. //  The following are the inherit flags that go into the AceFlags field
  3592. //  of an Ace header.
  3593. //
  3594.  
  3595. #define OBJECT_INHERIT_ACE                (0x1)
  3596. #define CONTAINER_INHERIT_ACE             (0x2)
  3597. #define NO_PROPAGATE_INHERIT_ACE          (0x4)
  3598. #define INHERIT_ONLY_ACE                  (0x8)
  3599. #define INHERITED_ACE                     (0x10)
  3600. #define VALID_INHERIT_FLAGS               (0x1F)
  3601.  
  3602.  
  3603. //  The following are the currently defined ACE flags that go into the
  3604. //  AceFlags field of an ACE header.  Each ACE type has its own set of
  3605. //  AceFlags.
  3606. //
  3607. //  SUCCESSFUL_ACCESS_ACE_FLAG - used only with system audit and alarm ACE
  3608. //  types to indicate that a message is generated for successful accesses.
  3609. //
  3610. //  FAILED_ACCESS_ACE_FLAG - used only with system audit and alarm ACE types
  3611. //  to indicate that a message is generated for failed accesses.
  3612. //
  3613.  
  3614. //
  3615. //  SYSTEM_AUDIT and SYSTEM_ALARM AceFlags
  3616. //
  3617. //  These control the signaling of audit and alarms for success or failure.
  3618. //
  3619.  
  3620. #define SUCCESSFUL_ACCESS_ACE_FLAG       (0x40)
  3621. #define FAILED_ACCESS_ACE_FLAG           (0x80)
  3622.  
  3623.  
  3624. //
  3625. //  We'll define the structure of the predefined ACE types.  Pictorally
  3626. //  the structure of the predefined ACE's is as follows:
  3627. //
  3628. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  3629. //       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  3630. //      +---------------+-------+-------+---------------+---------------+
  3631. //      |    AceFlags   | Resd  |Inherit|    AceSize    |     AceType   |
  3632. //      +---------------+-------+-------+---------------+---------------+
  3633. //      |                              Mask                             |
  3634. //      +---------------------------------------------------------------+
  3635. //      |                                                               |
  3636. //      +                                                               +
  3637. //      |                                                               |
  3638. //      +                              Sid                              +
  3639. //      |                                                               |
  3640. //      +                                                               +
  3641. //      |                                                               |
  3642. //      +---------------------------------------------------------------+
  3643. //
  3644. //  Mask is the access mask associated with the ACE.  This is either the
  3645. //  access allowed, access denied, audit, or alarm mask.
  3646. //
  3647. //  Sid is the Sid associated with the ACE.
  3648. //
  3649.  
  3650. //  The following are the four predefined ACE types.
  3651.  
  3652. //  Examine the AceType field in the Header to determine
  3653. //  which structure is appropriate to use for casting.
  3654.  
  3655.  
  3656. typedef struct _ACCESS_ALLOWED_ACE {
  3657.     ACE_HEADER Header;
  3658.     ACCESS_MASK Mask;
  3659.     DWORD SidStart;
  3660. } ACCESS_ALLOWED_ACE;
  3661.  
  3662. typedef ACCESS_ALLOWED_ACE *PACCESS_ALLOWED_ACE;
  3663.  
  3664. typedef struct _ACCESS_DENIED_ACE {
  3665.     ACE_HEADER Header;
  3666.     ACCESS_MASK Mask;
  3667.     DWORD SidStart;
  3668. } ACCESS_DENIED_ACE;
  3669. typedef ACCESS_DENIED_ACE *PACCESS_DENIED_ACE;
  3670.  
  3671. typedef struct _SYSTEM_AUDIT_ACE {
  3672.     ACE_HEADER Header;
  3673.     ACCESS_MASK Mask;
  3674.     DWORD SidStart;
  3675. } SYSTEM_AUDIT_ACE;
  3676. typedef SYSTEM_AUDIT_ACE *PSYSTEM_AUDIT_ACE;
  3677.  
  3678. typedef struct _SYSTEM_ALARM_ACE {
  3679.     ACE_HEADER Header;
  3680.     ACCESS_MASK Mask;
  3681.     DWORD SidStart;
  3682. } SYSTEM_ALARM_ACE;
  3683. typedef SYSTEM_ALARM_ACE *PSYSTEM_ALARM_ACE;
  3684.  
  3685. // end_ntifs
  3686.  
  3687.  
  3688. typedef struct _ACCESS_ALLOWED_OBJECT_ACE {
  3689.     ACE_HEADER Header;
  3690.     ACCESS_MASK Mask;
  3691.     DWORD Flags;
  3692.     GUID ObjectType;
  3693.     GUID InheritedObjectType;
  3694.     DWORD SidStart;
  3695. } ACCESS_ALLOWED_OBJECT_ACE, *PACCESS_ALLOWED_OBJECT_ACE;
  3696.  
  3697. typedef struct _ACCESS_DENIED_OBJECT_ACE {
  3698.     ACE_HEADER Header;
  3699.     ACCESS_MASK Mask;
  3700.     DWORD Flags;
  3701.     GUID ObjectType;
  3702.     GUID InheritedObjectType;
  3703.     DWORD SidStart;
  3704. } ACCESS_DENIED_OBJECT_ACE, *PACCESS_DENIED_OBJECT_ACE;
  3705.  
  3706. typedef struct _SYSTEM_AUDIT_OBJECT_ACE {
  3707.     ACE_HEADER Header;
  3708.     ACCESS_MASK Mask;
  3709.     DWORD Flags;
  3710.     GUID ObjectType;
  3711.     GUID InheritedObjectType;
  3712.     DWORD SidStart;
  3713. } SYSTEM_AUDIT_OBJECT_ACE, *PSYSTEM_AUDIT_OBJECT_ACE;
  3714.  
  3715. typedef struct _SYSTEM_ALARM_OBJECT_ACE {
  3716.     ACE_HEADER Header;
  3717.     ACCESS_MASK Mask;
  3718.     DWORD Flags;
  3719.     GUID ObjectType;
  3720.     GUID InheritedObjectType;
  3721.     DWORD SidStart;
  3722. } SYSTEM_ALARM_OBJECT_ACE, *PSYSTEM_ALARM_OBJECT_ACE;
  3723.  
  3724. //
  3725. // Currently define Flags for "OBJECT" ACE types.
  3726. //
  3727.  
  3728. #define ACE_OBJECT_TYPE_PRESENT           0x1
  3729. #define ACE_INHERITED_OBJECT_TYPE_PRESENT 0x2
  3730.  
  3731.  
  3732. //
  3733. //  The following declarations are used for setting and querying information
  3734. //  about and ACL.  First are the various information classes available to
  3735. //  the user.
  3736. //
  3737.  
  3738. typedef enum _ACL_INFORMATION_CLASS {
  3739.     AclRevisionInformation = 1,
  3740.     AclSizeInformation
  3741. } ACL_INFORMATION_CLASS;
  3742.  
  3743. //
  3744. //  This record is returned/sent if the user is requesting/setting the
  3745. //  AclRevisionInformation
  3746. //
  3747.  
  3748. typedef struct _ACL_REVISION_INFORMATION {
  3749.     DWORD AclRevision;
  3750. } ACL_REVISION_INFORMATION;
  3751. typedef ACL_REVISION_INFORMATION *PACL_REVISION_INFORMATION;
  3752.  
  3753. //
  3754. //  This record is returned if the user is requesting AclSizeInformation
  3755. //
  3756.  
  3757. typedef struct _ACL_SIZE_INFORMATION {
  3758.     DWORD AceCount;
  3759.     DWORD AclBytesInUse;
  3760.     DWORD AclBytesFree;
  3761. } ACL_SIZE_INFORMATION;
  3762. typedef ACL_SIZE_INFORMATION *PACL_SIZE_INFORMATION;
  3763.  
  3764.  
  3765. ////////////////////////////////////////////////////////////////////////
  3766. //                                                                    //
  3767. //                             SECURITY_DESCRIPTOR                    //
  3768. //                                                                    //
  3769. ////////////////////////////////////////////////////////////////////////
  3770. //
  3771. //  Define the Security Descriptor and related data types.
  3772. //  This is an opaque data structure.
  3773. //
  3774.  
  3775. // begin_ntddk begin_ntifs
  3776. //
  3777. // Current security descriptor revision value
  3778. //
  3779.  
  3780. #define SECURITY_DESCRIPTOR_REVISION     (1)
  3781. #define SECURITY_DESCRIPTOR_REVISION1    (1)
  3782.  
  3783. // end_ntddk
  3784.  
  3785.  
  3786. #define SECURITY_DESCRIPTOR_MIN_LENGTH   (sizeof(SECURITY_DESCRIPTOR))
  3787.  
  3788.  
  3789. typedef WORD   SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
  3790.  
  3791. #define SE_OWNER_DEFAULTED               (0x0001)
  3792. #define SE_GROUP_DEFAULTED               (0x0002)
  3793. #define SE_DACL_PRESENT                  (0x0004)
  3794. #define SE_DACL_DEFAULTED                (0x0008)
  3795. #define SE_SACL_PRESENT                  (0x0010)
  3796. #define SE_SACL_DEFAULTED                (0x0020)
  3797. #define SE_DACL_AUTO_INHERIT_REQ         (0x0100)
  3798. #define SE_SACL_AUTO_INHERIT_REQ         (0x0200)
  3799. #define SE_DACL_AUTO_INHERITED           (0x0400)
  3800. #define SE_SACL_AUTO_INHERITED           (0x0800)
  3801. #define SE_DACL_PROTECTED                (0x1000)
  3802. #define SE_SACL_PROTECTED                (0x2000)
  3803. #define SE_RM_CONTROL_VALID              (0x4000)
  3804. #define SE_SELF_RELATIVE                 (0x8000)
  3805.  
  3806. //
  3807. //  Where:
  3808. //
  3809. //      SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the
  3810. //          SID pointed to by the Owner field was provided by a
  3811. //          defaulting mechanism rather than explicitly provided by the
  3812. //          original provider of the security descriptor.  This may
  3813. //          affect the treatment of the SID with respect to inheritence
  3814. //          of an owner.
  3815. //
  3816. //      SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the
  3817. //          SID in the Group field was provided by a defaulting mechanism
  3818. //          rather than explicitly provided by the original provider of
  3819. //          the security descriptor.  This may affect the treatment of
  3820. //          the SID with respect to inheritence of a primary group.
  3821. //
  3822. //      SE_DACL_PRESENT - This boolean flag, when set, indicates that the
  3823. //          security descriptor contains a discretionary ACL.  If this
  3824. //          flag is set and the Dacl field of the SECURITY_DESCRIPTOR is
  3825. //          null, then a null ACL is explicitly being specified.
  3826. //
  3827. //      SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the
  3828. //          ACL pointed to by the Dacl field was provided by a defaulting
  3829. //          mechanism rather than explicitly provided by the original
  3830. //          provider of the security descriptor.  This may affect the
  3831. //          treatment of the ACL with respect to inheritence of an ACL.
  3832. //          This flag is ignored if the DaclPresent flag is not set.
  3833. //
  3834. //      SE_SACL_PRESENT - This boolean flag, when set,  indicates that the
  3835. //          security descriptor contains a system ACL pointed to by the
  3836. //          Sacl field.  If this flag is set and the Sacl field of the
  3837. //          SECURITY_DESCRIPTOR is null, then an empty (but present)
  3838. //          ACL is being specified.
  3839. //
  3840. //      SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the
  3841. //          ACL pointed to by the Sacl field was provided by a defaulting
  3842. //          mechanism rather than explicitly provided by the original
  3843. //          provider of the security descriptor.  This may affect the
  3844. //          treatment of the ACL with respect to inheritence of an ACL.
  3845. //          This flag is ignored if the SaclPresent flag is not set.
  3846. //
  3847. //      SE_SELF_RELATIVE - This boolean flag, when set, indicates that the
  3848. //          security descriptor is in self-relative form.  In this form,
  3849. //          all fields of the security descriptor are contiguous in memory
  3850. //          and all pointer fields are expressed as offsets from the
  3851. //          beginning of the security descriptor.  This form is useful
  3852. //          for treating security descriptors as opaque data structures
  3853. //          for transmission in communication protocol or for storage on
  3854. //          secondary media.
  3855. //
  3856. //
  3857. //
  3858. // Pictorially the structure of a security descriptor is as follows:
  3859. //
  3860. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  3861. //       1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  3862. //      +---------------------------------------------------------------+
  3863. //      |            Control            |Reserved1 (SBZ)|   Revision    |
  3864. //      +---------------------------------------------------------------+
  3865. //      |                            Owner                              |
  3866. //      +---------------------------------------------------------------+
  3867. //      |                            Group                              |
  3868. //      +---------------------------------------------------------------+
  3869. //      |                            Sacl                               |
  3870. //      +---------------------------------------------------------------+
  3871. //      |                            Dacl                               |
  3872. //      +---------------------------------------------------------------+
  3873. //
  3874. // In general, this data structure should be treated opaquely to ensure future
  3875. // compatibility.
  3876. //
  3877. //
  3878.  
  3879. typedef struct _SECURITY_DESCRIPTOR_RELATIVE {
  3880.     BYTE  Revision;
  3881.     BYTE  Sbz1;
  3882.     SECURITY_DESCRIPTOR_CONTROL Control;
  3883.     DWORD Owner;
  3884.     DWORD Group;
  3885.     DWORD Sacl;
  3886.     DWORD Dacl;
  3887.     } SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
  3888.  
  3889. typedef struct _SECURITY_DESCRIPTOR {
  3890.    BYTE  Revision;
  3891.    BYTE  Sbz1;
  3892.    SECURITY_DESCRIPTOR_CONTROL Control;
  3893.    PSID Owner;
  3894.    PSID Group;
  3895.    PACL Sacl;
  3896.    PACL Dacl;
  3897.  
  3898.    } SECURITY_DESCRIPTOR, *PISECURITY_DESCRIPTOR;
  3899.  
  3900. // end_ntifs
  3901.  
  3902. // Where:
  3903. //
  3904. //     Revision - Contains the revision level of the security
  3905. //         descriptor.  This allows this structure to be passed between
  3906. //         systems or stored on disk even though it is expected to
  3907. //         change in the future.
  3908. //
  3909. //     Control - A set of flags which qualify the meaning of the
  3910. //         security descriptor or individual fields of the security
  3911. //         descriptor.
  3912. //
  3913. //     Owner - is a pointer to an SID representing an object's owner.
  3914. //         If this field is null, then no owner SID is present in the
  3915. //         security descriptor.  If the security descriptor is in
  3916. //         self-relative form, then this field contains an offset to
  3917. //         the SID, rather than a pointer.
  3918. //
  3919. //     Group - is a pointer to an SID representing an object's primary
  3920. //         group.  If this field is null, then no primary group SID is
  3921. //         present in the security descriptor.  If the security descriptor
  3922. //         is in self-relative form, then this field contains an offset to
  3923. //         the SID, rather than a pointer.
  3924. //
  3925. //     Sacl - is a pointer to a system ACL.  This field value is only
  3926. //         valid if the DaclPresent control flag is set.  If the
  3927. //         SaclPresent flag is set and this field is null, then a null
  3928. //         ACL  is specified.  If the security descriptor is in
  3929. //         self-relative form, then this field contains an offset to
  3930. //         the ACL, rather than a pointer.
  3931. //
  3932. //     Dacl - is a pointer to a discretionary ACL.  This field value is
  3933. //         only valid if the DaclPresent control flag is set.  If the
  3934. //         DaclPresent flag is set and this field is null, then a null
  3935. //         ACL (unconditionally granting access) is specified.  If the
  3936. //         security descriptor is in self-relative form, then this field
  3937. //         contains an offset to the ACL, rather than a pointer.
  3938. //
  3939.  
  3940.  
  3941.  
  3942. ////////////////////////////////////////////////////////////////////////
  3943. //                                                                    //
  3944. //               Object Type list for AccessCheckByType               //
  3945. //                                                                    //
  3946. ////////////////////////////////////////////////////////////////////////
  3947.  
  3948. typedef struct _OBJECT_TYPE_LIST {
  3949.     WORD   Level;
  3950.     WORD   Sbz;
  3951.     GUID *ObjectType;
  3952. } OBJECT_TYPE_LIST, *POBJECT_TYPE_LIST;
  3953.  
  3954. //
  3955. // DS values for Level
  3956. //
  3957.  
  3958. #define ACCESS_OBJECT_GUID       0
  3959. #define ACCESS_PROPERTY_SET_GUID 1
  3960. #define ACCESS_PROPERTY_GUID     2
  3961.  
  3962. #define ACCESS_MAX_LEVEL         4
  3963.  
  3964. //
  3965. // Parameters to NtAccessCheckByTypeAndAditAlarm
  3966. //
  3967.  
  3968. typedef enum _AUDIT_EVENT_TYPE {
  3969.     AuditEventObjectAccess,
  3970.     AuditEventDirectoryServiceAccess
  3971. } AUDIT_EVENT_TYPE, *PAUDIT_EVENT_TYPE;
  3972.  
  3973. #define AUDIT_ALLOW_NO_PRIVILEGE 0x1
  3974.  
  3975. //
  3976. // DS values for Source and ObjectTypeName
  3977. //
  3978.  
  3979. #define ACCESS_DS_SOURCE_A "DS"
  3980. #define ACCESS_DS_SOURCE_W L"DS"
  3981. #define ACCESS_DS_OBJECT_TYPE_NAME_A "Directory Service Object"
  3982. #define ACCESS_DS_OBJECT_TYPE_NAME_W L"Directory Service Object"
  3983.  
  3984. // end_ntsrv
  3985.  
  3986. ////////////////////////////////////////////////////////////////////////
  3987. //                                                                    //
  3988. //               Privilege Related Data Structures                    //
  3989. //                                                                    //
  3990. ////////////////////////////////////////////////////////////////////////
  3991.  
  3992.  
  3993. // begin_ntddk begin_nthal begin_ntifs
  3994. //
  3995. // Privilege attributes
  3996. //
  3997.  
  3998. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  3999. #define SE_PRIVILEGE_ENABLED            (0x00000002L)
  4000. #define SE_PRIVILEGE_USED_FOR_ACCESS    (0x80000000L)
  4001.  
  4002. //
  4003. // Privilege Set Control flags
  4004. //
  4005.  
  4006. #define PRIVILEGE_SET_ALL_NECESSARY    (1)
  4007.  
  4008. //
  4009. //  Privilege Set - This is defined for a privilege set of one.
  4010. //                  If more than one privilege is needed, then this structure
  4011. //                  will need to be allocated with more space.
  4012. //
  4013. //  Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  4014. //  structure (defined in se.h)
  4015. //
  4016.  
  4017. typedef struct _PRIVILEGE_SET {
  4018.     DWORD PrivilegeCount;
  4019.     DWORD Control;
  4020.     LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  4021.     } PRIVILEGE_SET, * PPRIVILEGE_SET;
  4022.  
  4023.  
  4024. ////////////////////////////////////////////////////////////////////////
  4025. //                                                                    //
  4026. //               NT Defined Privileges                                //
  4027. //                                                                    //
  4028. ////////////////////////////////////////////////////////////////////////
  4029.  
  4030. #define SE_CREATE_TOKEN_NAME              TEXT("SeCreateTokenPrivilege")
  4031. #define SE_ASSIGNPRIMARYTOKEN_NAME        TEXT("SeAssignPrimaryTokenPrivilege")
  4032. #define SE_LOCK_MEMORY_NAME               TEXT("SeLockMemoryPrivilege")
  4033. #define SE_INCREASE_QUOTA_NAME            TEXT("SeIncreaseQuotaPrivilege")
  4034. #define SE_UNSOLICITED_INPUT_NAME         TEXT("SeUnsolicitedInputPrivilege")
  4035. #define SE_MACHINE_ACCOUNT_NAME           TEXT("SeMachineAccountPrivilege")
  4036. #define SE_TCB_NAME                       TEXT("SeTcbPrivilege")
  4037. #define SE_SECURITY_NAME                  TEXT("SeSecurityPrivilege")
  4038. #define SE_TAKE_OWNERSHIP_NAME            TEXT("SeTakeOwnershipPrivilege")
  4039. #define SE_LOAD_DRIVER_NAME               TEXT("SeLoadDriverPrivilege")
  4040. #define SE_SYSTEM_PROFILE_NAME            TEXT("SeSystemProfilePrivilege")
  4041. #define SE_SYSTEMTIME_NAME                TEXT("SeSystemtimePrivilege")
  4042. #define SE_PROF_SINGLE_PROCESS_NAME       TEXT("SeProfileSingleProcessPrivilege")
  4043. #define SE_INC_BASE_PRIORITY_NAME         TEXT("SeIncreaseBasePriorityPrivilege")
  4044. #define SE_CREATE_PAGEFILE_NAME           TEXT("SeCreatePagefilePrivilege")
  4045. #define SE_CREATE_PERMANENT_NAME          TEXT("SeCreatePermanentPrivilege")
  4046. #define SE_BACKUP_NAME                    TEXT("SeBackupPrivilege")
  4047. #define SE_RESTORE_NAME                   TEXT("SeRestorePrivilege")
  4048. #define SE_SHUTDOWN_NAME                  TEXT("SeShutdownPrivilege")
  4049. #define SE_DEBUG_NAME                     TEXT("SeDebugPrivilege")
  4050. #define SE_AUDIT_NAME                     TEXT("SeAuditPrivilege")
  4051. #define SE_SYSTEM_ENVIRONMENT_NAME        TEXT("SeSystemEnvironmentPrivilege")
  4052. #define SE_CHANGE_NOTIFY_NAME             TEXT("SeChangeNotifyPrivilege")
  4053. #define SE_REMOTE_SHUTDOWN_NAME           TEXT("SeRemoteShutdownPrivilege")
  4054. #define SE_UNDOCK_NAME                    TEXT("SeUndockPrivilege")
  4055. #define SE_SYNC_AGENT_NAME                TEXT("SeSyncAgentPrivilege")
  4056. #define SE_ENABLE_DELEGATION_NAME         TEXT("SeEnableDelegationPrivilege")
  4057.  
  4058.  
  4059. ////////////////////////////////////////////////////////////////////
  4060. //                                                                //
  4061. //           Security Quality Of Service                          //
  4062. //                                                                //
  4063. //                                                                //
  4064. ////////////////////////////////////////////////////////////////////
  4065.  
  4066. // begin_ntddk begin_nthal begin_ntifs
  4067. //
  4068. // Impersonation Level
  4069. //
  4070. // Impersonation level is represented by a pair of bits in Windows.
  4071. // If a new impersonation level is added or lowest value is changed from
  4072. // 0 to something else, fix the Windows CreateFile call.
  4073. //
  4074.  
  4075. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  4076.     SecurityAnonymous,
  4077.     SecurityIdentification,
  4078.     SecurityImpersonation,
  4079.     SecurityDelegation
  4080.     } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  4081.  
  4082. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  4083.  
  4084. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  4085.  
  4086.  
  4087. ////////////////////////////////////////////////////////////////////
  4088. //                                                                //
  4089. //           Token Object Definitions                             //
  4090. //                                                                //
  4091. //                                                                //
  4092. ////////////////////////////////////////////////////////////////////
  4093.  
  4094.  
  4095. //
  4096. // Token Specific Access Rights.
  4097. //
  4098.  
  4099. #define TOKEN_ASSIGN_PRIMARY    (0x0001)
  4100. #define TOKEN_DUPLICATE         (0x0002)
  4101. #define TOKEN_IMPERSONATE       (0x0004)
  4102. #define TOKEN_QUERY             (0x0008)
  4103. #define TOKEN_QUERY_SOURCE      (0x0010)
  4104. #define TOKEN_ADJUST_PRIVILEGES (0x0020)
  4105. #define TOKEN_ADJUST_GROUPS     (0x0040)
  4106. #define TOKEN_ADJUST_DEFAULT    (0x0080)
  4107. #define TOKEN_ADJUST_SESSIONID  (0x0100)
  4108.  
  4109. #define TOKEN_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED  |\
  4110.                           TOKEN_ASSIGN_PRIMARY      |\
  4111.                           TOKEN_DUPLICATE           |\
  4112.                           TOKEN_IMPERSONATE         |\
  4113.                           TOKEN_QUERY               |\
  4114.                           TOKEN_QUERY_SOURCE        |\
  4115.                           TOKEN_ADJUST_PRIVILEGES   |\
  4116.                           TOKEN_ADJUST_GROUPS       |\
  4117.                           TOKEN_ADJUST_SESSIONID    |\
  4118.                           TOKEN_ADJUST_DEFAULT)
  4119.  
  4120.  
  4121. #define TOKEN_READ       (STANDARD_RIGHTS_READ      |\
  4122.                           TOKEN_QUERY)
  4123.  
  4124.  
  4125. #define TOKEN_WRITE      (STANDARD_RIGHTS_WRITE     |\
  4126.                           TOKEN_ADJUST_PRIVILEGES   |\
  4127.                           TOKEN_ADJUST_GROUPS       |\
  4128.                           TOKEN_ADJUST_DEFAULT)
  4129.  
  4130. #define TOKEN_EXECUTE    (STANDARD_RIGHTS_EXECUTE)
  4131.  
  4132.  
  4133. //
  4134. //
  4135. // Token Types
  4136. //
  4137.  
  4138. typedef enum _TOKEN_TYPE {
  4139.     TokenPrimary = 1,
  4140.     TokenImpersonation
  4141.     } TOKEN_TYPE;
  4142. typedef TOKEN_TYPE *PTOKEN_TYPE;
  4143.  
  4144.  
  4145. //
  4146. // Token Information Classes.
  4147. //
  4148.  
  4149.  
  4150. typedef enum _TOKEN_INFORMATION_CLASS {
  4151.     TokenUser = 1,
  4152.     TokenGroups,
  4153.     TokenPrivileges,
  4154.     TokenOwner,
  4155.     TokenPrimaryGroup,
  4156.     TokenDefaultDacl,
  4157.     TokenSource,
  4158.     TokenType,
  4159.     TokenImpersonationLevel,
  4160.     TokenStatistics,
  4161.     TokenRestrictedSids,
  4162.     TokenSessionId
  4163. } TOKEN_INFORMATION_CLASS, *PTOKEN_INFORMATION_CLASS;
  4164.  
  4165. //
  4166. // Token information class structures
  4167. //
  4168.  
  4169.  
  4170. typedef struct _TOKEN_USER {
  4171.     SID_AND_ATTRIBUTES User;
  4172. } TOKEN_USER, *PTOKEN_USER;
  4173.  
  4174. typedef struct _TOKEN_GROUPS {
  4175.     DWORD GroupCount;
  4176.     SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
  4177. } TOKEN_GROUPS, *PTOKEN_GROUPS;
  4178.  
  4179.  
  4180. typedef struct _TOKEN_PRIVILEGES {
  4181.     DWORD PrivilegeCount;
  4182.     LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
  4183. } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
  4184.  
  4185.  
  4186. typedef struct _TOKEN_OWNER {
  4187.     PSID Owner;
  4188. } TOKEN_OWNER, *PTOKEN_OWNER;
  4189.  
  4190.  
  4191. typedef struct _TOKEN_PRIMARY_GROUP {
  4192.     PSID PrimaryGroup;
  4193. } TOKEN_PRIMARY_GROUP, *PTOKEN_PRIMARY_GROUP;
  4194.  
  4195.  
  4196. typedef struct _TOKEN_DEFAULT_DACL {
  4197.     PACL DefaultDacl;
  4198. } TOKEN_DEFAULT_DACL, *PTOKEN_DEFAULT_DACL;
  4199.  
  4200.  
  4201.  
  4202. #define TOKEN_SOURCE_LENGTH 8
  4203.  
  4204. typedef struct _TOKEN_SOURCE {
  4205.     CHAR SourceName[TOKEN_SOURCE_LENGTH];
  4206.     LUID SourceIdentifier;
  4207. } TOKEN_SOURCE, *PTOKEN_SOURCE;
  4208.  
  4209.  
  4210. typedef struct _TOKEN_STATISTICS {
  4211.     LUID TokenId;
  4212.     LUID AuthenticationId;
  4213.     LARGE_INTEGER ExpirationTime;
  4214.     TOKEN_TYPE TokenType;
  4215.     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  4216.     DWORD DynamicCharged;
  4217.     DWORD DynamicAvailable;
  4218.     DWORD GroupCount;
  4219.     DWORD PrivilegeCount;
  4220.     LUID ModifiedId;
  4221. } TOKEN_STATISTICS, *PTOKEN_STATISTICS;
  4222.  
  4223.  
  4224.  
  4225. typedef struct _TOKEN_CONTROL {
  4226.     LUID TokenId;
  4227.     LUID AuthenticationId;
  4228.     LUID ModifiedId;
  4229.     TOKEN_SOURCE TokenSource;
  4230.     } TOKEN_CONTROL, *PTOKEN_CONTROL;
  4231.  
  4232. //
  4233. // Security Tracking Mode
  4234. //
  4235.  
  4236. #define SECURITY_DYNAMIC_TRACKING      (TRUE)
  4237. #define SECURITY_STATIC_TRACKING       (FALSE)
  4238.  
  4239. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  4240.                     * PSECURITY_CONTEXT_TRACKING_MODE;
  4241.  
  4242.  
  4243.  
  4244. //
  4245. // Quality Of Service
  4246. //
  4247.  
  4248. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  4249.     DWORD Length;
  4250.     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  4251.     SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  4252.     BOOLEAN EffectiveOnly;
  4253.     } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  4254.  
  4255.  
  4256. //
  4257. // Used to represent information related to a thread impersonation
  4258. //
  4259.  
  4260. typedef struct _SE_IMPERSONATION_STATE {
  4261.     PACCESS_TOKEN Token;
  4262.     BOOLEAN CopyOnOpen;
  4263.     BOOLEAN EffectiveOnly;
  4264.     SECURITY_IMPERSONATION_LEVEL Level;
  4265. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  4266.  
  4267. #define DISABLE_MAX_PRIVILEGE   0x1 
  4268.  
  4269. typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  4270.  
  4271. #define OWNER_SECURITY_INFORMATION       (0X00000001L)
  4272. #define GROUP_SECURITY_INFORMATION       (0X00000002L)
  4273. #define DACL_SECURITY_INFORMATION        (0X00000004L)
  4274. #define SACL_SECURITY_INFORMATION        (0X00000008L)
  4275.  
  4276. #define PROTECTED_DACL_SECURITY_INFORMATION     (0x80000000L)
  4277. #define PROTECTED_SACL_SECURITY_INFORMATION     (0x40000000L)
  4278. #define UNPROTECTED_DACL_SECURITY_INFORMATION   (0x20000000L)
  4279. #define UNPROTECTED_SACL_SECURITY_INFORMATION   (0x10000000L)
  4280.  
  4281. #define PROCESS_TERMINATE         (0x0001)  
  4282. #define PROCESS_CREATE_THREAD     (0x0002)  
  4283. #define PROCESS_SET_SESSIONID     (0x0004)  
  4284. #define PROCESS_VM_OPERATION      (0x0008)  
  4285. #define PROCESS_VM_READ           (0x0010)  
  4286. #define PROCESS_VM_WRITE          (0x0020)  
  4287. #define PROCESS_DUP_HANDLE        (0x0040)  
  4288. #define PROCESS_CREATE_PROCESS    (0x0080)  
  4289. #define PROCESS_SET_QUOTA         (0x0100)  
  4290. #define PROCESS_SET_INFORMATION   (0x0200)  
  4291. #define PROCESS_QUERY_INFORMATION (0x0400)  
  4292. #define PROCESS_ALL_ACCESS        (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4293.                                    0xFFF)
  4294.  
  4295. // end_ntifs
  4296.  
  4297. #define MAXIMUM_PROCESSORS 32
  4298.  
  4299. #define THREAD_TERMINATE               (0x0001)  
  4300. #define THREAD_SUSPEND_RESUME          (0x0002)  
  4301. #define THREAD_GET_CONTEXT             (0x0008)  
  4302. #define THREAD_SET_CONTEXT             (0x0010)  
  4303. #define THREAD_SET_INFORMATION         (0x0020)  
  4304. #define THREAD_QUERY_INFORMATION       (0x0040)  
  4305. #define THREAD_SET_THREAD_TOKEN        (0x0080)
  4306. #define THREAD_IMPERSONATE             (0x0100)
  4307. #define THREAD_DIRECT_IMPERSONATION    (0x0200)
  4308. // begin_ntddk begin_wdm begin_ntifs
  4309.  
  4310. #define THREAD_ALL_ACCESS         (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4311.                                    0x3FF)
  4312.  
  4313. // end_ntddk end_wdm end_ntifs
  4314. #define JOB_OBJECT_ASSIGN_PROCESS           (0x0001)
  4315. #define JOB_OBJECT_SET_ATTRIBUTES           (0x0002)
  4316. #define JOB_OBJECT_QUERY                    (0x0004)
  4317. #define JOB_OBJECT_TERMINATE                (0x0008)
  4318. #define JOB_OBJECT_SET_SECURITY_ATTRIBUTES  (0x0010)
  4319. #define JOB_OBJECT_ALL_ACCESS       (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4320.                                         0x1F )
  4321. #define TLS_MINIMUM_AVAILABLE 64    
  4322.  
  4323. typedef struct _NT_TIB {
  4324.     struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
  4325.     PVOID StackBase;
  4326.     PVOID StackLimit;
  4327.     PVOID SubSystemTib;
  4328.     union {
  4329.         PVOID FiberData;
  4330.         DWORD Version;
  4331.     };
  4332.     PVOID ArbitraryUserPointer;
  4333.     struct _NT_TIB *Self;
  4334. } NT_TIB;
  4335. typedef NT_TIB *PNT_TIB;
  4336.  
  4337. #if !defined(_X86_) && !defined(_IA64_) && !defined(_AXP64_)
  4338. #define WX86
  4339. #endif
  4340.  
  4341. #define THREAD_BASE_PRIORITY_LOWRT  15  // value that gets a thread to LowRealtime-1
  4342. #define THREAD_BASE_PRIORITY_MAX    2   // maximum thread base priority boost
  4343. #define THREAD_BASE_PRIORITY_MIN    -2  // minimum thread base priority boost
  4344. #define THREAD_BASE_PRIORITY_IDLE   -15 // value that gets a thread to idle
  4345.  
  4346. typedef struct _QUOTA_LIMITS {
  4347.     SIZE_T PagedPoolLimit;
  4348.     SIZE_T NonPagedPoolLimit;
  4349.     SIZE_T MinimumWorkingSetSize;
  4350.     SIZE_T MaximumWorkingSetSize;
  4351.     SIZE_T PagefileLimit;
  4352.     LARGE_INTEGER TimeLimit;
  4353. } QUOTA_LIMITS;
  4354. typedef QUOTA_LIMITS *PQUOTA_LIMITS;
  4355.  
  4356. typedef struct _IO_COUNTERS {
  4357.     ULONGLONG  ReadOperationCount;
  4358.     ULONGLONG  WriteOperationCount;
  4359.     ULONGLONG  OtherOperationCount;
  4360.     ULONGLONG ReadTransferCount;
  4361.     ULONGLONG WriteTransferCount;
  4362.     ULONGLONG OtherTransferCount;
  4363. } IO_COUNTERS;
  4364. typedef IO_COUNTERS *PIO_COUNTERS;
  4365. //
  4366.  
  4367. typedef struct _JOBOBJECT_BASIC_ACCOUNTING_INFORMATION {
  4368.     LARGE_INTEGER TotalUserTime;
  4369.     LARGE_INTEGER TotalKernelTime;
  4370.     LARGE_INTEGER ThisPeriodTotalUserTime;
  4371.     LARGE_INTEGER ThisPeriodTotalKernelTime;
  4372.     DWORD TotalPageFaultCount;
  4373.     DWORD TotalProcesses;
  4374.     DWORD ActiveProcesses;
  4375.     DWORD TotalTerminatedProcesses;
  4376. } JOBOBJECT_BASIC_ACCOUNTING_INFORMATION, *PJOBOBJECT_BASIC_ACCOUNTING_INFORMATION;
  4377.  
  4378. typedef struct _JOBOBJECT_BASIC_LIMIT_INFORMATION {
  4379.     LARGE_INTEGER PerProcessUserTimeLimit;
  4380.     LARGE_INTEGER PerJobUserTimeLimit;
  4381.     DWORD LimitFlags;
  4382.     SIZE_T MinimumWorkingSetSize;
  4383.     SIZE_T MaximumWorkingSetSize;
  4384.     DWORD ActiveProcessLimit;
  4385.     ULONG_PTR Affinity;
  4386.     DWORD PriorityClass;
  4387.     DWORD SchedulingClass;
  4388. } JOBOBJECT_BASIC_LIMIT_INFORMATION, *PJOBOBJECT_BASIC_LIMIT_INFORMATION;
  4389.  
  4390. typedef struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
  4391.     JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
  4392.     IO_COUNTERS IoInfo;
  4393.     SIZE_T ProcessMemoryLimit;
  4394.     SIZE_T JobMemoryLimit;
  4395.     SIZE_T PeakProcessMemoryUsed;
  4396.     SIZE_T PeakJobMemoryUsed;
  4397. } JOBOBJECT_EXTENDED_LIMIT_INFORMATION, *PJOBOBJECT_EXTENDED_LIMIT_INFORMATION;
  4398.  
  4399. typedef struct _JOBOBJECT_BASIC_PROCESS_ID_LIST {
  4400.     DWORD NumberOfAssignedProcesses;
  4401.     DWORD NumberOfProcessIdsInList;
  4402.     ULONG_PTR ProcessIdList[1];
  4403. } JOBOBJECT_BASIC_PROCESS_ID_LIST, *PJOBOBJECT_BASIC_PROCESS_ID_LIST;
  4404.  
  4405. typedef struct _JOBOBJECT_BASIC_UI_RESTRICTIONS {
  4406.     DWORD UIRestrictionsClass;
  4407. } JOBOBJECT_BASIC_UI_RESTRICTIONS, *PJOBOBJECT_BASIC_UI_RESTRICTIONS;
  4408.  
  4409. typedef struct _JOBOBJECT_SECURITY_LIMIT_INFORMATION {
  4410.     DWORD SecurityLimitFlags ;
  4411.     HANDLE JobToken ;
  4412.     PTOKEN_GROUPS SidsToDisable ;
  4413.     PTOKEN_PRIVILEGES PrivilegesToDelete ;
  4414.     PTOKEN_GROUPS RestrictedSids ;
  4415. } JOBOBJECT_SECURITY_LIMIT_INFORMATION, *PJOBOBJECT_SECURITY_LIMIT_INFORMATION ;
  4416.  
  4417. typedef struct _JOBOBJECT_END_OF_JOB_TIME_INFORMATION {
  4418.     DWORD EndOfJobTimeAction;
  4419. } JOBOBJECT_END_OF_JOB_TIME_INFORMATION, *PJOBOBJECT_END_OF_JOB_TIME_INFORMATION;
  4420.  
  4421. typedef struct _JOBOBJECT_ASSOCIATE_COMPLETION_PORT {
  4422.     PVOID CompletionKey;
  4423.     HANDLE CompletionPort;
  4424. } JOBOBJECT_ASSOCIATE_COMPLETION_PORT, *PJOBOBJECT_ASSOCIATE_COMPLETION_PORT;
  4425.  
  4426. typedef struct _JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION {
  4427.     JOBOBJECT_BASIC_ACCOUNTING_INFORMATION BasicInfo;
  4428.     IO_COUNTERS IoInfo;
  4429. } JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION, *PJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION;
  4430.  
  4431. #define JOB_OBJECT_TERMINATE_AT_END_OF_JOB  0
  4432. #define JOB_OBJECT_POST_AT_END_OF_JOB       1
  4433.  
  4434. //
  4435. // Completion Port Messages for job objects
  4436. //
  4437. // These values are returned via the lpNumberOfBytesTransferred parameter
  4438. //
  4439.  
  4440. #define JOB_OBJECT_MSG_END_OF_JOB_TIME          1
  4441. #define JOB_OBJECT_MSG_END_OF_PROCESS_TIME      2
  4442. #define JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT     3
  4443. #define JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO      4
  4444. #define JOB_OBJECT_MSG_NEW_PROCESS              6
  4445. #define JOB_OBJECT_MSG_EXIT_PROCESS             7
  4446. #define JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS    8
  4447. #define JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT     9
  4448. #define JOB_OBJECT_MSG_JOB_MEMORY_LIMIT         10
  4449.  
  4450.  
  4451. //
  4452. // Basic Limits
  4453. //
  4454. #define JOB_OBJECT_LIMIT_WORKINGSET                 0x00000001
  4455. #define JOB_OBJECT_LIMIT_PROCESS_TIME               0x00000002
  4456. #define JOB_OBJECT_LIMIT_JOB_TIME                   0x00000004
  4457. #define JOB_OBJECT_LIMIT_ACTIVE_PROCESS             0x00000008
  4458. #define JOB_OBJECT_LIMIT_AFFINITY                   0x00000010
  4459. #define JOB_OBJECT_LIMIT_PRIORITY_CLASS             0x00000020
  4460. #define JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME          0x00000040
  4461. #define JOB_OBJECT_LIMIT_SCHEDULING_CLASS           0x00000080
  4462.  
  4463. //
  4464. // Extended Limits
  4465. //
  4466. #define JOB_OBJECT_LIMIT_PROCESS_MEMORY             0x00000100
  4467. #define JOB_OBJECT_LIMIT_JOB_MEMORY                 0x00000200
  4468. #define JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION 0x00000400
  4469. #define JOB_OBJECT_LIMIT_BREAKAWAY_OK               0x00000800
  4470. #define JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK        0x00001000
  4471.  
  4472. #define JOB_OBJECT_LIMIT_RESERVED1                  0x00002000
  4473. #define JOB_OBJECT_LIMIT_RESERVED2                  0x00004000
  4474. #define JOB_OBJECT_LIMIT_RESERVED3                  0x00008000
  4475. #define JOB_OBJECT_LIMIT_RESERVED4                  0x00010000
  4476. #define JOB_OBJECT_LIMIT_RESERVED5                  0x00020000
  4477. #define JOB_OBJECT_LIMIT_RESERVED6                  0x00040000
  4478.  
  4479.  
  4480. #define JOB_OBJECT_LIMIT_VALID_FLAGS            0x0007ffff
  4481.  
  4482. #define JOB_OBJECT_BASIC_LIMIT_VALID_FLAGS      0x000000ff
  4483. #define JOB_OBJECT_EXTENDED_LIMIT_VALID_FLAGS   0x00001fff
  4484. #define JOB_OBJECT_RESERVED_LIMIT_VALID_FLAGS   0x0007ffff
  4485.  
  4486. //
  4487. // UI restrictions for jobs
  4488. //
  4489.  
  4490. #define JOB_OBJECT_UILIMIT_NONE             0x00000000
  4491.  
  4492. #define JOB_OBJECT_UILIMIT_HANDLES          0x00000001
  4493. #define JOB_OBJECT_UILIMIT_READCLIPBOARD    0x00000002
  4494. #define JOB_OBJECT_UILIMIT_WRITECLIPBOARD   0x00000004
  4495. #define JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS 0x00000008
  4496. #define JOB_OBJECT_UILIMIT_DISPLAYSETTINGS  0x00000010
  4497. #define JOB_OBJECT_UILIMIT_GLOBALATOMS      0x00000020
  4498. #define JOB_OBJECT_UILIMIT_DESKTOP          0x00000040
  4499. #define JOB_OBJECT_UILIMIT_EXITWINDOWS      0x00000080
  4500.  
  4501. #define JOB_OBJECT_UILIMIT_ALL              0x000000FF
  4502.  
  4503. #define JOB_OBJECT_UI_VALID_FLAGS           0x000000FF
  4504.  
  4505. #define JOB_OBJECT_SECURITY_NO_ADMIN            0x00000001
  4506. #define JOB_OBJECT_SECURITY_RESTRICTED_TOKEN    0x00000002
  4507. #define JOB_OBJECT_SECURITY_ONLY_TOKEN          0x00000004
  4508. #define JOB_OBJECT_SECURITY_FILTER_TOKENS       0x00000008
  4509.  
  4510. #define JOB_OBJECT_SECURITY_VALID_FLAGS         0x0000000f
  4511.  
  4512. typedef enum _JOBOBJECTINFOCLASS {
  4513.     JobObjectBasicAccountingInformation = 1,
  4514.     JobObjectBasicLimitInformation,
  4515.     JobObjectBasicProcessIdList,
  4516.     JobObjectBasicUIRestrictions,
  4517.     JobObjectSecurityLimitInformation,
  4518.     JobObjectEndOfJobTimeInformation,
  4519.     JobObjectAssociateCompletionPortInformation,
  4520.     JobObjectBasicAndIoAccountingInformation,
  4521.     JobObjectExtendedLimitInformation,
  4522.     MaxJobObjectInfoClass
  4523.     } JOBOBJECTINFOCLASS;
  4524. //
  4525. #define EVENT_MODIFY_STATE      0x0002  
  4526. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  4527. #define MUTANT_QUERY_STATE      0x0001
  4528.  
  4529. #define MUTANT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|\
  4530.                           MUTANT_QUERY_STATE)
  4531. #define SEMAPHORE_MODIFY_STATE      0x0002  
  4532. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  4533. //
  4534. // Timer Specific Access Rights.
  4535. //
  4536.  
  4537. #define TIMER_QUERY_STATE       0x0001
  4538. #define TIMER_MODIFY_STATE      0x0002
  4539.  
  4540. #define TIMER_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|\
  4541.                           TIMER_QUERY_STATE|TIMER_MODIFY_STATE)
  4542.  
  4543.  
  4544. #define TIME_ZONE_ID_UNKNOWN  0
  4545. #define TIME_ZONE_ID_STANDARD 1
  4546. #define TIME_ZONE_ID_DAYLIGHT 2
  4547.  
  4548. #define PROCESSOR_INTEL_386     386
  4549. #define PROCESSOR_INTEL_486     486
  4550. #define PROCESSOR_INTEL_PENTIUM 586
  4551. #define PROCESSOR_INTEL_IA64    2200
  4552. #define PROCESSOR_MIPS_R4000    4000    // incl R4101 & R3910 for Windows CE
  4553. #define PROCESSOR_ALPHA_21064   21064
  4554. #define PROCESSOR_PPC_601       601
  4555. #define PROCESSOR_PPC_603       603
  4556. #define PROCESSOR_PPC_604       604
  4557. #define PROCESSOR_PPC_620       620
  4558. #define PROCESSOR_HITACHI_SH3   10003   // Windows CE
  4559. #define PROCESSOR_HITACHI_SH3E  10004   // Windows CE
  4560. #define PROCESSOR_HITACHI_SH4   10005   // Windows CE
  4561. #define PROCESSOR_MOTOROLA_821  821     // Windows CE
  4562. #define PROCESSOR_SHx_SH3       103     // Windows CE
  4563. #define PROCESSOR_SHx_SH4       104     // Windows CE
  4564. #define PROCESSOR_STRONGARM     2577    // Windows CE - 0xA11
  4565. #define PROCESSOR_ARM720        1824    // Windows CE - 0x720
  4566. #define PROCESSOR_ARM820        2080    // Windows CE - 0x820
  4567. #define PROCESSOR_ARM920        2336    // Windows CE - 0x920
  4568. #define PROCESSOR_ARM_7TDMI     70001   // Windows CE
  4569. #define PROCESSOR_OPTIL         0x494f  // MSIL
  4570.  
  4571. #define PROCESSOR_ARCHITECTURE_INTEL    0
  4572. #define PROCESSOR_ARCHITECTURE_MIPS     1
  4573. #define PROCESSOR_ARCHITECTURE_ALPHA    2
  4574. #define PROCESSOR_ARCHITECTURE_PPC      3
  4575. #define PROCESSOR_ARCHITECTURE_SHX      4
  4576. #define PROCESSOR_ARCHITECTURE_ARM      5
  4577. #define PROCESSOR_ARCHITECTURE_IA64     6
  4578. #define PROCESSOR_ARCHITECTURE_ALPHA64  7
  4579. #define PROCESSOR_ARCHITECTURE_MSIL     8
  4580.  
  4581. #define PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF
  4582.  
  4583. #define PF_FLOATING_POINT_PRECISION_ERRATA  0   
  4584. #define PF_FLOATING_POINT_EMULATED          1   
  4585. #define PF_COMPARE_EXCHANGE_DOUBLE          2   
  4586. #define PF_MMX_INSTRUCTIONS_AVAILABLE       3   
  4587. #define PF_PPC_MOVEMEM_64BIT_OK             4   
  4588. #define PF_ALPHA_BYTE_INSTRUCTIONS          5   
  4589. #define PF_XMMI_INSTRUCTIONS_AVAILABLE      6   
  4590. #define PF_3DNOW_INSTRUCTIONS_AVAILABLE     7   
  4591. #define PF_RDTSC_INSTRUCTION_AVAILABLE      8   
  4592. #define PF_PAE_ENABLED                      9   
  4593. typedef struct _MEMORY_BASIC_INFORMATION {
  4594.     PVOID BaseAddress;
  4595.     PVOID AllocationBase;
  4596.     DWORD AllocationProtect;
  4597.     SIZE_T RegionSize;
  4598.     DWORD State;
  4599.     DWORD Protect;
  4600.     DWORD Type;
  4601. } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
  4602.  
  4603. typedef struct _MEMORY_BASIC_INFORMATION_VLM {
  4604.     union {
  4605.         PVOID64 BaseAddress;
  4606.         ULONGLONG BaseAddressAsUlongLong;
  4607.     };
  4608.     union {
  4609.         PVOID64 AllocationBase;
  4610.         ULONGLONG AllocationBaseAsUlongLong;
  4611.     };
  4612.     ULONGLONG RegionSize;
  4613.     DWORD AllocationProtect;
  4614.     DWORD State;
  4615.     DWORD Protect;
  4616.     DWORD Type;
  4617. } MEMORY_BASIC_INFORMATION_VLM, *PMEMORY_BASIC_INFORMATION_VLM;
  4618. #define SECTION_QUERY       0x0001
  4619. #define SECTION_MAP_WRITE   0x0002
  4620. #define SECTION_MAP_READ    0x0004
  4621. #define SECTION_MAP_EXECUTE 0x0008
  4622. #define SECTION_EXTEND_SIZE 0x0010
  4623.  
  4624. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  4625.                             SECTION_MAP_WRITE |      \
  4626.                             SECTION_MAP_READ |       \
  4627.                             SECTION_MAP_EXECUTE |    \
  4628.                             SECTION_EXTEND_SIZE)
  4629. #define PAGE_NOACCESS          0x01     
  4630. #define PAGE_READONLY          0x02     
  4631. #define PAGE_READWRITE         0x04     
  4632. #define PAGE_WRITECOPY         0x08     
  4633. #define PAGE_EXECUTE           0x10     
  4634. #define PAGE_EXECUTE_READ      0x20     
  4635. #define PAGE_EXECUTE_READWRITE 0x40     
  4636. #define PAGE_EXECUTE_WRITECOPY 0x80     
  4637. #define PAGE_GUARD            0x100     
  4638. #define PAGE_NOCACHE          0x200     
  4639. #define PAGE_WRITECOMBINE     0x400     
  4640. #define MEM_COMMIT           0x1000     
  4641. #define MEM_RESERVE          0x2000     
  4642. #define MEM_DECOMMIT         0x4000     
  4643. #define MEM_RELEASE          0x8000     
  4644. #define MEM_FREE            0x10000     
  4645. #define MEM_PRIVATE         0x20000     
  4646. #define MEM_MAPPED          0x40000     
  4647. #define MEM_RESET           0x80000     
  4648. #define MEM_TOP_DOWN       0x100000     
  4649. #define MEM_WRITE_WATCH    0x200000     
  4650. #define MEM_PHYSICAL       0x400000     
  4651. #define MEM_4MB_PAGES    0x80000000     
  4652. #define SEC_FILE           0x800000     
  4653. #define SEC_IMAGE         0x1000000     
  4654. #define SEC_VLM           0x2000000     
  4655. #define SEC_RESERVE       0x4000000     
  4656. #define SEC_COMMIT        0x8000000     
  4657. #define SEC_NOCACHE      0x10000000     
  4658. #define MEM_IMAGE         SEC_IMAGE     
  4659. #define WRITE_WATCH_FLAG_RESET 0x01     
  4660.  
  4661. //
  4662. // Define access rights to files and directories
  4663. //
  4664.  
  4665. //
  4666. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  4667. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  4668. // constants *MUST* always be in sync.
  4669. // The values are redefined in devioctl.h because they must be available to
  4670. // both DOS and NT.
  4671. //
  4672.  
  4673. #define FILE_READ_DATA            ( 0x0001 )    // file & pipe
  4674. #define FILE_LIST_DIRECTORY       ( 0x0001 )    // directory
  4675.  
  4676. #define FILE_WRITE_DATA           ( 0x0002 )    // file & pipe
  4677. #define FILE_ADD_FILE             ( 0x0002 )    // directory
  4678.  
  4679. #define FILE_APPEND_DATA          ( 0x0004 )    // file
  4680. #define FILE_ADD_SUBDIRECTORY     ( 0x0004 )    // directory
  4681. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 )    // named pipe
  4682.  
  4683.  
  4684. #define FILE_READ_EA              ( 0x0008 )    // file & directory
  4685.  
  4686. #define FILE_WRITE_EA             ( 0x0010 )    // file & directory
  4687.  
  4688. #define FILE_EXECUTE              ( 0x0020 )    // file
  4689. #define FILE_TRAVERSE             ( 0x0020 )    // directory
  4690.  
  4691. #define FILE_DELETE_CHILD         ( 0x0040 )    // directory
  4692.  
  4693. #define FILE_READ_ATTRIBUTES      ( 0x0080 )    // all
  4694.  
  4695. #define FILE_WRITE_ATTRIBUTES     ( 0x0100 )    // all
  4696.  
  4697. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  4698.  
  4699. #define FILE_GENERIC_READ         (STANDARD_RIGHTS_READ     |\
  4700.                                    FILE_READ_DATA           |\
  4701.                                    FILE_READ_ATTRIBUTES     |\
  4702.                                    FILE_READ_EA             |\
  4703.                                    SYNCHRONIZE)
  4704.  
  4705.  
  4706. #define FILE_GENERIC_WRITE        (STANDARD_RIGHTS_WRITE    |\
  4707.                                    FILE_WRITE_DATA          |\
  4708.                                    FILE_WRITE_ATTRIBUTES    |\
  4709.                                    FILE_WRITE_EA            |\
  4710.                                    FILE_APPEND_DATA         |\
  4711.                                    SYNCHRONIZE)
  4712.  
  4713.  
  4714. #define FILE_GENERIC_EXECUTE      (STANDARD_RIGHTS_EXECUTE  |\
  4715.                                    FILE_READ_ATTRIBUTES     |\
  4716.                                    FILE_EXECUTE             |\
  4717.                                    SYNCHRONIZE)
  4718.  
  4719. #define FILE_SHARE_READ                 0x00000001  
  4720. #define FILE_SHARE_WRITE                0x00000002  
  4721. #define FILE_SHARE_DELETE               0x00000004  
  4722. #define FILE_ATTRIBUTE_READONLY             0x00000001  
  4723. #define FILE_ATTRIBUTE_HIDDEN               0x00000002  
  4724. #define FILE_ATTRIBUTE_SYSTEM               0x00000004  
  4725. #define FILE_ATTRIBUTE_DIRECTORY            0x00000010  
  4726. #define FILE_ATTRIBUTE_ARCHIVE              0x00000020  
  4727. #define FILE_ATTRIBUTE_DEVICE               0x00000040  
  4728. #define FILE_ATTRIBUTE_NORMAL               0x00000080  
  4729. #define FILE_ATTRIBUTE_TEMPORARY            0x00000100  
  4730. #define FILE_ATTRIBUTE_SPARSE_FILE          0x00000200  
  4731. #define FILE_ATTRIBUTE_REPARSE_POINT        0x00000400  
  4732. #define FILE_ATTRIBUTE_COMPRESSED           0x00000800  
  4733. #define FILE_ATTRIBUTE_OFFLINE              0x00001000  
  4734. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000  
  4735. #define FILE_ATTRIBUTE_ENCRYPTED            0x00004000  
  4736. #define FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001   
  4737. #define FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002   
  4738. #define FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004   
  4739. #define FILE_NOTIFY_CHANGE_SIZE         0x00000008   
  4740. #define FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010   
  4741. #define FILE_NOTIFY_CHANGE_LAST_ACCESS  0x00000020   
  4742. #define FILE_NOTIFY_CHANGE_CREATION     0x00000040   
  4743. #define FILE_NOTIFY_CHANGE_SECURITY     0x00000100   
  4744. #define FILE_ACTION_ADDED                   0x00000001   
  4745. #define FILE_ACTION_REMOVED                 0x00000002   
  4746. #define FILE_ACTION_MODIFIED                0x00000003   
  4747. #define FILE_ACTION_RENAMED_OLD_NAME        0x00000004   
  4748. #define FILE_ACTION_RENAMED_NEW_NAME        0x00000005   
  4749. #define MAILSLOT_NO_MESSAGE             ((DWORD)-1) 
  4750. #define MAILSLOT_WAIT_FOREVER           ((DWORD)-1) 
  4751. #define FILE_CASE_SENSITIVE_SEARCH      0x00000001  
  4752. #define FILE_CASE_PRESERVED_NAMES       0x00000002  
  4753. #define FILE_UNICODE_ON_DISK            0x00000004  
  4754. #define FILE_PERSISTENT_ACLS            0x00000008  
  4755. #define FILE_FILE_COMPRESSION           0x00000010  
  4756. #define FILE_VOLUME_QUOTAS              0x00000020  
  4757. #define FILE_SUPPORTS_SPARSE_FILES      0x00000040  
  4758. #define FILE_SUPPORTS_REPARSE_POINTS    0x00000080  
  4759. #define FILE_SUPPORTS_REMOTE_STORAGE    0x00000100  
  4760. #define FILE_VOLUME_IS_COMPRESSED       0x00008000  
  4761. #define FILE_SUPPORTS_OBJECT_IDS        0x00010000  
  4762. #define FILE_SUPPORTS_ENCRYPTION        0x00020000  
  4763. #define FILE_NAMED_STREAMS              0x00040000  
  4764.  
  4765. //
  4766. // Define the file notification information structure
  4767. //
  4768.  
  4769. typedef struct _FILE_NOTIFY_INFORMATION {
  4770.     DWORD NextEntryOffset;
  4771.     DWORD Action;
  4772.     DWORD FileNameLength;
  4773.     WCHAR FileName[1];
  4774. } FILE_NOTIFY_INFORMATION, *PFILE_NOTIFY_INFORMATION;
  4775.  
  4776.  
  4777. //
  4778. // Define segement buffer structure for scatter/gather read/write.
  4779. //
  4780.  
  4781. typedef union _FILE_SEGMENT_ELEMENT {
  4782.     PVOID64 Buffer;
  4783.     ULONGLONG Alignment;
  4784. }FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
  4785.  
  4786. //
  4787. // The reparse GUID structure is used by all 3rd party layered drivers to
  4788. // store data in a reparse point. For non-Microsoft tags, The GUID field
  4789. // cannot be GUID_NULL.
  4790. // The constraints on reparse tags are defined below.
  4791. // Microsoft tags can also be used with this format of the reparse point buffer.
  4792. //
  4793.  
  4794. typedef struct _REPARSE_GUID_DATA_BUFFER {
  4795.     DWORD  ReparseTag;
  4796.     WORD   ReparseDataLength;
  4797.     WORD   Reserved;
  4798.     GUID   ReparseGuid;
  4799.     struct {
  4800.         BYTE   DataBuffer[1];
  4801.     } GenericReparseBuffer;
  4802. } REPARSE_GUID_DATA_BUFFER, *PREPARSE_GUID_DATA_BUFFER;
  4803.  
  4804. #define REPARSE_GUID_DATA_BUFFER_HEADER_SIZE   FIELD_OFFSET(REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer)
  4805.  
  4806.  
  4807.  
  4808. //
  4809. // Maximum allowed size of the reparse data.
  4810. //
  4811.  
  4812. #define MAXIMUM_REPARSE_DATA_BUFFER_SIZE      ( 16 * 1024 )
  4813.  
  4814. //
  4815. // Predefined reparse tags.
  4816. // These tags need to avoid conflicting with IO_REMOUNT defined in ntos\inc\io.h
  4817. //
  4818.  
  4819. #define IO_REPARSE_TAG_RESERVED_ZERO             (0)
  4820. #define IO_REPARSE_TAG_RESERVED_ONE              (1)
  4821.  
  4822. //
  4823. // The value of the following constant needs to satisfy the following conditions:
  4824. //  (1) Be at least as large as the largest of the reserved tags.
  4825. //  (2) Be strictly smaller than all the tags in use.
  4826. //
  4827.  
  4828. #define IO_REPARSE_TAG_RESERVED_RANGE            IO_REPARSE_TAG_RESERVED_ONE
  4829.  
  4830. //
  4831. // The reparse tags are a DWORD. The 32 bits are laid out as follows:
  4832. //
  4833. //   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  4834. //   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  4835. //  +-+-+-+-------------------------+-------------------------------+
  4836. //  |M|L|N|   Reserved bits         |       Reparse Tag Value       |
  4837. //  +-+-+-+-------------------------+-------------------------------+
  4838. //
  4839. // M is the Microsoft bit. When set to 1, it denotes a tag owned by Microsoft.
  4840. //   All ISVs must use a tag with a 0 in this position.
  4841. //   Note: If a Microsoft tag is used by non-Microsoft software, the
  4842. //   behavior is not defined.
  4843. //
  4844. // L is the high-latency bit. When set to 1, a file with this tag is
  4845. //   expected to have a long latency to retrieve the first byte of data.
  4846. //
  4847. // N is name surrogate. When set to 1, the file represents another named
  4848. //   entity in the system.
  4849. //
  4850. // The M, L, and N bits are OR-able.
  4851. // The following macros check for the M, L and N bit values:
  4852. //
  4853.  
  4854. //
  4855. // Macro to determine whether a reparse point tag corresponds to a tag
  4856. // owned by Microsoft.
  4857. //
  4858.  
  4859. #define IsReparseTagMicrosoft(_tag) (              \
  4860.                            ((_tag) & 0x80000000)   \
  4861.                            )
  4862.  
  4863. //
  4864. // Macro to determine whether a reparse point tag corresponds to a file
  4865. // that is to be displayed with the slow icon overlay.
  4866. //
  4867.  
  4868. #define IsReparseTagHighLatency(_tag) (            \
  4869.                            ((_tag) & 0x40000000)   \
  4870.                            )
  4871.  
  4872. //
  4873. // Macro to determine whether a reparse point tag corresponds to a file
  4874. // that is to be displayed with the slow icon overlay.
  4875. //
  4876.  
  4877. #define IsReparseTagNameSurrogate(_tag) (          \
  4878.                            ((_tag) & 0x20000000)   \
  4879.                            )
  4880.  
  4881.  
  4882. #define IO_REPARSE_TAG_MOUNT_POINT               (0xA0000003)        
  4883. #define IO_REPARSE_TAG_HSM                       (0xC0000004)        
  4884. #define IO_REPARSE_TAG_SIS                       (0x80000007)        
  4885. #define IO_COMPLETION_MODIFY_STATE  0x0002  
  4886. #define IO_COMPLETION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  4887. #define DUPLICATE_CLOSE_SOURCE      0x00000001  
  4888. #define DUPLICATE_SAME_ACCESS       0x00000002  
  4889.  
  4890. #define ES_SYSTEM_REQUIRED  ((DWORD)0x00000001)
  4891. #define ES_DISPLAY_REQUIRED ((DWORD)0x00000002)
  4892. #define ES_USER_PRESENT     ((DWORD)0x00000004)
  4893. #define ES_CONTINUOUS       ((DWORD)0x80000000)
  4894.  
  4895. typedef DWORD EXECUTION_STATE;
  4896.  
  4897. typedef enum {
  4898.     LT_DONT_CARE,
  4899.     LT_LOWEST_LATENCY
  4900. } LATENCY_TIME;
  4901.  
  4902.  
  4903.  
  4904. //
  4905. // Image Format
  4906. //
  4907.  
  4908.  
  4909. #ifndef _MAC
  4910.  
  4911. #include "pshpack4.h"                   // 4 byte packing is the default
  4912.  
  4913. #define IMAGE_DOS_SIGNATURE                 0x5A4D      // MZ
  4914. #define IMAGE_OS2_SIGNATURE                 0x454E      // NE
  4915. #define IMAGE_OS2_SIGNATURE_LE              0x454C      // LE
  4916. #define IMAGE_VXD_SIGNATURE                 0x454C      // LE
  4917. #define IMAGE_NT_SIGNATURE                  0x00004550  // PE00
  4918.  
  4919. #include "pshpack2.h"                   // 16 bit headers are 2 byte packed
  4920.  
  4921. #else
  4922.  
  4923. #include "pshpack1.h"
  4924.  
  4925. #define IMAGE_DOS_SIGNATURE                 0x4D5A      // MZ
  4926. #define IMAGE_OS2_SIGNATURE                 0x4E45      // NE
  4927. #define IMAGE_OS2_SIGNATURE_LE              0x4C45      // LE
  4928. #define IMAGE_NT_SIGNATURE                  0x50450000  // PE00
  4929. #endif
  4930.  
  4931. typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
  4932.     WORD   e_magic;                     // Magic number
  4933.     WORD   e_cblp;                      // Bytes on last page of file
  4934.     WORD   e_cp;                        // Pages in file
  4935.     WORD   e_crlc;                      // Relocations
  4936.     WORD   e_cparhdr;                   // Size of header in paragraphs
  4937.     WORD   e_minalloc;                  // Minimum extra paragraphs needed
  4938.     WORD   e_maxalloc;                  // Maximum extra paragraphs needed
  4939.     WORD   e_ss;                        // Initial (relative) SS value
  4940.     WORD   e_sp;                        // Initial SP value
  4941.     WORD   e_csum;                      // Checksum
  4942.     WORD   e_ip;                        // Initial IP value
  4943.     WORD   e_cs;                        // Initial (relative) CS value
  4944.     WORD   e_lfarlc;                    // File address of relocation table
  4945.     WORD   e_ovno;                      // Overlay number
  4946.     WORD   e_res[4];                    // Reserved words
  4947.     WORD   e_oemid;                     // OEM identifier (for e_oeminfo)
  4948.     WORD   e_oeminfo;                   // OEM information; e_oemid specific
  4949.     WORD   e_res2[10];                  // Reserved words
  4950.     LONG   e_lfanew;                    // File address of new exe header
  4951.   } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
  4952.  
  4953. typedef struct _IMAGE_OS2_HEADER {      // OS/2 .EXE header
  4954.     WORD   ne_magic;                    // Magic number
  4955.     CHAR   ne_ver;                      // Version number
  4956.     CHAR   ne_rev;                      // Revision number
  4957.     WORD   ne_enttab;                   // Offset of Entry Table
  4958.     WORD   ne_cbenttab;                 // Number of bytes in Entry Table
  4959.     LONG   ne_crc;                      // Checksum of whole file
  4960.     WORD   ne_flags;                    // Flag word
  4961.     WORD   ne_autodata;                 // Automatic data segment number
  4962.     WORD   ne_heap;                     // Initial heap allocation
  4963.     WORD   ne_stack;                    // Initial stack allocation
  4964.     LONG   ne_csip;                     // Initial CS:IP setting
  4965.     LONG   ne_sssp;                     // Initial SS:SP setting
  4966.     WORD   ne_cseg;                     // Count of file segments
  4967.     WORD   ne_cmod;                     // Entries in Module Reference Table
  4968.     WORD   ne_cbnrestab;                // Size of non-resident name table
  4969.     WORD   ne_segtab;                   // Offset of Segment Table
  4970.     WORD   ne_rsrctab;                  // Offset of Resource Table
  4971.     WORD   ne_restab;                   // Offset of resident name table
  4972.     WORD   ne_modtab;                   // Offset of Module Reference Table
  4973.     WORD   ne_imptab;                   // Offset of Imported Names Table
  4974.     LONG   ne_nrestab;                  // Offset of Non-resident Names Table
  4975.     WORD   ne_cmovent;                  // Count of movable entries
  4976.     WORD   ne_align;                    // Segment alignment shift count
  4977.     WORD   ne_cres;                     // Count of resource segments
  4978.     BYTE   ne_exetyp;                   // Target Operating system
  4979.     BYTE   ne_flagsothers;              // Other .EXE flags
  4980.     WORD   ne_pretthunks;               // offset to return thunks
  4981.     WORD   ne_psegrefbytes;             // offset to segment ref. bytes
  4982.     WORD   ne_swaparea;                 // Minimum code swap area size
  4983.     WORD   ne_expver;                   // Expected Windows version number
  4984.   } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
  4985.  
  4986. typedef struct _IMAGE_VXD_HEADER {      // Windows VXD header
  4987.     WORD   e32_magic;                   // Magic number
  4988.     BYTE   e32_border;                  // The byte ordering for the VXD
  4989.     BYTE   e32_worder;                  // The word ordering for the VXD
  4990.     DWORD  e32_level;                   // The EXE format level for now = 0
  4991.     WORD   e32_cpu;                     // The CPU type
  4992.     WORD   e32_os;                      // The OS type
  4993.     DWORD  e32_ver;                     // Module version
  4994.     DWORD  e32_mflags;                  // Module flags
  4995.     DWORD  e32_mpages;                  // Module # pages
  4996.     DWORD  e32_startobj;                // Object # for instruction pointer
  4997.     DWORD  e32_eip;                     // Extended instruction pointer
  4998.     DWORD  e32_stackobj;                // Object # for stack pointer
  4999.     DWORD  e32_esp;                     // Extended stack pointer
  5000.     DWORD  e32_pagesize;                // VXD page size
  5001.     DWORD  e32_lastpagesize;            // Last page size in VXD
  5002.     DWORD  e32_fixupsize;               // Fixup section size
  5003.     DWORD  e32_fixupsum;                // Fixup section checksum
  5004.     DWORD  e32_ldrsize;                 // Loader section size
  5005.     DWORD  e32_ldrsum;                  // Loader section checksum
  5006.     DWORD  e32_objtab;                  // Object table offset
  5007.     DWORD  e32_objcnt;                  // Number of objects in module
  5008.     DWORD  e32_objmap;                  // Object page map offset
  5009.     DWORD  e32_itermap;                 // Object iterated data map offset
  5010.     DWORD  e32_rsrctab;                 // Offset of Resource Table
  5011.     DWORD  e32_rsrccnt;                 // Number of resource entries
  5012.     DWORD  e32_restab;                  // Offset of resident name table
  5013.     DWORD  e32_enttab;                  // Offset of Entry Table
  5014.     DWORD  e32_dirtab;                  // Offset of Module Directive Table
  5015.     DWORD  e32_dircnt;                  // Number of module directives
  5016.     DWORD  e32_fpagetab;                // Offset of Fixup Page Table
  5017.     DWORD  e32_frectab;                 // Offset of Fixup Record Table
  5018.     DWORD  e32_impmod;                  // Offset of Import Module Name Table
  5019.     DWORD  e32_impmodcnt;               // Number of entries in Import Module Name Table
  5020.     DWORD  e32_impproc;                 // Offset of Import Procedure Name Table
  5021.     DWORD  e32_pagesum;                 // Offset of Per-Page Checksum Table
  5022.     DWORD  e32_datapage;                // Offset of Enumerated Data Pages
  5023.     DWORD  e32_preload;                 // Number of preload pages
  5024.     DWORD  e32_nrestab;                 // Offset of Non-resident Names Table
  5025.     DWORD  e32_cbnrestab;               // Size of Non-resident Name Table
  5026.     DWORD  e32_nressum;                 // Non-resident Name Table Checksum
  5027.     DWORD  e32_autodata;                // Object # for automatic data object
  5028.     DWORD  e32_debuginfo;               // Offset of the debugging information
  5029.     DWORD  e32_debuglen;                // The length of the debugging info. in bytes
  5030.     DWORD  e32_instpreload;             // Number of instance pages in preload section of VXD file
  5031.     DWORD  e32_instdemand;              // Number of instance pages in demand load section of VXD file
  5032.     DWORD  e32_heapsize;                // Size of heap - for 16-bit apps
  5033.     BYTE   e32_res3[12];                // Reserved words
  5034.     DWORD  e32_winresoff;
  5035.     DWORD  e32_winreslen;
  5036.     WORD   e32_devid;                   // Device ID for VxD
  5037.     WORD   e32_ddkver;                  // DDK version for VxD
  5038.   } IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
  5039.  
  5040. #ifndef _MAC
  5041. #include "poppack.h"                    // Back to 4 byte packing
  5042. #endif
  5043.  
  5044. //
  5045. // File header format.
  5046. //
  5047.  
  5048. typedef struct _IMAGE_FILE_HEADER {
  5049.     WORD    Machine;
  5050.     WORD    NumberOfSections;
  5051.     DWORD   TimeDateStamp;
  5052.     DWORD   PointerToSymbolTable;
  5053.     DWORD   NumberOfSymbols;
  5054.     WORD    SizeOfOptionalHeader;
  5055.     WORD    Characteristics;
  5056. } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
  5057.  
  5058. #define IMAGE_SIZEOF_FILE_HEADER             20
  5059.  
  5060.  
  5061. #define IMAGE_FILE_RELOCS_STRIPPED           0x0001  // Relocation info stripped from file.
  5062. #define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002  // File is executable  (i.e. no unresolved externel references).
  5063. #define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004  // Line nunbers stripped from file.
  5064. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008  // Local symbols stripped from file.
  5065. #define IMAGE_FILE_AGGRESIVE_WS_TRIM         0x0010  // Agressively trim working set
  5066. #define IMAGE_FILE_LARGE_ADDRESS_AWARE       0x0020  // App can handle >2gb addresses
  5067. #define IMAGE_FILE_BYTES_REVERSED_LO         0x0080  // Bytes of machine word are reversed.
  5068. #define IMAGE_FILE_32BIT_MACHINE             0x0100  // 32 bit word machine.
  5069. #define IMAGE_FILE_DEBUG_STRIPPED            0x0200  // Debugging info stripped from file in .DBG file
  5070. #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP   0x0400  // If Image is on removable media, copy and run from the swap file.
  5071. #define IMAGE_FILE_NET_RUN_FROM_SWAP         0x0800  // If Image is on Net, copy and run from the swap file.
  5072. #define IMAGE_FILE_SYSTEM                    0x1000  // System File.
  5073. #define IMAGE_FILE_DLL                       0x2000  // File is a DLL.
  5074. #define IMAGE_FILE_UP_SYSTEM_ONLY            0x4000  // File should only be run on a UP machine
  5075. #define IMAGE_FILE_BYTES_REVERSED_HI         0x8000  // Bytes of machine word are reversed.
  5076.  
  5077. #define IMAGE_FILE_MACHINE_UNKNOWN           0
  5078. #define IMAGE_FILE_MACHINE_I386              0x014c  // Intel 386.
  5079. #define IMAGE_FILE_MACHINE_R3000             0x0162  // MIPS little-endian, 0x160 big-endian
  5080. #define IMAGE_FILE_MACHINE_R4000             0x0166  // MIPS little-endian
  5081. #define IMAGE_FILE_MACHINE_R10000            0x0168  // MIPS little-endian
  5082. #define IMAGE_FILE_MACHINE_WCEMIPSV2         0x0169  // MIPS little-endian WCE v2
  5083. #define IMAGE_FILE_MACHINE_ALPHA             0x0184  // Alpha_AXP
  5084. #define IMAGE_FILE_MACHINE_POWERPC           0x01F0  // IBM PowerPC Little-Endian
  5085. #define IMAGE_FILE_MACHINE_SH3               0x01a2  // SH3 little-endian
  5086. #define IMAGE_FILE_MACHINE_SH3E              0x01a4  // SH3E little-endian
  5087. #define IMAGE_FILE_MACHINE_SH4               0x01a6  // SH4 little-endian
  5088. #define IMAGE_FILE_MACHINE_ARM               0x01c0  // ARM Little-Endian
  5089. #define IMAGE_FILE_MACHINE_THUMB             0x01c2
  5090. #define IMAGE_FILE_MACHINE_IA64              0x0200  // Intel 64
  5091. #define IMAGE_FILE_MACHINE_MIPS16            0x0266  // MIPS
  5092. #define IMAGE_FILE_MACHINE_MIPSFPU           0x0366  // MIPS
  5093. #define IMAGE_FILE_MACHINE_MIPSFPU16         0x0466  // MIPS
  5094. #define IMAGE_FILE_MACHINE_ALPHA64           0x0284  // ALPHA64
  5095. #define IMAGE_FILE_MACHINE_AXP64             IMAGE_FILE_MACHINE_ALPHA64
  5096. //
  5097. // Directory format.
  5098. //
  5099.  
  5100. typedef struct _IMAGE_DATA_DIRECTORY {
  5101.     DWORD   VirtualAddress;
  5102.     DWORD   Size;
  5103. } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
  5104.  
  5105. #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES    16
  5106.  
  5107. //
  5108. // Optional header format.
  5109. //
  5110.  
  5111. typedef struct _IMAGE_OPTIONAL_HEADER {
  5112.     //
  5113.     // Standard fields.
  5114.     //
  5115.  
  5116.     WORD    Magic;
  5117.     BYTE    MajorLinkerVersion;
  5118.     BYTE    MinorLinkerVersion;
  5119.     DWORD   SizeOfCode;
  5120.     DWORD   SizeOfInitializedData;
  5121.     DWORD   SizeOfUninitializedData;
  5122.     DWORD   AddressOfEntryPoint;
  5123.     DWORD   BaseOfCode;
  5124.     DWORD   BaseOfData;
  5125.  
  5126.     //
  5127.     // NT additional fields.
  5128.     //
  5129.  
  5130.     DWORD   ImageBase;
  5131.     DWORD   SectionAlignment;
  5132.     DWORD   FileAlignment;
  5133.     WORD    MajorOperatingSystemVersion;
  5134.     WORD    MinorOperatingSystemVersion;
  5135.     WORD    MajorImageVersion;
  5136.     WORD    MinorImageVersion;
  5137.     WORD    MajorSubsystemVersion;
  5138.     WORD    MinorSubsystemVersion;
  5139.     DWORD   Win32VersionValue;
  5140.     DWORD   SizeOfImage;
  5141.     DWORD   SizeOfHeaders;
  5142.     DWORD   CheckSum;
  5143.     WORD    Subsystem;
  5144.     WORD    DllCharacteristics;
  5145.     DWORD   SizeOfStackReserve;
  5146.     DWORD   SizeOfStackCommit;
  5147.     DWORD   SizeOfHeapReserve;
  5148.     DWORD   SizeOfHeapCommit;
  5149.     DWORD   LoaderFlags;
  5150.     DWORD   NumberOfRvaAndSizes;
  5151.     IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  5152. } IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;
  5153.  
  5154. typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
  5155.     WORD   Magic;
  5156.     BYTE   MajorLinkerVersion;
  5157.     BYTE   MinorLinkerVersion;
  5158.     DWORD  SizeOfCode;
  5159.     DWORD  SizeOfInitializedData;
  5160.     DWORD  SizeOfUninitializedData;
  5161.     DWORD  AddressOfEntryPoint;
  5162.     DWORD  BaseOfCode;
  5163.     DWORD  BaseOfData;
  5164.     DWORD  BaseOfBss;
  5165.     DWORD  GprMask;
  5166.     DWORD  CprMask[4];
  5167.     DWORD  GpValue;
  5168. } IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
  5169.  
  5170. typedef struct _IMAGE_OPTIONAL_HEADER64 {
  5171.     WORD        Magic;
  5172.     BYTE        MajorLinkerVersion;
  5173.     BYTE        MinorLinkerVersion;
  5174.     DWORD       SizeOfCode;
  5175.     DWORD       SizeOfInitializedData;
  5176.     DWORD       SizeOfUninitializedData;
  5177.     DWORD       AddressOfEntryPoint;
  5178.     DWORD       BaseOfCode;
  5179.     ULONGLONG   ImageBase;
  5180.     DWORD       SectionAlignment;
  5181.     DWORD       FileAlignment;
  5182.     WORD        MajorOperatingSystemVersion;
  5183.     WORD        MinorOperatingSystemVersion;
  5184.     WORD        MajorImageVersion;
  5185.     WORD        MinorImageVersion;
  5186.     WORD        MajorSubsystemVersion;
  5187.     WORD        MinorSubsystemVersion;
  5188.     DWORD       Win32VersionValue;
  5189.     DWORD       SizeOfImage;
  5190.     DWORD       SizeOfHeaders;
  5191.     DWORD       CheckSum;
  5192.     WORD        Subsystem;
  5193.     WORD        DllCharacteristics;
  5194.     ULONGLONG   SizeOfStackReserve;
  5195.     ULONGLONG   SizeOfStackCommit;
  5196.     ULONGLONG   SizeOfHeapReserve;
  5197.     ULONGLONG   SizeOfHeapCommit;
  5198.     DWORD       LoaderFlags;
  5199.     DWORD       NumberOfRvaAndSizes;
  5200.     IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  5201. } IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64;
  5202.  
  5203. #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER      56
  5204. #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER      28
  5205. #define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER    224
  5206. #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER    240
  5207.  
  5208. #define IMAGE_NT_OPTIONAL_HDR32_MAGIC      0x10b
  5209. #define IMAGE_NT_OPTIONAL_HDR64_MAGIC      0x20b
  5210. #define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
  5211.  
  5212. #ifdef _WIN64
  5213. typedef IMAGE_OPTIONAL_HEADER64             IMAGE_OPTIONAL_HEADER;
  5214. typedef PIMAGE_OPTIONAL_HEADER64            PIMAGE_OPTIONAL_HEADER;
  5215. #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER     IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
  5216. #define IMAGE_NT_OPTIONAL_HDR_MAGIC         IMAGE_NT_OPTIONAL_HDR64_MAGIC
  5217. #else
  5218. typedef IMAGE_OPTIONAL_HEADER32             IMAGE_OPTIONAL_HEADER;
  5219. typedef PIMAGE_OPTIONAL_HEADER32            PIMAGE_OPTIONAL_HEADER;
  5220. #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER     IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
  5221. #define IMAGE_NT_OPTIONAL_HDR_MAGIC         IMAGE_NT_OPTIONAL_HDR32_MAGIC
  5222. #endif
  5223.  
  5224. typedef struct _IMAGE_NT_HEADERS64 {
  5225.     DWORD Signature;
  5226.     IMAGE_FILE_HEADER FileHeader;
  5227.     IMAGE_OPTIONAL_HEADER64 OptionalHeader;
  5228. } IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64;
  5229.  
  5230. typedef struct _IMAGE_NT_HEADERS {
  5231.     DWORD Signature;
  5232.     IMAGE_FILE_HEADER FileHeader;
  5233.     IMAGE_OPTIONAL_HEADER32 OptionalHeader;
  5234. } IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
  5235.  
  5236. typedef struct _IMAGE_ROM_HEADERS {
  5237.     IMAGE_FILE_HEADER FileHeader;
  5238.     IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
  5239. } IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
  5240.  
  5241. #ifdef _WIN64
  5242. typedef IMAGE_NT_HEADERS64                  IMAGE_NT_HEADERS;
  5243. typedef PIMAGE_NT_HEADERS64                 PIMAGE_NT_HEADERS;
  5244. #else
  5245. typedef IMAGE_NT_HEADERS32                  IMAGE_NT_HEADERS;
  5246. typedef PIMAGE_NT_HEADERS32                 PIMAGE_NT_HEADERS;
  5247. #endif
  5248.  
  5249. // IMAGE_FIRST_SECTION doesn't need 32/64 versions since the file header is the same either way.
  5250.  
  5251. #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER)        \
  5252.     ((ULONG_PTR)ntheader +                                              \
  5253.      FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) +                 \
  5254.      ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader   \
  5255.     ))
  5256.  
  5257. // Subsystem Values
  5258.  
  5259. #define IMAGE_SUBSYSTEM_UNKNOWN              0   // Unknown subsystem.
  5260. #define IMAGE_SUBSYSTEM_NATIVE               1   // Image doesn't require a subsystem.
  5261. #define IMAGE_SUBSYSTEM_WINDOWS_GUI          2   // Image runs in the Windows GUI subsystem.
  5262. #define IMAGE_SUBSYSTEM_WINDOWS_CUI          3   // Image runs in the Windows character subsystem.
  5263. #define IMAGE_SUBSYSTEM_OS2_CUI              5   // image runs in the OS/2 character subsystem.
  5264. #define IMAGE_SUBSYSTEM_POSIX_CUI            7   // image runs in the Posix character subsystem.
  5265. #define IMAGE_SUBSYSTEM_NATIVE_WINDOWS       8   // image is a native Win9x driver.
  5266. #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI       9   // Image runs in the Windows CE subsystem.
  5267. #define IMAGE_SUBSYSTEM_EFI_APPLICATION     10   //
  5268. #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER  11   //
  5269. #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER  12   //
  5270.  
  5271. // DllCharacteristics Entries
  5272.  
  5273. //      IMAGE_LIBRARY_PROCESS_INIT           0x0001     // Reserved.
  5274. //      IMAGE_LIBRARY_PROCESS_TERM           0x0002     // Reserved.
  5275. //      IMAGE_LIBRARY_THREAD_INIT            0x0004     // Reserved.
  5276. //      IMAGE_LIBRARY_THREAD_TERM            0x0008     // Reserved.
  5277. #define IMAGE_DLLCHARACTERISTICS_NO_BIND     0x0800     // Do not bind this image.
  5278. //                                           0x1000     // Reserved.
  5279. #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER  0x2000     // Driver uses WDM model
  5280. //                                           0x4000     // Reserved.
  5281. #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE     0x8000
  5282.  
  5283. // Directory Entries
  5284.  
  5285. #define IMAGE_DIRECTORY_ENTRY_EXPORT          0   // Export Directory
  5286. #define IMAGE_DIRECTORY_ENTRY_IMPORT          1   // Import Directory
  5287. #define IMAGE_DIRECTORY_ENTRY_RESOURCE        2   // Resource Directory
  5288. #define IMAGE_DIRECTORY_ENTRY_EXCEPTION       3   // Exception Directory
  5289. #define IMAGE_DIRECTORY_ENTRY_SECURITY        4   // Security Directory
  5290. #define IMAGE_DIRECTORY_ENTRY_BASERELOC       5   // Base Relocation Table
  5291. #define IMAGE_DIRECTORY_ENTRY_DEBUG           6   // Debug Directory
  5292. //      IMAGE_DIRECTORY_ENTRY_COPYRIGHT       7   // (X86 usage)
  5293. #define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE    7   // Architecture Specific Data
  5294. #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR       8   // RVA of GP
  5295. #define IMAGE_DIRECTORY_ENTRY_TLS             9   // TLS Directory
  5296. #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG    10   // Load Configuration Directory
  5297. #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT   11   // Bound Import Directory in headers
  5298. #define IMAGE_DIRECTORY_ENTRY_IAT            12   // Import Address Table
  5299. #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT   13   // Delay Load Import Descriptors
  5300. #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14   // COM Runtime descriptor
  5301.  
  5302. //
  5303. // Non-COFF Object file header
  5304. //
  5305.  
  5306. typedef struct ANON_OBJECT_HEADER {
  5307.     WORD    Sig1;            // Must be IMAGE_FILE_MACHINE_UNKNOWN
  5308.     WORD    Sig2;            // Must be 0xffff
  5309.     WORD    Version;         // >= 1 (implies the CLSID field is present)
  5310.     WORD    Machine;
  5311.     DWORD   TimeDateStamp;
  5312.     CLSID   ClassID;         // Used to invoke CoCreateInstance
  5313.     DWORD   SizeOfData;      // Size of data that follows the header
  5314. } ANON_OBJECT_HEADER;
  5315.  
  5316. //
  5317. // Section header format.
  5318. //
  5319.  
  5320. #define IMAGE_SIZEOF_SHORT_NAME              8
  5321.  
  5322. typedef struct _IMAGE_SECTION_HEADER {
  5323.     BYTE    Name[IMAGE_SIZEOF_SHORT_NAME];
  5324.     union {
  5325.             DWORD   PhysicalAddress;
  5326.             DWORD   VirtualSize;
  5327.     } Misc;
  5328.     DWORD   VirtualAddress;
  5329.     DWORD   SizeOfRawData;
  5330.     DWORD   PointerToRawData;
  5331.     DWORD   PointerToRelocations;
  5332.     DWORD   PointerToLinenumbers;
  5333.     WORD    NumberOfRelocations;
  5334.     WORD    NumberOfLinenumbers;
  5335.     DWORD   Characteristics;
  5336. } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
  5337.  
  5338. #define IMAGE_SIZEOF_SECTION_HEADER          40
  5339.  
  5340. //
  5341. // Section characteristics.
  5342. //
  5343. //      IMAGE_SCN_TYPE_REG                   0x00000000  // Reserved.
  5344. //      IMAGE_SCN_TYPE_DSECT                 0x00000001  // Reserved.
  5345. //      IMAGE_SCN_TYPE_NOLOAD                0x00000002  // Reserved.
  5346. //      IMAGE_SCN_TYPE_GROUP                 0x00000004  // Reserved.
  5347. #define IMAGE_SCN_TYPE_NO_PAD                0x00000008  // Reserved.
  5348. //      IMAGE_SCN_TYPE_COPY                  0x00000010  // Reserved.
  5349.  
  5350. #define IMAGE_SCN_CNT_CODE                   0x00000020  // Section contains code.
  5351. #define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  // Section contains initialized data.
  5352. #define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  // Section contains uninitialized data.
  5353.  
  5354. #define IMAGE_SCN_LNK_OTHER                  0x00000100  // Reserved.
  5355. #define IMAGE_SCN_LNK_INFO                   0x00000200  // Section contains comments or some other type of information.
  5356. //      IMAGE_SCN_TYPE_OVER                  0x00000400  // Reserved.
  5357. #define IMAGE_SCN_LNK_REMOVE                 0x00000800  // Section contents will not become part of image.
  5358. #define IMAGE_SCN_LNK_COMDAT                 0x00001000  // Section contents comdat.
  5359. //                                           0x00002000  // Reserved.
  5360. //      IMAGE_SCN_MEM_PROTECTED - Obsolete   0x00004000
  5361. #define IMAGE_SCN_NO_DEFER_SPEC_EXC          0x00004000  // Reset speculative exceptions handling bits in the TLB entries for this section.
  5362. #define IMAGE_SCN_GPREL                      0x00008000  // Section content can be accessed relative to GP
  5363. #define IMAGE_SCN_MEM_FARDATA                0x00008000
  5364. //      IMAGE_SCN_MEM_SYSHEAP  - Obsolete    0x00010000
  5365. #define IMAGE_SCN_MEM_PURGEABLE              0x00020000
  5366. #define IMAGE_SCN_MEM_16BIT                  0x00020000
  5367. #define IMAGE_SCN_MEM_LOCKED                 0x00040000
  5368. #define IMAGE_SCN_MEM_PRELOAD                0x00080000
  5369.  
  5370. #define IMAGE_SCN_ALIGN_1BYTES               0x00100000  //
  5371. #define IMAGE_SCN_ALIGN_2BYTES               0x00200000  //
  5372. #define IMAGE_SCN_ALIGN_4BYTES               0x00300000  //
  5373. #define IMAGE_SCN_ALIGN_8BYTES               0x00400000  //
  5374. #define IMAGE_SCN_ALIGN_16BYTES              0x00500000  // Default alignment if no others are specified.
  5375. #define IMAGE_SCN_ALIGN_32BYTES              0x00600000  //
  5376. #define IMAGE_SCN_ALIGN_64BYTES              0x00700000  //
  5377. #define IMAGE_SCN_ALIGN_128BYTES             0x00800000  //
  5378. #define IMAGE_SCN_ALIGN_256BYTES             0x00900000  //
  5379. #define IMAGE_SCN_ALIGN_512BYTES             0x00A00000  //
  5380. #define IMAGE_SCN_ALIGN_1024BYTES            0x00B00000  //
  5381. #define IMAGE_SCN_ALIGN_2048BYTES            0x00C00000  //
  5382. #define IMAGE_SCN_ALIGN_4096BYTES            0x00D00000  //
  5383. #define IMAGE_SCN_ALIGN_8192BYTES            0x00E00000  //
  5384. // Unused                                    0x00F00000
  5385. #define IMAGE_SCN_ALIGN_MASK                 0x00F00000
  5386.  
  5387. #define IMAGE_SCN_LNK_NRELOC_OVFL            0x01000000  // Section contains extended relocations.
  5388. #define IMAGE_SCN_MEM_DISCARDABLE            0x02000000  // Section can be discarded.
  5389. #define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  // Section is not cachable.
  5390. #define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  // Section is not pageable.
  5391. #define IMAGE_SCN_MEM_SHARED                 0x10000000  // Section is shareable.
  5392. #define IMAGE_SCN_MEM_EXECUTE                0x20000000  // Section is executable.
  5393. #define IMAGE_SCN_MEM_READ                   0x40000000  // Section is readable.
  5394. #define IMAGE_SCN_MEM_WRITE                  0x80000000  // Section is writeable.
  5395.  
  5396. //
  5397. // TLS Chaacteristic Flags
  5398. //
  5399. #define IMAGE_SCN_SCALE_INDEX                0x00000001  // Tls index is scaled
  5400.  
  5401. #ifndef _MAC
  5402. #include "pshpack2.h"                       // Symbols, relocs, and linenumbers are 2 byte packed
  5403. #endif
  5404.  
  5405. //
  5406. // Symbol format.
  5407. //
  5408.  
  5409. typedef struct _IMAGE_SYMBOL {
  5410.     union {
  5411.         BYTE    ShortName[8];
  5412.         struct {
  5413.             DWORD   Short;     // if 0, use LongName
  5414.             DWORD   Long;      // offset into string table
  5415.         } Name;
  5416.         DWORD   LongName[2];    // PBYTE [2]
  5417.     } N;
  5418.     DWORD   Value;
  5419.     SHORT   SectionNumber;
  5420.     WORD    Type;
  5421.     BYTE    StorageClass;
  5422.     BYTE    NumberOfAuxSymbols;
  5423. } IMAGE_SYMBOL;
  5424. typedef IMAGE_SYMBOL UNALIGNED *PIMAGE_SYMBOL;
  5425.  
  5426.  
  5427. #define IMAGE_SIZEOF_SYMBOL                  18
  5428.  
  5429. //
  5430. // Section values.
  5431. //
  5432. // Symbols have a section number of the section in which they are
  5433. // defined. Otherwise, section numbers have the following meanings:
  5434. //
  5435.  
  5436. #define IMAGE_SYM_UNDEFINED           (SHORT)0          // Symbol is undefined or is common.
  5437. #define IMAGE_SYM_ABSOLUTE            (SHORT)-1         // Symbol is an absolute value.
  5438. #define IMAGE_SYM_DEBUG               (SHORT)-2         // Symbol is a special debug item.
  5439.  
  5440. //
  5441. // Type (fundamental) values.
  5442. //
  5443.  
  5444. #define IMAGE_SYM_TYPE_NULL                 0x0000  // no type.
  5445. #define IMAGE_SYM_TYPE_VOID                 0x0001  //
  5446. #define IMAGE_SYM_TYPE_CHAR                 0x0002  // type character.
  5447. #define IMAGE_SYM_TYPE_SHORT                0x0003  // type short integer.
  5448. #define IMAGE_SYM_TYPE_INT                  0x0004  //
  5449. #define IMAGE_SYM_TYPE_LONG                 0x0005  //
  5450. #define IMAGE_SYM_TYPE_FLOAT                0x0006  //
  5451. #define IMAGE_SYM_TYPE_DOUBLE               0x0007  //
  5452. #define IMAGE_SYM_TYPE_STRUCT               0x0008  //
  5453. #define IMAGE_SYM_TYPE_UNION                0x0009  //
  5454. #define IMAGE_SYM_TYPE_ENUM                 0x000A  // enumeration.
  5455. #define IMAGE_SYM_TYPE_MOE                  0x000B  // member of enumeration.
  5456. #define IMAGE_SYM_TYPE_BYTE                 0x000C  //
  5457. #define IMAGE_SYM_TYPE_WORD                 0x000D  //
  5458. #define IMAGE_SYM_TYPE_UINT                 0x000E  //
  5459. #define IMAGE_SYM_TYPE_DWORD                0x000F  //
  5460. #define IMAGE_SYM_TYPE_PCODE                0x8000  //
  5461. //
  5462. // Type (derived) values.
  5463. //
  5464.  
  5465. #define IMAGE_SYM_DTYPE_NULL                0       // no derived type.
  5466. #define IMAGE_SYM_DTYPE_POINTER             1       // pointer.
  5467. #define IMAGE_SYM_DTYPE_FUNCTION            2       // function.
  5468. #define IMAGE_SYM_DTYPE_ARRAY               3       // array.
  5469.  
  5470. //
  5471. // Storage classes.
  5472. //
  5473. #define IMAGE_SYM_CLASS_END_OF_FUNCTION     (BYTE )-1
  5474. #define IMAGE_SYM_CLASS_NULL                0x0000
  5475. #define IMAGE_SYM_CLASS_AUTOMATIC           0x0001
  5476. #define IMAGE_SYM_CLASS_EXTERNAL            0x0002
  5477. #define IMAGE_SYM_CLASS_STATIC              0x0003
  5478. #define IMAGE_SYM_CLASS_REGISTER            0x0004
  5479. #define IMAGE_SYM_CLASS_EXTERNAL_DEF        0x0005
  5480. #define IMAGE_SYM_CLASS_LABEL               0x0006
  5481. #define IMAGE_SYM_CLASS_UNDEFINED_LABEL     0x0007
  5482. #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT    0x0008
  5483. #define IMAGE_SYM_CLASS_ARGUMENT            0x0009
  5484. #define IMAGE_SYM_CLASS_STRUCT_TAG          0x000A
  5485. #define IMAGE_SYM_CLASS_MEMBER_OF_UNION     0x000B
  5486. #define IMAGE_SYM_CLASS_UNION_TAG           0x000C
  5487. #define IMAGE_SYM_CLASS_TYPE_DEFINITION     0x000D
  5488. #define IMAGE_SYM_CLASS_UNDEFINED_STATIC    0x000E
  5489. #define IMAGE_SYM_CLASS_ENUM_TAG            0x000F
  5490. #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM      0x0010
  5491. #define IMAGE_SYM_CLASS_REGISTER_PARAM      0x0011
  5492. #define IMAGE_SYM_CLASS_BIT_FIELD           0x0012
  5493.  
  5494. #define IMAGE_SYM_CLASS_FAR_EXTERNAL        0x0044  //
  5495.  
  5496. #define IMAGE_SYM_CLASS_BLOCK               0x0064
  5497. #define IMAGE_SYM_CLASS_FUNCTION            0x0065
  5498. #define IMAGE_SYM_CLASS_END_OF_STRUCT       0x0066
  5499. #define IMAGE_SYM_CLASS_FILE                0x0067
  5500. // new
  5501. #define IMAGE_SYM_CLASS_SECTION             0x0068
  5502. #define IMAGE_SYM_CLASS_WEAK_EXTERNAL       0x0069
  5503.  
  5504. // type packing constants
  5505.  
  5506. #define N_BTMASK                            0x000F
  5507. #define N_TMASK                             0x0030
  5508. #define N_TMASK1                            0x00C0
  5509. #define N_TMASK2                            0x00F0
  5510. #define N_BTSHFT                            4
  5511. #define N_TSHIFT                            2
  5512. // MACROS
  5513.  
  5514. // Basic Type of  x
  5515. #define BTYPE(x) ((x) & N_BTMASK)
  5516.  
  5517. // Is x a pointer?
  5518. #ifndef ISPTR
  5519. #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
  5520. #endif
  5521.  
  5522. // Is x a function?
  5523. #ifndef ISFCN
  5524. #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
  5525. #endif
  5526.  
  5527. // Is x an array?
  5528.  
  5529. #ifndef ISARY
  5530. #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
  5531. #endif
  5532.  
  5533. // Is x a structure, union, or enumeration TAG?
  5534. #ifndef ISTAG
  5535. #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
  5536. #endif
  5537.  
  5538. #ifndef INCREF
  5539. #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
  5540. #endif
  5541. #ifndef DECREF
  5542. #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  5543. #endif
  5544.  
  5545. //
  5546. // Auxiliary entry format.
  5547. //
  5548.  
  5549. typedef union _IMAGE_AUX_SYMBOL {
  5550.     struct {
  5551.         DWORD    TagIndex;                      // struct, union, or enum tag index
  5552.         union {
  5553.             struct {
  5554.                 WORD    Linenumber;             // declaration line number
  5555.                 WORD    Size;                   // size of struct, union, or enum
  5556.             } LnSz;
  5557.            DWORD    TotalSize;
  5558.         } Misc;
  5559.         union {
  5560.             struct {                            // if ISFCN, tag, or .bb
  5561.                 DWORD    PointerToLinenumber;
  5562.                 DWORD    PointerToNextFunction;
  5563.             } Function;
  5564.             struct {                            // if ISARY, up to 4 dimen.
  5565.                 WORD     Dimension[4];
  5566.             } Array;
  5567.         } FcnAry;
  5568.         WORD    TvIndex;                        // tv index
  5569.     } Sym;
  5570.     struct {
  5571.         BYTE    Name[IMAGE_SIZEOF_SYMBOL];
  5572.     } File;
  5573.     struct {
  5574.         DWORD   Length;                         // section length
  5575.         WORD    NumberOfRelocations;            // number of relocation entries
  5576.         WORD    NumberOfLinenumbers;            // number of line numbers
  5577.         DWORD   CheckSum;                       // checksum for communal
  5578.         SHORT   Number;                         // section number to associate with
  5579.         BYTE    Selection;                      // communal selection type
  5580.     } Section;
  5581. } IMAGE_AUX_SYMBOL;
  5582. typedef IMAGE_AUX_SYMBOL UNALIGNED *PIMAGE_AUX_SYMBOL;
  5583.  
  5584. #define IMAGE_SIZEOF_AUX_SYMBOL             18
  5585.  
  5586. //
  5587. // Communal selection types.
  5588. //
  5589.  
  5590. #define IMAGE_COMDAT_SELECT_NODUPLICATES    1
  5591. #define IMAGE_COMDAT_SELECT_ANY             2
  5592. #define IMAGE_COMDAT_SELECT_SAME_SIZE       3
  5593. #define IMAGE_COMDAT_SELECT_EXACT_MATCH     4
  5594. #define IMAGE_COMDAT_SELECT_ASSOCIATIVE     5
  5595. #define IMAGE_COMDAT_SELECT_LARGEST         6
  5596. #define IMAGE_COMDAT_SELECT_NEWEST          7
  5597.  
  5598. #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY  1
  5599. #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY    2
  5600. #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS      3
  5601.  
  5602. //
  5603. // Relocation format.
  5604. //
  5605.  
  5606. typedef struct _IMAGE_RELOCATION {
  5607.     union {
  5608.         DWORD   VirtualAddress;
  5609.         DWORD   RelocCount;             // Set to the real count when IMAGE_SCN_LNK_NRELOC_OVFL is set
  5610.     };
  5611.     DWORD   SymbolTableIndex;
  5612.     WORD    Type;
  5613. } IMAGE_RELOCATION;
  5614. typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION;
  5615.  
  5616. #define IMAGE_SIZEOF_RELOCATION         10
  5617.  
  5618. //
  5619. // I386 relocation types.
  5620. //
  5621. #define IMAGE_REL_I386_ABSOLUTE         0x0000  // Reference is absolute, no relocation is necessary
  5622. #define IMAGE_REL_I386_DIR16            0x0001  // Direct 16-bit reference to the symbols virtual address
  5623. #define IMAGE_REL_I386_REL16            0x0002  // PC-relative 16-bit reference to the symbols virtual address
  5624. #define IMAGE_REL_I386_DIR32            0x0006  // Direct 32-bit reference to the symbols virtual address
  5625. #define IMAGE_REL_I386_DIR32NB          0x0007  // Direct 32-bit reference to the symbols virtual address, base not included
  5626. #define IMAGE_REL_I386_SEG12            0x0009  // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
  5627. #define IMAGE_REL_I386_SECTION          0x000A
  5628. #define IMAGE_REL_I386_SECREL           0x000B
  5629. #define IMAGE_REL_I386_REL32            0x0014  // PC-relative 32-bit reference to the symbols virtual address
  5630.  
  5631. //
  5632. // MIPS relocation types.
  5633. //
  5634.  
  5635. #define IMAGE_REL_MIPS_ABSOLUTE         0x0000  // Reference is absolute, no relocation is necessary
  5636. #define IMAGE_REL_MIPS_REFHALF          0x0001
  5637. #define IMAGE_REL_MIPS_REFWORD          0x0002
  5638. #define IMAGE_REL_MIPS_JMPADDR          0x0003
  5639. #define IMAGE_REL_MIPS_REFHI            0x0004
  5640. #define IMAGE_REL_MIPS_REFLO            0x0005
  5641. #define IMAGE_REL_MIPS_GPREL            0x0006
  5642. #define IMAGE_REL_MIPS_LITERAL          0x0007
  5643. #define IMAGE_REL_MIPS_SECTION          0x000A
  5644. #define IMAGE_REL_MIPS_SECREL           0x000B
  5645. #define IMAGE_REL_MIPS_SECRELLO         0x000C  // Low 16-bit section relative referemce (used for >32k TLS)
  5646. #define IMAGE_REL_MIPS_SECRELHI         0x000D  // High 16-bit section relative reference (used for >32k TLS)
  5647. #define IMAGE_REL_MIPS_JMPADDR16        0x0010
  5648. #define IMAGE_REL_MIPS_REFWORDNB        0x0022
  5649. #define IMAGE_REL_MIPS_PAIR             0x0025
  5650.  
  5651. //
  5652. // Alpha Relocation types.
  5653. //
  5654.  
  5655. #define IMAGE_REL_ALPHA_ABSOLUTE        0x0000
  5656. #define IMAGE_REL_ALPHA_REFLONG         0x0001
  5657. #define IMAGE_REL_ALPHA_REFQUAD         0x0002
  5658. #define IMAGE_REL_ALPHA_GPREL32         0x0003
  5659. #define IMAGE_REL_ALPHA_LITERAL         0x0004
  5660. #define IMAGE_REL_ALPHA_LITUSE          0x0005
  5661. #define IMAGE_REL_ALPHA_GPDISP          0x0006
  5662. #define IMAGE_REL_ALPHA_BRADDR          0x0007
  5663. #define IMAGE_REL_ALPHA_HINT            0x0008
  5664. #define IMAGE_REL_ALPHA_INLINE_REFLONG  0x0009
  5665. #define IMAGE_REL_ALPHA_REFHI           0x000A
  5666. #define IMAGE_REL_ALPHA_REFLO           0x000B
  5667. #define IMAGE_REL_ALPHA_PAIR            0x000C
  5668. #define IMAGE_REL_ALPHA_MATCH           0x000D
  5669. #define IMAGE_REL_ALPHA_SECTION         0x000E
  5670. #define IMAGE_REL_ALPHA_SECREL          0x000F
  5671. #define IMAGE_REL_ALPHA_REFLONGNB       0x0010
  5672. #define IMAGE_REL_ALPHA_SECRELLO        0x0011  // Low 16-bit section relative reference
  5673. #define IMAGE_REL_ALPHA_SECRELHI        0x0012  // High 16-bit section relative reference
  5674. #define IMAGE_REL_ALPHA_REFQ3           0x0013  // High 16 bits of 48 bit reference
  5675. #define IMAGE_REL_ALPHA_REFQ2           0x0014  // Middle 16 bits of 48 bit reference
  5676. #define IMAGE_REL_ALPHA_REFQ1           0x0015  // Low 16 bits of 48 bit reference
  5677. #define IMAGE_REL_ALPHA_GPRELLO         0x0016  // Low 16-bit GP relative reference
  5678. #define IMAGE_REL_ALPHA_GPRELHI         0x0017  // High 16-bit GP relative reference
  5679.  
  5680.  
  5681. //
  5682. // IBM PowerPC relocation types.
  5683. //
  5684.  
  5685. #define IMAGE_REL_PPC_ABSOLUTE          0x0000  // NOP
  5686. #define IMAGE_REL_PPC_ADDR64            0x0001  // 64-bit address
  5687. #define IMAGE_REL_PPC_ADDR32            0x0002  // 32-bit address
  5688. #define IMAGE_REL_PPC_ADDR24            0x0003  // 26-bit address, shifted left 2 (branch absolute)
  5689. #define IMAGE_REL_PPC_ADDR16            0x0004  // 16-bit address
  5690. #define IMAGE_REL_PPC_ADDR14            0x0005  // 16-bit address, shifted left 2 (load doubleword)
  5691. #define IMAGE_REL_PPC_REL24             0x0006  // 26-bit PC-relative offset, shifted left 2 (branch relative)
  5692. #define IMAGE_REL_PPC_REL14             0x0007  // 16-bit PC-relative offset, shifted left 2 (br cond relative)
  5693. #define IMAGE_REL_PPC_TOCREL16          0x0008  // 16-bit offset from TOC base
  5694. #define IMAGE_REL_PPC_TOCREL14          0x0009  // 16-bit offset from TOC base, shifted left 2 (load doubleword)
  5695.  
  5696. #define IMAGE_REL_PPC_ADDR32NB          0x000A  // 32-bit addr w/o image base
  5697. #define IMAGE_REL_PPC_SECREL            0x000B  // va of containing section (as in an image sectionhdr)
  5698. #define IMAGE_REL_PPC_SECTION           0x000C  // sectionheader number
  5699. #define IMAGE_REL_PPC_IFGLUE            0x000D  // substitute TOC restore instruction iff symbol is glue code
  5700. #define IMAGE_REL_PPC_IMGLUE            0x000E  // symbol is glue code; virtual address is TOC restore instruction
  5701. #define IMAGE_REL_PPC_SECREL16          0x000F  // va of containing section (limited to 16 bits)
  5702. #define IMAGE_REL_PPC_REFHI             0x0010
  5703. #define IMAGE_REL_PPC_REFLO             0x0011
  5704. #define IMAGE_REL_PPC_PAIR              0x0012
  5705. #define IMAGE_REL_PPC_SECRELLO          0x0013  // Low 16-bit section relative reference (used for >32k TLS)
  5706. #define IMAGE_REL_PPC_SECRELHI          0x0014  // High 16-bit section relative reference (used for >32k TLS)
  5707. #define IMAGE_REL_PPC_GPREL             0x0015
  5708.  
  5709. #define IMAGE_REL_PPC_TYPEMASK          0x00FF  // mask to isolate above values in IMAGE_RELOCATION.Type
  5710.  
  5711. // Flag bits in IMAGE_RELOCATION.TYPE
  5712.  
  5713. #define IMAGE_REL_PPC_NEG               0x0100  // subtract reloc value rather than adding it
  5714. #define IMAGE_REL_PPC_BRTAKEN           0x0200  // fix branch prediction bit to predict branch taken
  5715. #define IMAGE_REL_PPC_BRNTAKEN          0x0400  // fix branch prediction bit to predict branch not taken
  5716. #define IMAGE_REL_PPC_TOCDEFN           0x0800  // toc slot defined in file (or, data in toc)
  5717.  
  5718. //
  5719. // Hitachi SH3 relocation types.
  5720. //
  5721. #define IMAGE_REL_SH3_ABSOLUTE          0x0000  // No relocation
  5722. #define IMAGE_REL_SH3_DIRECT16          0x0001  // 16 bit direct
  5723. #define IMAGE_REL_SH3_DIRECT32          0x0002  // 32 bit direct
  5724. #define IMAGE_REL_SH3_DIRECT8           0x0003  // 8 bit direct, -128..255
  5725. #define IMAGE_REL_SH3_DIRECT8_WORD      0x0004  // 8 bit direct .W (0 ext.)
  5726. #define IMAGE_REL_SH3_DIRECT8_LONG      0x0005  // 8 bit direct .L (0 ext.)
  5727. #define IMAGE_REL_SH3_DIRECT4           0x0006  // 4 bit direct (0 ext.)
  5728. #define IMAGE_REL_SH3_DIRECT4_WORD      0x0007  // 4 bit direct .W (0 ext.)
  5729. #define IMAGE_REL_SH3_DIRECT4_LONG      0x0008  // 4 bit direct .L (0 ext.)
  5730. #define IMAGE_REL_SH3_PCREL8_WORD       0x0009  // 8 bit PC relative .W
  5731. #define IMAGE_REL_SH3_PCREL8_LONG       0x000A  // 8 bit PC relative .L
  5732. #define IMAGE_REL_SH3_PCREL12_WORD      0x000B  // 12 LSB PC relative .W
  5733. #define IMAGE_REL_SH3_STARTOF_SECTION   0x000C  // Start of EXE section
  5734. #define IMAGE_REL_SH3_SIZEOF_SECTION    0x000D  // Size of EXE section
  5735. #define IMAGE_REL_SH3_SECTION           0x000E  // Section table index
  5736. #define IMAGE_REL_SH3_SECREL            0x000F  // Offset within section
  5737. #define IMAGE_REL_SH3_DIRECT32_NB       0x0010  // 32 bit direct not based
  5738.  
  5739. #define IMAGE_REL_ARM_ABSOLUTE          0x0000  // No relocation required
  5740. #define IMAGE_REL_ARM_ADDR32            0x0001  // 32 bit address
  5741. #define IMAGE_REL_ARM_ADDR32NB          0x0002  // 32 bit address w/o image base
  5742. #define IMAGE_REL_ARM_BRANCH24          0x0003  // 24 bit offset << 2 & sign ext.
  5743. #define IMAGE_REL_ARM_BRANCH11          0x0004  // Thumb: 2 11 bit offsets
  5744. #define IMAGE_REL_ARM_GPREL12           0x0006  // GP-relative addressing (ARM)
  5745. #define IMAGE_REL_ARM_GPREL7            0x0007  // GP-relative addressing (Thumb)
  5746. #define IMAGE_REL_ARM_SECTION           0x000E  // Section table index
  5747. #define IMAGE_REL_ARM_SECREL            0x000F  // Offset within section
  5748.  
  5749. //
  5750. // IA64 relocation types.
  5751. //
  5752.  
  5753. #define IMAGE_REL_IA64_ABSOLUTE         0x0000
  5754. #define IMAGE_REL_IA64_IMM14            0x0001
  5755. #define IMAGE_REL_IA64_IMM22            0x0002
  5756. #define IMAGE_REL_IA64_IMM64            0x0003
  5757. #define IMAGE_REL_IA64_DIR32            0x0004
  5758. #define IMAGE_REL_IA64_DIR64            0x0005
  5759. #define IMAGE_REL_IA64_PCREL21B         0x0006
  5760. #define IMAGE_REL_IA64_PCREL21M         0x0007
  5761. #define IMAGE_REL_IA64_PCREL21F         0x0008
  5762. #define IMAGE_REL_IA64_GPREL22          0x0009
  5763. #define IMAGE_REL_IA64_LTOFF22          0x000A
  5764. #define IMAGE_REL_IA64_SECTION          0x000B
  5765. #define IMAGE_REL_IA64_SECREL22         0x000C
  5766. #define IMAGE_REL_IA64_SECREL64I        0x000D
  5767. #define IMAGE_REL_IA64_SECREL32         0x000E
  5768. #define IMAGE_REL_IA64_LTOFF64          0x000F
  5769. #define IMAGE_REL_IA64_DIR32NB          0x0010
  5770. #define IMAGE_REL_IA64_ADDEND           0x001F
  5771.  
  5772. // Please contact INTEL to get IA64-specific information
  5773. // @@BEGIN_DDKSPLIT
  5774.  
  5775.  
  5776.  
  5777.  
  5778.  
  5779.  
  5780.  
  5781.  
  5782.  
  5783.  
  5784.  
  5785.  
  5786.  
  5787.  
  5788.  
  5789.  
  5790.  
  5791.  
  5792.  
  5793.  
  5794.  
  5795.  
  5796.  
  5797.  
  5798.  
  5799.  
  5800.  
  5801.  
  5802.  
  5803.  
  5804.  
  5805.  
  5806.  
  5807.  
  5808.  
  5809.  
  5810.  
  5811.  
  5812.  
  5813.  
  5814.  
  5815.  
  5816.  
  5817.  
  5818.  
  5819.  
  5820.  
  5821.  
  5822. // @@END_DDKSPLIT
  5823.  
  5824. //
  5825. // Line number format.
  5826. //
  5827.  
  5828. typedef struct _IMAGE_LINENUMBER {
  5829.     union {
  5830.         DWORD   SymbolTableIndex;               // Symbol table index of function name if Linenumber is 0.
  5831.         DWORD   VirtualAddress;                 // Virtual address of line number.
  5832.     } Type;
  5833.     WORD    Linenumber;                         // Line number.
  5834. } IMAGE_LINENUMBER;
  5835. typedef IMAGE_LINENUMBER UNALIGNED *PIMAGE_LINENUMBER;
  5836.  
  5837. #define IMAGE_SIZEOF_LINENUMBER              6
  5838.  
  5839. #ifndef _MAC
  5840. #include "poppack.h"                        // Back to 4 byte packing
  5841. #endif
  5842.  
  5843. //
  5844. // Based relocation format.
  5845. //
  5846.  
  5847. typedef struct _IMAGE_BASE_RELOCATION {
  5848.     DWORD   VirtualAddress;
  5849.     DWORD   SizeOfBlock;
  5850. //  WORD    TypeOffset[1];
  5851. } IMAGE_BASE_RELOCATION;
  5852. typedef IMAGE_BASE_RELOCATION UNALIGNED * PIMAGE_BASE_RELOCATION;
  5853.  
  5854. #define IMAGE_SIZEOF_BASE_RELOCATION         8
  5855.  
  5856. //
  5857. // Based relocation types.
  5858. //
  5859.  
  5860. #define IMAGE_REL_BASED_ABSOLUTE              0
  5861. #define IMAGE_REL_BASED_HIGH                  1
  5862. #define IMAGE_REL_BASED_LOW                   2
  5863. #define IMAGE_REL_BASED_HIGHLOW               3
  5864. #define IMAGE_REL_BASED_HIGHADJ               4
  5865. #define IMAGE_REL_BASED_MIPS_JMPADDR          5
  5866. #define IMAGE_REL_BASED_SECTION               6
  5867. #define IMAGE_REL_BASED_REL32                 7
  5868.  
  5869. #define IMAGE_REL_BASED_MIPS_JMPADDR16        9
  5870. #define IMAGE_REL_BASED_IA64_IMM64            9
  5871. #define IMAGE_REL_BASED_DIR64                 10
  5872. #define IMAGE_REL_BASED_HIGH3ADJ              11
  5873.  
  5874.  
  5875. //
  5876. // Archive format.
  5877. //
  5878.  
  5879. #define IMAGE_ARCHIVE_START_SIZE             8
  5880. #define IMAGE_ARCHIVE_START                  "!<arch>\n"
  5881. #define IMAGE_ARCHIVE_END                    "`\n"
  5882. #define IMAGE_ARCHIVE_PAD                    "\n"
  5883. #define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
  5884. #define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
  5885.  
  5886. typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
  5887.     BYTE     Name[16];                          // File member name - `/' terminated.
  5888.     BYTE     Date[12];                          // File member date - decimal.
  5889.     BYTE     UserID[6];                         // File member user id - decimal.
  5890.     BYTE     GroupID[6];                        // File member group id - decimal.
  5891.     BYTE     Mode[8];                           // File member mode - octal.
  5892.     BYTE     Size[10];                          // File member size - decimal.
  5893.     BYTE     EndHeader[2];                      // String to end header.
  5894. } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
  5895.  
  5896. #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR      60
  5897.  
  5898. //
  5899. // DLL support.
  5900. //
  5901.  
  5902. //
  5903. // Export Format
  5904. //
  5905.  
  5906. typedef struct _IMAGE_EXPORT_DIRECTORY {
  5907.     DWORD   Characteristics;
  5908.     DWORD   TimeDateStamp;
  5909.     WORD    MajorVersion;
  5910.     WORD    MinorVersion;
  5911.     DWORD   Name;
  5912.     DWORD   Base;
  5913.     DWORD   NumberOfFunctions;
  5914.     DWORD   NumberOfNames;
  5915.     DWORD   AddressOfFunctions;     // RVA from base of image
  5916.     DWORD   AddressOfNames;         // RVA from base of image
  5917.     DWORD   AddressOfNameOrdinals;  // RVA from base of image
  5918. } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
  5919.  
  5920. //
  5921. // Import Format
  5922. //
  5923.  
  5924. typedef struct _IMAGE_IMPORT_BY_NAME {
  5925.     WORD    Hint;
  5926.     BYTE    Name[1];
  5927. } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
  5928.  
  5929. #include "pshpack8.h"                       // Use align 8 for the 64-bit IAT.
  5930.  
  5931. typedef struct _IMAGE_THUNK_DATA64 {
  5932.     union {
  5933.         ULONGLONG ForwarderString;  // PBYTE 
  5934.         ULONGLONG Function;         // PDWORD
  5935.         ULONGLONG Ordinal;
  5936.         ULONGLONG AddressOfData;    // PIMAGE_IMPORT_BY_NAME
  5937.     } u1;
  5938. } IMAGE_THUNK_DATA64;
  5939. typedef IMAGE_THUNK_DATA64 * PIMAGE_THUNK_DATA64;
  5940.  
  5941. #include "poppack.h"                        // Back to 4 byte packing
  5942.  
  5943. typedef struct _IMAGE_THUNK_DATA32 {
  5944.     union {
  5945.         DWORD ForwarderString;      // PBYTE 
  5946.         DWORD Function;             // PDWORD
  5947.         DWORD Ordinal;
  5948.         DWORD AddressOfData;        // PIMAGE_IMPORT_BY_NAME
  5949.     } u1;
  5950. } IMAGE_THUNK_DATA32;
  5951. typedef IMAGE_THUNK_DATA32 * PIMAGE_THUNK_DATA32;
  5952.  
  5953. #define IMAGE_ORDINAL_FLAG64 0x8000000000000000
  5954. #define IMAGE_ORDINAL_FLAG32 0x80000000
  5955. #define IMAGE_ORDINAL64(Ordinal) (Ordinal & 0xffff)
  5956. #define IMAGE_ORDINAL32(Ordinal) (Ordinal & 0xffff)
  5957. #define IMAGE_SNAP_BY_ORDINAL64(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG64) != 0)
  5958. #define IMAGE_SNAP_BY_ORDINAL32(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG32) != 0)
  5959.  
  5960. //
  5961. // Thread Local Storage
  5962. //
  5963.  
  5964. typedef VOID
  5965. (NTAPI *PIMAGE_TLS_CALLBACK) (
  5966.     PVOID DllHandle,
  5967.     DWORD Reason,
  5968.     PVOID Reserved
  5969.     );
  5970.  
  5971. typedef struct _IMAGE_TLS_DIRECTORY64 {
  5972.     ULONGLONG   StartAddressOfRawData;
  5973.     ULONGLONG   EndAddressOfRawData;
  5974.     ULONGLONG   AddressOfIndex;         // PDWORD
  5975.     ULONGLONG   AddressOfCallBacks;     // PIMAGE_TLS_CALLBACK *;
  5976.     DWORD   SizeOfZeroFill;
  5977.     DWORD   Characteristics;
  5978. } IMAGE_TLS_DIRECTORY64;
  5979. typedef IMAGE_TLS_DIRECTORY64 * PIMAGE_TLS_DIRECTORY64;
  5980.  
  5981. typedef struct _IMAGE_TLS_DIRECTORY32 {
  5982.     DWORD   StartAddressOfRawData;
  5983.     DWORD   EndAddressOfRawData;
  5984.     DWORD   AddressOfIndex;             // PDWORD
  5985.     DWORD   AddressOfCallBacks;         // PIMAGE_TLS_CALLBACK *
  5986.     DWORD   SizeOfZeroFill;
  5987.     DWORD   Characteristics;
  5988. } IMAGE_TLS_DIRECTORY32;
  5989. typedef IMAGE_TLS_DIRECTORY32 * PIMAGE_TLS_DIRECTORY32;
  5990.  
  5991. #ifdef _WIN64
  5992. #define IMAGE_ORDINAL_FLAG              IMAGE_ORDINAL_FLAG64
  5993. #define IMAGE_ORDINAL(Ordinal)          IMAGE_ORDINAL64(Ordinal)
  5994. typedef IMAGE_THUNK_DATA64              IMAGE_THUNK_DATA;
  5995. typedef PIMAGE_THUNK_DATA64             PIMAGE_THUNK_DATA;
  5996. #define IMAGE_SNAP_BY_ORDINAL(Ordinal)  IMAGE_SNAP_BY_ORDINAL64(Ordinal)
  5997. typedef IMAGE_TLS_DIRECTORY64           IMAGE_TLS_DIRECTORY;
  5998. typedef PIMAGE_TLS_DIRECTORY64          PIMAGE_TLS_DIRECTORY;
  5999. #else
  6000. #define IMAGE_ORDINAL_FLAG              IMAGE_ORDINAL_FLAG32
  6001. #define IMAGE_ORDINAL(Ordinal)          IMAGE_ORDINAL32(Ordinal)
  6002. typedef IMAGE_THUNK_DATA32              IMAGE_THUNK_DATA;
  6003. typedef PIMAGE_THUNK_DATA32             PIMAGE_THUNK_DATA;
  6004. #define IMAGE_SNAP_BY_ORDINAL(Ordinal)  IMAGE_SNAP_BY_ORDINAL32(Ordinal)
  6005. typedef IMAGE_TLS_DIRECTORY32           IMAGE_TLS_DIRECTORY;
  6006. typedef PIMAGE_TLS_DIRECTORY32          PIMAGE_TLS_DIRECTORY;
  6007. #endif
  6008.  
  6009. typedef struct _IMAGE_IMPORT_DESCRIPTOR {
  6010.     union {
  6011.         DWORD   Characteristics;            // 0 for terminating null import descriptor
  6012.         DWORD   OriginalFirstThunk;         // RVA to original unbound IAT (PIMAGE_THUNK_DATA)
  6013.     };
  6014.     DWORD   TimeDateStamp;                  // 0 if not bound,
  6015.                                             // -1 if bound, and real date\time stamp
  6016.                                             //     in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
  6017.                                             // O.W. date/time stamp of DLL bound to (Old BIND)
  6018.  
  6019.     DWORD   ForwarderChain;                 // -1 if no forwarders
  6020.     DWORD   Name;
  6021.     DWORD   FirstThunk;                     // RVA to IAT (if bound this IAT has actual addresses)
  6022. } IMAGE_IMPORT_DESCRIPTOR;
  6023. typedef IMAGE_IMPORT_DESCRIPTOR UNALIGNED *PIMAGE_IMPORT_DESCRIPTOR;
  6024.  
  6025. //
  6026. // New format import descriptors pointed to by DataDirectory[ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT ]
  6027. //
  6028.  
  6029. typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR {
  6030.     DWORD   TimeDateStamp;
  6031.     WORD    OffsetModuleName;
  6032.     WORD    NumberOfModuleForwarderRefs;
  6033. // Array of zero or more IMAGE_BOUND_FORWARDER_REF follows
  6034. } IMAGE_BOUND_IMPORT_DESCRIPTOR,  *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
  6035.  
  6036. typedef struct _IMAGE_BOUND_FORWARDER_REF {
  6037.     DWORD   TimeDateStamp;
  6038.     WORD    OffsetModuleName;
  6039.     WORD    Reserved;
  6040. } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
  6041.  
  6042. //
  6043. // Resource Format.
  6044. //
  6045.  
  6046. //
  6047. // Resource directory consists of two counts, following by a variable length
  6048. // array of directory entries.  The first count is the number of entries at
  6049. // beginning of the array that have actual names associated with each entry.
  6050. // The entries are in ascending order, case insensitive strings.  The second
  6051. // count is the number of entries that immediately follow the named entries.
  6052. // This second count identifies the number of entries that have 16-bit integer
  6053. // Ids as their name.  These entries are also sorted in ascending order.
  6054. //
  6055. // This structure allows fast lookup by either name or number, but for any
  6056. // given resource entry only one form of lookup is supported, not both.
  6057. // This is consistant with the syntax of the .RC file and the .RES file.
  6058. //
  6059.  
  6060. typedef struct _IMAGE_RESOURCE_DIRECTORY {
  6061.     DWORD   Characteristics;
  6062.     DWORD   TimeDateStamp;
  6063.     WORD    MajorVersion;
  6064.     WORD    MinorVersion;
  6065.     WORD    NumberOfNamedEntries;
  6066.     WORD    NumberOfIdEntries;
  6067. //  IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[];
  6068. } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
  6069.  
  6070. #define IMAGE_RESOURCE_NAME_IS_STRING        0x80000000
  6071. #define IMAGE_RESOURCE_DATA_IS_DIRECTORY     0x80000000
  6072. //
  6073. // Each directory contains the 32-bit Name of the entry and an offset,
  6074. // relative to the beginning of the resource directory of the data associated
  6075. // with this directory entry.  If the name of the entry is an actual text
  6076. // string instead of an integer Id, then the high order bit of the name field
  6077. // is set to one and the low order 31-bits are an offset, relative to the
  6078. // beginning of the resource directory of the string, which is of type
  6079. // IMAGE_RESOURCE_DIRECTORY_STRING.  Otherwise the high bit is clear and the
  6080. // low-order 16-bits are the integer Id that identify this resource directory
  6081. // entry. If the directory entry is yet another resource directory (i.e. a
  6082. // subdirectory), then the high order bit of the offset field will be
  6083. // set to indicate this.  Otherwise the high bit is clear and the offset
  6084. // field points to a resource data entry.
  6085. //
  6086.  
  6087. typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
  6088.     union {
  6089.         struct {
  6090.             DWORD NameOffset:31;
  6091.             DWORD NameIsString:1;
  6092.         };
  6093.         DWORD   Name;
  6094.         WORD    Id;
  6095.     };
  6096.     union {
  6097.         DWORD   OffsetToData;
  6098.         struct {
  6099.             DWORD   OffsetToDirectory:31;
  6100.             DWORD   DataIsDirectory:1;
  6101.         };
  6102.     };
  6103. } IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
  6104.  
  6105. //
  6106. // For resource directory entries that have actual string names, the Name
  6107. // field of the directory entry points to an object of the following type.
  6108. // All of these string objects are stored together after the last resource
  6109. // directory entry and before the first resource data object.  This minimizes
  6110. // the impact of these variable length objects on the alignment of the fixed
  6111. // size directory entry objects.
  6112. //
  6113.  
  6114. typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
  6115.     WORD    Length;
  6116.     CHAR    NameString[ 1 ];
  6117. } IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
  6118.  
  6119.  
  6120. typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
  6121.     WORD    Length;
  6122.     WCHAR   NameString[ 1 ];
  6123. } IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
  6124.  
  6125.  
  6126. //
  6127. // Each resource data entry describes a leaf node in the resource directory
  6128. // tree.  It contains an offset, relative to the beginning of the resource
  6129. // directory of the data for the resource, a size field that gives the number
  6130. // of bytes of data at that offset, a CodePage that should be used when
  6131. // decoding code point values within the resource data.  Typically for new
  6132. // applications the code page would be the unicode code page.
  6133. //
  6134.  
  6135. typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
  6136.     DWORD   OffsetToData;
  6137.     DWORD   Size;
  6138.     DWORD   CodePage;
  6139.     DWORD   Reserved;
  6140. } IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
  6141.  
  6142. //
  6143. // Load Configuration Directory Entry
  6144. //
  6145.  
  6146. typedef struct {
  6147.     DWORD   Characteristics;
  6148.     DWORD   TimeDateStamp;
  6149.     WORD    MajorVersion;
  6150.     WORD    MinorVersion;
  6151.     DWORD   GlobalFlagsClear;
  6152.     DWORD   GlobalFlagsSet;
  6153.     DWORD   CriticalSectionDefaultTimeout;
  6154.     DWORD   DeCommitFreeBlockThreshold;
  6155.     DWORD   DeCommitTotalFreeThreshold;
  6156.     DWORD   LockPrefixTable;            // VA
  6157.     DWORD   MaximumAllocationSize;
  6158.     DWORD   VirtualMemoryThreshold;
  6159.     DWORD   ProcessHeapFlags;
  6160.     DWORD   ProcessAffinityMask;
  6161.     WORD    CSDVersion;
  6162.     WORD    Reserved1;
  6163.     DWORD   EditList;                   // VA
  6164.     DWORD   Reserved[ 1 ];
  6165. } IMAGE_LOAD_CONFIG_DIRECTORY32, *PIMAGE_LOAD_CONFIG_DIRECTORY32;
  6166.  
  6167. typedef struct {
  6168.     DWORD   Characteristics;
  6169.     DWORD   TimeDateStamp;
  6170.     WORD    MajorVersion;
  6171.     WORD    MinorVersion;
  6172.     DWORD   GlobalFlagsClear;
  6173.     DWORD   GlobalFlagsSet;
  6174.     DWORD   CriticalSectionDefaultTimeout;
  6175.     DWORD   DeCommitFreeBlockThreshold;
  6176.     DWORD   DeCommitTotalFreeThreshold;
  6177.     ULONGLONG  LockPrefixTable;         // VA
  6178.     DWORD   MaximumAllocationSize;
  6179.     DWORD   VirtualMemoryThreshold;
  6180.     DWORD   ProcessHeapFlags;
  6181.     DWORD   ProcessAffinityMask;
  6182.     WORD    CSDVersion;
  6183.     WORD    Reserved1;
  6184.     ULONGLONG  EditList;                // VA
  6185.     DWORD   Reserved[ 1 ];
  6186. } IMAGE_LOAD_CONFIG_DIRECTORY64, *PIMAGE_LOAD_CONFIG_DIRECTORY64;
  6187.  
  6188. #ifdef _WIN64
  6189. typedef IMAGE_LOAD_CONFIG_DIRECTORY64   IMAGE_LOAD_CONFIG_DIRECTORY;
  6190. typedef PIMAGE_LOAD_CONFIG_DIRECTORY64  PIMAGE_LOAD_CONFIG_DIRECTORY;
  6191. #else
  6192. typedef IMAGE_LOAD_CONFIG_DIRECTORY32   IMAGE_LOAD_CONFIG_DIRECTORY;
  6193. typedef PIMAGE_LOAD_CONFIG_DIRECTORY32  PIMAGE_LOAD_CONFIG_DIRECTORY;
  6194. #endif
  6195.  
  6196. //
  6197. // Function table entry format for IA64 images.  Function table is
  6198. // pointed to by the IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
  6199. // This definition duplicates the one in ntia64.h for use by portable
  6200. // image file mungers.
  6201. //
  6202.  
  6203. typedef struct _IMAGE_IA64_RUNTIME_FUNCTION_ENTRY {
  6204.     DWORD BeginAddress;
  6205.     DWORD EndAddress;
  6206.     DWORD UnwindInfoAddress;
  6207. } IMAGE_IA64_RUNTIME_FUNCTION_ENTRY, *PIMAGE_IA64_RUNTIME_FUNCTION_ENTRY;
  6208.  
  6209. //
  6210. // Function table entry format for ALPHA images.  Function table is
  6211. // pointed to by the IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
  6212. // This definition duplicates ones in ntmips.h and ntalpha.h for use
  6213. // by portable image file mungers.
  6214. //
  6215.  
  6216. typedef struct _IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY {
  6217.     DWORD BeginAddress;
  6218.     DWORD EndAddress;
  6219.     DWORD ExceptionHandler;
  6220.     DWORD HandlerData;
  6221.     DWORD PrologEndAddress;
  6222. } IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY, *PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY;
  6223.  
  6224. typedef struct _IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY {
  6225.     ULONGLONG BeginAddress;
  6226.     ULONGLONG EndAddress;
  6227.     ULONGLONG ExceptionHandler;
  6228.     ULONGLONG HandlerData;
  6229.     ULONGLONG PrologEndAddress;
  6230. } IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY, *PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY;
  6231.  
  6232. typedef  IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY  IMAGE_AXP64_RUNTIME_FUNCTION_ENTRY;
  6233. typedef PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY PIMAGE_AXP64_RUNTIME_FUNCTION_ENTRY;
  6234.  
  6235. //
  6236. // WIN CE Exception table format
  6237. //
  6238.  
  6239. typedef struct _IMAGE_CE_RUNTIME_FUNCTION_ENTRY {
  6240.     DWORD FuncStart;
  6241.     DWORD PrologLen : 8;
  6242.     DWORD FuncLen : 22;
  6243.     DWORD ThirtyTwoBit : 1;
  6244.     DWORD ExceptionFlag : 1;
  6245. } IMAGE_CE_RUNTIME_FUNCTION_ENTRY, * PIMAGE_CE_RUNTIME_FUNCTION_ENTRY;
  6246.  
  6247. #if defined(_IA64_)
  6248.  
  6249. typedef  IMAGE_IA64_RUNTIME_FUNCTION_ENTRY  IMAGE_RUNTIME_FUNCTION_ENTRY;
  6250. typedef PIMAGE_IA64_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
  6251.  
  6252. #elif defined(_AXP64_)
  6253.  
  6254. typedef  IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY  IMAGE_RUNTIME_FUNCTION_ENTRY;
  6255. typedef PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
  6256.  
  6257. #else
  6258.  
  6259. typedef  IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY  IMAGE_RUNTIME_FUNCTION_ENTRY;
  6260. typedef PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
  6261.  
  6262. #endif
  6263.  
  6264. //
  6265. // Debug Format
  6266. //
  6267.  
  6268. typedef struct _IMAGE_DEBUG_DIRECTORY {
  6269.     DWORD   Characteristics;
  6270.     DWORD   TimeDateStamp;
  6271.     WORD    MajorVersion;
  6272.     WORD    MinorVersion;
  6273.     DWORD   Type;
  6274.     DWORD   SizeOfData;
  6275.     DWORD   AddressOfRawData;
  6276.     DWORD   PointerToRawData;
  6277. } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
  6278.  
  6279. #define IMAGE_DEBUG_TYPE_UNKNOWN          0
  6280. #define IMAGE_DEBUG_TYPE_COFF             1
  6281. #define IMAGE_DEBUG_TYPE_CODEVIEW         2
  6282. #define IMAGE_DEBUG_TYPE_FPO              3
  6283. #define IMAGE_DEBUG_TYPE_MISC             4
  6284. #define IMAGE_DEBUG_TYPE_EXCEPTION        5
  6285. #define IMAGE_DEBUG_TYPE_FIXUP            6
  6286. #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC      7
  6287. #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC    8
  6288. #define IMAGE_DEBUG_TYPE_BORLAND          9
  6289. #define IMAGE_DEBUG_TYPE_RESERVED10       10
  6290.  
  6291.  
  6292. typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
  6293.     DWORD   NumberOfSymbols;
  6294.     DWORD   LvaToFirstSymbol;
  6295.     DWORD   NumberOfLinenumbers;
  6296.     DWORD   LvaToFirstLinenumber;
  6297.     DWORD   RvaToFirstByteOfCode;
  6298.     DWORD   RvaToLastByteOfCode;
  6299.     DWORD   RvaToFirstByteOfData;
  6300.     DWORD   RvaToLastByteOfData;
  6301. } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
  6302.  
  6303. #define FRAME_FPO       0
  6304. #define FRAME_TRAP      1
  6305. #define FRAME_TSS       2
  6306. #define FRAME_NONFPO    3
  6307.  
  6308. typedef struct _FPO_DATA {
  6309.     DWORD       ulOffStart;             // offset 1st byte of function code
  6310.     DWORD       cbProcSize;             // # bytes in function
  6311.     DWORD       cdwLocals;              // # bytes in locals/4
  6312.     WORD        cdwParams;              // # bytes in params/4
  6313.     WORD        cbProlog : 8;           // # bytes in prolog
  6314.     WORD        cbRegs   : 3;           // # regs saved
  6315.     WORD        fHasSEH  : 1;           // TRUE if SEH in func
  6316.     WORD        fUseBP   : 1;           // TRUE if EBP has been allocated
  6317.     WORD        reserved : 1;           // reserved for future use
  6318.     WORD        cbFrame  : 2;           // frame type
  6319. } FPO_DATA, *PFPO_DATA;
  6320. #define SIZEOF_RFPO_DATA 16
  6321.  
  6322.  
  6323. #define IMAGE_DEBUG_MISC_EXENAME    1
  6324.  
  6325. typedef struct _IMAGE_DEBUG_MISC {
  6326.     DWORD       DataType;               // type of misc data, see defines
  6327.     DWORD       Length;                 // total length of record, rounded to four
  6328.                                         // byte multiple.
  6329.     BOOLEAN     Unicode;                // TRUE if data is unicode string
  6330.     BYTE        Reserved[ 3 ];
  6331.     BYTE        Data[ 1 ];              // Actual data
  6332. } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
  6333.  
  6334.  
  6335. //
  6336. // Function table extracted from MIPS/ALPHA/IA64 images.  Does not contain
  6337. // information needed only for runtime support.  Just those fields for
  6338. // each entry needed by a debugger.
  6339. //
  6340.  
  6341. typedef struct _IMAGE_FUNCTION_ENTRY {
  6342.     DWORD   StartingAddress;
  6343.     DWORD   EndingAddress;
  6344.     DWORD   EndOfPrologue;
  6345. } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
  6346.  
  6347. typedef struct _IMAGE_FUNCTION_ENTRY64 {
  6348.     ULONGLONG   StartingAddress;
  6349.     ULONGLONG   EndingAddress;
  6350.     union {
  6351.         ULONGLONG   EndOfPrologue;
  6352.         ULONGLONG   UnwindInfoAddress;
  6353.     };
  6354. } IMAGE_FUNCTION_ENTRY64, *PIMAGE_FUNCTION_ENTRY64;
  6355.  
  6356. //
  6357. // Debugging information can be stripped from an image file and placed
  6358. // in a separate .DBG file, whose file name part is the same as the
  6359. // image file name part (e.g. symbols for CMD.EXE could be stripped
  6360. // and placed in CMD.DBG).  This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
  6361. // flag in the Characteristics field of the file header.  The beginning of
  6362. // the .DBG file contains the following structure which captures certain
  6363. // information from the image file.  This allows a debug to proceed even if
  6364. // the original image file is not accessable.  This header is followed by
  6365. // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
  6366. // IMAGE_DEBUG_DIRECTORY structures.  The latter structures and those in
  6367. // the image file contain file offsets relative to the beginning of the
  6368. // .DBG file.
  6369. //
  6370. // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
  6371. // is left in the image file, but not mapped.  This allows a debugger to
  6372. // compute the name of the .DBG file, from the name of the image in the
  6373. // IMAGE_DEBUG_MISC structure.
  6374. //
  6375.  
  6376. typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
  6377.     WORD        Signature;
  6378.     WORD        Flags;
  6379.     WORD        Machine;
  6380.     WORD        Characteristics;
  6381.     DWORD       TimeDateStamp;
  6382.     DWORD       CheckSum;
  6383.     DWORD       ImageBase;
  6384.     DWORD       SizeOfImage;
  6385.     DWORD       NumberOfSections;
  6386.     DWORD       ExportedNamesSize;
  6387.     DWORD       DebugDirectorySize;
  6388.     DWORD       SectionAlignment;
  6389.     DWORD       Reserved[2];
  6390. } IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
  6391.  
  6392. #ifndef _MAC
  6393. #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
  6394. #else
  6395. #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4449
  6396. #endif
  6397.  
  6398. #define IMAGE_SEPARATE_DEBUG_FLAGS_MASK 0x8000
  6399. #define IMAGE_SEPARATE_DEBUG_MISMATCH   0x8000  // when DBG was updated, the
  6400.                                                 // old checksum didn't match.
  6401.  
  6402. //
  6403. //  The .arch section is made up of headers, each describing an amask position/value
  6404. //  pointing to an array of IMAGE_ARCHITECTURE_ENTRY's.  Each "array" (both the header
  6405. //  and entry arrays) are terminiated by a quadword of 0xffffffffL.
  6406. //
  6407. //  NOTE: There may be quadwords of 0 sprinkled around and must be skipped.
  6408. //
  6409.  
  6410. typedef struct _ImageArchitectureHeader {
  6411.     unsigned int AmaskValue: 1;                 // 1 -> code section depends on mask bit
  6412.                                                 // 0 -> new instruction depends on mask bit
  6413.     int :7;                                     // MBZ
  6414.     unsigned int AmaskShift: 8;                 // Amask bit in question for this fixup
  6415.     int :16;                                    // MBZ
  6416.     DWORD FirstEntryRVA;                        // RVA into .arch section to array of ARCHITECTURE_ENTRY's
  6417. } IMAGE_ARCHITECTURE_HEADER, *PIMAGE_ARCHITECTURE_HEADER;
  6418.  
  6419. typedef struct _ImageArchitectureEntry {
  6420.     DWORD FixupInstRVA;                         // RVA of instruction to fixup
  6421.     DWORD NewInst;                              // fixup instruction (see alphaops.h)
  6422. } IMAGE_ARCHITECTURE_ENTRY, *PIMAGE_ARCHITECTURE_ENTRY;
  6423.  
  6424. #include "poppack.h"                // Back to the initial value
  6425.  
  6426. // The following structure defines the new import object.  Note the values of the first two fields,
  6427. // which must be set as stated in order to differentiate old and new import members.
  6428. // Following this structure, the linker emits two null-terminated strings used to recreate the
  6429. // import at the time of use.  The first string is the import's name, the second is the dll's name.
  6430.  
  6431. #define IMPORT_OBJECT_HDR_SIG2  0xffff
  6432.  
  6433. typedef struct IMPORT_OBJECT_HEADER {
  6434.     WORD    Sig1;                       // Must be IMAGE_FILE_MACHINE_UNKNOWN
  6435.     WORD    Sig2;                       // Must be IMPORT_OBJECT_HDR_SIG2.
  6436.     WORD    Version;
  6437.     WORD    Machine;
  6438.     DWORD   TimeDateStamp;              // Time/date stamp
  6439.     DWORD   SizeOfData;                 // particularly useful for incremental links
  6440.  
  6441.     union {
  6442.         WORD    Ordinal;                // if grf & IMPORT_OBJECT_ORDINAL
  6443.         WORD    Hint;
  6444.     };
  6445.  
  6446.     WORD    Type : 2;                   // IMPORT_TYPE
  6447.     WORD    NameType : 3;               // IMPORT_NAME_TYPE
  6448.     WORD    Reserved : 11;              // Reserved. Must be zero.
  6449. } IMPORT_OBJECT_HEADER;
  6450.  
  6451. typedef enum IMPORT_OBJECT_TYPE
  6452. {
  6453.     IMPORT_OBJECT_CODE = 0,
  6454.     IMPORT_OBJECT_DATA = 1,
  6455.     IMPORT_OBJECT_CONST = 2,
  6456. } IMPORT_OBJECT_TYPE;
  6457.  
  6458. typedef enum IMPORT_OBJECT_NAME_TYPE
  6459. {
  6460.     IMPORT_OBJECT_ORDINAL = 0,          // Import by ordinal
  6461.     IMPORT_OBJECT_NAME = 1,             // Import name == public symbol name.
  6462.     IMPORT_OBJECT_NAME_NO_PREFIX = 2,   // Import name == public symbol name skipping leading ?, @, or optionally _.
  6463.     IMPORT_OBJECT_NAME_UNDECORATE = 3,  // Import name == public symbol name skipping leading ?, @, or optionally _
  6464.                                         // and truncating at first @
  6465. } IMPORT_OBJECT_NAME_TYPE;
  6466.  
  6467. //
  6468. // End Image Format
  6469. //
  6470.  
  6471. //
  6472. // for move macros
  6473. //
  6474. #ifdef _MAC
  6475. #ifndef _INC_STRING
  6476. #include <string.h>
  6477. #endif /* _INC_STRING */
  6478. #else
  6479. #include <string.h>
  6480. #endif // _MAC
  6481.  
  6482. #define HEAP_NO_SERIALIZE               0x00000001      
  6483. #define HEAP_GROWABLE                   0x00000002      
  6484. #define HEAP_GENERATE_EXCEPTIONS        0x00000004      
  6485. #define HEAP_ZERO_MEMORY                0x00000008      
  6486. #define HEAP_REALLOC_IN_PLACE_ONLY      0x00000010      
  6487. #define HEAP_TAIL_CHECKING_ENABLED      0x00000020      
  6488. #define HEAP_FREE_CHECKING_ENABLED      0x00000040      
  6489. #define HEAP_DISABLE_COALESCE_ON_FREE   0x00000080      
  6490. #define HEAP_CREATE_ALIGN_16            0x00010000      
  6491. #define HEAP_CREATE_ENABLE_TRACING      0x00020000      
  6492. #define HEAP_MAXIMUM_TAG                0x0FFF              
  6493. #define HEAP_PSEUDO_TAG_FLAG            0x8000              
  6494. #define HEAP_TAG_SHIFT                  18                  
  6495. #define HEAP_MAKE_TAG_FLAGS( b, o ) ((DWORD)((b) + ((o) << 18)))  
  6496.  
  6497. #define IS_TEXT_UNICODE_ASCII16               0x0001
  6498. #define IS_TEXT_UNICODE_REVERSE_ASCII16       0x0010
  6499.  
  6500. #define IS_TEXT_UNICODE_STATISTICS            0x0002
  6501. #define IS_TEXT_UNICODE_REVERSE_STATISTICS    0x0020
  6502.  
  6503. #define IS_TEXT_UNICODE_CONTROLS              0x0004
  6504. #define IS_TEXT_UNICODE_REVERSE_CONTROLS      0x0040
  6505.  
  6506. #define IS_TEXT_UNICODE_SIGNATURE             0x0008
  6507. #define IS_TEXT_UNICODE_REVERSE_SIGNATURE     0x0080
  6508.  
  6509. #define IS_TEXT_UNICODE_ILLEGAL_CHARS         0x0100
  6510. #define IS_TEXT_UNICODE_ODD_LENGTH            0x0200
  6511. #define IS_TEXT_UNICODE_DBCS_LEADBYTE         0x0400
  6512. #define IS_TEXT_UNICODE_NULL_BYTES            0x1000
  6513.  
  6514. #define IS_TEXT_UNICODE_UNICODE_MASK          0x000F
  6515. #define IS_TEXT_UNICODE_REVERSE_MASK          0x00F0
  6516. #define IS_TEXT_UNICODE_NOT_UNICODE_MASK      0x0F00
  6517. #define IS_TEXT_UNICODE_NOT_ASCII_MASK        0xF000
  6518.  
  6519. #define COMPRESSION_FORMAT_NONE          (0x0000)   
  6520. #define COMPRESSION_FORMAT_DEFAULT       (0x0001)   
  6521. #define COMPRESSION_FORMAT_LZNT1         (0x0002)   
  6522. #define COMPRESSION_ENGINE_STANDARD      (0x0000)   
  6523. #define COMPRESSION_ENGINE_MAXIMUM       (0x0100)   
  6524. #define COMPRESSION_ENGINE_HIBER         (0x0200)   
  6525.  
  6526. NTSYSAPI
  6527. SIZE_T
  6528. NTAPI
  6529. RtlCompareMemory (
  6530.     const VOID *Source1,
  6531.     const VOID *Source2,
  6532.     SIZE_T Length
  6533.     );
  6534.  
  6535. #if defined(_M_AXP64) || defined(_M_IA64)
  6536.  
  6537. #define RtlEqualMemory(Source1, Source2, Length) \
  6538.     ((Length) == RtlCompareMemory(Source1, Source2, Length))
  6539.  
  6540. NTSYSAPI
  6541. VOID
  6542. NTAPI
  6543. RtlCopyMemory (
  6544.    VOID UNALIGNED *Destination,
  6545.    CONST VOID UNALIGNED *Source,
  6546.    SIZE_T Length
  6547.    );
  6548.  
  6549. NTSYSAPI
  6550. VOID
  6551. NTAPI
  6552. RtlCopyMemory32 (
  6553.    VOID UNALIGNED *Destination,
  6554.    CONST VOID UNALIGNED *Source,
  6555.    DWORD Length
  6556.    );
  6557.  
  6558. NTSYSAPI
  6559. VOID
  6560. NTAPI
  6561. RtlMoveMemory (
  6562.    VOID UNALIGNED *Destination,
  6563.    CONST VOID UNALIGNED *Source,
  6564.    SIZE_T Length
  6565.    );
  6566.  
  6567. NTSYSAPI
  6568. VOID
  6569. NTAPI
  6570. RtlFillMemory (
  6571.    VOID UNALIGNED *Destination,
  6572.    SIZE_T Length,
  6573.    BYTE  Fill
  6574.    );
  6575.  
  6576. NTSYSAPI
  6577. VOID
  6578. NTAPI
  6579. RtlZeroMemory (
  6580.    VOID UNALIGNED *Destination,
  6581.    SIZE_T Length
  6582.    );
  6583.  
  6584. #else
  6585.  
  6586. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  6587. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  6588. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  6589. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  6590. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  6591.  
  6592. #endif
  6593.  
  6594.  
  6595. #if (defined(_ALPHA_) || defined(_M_IA64)) && !(defined(MIDL_PASS) || defined(RC_INVOKED))
  6596.  
  6597. NTSYSAPI
  6598. VOID
  6599. NTAPI
  6600. RtlMoveMemory64 (
  6601.    IN PVOID64 Destination,
  6602.    IN PVOID64 Source,
  6603.    IN ULONGLONG Length
  6604.    );
  6605.  
  6606. NTSYSAPI
  6607. VOID
  6608. NTAPI
  6609. RtlFillMemory64 (
  6610.    IN PVOID64 Destination,
  6611.    IN ULONGLONG Length,
  6612.    IN BYTE  Fill
  6613.    );
  6614.  
  6615. NTSYSAPI
  6616. VOID
  6617. NTAPI
  6618. RtlZeroMemory64 (
  6619.    IN PVOID64 Destination,
  6620.    IN ULONGLONG Length
  6621.    );
  6622.  
  6623. #endif
  6624.  
  6625. typedef struct _MESSAGE_RESOURCE_ENTRY {
  6626.     WORD   Length;
  6627.     WORD   Flags;
  6628.     BYTE  Text[ 1 ];
  6629. } MESSAGE_RESOURCE_ENTRY, *PMESSAGE_RESOURCE_ENTRY;
  6630.  
  6631. #define MESSAGE_RESOURCE_UNICODE 0x0001
  6632.  
  6633. typedef struct _MESSAGE_RESOURCE_BLOCK {
  6634.     DWORD LowId;
  6635.     DWORD HighId;
  6636.     DWORD OffsetToEntries;
  6637. } MESSAGE_RESOURCE_BLOCK, *PMESSAGE_RESOURCE_BLOCK;
  6638.  
  6639. typedef struct _MESSAGE_RESOURCE_DATA {
  6640.     DWORD NumberOfBlocks;
  6641.     MESSAGE_RESOURCE_BLOCK Blocks[ 1 ];
  6642. } MESSAGE_RESOURCE_DATA, *PMESSAGE_RESOURCE_DATA;
  6643.  
  6644. typedef struct _OSVERSIONINFOA {
  6645.     DWORD dwOSVersionInfoSize;
  6646.     DWORD dwMajorVersion;
  6647.     DWORD dwMinorVersion;
  6648.     DWORD dwBuildNumber;
  6649.     DWORD dwPlatformId;
  6650.     CHAR   szCSDVersion[ 128 ];     // Maintenance string for PSS usage
  6651. } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
  6652.  
  6653. typedef struct _OSVERSIONINFOW {
  6654.     DWORD dwOSVersionInfoSize;
  6655.     DWORD dwMajorVersion;
  6656.     DWORD dwMinorVersion;
  6657.     DWORD dwBuildNumber;
  6658.     DWORD dwPlatformId;
  6659.     WCHAR  szCSDVersion[ 128 ];     // Maintenance string for PSS usage
  6660. } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;
  6661. #ifdef UNICODE
  6662. typedef OSVERSIONINFOW OSVERSIONINFO;
  6663. typedef POSVERSIONINFOW POSVERSIONINFO;
  6664. typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
  6665. #else
  6666. typedef OSVERSIONINFOA OSVERSIONINFO;
  6667. typedef POSVERSIONINFOA POSVERSIONINFO;
  6668. typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
  6669. #endif // UNICODE
  6670.  
  6671. typedef struct _OSVERSIONINFOEXA {
  6672.     DWORD dwOSVersionInfoSize;
  6673.     DWORD dwMajorVersion;
  6674.     DWORD dwMinorVersion;
  6675.     DWORD dwBuildNumber;
  6676.     DWORD dwPlatformId;
  6677.     CHAR   szCSDVersion[ 128 ];     // Maintenance string for PSS usage
  6678.     WORD   wServicePackMajor;
  6679.     WORD   wServicePackMinor;
  6680.     WORD   wSuiteMask;
  6681.     BYTE  wProductType;
  6682.     BYTE  wReserved;
  6683. } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
  6684. typedef struct _OSVERSIONINFOEXW {
  6685.     DWORD dwOSVersionInfoSize;
  6686.     DWORD dwMajorVersion;
  6687.     DWORD dwMinorVersion;
  6688.     DWORD dwBuildNumber;
  6689.     DWORD dwPlatformId;
  6690.     WCHAR  szCSDVersion[ 128 ];     // Maintenance string for PSS usage
  6691.     WORD   wServicePackMajor;
  6692.     WORD   wServicePackMinor;
  6693.     WORD   wSuiteMask;
  6694.     BYTE  wProductType;
  6695.     BYTE  wReserved;
  6696. } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW, RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
  6697. #ifdef UNICODE
  6698. typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
  6699. typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
  6700. typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
  6701. #else
  6702. typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
  6703. typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
  6704. typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
  6705. #endif // UNICODE
  6706.  
  6707. //
  6708. // RtlVerifyVersionInfo() conditions
  6709. //
  6710.  
  6711. #define VER_EQUAL                       1
  6712. #define VER_GREATER                     2
  6713. #define VER_GREATER_EQUAL               3
  6714. #define VER_LESS                        4
  6715. #define VER_LESS_EQUAL                  5
  6716. #define VER_AND                         6
  6717. #define VER_OR                          7
  6718.  
  6719. #define VER_CONDITION_MASK              7
  6720. #define VER_NUM_BITS_PER_CONDITION_MASK 3
  6721.  
  6722. //
  6723. // RtlVerifyVersionInfo() type mask bits
  6724. //
  6725.  
  6726. #define VER_MINORVERSION                0x0000001
  6727. #define VER_MAJORVERSION                0x0000002
  6728. #define VER_BUILDNUMBER                 0x0000004
  6729. #define VER_PLATFORMID                  0x0000008
  6730. #define VER_SERVICEPACKMINOR            0x0000010
  6731. #define VER_SERVICEPACKMAJOR            0x0000020
  6732. #define VER_SUITENAME                   0x0000040
  6733. #define VER_PRODUCT_TYPE                0x0000080
  6734.  
  6735. //
  6736. // RtlVerifyVersionInfo() os product type values
  6737. //
  6738.  
  6739. #define VER_NT_WORKSTATION              0x0000001
  6740. #define VER_NT_DOMAIN_CONTROLLER        0x0000002
  6741. #define VER_NT_SERVER                   0x0000003
  6742.  
  6743. //
  6744. // dwPlatformId defines:
  6745. //
  6746.  
  6747. #define VER_PLATFORM_WIN32s             0
  6748. #define VER_PLATFORM_WIN32_WINDOWS      1
  6749. #define VER_PLATFORM_WIN32_NT           2
  6750.  
  6751.  
  6752. //
  6753. //
  6754. // VerifyVersionInfo() macro to set the condition mask
  6755. //
  6756. // For documentation sakes here's the old version of the macro that got
  6757. // changed to call an API
  6758. // #define VER_SET_CONDITION(_m_,_t_,_c_)  _m_=(_m_|(_c_<<(1<<_t_)))
  6759. //
  6760.  
  6761. #define VER_SET_CONDITION(_m_,_t_,_c_)  \
  6762.         ((_m_)=VerSetConditionMask((_m_),(_t_),(_c_)))
  6763.  
  6764. ULONGLONG
  6765. NTAPI
  6766. VerSetConditionMask(
  6767.         IN  ULONGLONG   ConditionMask,
  6768.         IN  DWORD   TypeMask,
  6769.         IN  BYTE    Condition
  6770.         );
  6771. //
  6772.  
  6773. typedef struct _RTL_CRITICAL_SECTION_DEBUG {
  6774.     WORD   Type;
  6775.     WORD   CreatorBackTraceIndex;
  6776.     struct _RTL_CRITICAL_SECTION *CriticalSection;
  6777.     LIST_ENTRY ProcessLocksList;
  6778.     DWORD EntryCount;
  6779.     DWORD ContentionCount;
  6780.     DWORD Spare[ 2 ];
  6781. } RTL_CRITICAL_SECTION_DEBUG, *PRTL_CRITICAL_SECTION_DEBUG, RTL_RESOURCE_DEBUG, *PRTL_RESOURCE_DEBUG;
  6782.  
  6783. #define RTL_CRITSECT_TYPE 0
  6784. #define RTL_RESOURCE_TYPE 1
  6785.  
  6786. typedef struct _RTL_CRITICAL_SECTION {
  6787.     PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
  6788.  
  6789.     //
  6790.     //  The following three fields control entering and exiting the critical
  6791.     //  section for the resource
  6792.     //
  6793.  
  6794.     LONG LockCount;
  6795.     LONG RecursionCount;
  6796.     HANDLE OwningThread;        // from the thread's ClientId->UniqueThread
  6797.     HANDLE LockSemaphore;
  6798.     ULONG_PTR SpinCount;        // force size on 64-bit systems when packed
  6799. } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
  6800. #define SEF_DACL_AUTO_INHERIT             0x01
  6801. #define SEF_SACL_AUTO_INHERIT             0x02
  6802. #define SEF_DEFAULT_DESCRIPTOR_FOR_OBJECT 0x04
  6803. #define SEF_AVOID_PRIVILEGE_CHECK         0x08
  6804. #define SEF_AVOID_OWNER_CHECK             0x10
  6805. #define SEF_DEFAULT_OWNER_FROM_PARENT     0x20
  6806. #define SEF_DEFAULT_GROUP_FROM_PARENT     0x40
  6807. #define WT_EXECUTEDEFAULT       0x00000000                           
  6808. #define WT_EXECUTEINIOTHREAD    0x00000001                           
  6809. #define WT_EXECUTEINUITHREAD    0x00000002                           
  6810. #define WT_EXECUTEINWAITTHREAD  0x00000004                           
  6811. #define WT_EXECUTEONLYONCE      0x00000008                           
  6812. #define WT_EXECUTEINTIMERTHREAD 0x00000020                           
  6813. #define WT_EXECUTELONGFUNCTION  0x00000010                           
  6814. #define WT_EXECUTEINPERSISTENTIOTHREAD  0x00000040                   
  6815. #define WT_EXECUTEINPERSISTENTTHREAD 0x00000080                      
  6816. typedef VOID (NTAPI * WAITORTIMERCALLBACKFUNC) (PVOID, BOOLEAN );   
  6817. typedef VOID (NTAPI * WORKERCALLBACKFUNC) (PVOID );                 
  6818. typedef VOID (NTAPI * APC_CALLBACK_FUNCTION) (DWORD   , PVOID, PVOID); 
  6819. #define WT_EXECUTEINLONGTHREAD  0x00000010                           
  6820. #define WT_EXECUTEDELETEWAIT    0x00000008                           
  6821. #define DLL_PROCESS_ATTACH 1    
  6822. #define DLL_THREAD_ATTACH  2    
  6823. #define DLL_THREAD_DETACH  3    
  6824. #define DLL_PROCESS_DETACH 0    
  6825.  
  6826. //
  6827. // Defines for the READ flags for Eventlogging
  6828. //
  6829. #define EVENTLOG_SEQUENTIAL_READ        0X0001
  6830. #define EVENTLOG_SEEK_READ              0X0002
  6831. #define EVENTLOG_FORWARDS_READ          0X0004
  6832. #define EVENTLOG_BACKWARDS_READ         0X0008
  6833.  
  6834. //
  6835. // The types of events that can be logged.
  6836. //
  6837. #define EVENTLOG_SUCCESS                0X0000
  6838. #define EVENTLOG_ERROR_TYPE             0x0001
  6839. #define EVENTLOG_WARNING_TYPE           0x0002
  6840. #define EVENTLOG_INFORMATION_TYPE       0x0004
  6841. #define EVENTLOG_AUDIT_SUCCESS          0x0008
  6842. #define EVENTLOG_AUDIT_FAILURE          0x0010
  6843.  
  6844. //
  6845. // Defines for the WRITE flags used by Auditing for paired events
  6846. // These are not implemented in Product 1
  6847. //
  6848.  
  6849. #define EVENTLOG_START_PAIRED_EVENT    0x0001
  6850. #define EVENTLOG_END_PAIRED_EVENT      0x0002
  6851. #define EVENTLOG_END_ALL_PAIRED_EVENTS 0x0004
  6852. #define EVENTLOG_PAIRED_EVENT_ACTIVE   0x0008
  6853. #define EVENTLOG_PAIRED_EVENT_INACTIVE 0x0010
  6854.  
  6855. //
  6856. // Structure that defines the header of the Eventlog record. This is the
  6857. // fixed-sized portion before all the variable-length strings, binary
  6858. // data and pad bytes.
  6859. //
  6860. // TimeGenerated is the time it was generated at the client.
  6861. // TimeWritten is the time it was put into the log at the server end.
  6862. //
  6863.  
  6864. typedef struct _EVENTLOGRECORD {
  6865.     DWORD  Length;        // Length of full record
  6866.     DWORD  Reserved;      // Used by the service
  6867.     DWORD  RecordNumber;  // Absolute record number
  6868.     DWORD  TimeGenerated; // Seconds since 1-1-1970
  6869.     DWORD  TimeWritten;   // Seconds since 1-1-1970
  6870.     DWORD  EventID;
  6871.     WORD   EventType;
  6872.     WORD   NumStrings;
  6873.     WORD   EventCategory;
  6874.     WORD   ReservedFlags; // For use with paired events (auditing)
  6875.     DWORD  ClosingRecordNumber; // For use with paired events (auditing)
  6876.     DWORD  StringOffset;  // Offset from beginning of record
  6877.     DWORD  UserSidLength;
  6878.     DWORD  UserSidOffset;
  6879.     DWORD  DataLength;
  6880.     DWORD  DataOffset;    // Offset from beginning of record
  6881.     //
  6882.     // Then follow:
  6883.     //
  6884.     // WCHAR SourceName[]
  6885.     // WCHAR Computername[]
  6886.     // SID   UserSid
  6887.     // WCHAR Strings[]
  6888.     // BYTE  Data[]
  6889.     // CHAR  Pad[]
  6890.     // DWORD Length;
  6891.     //
  6892. } EVENTLOGRECORD, *PEVENTLOGRECORD;
  6893.  
  6894. //SS: start of changes to support clustering
  6895. //SS: ideally the
  6896. #define MAXLOGICALLOGNAMESIZE   256
  6897.  
  6898. #if _MSC_VER >= 1200
  6899. #pragma warning(push)
  6900. #endif
  6901. #pragma warning(disable : 4200)
  6902. typedef struct _EVENTSFORLOGFILE{
  6903.     DWORD            ulSize;
  6904.     WCHAR           szLogicalLogFile[MAXLOGICALLOGNAMESIZE];        //name of the logical file-security/application/system
  6905.     DWORD            ulNumRecords;
  6906.     EVENTLOGRECORD     pEventLogRecords[];
  6907. }EVENTSFORLOGFILE, *PEVENTSFORLOGFILE;
  6908.  
  6909. typedef struct _PACKEDEVENTINFO{
  6910.     DWORD               ulSize;  //total size of the structure
  6911.     DWORD               ulNumEventsForLogFile; //number of EventsForLogFile structure that follow
  6912.     DWORD                 ulOffsets[];           //the offsets from the start of this structure to the EVENTSFORLOGFILE structure
  6913. }PACKEDEVENTINFO, *PPACKEDEVENTINFO;
  6914.  
  6915. #if _MSC_VER >= 1200
  6916. #pragma warning(pop)
  6917. #else
  6918. #pragma warning(default : 4200)
  6919. #endif
  6920. //SS: end of changes to support clustering
  6921. //
  6922.  
  6923. // begin_ntddk begin_wdm begin_nthal
  6924. //
  6925. // Registry Specific Access Rights.
  6926. //
  6927.  
  6928. #define KEY_QUERY_VALUE         (0x0001)
  6929. #define KEY_SET_VALUE           (0x0002)
  6930. #define KEY_CREATE_SUB_KEY      (0x0004)
  6931. #define KEY_ENUMERATE_SUB_KEYS  (0x0008)
  6932. #define KEY_NOTIFY              (0x0010)
  6933. #define KEY_CREATE_LINK         (0x0020)
  6934.  
  6935. #define KEY_READ                ((STANDARD_RIGHTS_READ       |\
  6936.                                   KEY_QUERY_VALUE            |\
  6937.                                   KEY_ENUMERATE_SUB_KEYS     |\
  6938.                                   KEY_NOTIFY)                 \
  6939.                                   &                           \
  6940.                                  (~SYNCHRONIZE))
  6941.  
  6942.  
  6943. #define KEY_WRITE               ((STANDARD_RIGHTS_WRITE      |\
  6944.                                   KEY_SET_VALUE              |\
  6945.                                   KEY_CREATE_SUB_KEY)         \
  6946.                                   &                           \
  6947.                                  (~SYNCHRONIZE))
  6948.  
  6949. #define KEY_EXECUTE             ((KEY_READ)                   \
  6950.                                   &                           \
  6951.                                  (~SYNCHRONIZE))
  6952.  
  6953. #define KEY_ALL_ACCESS          ((STANDARD_RIGHTS_ALL        |\
  6954.                                   KEY_QUERY_VALUE            |\
  6955.                                   KEY_SET_VALUE              |\
  6956.                                   KEY_CREATE_SUB_KEY         |\
  6957.                                   KEY_ENUMERATE_SUB_KEYS     |\
  6958.                                   KEY_NOTIFY                 |\
  6959.                                   KEY_CREATE_LINK)            \
  6960.                                   &                           \
  6961.                                  (~SYNCHRONIZE))
  6962.  
  6963. //
  6964. // Open/Create Options
  6965. //
  6966.  
  6967. #define REG_OPTION_RESERVED         (0x00000000L)   // Parameter is reserved
  6968.  
  6969. #define REG_OPTION_NON_VOLATILE     (0x00000000L)   // Key is preserved
  6970.                                                     // when system is rebooted
  6971.  
  6972. #define REG_OPTION_VOLATILE         (0x00000001L)   // Key is not preserved
  6973.                                                     // when system is rebooted
  6974.  
  6975. #define REG_OPTION_CREATE_LINK      (0x00000002L)   // Created key is a
  6976.                                                     // symbolic link
  6977.  
  6978. #define REG_OPTION_BACKUP_RESTORE   (0x00000004L)   // open for backup or restore
  6979.                                                     // special access rules
  6980.                                                     // privilege required
  6981.  
  6982. #define REG_OPTION_OPEN_LINK        (0x00000008L)   // Open symbolic link
  6983.  
  6984. #define REG_LEGAL_OPTION            \
  6985.                 (REG_OPTION_RESERVED            |\
  6986.                  REG_OPTION_NON_VOLATILE        |\
  6987.                  REG_OPTION_VOLATILE            |\
  6988.                  REG_OPTION_CREATE_LINK         |\
  6989.                  REG_OPTION_BACKUP_RESTORE      |\
  6990.                  REG_OPTION_OPEN_LINK)
  6991.  
  6992. //
  6993. // Key creation/open disposition
  6994. //
  6995.  
  6996. #define REG_CREATED_NEW_KEY         (0x00000001L)   // New Registry Key created
  6997. #define REG_OPENED_EXISTING_KEY     (0x00000002L)   // Existing Key opened
  6998.  
  6999. //
  7000. // Key restore flags
  7001. //
  7002.  
  7003. #define REG_WHOLE_HIVE_VOLATILE     (0x00000001L)   // Restore whole hive volatile
  7004. #define REG_REFRESH_HIVE            (0x00000002L)   // Unwind changes to last flush
  7005. #define REG_NO_LAZY_FLUSH           (0x00000004L)   // Never lazy flush this hive
  7006. #define REG_FORCE_RESTORE           (0x00000008L)   // Force the restore process even when we have open handles on subkeys
  7007.  
  7008. // end_ntddk end_wdm end_nthal
  7009.  
  7010. //
  7011. // Notify filter values
  7012. //
  7013. #define REG_NOTIFY_CHANGE_NAME          (0x00000001L) // Create or delete (child)
  7014. #define REG_NOTIFY_CHANGE_ATTRIBUTES    (0x00000002L)
  7015. #define REG_NOTIFY_CHANGE_LAST_SET      (0x00000004L) // time stamp
  7016. #define REG_NOTIFY_CHANGE_SECURITY      (0x00000008L)
  7017.  
  7018. #define REG_LEGAL_CHANGE_FILTER                 \
  7019.                 (REG_NOTIFY_CHANGE_NAME          |\
  7020.                  REG_NOTIFY_CHANGE_ATTRIBUTES    |\
  7021.                  REG_NOTIFY_CHANGE_LAST_SET      |\
  7022.                  REG_NOTIFY_CHANGE_SECURITY)
  7023.  
  7024. //
  7025. //
  7026. // Predefined Value Types.
  7027. //
  7028.  
  7029. #define REG_NONE                    ( 0 )   // No value type
  7030. #define REG_SZ                      ( 1 )   // Unicode nul terminated string
  7031. #define REG_EXPAND_SZ               ( 2 )   // Unicode nul terminated string
  7032.                                             // (with environment variable references)
  7033. #define REG_BINARY                  ( 3 )   // Free form binary
  7034. #define REG_DWORD                   ( 4 )   // 32-bit number
  7035. #define REG_DWORD_LITTLE_ENDIAN     ( 4 )   // 32-bit number (same as REG_DWORD)
  7036. #define REG_DWORD_BIG_ENDIAN        ( 5 )   // 32-bit number
  7037. #define REG_LINK                    ( 6 )   // Symbolic Link (unicode)
  7038. #define REG_MULTI_SZ                ( 7 )   // Multiple Unicode strings
  7039. #define REG_RESOURCE_LIST           ( 8 )   // Resource list in the resource map
  7040. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 )  // Resource list in the hardware description
  7041. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  7042. #define REG_QWORD                   ( 11 )  // 64-bit number
  7043. #define REG_QWORD_LITTLE_ENDIAN     ( 11 )  // 64-bit number (same as REG_QWORD)
  7044.  
  7045. // end_ntddk end_wdm end_nthal
  7046.  
  7047. // begin_ntddk begin_wdm begin_nthal
  7048. //
  7049. // Service Types (Bit Mask)
  7050. //
  7051. #define SERVICE_KERNEL_DRIVER          0x00000001
  7052. #define SERVICE_FILE_SYSTEM_DRIVER     0x00000002
  7053. #define SERVICE_ADAPTER                0x00000004
  7054. #define SERVICE_RECOGNIZER_DRIVER      0x00000008
  7055.  
  7056. #define SERVICE_DRIVER                 (SERVICE_KERNEL_DRIVER | \
  7057.                                         SERVICE_FILE_SYSTEM_DRIVER | \
  7058.                                         SERVICE_RECOGNIZER_DRIVER)
  7059.  
  7060. #define SERVICE_WIN32_OWN_PROCESS      0x00000010
  7061. #define SERVICE_WIN32_SHARE_PROCESS    0x00000020
  7062. #define SERVICE_WIN32                  (SERVICE_WIN32_OWN_PROCESS | \
  7063.                                         SERVICE_WIN32_SHARE_PROCESS)
  7064.  
  7065. #define SERVICE_INTERACTIVE_PROCESS    0x00000100
  7066.  
  7067. #define SERVICE_TYPE_ALL               (SERVICE_WIN32  | \
  7068.                                         SERVICE_ADAPTER | \
  7069.                                         SERVICE_DRIVER  | \
  7070.                                         SERVICE_INTERACTIVE_PROCESS)
  7071.  
  7072. //
  7073. // Start Type
  7074. //
  7075.  
  7076. #define SERVICE_BOOT_START             0x00000000
  7077. #define SERVICE_SYSTEM_START           0x00000001
  7078. #define SERVICE_AUTO_START             0x00000002
  7079. #define SERVICE_DEMAND_START           0x00000003
  7080. #define SERVICE_DISABLED               0x00000004
  7081.  
  7082. //
  7083. // Error control type
  7084. //
  7085. #define SERVICE_ERROR_IGNORE           0x00000000
  7086. #define SERVICE_ERROR_NORMAL           0x00000001
  7087. #define SERVICE_ERROR_SEVERE           0x00000002
  7088. #define SERVICE_ERROR_CRITICAL         0x00000003
  7089.  
  7090. //
  7091. //
  7092. // Define the registry driver node enumerations
  7093. //
  7094.  
  7095. typedef enum _CM_SERVICE_NODE_TYPE {
  7096.     DriverType               = SERVICE_KERNEL_DRIVER,
  7097.     FileSystemType           = SERVICE_FILE_SYSTEM_DRIVER,
  7098.     Win32ServiceOwnProcess   = SERVICE_WIN32_OWN_PROCESS,
  7099.     Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  7100.     AdapterType              = SERVICE_ADAPTER,
  7101.     RecognizerType           = SERVICE_RECOGNIZER_DRIVER
  7102. } SERVICE_NODE_TYPE;
  7103.  
  7104. typedef enum _CM_SERVICE_LOAD_TYPE {
  7105.     BootLoad    = SERVICE_BOOT_START,
  7106.     SystemLoad  = SERVICE_SYSTEM_START,
  7107.     AutoLoad    = SERVICE_AUTO_START,
  7108.     DemandLoad  = SERVICE_DEMAND_START,
  7109.     DisableLoad = SERVICE_DISABLED
  7110. } SERVICE_LOAD_TYPE;
  7111.  
  7112. typedef enum _CM_ERROR_CONTROL_TYPE {
  7113.     IgnoreError   = SERVICE_ERROR_IGNORE,
  7114.     NormalError   = SERVICE_ERROR_NORMAL,
  7115.     SevereError   = SERVICE_ERROR_SEVERE,
  7116.     CriticalError = SERVICE_ERROR_CRITICAL
  7117. } SERVICE_ERROR_TYPE;
  7118.  
  7119.  
  7120.  
  7121. //
  7122. // IOCTL_TAPE_ERASE definitions
  7123. //
  7124.  
  7125. #define TAPE_ERASE_SHORT            0L
  7126. #define TAPE_ERASE_LONG             1L
  7127.  
  7128. typedef struct _TAPE_ERASE {
  7129.     DWORD Type;
  7130.     BOOLEAN Immediate;
  7131. } TAPE_ERASE, *PTAPE_ERASE;
  7132.  
  7133. //
  7134. // IOCTL_TAPE_PREPARE definitions
  7135. //
  7136.  
  7137. #define TAPE_LOAD                   0L
  7138. #define TAPE_UNLOAD                 1L
  7139. #define TAPE_TENSION                2L
  7140. #define TAPE_LOCK                   3L
  7141. #define TAPE_UNLOCK                 4L
  7142. #define TAPE_FORMAT                 5L
  7143.  
  7144. typedef struct _TAPE_PREPARE {
  7145.     DWORD Operation;
  7146.     BOOLEAN Immediate;
  7147. } TAPE_PREPARE, *PTAPE_PREPARE;
  7148.  
  7149. //
  7150. // IOCTL_TAPE_WRITE_MARKS definitions
  7151. //
  7152.  
  7153. #define TAPE_SETMARKS               0L
  7154. #define TAPE_FILEMARKS              1L
  7155. #define TAPE_SHORT_FILEMARKS        2L
  7156. #define TAPE_LONG_FILEMARKS         3L
  7157.  
  7158. typedef struct _TAPE_WRITE_MARKS {
  7159.     DWORD Type;
  7160.     DWORD Count;
  7161.     BOOLEAN Immediate;
  7162. } TAPE_WRITE_MARKS, *PTAPE_WRITE_MARKS;
  7163.  
  7164. //
  7165. // IOCTL_TAPE_GET_POSITION definitions
  7166. //
  7167.  
  7168. #define TAPE_ABSOLUTE_POSITION       0L
  7169. #define TAPE_LOGICAL_POSITION        1L
  7170. #define TAPE_PSEUDO_LOGICAL_POSITION 2L
  7171.  
  7172. typedef struct _TAPE_GET_POSITION {
  7173.     DWORD Type;
  7174.     DWORD Partition;
  7175.     LARGE_INTEGER Offset;
  7176. } TAPE_GET_POSITION, *PTAPE_GET_POSITION;
  7177.  
  7178. //
  7179. // IOCTL_TAPE_SET_POSITION definitions
  7180. //
  7181.  
  7182. #define TAPE_REWIND                 0L
  7183. #define TAPE_ABSOLUTE_BLOCK         1L
  7184. #define TAPE_LOGICAL_BLOCK          2L
  7185. #define TAPE_PSEUDO_LOGICAL_BLOCK   3L
  7186. #define TAPE_SPACE_END_OF_DATA      4L
  7187. #define TAPE_SPACE_RELATIVE_BLOCKS  5L
  7188. #define TAPE_SPACE_FILEMARKS        6L
  7189. #define TAPE_SPACE_SEQUENTIAL_FMKS  7L
  7190. #define TAPE_SPACE_SETMARKS         8L
  7191. #define TAPE_SPACE_SEQUENTIAL_SMKS  9L
  7192.  
  7193. typedef struct _TAPE_SET_POSITION {
  7194.     DWORD Method;
  7195.     DWORD Partition;
  7196.     LARGE_INTEGER Offset;
  7197.     BOOLEAN Immediate;
  7198. } TAPE_SET_POSITION, *PTAPE_SET_POSITION;
  7199.  
  7200. //
  7201. // IOCTL_TAPE_GET_DRIVE_PARAMS definitions
  7202. //
  7203.  
  7204. //
  7205. // Definitions for FeaturesLow parameter
  7206. //
  7207.  
  7208. #define TAPE_DRIVE_FIXED            0x00000001
  7209. #define TAPE_DRIVE_SELECT           0x00000002
  7210. #define TAPE_DRIVE_INITIATOR        0x00000004
  7211.  
  7212. #define TAPE_DRIVE_ERASE_SHORT      0x00000010
  7213. #define TAPE_DRIVE_ERASE_LONG       0x00000020
  7214. #define TAPE_DRIVE_ERASE_BOP_ONLY   0x00000040
  7215. #define TAPE_DRIVE_ERASE_IMMEDIATE  0x00000080
  7216.  
  7217. #define TAPE_DRIVE_TAPE_CAPACITY    0x00000100
  7218. #define TAPE_DRIVE_TAPE_REMAINING   0x00000200
  7219. #define TAPE_DRIVE_FIXED_BLOCK      0x00000400
  7220. #define TAPE_DRIVE_VARIABLE_BLOCK   0x00000800
  7221.  
  7222. #define TAPE_DRIVE_WRITE_PROTECT    0x00001000
  7223. #define TAPE_DRIVE_EOT_WZ_SIZE      0x00002000
  7224.  
  7225. #define TAPE_DRIVE_ECC              0x00010000
  7226. #define TAPE_DRIVE_COMPRESSION      0x00020000
  7227. #define TAPE_DRIVE_PADDING          0x00040000
  7228. #define TAPE_DRIVE_REPORT_SMKS      0x00080000
  7229.  
  7230. #define TAPE_DRIVE_GET_ABSOLUTE_BLK 0x00100000
  7231. #define TAPE_DRIVE_GET_LOGICAL_BLK  0x00200000
  7232. #define TAPE_DRIVE_SET_EOT_WZ_SIZE  0x00400000
  7233.  
  7234. #define TAPE_DRIVE_EJECT_MEDIA      0x01000000
  7235. #define TAPE_DRIVE_CLEAN_REQUESTS   0x02000000
  7236. #define TAPE_DRIVE_SET_CMP_BOP_ONLY 0x04000000
  7237.  
  7238. #define TAPE_DRIVE_RESERVED_BIT     0x80000000  //don't use this bit!
  7239. //                                              //can't be a low features bit!
  7240. //                                              //reserved; high features only
  7241.  
  7242. //
  7243. // Definitions for FeaturesHigh parameter
  7244. //
  7245.  
  7246. #define TAPE_DRIVE_LOAD_UNLOAD      0x80000001
  7247. #define TAPE_DRIVE_TENSION          0x80000002
  7248. #define TAPE_DRIVE_LOCK_UNLOCK      0x80000004
  7249. #define TAPE_DRIVE_REWIND_IMMEDIATE 0x80000008
  7250.  
  7251. #define TAPE_DRIVE_SET_BLOCK_SIZE   0x80000010
  7252. #define TAPE_DRIVE_LOAD_UNLD_IMMED  0x80000020
  7253. #define TAPE_DRIVE_TENSION_IMMED    0x80000040
  7254. #define TAPE_DRIVE_LOCK_UNLK_IMMED  0x80000080
  7255.  
  7256. #define TAPE_DRIVE_SET_ECC          0x80000100
  7257. #define TAPE_DRIVE_SET_COMPRESSION  0x80000200
  7258. #define TAPE_DRIVE_SET_PADDING      0x80000400
  7259. #define TAPE_DRIVE_SET_REPORT_SMKS  0x80000800
  7260.  
  7261. #define TAPE_DRIVE_ABSOLUTE_BLK     0x80001000
  7262. #define TAPE_DRIVE_ABS_BLK_IMMED    0x80002000
  7263. #define TAPE_DRIVE_LOGICAL_BLK      0x80004000
  7264. #define TAPE_DRIVE_LOG_BLK_IMMED    0x80008000
  7265.  
  7266. #define TAPE_DRIVE_END_OF_DATA      0x80010000
  7267. #define TAPE_DRIVE_RELATIVE_BLKS    0x80020000
  7268. #define TAPE_DRIVE_FILEMARKS        0x80040000
  7269. #define TAPE_DRIVE_SEQUENTIAL_FMKS  0x80080000
  7270.  
  7271. #define TAPE_DRIVE_SETMARKS         0x80100000
  7272. #define TAPE_DRIVE_SEQUENTIAL_SMKS  0x80200000
  7273. #define TAPE_DRIVE_REVERSE_POSITION 0x80400000
  7274. #define TAPE_DRIVE_SPACE_IMMEDIATE  0x80800000
  7275.  
  7276. #define TAPE_DRIVE_WRITE_SETMARKS   0x81000000
  7277. #define TAPE_DRIVE_WRITE_FILEMARKS  0x82000000
  7278. #define TAPE_DRIVE_WRITE_SHORT_FMKS 0x84000000
  7279. #define TAPE_DRIVE_WRITE_LONG_FMKS  0x88000000
  7280.  
  7281. #define TAPE_DRIVE_WRITE_MARK_IMMED 0x90000000
  7282. #define TAPE_DRIVE_FORMAT           0xA0000000
  7283. #define TAPE_DRIVE_FORMAT_IMMEDIATE 0xC0000000
  7284. #define TAPE_DRIVE_HIGH_FEATURES    0x80000000  //mask for high features flag
  7285.  
  7286. typedef struct _TAPE_GET_DRIVE_PARAMETERS {
  7287.     BOOLEAN ECC;
  7288.     BOOLEAN Compression;
  7289.     BOOLEAN DataPadding;
  7290.     BOOLEAN ReportSetmarks;
  7291.     DWORD DefaultBlockSize;
  7292.     DWORD MaximumBlockSize;
  7293.     DWORD MinimumBlockSize;
  7294.     DWORD MaximumPartitionCount;
  7295.     DWORD FeaturesLow;
  7296.     DWORD FeaturesHigh;
  7297.     DWORD EOTWarningZoneSize;
  7298. } TAPE_GET_DRIVE_PARAMETERS, *PTAPE_GET_DRIVE_PARAMETERS;
  7299.  
  7300. //
  7301. // IOCTL_TAPE_SET_DRIVE_PARAMETERS definitions
  7302. //
  7303.  
  7304. typedef struct _TAPE_SET_DRIVE_PARAMETERS {
  7305.     BOOLEAN ECC;
  7306.     BOOLEAN Compression;
  7307.     BOOLEAN DataPadding;
  7308.     BOOLEAN ReportSetmarks;
  7309.     DWORD EOTWarningZoneSize;
  7310. } TAPE_SET_DRIVE_PARAMETERS, *PTAPE_SET_DRIVE_PARAMETERS;
  7311.  
  7312. //
  7313. // IOCTL_TAPE_GET_MEDIA_PARAMETERS definitions
  7314. //
  7315.  
  7316. typedef struct _TAPE_GET_MEDIA_PARAMETERS {
  7317.     LARGE_INTEGER Capacity;
  7318.     LARGE_INTEGER Remaining;
  7319.     DWORD BlockSize;
  7320.     DWORD PartitionCount;
  7321.     BOOLEAN WriteProtected;
  7322. } TAPE_GET_MEDIA_PARAMETERS, *PTAPE_GET_MEDIA_PARAMETERS;
  7323.  
  7324. //
  7325. // IOCTL_TAPE_SET_MEDIA_PARAMETERS definitions
  7326. //
  7327.  
  7328. typedef struct _TAPE_SET_MEDIA_PARAMETERS {
  7329.     DWORD BlockSize;
  7330. } TAPE_SET_MEDIA_PARAMETERS, *PTAPE_SET_MEDIA_PARAMETERS;
  7331.  
  7332. //
  7333. // IOCTL_TAPE_CREATE_PARTITION definitions
  7334. //
  7335.  
  7336. #define TAPE_FIXED_PARTITIONS       0L
  7337. #define TAPE_SELECT_PARTITIONS      1L
  7338. #define TAPE_INITIATOR_PARTITIONS   2L
  7339.  
  7340. typedef struct _TAPE_CREATE_PARTITION {
  7341.     DWORD Method;
  7342.     DWORD Count;
  7343.     DWORD Size;
  7344. } TAPE_CREATE_PARTITION, *PTAPE_CREATE_PARTITION;
  7345.  
  7346.  
  7347. #ifdef __cplusplus
  7348. }
  7349. #endif
  7350.  
  7351. #pragma option pop /*P_O_Pop*/
  7352. #endif /* _WINNT_ */
  7353.  
  7354.