home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / winnt.h < prev    next >
C/C++ Source or Header  |  1998-08-20  |  246KB  |  7,223 lines

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