home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / directx2 / sdk / samples / watinc / winnt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-06  |  162.3 KB  |  4,795 lines

  1. /*++ BUILD Version: 0093     Increment this if a change has global effects
  2.  
  3. Copyright (c) 1990-1995  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)
  35. #define UNALIGNED __unaligned
  36. #else
  37. #define UNALIGNED
  38. #endif
  39.  
  40.  
  41. #if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS)
  42. #define DECLSPEC_IMPORT __declspec(dllimport)
  43. #else
  44. #define DECLSPEC_IMPORT
  45. #endif
  46.  
  47. typedef void *PVOID;    
  48.  
  49. #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
  50. #define NTAPI __stdcall
  51. #else
  52. #define _cdecl
  53. #define NTAPI
  54. #endif
  55.  
  56. //
  57. // Define API decoration for direct importing system DLL references.
  58. //
  59.  
  60. #if !defined(_NTSYSTEM_)
  61. #define NTSYSAPI DECLSPEC_IMPORT
  62. #else
  63. #define NTSYSAPI
  64. #endif
  65.  
  66.  
  67. //
  68. // Basics
  69. //
  70.  
  71. #ifndef VOID
  72. #define VOID void
  73. typedef char CHAR;
  74. typedef short SHORT;
  75. typedef long LONG;
  76. #endif
  77.  
  78. //
  79. // UNICODE (Wide Character) types
  80. //
  81.  
  82. typedef wchar_t WCHAR;    // wc,   16-bit UNICODE character
  83.  
  84. typedef WCHAR *PWCHAR;
  85. typedef WCHAR *LPWCH, *PWCH;
  86. typedef CONST WCHAR *LPCWCH, *PCWCH;
  87. typedef WCHAR *NWPSTR;
  88. typedef WCHAR *LPWSTR, *PWSTR;
  89.  
  90. typedef CONST WCHAR *LPCWSTR, *PCWSTR;
  91.  
  92. //
  93. // ANSI (Multi-byte Character) types
  94. //
  95. typedef CHAR *PCHAR;
  96. typedef CHAR *LPCH, *PCH;
  97.  
  98. typedef CONST CHAR *LPCCH, *PCCH;
  99. typedef CHAR *NPSTR;
  100. typedef CHAR *LPSTR, *PSTR;
  101. typedef CONST CHAR *LPCSTR, *PCSTR;
  102.  
  103. //
  104. // Neutral ANSI/UNICODE types and macros
  105. //
  106. #ifdef  UNICODE
  107.  
  108. #ifndef _TCHAR_DEFINED
  109. typedef WCHAR TCHAR, *PTCHAR;
  110. typedef WCHAR TBYTE , *PTBYTE ;
  111. #define _TCHAR_DEFINED
  112. #endif /* !_TCHAR_DEFINED */
  113.  
  114. typedef LPWSTR LPTCH, PTCH;
  115. typedef LPWSTR PTSTR, LPTSTR;
  116. typedef LPCWSTR LPCTSTR;
  117. typedef LPWSTR LP;
  118. #define __TEXT(quote) L##quote
  119.  
  120. #else   /* UNICODE */
  121.  
  122. #ifndef _TCHAR_DEFINED
  123. typedef char TCHAR, *PTCHAR;
  124. typedef unsigned char TBYTE , *PTBYTE ;
  125. #define _TCHAR_DEFINED
  126. #endif /* !_TCHAR_DEFINED */
  127.  
  128. typedef LPSTR LPTCH, PTCH;
  129. typedef LPSTR PTSTR, LPTSTR;
  130. typedef LPCSTR LPCTSTR;
  131. #define __TEXT(quote) quote
  132.  
  133. #endif /* UNICODE */
  134. #define TEXT(quote) __TEXT(quote)
  135.  
  136.  
  137. typedef SHORT *PSHORT;  
  138. typedef LONG *PLONG;    
  139.  
  140. #ifdef STRICT
  141. typedef void *HANDLE;
  142. #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
  143. #else
  144. typedef PVOID HANDLE;
  145. #define DECLARE_HANDLE(name) typedef HANDLE name
  146. #endif
  147. typedef HANDLE *PHANDLE;
  148.  
  149. typedef char CCHAR;          
  150. typedef DWORD LCID;         
  151. typedef PDWORD PLCID;       
  152. typedef WORD   LANGID;      
  153. /*lint -e624 */  
  154. /*lint +e624 */  
  155. #define APPLICATION_ERROR_MASK       0x20000000
  156. #define ERROR_SEVERITY_SUCCESS       0x00000000
  157. #define ERROR_SEVERITY_INFORMATIONAL 0x40000000
  158. #define ERROR_SEVERITY_WARNING       0x80000000
  159. #define ERROR_SEVERITY_ERROR         0xC0000000
  160.  
  161. //
  162. // __int64 is only supported by 2.0 and later midl.
  163. // __midl is set by the 2.0 midl and not by 1.0 midl.
  164. //
  165.  
  166. #if (!defined(MIDL_PASS) || defined(__midl)) && (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64))
  167. typedef __int64 LONGLONG;
  168. typedef unsigned __int64 DWORDLONG;
  169. #else
  170. typedef double LONGLONG;
  171. typedef double DWORDLONG;
  172. #endif
  173.  
  174. typedef LONGLONG *PLONGLONG;
  175. typedef DWORDLONG *PDWORDLONG;
  176.  
  177. // Update Sequence Number
  178.  
  179. typedef LONGLONG USN;
  180.  
  181. #if defined(MIDL_PASS)
  182. typedef struct _LARGE_INTEGER {
  183. #else // MIDL_PASS
  184. typedef union _LARGE_INTEGER {
  185.     struct {
  186.         DWORD LowPart;
  187.         LONG HighPart;
  188.     };
  189.     struct {
  190.         DWORD LowPart;
  191.         LONG HighPart;
  192.     } u;
  193. #endif //MIDL_PASS
  194.     LONGLONG QuadPart;
  195. } LARGE_INTEGER;
  196.  
  197. typedef LARGE_INTEGER *PLARGE_INTEGER;
  198.  
  199.  
  200. #if defined(MIDL_PASS)
  201. typedef struct _ULARGE_INTEGER {
  202. #else // MIDL_PASS
  203. typedef union _ULARGE_INTEGER {
  204.     struct {
  205.         DWORD LowPart;
  206.         DWORD HighPart;
  207.     };
  208.     struct {
  209.         DWORD LowPart;
  210.         DWORD HighPart;
  211.     } u;
  212. #endif //MIDL_PASS
  213.     DWORDLONG QuadPart;
  214. } ULARGE_INTEGER;
  215.  
  216. typedef ULARGE_INTEGER *PULARGE_INTEGER;
  217.  
  218. // end_ntminiport end_ntndis
  219.  
  220. //
  221. // Locally Unique Identifier
  222. //
  223.  
  224. typedef LARGE_INTEGER LUID, *PLUID;
  225.  
  226.  
  227. //
  228. // Define operations to logically shift an int64 by 0..31 bits and to multiply
  229. // 32-bits by 32-bits to form a 64-bit product.
  230. //
  231.  
  232. #if defined(MIDL_PASS) || defined(RC_INVOKED)
  233.  
  234. //
  235. // Midl does not understand inline assembler. Therefore, the Rtl functions
  236. // are used for shifts by 0.31 and multiplies of 32-bits times 32-bits to
  237. // form a 64-bit product.
  238. //
  239.  
  240. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  241. #define UInt32x32To64(a, b) ((DWORDLONG)((DWORD)(a)) * (DWORDLONG)((DWORD)(b)))
  242.  
  243. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  244. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  245. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  246.  
  247. #elif defined(__WATCOMC__)
  248.  
  249. LONGLONG
  250. Int32x32To64 (
  251.     LONG Multiplier,
  252.     LONG Multiplicand
  253.     );
  254.  
  255. DWORDLONG
  256. UInt32x32To64 (
  257.     DWORD Multiplier,
  258.     DWORD Multiplicand
  259.     );
  260.  
  261. DWORDLONG
  262. Int64ShllMod32 (
  263.     DWORDLONG Value,
  264.     DWORD ShiftCount
  265.     );
  266.  
  267. LONGLONG
  268. Int64ShraMod32 (
  269.     LONGLONG Value,
  270.     DWORD ShiftCount
  271.     );
  272.  
  273. DWORDLONG
  274. Int64ShrlMod32 (
  275.     DWORDLONG Value,
  276.     DWORD ShiftCount
  277.     );
  278.  
  279. #pragma aux Int32x32To64 = \
  280.     "imul edx" \
  281.     parm [eax] [edx] \
  282.     value no8087 [eax edx];
  283.  
  284. #pragma aux UInt32x32To64 = \
  285.     "mul edx" \
  286.     parm [eax] [edx] \
  287.     value no8087 [eax edx];
  288.  
  289. #pragma aux Int64ShllMod32 = \
  290.     "shld edx,eax,cl" \
  291.     "shl eax,cl" \
  292.     parm [eax edx] [ecx] \
  293.     modify exact [eax edx] \
  294.     value no8087 [eax edx];
  295.  
  296. #pragma aux Int64ShraMod32 = \
  297.     "shrd eax,edx,cl" \
  298.     "sar edx,cl" \
  299.     parm [eax edx] [ecx] \
  300.     modify exact [eax edx] \
  301.     value no8087 [eax edx];
  302.  
  303. #pragma aux Int64ShrlMod32 = \
  304.     "shrd eax,edx,cl" \
  305.     "shr edx,cl" \
  306.     parm [eax edx] [ecx] \
  307.     modify exact [eax edx] \
  308.     value no8087 [eax edx];
  309.  
  310. #elif defined(_M_MRX000)
  311.  
  312. //
  313. // MIPS uses intrinsic functions to perform shifts by 0..31 and multiplies of
  314. // 32-bits times 32-bits to 64-bits.
  315. //
  316.  
  317. #define Int32x32To64 __emul
  318. #define UInt32x32To64 __emulu
  319.  
  320. #define Int64ShllMod32 __ll_lshift
  321. #define Int64ShraMod32 __ll_rshift
  322. #define Int64ShrlMod32 __ull_rshift
  323.  
  324. #if defined (__cplusplus)
  325. extern "C" {
  326. #endif
  327.  
  328. LONGLONG
  329. NTAPI
  330. Int32x32To64 (
  331.     LONG Multiplier,
  332.     LONG Multiplicand
  333.     );
  334.  
  335. DWORDLONG
  336. NTAPI
  337. UInt32x32To64 (
  338.     DWORD Multiplier,
  339.     DWORD Multiplicand
  340.     );
  341.  
  342. DWORDLONG
  343. NTAPI
  344. Int64ShllMod32 (
  345.     DWORDLONG Value,
  346.     DWORD ShiftCount
  347.     );
  348.  
  349. LONGLONG
  350. NTAPI
  351. Int64ShraMod32 (
  352.     LONGLONG Value,
  353.     DWORD ShiftCount
  354.     );
  355.  
  356. DWORDLONG
  357. NTAPI
  358. Int64ShrlMod32 (
  359.     DWORDLONG Value,
  360.     DWORD ShiftCount
  361.     );
  362.  
  363. #if defined (__cplusplus)
  364. };
  365. #endif
  366.  
  367. #pragma intrinsic(__emul)
  368. #pragma intrinsic(__emulu)
  369.  
  370. #pragma intrinsic(__ll_lshift)
  371. #pragma intrinsic(__ll_rshift)
  372. #pragma intrinsic(__ull_rshift)
  373.  
  374. #elif defined(_M_IX86)
  375.  
  376. //
  377. // The x86 C compiler understands inline assembler. Therefore, inline functions
  378. // that employ inline assembler are used for shifts of 0..31.  The multiplies
  379. // rely on the compiler recognizing the cast of the multiplicand to int64 to
  380. // generate the optimal code inline.
  381. //
  382.  
  383. #define Int32x32To64( a, b ) (LONGLONG)((LONGLONG)(LONG)(a) * (LONG)(b))
  384. #define UInt32x32To64( a, b ) (DWORDLONG)((DWORDLONG)(DWORD)(a) * (DWORD)(b))
  385.  
  386. DWORDLONG
  387. NTAPI
  388. Int64ShllMod32 (
  389.     DWORDLONG Value,
  390.     DWORD ShiftCount
  391.     );
  392.  
  393. LONGLONG
  394. NTAPI
  395. Int64ShraMod32 (
  396.     LONGLONG Value,
  397.     DWORD ShiftCount
  398.     );
  399.  
  400. DWORDLONG
  401. NTAPI
  402. Int64ShrlMod32 (
  403.     DWORDLONG Value,
  404.     DWORD ShiftCount
  405.     );
  406.  
  407. #if !defined (__cplusplus)
  408.  
  409. #pragma warning(disable:4035)               // re-enable below
  410.  
  411. __inline DWORDLONG
  412. NTAPI
  413. Int64ShllMod32 (
  414.     DWORDLONG Value,
  415.     DWORD ShiftCount
  416.     )
  417. {
  418.     _asm    {
  419.         mov     ecx, ShiftCount
  420.         mov     eax, dword ptr [Value]
  421.         mov     edx, dword ptr [Value+4]
  422.         shld    edx, eax, cl
  423.         shl     eax, cl
  424.     }
  425. }
  426.  
  427. __inline LONGLONG
  428. NTAPI
  429. Int64ShraMod32 (
  430.     LONGLONG Value,
  431.     DWORD ShiftCount
  432.     )
  433. {
  434.     _asm {
  435.         mov     ecx, ShiftCount
  436.         mov     eax, dword ptr [Value]
  437.         mov     edx, dword ptr [Value+4]
  438.         shrd    eax, edx, cl
  439.         sar     edx, cl
  440.     }
  441. }
  442.  
  443. __inline DWORDLONG
  444. NTAPI
  445. Int64ShrlMod32 (
  446.     DWORDLONG Value,
  447.     DWORD ShiftCount
  448.     )
  449. {
  450.     _asm    {
  451.         mov     ecx, ShiftCount
  452.         mov     eax, dword ptr [Value]
  453.         mov     edx, dword ptr [Value+4]
  454.         shrd    eax, edx, cl
  455.         shr     edx, cl
  456.     }
  457. }
  458.  
  459. #else
  460.  
  461. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  462. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  463. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  464.  
  465. #endif // !defined (__cplusplus)
  466.  
  467. #pragma warning(default:4035)
  468.  
  469. #elif defined(_M_ALPHA)
  470.  
  471. //
  472. // Alpha has native 64-bit operations that are just as fast as their 32-bit
  473. // counter parts. Therefore, the int64 data type is used directly to form
  474. // shifts of 0..31 and multiplies of 32-bits times 32-bits to form a 64-bit
  475. // product.
  476. //
  477.  
  478. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  479. #define UInt32x32To64(a, b) ((DWORDLONG)((DWORD)(a)) * (DWORDLONG)((DWORD)(b)))
  480.  
  481. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  482. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  483. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  484.  
  485.  
  486. #elif defined(_M_PPC)
  487.  
  488. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  489. #define UInt32x32To64(a, b) ((DWORDLONG)((DWORD)(a)) * (DWORDLONG)((DWORD)(b)))
  490.  
  491. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  492. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  493. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  494.  
  495. #else
  496.  
  497. #error Must define a target architecture.
  498.  
  499. #endif
  500.  
  501. #define UNICODE_NULL ((WCHAR)0) 
  502. typedef BYTE  BOOLEAN;           
  503. typedef BOOLEAN *PBOOLEAN;       
  504. //
  505. //  Doubly linked list structure.  Can be used as either a list head, or
  506. //  as link words.
  507. //
  508.  
  509. typedef struct _LIST_ENTRY {
  510.    struct _LIST_ENTRY *Flink;
  511.    struct _LIST_ENTRY *Blink;
  512. } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;
  513.  
  514. //
  515. //  Singly linked list structure. Can be used as either a list head, or
  516. //  as link words.
  517. //
  518.  
  519. typedef struct _SINGLE_LIST_ENTRY {
  520.     struct _SINGLE_LIST_ENTRY *Next;
  521. } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
  522.  
  523. //
  524. // Base data structures for OLE support
  525. //
  526.  
  527. #ifndef GUID_DEFINED
  528. #define GUID_DEFINED
  529.  
  530. typedef struct _GUID {          // size is 16
  531.     DWORD Data1;
  532.     WORD   Data2;
  533.     WORD   Data3;
  534.     BYTE  Data4[8];
  535. } GUID;
  536.  
  537. #endif // !GUID_DEFINED
  538.  
  539. #ifndef __OBJECTID_DEFINED
  540. #define __OBJECTID_DEFINED
  541.  
  542. typedef struct  _OBJECTID {     // size is 20
  543.     GUID Lineage;
  544.     DWORD Uniquifier;
  545. } OBJECTID;
  546. #endif // !_OBJECTID_DEFINED
  547.  
  548. #define MINCHAR     0x80        
  549. #define MAXCHAR     0x7f        
  550. #define MINSHORT    0x8000      
  551. #define MAXSHORT    0x7fff      
  552. #define MINLONG     0x80000000  
  553. #define MAXLONG     0x7fffffff  
  554. #define MAXBYTE     0xff        
  555. #define MAXWORD     0xffff      
  556. #define MAXDWORD    0xffffffff  
  557. //
  558. // Calculate the byte offset of a field in a structure of type type.
  559. //
  560.  
  561. #define FIELD_OFFSET(type, field)    ((LONG)&(((type *)0)->field))
  562.  
  563.  
  564. //
  565. // Calculate the address of the base of the structure given its type, and an
  566. // address of a field within the structure.
  567. //
  568.  
  569. #define CONTAINING_RECORD(address, type, field) ((type *)( \
  570.                                                   (PCHAR)(address) - \
  571.                                                   (PCHAR)(&((type *)0)->field)))
  572.  
  573. /*
  574.  *  Language IDs.
  575.  *
  576.  *  The following two combinations of primary language ID and
  577.  *  sublanguage ID have special semantics:
  578.  *
  579.  *    Primary Language ID   Sublanguage ID      Result
  580.  *    -------------------   ---------------     ------------------------
  581.  *    LANG_NEUTRAL          SUBLANG_NEUTRAL     Language neutral
  582.  *    LANG_NEUTRAL          SUBLANG_DEFAULT     User default language
  583.  *    LANG_NEUTRAL          SUBLANG_SYS_DEFAULT System default language
  584.  */
  585.  
  586. /*
  587.  *  Primary language IDs.
  588.  */
  589. #define LANG_NEUTRAL                     0x00
  590.  
  591. #define LANG_ARABIC                      0x01
  592. #define LANG_AFRIKAANS                   0x36
  593. #define LANG_ALBANIAN                    0x1c
  594. #define LANG_BASQUE                      0x2d
  595. #define LANG_BULGARIAN                   0x02
  596. #define LANG_BYELORUSSIAN                0x23
  597. #define LANG_CATALAN                     0x03
  598. #define LANG_CHINESE                     0x04
  599. #define LANG_CROATIAN                    0x1a
  600. #define LANG_CZECH                       0x05
  601. #define LANG_DANISH                      0x06
  602. #define LANG_DUTCH                       0x13
  603. #define LANG_ENGLISH                     0x09
  604. #define LANG_ESTONIAN                    0x25
  605. #define LANG_FAEROESE                    0x38
  606. #define LANG_FARSI                       0x29
  607. #define LANG_FINNISH                     0x0b
  608. #define LANG_FRENCH                      0x0c
  609. #define LANG_GERMAN                      0x07
  610. #define LANG_GREEK                       0x08
  611. #define LANG_HEBREW                      0x0D
  612. #define LANG_HUNGARIAN                   0x0e
  613. #define LANG_ICELANDIC                   0x0f
  614. #define LANG_INDONESIAN                  0x21
  615. #define LANG_ITALIAN                     0x10
  616. #define LANG_JAPANESE                    0x11
  617. #define LANG_KOREAN                      0x12
  618. #define LANG_LATVIAN                     0x26
  619. #define LANG_LITHUANIAN                  0x27
  620. #define LANG_NORWEGIAN                   0x14
  621. #define LANG_POLISH                      0x15
  622. #define LANG_PORTUGUESE                  0x16
  623. #define LANG_ROMANIAN                    0x18
  624. #define LANG_RUSSIAN                     0x19
  625. #define LANG_SLOVAK                      0x1b
  626. #define LANG_SLOVENIAN                   0x24
  627. #define LANG_SORBIAN                     0x2e
  628. #define LANG_SPANISH                     0x0a
  629. #define LANG_SWEDISH                     0x1d
  630. #define LANG_THAI                        0x1e
  631. #define LANG_TURKISH                     0x1f
  632. #define LANG_UKRAINIAN                   0x22
  633.  
  634. /*
  635.  *  Sublanguage IDs.
  636.  *
  637.  *  The name immediately following SUBLANG_ dictates which primary
  638.  *  language ID that sublanguage ID can be combined with to form a
  639.  *  valid language ID.
  640.  */
  641. #define SUBLANG_NEUTRAL                  0x00    /* language neutral */
  642. #define SUBLANG_DEFAULT                  0x01    /* user default */
  643. #define SUBLANG_SYS_DEFAULT              0x02    /* system default */
  644.  
  645. #define SUBLANG_ARABIC                   0x01    /* Arabic (Saudi Arabia) */
  646. #define SUBLANG_ARABIC_IRAQ              0x02    /* Arabic (Iraq) */
  647. #define SUBLANG_ARABIC_EGYPT             0x03    /* Arabic (Egypt) */
  648. #define SUBLANG_ARABIC_LIBYA             0x04    /* Arabic (Libya) */
  649. #define SUBLANG_ARABIC_ALGERIA           0x05    /* Arabic (Algeria) */
  650. #define SUBLANG_ARABIC_MOROCCO           0x06    /* Arabic (Morocco) */
  651. #define SUBLANG_ARABIC_TUNISIA           0x07    /* Arabic (Tunisia) */
  652. #define SUBLANG_ARABIC_OMAN              0x08    /* Arabic (Oman) */
  653. #define SUBLANG_ARABIC_YEMEN             0x09    /* Arabic (Yemen) */
  654. #define SUBLANG_ARABIC_SYRIA             0x10    /* Arabic (Syria) */
  655. #define SUBLANG_ARABIC_JORDAN            0x11    /* Arabic (Jordan) */
  656. #define SUBLANG_ARABIC_LEBANON           0x12    /* Arabic (Lebanon) */
  657. #define SUBLANG_ARABIC_KUWAIT            0x13    /* Arabic (Kuwait) */
  658. #define SUBLANG_ARABIC_UAE               0x14    /* Arabic (United Arab Emirates) */
  659. #define SUBLANG_ARABIC_BAHRAIN           0x15    /* Arabic (Bahrain) */
  660. #define SUBLANG_ARABIC_QATAR             0x16    /* Arabic (Qatar) */
  661. #define SUBLANG_CHINESE_TRADITIONAL      0x01    /* Chinese (Taiwan) */
  662. #define SUBLANG_CHINESE_SIMPLIFIED       0x02    /* Chinese (PR China) */
  663. #define SUBLANG_CHINESE_HONGKONG         0x03    /* Chinese (Hong Kong) */
  664. #define SUBLANG_CHINESE_SINGAPORE        0x04    /* Chinese (Singapore) */
  665. #define SUBLANG_DUTCH                    0x01    /* Dutch */
  666. #define SUBLANG_DUTCH_BELGIAN            0x02    /* Dutch (Belgian) */
  667. #define SUBLANG_ENGLISH_US               0x01    /* English (USA) */
  668. #define SUBLANG_ENGLISH_UK               0x02    /* English (UK) */
  669. #define SUBLANG_ENGLISH_AUS              0x03    /* English (Australian) */
  670. #define SUBLANG_ENGLISH_CAN              0x04    /* English (Canadian) */
  671. #define SUBLANG_ENGLISH_NZ               0x05    /* English (New Zealand) */
  672. #define SUBLANG_ENGLISH_EIRE             0x06    /* English (Irish) */
  673. #define SUBLANG_ENGLISH_SAFRICA          0x07    /* English (South Africa) */
  674. #define SUBLANG_ENGLISH_JAMAICA          0x08    /* English (Jamaica) */
  675. #define SUBLANG_ENGLISH_CARRIBEAN        0x09    /* English (Carribean) */
  676. #define SUBLANG_FRENCH                   0x01    /* French */
  677. #define SUBLANG_FRENCH_BELGIAN           0x02    /* French (Belgian) */
  678. #define SUBLANG_FRENCH_CANADIAN          0x03    /* French (Canadian) */
  679. #define SUBLANG_FRENCH_SWISS             0x04    /* French (Swiss) */
  680. #define SUBLANG_FRENCH_LUXEMBOURG        0x05    /* French (Luxembourg) */
  681. #define SUBLANG_GERMAN                   0x01    /* German */
  682. #define SUBLANG_GERMAN_SWISS             0x02    /* German (Swiss) */
  683. #define SUBLANG_GERMAN_AUSTRIAN          0x03    /* German (Austrian) */
  684. #define SUBLANG_GERMAN_LUXEMBOURG        0x04    /* German (Luxembourg) */
  685. #define SUBLANG_GERMAN_LIECHTENSTEIN     0x05    /* German (Liechtenstein) */
  686. #define SUBLANG_ITALIAN                  0x01    /* Italian */
  687. #define SUBLANG_ITALIAN_SWISS            0x02    /* Italian (Swiss) */
  688. #define SUBLANG_KOREAN                   0x01    /* Korean */
  689. #define SUBLANG_KOREAN_JOHAB             0x02    /* Korean (Johab) */
  690. #define SUBLANG_NORWEGIAN_BOKMAL         0x01    /* Norwegian (Bokmal) */
  691. #define SUBLANG_NORWEGIAN_NYNORSK        0x02    /* Norwegian (Nynorsk) */
  692. #define SUBLANG_PORTUGUESE               0x02    /* Portuguese */
  693. #define SUBLANG_PORTUGUESE_BRAZILIAN     0x01    /* Portuguese (Brazilian) */
  694. #define SUBLANG_SPANISH                  0x01    /* Spanish (Castilian) */
  695. #define SUBLANG_SPANISH_MEXICAN          0x02    /* Spanish (Mexican) */
  696. #define SUBLANG_SPANISH_MODERN           0x03    /* Spanish (Modern) */
  697. #define SUBLANG_SPANISH_GUATEMALA        0x04    /* Spanish (Guatemala) */
  698. #define SUBLANG_SPANISH_COSTARICA        0x05    /* Spanish (Costa Rica) */
  699. #define SUBLANG_SPANISH_PANAMA           0x06    /* Spanish (Panama) */
  700. #define SUBLANG_SPANISH_DOMINICAN        0x07    /* Spanish (Dominican Republic) */
  701. #define SUBLANG_SPANISH_VENEZUELA        0x08    /* Spanish (Venezuela) */
  702. #define SUBLANG_SPANISH_COLOMBIA         0x09    /* Spanish (Colombia) */
  703. #define SUBLANG_SPANISH_PERU             0x10    /* Spanish (Peru) */
  704. #define SUBLANG_SPANISH_ARGENTINA        0x11    /* Spanish (Argentina) */
  705. #define SUBLANG_SPANISH_ECUADOR          0x12    /* Spanish (Ecuador) */
  706. #define SUBLANG_SPANISH_CHILE            0x13    /* Spanish (Chile) */
  707. #define SUBLANG_SPANISH_URUGUAY          0x14    /* Spanish (Uruguay) */
  708. #define SUBLANG_SPANISH_PARAGUAY         0x15    /* Spanish (Paraguay) */
  709. #define SUBLANG_SPANISH_BOLIVIA          0x16    /* Spanish (Bolivia) */
  710.  
  711. /*
  712.  *  Sorting IDs.
  713.  *
  714.  */
  715. #define SORT_DEFAULT                     0x0     /* sorting default */
  716.  
  717. #define SORT_JAPANESE_XJIS               0x0     /* Japanese XJIS order */
  718. #define SORT_JAPANESE_UNICODE            0x1     /* Japanese Unicode order */
  719.  
  720. #define SORT_CHINESE_BIG5                0x0     /* Chinese BIG5 order */
  721. #define SORT_CHINESE_UNICODE             0x1     /* Chinese Unicode order */
  722.  
  723. #define SORT_KOREAN_KSC                  0x0     /* Korean KSC order */
  724. #define SORT_KOREAN_UNICODE              0x1     /* Korean Unicode order */
  725.  
  726.  
  727. /*
  728.  *  A language ID is a 16 bit value which is the combination of a
  729.  *  primary language ID and a secondary language ID.  The bits are
  730.  *  allocated as follows:
  731.  *
  732.  *       +-----------------------+-------------------------+
  733.  *       |     Sublanguage ID    |   Primary Language ID   |
  734.  *       +-----------------------+-------------------------+
  735.  *        15                   10 9                       0   bit
  736.  *
  737.  *
  738.  *  Language ID creation/extraction macros:
  739.  *
  740.  *    MAKELANGID    - construct language id from a primary language id and
  741.  *                    a sublanguage id.
  742.  *    PRIMARYLANGID - extract primary language id from a language id.
  743.  *    SUBLANGID     - extract sublanguage id from a language id.
  744.  */
  745. #define MAKELANGID(p, s)       ((((WORD  )(s)) << 10) | (WORD  )(p))
  746. #define PRIMARYLANGID(lgid)    ((WORD  )(lgid) & 0x3ff)
  747. #define SUBLANGID(lgid)        ((WORD  )(lgid) >> 10)
  748.  
  749.  
  750. /*
  751.  *  A locale ID is a 32 bit value which is the combination of a
  752.  *  language ID, a sort ID, and a reserved area.  The bits are
  753.  *  allocated as follows:
  754.  *
  755.  *       +-------------+---------+-------------------------+
  756.  *       |   Reserved  | Sort ID |      Language ID        |
  757.  *       +-------------+---------+-------------------------+
  758.  *        31         20 19     16 15                      0   bit
  759.  *
  760.  *
  761.  *  Locale ID creation/extraction macros:
  762.  *
  763.  *    MAKELCID       - construct locale id from a language id and a sort id.
  764.  *    LANGIDFROMLCID - extract language id from a locale id.
  765.  *    SORTIDFROMLCID - extract sort id from a locale id.
  766.  */
  767. #define NLS_VALID_LOCALE_MASK  0x000fffff
  768.  
  769. #define MAKELCID(lgid, srtid)  ((DWORD)((((DWORD)((WORD  )(srtid))) << 16) |  \
  770.                                          ((DWORD)((WORD  )(lgid)))))
  771. #define LANGIDFROMLCID(lcid)   ((WORD  )(lcid))
  772. #define SORTIDFROMLCID(lcid)   ((WORD  )((((DWORD)(lcid)) & NLS_VALID_LOCALE_MASK) >> 16))
  773.  
  774.  
  775. /*
  776.  *  Default System and User IDs for language and locale.
  777.  */
  778. #define LANG_SYSTEM_DEFAULT    (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
  779. #define LANG_USER_DEFAULT      (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
  780.  
  781. #define LOCALE_SYSTEM_DEFAULT  (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
  782. #define LOCALE_USER_DEFAULT    (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT))
  783.  
  784.  
  785.  
  786. // begin_ntminiport begin_ntndis
  787.  
  788. //
  789. // Macros used to eliminate compiler warning generated when formal
  790. // parameters or local variables are not declared.
  791. //
  792. // Use DBG_UNREFERENCED_PARAMETER() when a parameter is not yet
  793. // referenced but will be once the module is completely developed.
  794. //
  795. // Use DBG_UNREFERENCED_LOCAL_VARIABLE() when a local variable is not yet
  796. // referenced but will be once the module is completely developed.
  797. //
  798. // Use UNREFERENCED_PARAMETER() if a parameter will never be referenced.
  799. //
  800. // DBG_UNREFERENCED_PARAMETER and DBG_UNREFERENCED_LOCAL_VARIABLE will
  801. // eventually be made into a null macro to help determine whether there
  802. // is unfinished work.
  803. //
  804.  
  805. #if ! (defined(lint) || defined(_lint))
  806. #define UNREFERENCED_PARAMETER(P)          (P)
  807. #define DBG_UNREFERENCED_PARAMETER(P)      (P)
  808. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) (V)
  809.  
  810. #else // lint or _lint
  811.  
  812. // Note: lint -e530 says don't complain about uninitialized variables for
  813. // this.  line +e530 turns that checking back on.  Error 527 has to do with
  814. // unreachable code.
  815.  
  816. #define UNREFERENCED_PARAMETER(P)          \
  817.     /*lint -e527 -e530 */ \
  818.     { \
  819.         (P) = (P); \
  820.     } \
  821.     /*lint +e527 +e530 */
  822. #define DBG_UNREFERENCED_PARAMETER(P)      \
  823.     /*lint -e527 -e530 */ \
  824.     { \
  825.         (P) = (P); \
  826.     } \
  827.     /*lint +e527 +e530 */
  828. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) \
  829.     /*lint -e527 -e530 */ \
  830.     { \
  831.         (V) = (V); \
  832.     } \
  833.     /*lint +e527 +e530 */
  834.  
  835. #endif // lint or _lint
  836.  
  837.  
  838. #ifndef WIN32_NO_STATUS 
  839. /*lint -save -e767 */  
  840. #define STATUS_WAIT_0                    ((DWORD   )0x00000000L)    
  841. #define STATUS_ABANDONED_WAIT_0          ((DWORD   )0x00000080L)    
  842. #define STATUS_USER_APC                  ((DWORD   )0x000000C0L)    
  843. #define STATUS_TIMEOUT                   ((DWORD   )0x00000102L)    
  844. #define STATUS_PENDING                   ((DWORD   )0x00000103L)    
  845. #define STATUS_SEGMENT_NOTIFICATION      ((DWORD   )0x40000005L)    
  846. #define STATUS_GUARD_PAGE_VIOLATION      ((DWORD   )0x80000001L)    
  847. #define STATUS_DATATYPE_MISALIGNMENT     ((DWORD   )0x80000002L)    
  848. #define STATUS_BREAKPOINT                ((DWORD   )0x80000003L)    
  849. #define STATUS_SINGLE_STEP               ((DWORD   )0x80000004L)    
  850. #define STATUS_ACCESS_VIOLATION          ((DWORD   )0xC0000005L)    
  851. #define STATUS_IN_PAGE_ERROR             ((DWORD   )0xC0000006L)    
  852. #define STATUS_NO_MEMORY                 ((DWORD   )0xC0000017L)    
  853. #define STATUS_ILLEGAL_INSTRUCTION       ((DWORD   )0xC000001DL)    
  854. #define STATUS_NONCONTINUABLE_EXCEPTION  ((DWORD   )0xC0000025L)    
  855. #define STATUS_INVALID_DISPOSITION       ((DWORD   )0xC0000026L)    
  856. #define STATUS_ARRAY_BOUNDS_EXCEEDED     ((DWORD   )0xC000008CL)    
  857. #define STATUS_FLOAT_DENORMAL_OPERAND    ((DWORD   )0xC000008DL)    
  858. #define STATUS_FLOAT_DIVIDE_BY_ZERO      ((DWORD   )0xC000008EL)    
  859. #define STATUS_FLOAT_INEXACT_RESULT      ((DWORD   )0xC000008FL)    
  860. #define STATUS_FLOAT_INVALID_OPERATION   ((DWORD   )0xC0000090L)    
  861. #define STATUS_FLOAT_OVERFLOW            ((DWORD   )0xC0000091L)    
  862. #define STATUS_FLOAT_STACK_CHECK         ((DWORD   )0xC0000092L)    
  863. #define STATUS_FLOAT_UNDERFLOW           ((DWORD   )0xC0000093L)    
  864. #define STATUS_INTEGER_DIVIDE_BY_ZERO    ((DWORD   )0xC0000094L)    
  865. #define STATUS_INTEGER_OVERFLOW          ((DWORD   )0xC0000095L)    
  866. #define STATUS_PRIVILEGED_INSTRUCTION    ((DWORD   )0xC0000096L)    
  867. #define STATUS_STACK_OVERFLOW            ((DWORD   )0xC00000FDL)    
  868. #define STATUS_CONTROL_C_EXIT            ((DWORD   )0xC000013AL)    
  869. /*lint -restore */  
  870. #endif 
  871. #define MAXIMUM_WAIT_OBJECTS 64     // Maximum number of wait objects
  872.  
  873. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  874. typedef DWORD KSPIN_LOCK;  
  875.  
  876. #ifdef _ALPHA_
  877.  
  878. // begin_ntddk begin_nthal
  879. //
  880. // The following flags control the contents of the CONTEXT structure.
  881. //
  882.  
  883. #if !defined(RC_INVOKED)
  884.  
  885. #define CONTEXT_PORTABLE_32BIT     0x00100000
  886. #define CONTEXT_ALPHA              0x00020000
  887.  
  888. #define CONTEXT_CONTROL         (CONTEXT_ALPHA | 0x00000001L)
  889. #define CONTEXT_FLOATING_POINT  (CONTEXT_ALPHA | 0x00000002L)
  890. #define CONTEXT_INTEGER         (CONTEXT_ALPHA | 0x00000004L)
  891.  
  892. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  893.  
  894. #endif
  895.  
  896. #ifndef _PORTABLE_32BIT_CONTEXT
  897.  
  898. //
  899. // Context Frame
  900. //
  901. //  This frame has a several purposes: 1) it is used as an argument to
  902. //  NtContinue, 2) it is used to construct a call frame for APC delivery,
  903. //  3) it is used to construct a call frame for exception dispatching
  904. //  in user mode, 4) it is used in the user level thread creation
  905. //  routines, and 5) it is used to to pass thread state to debuggers.
  906. //
  907. //  N.B. Because this record is used as a call frame, it must be EXACTLY
  908. //  a multiple of 16 bytes in length.
  909. //
  910. //  There are two variations of the context structure. This is the real one.
  911. //
  912.  
  913. typedef struct _CONTEXT {
  914.  
  915.     //
  916.     // This section is specified/returned if the ContextFlags word contains
  917.     // the flag CONTEXT_FLOATING_POINT.
  918.     //
  919.  
  920.     DWORDLONG FltF0;
  921.     DWORDLONG FltF1;
  922.     DWORDLONG FltF2;
  923.     DWORDLONG FltF3;
  924.     DWORDLONG FltF4;
  925.     DWORDLONG FltF5;
  926.     DWORDLONG FltF6;
  927.     DWORDLONG FltF7;
  928.     DWORDLONG FltF8;
  929.     DWORDLONG FltF9;
  930.     DWORDLONG FltF10;
  931.     DWORDLONG FltF11;
  932.     DWORDLONG FltF12;
  933.     DWORDLONG FltF13;
  934.     DWORDLONG FltF14;
  935.     DWORDLONG FltF15;
  936.     DWORDLONG FltF16;
  937.     DWORDLONG FltF17;
  938.     DWORDLONG FltF18;
  939.     DWORDLONG FltF19;
  940.     DWORDLONG FltF20;
  941.     DWORDLONG FltF21;
  942.     DWORDLONG FltF22;
  943.     DWORDLONG FltF23;
  944.     DWORDLONG FltF24;
  945.     DWORDLONG FltF25;
  946.     DWORDLONG FltF26;
  947.     DWORDLONG FltF27;
  948.     DWORDLONG FltF28;
  949.     DWORDLONG FltF29;
  950.     DWORDLONG FltF30;
  951.     DWORDLONG FltF31;
  952.  
  953.     //
  954.     // This section is specified/returned if the ContextFlags word contains
  955.     // the flag CONTEXT_INTEGER.
  956.     //
  957.     // N.B. The registers gp, sp, and ra are defined in this section, but are
  958.     //  considered part of the control context rather than part of the integer
  959.     //  context.
  960.     //
  961.  
  962.     DWORDLONG IntV0;    //  $0: return value register, v0
  963.     DWORDLONG IntT0;    //  $1: temporary registers, t0 - t7
  964.     DWORDLONG IntT1;    //  $2:
  965.     DWORDLONG IntT2;    //  $3:
  966.     DWORDLONG IntT3;    //  $4:
  967.     DWORDLONG IntT4;    //  $5:
  968.     DWORDLONG IntT5;    //  $6:
  969.     DWORDLONG IntT6;    //  $7:
  970.     DWORDLONG IntT7;    //  $8:
  971.     DWORDLONG IntS0;    //  $9: nonvolatile registers, s0 - s5
  972.     DWORDLONG IntS1;    // $10:
  973.     DWORDLONG IntS2;    // $11:
  974.     DWORDLONG IntS3;    // $12:
  975.     DWORDLONG IntS4;    // $13:
  976.     DWORDLONG IntS5;    // $14:
  977.     DWORDLONG IntFp;    // $15: frame pointer register, fp/s6
  978.     DWORDLONG IntA0;    // $16: argument registers, a0 - a5
  979.     DWORDLONG IntA1;    // $17:
  980.     DWORDLONG IntA2;    // $18:
  981.     DWORDLONG IntA3;    // $19:
  982.     DWORDLONG IntA4;    // $20:
  983.     DWORDLONG IntA5;    // $21:
  984.     DWORDLONG IntT8;    // $22: temporary registers, t8 - t11
  985.     DWORDLONG IntT9;    // $23:
  986.     DWORDLONG IntT10;   // $24:
  987.     DWORDLONG IntT11;   // $25:
  988.     DWORDLONG IntRa;    // $26: return address register, ra
  989.     DWORDLONG IntT12;   // $27: temporary register, t12
  990.     DWORDLONG IntAt;    // $28: assembler temp register, at
  991.     DWORDLONG IntGp;    // $29: global pointer register, gp
  992.     DWORDLONG IntSp;    // $30: stack pointer register, sp
  993.     DWORDLONG IntZero;  // $31: zero register, zero
  994.  
  995.     //
  996.     // This section is specified/returned if the ContextFlags word contains
  997.     // the flag CONTEXT_FLOATING_POINT.
  998.     //
  999.  
  1000.     DWORDLONG Fpcr;     // floating point control register
  1001.     DWORDLONG SoftFpcr; // software extension to FPCR
  1002.  
  1003.     //
  1004.     // This section is specified/returned if the ContextFlags word contains
  1005.     // the flag CONTEXT_CONTROL.
  1006.     //
  1007.     // N.B. The registers gp, sp, and ra are defined in the integer section,
  1008.     //   but are considered part of the control context rather than part of
  1009.     //   the integer context.
  1010.     //
  1011.  
  1012.     DWORDLONG Fir;      // (fault instruction) continuation address
  1013.     DWORD Psr;          // processor status
  1014.  
  1015.     //
  1016.     // The flags values within this flag control the contents of
  1017.     // a CONTEXT record.
  1018.     //
  1019.     // If the context record is used as an input parameter, then
  1020.     // for each portion of the context record controlled by a flag
  1021.     // whose value is set, it is assumed that that portion of the
  1022.     // context record contains valid context. If the context record
  1023.     // is being used to modify a thread's context, then only that
  1024.     // portion of the threads context will be modified.
  1025.     //
  1026.     // If the context record is used as an IN OUT parameter to capture
  1027.     // the context of a thread, then only those portions of the thread's
  1028.     // context corresponding to set flags will be returned.
  1029.     //
  1030.     // The context record is never used as an OUT only parameter.
  1031.     //
  1032.  
  1033.     DWORD ContextFlags;
  1034.     DWORD Fill[4];      // padding for 16-byte stack frame alignment
  1035.  
  1036. } CONTEXT, *PCONTEXT;
  1037.  
  1038. #else
  1039.  
  1040. //
  1041. // 32-bit Context Frame
  1042. //
  1043. //  This alternate version of the Alpha context structure parallels that
  1044. //  of MIPS and IX86 in style for the first 64 entries: 32-bit machines
  1045. //  can operate on the fields, and a value declared as a pointer to an
  1046. //  array of int's can be used to index into the fields.  This makes life
  1047. //  with windbg and ntsd vastly easier.
  1048. //
  1049. //  There are two parts: the first contains the lower 32-bits of each
  1050. //  element in the 64-bit definition above.  The second part contains
  1051. //  the upper 32-bits of each 64-bit element above.
  1052. //
  1053. //  The names in the first part are identical to the 64-bit names.
  1054. //  The second part names are prefixed with "High".
  1055. //
  1056. //  1st half: at 32 bits each, (containing the low parts of 64-bit values)
  1057. //      32 floats, 32 ints, fpcrs, fir, psr, contextflags
  1058. //  2nd half: at 32 bits each
  1059. //      32 floats, 32 ints, fpcrs, fir, fill
  1060. //
  1061. //  There is no external support for the 32-bit version of the context
  1062. //  structure.  It is only used internally by windbg and ntsd.
  1063. //
  1064. //  This structure must be the same size as the 64-bit version above.
  1065. //
  1066.  
  1067. typedef struct _CONTEXT {
  1068.  
  1069.     DWORD FltF0;
  1070.     DWORD FltF1;
  1071.     DWORD FltF2;
  1072.     DWORD FltF3;
  1073.     DWORD FltF4;
  1074.     DWORD FltF5;
  1075.     DWORD FltF6;
  1076.     DWORD FltF7;
  1077.     DWORD FltF8;
  1078.     DWORD FltF9;
  1079.     DWORD FltF10;
  1080.     DWORD FltF11;
  1081.     DWORD FltF12;
  1082.     DWORD FltF13;
  1083.     DWORD FltF14;
  1084.     DWORD FltF15;
  1085.     DWORD FltF16;
  1086.     DWORD FltF17;
  1087.     DWORD FltF18;
  1088.     DWORD FltF19;
  1089.     DWORD FltF20;
  1090.     DWORD FltF21;
  1091.     DWORD FltF22;
  1092.     DWORD FltF23;
  1093.     DWORD FltF24;
  1094.     DWORD FltF25;
  1095.     DWORD FltF26;
  1096.     DWORD FltF27;
  1097.     DWORD FltF28;
  1098.     DWORD FltF29;
  1099.     DWORD FltF30;
  1100.     DWORD FltF31;
  1101.  
  1102.     DWORD IntV0;        //  $0: return value register, v0
  1103.     DWORD IntT0;        //  $1: temporary registers, t0 - t7
  1104.     DWORD IntT1;        //  $2:
  1105.     DWORD IntT2;        //  $3:
  1106.     DWORD IntT3;        //  $4:
  1107.     DWORD IntT4;        //  $5:
  1108.     DWORD IntT5;        //  $6:
  1109.     DWORD IntT6;        //  $7:
  1110.     DWORD IntT7;        //  $8:
  1111.     DWORD IntS0;        //  $9: nonvolatile registers, s0 - s5
  1112.     DWORD IntS1;        // $10:
  1113.     DWORD IntS2;        // $11:
  1114.     DWORD IntS3;        // $12:
  1115.     DWORD IntS4;        // $13:
  1116.     DWORD IntS5;        // $14:
  1117.     DWORD IntFp;        // $15: frame pointer register, fp/s6
  1118.     DWORD IntA0;        // $16: argument registers, a0 - a5
  1119.     DWORD IntA1;        // $17:
  1120.     DWORD IntA2;        // $18:
  1121.     DWORD IntA3;        // $19:
  1122.     DWORD IntA4;        // $20:
  1123.     DWORD IntA5;        // $21:
  1124.     DWORD IntT8;        // $22: temporary registers, t8 - t11
  1125.     DWORD IntT9;        // $23:
  1126.     DWORD IntT10;       // $24:
  1127.     DWORD IntT11;       // $25:
  1128.     DWORD IntRa;        // $26: return address register, ra
  1129.     DWORD IntT12;       // $27: temporary register, t12
  1130.     DWORD IntAt;        // $28: assembler temp register, at
  1131.     DWORD IntGp;        // $29: global pointer register, gp
  1132.     DWORD IntSp;        // $30: stack pointer register, sp
  1133.     DWORD IntZero;      // $31: zero register, zero
  1134.  
  1135.     DWORD Fpcr;         // floating point control register
  1136.     DWORD SoftFpcr;     // software extension to FPCR
  1137.  
  1138.     DWORD Fir;          // (fault instruction) continuation address
  1139.  
  1140.     DWORD Psr;          // processor status
  1141.     DWORD ContextFlags;
  1142.  
  1143.     //
  1144.     // Beginning of the "second half".
  1145.     // The name "High" parallels the HighPart of a LargeInteger.
  1146.     //
  1147.  
  1148.     DWORD HighFltF0;
  1149.     DWORD HighFltF1;
  1150.     DWORD HighFltF2;
  1151.     DWORD HighFltF3;
  1152.     DWORD HighFltF4;
  1153.     DWORD HighFltF5;
  1154.     DWORD HighFltF6;
  1155.     DWORD HighFltF7;
  1156.     DWORD HighFltF8;
  1157.     DWORD HighFltF9;
  1158.     DWORD HighFltF10;
  1159.     DWORD HighFltF11;
  1160.     DWORD HighFltF12;
  1161.     DWORD HighFltF13;
  1162.     DWORD HighFltF14;
  1163.     DWORD HighFltF15;
  1164.     DWORD HighFltF16;
  1165.     DWORD HighFltF17;
  1166.     DWORD HighFltF18;
  1167.     DWORD HighFltF19;
  1168.     DWORD HighFltF20;
  1169.     DWORD HighFltF21;
  1170.     DWORD HighFltF22;
  1171.     DWORD HighFltF23;
  1172.     DWORD HighFltF24;
  1173.     DWORD HighFltF25;
  1174.     DWORD HighFltF26;
  1175.     DWORD HighFltF27;
  1176.     DWORD HighFltF28;
  1177.     DWORD HighFltF29;
  1178.     DWORD HighFltF30;
  1179.     DWORD HighFltF31;
  1180.  
  1181.     DWORD HighIntV0;        //  $0: return value register, v0
  1182.     DWORD HighIntT0;        //  $1: temporary registers, t0 - t7
  1183.     DWORD HighIntT1;        //  $2:
  1184.     DWORD HighIntT2;        //  $3:
  1185.     DWORD HighIntT3;        //  $4:
  1186.     DWORD HighIntT4;        //  $5:
  1187.     DWORD HighIntT5;        //  $6:
  1188.     DWORD HighIntT6;        //  $7:
  1189.     DWORD HighIntT7;        //  $8:
  1190.     DWORD HighIntS0;        //  $9: nonvolatile registers, s0 - s5
  1191.     DWORD HighIntS1;        // $10:
  1192.     DWORD HighIntS2;        // $11:
  1193.     DWORD HighIntS3;        // $12:
  1194.     DWORD HighIntS4;        // $13:
  1195.     DWORD HighIntS5;        // $14:
  1196.     DWORD HighIntFp;        // $15: frame pointer register, fp/s6
  1197.     DWORD HighIntA0;        // $16: argument registers, a0 - a5
  1198.     DWORD HighIntA1;        // $17:
  1199.     DWORD HighIntA2;        // $18:
  1200.     DWORD HighIntA3;        // $19:
  1201.     DWORD HighIntA4;        // $20:
  1202.     DWORD HighIntA5;        // $21:
  1203.     DWORD HighIntT8;        // $22: temporary registers, t8 - t11
  1204.     DWORD HighIntT9;        // $23:
  1205.     DWORD HighIntT10;       // $24:
  1206.     DWORD HighIntT11;       // $25:
  1207.     DWORD HighIntRa;        // $26: return address register, ra
  1208.     DWORD HighIntT12;       // $27: temporary register, t12
  1209.     DWORD HighIntAt;        // $28: assembler temp register, at
  1210.     DWORD HighIntGp;        // $29: global pointer register, gp
  1211.     DWORD HighIntSp;        // $30: stack pointer register, sp
  1212.     DWORD HighIntZero;      // $31: zero register, zero
  1213.  
  1214.     DWORD HighFpcr;         // floating point control register
  1215.     DWORD HighSoftFpcr;     // software extension to FPCR
  1216.     DWORD HighFir;          // processor status
  1217.  
  1218.     double DoNotUseThisField; // to force quadword structure alignment
  1219.     DWORD HighFill[2];      // padding for 16-byte stack frame alignment
  1220.  
  1221. } CONTEXT, *PCONTEXT;
  1222.  
  1223. //
  1224. // These should name the fields in the _PORTABLE_32BIT structure
  1225. // that overlay the Psr and ContextFlags in the normal structure.
  1226. //
  1227.  
  1228. #define _QUAD_PSR_OFFSET   HighSoftFpcr
  1229. #define _QUAD_FLAGS_OFFSET HighFir
  1230.  
  1231. #endif // _PORTABLE_32BIT_CONTEXT
  1232.  
  1233. // end_ntddk end_nthal
  1234.  
  1235. #endif // _ALPHA_
  1236.  
  1237.  
  1238. #ifdef _ALPHA_
  1239.  
  1240. VOID
  1241. __jump_unwind (
  1242.     PVOID VirtualFramePointer,
  1243.     PVOID TargetPc
  1244.     );
  1245.  
  1246. #endif // _ALPHA_
  1247.  
  1248.  
  1249. #ifdef _X86_
  1250.  
  1251. //
  1252. // Disable these two pramas that evaluate to "sti" "cli" on x86 so that driver
  1253. // writers to not leave them inadvertantly in their code.
  1254. //
  1255.  
  1256. #if !defined(MIDL_PASS)
  1257. #if !defined(RC_INVOKED)
  1258.  
  1259. #pragma warning(disable:4164)   // disable C4164 warning so that apps that
  1260.                                 // build with /Od don't get weird errors !
  1261. #ifdef _M_IX86
  1262. #pragma function(_enable)
  1263. #pragma function(_disable)
  1264. #endif
  1265.  
  1266. #pragma warning(default:4164)   // reenable C4164 warning
  1267.  
  1268. #endif
  1269. #endif
  1270.  
  1271.  
  1272. //
  1273. //  Define the size of the 80387 save area, which is in the context frame.
  1274. //
  1275.  
  1276. #define SIZE_OF_80387_REGISTERS      80
  1277.  
  1278. //
  1279. // The following flags control the contents of the CONTEXT structure.
  1280. //
  1281.  
  1282. #if !defined(RC_INVOKED)
  1283.  
  1284. #define CONTEXT_i386    0x00010000    // this assumes that i386 and
  1285. #define CONTEXT_i486    0x00010000    // i486 have identical context records
  1286.  
  1287. #define CONTEXT_CONTROL         (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  1288. #define CONTEXT_INTEGER         (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  1289. #define CONTEXT_SEGMENTS        (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  1290. #define CONTEXT_FLOATING_POINT  (CONTEXT_i386 | 0x00000008L) // 387 state
  1291. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  1292.  
  1293. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  1294.                       CONTEXT_SEGMENTS)
  1295.  
  1296. #endif
  1297.  
  1298. typedef struct _FLOATING_SAVE_AREA {
  1299.     DWORD   ControlWord;
  1300.     DWORD   StatusWord;
  1301.     DWORD   TagWord;
  1302.     DWORD   ErrorOffset;
  1303.     DWORD   ErrorSelector;
  1304.     DWORD   DataOffset;
  1305.     DWORD   DataSelector;
  1306.     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
  1307.     DWORD   Cr0NpxState;
  1308. } FLOATING_SAVE_AREA;
  1309.  
  1310. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  1311.  
  1312. //
  1313. // Context Frame
  1314. //
  1315. //  This frame has a several purposes: 1) it is used as an argument to
  1316. //  NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1317. //  and 3) it is used in the user level thread creation routines.
  1318. //
  1319. //  The layout of the record conforms to a standard call frame.
  1320. //
  1321.  
  1322. typedef struct _CONTEXT {
  1323.  
  1324.     //
  1325.     // The flags values within this flag control the contents of
  1326.     // a CONTEXT record.
  1327.     //
  1328.     // If the context record is used as an input parameter, then
  1329.     // for each portion of the context record controlled by a flag
  1330.     // whose value is set, it is assumed that that portion of the
  1331.     // context record contains valid context. If the context record
  1332.     // is being used to modify a threads context, then only that
  1333.     // portion of the threads context will be modified.
  1334.     //
  1335.     // If the context record is used as an IN OUT parameter to capture
  1336.     // the context of a thread, then only those portions of the thread's
  1337.     // context corresponding to set flags will be returned.
  1338.     //
  1339.     // The context record is never used as an OUT only parameter.
  1340.     //
  1341.  
  1342.     DWORD ContextFlags;
  1343.  
  1344.     //
  1345.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  1346.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  1347.     // included in CONTEXT_FULL.
  1348.     //
  1349.  
  1350.     DWORD   Dr0;
  1351.     DWORD   Dr1;
  1352.     DWORD   Dr2;
  1353.     DWORD   Dr3;
  1354.     DWORD   Dr6;
  1355.     DWORD   Dr7;
  1356.  
  1357.     //
  1358.     // This section is specified/returned if the
  1359.     // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  1360.     //
  1361.  
  1362.     FLOATING_SAVE_AREA FloatSave;
  1363.  
  1364.     //
  1365.     // This section is specified/returned if the
  1366.     // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  1367.     //
  1368.  
  1369.     DWORD   SegGs;
  1370.     DWORD   SegFs;
  1371.     DWORD   SegEs;
  1372.     DWORD   SegDs;
  1373.  
  1374.     //
  1375.     // This section is specified/returned if the
  1376.     // ContextFlags word contians the flag CONTEXT_INTEGER.
  1377.     //
  1378.  
  1379.     DWORD   Edi;
  1380.     DWORD   Esi;
  1381.     DWORD   Ebx;
  1382.     DWORD   Edx;
  1383.     DWORD   Ecx;
  1384.     DWORD   Eax;
  1385.  
  1386.     //
  1387.     // This section is specified/returned if the
  1388.     // ContextFlags word contians the flag CONTEXT_CONTROL.
  1389.     //
  1390.  
  1391.     DWORD   Ebp;
  1392.     DWORD   Eip;
  1393.     DWORD   SegCs;              // MUST BE SANITIZED
  1394.     DWORD   EFlags;             // MUST BE SANITIZED
  1395.     DWORD   Esp;
  1396.     DWORD   SegSs;
  1397.  
  1398. } CONTEXT;
  1399.  
  1400.  
  1401.  
  1402. typedef CONTEXT *PCONTEXT;
  1403.  
  1404. // begin_ntminiport
  1405.  
  1406. #endif //_X86_
  1407.  
  1408.  
  1409. typedef struct _LDT_ENTRY {
  1410.     WORD    LimitLow;
  1411.     WORD    BaseLow;
  1412.     union {
  1413.         struct {
  1414.             BYTE    BaseMid;
  1415.             BYTE    Flags1;     // Declare as bytes to avoid alignment
  1416.             BYTE    Flags2;     // Problems.
  1417.             BYTE    BaseHi;
  1418.         } Bytes;
  1419.         struct {
  1420.             DWORD   BaseMid : 8;
  1421.             DWORD   Type : 5;
  1422.             DWORD   Dpl : 2;
  1423.             DWORD   Pres : 1;
  1424.             DWORD   LimitHi : 4;
  1425.             DWORD   Sys : 1;
  1426.             DWORD   Reserved_0 : 1;
  1427.             DWORD   Default_Big : 1;
  1428.             DWORD   Granularity : 1;
  1429.             DWORD   BaseHi : 8;
  1430.         } Bits;
  1431.     } HighWord;
  1432. } LDT_ENTRY, *PLDT_ENTRY;
  1433.  
  1434.  
  1435. #if defined(_MIPS_)
  1436.  
  1437. // begin_ntddk begin_nthal
  1438. //
  1439. // The following flags control the contents of the CONTEXT structure.
  1440. //
  1441.  
  1442. #if !defined(RC_INVOKED)
  1443.  
  1444. #define CONTEXT_R4000   0x00010000    // r4000 context
  1445.  
  1446. #define CONTEXT_CONTROL         (CONTEXT_R4000 | 0x00000001L)
  1447. #define CONTEXT_FLOATING_POINT  (CONTEXT_R4000 | 0x00000002L)
  1448. #define CONTEXT_INTEGER         (CONTEXT_R4000 | 0x00000004L)
  1449.  
  1450. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  1451.  
  1452. #endif
  1453.  
  1454. //
  1455. // Context Frame
  1456. //
  1457. //  N.B. This frame must be exactly a multiple of 16 bytes in length.
  1458. //
  1459. //  This frame has a several purposes: 1) it is used as an argument to
  1460. //  NtContinue, 2) it is used to constuct a call frame for APC delivery,
  1461. //  3) it is used to construct a call frame for exception dispatching
  1462. //  in user mode, and 4) it is used in the user level thread creation
  1463. //  routines.
  1464. //
  1465. //  The layout of the record conforms to a standard call frame.
  1466. //
  1467.  
  1468. typedef struct _CONTEXT {
  1469.  
  1470.     //
  1471.     // This section is always present and is used as an argument build
  1472.     // area.
  1473.     //
  1474.  
  1475.     DWORD Argument[4];
  1476.  
  1477.     //
  1478.     // This section is specified/returned if the ContextFlags word contains
  1479.     // the flag CONTEXT_FLOATING_POINT.
  1480.     //
  1481.  
  1482.     DWORD FltF0;
  1483.     DWORD FltF1;
  1484.     DWORD FltF2;
  1485.     DWORD FltF3;
  1486.     DWORD FltF4;
  1487.     DWORD FltF5;
  1488.     DWORD FltF6;
  1489.     DWORD FltF7;
  1490.     DWORD FltF8;
  1491.     DWORD FltF9;
  1492.     DWORD FltF10;
  1493.     DWORD FltF11;
  1494.     DWORD FltF12;
  1495.     DWORD FltF13;
  1496.     DWORD FltF14;
  1497.     DWORD FltF15;
  1498.     DWORD FltF16;
  1499.     DWORD FltF17;
  1500.     DWORD FltF18;
  1501.     DWORD FltF19;
  1502.     DWORD FltF20;
  1503.     DWORD FltF21;
  1504.     DWORD FltF22;
  1505.     DWORD FltF23;
  1506.     DWORD FltF24;
  1507.     DWORD FltF25;
  1508.     DWORD FltF26;
  1509.     DWORD FltF27;
  1510.     DWORD FltF28;
  1511.     DWORD FltF29;
  1512.     DWORD FltF30;
  1513.     DWORD FltF31;
  1514.  
  1515.     //
  1516.     // This section is specified/returned if the ContextFlags word contains
  1517.     // the flag CONTEXT_INTEGER.
  1518.     //
  1519.     // N.B. The registers gp, sp, and ra are defined in this section, but are
  1520.     //  considered part of the control context rather than part of the integer
  1521.     //  context.
  1522.     //
  1523.     // N.B. Register zero is not stored in the frame.
  1524.     //
  1525.  
  1526.     DWORD IntZero;
  1527.     DWORD IntAt;
  1528.     DWORD IntV0;
  1529.     DWORD IntV1;
  1530.     DWORD IntA0;
  1531.     DWORD IntA1;
  1532.     DWORD IntA2;
  1533.     DWORD IntA3;
  1534.     DWORD IntT0;
  1535.     DWORD IntT1;
  1536.     DWORD IntT2;
  1537.     DWORD IntT3;
  1538.     DWORD IntT4;
  1539.     DWORD IntT5;
  1540.     DWORD IntT6;
  1541.     DWORD IntT7;
  1542.     DWORD IntS0;
  1543.     DWORD IntS1;
  1544.     DWORD IntS2;
  1545.     DWORD IntS3;
  1546.     DWORD IntS4;
  1547.     DWORD IntS5;
  1548.     DWORD IntS6;
  1549.     DWORD IntS7;
  1550.     DWORD IntT8;
  1551.     DWORD IntT9;
  1552.     DWORD IntK0;
  1553.     DWORD IntK1;
  1554.     DWORD IntGp;
  1555.     DWORD IntSp;
  1556.     DWORD IntS8;
  1557.     DWORD IntRa;
  1558.     DWORD IntLo;
  1559.     DWORD IntHi;
  1560.  
  1561.     //
  1562.     // This section is specified/returned if the ContextFlags word contains
  1563.     // the flag CONTEXT_FLOATING_POINT.
  1564.     //
  1565.  
  1566.     DWORD Fsr;
  1567.  
  1568.     //
  1569.     // This section is specified/returned if the ContextFlags word contains
  1570.     // the flag CONTEXT_CONTROL.
  1571.     //
  1572.     // N.B. The registers gp, sp, and ra are defined in the integer section,
  1573.     //   but are considered part of the control context rather than part of
  1574.     //   the integer context.
  1575.     //
  1576.  
  1577.     DWORD Fir;
  1578.     DWORD Psr;
  1579.  
  1580.     //
  1581.     // The flags values within this flag control the contents of
  1582.     // a CONTEXT record.
  1583.     //
  1584.     // If the context record is used as an input parameter, then
  1585.     // for each portion of the context record controlled by a flag
  1586.     // whose value is set, it is assumed that that portion of the
  1587.     // context record contains valid context. If the context record
  1588.     // is being used to modify a thread's context, then only that
  1589.     // portion of the threads context will be modified.
  1590.     //
  1591.     // If the context record is used as an IN OUT parameter to capture
  1592.     // the context of a thread, then only those portions of the thread's
  1593.     // context corresponding to set flags will be returned.
  1594.     //
  1595.     // The context record is never used as an OUT only parameter.
  1596.     //
  1597.  
  1598.     DWORD ContextFlags;
  1599.  
  1600.     DWORD Fill[2];
  1601. } CONTEXT, *PCONTEXT;
  1602.  
  1603. // end_ntddk end_nthal
  1604.  
  1605. #endif // MIPS
  1606.  
  1607.  
  1608. #if defined(_MIPS_)
  1609.  
  1610. VOID
  1611. __jump_unwind (
  1612.     PVOID Fp,
  1613.     PVOID TargetPc
  1614.     );
  1615.  
  1616. #endif // MIPS
  1617.  
  1618.  
  1619. #if defined(_PPC_)
  1620.  
  1621. // begin_ntddk begin_nthal
  1622. //
  1623. // The following flags control the contents of the CONTEXT structure.
  1624. //
  1625.  
  1626. #if !defined(RC_INVOKED)
  1627.  
  1628. #define CONTEXT_CONTROL         0x00000001L
  1629. #define CONTEXT_FLOATING_POINT  0x00000002L
  1630. #define CONTEXT_INTEGER         0x00000004L
  1631. #define CONTEXT_DEBUG_REGISTERS 0x00000008L
  1632.  
  1633. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  1634.  
  1635. #endif
  1636.  
  1637. //
  1638. // Context Frame
  1639. //
  1640. //  N.B. This frame must be exactly a multiple of 16 bytes in length.
  1641. //
  1642. //  This frame has a several purposes: 1) it is used as an argument to
  1643. //  NtContinue, 2) it is used to constuct a call frame for APC delivery,
  1644. //  3) it is used to construct a call frame for exception dispatching
  1645. //  in user mode, and 4) it is used in the user level thread creation
  1646. //  routines.
  1647. //
  1648. //  Requires at least 8-byte alignment (double)
  1649. //
  1650.  
  1651. typedef struct _CONTEXT {
  1652.  
  1653.     //
  1654.     // This section is specified/returned if the ContextFlags word contains
  1655.     // the flag CONTEXT_FLOATING_POINT.
  1656.     //
  1657.  
  1658.     double Fpr0;                        // Floating registers 0..31
  1659.     double Fpr1;
  1660.     double Fpr2;
  1661.     double Fpr3;
  1662.     double Fpr4;
  1663.     double Fpr5;
  1664.     double Fpr6;
  1665.     double Fpr7;
  1666.     double Fpr8;
  1667.     double Fpr9;
  1668.     double Fpr10;
  1669.     double Fpr11;
  1670.     double Fpr12;
  1671.     double Fpr13;
  1672.     double Fpr14;
  1673.     double Fpr15;
  1674.     double Fpr16;
  1675.     double Fpr17;
  1676.     double Fpr18;
  1677.     double Fpr19;
  1678.     double Fpr20;
  1679.     double Fpr21;
  1680.     double Fpr22;
  1681.     double Fpr23;
  1682.     double Fpr24;
  1683.     double Fpr25;
  1684.     double Fpr26;
  1685.     double Fpr27;
  1686.     double Fpr28;
  1687.     double Fpr29;
  1688.     double Fpr30;
  1689.     double Fpr31;
  1690.     double Fpscr;                       // Floating point status/control reg
  1691.  
  1692.     //
  1693.     // This section is specified/returned if the ContextFlags word contains
  1694.     // the flag CONTEXT_INTEGER.
  1695.     //
  1696.  
  1697.     DWORD Gpr0;                         // General registers 0..31
  1698.     DWORD Gpr1;
  1699.     DWORD Gpr2;
  1700.     DWORD Gpr3;
  1701.     DWORD Gpr4;
  1702.     DWORD Gpr5;
  1703.     DWORD Gpr6;
  1704.     DWORD Gpr7;
  1705.     DWORD Gpr8;
  1706.     DWORD Gpr9;
  1707.     DWORD Gpr10;
  1708.     DWORD Gpr11;
  1709.     DWORD Gpr12;
  1710.     DWORD Gpr13;
  1711.     DWORD Gpr14;
  1712.     DWORD Gpr15;
  1713.     DWORD Gpr16;
  1714.     DWORD Gpr17;
  1715.     DWORD Gpr18;
  1716.     DWORD Gpr19;
  1717.     DWORD Gpr20;
  1718.     DWORD Gpr21;
  1719.     DWORD Gpr22;
  1720.     DWORD Gpr23;
  1721.     DWORD Gpr24;
  1722.     DWORD Gpr25;
  1723.     DWORD Gpr26;
  1724.     DWORD Gpr27;
  1725.     DWORD Gpr28;
  1726.     DWORD Gpr29;
  1727.     DWORD Gpr30;
  1728.     DWORD Gpr31;
  1729.  
  1730.     DWORD Cr;                           // Condition register
  1731.     DWORD Xer;                          // Fixed point exception register
  1732.  
  1733.     //
  1734.     // This section is specified/returned if the ContextFlags word contains
  1735.     // the flag CONTEXT_CONTROL.
  1736.     //
  1737.  
  1738.     DWORD Msr;                          // Machine status register
  1739.     DWORD Iar;                          // Instruction address register
  1740.     DWORD Lr;                           // Link register
  1741.     DWORD Ctr;                          // Count register
  1742.  
  1743.     //
  1744.     // The flags values within this flag control the contents of
  1745.     // a CONTEXT record.
  1746.     //
  1747.     // If the context record is used as an input parameter, then
  1748.     // for each portion of the context record controlled by a flag
  1749.     // whose value is set, it is assumed that that portion of the
  1750.     // context record contains valid context. If the context record
  1751.     // is being used to modify a thread's context, then only that
  1752.     // portion of the threads context will be modified.
  1753.     //
  1754.     // If the context record is used as an IN OUT parameter to capture
  1755.     // the context of a thread, then only those portions of the thread's
  1756.     // context corresponding to set flags will be returned.
  1757.     //
  1758.     // The context record is never used as an OUT only parameter.
  1759.     //
  1760.  
  1761.     DWORD ContextFlags;
  1762.  
  1763.     DWORD Fill[3];                      // Pad out to multiple of 16 bytes
  1764.  
  1765.     //
  1766.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  1767.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  1768.     // included in CONTEXT_FULL.
  1769.     //
  1770.     DWORD Dr0;                          // Breakpoint Register 1
  1771.     DWORD Dr1;                          // Breakpoint Register 2
  1772.     DWORD Dr2;                          // Breakpoint Register 3
  1773.     DWORD Dr3;                          // Breakpoint Register 4
  1774.     DWORD Dr4;                          // Breakpoint Register 5
  1775.     DWORD Dr5;                          // Breakpoint Register 6
  1776.     DWORD Dr6;                          // Debug Status Register
  1777.     DWORD Dr7;                          // Debug Control Register
  1778.  
  1779. } CONTEXT, *PCONTEXT;
  1780.  
  1781. // end_ntddk end_nthal
  1782.  
  1783.  
  1784. //
  1785. // Stack frame header
  1786. //
  1787. //   Order of appearance in stack frame:
  1788. //      Header (six words)
  1789. //      Parameters (at least eight words)
  1790. //      Local variables
  1791. //      Saved GPRs
  1792. //      Saved FPRs
  1793. //
  1794. //   Minimum alignment is 8 bytes
  1795.  
  1796. typedef struct _STACK_FRAME_HEADER {    // GPR 1 points here
  1797.     DWORD BackChain;                    // Addr of previous frame
  1798.     DWORD GlueSaved1;                   // Used by glue code
  1799.     DWORD GlueSaved2;
  1800.     DWORD Reserved1;                    // Reserved
  1801.     DWORD Spare1;                       // Used by tracing, profiling, ...
  1802.     DWORD Spare2;
  1803.  
  1804.     DWORD Parameter0;                   // First 8 parameter words are
  1805.     DWORD Parameter1;                   //   always present
  1806.     DWORD Parameter2;
  1807.     DWORD Parameter3;
  1808.     DWORD Parameter4;
  1809.     DWORD Parameter5;
  1810.     DWORD Parameter6;
  1811.     DWORD Parameter7;
  1812.  
  1813. } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
  1814.  
  1815. #endif // _PPC_
  1816.  
  1817.  
  1818. #if defined(_PPC_)
  1819.  
  1820. // **FINISH** This may need alteration for PowerPC
  1821.  
  1822. VOID
  1823. __jump_unwind (
  1824.     PVOID Fp,
  1825.     PVOID TargetPc
  1826.     );
  1827.  
  1828. #endif // _PPC_
  1829.  
  1830. #define EXCEPTION_NONCONTINUABLE 0x1    // Noncontinuable exception
  1831. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  1832.  
  1833. //
  1834. // Exception record definition.
  1835. //
  1836.  
  1837. typedef struct _EXCEPTION_RECORD {
  1838.     /*lint -e18 */  // Don't complain about different definitions
  1839.     DWORD    ExceptionCode;
  1840.     /*lint +e18 */  // Resume checking for different definitions
  1841.     DWORD ExceptionFlags;
  1842.     struct _EXCEPTION_RECORD *ExceptionRecord;
  1843.     PVOID ExceptionAddress;
  1844.     DWORD NumberParameters;
  1845.     DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  1846.     } EXCEPTION_RECORD;
  1847.  
  1848. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  1849.  
  1850. //
  1851. // Typedef for pointer returned by exception_info()
  1852. //
  1853.  
  1854. typedef struct _EXCEPTION_POINTERS {
  1855.     PEXCEPTION_RECORD ExceptionRecord;
  1856.     PCONTEXT ContextRecord;
  1857. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  1858. #define PROCESS_TERMINATE         (0x0001)  
  1859. #define PROCESS_CREATE_THREAD     (0x0002)  
  1860. #define PROCESS_VM_OPERATION      (0x0008)  
  1861. #define PROCESS_VM_READ           (0x0010)  
  1862. #define PROCESS_VM_WRITE          (0x0020)  
  1863. #define PROCESS_DUP_HANDLE        (0x0040)  
  1864. #define PROCESS_CREATE_PROCESS    (0x0080)  
  1865. #define PROCESS_SET_QUOTA         (0x0100)  
  1866. #define PROCESS_SET_INFORMATION   (0x0200)  
  1867. #define PROCESS_QUERY_INFORMATION (0x0400)  
  1868. #define PROCESS_ALL_ACCESS        (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  1869.                                    0xFFF)
  1870.  
  1871. #define THREAD_TERMINATE               (0x0001)  
  1872. #define THREAD_SUSPEND_RESUME          (0x0002)  
  1873. #define THREAD_GET_CONTEXT             (0x0008)  
  1874. #define THREAD_SET_CONTEXT             (0x0010)  
  1875. #define THREAD_SET_INFORMATION         (0x0020)  
  1876. #define THREAD_QUERY_INFORMATION       (0x0040)  
  1877. #define THREAD_SET_THREAD_TOKEN        (0x0080)
  1878. #define THREAD_IMPERSONATE             (0x0100)
  1879. #define THREAD_DIRECT_IMPERSONATION    (0x0200)
  1880. // begin_ntddk
  1881.  
  1882. #define THREAD_ALL_ACCESS         (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  1883.                                    0x3FF)
  1884.  
  1885. // end_ntddk
  1886. #define TLS_MINIMUM_AVAILABLE 64    
  1887. #define THREAD_BASE_PRIORITY_LOWRT  15  // value that gets a thread to LowRealtime-1
  1888. #define THREAD_BASE_PRIORITY_MAX    2   // maximum thread base priority boost
  1889. #define THREAD_BASE_PRIORITY_MIN    -2  // minimum thread base priority boost
  1890. #define THREAD_BASE_PRIORITY_IDLE   -15 // value that gets a thread to idle
  1891.  
  1892. typedef struct _QUOTA_LIMITS {
  1893.     DWORD PagedPoolLimit;
  1894.     DWORD NonPagedPoolLimit;
  1895.     DWORD MinimumWorkingSetSize;
  1896.     DWORD MaximumWorkingSetSize;
  1897.     DWORD PagefileLimit;
  1898.     LARGE_INTEGER TimeLimit;
  1899. } QUOTA_LIMITS;
  1900. typedef QUOTA_LIMITS *PQUOTA_LIMITS;
  1901.  
  1902. #define EVENT_MODIFY_STATE      0x0002  
  1903. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  1904. #define MUTANT_QUERY_STATE      0x0001
  1905.  
  1906. #define MUTANT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|\
  1907.                           MUTANT_QUERY_STATE)
  1908. #define SEMAPHORE_MODIFY_STATE      0x0002  
  1909. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  1910. #define TIME_ZONE_ID_UNKNOWN  0
  1911. #define TIME_ZONE_ID_STANDARD 1
  1912. #define TIME_ZONE_ID_DAYLIGHT 2
  1913.  
  1914. #define PROCESSOR_INTEL_386     386
  1915. #define PROCESSOR_INTEL_486     486
  1916. #define PROCESSOR_INTEL_PENTIUM 586
  1917. #define PROCESSOR_MIPS_R4000    4000
  1918. #define PROCESSOR_ALPHA_21064   21064
  1919.  
  1920. #define PROCESSOR_ARCHITECTURE_INTEL 0
  1921. #define PROCESSOR_ARCHITECTURE_MIPS  1
  1922. #define PROCESSOR_ARCHITECTURE_ALPHA 2
  1923. #define PROCESSOR_ARCHITECTURE_PPC   3
  1924. #define PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF
  1925.  
  1926. typedef struct _MEMORY_BASIC_INFORMATION {
  1927.     PVOID BaseAddress;
  1928.     PVOID AllocationBase;
  1929.     DWORD AllocationProtect;
  1930.     DWORD RegionSize;
  1931.     DWORD State;
  1932.     DWORD Protect;
  1933.     DWORD Type;
  1934. } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
  1935. #define SECTION_QUERY       0x0001
  1936. #define SECTION_MAP_WRITE   0x0002
  1937. #define SECTION_MAP_READ    0x0004
  1938. #define SECTION_MAP_EXECUTE 0x0008
  1939. #define SECTION_EXTEND_SIZE 0x0010
  1940.  
  1941. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  1942.                             SECTION_MAP_WRITE |      \
  1943.                             SECTION_MAP_READ |       \
  1944.                             SECTION_MAP_EXECUTE |    \
  1945.                             SECTION_EXTEND_SIZE)
  1946. #define PAGE_NOACCESS          0x01     
  1947. #define PAGE_READONLY          0x02     
  1948. #define PAGE_READWRITE         0x04     
  1949. #define PAGE_WRITECOPY         0x08     
  1950. #define PAGE_EXECUTE           0x10     
  1951. #define PAGE_EXECUTE_READ      0x20     
  1952. #define PAGE_EXECUTE_READWRITE 0x40     
  1953. #define PAGE_EXECUTE_WRITECOPY 0x80     
  1954. #define PAGE_GUARD            0x100     
  1955. #define PAGE_NOCACHE          0x200     
  1956. #define MEM_COMMIT           0x1000     
  1957. #define MEM_RESERVE          0x2000     
  1958. #define MEM_DECOMMIT         0x4000     
  1959. #define MEM_RELEASE          0x8000     
  1960. #define MEM_FREE            0x10000     
  1961. #define MEM_PRIVATE         0x20000     
  1962. #define MEM_MAPPED          0x40000     
  1963. #define MEM_TOP_DOWN       0x100000     
  1964. #define SEC_FILE           0x800000     
  1965. #define SEC_IMAGE         0x1000000     
  1966. #define SEC_RESERVE       0x4000000     
  1967. #define SEC_COMMIT        0x8000000     
  1968. #define SEC_NOCACHE      0x10000000     
  1969. #define MEM_IMAGE         SEC_IMAGE     
  1970.  
  1971. //
  1972. // Define access rights to files and directories
  1973. //
  1974.  
  1975. //
  1976. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  1977. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  1978. // constants *MUST* always be in sync.
  1979. // The values are redefined in devioctl.h because they must be available to
  1980. // both DOS and NT.
  1981. //
  1982.  
  1983. #define FILE_READ_DATA            ( 0x0001 )    // file & pipe
  1984. #define FILE_LIST_DIRECTORY       ( 0x0001 )    // directory
  1985.  
  1986. #define FILE_WRITE_DATA           ( 0x0002 )    // file & pipe
  1987. #define FILE_ADD_FILE             ( 0x0002 )    // directory
  1988.  
  1989. #define FILE_APPEND_DATA          ( 0x0004 )    // file
  1990. #define FILE_ADD_SUBDIRECTORY     ( 0x0004 )    // directory
  1991. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 )    // named pipe
  1992.  
  1993. #define FILE_READ_EA              ( 0x0008 )    // file & directory
  1994. #define FILE_READ_PROPERTIES      FILE_READ_EA
  1995.  
  1996. #define FILE_WRITE_EA             ( 0x0010 )    // file & directory
  1997. #define FILE_WRITE_PROPERTIES     FILE_WRITE_EA
  1998.  
  1999. #define FILE_EXECUTE              ( 0x0020 )    // file
  2000. #define FILE_TRAVERSE             ( 0x0020 )    // directory
  2001.  
  2002. #define FILE_DELETE_CHILD         ( 0x0040 )    // directory
  2003.  
  2004. #define FILE_READ_ATTRIBUTES      ( 0x0080 )    // all
  2005.  
  2006. #define FILE_WRITE_ATTRIBUTES     ( 0x0100 )    // all
  2007.  
  2008. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  2009.  
  2010. #define FILE_GENERIC_READ         (STANDARD_RIGHTS_READ     |\
  2011.                                    FILE_READ_DATA           |\
  2012.                                    FILE_READ_ATTRIBUTES     |\
  2013.                                    FILE_READ_EA             |\
  2014.                                    SYNCHRONIZE)
  2015.  
  2016.  
  2017. #define FILE_GENERIC_WRITE        (STANDARD_RIGHTS_WRITE    |\
  2018.                                    FILE_WRITE_DATA          |\
  2019.                                    FILE_WRITE_ATTRIBUTES    |\
  2020.                                    FILE_WRITE_EA            |\
  2021.                                    FILE_APPEND_DATA         |\
  2022.                                    SYNCHRONIZE)
  2023.  
  2024.  
  2025. #define FILE_GENERIC_EXECUTE      (STANDARD_RIGHTS_EXECUTE  |\
  2026.                                    FILE_READ_ATTRIBUTES     |\
  2027.                                    FILE_EXECUTE             |\
  2028.                                    SYNCHRONIZE)
  2029.  
  2030. #define FILE_SHARE_READ                 0x00000001  
  2031. #define FILE_SHARE_WRITE                0x00000002  
  2032. #define FILE_ATTRIBUTE_READONLY         0x00000001  
  2033. #define FILE_ATTRIBUTE_HIDDEN           0x00000002  
  2034. #define FILE_ATTRIBUTE_SYSTEM           0x00000004  
  2035. #define FILE_ATTRIBUTE_DIRECTORY        0x00000010  
  2036. #define FILE_ATTRIBUTE_ARCHIVE          0x00000020  
  2037. #define FILE_ATTRIBUTE_NORMAL           0x00000080  
  2038. #define FILE_ATTRIBUTE_TEMPORARY        0x00000100  
  2039. #define FILE_ATTRIBUTE_COMPRESSED       0x00000800  
  2040. #define FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001   
  2041. #define FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002   
  2042. #define FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004   
  2043. #define FILE_NOTIFY_CHANGE_SIZE         0x00000008   
  2044. #define FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010   
  2045. #define FILE_NOTIFY_CHANGE_SECURITY     0x00000100   
  2046. #define MAILSLOT_NO_MESSAGE             ((DWORD)-1) 
  2047. #define MAILSLOT_WAIT_FOREVER           ((DWORD)-1) 
  2048. #define FILE_CASE_SENSITIVE_SEARCH      0x00000001  
  2049. #define FILE_CASE_PRESERVED_NAMES       0x00000002  
  2050. #define FILE_UNICODE_ON_DISK            0x00000004  
  2051. #define FILE_PERSISTENT_ACLS            0x00000008  
  2052. #define FILE_FILE_COMPRESSION           0x00000010  
  2053. #define FILE_VOLUME_IS_COMPRESSED       0x00008000  
  2054. #define IO_COMPLETION_MODIFY_STATE  0x0002  
  2055. #define IO_COMPLETION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  2056. #define DUPLICATE_CLOSE_SOURCE      0x00000001  
  2057. #define DUPLICATE_SAME_ACCESS       0x00000002  
  2058. typedef PVOID PACCESS_TOKEN;            
  2059. typedef PVOID PSECURITY_DESCRIPTOR;     
  2060. typedef PVOID PSID;     
  2061. ////////////////////////////////////////////////////////////////////////
  2062. //                                                                    //
  2063. //                             ACCESS MASK                            //
  2064. //                                                                    //
  2065. ////////////////////////////////////////////////////////////////////////
  2066.  
  2067. //
  2068. //  Define the access mask as a longword sized structure divided up as
  2069. //  follows:
  2070. //
  2071. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  2072. //       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
  2073. //      +---------------+---------------+-------------------------------+
  2074. //      |G|G|G|G|Res'd|A| StandardRights|         SpecificRights        |
  2075. //      |R|W|E|A|     |S|               |                               |
  2076. //      +-+-------------+---------------+-------------------------------+
  2077. //
  2078. //      typedef struct _ACCESS_MASK {
  2079. //          WORD   SpecificRights;
  2080. //          BYTE  StandardRights;
  2081. //          BYTE  AccessSystemAcl : 1;
  2082. //          BYTE  Reserved : 3;
  2083. //          BYTE  GenericAll : 1;
  2084. //          BYTE  GenericExecute : 1;
  2085. //          BYTE  GenericWrite : 1;
  2086. //          BYTE  GenericRead : 1;
  2087. //      } ACCESS_MASK;
  2088. //      typedef ACCESS_MASK *PACCESS_MASK;
  2089. //
  2090. //  but to make life simple for programmer's we'll allow them to specify
  2091. //  a desired access mask by simply OR'ing together mulitple single rights
  2092. //  and treat an access mask as a DWORD.  For example
  2093. //
  2094. //      DesiredAccess = DELETE | READ_CONTROL
  2095. //
  2096. //  So we'll declare ACCESS_MASK as DWORD
  2097. //
  2098.  
  2099. // begin_ntddk begin_nthal begin_ntifs
  2100. typedef DWORD ACCESS_MASK;
  2101. typedef ACCESS_MASK *PACCESS_MASK;
  2102.  
  2103. ////////////////////////////////////////////////////////////////////////
  2104. //                                                                    //
  2105. //                             ACCESS TYPES                           //
  2106. //                                                                    //
  2107. ////////////////////////////////////////////////////////////////////////
  2108.  
  2109.  
  2110. // begin_ntddk begin_nthal begin_ntifs
  2111. //
  2112. //  The following are masks for the predefined standard access types
  2113. //
  2114.  
  2115. #define DELETE                           (0x00010000L)
  2116. #define READ_CONTROL                     (0x00020000L)
  2117. #define WRITE_DAC                        (0x00040000L)
  2118. #define WRITE_OWNER                      (0x00080000L)
  2119. #define SYNCHRONIZE                      (0x00100000L)
  2120.  
  2121. #define STANDARD_RIGHTS_REQUIRED         (0x000F0000L)
  2122.  
  2123. #define STANDARD_RIGHTS_READ             (READ_CONTROL)
  2124. #define STANDARD_RIGHTS_WRITE            (READ_CONTROL)
  2125. #define STANDARD_RIGHTS_EXECUTE          (READ_CONTROL)
  2126.  
  2127. #define STANDARD_RIGHTS_ALL              (0x001F0000L)
  2128.  
  2129. #define SPECIFIC_RIGHTS_ALL              (0x0000FFFFL)
  2130.  
  2131. //
  2132. // AccessSystemAcl access type
  2133. //
  2134.  
  2135. #define ACCESS_SYSTEM_SECURITY           (0x01000000L)
  2136.  
  2137. //
  2138. // MaximumAllowed access type
  2139. //
  2140.  
  2141. #define MAXIMUM_ALLOWED                  (0x02000000L)
  2142.  
  2143. //
  2144. //  These are the generic rights.
  2145. //
  2146.  
  2147. #define GENERIC_READ                     (0x80000000L)
  2148. #define GENERIC_WRITE                    (0x40000000L)
  2149. #define GENERIC_EXECUTE                  (0x20000000L)
  2150. #define GENERIC_ALL                      (0x10000000L)
  2151.  
  2152.  
  2153. //
  2154. //  Define the generic mapping array.  This is used to denote the
  2155. //  mapping of each generic access right to a specific access mask.
  2156. //
  2157.  
  2158. typedef struct _GENERIC_MAPPING {
  2159.     ACCESS_MASK GenericRead;
  2160.     ACCESS_MASK GenericWrite;
  2161.     ACCESS_MASK GenericExecute;
  2162.     ACCESS_MASK GenericAll;
  2163. } GENERIC_MAPPING;
  2164. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  2165.  
  2166.  
  2167.  
  2168. ////////////////////////////////////////////////////////////////////////
  2169. //                                                                    //
  2170. //                        LUID_AND_ATTRIBUTES                         //
  2171. //                                                                    //
  2172. ////////////////////////////////////////////////////////////////////////
  2173. //
  2174. //
  2175.  
  2176.  
  2177. #include <pshpack4.h>
  2178.  
  2179. typedef struct _LUID_AND_ATTRIBUTES {
  2180.     LUID Luid;
  2181.     DWORD Attributes;
  2182.     } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  2183. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  2184. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  2185.  
  2186. #include <poppack.h>
  2187.  
  2188.  
  2189. ////////////////////////////////////////////////////////////////////////
  2190. //                                                                    //
  2191. //              Security Id     (SID)                                 //
  2192. //                                                                    //
  2193. ////////////////////////////////////////////////////////////////////////
  2194. //
  2195. //
  2196. // Pictorially the structure of an SID is as follows:
  2197. //
  2198. //         1   1   1   1   1   1
  2199. //         5   4   3   2   1   0   9   8   7   6   5   4   3   2   1   0
  2200. //      +---------------------------------------------------------------+
  2201. //      |      SubAuthorityCount        |Reserved1 (SBZ)|   Revision    |
  2202. //      +---------------------------------------------------------------+
  2203. //      |                   IdentifierAuthority[0]                      |
  2204. //      +---------------------------------------------------------------+
  2205. //      |                   IdentifierAuthority[1]                      |
  2206. //      +---------------------------------------------------------------+
  2207. //      |                   IdentifierAuthority[2]                      |
  2208. //      +---------------------------------------------------------------+
  2209. //      |                                                               |
  2210. //      +- -  -  -  -  -  -  -  SubAuthority[]  -  -  -  -  -  -  -  - -+
  2211. //      |                                                               |
  2212. //      +---------------------------------------------------------------+
  2213. //
  2214. //
  2215.  
  2216.  
  2217. // begin_ntifs
  2218.  
  2219. typedef struct _SID_IDENTIFIER_AUTHORITY {
  2220.     BYTE  Value[6];
  2221. } SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY;
  2222.  
  2223.  
  2224. typedef struct _SID {
  2225.    BYTE  Revision;
  2226.    BYTE  SubAuthorityCount;
  2227.    SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
  2228. #ifdef MIDL_PASS
  2229.    [size_is(SubAuthorityCount)] DWORD SubAuthority[*];
  2230. #else // MIDL_PASS
  2231.    DWORD SubAuthority[ANYSIZE_ARRAY];
  2232. #endif // MIDL_PASS
  2233. } SID, *PISID;
  2234.  
  2235.  
  2236. #define SID_REVISION                     (1)    // Current revision level
  2237. #define SID_MAX_SUB_AUTHORITIES          (15)
  2238. #define SID_RECOMMENDED_SUB_AUTHORITIES  (1)    // Will change to around 6
  2239.                                                 // in a future release.
  2240.  
  2241. typedef enum _SID_NAME_USE {
  2242.     SidTypeUser = 1,
  2243.     SidTypeGroup,
  2244.     SidTypeDomain,
  2245.     SidTypeAlias,
  2246.     SidTypeWellKnownGroup,
  2247.     SidTypeDeletedAccount,
  2248.     SidTypeInvalid,
  2249.     SidTypeUnknown
  2250. } SID_NAME_USE, *PSID_NAME_USE;
  2251.  
  2252. // end_ntifs
  2253.  
  2254. typedef struct _SID_AND_ATTRIBUTES {
  2255.     PSID Sid;
  2256.     DWORD Attributes;
  2257.     } SID_AND_ATTRIBUTES, * PSID_AND_ATTRIBUTES;
  2258.  
  2259. typedef SID_AND_ATTRIBUTES SID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  2260. typedef SID_AND_ATTRIBUTES_ARRAY *PSID_AND_ATTRIBUTES_ARRAY;
  2261.  
  2262.  
  2263.  
  2264. /////////////////////////////////////////////////////////////////////////////
  2265. //                                                                         //
  2266. // Universal well-known SIDs                                               //
  2267. //                                                                         //
  2268. //     Null SID              S-1-0-0                                       //
  2269. //     World                 S-1-1-0                                       //
  2270. //     Local                 S-1-2-0                                       //
  2271. //     Creator Owner ID      S-1-3-0                                       //
  2272. //     Creator Group ID      S-1-3-1                                       //
  2273. //                                                                         //
  2274. //     (Non-unique IDs)      S-1-4                                         //
  2275. //                                                                         //
  2276. /////////////////////////////////////////////////////////////////////////////
  2277.  
  2278. #define SECURITY_NULL_SID_AUTHORITY     {0,0,0,0,0,0}
  2279. #define SECURITY_WORLD_SID_AUTHORITY    {0,0,0,0,0,1}
  2280. #define SECURITY_LOCAL_SID_AUTHORITY    {0,0,0,0,0,2}
  2281. #define SECURITY_CREATOR_SID_AUTHORITY  {0,0,0,0,0,3}
  2282. #define SECURITY_NON_UNIQUE_AUTHORITY   {0,0,0,0,0,4}
  2283.  
  2284. #define SECURITY_NULL_RID               (0x00000000L)
  2285. #define SECURITY_WORLD_RID              (0x00000000L)
  2286. #define SECURITY_LOCAL_RID              (0X00000000L)
  2287.  
  2288. #define SECURITY_CREATOR_OWNER_RID      (0x00000000L)
  2289. #define SECURITY_CREATOR_GROUP_RID      (0x00000001L)
  2290.  
  2291.  
  2292.  
  2293.  
  2294. /////////////////////////////////////////////////////////////////////////////
  2295. //                                                                         //
  2296. // NT well-known SIDs                                                      //
  2297. //                                                                         //
  2298. //     NT Authority          S-1-5                                         //
  2299. //     Dialup                S-1-5-1                                       //
  2300. //                                                                         //
  2301. //     Network               S-1-5-2                                       //
  2302. //     Batch                 S-1-5-3                                       //
  2303. //     Interactive           S-1-5-4                                       //
  2304. //     Service               S-1-5-6                                       //
  2305. //     AnonymousLogon        S-1-5-7       (aka null logon session)        //
  2306. //                                                                         //
  2307. //     (Logon IDs)           S-1-5-5-X-Y                                   //
  2308. //                                                                         //
  2309. //     (NT non-unique IDs)   S-1-5-0x15-...                                //
  2310. //                                                                         //
  2311. //     (Built-in domain)     s-1-5-0x20                                    //
  2312. //                                                                         //
  2313. /////////////////////////////////////////////////////////////////////////////
  2314.  
  2315.  
  2316. #define SECURITY_NT_AUTHORITY           {0,0,0,0,0,5}   // ntifs
  2317.  
  2318. #define SECURITY_DIALUP_RID             (0x00000001L)
  2319. #define SECURITY_NETWORK_RID            (0x00000002L)
  2320. #define SECURITY_BATCH_RID              (0x00000003L)
  2321. #define SECURITY_INTERACTIVE_RID        (0x00000004L)
  2322. #define SECURITY_SERVICE_RID            (0x00000006L)
  2323. #define SECURITY_ANONYMOUS_LOGON_RID    (0x00000007L)
  2324.  
  2325. #define SECURITY_LOGON_IDS_RID          (0x00000005L)
  2326. #define SECURITY_LOGON_IDS_RID_COUNT    (3L)
  2327.  
  2328. #define SECURITY_LOCAL_SYSTEM_RID       (0x00000012L)
  2329.  
  2330. #define SECURITY_NT_NON_UNIQUE          (0x00000015L)
  2331.  
  2332. #define SECURITY_BUILTIN_DOMAIN_RID     (0x00000020L)
  2333.  
  2334.  
  2335.  
  2336.  
  2337.  
  2338. /////////////////////////////////////////////////////////////////////////////
  2339. //                                                                         //
  2340. // well-known domain relative sub-authority values (RIDs)...               //
  2341. //                                                                         //
  2342. /////////////////////////////////////////////////////////////////////////////
  2343.  
  2344. // Well-known users ...
  2345.  
  2346. #define DOMAIN_USER_RID_ADMIN          (0x000001F4L)
  2347. #define DOMAIN_USER_RID_GUEST          (0x000001F5L)
  2348.  
  2349.  
  2350.  
  2351. // well-known groups ...
  2352.  
  2353. #define DOMAIN_GROUP_RID_ADMINS        (0x00000200L)
  2354. #define DOMAIN_GROUP_RID_USERS         (0x00000201L)
  2355. #define DOMAIN_GROUP_RID_GUESTS        (0x00000202L)
  2356.  
  2357.  
  2358.  
  2359.  
  2360. // well-known aliases ...
  2361.  
  2362. #define DOMAIN_ALIAS_RID_ADMINS        (0x00000220L)
  2363. #define DOMAIN_ALIAS_RID_USERS         (0x00000221L)
  2364. #define DOMAIN_ALIAS_RID_GUESTS        (0x00000222L)
  2365. #define DOMAIN_ALIAS_RID_POWER_USERS   (0x00000223L)
  2366.  
  2367. #define DOMAIN_ALIAS_RID_ACCOUNT_OPS   (0x00000224L)
  2368. #define DOMAIN_ALIAS_RID_SYSTEM_OPS    (0x00000225L)
  2369. #define DOMAIN_ALIAS_RID_PRINT_OPS     (0x00000226L)
  2370. #define DOMAIN_ALIAS_RID_BACKUP_OPS    (0x00000227L)
  2371.  
  2372. #define DOMAIN_ALIAS_RID_REPLICATOR    (0x00000228L)
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379. //
  2380. // Allocate the System Luid.  The first 1000 LUIDs are reserved.
  2381. // Use #999 here (0x3E7 = 999)
  2382. //
  2383.  
  2384. #define SYSTEM_LUID                     { 0x3E7, 0x0 }
  2385.  
  2386. // end_ntifs
  2387.  
  2388. ////////////////////////////////////////////////////////////////////////
  2389. //                                                                    //
  2390. //                          User and Group related SID attributes     //
  2391. //                                                                    //
  2392. ////////////////////////////////////////////////////////////////////////
  2393.  
  2394. //
  2395. // Group attributes
  2396. //
  2397.  
  2398. #define SE_GROUP_MANDATORY              (0x00000001L)
  2399. #define SE_GROUP_ENABLED_BY_DEFAULT     (0x00000002L)
  2400. #define SE_GROUP_ENABLED                (0x00000004L)
  2401. #define SE_GROUP_OWNER                  (0x00000008L)
  2402. #define SE_GROUP_LOGON_ID               (0xC0000000L)
  2403.  
  2404.  
  2405.  
  2406. //
  2407. // User attributes
  2408. //
  2409.  
  2410. // (None yet defined.)
  2411.  
  2412.  
  2413.  
  2414.  
  2415. ////////////////////////////////////////////////////////////////////////
  2416. //                                                                    //
  2417. //                         ACL  and  ACE                              //
  2418. //                                                                    //
  2419. ////////////////////////////////////////////////////////////////////////
  2420.  
  2421. //
  2422. //  Define an ACL and the ACE format.  The structure of an ACL header
  2423. //  followed by one or more ACEs.  Pictorally the structure of an ACL header
  2424. //  is as follows:
  2425. //
  2426. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  2427. //       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
  2428. //      +-------------------------------+---------------+---------------+
  2429. //      |            AclSize            |      Sbz1     |  AclRevision  |
  2430. //      +-------------------------------+---------------+---------------+
  2431. //      |              Sbz2             |           AceCount            |
  2432. //      +-------------------------------+-------------------------------+
  2433. //
  2434. //  The current AclRevision is defined to be ACL_REVISION.
  2435. //
  2436. //  AclSize is the size, in bytes, allocated for the ACL.  This includes
  2437. //  the ACL header, ACES, and remaining free space in the buffer.
  2438. //
  2439. //  AceCount is the number of ACES in the ACL.
  2440. //
  2441.  
  2442. // begin_ntddk begin_ntifs
  2443. // This is the *current* ACL revision
  2444.  
  2445. #define ACL_REVISION     (2)
  2446.  
  2447. // This is the history of ACL revisions.  Add a new one whenever
  2448. // ACL_REVISION is updated
  2449.  
  2450. #define ACL_REVISION1   (1)
  2451. #define ACL_REVISION2   (2)
  2452.  
  2453. typedef struct _ACL {
  2454.     BYTE  AclRevision;
  2455.     BYTE  Sbz1;
  2456.     WORD   AclSize;
  2457.     WORD   AceCount;
  2458.     WORD   Sbz2;
  2459. } ACL;
  2460. typedef ACL *PACL;
  2461.  
  2462. // end_ntddk
  2463.  
  2464. //
  2465. //  The structure of an ACE is a common ace header followed by ace type
  2466. //  specific data.  Pictorally the structure of the common ace header is
  2467. //  as follows:
  2468. //
  2469. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  2470. //       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
  2471. //      +---------------+-------+-------+---------------+---------------+
  2472. //      |            AceSize            |    AceFlags   |     AceType   |
  2473. //      +---------------+-------+-------+---------------+---------------+
  2474. //
  2475. //  AceType denotes the type of the ace, there are some predefined ace
  2476. //  types
  2477. //
  2478. //  AceSize is the size, in bytes, of ace.
  2479. //
  2480. //  AceFlags are the Ace flags for audit and inheritance, defined shortly.
  2481.  
  2482. typedef struct _ACE_HEADER {
  2483.     BYTE  AceType;
  2484.     BYTE  AceFlags;
  2485.     WORD   AceSize;
  2486. } ACE_HEADER;
  2487. typedef ACE_HEADER *PACE_HEADER;
  2488.  
  2489. //
  2490. //  The following are the predefined ace types that go into the AceType
  2491. //  field of an Ace header.
  2492. //
  2493.  
  2494. #define ACCESS_ALLOWED_ACE_TYPE          (0x0)
  2495. #define ACCESS_DENIED_ACE_TYPE           (0x1)
  2496. #define SYSTEM_AUDIT_ACE_TYPE            (0x2)
  2497. #define SYSTEM_ALARM_ACE_TYPE            (0x3)
  2498.  
  2499. //
  2500. //  The following are the inherit flags that go into the AceFlags field
  2501. //  of an Ace header.
  2502. //
  2503.  
  2504. #define OBJECT_INHERIT_ACE                (0x1)
  2505. #define CONTAINER_INHERIT_ACE             (0x2)
  2506. #define NO_PROPAGATE_INHERIT_ACE          (0x4)
  2507. #define INHERIT_ONLY_ACE                  (0x8)
  2508. #define VALID_INHERIT_FLAGS               (0xF)
  2509.  
  2510.  
  2511. //  The following are the currently defined ACE flags that go into the
  2512. //  AceFlags field of an ACE header.  Each ACE type has its own set of
  2513. //  AceFlags.
  2514. //
  2515. //  SUCCESSFUL_ACCESS_ACE_FLAG - used only with system audit and alarm ACE
  2516. //  types to indicate that a message is generated for successful accesses.
  2517. //
  2518. //  FAILED_ACCESS_ACE_FLAG - used only with system audit and alarm ACE types
  2519. //  to indicate that a message is generated for failed accesses.
  2520. //
  2521.  
  2522. //
  2523. //  SYSTEM_AUDIT and SYSTEM_ALARM AceFlags
  2524. //
  2525. //  These control the signaling of audit and alarms for success or failure.
  2526. //
  2527.  
  2528. #define SUCCESSFUL_ACCESS_ACE_FLAG       (0x40)
  2529. #define FAILED_ACCESS_ACE_FLAG           (0x80)
  2530.  
  2531.  
  2532. //
  2533. //  We'll define the structure of the predefined ACE types.  Pictorally
  2534. //  the structure of the predefined ACE's is as follows:
  2535. //
  2536. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  2537. //       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
  2538. //      +---------------+-------+-------+---------------+---------------+
  2539. //      |    AceFlags   | Resd  |Inherit|    AceSize    |     AceType   |
  2540. //      +---------------+-------+-------+---------------+---------------+
  2541. //      |                              Mask                             |
  2542. //      +---------------------------------------------------------------+
  2543. //      |                                                               |
  2544. //      +                                                               +
  2545. //      |                                                               |
  2546. //      +                              Sid                              +
  2547. //      |                                                               |
  2548. //      +                                                               +
  2549. //      |                                                               |
  2550. //      +---------------------------------------------------------------+
  2551. //
  2552. //  Mask is the access mask associated with the ACE.  This is either the
  2553. //  access allowed, access denied, audit, or alarm mask.
  2554. //
  2555. //  Sid is the Sid associated with the ACE.
  2556. //
  2557.  
  2558. //  The following are the four predefined ACE types.
  2559.  
  2560. //  Examine the AceType field in the Header to determine
  2561. //  which structure is appropriate to use for casting.
  2562.  
  2563.  
  2564. typedef struct _ACCESS_ALLOWED_ACE {
  2565.     ACE_HEADER Header;
  2566.     ACCESS_MASK Mask;
  2567.     DWORD SidStart;
  2568. } ACCESS_ALLOWED_ACE;
  2569.  
  2570. typedef ACCESS_ALLOWED_ACE *PACCESS_ALLOWED_ACE;
  2571.  
  2572. typedef struct _ACCESS_DENIED_ACE {
  2573.     ACE_HEADER Header;
  2574.     ACCESS_MASK Mask;
  2575.     DWORD SidStart;
  2576. } ACCESS_DENIED_ACE;
  2577. typedef ACCESS_DENIED_ACE *PACCESS_DENIED_ACE;
  2578.  
  2579. typedef struct _SYSTEM_AUDIT_ACE {
  2580.     ACE_HEADER Header;
  2581.     ACCESS_MASK Mask;
  2582.     DWORD SidStart;
  2583. } SYSTEM_AUDIT_ACE;
  2584. typedef SYSTEM_AUDIT_ACE *PSYSTEM_AUDIT_ACE;
  2585.  
  2586. typedef struct _SYSTEM_ALARM_ACE {
  2587.     ACE_HEADER Header;
  2588.     ACCESS_MASK Mask;
  2589.     DWORD SidStart;
  2590. } SYSTEM_ALARM_ACE;
  2591. typedef SYSTEM_ALARM_ACE *PSYSTEM_ALARM_ACE;
  2592.  
  2593. // end_ntifs
  2594.  
  2595.  
  2596. //
  2597. //  The following declarations are used for setting and querying information
  2598. //  about and ACL.  First are the various information classes available to
  2599. //  the user.
  2600. //
  2601.  
  2602. typedef enum _ACL_INFORMATION_CLASS {
  2603.     AclRevisionInformation = 1,
  2604.     AclSizeInformation
  2605. } ACL_INFORMATION_CLASS;
  2606.  
  2607. //
  2608. //  This record is returned/sent if the user is requesting/setting the
  2609. //  AclRevisionInformation
  2610. //
  2611.  
  2612. typedef struct _ACL_REVISION_INFORMATION {
  2613.     DWORD AclRevision;
  2614. } ACL_REVISION_INFORMATION;
  2615. typedef ACL_REVISION_INFORMATION *PACL_REVISION_INFORMATION;
  2616.  
  2617. //
  2618. //  This record is returned if the user is requesting AclSizeInformation
  2619. //
  2620.  
  2621. typedef struct _ACL_SIZE_INFORMATION {
  2622.     DWORD AceCount;
  2623.     DWORD AclBytesInUse;
  2624.     DWORD AclBytesFree;
  2625. } ACL_SIZE_INFORMATION;
  2626. typedef ACL_SIZE_INFORMATION *PACL_SIZE_INFORMATION;
  2627.  
  2628.  
  2629. ////////////////////////////////////////////////////////////////////////
  2630. //                                                                    //
  2631. //                             SECURITY_DESCRIPTOR                    //
  2632. //                                                                    //
  2633. ////////////////////////////////////////////////////////////////////////
  2634. //
  2635. //  Define the Security Descriptor and related data types.
  2636. //  This is an opaque data structure.
  2637. //
  2638.  
  2639. // begin_ntddk begin_ntifs
  2640. //
  2641. // Current security descriptor revision value
  2642. //
  2643.  
  2644. #define SECURITY_DESCRIPTOR_REVISION     (1)
  2645. #define SECURITY_DESCRIPTOR_REVISION1    (1)
  2646.  
  2647. // end_ntddk
  2648.  
  2649. //
  2650. // Minimum length, in bytes, needed to build a security descriptor
  2651. // (NOTE: This must manually be kept consistent with the)
  2652. // (sizeof(SECURITY_DESCRIPTOR)                         )
  2653. //
  2654.  
  2655. #define SECURITY_DESCRIPTOR_MIN_LENGTH   (20)
  2656.  
  2657.  
  2658. typedef WORD   SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
  2659.  
  2660. #define SE_OWNER_DEFAULTED               (0x0001)
  2661. #define SE_GROUP_DEFAULTED               (0x0002)
  2662. #define SE_DACL_PRESENT                  (0x0004)
  2663. #define SE_DACL_DEFAULTED                (0x0008)
  2664. #define SE_SACL_PRESENT                  (0x0010)
  2665. #define SE_SACL_DEFAULTED                (0x0020)
  2666. #define SE_SELF_RELATIVE                 (0x8000)
  2667.  
  2668. //
  2669. //  Where:
  2670. //
  2671. //      SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the
  2672. //          SID pointed to by the Owner field was provided by a
  2673. //          defaulting mechanism rather than explicitly provided by the
  2674. //          original provider of the security descriptor.  This may
  2675. //          affect the treatment of the SID with respect to inheritence
  2676. //          of an owner.
  2677. //
  2678. //      SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the
  2679. //          SID in the Group field was provided by a defaulting mechanism
  2680. //          rather than explicitly provided by the original provider of
  2681. //          the security descriptor.  This may affect the treatment of
  2682. //          the SID with respect to inheritence of a primary group.
  2683. //
  2684. //      SE_DACL_PRESENT - This boolean flag, when set, indicates that the
  2685. //          security descriptor contains a discretionary ACL.  If this
  2686. //          flag is set and the Dacl field of the SECURITY_DESCRIPTOR is
  2687. //          null, then a null ACL is explicitly being specified.
  2688. //
  2689. //      SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the
  2690. //          ACL pointed to by the Dacl field was provided by a defaulting
  2691. //          mechanism rather than explicitly provided by the original
  2692. //          provider of the security descriptor.  This may affect the
  2693. //          treatment of the ACL with respect to inheritence of an ACL.
  2694. //          This flag is ignored if the DaclPresent flag is not set.
  2695. //
  2696. //      SE_SACL_PRESENT - This boolean flag, when set,  indicates that the
  2697. //          security descriptor contains a system ACL pointed to by the
  2698. //          Sacl field.  If this flag is set and the Sacl field of the
  2699. //          SECURITY_DESCRIPTOR is null, then an empty (but present)
  2700. //          ACL is being specified.
  2701. //
  2702. //      SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the
  2703. //          ACL pointed to by the Sacl field was provided by a defaulting
  2704. //          mechanism rather than explicitly provided by the original
  2705. //          provider of the security descriptor.  This may affect the
  2706. //          treatment of the ACL with respect to inheritence of an ACL.
  2707. //          This flag is ignored if the SaclPresent flag is not set.
  2708. //
  2709. //      SE_SELF_RELATIVE - This boolean flag, when set, indicates that the
  2710. //          security descriptor is in self-relative form.  In this form,
  2711. //          all fields of the security descriptor are contiguous in memory
  2712. //          and all pointer fields are expressed as offsets from the
  2713. //          beginning of the security descriptor.  This form is useful
  2714. //          for treating security descriptors as opaque data structures
  2715. //          for transmission in communication protocol or for storage on
  2716. //          secondary media.
  2717. //
  2718. //
  2719. //
  2720. // Pictorially the structure of a security descriptor is as follows:
  2721. //
  2722. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  2723. //       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
  2724. //      +---------------------------------------------------------------+
  2725. //      |            Control            |Reserved1 (SBZ)|   Revision    |
  2726. //      +---------------------------------------------------------------+
  2727. //      |                            Owner                              |
  2728. //      +---------------------------------------------------------------+
  2729. //      |                            Group                              |
  2730. //      +---------------------------------------------------------------+
  2731. //      |                            Sacl                               |
  2732. //      +---------------------------------------------------------------+
  2733. //      |                            Dacl                               |
  2734. //      +---------------------------------------------------------------+
  2735. //
  2736. // In general, this data structure should be treated opaquely to ensure future
  2737. // compatibility.
  2738. //
  2739. //
  2740.  
  2741. typedef struct _SECURITY_DESCRIPTOR {
  2742.    BYTE  Revision;
  2743.    BYTE  Sbz1;
  2744.    SECURITY_DESCRIPTOR_CONTROL Control;
  2745.    PSID Owner;
  2746.    PSID Group;
  2747.    PACL Sacl;
  2748.    PACL Dacl;
  2749.    } SECURITY_DESCRIPTOR, *PISECURITY_DESCRIPTOR;
  2750.  
  2751. // end_ntifs
  2752.  
  2753. // Where:
  2754. //
  2755. //     Revision - Contains the revision level of the security
  2756. //         descriptor.  This allows this structure to be passed between
  2757. //         systems or stored on disk even though it is expected to
  2758. //         change in the future.
  2759. //
  2760. //     Control - A set of flags which qualify the meaning of the
  2761. //         security descriptor or individual fields of the security
  2762. //         descriptor.
  2763. //
  2764. //     Owner - is a pointer to an SID representing an object's owner.
  2765. //         If this field is null, then no owner SID is present in the
  2766. //         security descriptor.  If the security descriptor is in
  2767. //         self-relative form, then this field contains an offset to
  2768. //         the SID, rather than a pointer.
  2769. //
  2770. //     Group - is a pointer to an SID representing an object's primary
  2771. //         group.  If this field is null, then no primary group SID is
  2772. //         present in the security descriptor.  If the security descriptor
  2773. //         is in self-relative form, then this field contains an offset to
  2774. //         the SID, rather than a pointer.
  2775. //
  2776. //     Sacl - is a pointer to a system ACL.  This field value is only
  2777. //         valid if the DaclPresent control flag is set.  If the
  2778. //         SaclPresent flag is set and this field is null, then a null
  2779. //         ACL  is specified.  If the security descriptor is in
  2780. //         self-relative form, then this field contains an offset to
  2781. //         the ACL, rather than a pointer.
  2782. //
  2783. //     Dacl - is a pointer to a discretionary ACL.  This field value is
  2784. //         only valid if the DaclPresent control flag is set.  If the
  2785. //         DaclPresent flag is set and this field is null, then a null
  2786. //         ACL (unconditionally granting access) is specified.  If the
  2787. //         security descriptor is in self-relative form, then this field
  2788. //         contains an offset to the ACL, rather than a pointer.
  2789. //
  2790.  
  2791.  
  2792.  
  2793. ////////////////////////////////////////////////////////////////////////
  2794. //                                                                    //
  2795. //               Privilege Related Data Structures                    //
  2796. //                                                                    //
  2797. ////////////////////////////////////////////////////////////////////////
  2798.  
  2799.  
  2800. // begin_ntddk begin_nthal begin_ntifs
  2801. //
  2802. // Privilege attributes
  2803. //
  2804.  
  2805. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  2806. #define SE_PRIVILEGE_ENABLED            (0x00000002L)
  2807. #define SE_PRIVILEGE_USED_FOR_ACCESS    (0x80000000L)
  2808.  
  2809. //
  2810. // Privilege Set Control flags
  2811. //
  2812.  
  2813. #define PRIVILEGE_SET_ALL_NECESSARY    (1)
  2814.  
  2815. //
  2816. //  Privilege Set - This is defined for a privilege set of one.
  2817. //                  If more than one privilege is needed, then this structure
  2818. //                  will need to be allocated with more space.
  2819. //
  2820. //  Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  2821. //  structure (defined in se.h)
  2822. //
  2823.  
  2824. typedef struct _PRIVILEGE_SET {
  2825.     DWORD PrivilegeCount;
  2826.     DWORD Control;
  2827.     LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  2828.     } PRIVILEGE_SET, * PPRIVILEGE_SET;
  2829.  
  2830.  
  2831. ////////////////////////////////////////////////////////////////////////
  2832. //                                                                    //
  2833. //               NT Defined Privileges                                //
  2834. //                                                                    //
  2835. ////////////////////////////////////////////////////////////////////////
  2836.  
  2837. #define SE_CREATE_TOKEN_NAME              TEXT("SeCreateTokenPrivilege")
  2838. #define SE_ASSIGNPRIMARYTOKEN_NAME        TEXT("SeAssignPrimaryTokenPrivilege")
  2839. #define SE_LOCK_MEMORY_NAME               TEXT("SeLockMemoryPrivilege")
  2840. #define SE_INCREASE_QUOTA_NAME            TEXT("SeIncreaseQuotaPrivilege")
  2841. #define SE_UNSOLICITED_INPUT_NAME         TEXT("SeUnsolicitedInputPrivilege")
  2842. #define SE_MACHINE_ACCOUNT_NAME           TEXT("SeMachineAccountPrivilege")
  2843. #define SE_TCB_NAME                       TEXT("SeTcbPrivilege")
  2844. #define SE_SECURITY_NAME                  TEXT("SeSecurityPrivilege")
  2845. #define SE_TAKE_OWNERSHIP_NAME            TEXT("SeTakeOwnershipPrivilege")
  2846. #define SE_LOAD_DRIVER_NAME               TEXT("SeLoadDriverPrivilege")
  2847. #define SE_SYSTEM_PROFILE_NAME            TEXT("SeSystemProfilePrivilege")
  2848. #define SE_SYSTEMTIME_NAME                TEXT("SeSystemtimePrivilege")
  2849. #define SE_PROF_SINGLE_PROCESS_NAME       TEXT("SeProfileSingleProcessPrivilege")
  2850. #define SE_INC_BASE_PRIORITY_NAME         TEXT("SeIncreaseBasePriorityPrivilege")
  2851. #define SE_CREATE_PAGEFILE_NAME           TEXT("SeCreatePagefilePrivilege")
  2852. #define SE_CREATE_PERMANENT_NAME          TEXT("SeCreatePermanentPrivilege")
  2853. #define SE_BACKUP_NAME                    TEXT("SeBackupPrivilege")
  2854. #define SE_RESTORE_NAME                   TEXT("SeRestorePrivilege")
  2855. #define SE_SHUTDOWN_NAME                  TEXT("SeShutdownPrivilege")
  2856. #define SE_DEBUG_NAME                     TEXT("SeDebugPrivilege")
  2857. #define SE_AUDIT_NAME                     TEXT("SeAuditPrivilege")
  2858. #define SE_SYSTEM_ENVIRONMENT_NAME        TEXT("SeSystemEnvironmentPrivilege")
  2859. #define SE_CHANGE_NOTIFY_NAME             TEXT("SeChangeNotifyPrivilege")
  2860. #define SE_REMOTE_SHUTDOWN_NAME           TEXT("SeRemoteShutdownPrivilege")
  2861.  
  2862.  
  2863. ////////////////////////////////////////////////////////////////////
  2864. //                                                                //
  2865. //           Security Quality Of Service                          //
  2866. //                                                                //
  2867. //                                                                //
  2868. ////////////////////////////////////////////////////////////////////
  2869.  
  2870. // begin_ntddk begin_nthal begin_ntifs
  2871. //
  2872. // Impersonation Level
  2873. //
  2874. // Impersonation level is represented by a pair of bits in Windows.
  2875. // If a new impersonation level is added or lowest value is changed from
  2876. // 0 to something else, fix the Windows CreateFile call.
  2877. //
  2878.  
  2879. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  2880.     SecurityAnonymous,
  2881.     SecurityIdentification,
  2882.     SecurityImpersonation,
  2883.     SecurityDelegation
  2884.     } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  2885.  
  2886. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  2887.  
  2888. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  2889.  
  2890. // end_nthal
  2891. //
  2892. // Security Tracking Mode
  2893. //
  2894.  
  2895. #define SECURITY_DYNAMIC_TRACKING      (TRUE)
  2896. #define SECURITY_STATIC_TRACKING       (FALSE)
  2897.  
  2898. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  2899.                     * PSECURITY_CONTEXT_TRACKING_MODE;
  2900.  
  2901.  
  2902.  
  2903. //
  2904. // Quality Of Service
  2905. //
  2906.  
  2907. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  2908.     DWORD Length;
  2909.     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  2910.     SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  2911.     BOOLEAN EffectiveOnly;
  2912.     } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  2913.  
  2914.  
  2915. //
  2916. // Used to represent information related to a thread impersonation
  2917. //
  2918.  
  2919. typedef struct _SE_IMPERSONATION_STATE {
  2920.     PACCESS_TOKEN Token;
  2921.     BOOLEAN CopyOnOpen;
  2922.     BOOLEAN EffectiveOnly;
  2923.     SECURITY_IMPERSONATION_LEVEL Level;
  2924. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  2925.  
  2926.  
  2927. ////////////////////////////////////////////////////////////////////
  2928. //                                                                //
  2929. //           Token Object Definitions                             //
  2930. //                                                                //
  2931. //                                                                //
  2932. ////////////////////////////////////////////////////////////////////
  2933.  
  2934.  
  2935. //
  2936. // Token Specific Access Rights.
  2937. //
  2938.  
  2939. #define TOKEN_ASSIGN_PRIMARY    (0x0001)
  2940. #define TOKEN_DUPLICATE         (0x0002)
  2941. #define TOKEN_IMPERSONATE       (0x0004)
  2942. #define TOKEN_QUERY             (0x0008)
  2943. #define TOKEN_QUERY_SOURCE      (0x0010)
  2944. #define TOKEN_ADJUST_PRIVILEGES (0x0020)
  2945. #define TOKEN_ADJUST_GROUPS     (0x0040)
  2946. #define TOKEN_ADJUST_DEFAULT    (0x0080)
  2947.  
  2948. #define TOKEN_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED  |\
  2949.                           TOKEN_ASSIGN_PRIMARY      |\
  2950.                           TOKEN_DUPLICATE           |\
  2951.                           TOKEN_IMPERSONATE         |\
  2952.                           TOKEN_QUERY               |\
  2953.                           TOKEN_QUERY_SOURCE        |\
  2954.                           TOKEN_ADJUST_PRIVILEGES   |\
  2955.                           TOKEN_ADJUST_GROUPS       |\
  2956.                           TOKEN_ADJUST_DEFAULT)
  2957.  
  2958.  
  2959. #define TOKEN_READ       (STANDARD_RIGHTS_READ      |\
  2960.                           TOKEN_QUERY)
  2961.  
  2962.  
  2963. #define TOKEN_WRITE      (STANDARD_RIGHTS_WRITE     |\
  2964.                           TOKEN_ADJUST_PRIVILEGES   |\
  2965.                           TOKEN_ADJUST_GROUPS       |\
  2966.                           TOKEN_ADJUST_DEFAULT)
  2967.  
  2968. #define TOKEN_EXECUTE    (STANDARD_RIGHTS_EXECUTE)
  2969.  
  2970.  
  2971. // begin_ntifs
  2972. //
  2973. // Token Types
  2974. //
  2975.  
  2976. typedef enum _TOKEN_TYPE {
  2977.     TokenPrimary = 1,
  2978.     TokenImpersonation
  2979.     } TOKEN_TYPE;
  2980. typedef TOKEN_TYPE *PTOKEN_TYPE;
  2981.  
  2982. // end_ntifs
  2983.  
  2984. //
  2985. // Token Information Classes.
  2986. //
  2987.  
  2988.  
  2989. typedef enum _TOKEN_INFORMATION_CLASS {
  2990.     TokenUser = 1,
  2991.     TokenGroups,
  2992.     TokenPrivileges,
  2993.     TokenOwner,
  2994.     TokenPrimaryGroup,
  2995.     TokenDefaultDacl,
  2996.     TokenSource,
  2997.     TokenType,
  2998.     TokenImpersonationLevel,
  2999.     TokenStatistics
  3000. } TOKEN_INFORMATION_CLASS, *PTOKEN_INFORMATION_CLASS;
  3001.  
  3002. //
  3003. // Token information class structures
  3004. //
  3005.  
  3006.  
  3007. typedef struct _TOKEN_USER {
  3008.     SID_AND_ATTRIBUTES User;
  3009. } TOKEN_USER, *PTOKEN_USER;
  3010.  
  3011.  
  3012. typedef struct _TOKEN_GROUPS {
  3013.     DWORD GroupCount;
  3014.     SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
  3015. } TOKEN_GROUPS, *PTOKEN_GROUPS;
  3016.  
  3017.  
  3018. typedef struct _TOKEN_PRIVILEGES {
  3019.     DWORD PrivilegeCount;
  3020.     LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
  3021. } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
  3022.  
  3023.  
  3024. typedef struct _TOKEN_OWNER {
  3025.     PSID Owner;
  3026. } TOKEN_OWNER, *PTOKEN_OWNER;
  3027.  
  3028.  
  3029. typedef struct _TOKEN_PRIMARY_GROUP {
  3030.     PSID PrimaryGroup;
  3031. } TOKEN_PRIMARY_GROUP, *PTOKEN_PRIMARY_GROUP;
  3032.  
  3033.  
  3034. typedef struct _TOKEN_DEFAULT_DACL {
  3035.     PACL DefaultDacl;
  3036. } TOKEN_DEFAULT_DACL, *PTOKEN_DEFAULT_DACL;
  3037.  
  3038.  
  3039. // begin_ntifs
  3040.  
  3041. #define TOKEN_SOURCE_LENGTH 8
  3042.  
  3043. typedef struct _TOKEN_SOURCE {
  3044.     CHAR SourceName[TOKEN_SOURCE_LENGTH];
  3045.     LUID SourceIdentifier;
  3046. } TOKEN_SOURCE, *PTOKEN_SOURCE;
  3047.  
  3048. // end_ntifs
  3049.  
  3050. typedef struct _TOKEN_STATISTICS {
  3051.     LUID TokenId;
  3052.     LUID AuthenticationId;
  3053.     LARGE_INTEGER ExpirationTime;
  3054.     TOKEN_TYPE TokenType;
  3055.     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  3056.     DWORD DynamicCharged;
  3057.     DWORD DynamicAvailable;
  3058.     DWORD GroupCount;
  3059.     DWORD PrivilegeCount;
  3060.     LUID ModifiedId;
  3061. } TOKEN_STATISTICS, *PTOKEN_STATISTICS;
  3062.  
  3063.  
  3064. // begin_ntifs
  3065.  
  3066. typedef struct _TOKEN_CONTROL {
  3067.     LUID TokenId;
  3068.     LUID AuthenticationId;
  3069.     LUID ModifiedId;
  3070.     TOKEN_SOURCE TokenSource;
  3071.     } TOKEN_CONTROL, *PTOKEN_CONTROL;
  3072.  
  3073.  
  3074. typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  3075.  
  3076. #define OWNER_SECURITY_INFORMATION       (0X00000001L)
  3077. #define GROUP_SECURITY_INFORMATION       (0X00000002L)
  3078. #define DACL_SECURITY_INFORMATION        (0X00000004L)
  3079. #define SACL_SECURITY_INFORMATION        (0X00000008L)
  3080.  
  3081.  
  3082. //
  3083. // Image Format
  3084. //
  3085.  
  3086. #include "pshpack1.h"
  3087.  
  3088. #define IMAGE_DOS_SIGNATURE                 0x5A4D      // MZ
  3089. #define IMAGE_OS2_SIGNATURE                 0x454E      // NE
  3090. #define IMAGE_OS2_SIGNATURE_LE              0x454C      // LE
  3091. #define IMAGE_VXD_SIGNATURE                 0x454C      // LE
  3092. #define IMAGE_NT_SIGNATURE                  0x00004550  // PE00
  3093.  
  3094. typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
  3095.     WORD   e_magic;                     // Magic number
  3096.     WORD   e_cblp;                      // Bytes on last page of file
  3097.     WORD   e_cp;                        // Pages in file
  3098.     WORD   e_crlc;                      // Relocations
  3099.     WORD   e_cparhdr;                   // Size of header in paragraphs
  3100.     WORD   e_minalloc;                  // Minimum extra paragraphs needed
  3101.     WORD   e_maxalloc;                  // Maximum extra paragraphs needed
  3102.     WORD   e_ss;                        // Initial (relative) SS value
  3103.     WORD   e_sp;                        // Initial SP value
  3104.     WORD   e_csum;                      // Checksum
  3105.     WORD   e_ip;                        // Initial IP value
  3106.     WORD   e_cs;                        // Initial (relative) CS value
  3107.     WORD   e_lfarlc;                    // File address of relocation table
  3108.     WORD   e_ovno;                      // Overlay number
  3109.     WORD   e_res[4];                    // Reserved words
  3110.     WORD   e_oemid;                     // OEM identifier (for e_oeminfo)
  3111.     WORD   e_oeminfo;                   // OEM information; e_oemid specific
  3112.     WORD   e_res2[10];                  // Reserved words
  3113.     LONG   e_lfanew;                    // File address of new exe header
  3114.   } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
  3115.  
  3116. typedef struct _IMAGE_OS2_HEADER {      // OS/2 .EXE header
  3117.     WORD   ne_magic;                    // Magic number
  3118.     CHAR   ne_ver;                      // Version number
  3119.     CHAR   ne_rev;                      // Revision number
  3120.     WORD   ne_enttab;                   // Offset of Entry Table
  3121.     WORD   ne_cbenttab;                 // Number of bytes in Entry Table
  3122.     LONG   ne_crc;                      // Checksum of whole file
  3123.     WORD   ne_flags;                    // Flag word
  3124.     WORD   ne_autodata;                 // Automatic data segment number
  3125.     WORD   ne_heap;                     // Initial heap allocation
  3126.     WORD   ne_stack;                    // Initial stack allocation
  3127.     LONG   ne_csip;                     // Initial CS:IP setting
  3128.     LONG   ne_sssp;                     // Initial SS:SP setting
  3129.     WORD   ne_cseg;                     // Count of file segments
  3130.     WORD   ne_cmod;                     // Entries in Module Reference Table
  3131.     WORD   ne_cbnrestab;                // Size of non-resident name table
  3132.     WORD   ne_segtab;                   // Offset of Segment Table
  3133.     WORD   ne_rsrctab;                  // Offset of Resource Table
  3134.     WORD   ne_restab;                   // Offset of resident name table
  3135.     WORD   ne_modtab;                   // Offset of Module Reference Table
  3136.     WORD   ne_imptab;                   // Offset of Imported Names Table
  3137.     LONG   ne_nrestab;                  // Offset of Non-resident Names Table
  3138.     WORD   ne_cmovent;                  // Count of movable entries
  3139.     WORD   ne_align;                    // Segment alignment shift count
  3140.     WORD   ne_cres;                     // Count of resource segments
  3141.     BYTE   ne_exetyp;                   // Target Operating system
  3142.     BYTE   ne_flagsothers;              // Other .EXE flags
  3143.     WORD   ne_pretthunks;               // offset to return thunks
  3144.     WORD   ne_psegrefbytes;             // offset to segment ref. bytes
  3145.     WORD   ne_swaparea;                 // Minimum code swap area size
  3146.     WORD   ne_expver;                   // Expected Windows version number
  3147.   } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
  3148.  
  3149. typedef struct _IMAGE_VXD_HEADER {      // Windows VXD header
  3150.     WORD   e32_magic;                   // Magic number
  3151.     BYTE   e32_border;                  // The byte ordering for the VXD
  3152.     BYTE   e32_worder;                  // The word ordering for the VXD
  3153.     DWORD  e32_level;                   // The EXE format level for now = 0
  3154.     WORD   e32_cpu;                     // The CPU type
  3155.     WORD   e32_os;                      // The OS type
  3156.     DWORD  e32_ver;                     // Module version
  3157.     DWORD  e32_mflags;                  // Module flags
  3158.     DWORD  e32_mpages;                  // Module # pages
  3159.     DWORD  e32_startobj;                // Object # for instruction pointer
  3160.     DWORD  e32_eip;                     // Extended instruction pointer
  3161.     DWORD  e32_stackobj;                // Object # for stack pointer
  3162.     DWORD  e32_esp;                     // Extended stack pointer
  3163.     DWORD  e32_pagesize;                // VXD page size
  3164.     DWORD  e32_lastpagesize;            // Last page size in VXD
  3165.     DWORD  e32_fixupsize;               // Fixup section size
  3166.     DWORD  e32_fixupsum;                // Fixup section checksum
  3167.     DWORD  e32_ldrsize;                 // Loader section size
  3168.     DWORD  e32_ldrsum;                  // Loader section checksum
  3169.     DWORD  e32_objtab;                  // Object table offset
  3170.     DWORD  e32_objcnt;                  // Number of objects in module
  3171.     DWORD  e32_objmap;                  // Object page map offset
  3172.     DWORD  e32_itermap;                 // Object iterated data map offset
  3173.     DWORD  e32_rsrctab;                 // Offset of Resource Table
  3174.     DWORD  e32_rsrccnt;                 // Number of resource entries
  3175.     DWORD  e32_restab;                  // Offset of resident name table
  3176.     DWORD  e32_enttab;                  // Offset of Entry Table
  3177.     DWORD  e32_dirtab;                  // Offset of Module Directive Table
  3178.     DWORD  e32_dircnt;                  // Number of module directives
  3179.     DWORD  e32_fpagetab;                // Offset of Fixup Page Table
  3180.     DWORD  e32_frectab;                 // Offset of Fixup Record Table
  3181.     DWORD  e32_impmod;                  // Offset of Import Module Name Table
  3182.     DWORD  e32_impmodcnt;               // Number of entries in Import Module Name Table
  3183.     DWORD  e32_impproc;                 // Offset of Import Procedure Name Table
  3184.     DWORD  e32_pagesum;                 // Offset of Per-Page Checksum Table
  3185.     DWORD  e32_datapage;                // Offset of Enumerated Data Pages
  3186.     DWORD  e32_preload;                 // Number of preload pages
  3187.     DWORD  e32_nrestab;                 // Offset of Non-resident Names Table
  3188.     DWORD  e32_cbnrestab;               // Size of Non-resident Name Table
  3189.     DWORD  e32_nressum;                 // Non-resident Name Table Checksum
  3190.     DWORD  e32_autodata;                // Object # for automatic data object
  3191.     DWORD  e32_debuginfo;               // Offset of the debugging information
  3192.     DWORD  e32_debuglen;                // The length of the debugging info. in bytes
  3193.     DWORD  e32_instpreload;             // Number of instance pages in preload section of VXD file
  3194.     DWORD  e32_instdemand;              // Number of instance pages in demand load section of VXD file
  3195.     DWORD  e32_heapsize;                // Size of heap - for 16-bit apps
  3196.     BYTE   e32_res3[12];                // Reserved words
  3197.     DWORD  e32_winresoff;
  3198.     DWORD  e32_winreslen;
  3199.     WORD   e32_devid;                   // Device ID for VxD
  3200.     WORD   e32_ddkver;                  // DDK version for VxD
  3201.   } IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
  3202.  
  3203. //
  3204. // File header format.
  3205. //
  3206.  
  3207. typedef struct _IMAGE_FILE_HEADER {
  3208.     WORD    Machine;
  3209.     WORD    NumberOfSections;
  3210.     DWORD   TimeDateStamp;
  3211.     DWORD   PointerToSymbolTable;
  3212.     DWORD   NumberOfSymbols;
  3213.     WORD    SizeOfOptionalHeader;
  3214.     WORD    Characteristics;
  3215. } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
  3216.  
  3217. #define IMAGE_SIZEOF_FILE_HEADER             20
  3218.  
  3219. #define IMAGE_FILE_RELOCS_STRIPPED           0x0001  // Relocation info stripped from file.
  3220. #define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002  // File is executable  (i.e. no unresolved externel references).
  3221. #define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004  // Line nunbers stripped from file.
  3222. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008  // Local symbols stripped from file.
  3223. #define IMAGE_FILE_BYTES_REVERSED_LO         0x0080  // Bytes of machine word are reversed.
  3224. #define IMAGE_FILE_32BIT_MACHINE             0x0100  // 32 bit word machine.
  3225. #define IMAGE_FILE_DEBUG_STRIPPED            0x0200  // Debugging info stripped from file in .DBG file
  3226. #define IMAGE_FILE_SYSTEM                    0x1000  // System File.
  3227. #define IMAGE_FILE_DLL                       0x2000  // File is a DLL.
  3228. #define IMAGE_FILE_BYTES_REVERSED_HI         0x8000  // Bytes of machine word are reversed.
  3229.  
  3230. #define IMAGE_FILE_MACHINE_UNKNOWN           0
  3231. #define IMAGE_FILE_MACHINE_I386              0x14c   // Intel 386.
  3232. #define IMAGE_FILE_MACHINE_R3000             0x162   // MIPS little-endian, 0x160 big-endian
  3233. #define IMAGE_FILE_MACHINE_R4000             0x166   // MIPS little-endian
  3234. #define IMAGE_FILE_MACHINE_R10000            0x168   // MIPS little-endian
  3235. #define IMAGE_FILE_MACHINE_ALPHA             0x184   // Alpha_AXP
  3236. #define IMAGE_FILE_MACHINE_POWERPC           0x1F0   // IBM PowerPC Little-Endian
  3237.  
  3238. //
  3239. // Directory format.
  3240. //
  3241.  
  3242. typedef struct _IMAGE_DATA_DIRECTORY {
  3243.     DWORD   VirtualAddress;
  3244.     DWORD   Size;
  3245. } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
  3246.  
  3247. #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES    16
  3248.  
  3249. //
  3250. // Optional header format.
  3251. //
  3252.  
  3253. typedef struct _IMAGE_OPTIONAL_HEADER {
  3254.     //
  3255.     // Standard fields.
  3256.     //
  3257.  
  3258.     WORD    Magic;
  3259.     BYTE    MajorLinkerVersion;
  3260.     BYTE    MinorLinkerVersion;
  3261.     DWORD   SizeOfCode;
  3262.     DWORD   SizeOfInitializedData;
  3263.     DWORD   SizeOfUninitializedData;
  3264.     DWORD   AddressOfEntryPoint;
  3265.     DWORD   BaseOfCode;
  3266.     DWORD   BaseOfData;
  3267.  
  3268.     //
  3269.     // NT additional fields.
  3270.     //
  3271.  
  3272.     DWORD   ImageBase;
  3273.     DWORD   SectionAlignment;
  3274.     DWORD   FileAlignment;
  3275.     WORD    MajorOperatingSystemVersion;
  3276.     WORD    MinorOperatingSystemVersion;
  3277.     WORD    MajorImageVersion;
  3278.     WORD    MinorImageVersion;
  3279.     WORD    MajorSubsystemVersion;
  3280.     WORD    MinorSubsystemVersion;
  3281.     DWORD   Reserved1;
  3282.     DWORD   SizeOfImage;
  3283.     DWORD   SizeOfHeaders;
  3284.     DWORD   CheckSum;
  3285.     WORD    Subsystem;
  3286.     WORD    DllCharacteristics;
  3287.     DWORD   SizeOfStackReserve;
  3288.     DWORD   SizeOfStackCommit;
  3289.     DWORD   SizeOfHeapReserve;
  3290.     DWORD   SizeOfHeapCommit;
  3291.     DWORD   LoaderFlags;
  3292.     DWORD   NumberOfRvaAndSizes;
  3293.     IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  3294. } IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
  3295.  
  3296. typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
  3297.     WORD   Magic;
  3298.     BYTE   MajorLinkerVersion;
  3299.     BYTE   MinorLinkerVersion;
  3300.     DWORD  SizeOfCode;
  3301.     DWORD  SizeOfInitializedData;
  3302.     DWORD  SizeOfUninitializedData;
  3303.     DWORD  AddressOfEntryPoint;
  3304.     DWORD  BaseOfCode;
  3305.     DWORD  BaseOfData;
  3306.     DWORD  BaseOfBss;
  3307.     DWORD  GprMask;
  3308.     DWORD  CprMask[4];
  3309.     DWORD  GpValue;
  3310. } IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
  3311.  
  3312. #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER      56
  3313. #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER      28
  3314. #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER      224
  3315.  
  3316. #define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
  3317. #define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
  3318.  
  3319. typedef struct _IMAGE_NT_HEADERS {
  3320.     DWORD Signature;
  3321.     IMAGE_FILE_HEADER FileHeader;
  3322.     IMAGE_OPTIONAL_HEADER OptionalHeader;
  3323. } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
  3324.  
  3325. typedef struct _IMAGE_ROM_HEADERS {
  3326.     IMAGE_FILE_HEADER FileHeader;
  3327.     IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
  3328. } IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
  3329.  
  3330. #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER)        \
  3331.     ((DWORD)ntheader +                                                  \
  3332.      FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) +                 \
  3333.      ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader   \
  3334.     ))
  3335.  
  3336.  
  3337. // Subsystem Values
  3338.  
  3339. #define IMAGE_SUBSYSTEM_UNKNOWN              0   // Unknown subsystem.
  3340. #define IMAGE_SUBSYSTEM_NATIVE               1   // Image doesn't require a subsystem.
  3341. #define IMAGE_SUBSYSTEM_WINDOWS_GUI          2   // Image runs in the Windows GUI subsystem.
  3342. #define IMAGE_SUBSYSTEM_WINDOWS_CUI          3   // Image runs in the Windows character subsystem.
  3343. #define IMAGE_SUBSYSTEM_OS2_CUI              5   // image runs in the OS/2 character subsystem.
  3344. #define IMAGE_SUBSYSTEM_POSIX_CUI            7   // image run  in the Posix character subsystem.
  3345.  
  3346.  
  3347. // Directory Entries
  3348.  
  3349. #define IMAGE_DIRECTORY_ENTRY_EXPORT         0   // Export Directory
  3350. #define IMAGE_DIRECTORY_ENTRY_IMPORT         1   // Import Directory
  3351. #define IMAGE_DIRECTORY_ENTRY_RESOURCE       2   // Resource Directory
  3352. #define IMAGE_DIRECTORY_ENTRY_EXCEPTION      3   // Exception Directory
  3353. #define IMAGE_DIRECTORY_ENTRY_SECURITY       4   // Security Directory
  3354. #define IMAGE_DIRECTORY_ENTRY_BASERELOC      5   // Base Relocation Table
  3355. #define IMAGE_DIRECTORY_ENTRY_DEBUG          6   // Debug Directory
  3356. #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT      7   // Description String
  3357. #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR      8   // Machine Value (MIPS GP)
  3358. #define IMAGE_DIRECTORY_ENTRY_TLS            9   // TLS Directory
  3359. #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG   10   // Load Configuration Directory
  3360. #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT  11   // Bound Import Directory in headers
  3361. #define IMAGE_DIRECTORY_ENTRY_IAT           12   // Import Address Table
  3362.  
  3363. //
  3364. // Section header format.
  3365. //
  3366.  
  3367. #define IMAGE_SIZEOF_SHORT_NAME              8
  3368.  
  3369. typedef struct _IMAGE_SECTION_HEADER {
  3370.     BYTE    Name[IMAGE_SIZEOF_SHORT_NAME];
  3371.     union {
  3372.             DWORD   PhysicalAddress;
  3373.             DWORD   VirtualSize;
  3374.     } Misc;
  3375.     DWORD   VirtualAddress;
  3376.     DWORD   SizeOfRawData;
  3377.     DWORD   PointerToRawData;
  3378.     DWORD   PointerToRelocations;
  3379.     DWORD   PointerToLinenumbers;
  3380.     WORD    NumberOfRelocations;
  3381.     WORD    NumberOfLinenumbers;
  3382.     DWORD   Characteristics;
  3383. } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
  3384.  
  3385. #define IMAGE_SIZEOF_SECTION_HEADER          40
  3386.  
  3387. //
  3388. // Section characteristics.
  3389. //
  3390.  
  3391. //      IMAGE_SCN_TYPE_REG                   0x00000000  // Reserved.
  3392. //      IMAGE_SCN_TYPE_DSECT                 0x00000001  // Reserved.
  3393. //      IMAGE_SCN_TYPE_NOLOAD                0x00000002  // Reserved.
  3394. //      IMAGE_SCN_TYPE_GROUP                 0x00000004  // Reserved.
  3395. #define IMAGE_SCN_TYPE_NO_PAD                0x00000008  // Reserved.
  3396. //      IMAGE_SCN_TYPE_COPY                  0x00000010  // Reserved.
  3397.  
  3398. #define IMAGE_SCN_CNT_CODE                   0x00000020  // Section contains code.
  3399. #define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  // Section contains initialized data.
  3400. #define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  // Section contains uninitialized data.
  3401.  
  3402. #define IMAGE_SCN_LNK_OTHER                  0x00000100  // Reserved.
  3403. #define IMAGE_SCN_LNK_INFO                   0x00000200  // Section contains comments or some other type of information.
  3404. //      IMAGE_SCN_TYPE_OVER                  0x00000400  // Reserved.
  3405. #define IMAGE_SCN_LNK_REMOVE                 0x00000800  // Section contents will not become part of image.
  3406. #define IMAGE_SCN_LNK_COMDAT                 0x00001000  // Section contents comdat.
  3407. //                                           0x00002000  // Reserved.
  3408.  
  3409. //      IMAGE_SCN_MEM_PROTECTED - Obsolete   0x00004000
  3410. #define IMAGE_SCN_MEM_FARDATA                0x00008000
  3411. //      IMAGE_SCN_MEM_SYSHEAP  - Obsolete    0x00010000
  3412. #define IMAGE_SCN_MEM_PURGEABLE              0x00020000
  3413. #define IMAGE_SCN_MEM_16BIT                  0x00020000
  3414. #define IMAGE_SCN_MEM_LOCKED                 0x00040000
  3415. #define IMAGE_SCN_MEM_PRELOAD                0x00080000
  3416.  
  3417. #define IMAGE_SCN_ALIGN_1BYTES               0x00100000  //
  3418. #define IMAGE_SCN_ALIGN_2BYTES               0x00200000  //
  3419. #define IMAGE_SCN_ALIGN_4BYTES               0x00300000  //
  3420. #define IMAGE_SCN_ALIGN_8BYTES               0x00400000  //
  3421. #define IMAGE_SCN_ALIGN_16BYTES              0x00500000  // Default alignment if no others are specified.
  3422. #define IMAGE_SCN_ALIGN_32BYTES              0x00600000  //
  3423. #define IMAGE_SCN_ALIGN_64BYTES              0x00700000  //
  3424. // Unused                                    0x00800000
  3425.  
  3426. #define IMAGE_SCN_LNK_NRELOC_OVFL            0x01000000  // Section contains extended relocations.
  3427. #define IMAGE_SCN_MEM_DISCARDABLE            0x02000000  // Section can be discarded.
  3428. #define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  // Section is not cachable.
  3429. #define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  // Section is not pageable.
  3430. #define IMAGE_SCN_MEM_SHARED                 0x10000000  // Section is shareable.
  3431. #define IMAGE_SCN_MEM_EXECUTE                0x20000000  // Section is executable.
  3432. #define IMAGE_SCN_MEM_READ                   0x40000000  // Section is readable.
  3433. #define IMAGE_SCN_MEM_WRITE                  0x80000000  // Section is writeable.
  3434.  
  3435. //
  3436. // Symbol format.
  3437. //
  3438.  
  3439. typedef struct _IMAGE_SYMBOL {
  3440.     union {
  3441.         BYTE    ShortName[8];
  3442.         struct {
  3443.             DWORD   Short;     // if 0, use LongName
  3444.             DWORD   Long;      // offset into string table
  3445.         } Name;
  3446.         PBYTE   LongName[2];
  3447.     } N;
  3448.     DWORD   Value;
  3449.     SHORT   SectionNumber;
  3450.     WORD    Type;
  3451.     BYTE    StorageClass;
  3452.     BYTE    NumberOfAuxSymbols;
  3453. } IMAGE_SYMBOL;
  3454. typedef IMAGE_SYMBOL UNALIGNED *PIMAGE_SYMBOL;
  3455.  
  3456. #define IMAGE_SIZEOF_SYMBOL                  18
  3457.  
  3458. //
  3459. // Section values.
  3460. //
  3461. // Symbols have a section number of the section in which they are
  3462. // defined. Otherwise, section numbers have the following meanings:
  3463. //
  3464.  
  3465. #define IMAGE_SYM_UNDEFINED           (SHORT)0          // Symbol is undefined or is common.
  3466. #define IMAGE_SYM_ABSOLUTE            (SHORT)-1         // Symbol is an absolute value.
  3467. #define IMAGE_SYM_DEBUG               (SHORT)-2         // Symbol is a special debug item.
  3468.  
  3469. //
  3470. // Type (fundamental) values.
  3471. //
  3472.  
  3473. #define IMAGE_SYM_TYPE_NULL                 0x0000  // no type.
  3474. #define IMAGE_SYM_TYPE_VOID                 0x0001  //
  3475. #define IMAGE_SYM_TYPE_CHAR                 0x0002  // type character.
  3476. #define IMAGE_SYM_TYPE_SHORT                0x0003  // type short integer.
  3477. #define IMAGE_SYM_TYPE_INT                  0x0004  //
  3478. #define IMAGE_SYM_TYPE_LONG                 0x0005  //
  3479. #define IMAGE_SYM_TYPE_FLOAT                0x0006  //
  3480. #define IMAGE_SYM_TYPE_DOUBLE               0x0007  //
  3481. #define IMAGE_SYM_TYPE_STRUCT               0x0008  //
  3482. #define IMAGE_SYM_TYPE_UNION                0x0009  //
  3483. #define IMAGE_SYM_TYPE_ENUM                 0x000A  // enumeration.
  3484. #define IMAGE_SYM_TYPE_MOE                  0x000B  // member of enumeration.
  3485. #define IMAGE_SYM_TYPE_BYTE                 0x000C  //
  3486. #define IMAGE_SYM_TYPE_WORD                 0x000D  //
  3487. #define IMAGE_SYM_TYPE_UINT                 0x000E  //
  3488. #define IMAGE_SYM_TYPE_DWORD                0x000F  //
  3489. #define IMAGE_SYM_TYPE_PCODE                0x8000  //
  3490.  
  3491. //
  3492. // Type (derived) values.
  3493. //
  3494.  
  3495. #define IMAGE_SYM_DTYPE_NULL                0       // no derived type.
  3496. #define IMAGE_SYM_DTYPE_POINTER             1       // pointer.
  3497. #define IMAGE_SYM_DTYPE_FUNCTION            2       // function.
  3498. #define IMAGE_SYM_DTYPE_ARRAY               3       // array.
  3499.  
  3500. //
  3501. // Storage classes.
  3502. //
  3503.  
  3504. #define IMAGE_SYM_CLASS_END_OF_FUNCTION     (BYTE )-1
  3505. #define IMAGE_SYM_CLASS_NULL                0x0000
  3506. #define IMAGE_SYM_CLASS_AUTOMATIC           0x0001
  3507. #define IMAGE_SYM_CLASS_EXTERNAL            0x0002
  3508. #define IMAGE_SYM_CLASS_STATIC              0x0003
  3509. #define IMAGE_SYM_CLASS_REGISTER            0x0004
  3510. #define IMAGE_SYM_CLASS_EXTERNAL_DEF        0x0005
  3511. #define IMAGE_SYM_CLASS_LABEL               0x0006
  3512. #define IMAGE_SYM_CLASS_UNDEFINED_LABEL     0x0007
  3513. #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT    0x0008
  3514. #define IMAGE_SYM_CLASS_ARGUMENT            0x0009
  3515. #define IMAGE_SYM_CLASS_STRUCT_TAG          0x000A
  3516. #define IMAGE_SYM_CLASS_MEMBER_OF_UNION     0x000B
  3517. #define IMAGE_SYM_CLASS_UNION_TAG           0x000C
  3518. #define IMAGE_SYM_CLASS_TYPE_DEFINITION     0x000D
  3519. #define IMAGE_SYM_CLASS_UNDEFINED_STATIC    0x000E
  3520. #define IMAGE_SYM_CLASS_ENUM_TAG            0x000F
  3521. #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM      0x0010
  3522. #define IMAGE_SYM_CLASS_REGISTER_PARAM      0x0011
  3523. #define IMAGE_SYM_CLASS_BIT_FIELD           0x0012
  3524.  
  3525. #define IMAGE_SYM_CLASS_FAR_EXTERNAL        0x0044  //
  3526.  
  3527. #define IMAGE_SYM_CLASS_BLOCK               0x0064
  3528. #define IMAGE_SYM_CLASS_FUNCTION            0x0065
  3529. #define IMAGE_SYM_CLASS_END_OF_STRUCT       0x0066
  3530. #define IMAGE_SYM_CLASS_FILE                0x0067
  3531. // new
  3532. #define IMAGE_SYM_CLASS_SECTION             0x0068
  3533. #define IMAGE_SYM_CLASS_WEAK_EXTERNAL       0x0069
  3534.  
  3535. // type packing constants
  3536.  
  3537. #define N_BTMASK                            0x000F
  3538. #define N_TMASK                             0x0030
  3539. #define N_TMASK1                            0x00C0
  3540. #define N_TMASK2                            0x00F0
  3541. #define N_BTSHFT                            4
  3542. #define N_TSHIFT                            2
  3543.  
  3544. // MACROS
  3545.  
  3546. // Basic Type of  x
  3547. #define BTYPE(x) ((x) & N_BTMASK)
  3548.  
  3549. // Is x a pointer?
  3550. #ifndef ISPTR
  3551. #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
  3552. #endif
  3553.  
  3554. // Is x a function?
  3555. #ifndef ISFCN
  3556. #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
  3557. #endif
  3558.  
  3559. // Is x an array?
  3560.  
  3561. #ifndef ISARY
  3562. #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
  3563. #endif
  3564.  
  3565. // Is x a structure, union, or enumeration TAG?
  3566. #ifndef ISTAG
  3567. #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
  3568. #endif
  3569.  
  3570. #ifndef INCREF
  3571. #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
  3572. #endif
  3573. #ifndef DECREF
  3574. #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  3575. #endif
  3576.  
  3577. //
  3578. // Auxiliary entry format.
  3579. //
  3580.  
  3581. typedef union _IMAGE_AUX_SYMBOL {
  3582.     struct {
  3583.         DWORD    TagIndex;                      // struct, union, or enum tag index
  3584.         union {
  3585.             struct {
  3586.                 WORD    Linenumber;             // declaration line number
  3587.                 WORD    Size;                   // size of struct, union, or enum
  3588.             } LnSz;
  3589.            DWORD    TotalSize;
  3590.         } Misc;
  3591.         union {
  3592.             struct {                            // if ISFCN, tag, or .bb
  3593.                 DWORD    PointerToLinenumber;
  3594.                 DWORD    PointerToNextFunction;
  3595.             } Function;
  3596.             struct {                            // if ISARY, up to 4 dimen.
  3597.                 WORD     Dimension[4];
  3598.             } Array;
  3599.         } FcnAry;
  3600.         WORD    TvIndex;                        // tv index
  3601.     } Sym;
  3602.     struct {
  3603.         BYTE    Name[IMAGE_SIZEOF_SYMBOL];
  3604.     } File;
  3605.     struct {
  3606.         DWORD   Length;                         // section length
  3607.         WORD    NumberOfRelocations;            // number of relocation entries
  3608.         WORD    NumberOfLinenumbers;            // number of line numbers
  3609.         DWORD   CheckSum;                       // checksum for communal
  3610.         SHORT   Number;                         // section number to associate with
  3611.         BYTE    Selection;                      // communal selection type
  3612.     } Section;
  3613. } IMAGE_AUX_SYMBOL;
  3614. typedef IMAGE_AUX_SYMBOL UNALIGNED *PIMAGE_AUX_SYMBOL;
  3615.  
  3616. #define IMAGE_SIZEOF_AUX_SYMBOL             18
  3617.  
  3618. //
  3619. // Communal selection types.
  3620. //
  3621.  
  3622. #define IMAGE_COMDAT_SELECT_NODUPLICATES    1
  3623. #define IMAGE_COMDAT_SELECT_ANY             2
  3624. #define IMAGE_COMDAT_SELECT_SAME_SIZE       3
  3625. #define IMAGE_COMDAT_SELECT_EXACT_MATCH     4
  3626. #define IMAGE_COMDAT_SELECT_ASSOCIATIVE     5
  3627. #define IMAGE_COMDAT_SELECT_LARGEST         6
  3628. #define IMAGE_COMDAT_SELECT_NEWEST          7
  3629.  
  3630. #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY  1
  3631. #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY    2
  3632. #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS      3
  3633.  
  3634. //
  3635. // Relocation format.
  3636. //
  3637.  
  3638. typedef struct _IMAGE_RELOCATION {
  3639.     union {
  3640.         DWORD   VirtualAddress;
  3641.         DWORD   RelocCount;             // Set to the real count when IMAGE_SCN_LNK_NRELOC_OVFL is set
  3642.     };
  3643.     DWORD   SymbolTableIndex;
  3644.     WORD    Type;
  3645. } IMAGE_RELOCATION;
  3646. typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION;
  3647.  
  3648. #define IMAGE_SIZEOF_RELOCATION         10
  3649.  
  3650. //
  3651. // I386 relocation types.
  3652. //
  3653.  
  3654. #define IMAGE_REL_I386_ABSOLUTE         0x0000  // Reference is absolute, no relocation is necessary
  3655. #define IMAGE_REL_I386_DIR16            0x0001  // Direct 16-bit reference to the symbols virtual address
  3656. #define IMAGE_REL_I386_REL16            0x0002  // PC-relative 16-bit reference to the symbols virtual address
  3657. #define IMAGE_REL_I386_DIR32            0x0006  // Direct 32-bit reference to the symbols virtual address
  3658. #define IMAGE_REL_I386_DIR32NB          0x0007  // Direct 32-bit reference to the symbols virtual address, base not included
  3659. #define IMAGE_REL_I386_SEG12            0x0009  // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
  3660. #define IMAGE_REL_I386_SECTION          0x000A
  3661. #define IMAGE_REL_I386_SECREL           0x000B
  3662. #define IMAGE_REL_I386_REL32            0x0014  // PC-relative 32-bit reference to the symbols virtual address
  3663.  
  3664. //
  3665. // MIPS relocation types.
  3666. //
  3667.  
  3668. #define IMAGE_REL_MIPS_ABSOLUTE         0x0000  // Reference is absolute, no relocation is necessary
  3669. #define IMAGE_REL_MIPS_REFHALF          0x0001
  3670. #define IMAGE_REL_MIPS_REFWORD          0x0002
  3671. #define IMAGE_REL_MIPS_JMPADDR          0x0003
  3672. #define IMAGE_REL_MIPS_REFHI            0x0004
  3673. #define IMAGE_REL_MIPS_REFLO            0x0005
  3674. #define IMAGE_REL_MIPS_GPREL            0x0006
  3675. #define IMAGE_REL_MIPS_LITERAL          0x0007
  3676. #define IMAGE_REL_MIPS_SECTION          0x000A
  3677. #define IMAGE_REL_MIPS_SECREL           0x000B
  3678. #define IMAGE_REL_MIPS_SECRELLO         0x000C  // Low 16-bit section relative referemce (used for >32k TLS)
  3679. #define IMAGE_REL_MIPS_SECRELHI         0x000D  // High 16-bit section relative reference (used for >32k TLS)
  3680. #define IMAGE_REL_MIPS_REFWORDNB        0x0022
  3681. #define IMAGE_REL_MIPS_PAIR             0x0025
  3682.  
  3683. //
  3684. // Alpha Relocation types.
  3685. //
  3686.  
  3687. #define IMAGE_REL_ALPHA_ABSOLUTE        0x0000
  3688. #define IMAGE_REL_ALPHA_REFLONG         0x0001
  3689. #define IMAGE_REL_ALPHA_REFQUAD         0x0002
  3690. #define IMAGE_REL_ALPHA_GPREL32         0x0003
  3691. #define IMAGE_REL_ALPHA_LITERAL         0x0004
  3692. #define IMAGE_REL_ALPHA_LITUSE          0x0005
  3693. #define IMAGE_REL_ALPHA_GPDISP          0x0006
  3694. #define IMAGE_REL_ALPHA_BRADDR          0x0007
  3695. #define IMAGE_REL_ALPHA_HINT            0x0008
  3696. #define IMAGE_REL_ALPHA_INLINE_REFLONG  0x0009
  3697. #define IMAGE_REL_ALPHA_REFHI           0x000A
  3698. #define IMAGE_REL_ALPHA_REFLO           0x000B
  3699. #define IMAGE_REL_ALPHA_PAIR            0x000C
  3700. #define IMAGE_REL_ALPHA_MATCH           0x000D
  3701. #define IMAGE_REL_ALPHA_SECTION         0x000E
  3702. #define IMAGE_REL_ALPHA_SECREL          0x000F
  3703. #define IMAGE_REL_ALPHA_REFLONGNB       0x0010
  3704. #define IMAGE_REL_ALPHA_SECRELLO        0x0011  // Low 16-bit section relative reference
  3705. #define IMAGE_REL_ALPHA_SECRELHI        0x0012  // High 16-bit section relative reference
  3706.  
  3707. //
  3708. // IBM PowerPC relocation types.
  3709. //
  3710.  
  3711. #define IMAGE_REL_PPC_ABSOLUTE          0x0000  // NOP
  3712. #define IMAGE_REL_PPC_ADDR64            0x0001  // 64-bit address
  3713. #define IMAGE_REL_PPC_ADDR32            0x0002  // 32-bit address
  3714. #define IMAGE_REL_PPC_ADDR24            0x0003  // 26-bit address, shifted left 2 (branch absolute)
  3715. #define IMAGE_REL_PPC_ADDR16            0x0004  // 16-bit address
  3716. #define IMAGE_REL_PPC_ADDR14            0x0005  // 16-bit address, shifted left 2 (load doubleword)
  3717. #define IMAGE_REL_PPC_REL24             0x0006  // 26-bit PC-relative offset, shifted left 2 (branch relative)
  3718. #define IMAGE_REL_PPC_REL14             0x0007  // 16-bit PC-relative offset, shifted left 2 (br cond relative)
  3719. #define IMAGE_REL_PPC_TOCREL16          0x0008  // 16-bit offset from TOC base
  3720. #define IMAGE_REL_PPC_TOCREL14          0x0009  // 16-bit offset from TOC base, shifted left 2 (load doubleword)
  3721.  
  3722. #define IMAGE_REL_PPC_ADDR32NB          0x000A  // 32-bit addr w/o image base
  3723. #define IMAGE_REL_PPC_SECREL            0x000B  // va of containing section (as in an image sectionhdr)
  3724. #define IMAGE_REL_PPC_SECTION           0x000C  // sectionheader number
  3725. #define IMAGE_REL_PPC_IFGLUE            0x000D  // substitute TOC restore instruction iff symbol is glue code
  3726. #define IMAGE_REL_PPC_IMGLUE            0x000E  // symbol is glue code; virtual address is TOC restore instruction
  3727. #define IMAGE_REL_PPC_SECREL16          0x000F  // va of containing section (limited to 16 bits)
  3728. #define IMAGE_REL_PPC_REFHI             0x0010
  3729. #define IMAGE_REL_PPC_REFLO             0x0011
  3730. #define IMAGE_REL_PPC_PAIR              0x0012
  3731.  
  3732. #define IMAGE_REL_PPC_TYPEMASK          0x00FF  // mask to isolate above values in IMAGE_RELOCATION.Type
  3733.  
  3734. // Flag bits in IMAGE_RELOCATION.TYPE
  3735.  
  3736. #define IMAGE_REL_PPC_NEG               0x0100  // subtract reloc value rather than adding it
  3737. #define IMAGE_REL_PPC_BRTAKEN           0x0200  // fix branch prediction bit to predict branch taken
  3738. #define IMAGE_REL_PPC_BRNTAKEN          0x0400  // fix branch prediction bit to predict branch not taken
  3739. #define IMAGE_REL_PPC_TOCDEFN           0x0800  // toc slot defined in file (or, data in toc)
  3740.  
  3741. //
  3742. // Based relocation format.
  3743. //
  3744.  
  3745. typedef struct _IMAGE_BASE_RELOCATION {
  3746.     DWORD   VirtualAddress;
  3747.     DWORD   SizeOfBlock;
  3748. //  WORD    TypeOffset[1];
  3749. } IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION;
  3750.  
  3751. #define IMAGE_SIZEOF_BASE_RELOCATION         8
  3752.  
  3753. //
  3754. // Based relocation types.
  3755. //
  3756.  
  3757. #define IMAGE_REL_BASED_ABSOLUTE              0
  3758. #define IMAGE_REL_BASED_HIGH                  1
  3759. #define IMAGE_REL_BASED_LOW                   2
  3760. #define IMAGE_REL_BASED_HIGHLOW               3
  3761. #define IMAGE_REL_BASED_HIGHADJ               4
  3762. #define IMAGE_REL_BASED_MIPS_JMPADDR          5
  3763.  
  3764. //
  3765. // Line number format.
  3766. //
  3767.  
  3768. typedef struct _IMAGE_LINENUMBER {
  3769.     union {
  3770.         DWORD   SymbolTableIndex;               // Symbol table index of function name if Linenumber is 0.
  3771.         DWORD   VirtualAddress;                 // Virtual address of line number.
  3772.     } Type;
  3773.     WORD    Linenumber;                         // Line number.
  3774. } IMAGE_LINENUMBER;
  3775. typedef IMAGE_LINENUMBER UNALIGNED *PIMAGE_LINENUMBER;
  3776.  
  3777. #define IMAGE_SIZEOF_LINENUMBER              6
  3778.  
  3779. //
  3780. // Archive format.
  3781. //
  3782.  
  3783. #define IMAGE_ARCHIVE_START_SIZE             8
  3784. #define IMAGE_ARCHIVE_START                  "!<arch>\n"
  3785. #define IMAGE_ARCHIVE_END                    "`\n"
  3786. #define IMAGE_ARCHIVE_PAD                    "\n"
  3787. #define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
  3788. #define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
  3789.  
  3790. typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
  3791.     BYTE     Name[16];                          // File member name - `/' terminated.
  3792.     BYTE     Date[12];                          // File member date - decimal.
  3793.     BYTE     UserID[6];                         // File member user id - decimal.
  3794.     BYTE     GroupID[6];                        // File member group id - decimal.
  3795.     BYTE     Mode[8];                           // File member mode - octal.
  3796.     BYTE     Size[10];                          // File member size - decimal.
  3797.     BYTE     EndHeader[2];                      // String to end header.
  3798. } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
  3799.  
  3800. #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR      60
  3801.  
  3802. //
  3803. // DLL support.
  3804. //
  3805.  
  3806. //
  3807. // Export Format
  3808. //
  3809.  
  3810. typedef struct _IMAGE_EXPORT_DIRECTORY {
  3811.     DWORD   Characteristics;
  3812.     DWORD   TimeDateStamp;
  3813.     WORD    MajorVersion;
  3814.     WORD    MinorVersion;
  3815.     DWORD   Name;
  3816.     DWORD   Base;
  3817.     DWORD   NumberOfFunctions;
  3818.     DWORD   NumberOfNames;
  3819.     PDWORD  *AddressOfFunctions;
  3820.     PDWORD  *AddressOfNames;
  3821.     PWORD   *AddressOfNameOrdinals;
  3822. } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
  3823.  
  3824. //
  3825. // Import Format
  3826. //
  3827.  
  3828. typedef struct _IMAGE_IMPORT_BY_NAME {
  3829.     WORD    Hint;
  3830.     BYTE    Name[1];
  3831. } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
  3832.  
  3833. typedef struct _IMAGE_THUNK_DATA {
  3834.     union {
  3835.         PBYTE  ForwarderString;
  3836.         PDWORD Function;
  3837.         DWORD Ordinal;
  3838.         PIMAGE_IMPORT_BY_NAME AddressOfData;
  3839.     } u1;
  3840. } IMAGE_THUNK_DATA, *PIMAGE_THUNK_DATA;
  3841.  
  3842. #define IMAGE_ORDINAL_FLAG 0x80000000
  3843. #define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
  3844. #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
  3845.  
  3846. typedef struct _IMAGE_IMPORT_DESCRIPTOR {
  3847.     union {
  3848.         DWORD   Characteristics;                // 0 for terminating null import descriptor
  3849.         PIMAGE_THUNK_DATA OriginalFirstThunk;   // RVA to original unbound IAT
  3850.     };
  3851.     DWORD   TimeDateStamp;                  // 0 if not bound,
  3852.                                             // -1 if bound, and real date\time stamp
  3853.                                             //     in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
  3854.                                             // O.W. date/time stamp of DLL bound to (Old BIND)
  3855.  
  3856.     DWORD   ForwarderChain;                 // -1 if no forwarders
  3857.     DWORD   Name;
  3858.     PIMAGE_THUNK_DATA FirstThunk;           // RVA to IAT (if bound this IAT has actual addresses)
  3859. } IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR;
  3860.  
  3861. //
  3862. // New format import descriptors pointed to by DataDirectory[ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT ]
  3863. //
  3864.  
  3865. typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR {
  3866.     DWORD   TimeDateStamp;
  3867.     WORD    OffsetModuleName;
  3868.     WORD    NumberOfModuleForwarderRefs;
  3869. // Array of zero or more IMAGE_BOUND_FORWARDER_REF follows
  3870. } IMAGE_BOUND_IMPORT_DESCRIPTOR, *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
  3871.  
  3872. typedef struct _IMAGE_BOUND_FORWARDER_REF {
  3873.     DWORD   TimeDateStamp;
  3874.     WORD    OffsetModuleName;
  3875.     WORD    Reserved;
  3876. } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
  3877.  
  3878.  
  3879. //
  3880. // Thread Local Storage
  3881. //
  3882.  
  3883. typedef VOID
  3884. (NTAPI *PIMAGE_TLS_CALLBACK) (
  3885.     PVOID DllHandle,
  3886.     DWORD Reason,
  3887.     PVOID Reserved
  3888.     );
  3889.  
  3890. typedef struct _IMAGE_TLS_DIRECTORY {
  3891.     DWORD   StartAddressOfRawData;
  3892.     DWORD   EndAddressOfRawData;
  3893.     PDWORD  AddressOfIndex;
  3894.     PIMAGE_TLS_CALLBACK *AddressOfCallBacks;
  3895.     DWORD   SizeOfZeroFill;
  3896.     DWORD   Characteristics;
  3897. } IMAGE_TLS_DIRECTORY, *PIMAGE_TLS_DIRECTORY;
  3898.  
  3899.  
  3900. //
  3901. // Resource Format.
  3902. //
  3903.  
  3904. //
  3905. // Resource directory consists of two counts, following by a variable length
  3906. // array of directory entries.  The first count is the number of entries at
  3907. // beginning of the array that have actual names associated with each entry.
  3908. // The entries are in ascending order, case insensitive strings.  The second
  3909. // count is the number of entries that immediately follow the named entries.
  3910. // This second count identifies the number of entries that have 16-bit integer
  3911. // Ids as their name.  These entries are also sorted in ascending order.
  3912. //
  3913. // This structure allows fast lookup by either name or number, but for any
  3914. // given resource entry only one form of lookup is supported, not both.
  3915. // This is consistant with the syntax of the .RC file and the .RES file.
  3916. //
  3917.  
  3918. typedef struct _IMAGE_RESOURCE_DIRECTORY {
  3919.     DWORD   Characteristics;
  3920.     DWORD   TimeDateStamp;
  3921.     WORD    MajorVersion;
  3922.     WORD    MinorVersion;
  3923.     WORD    NumberOfNamedEntries;
  3924.     WORD    NumberOfIdEntries;
  3925. //  IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[];
  3926. } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
  3927.  
  3928. #define IMAGE_RESOURCE_NAME_IS_STRING        0x80000000
  3929. #define IMAGE_RESOURCE_DATA_IS_DIRECTORY     0x80000000
  3930.  
  3931. //
  3932. // Each directory contains the 32-bit Name of the entry and an offset,
  3933. // relative to the beginning of the resource directory of the data associated
  3934. // with this directory entry.  If the name of the entry is an actual text
  3935. // string instead of an integer Id, then the high order bit of the name field
  3936. // is set to one and the low order 31-bits are an offset, relative to the
  3937. // beginning of the resource directory of the string, which is of type
  3938. // IMAGE_RESOURCE_DIRECTORY_STRING.  Otherwise the high bit is clear and the
  3939. // low-order 16-bits are the integer Id that identify this resource directory
  3940. // entry. If the directory entry is yet another resource directory (i.e. a
  3941. // subdirectory), then the high order bit of the offset field will be
  3942. // set to indicate this.  Otherwise the high bit is clear and the offset
  3943. // field points to a resource data entry.
  3944. //
  3945.  
  3946. typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
  3947.     union {
  3948.         struct {
  3949.             DWORD NameOffset:31;
  3950.             DWORD NameIsString:1;
  3951.         };
  3952.         DWORD   Name;
  3953.         WORD    Id;
  3954.     };
  3955.     union {
  3956.         DWORD   OffsetToData;
  3957.         struct {
  3958.             DWORD   OffsetToDirectory:31;
  3959.             DWORD   DataIsDirectory:1;
  3960.         };
  3961.     };
  3962. } IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
  3963.  
  3964. //
  3965. // For resource directory entries that have actual string names, the Name
  3966. // field of the directory entry points to an object of the following type.
  3967. // All of these string objects are stored together after the last resource
  3968. // directory entry and before the first resource data object.  This minimizes
  3969. // the impact of these variable length objects on the alignment of the fixed
  3970. // size directory entry objects.
  3971. //
  3972.  
  3973. typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
  3974.     WORD    Length;
  3975.     CHAR    NameString[ 1 ];
  3976. } IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
  3977.  
  3978.  
  3979. typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
  3980.     WORD    Length;
  3981.     WCHAR   NameString[ 1 ];
  3982. } IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
  3983.  
  3984.  
  3985. //
  3986. // Each resource data entry describes a leaf node in the resource directory
  3987. // tree.  It contains an offset, relative to the beginning of the resource
  3988. // directory of the data for the resource, a size field that gives the number
  3989. // of bytes of data at that offset, a CodePage that should be used when
  3990. // decoding code point values within the resource data.  Typically for new
  3991. // applications the code page would be the unicode code page.
  3992. //
  3993.  
  3994. typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
  3995.     DWORD   OffsetToData;
  3996.     DWORD   Size;
  3997.     DWORD   CodePage;
  3998.     DWORD   Reserved;
  3999. } IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
  4000.  
  4001. //
  4002. // Load Configuration Directory Entry
  4003. //
  4004.  
  4005. typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
  4006.     DWORD   Characteristics;
  4007.     DWORD   TimeDateStamp;
  4008.     WORD    MajorVersion;
  4009.     WORD    MinorVersion;
  4010.     DWORD   GlobalFlagsClear;
  4011.     DWORD   GlobalFlagsSet;
  4012.     DWORD   CriticalSectionDefaultTimeout;
  4013.     DWORD   DeCommitFreeBlockThreshold;
  4014.     DWORD   DeCommitTotalFreeThreshold;
  4015.     PVOID   LockPrefixTable;
  4016.     DWORD   MaximumAllocationSize;
  4017.     DWORD   VirtualMemoryThreshold;
  4018.     DWORD   ProcessHeapFlags;
  4019.     DWORD   Reserved[ 4 ];
  4020. } IMAGE_LOAD_CONFIG_DIRECTORY, *PIMAGE_LOAD_CONFIG_DIRECTORY;
  4021.  
  4022.  
  4023. //
  4024. // Function table entry format for MIPS/ALPHA images.  Function table is
  4025. // pointed to by the IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
  4026. // This definition duplicates ones in ntmips.h and ntalpha.h for use
  4027. // by portable image file mungers.
  4028. //
  4029.  
  4030. typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY {
  4031.     DWORD BeginAddress;
  4032.     DWORD EndAddress;
  4033.     PVOID ExceptionHandler;
  4034.     PVOID HandlerData;
  4035.     DWORD PrologEndAddress;
  4036. } IMAGE_RUNTIME_FUNCTION_ENTRY, *PIMAGE_RUNTIME_FUNCTION_ENTRY;
  4037.  
  4038. //
  4039. // Debug Format
  4040. //
  4041.  
  4042. typedef struct _IMAGE_DEBUG_DIRECTORY {
  4043.     DWORD   Characteristics;
  4044.     DWORD   TimeDateStamp;
  4045.     WORD    MajorVersion;
  4046.     WORD    MinorVersion;
  4047.     DWORD   Type;
  4048.     DWORD   SizeOfData;
  4049.     DWORD   AddressOfRawData;
  4050.     DWORD   PointerToRawData;
  4051. } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
  4052.  
  4053. #define IMAGE_DEBUG_TYPE_UNKNOWN          0
  4054. #define IMAGE_DEBUG_TYPE_COFF             1
  4055. #define IMAGE_DEBUG_TYPE_CODEVIEW         2
  4056. #define IMAGE_DEBUG_TYPE_FPO              3
  4057. #define IMAGE_DEBUG_TYPE_MISC             4
  4058. #define IMAGE_DEBUG_TYPE_EXCEPTION        5
  4059. #define IMAGE_DEBUG_TYPE_FIXUP            6
  4060. #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC      7
  4061. #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC    8
  4062.  
  4063. typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
  4064.     DWORD   NumberOfSymbols;
  4065.     DWORD   LvaToFirstSymbol;
  4066.     DWORD   NumberOfLinenumbers;
  4067.     DWORD   LvaToFirstLinenumber;
  4068.     DWORD   RvaToFirstByteOfCode;
  4069.     DWORD   RvaToLastByteOfCode;
  4070.     DWORD   RvaToFirstByteOfData;
  4071.     DWORD   RvaToLastByteOfData;
  4072. } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
  4073.  
  4074. #define FRAME_FPO       0
  4075. #define FRAME_TRAP      1
  4076. #define FRAME_TSS       2
  4077. #define FRAME_NONFPO    3
  4078.  
  4079. typedef struct _FPO_DATA {
  4080.     DWORD       ulOffStart;             // offset 1st byte of function code
  4081.     DWORD       cbProcSize;             // # bytes in function
  4082.     DWORD       cdwLocals;              // # bytes in locals/4
  4083.     WORD        cdwParams;              // # bytes in params/4
  4084.     WORD        cbProlog : 8;           // # bytes in prolog
  4085.     WORD        cbRegs   : 3;           // # regs saved
  4086.     WORD        fHasSEH  : 1;           // TRUE if SEH in func
  4087.     WORD        fUseBP   : 1;           // TRUE if EBP has been allocated
  4088.     WORD        reserved : 1;           // reserved for future use
  4089.     WORD        cbFrame  : 2;           // frame type
  4090. } FPO_DATA, *PFPO_DATA;
  4091. #define SIZEOF_RFPO_DATA 16
  4092.  
  4093.  
  4094. #define IMAGE_DEBUG_MISC_EXENAME    1
  4095.  
  4096. typedef struct _IMAGE_DEBUG_MISC {
  4097.     DWORD       DataType;               // type of misc data, see defines
  4098.     DWORD       Length;                 // total length of record, rounded to four
  4099.                                         // byte multiple.
  4100.     BOOLEAN     Unicode;                // TRUE if data is unicode string
  4101.     BYTE        Reserved[ 3 ];
  4102.     BYTE        Data[ 1 ];              // Actual data
  4103. } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
  4104.  
  4105.  
  4106. //
  4107. // Function table extracted from MIPS/ALPHA images.  Does not contain
  4108. // information needed only for runtime support.  Just those fields for
  4109. // each entry needed by a debugger.
  4110. //
  4111.  
  4112. typedef struct _IMAGE_FUNCTION_ENTRY {
  4113.     DWORD   StartingAddress;
  4114.     DWORD   EndingAddress;
  4115.     DWORD   EndOfPrologue;
  4116. } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
  4117.  
  4118. //
  4119. // Debugging information can be stripped from an image file and placed
  4120. // in a separate .DBG file, whose file name part is the same as the
  4121. // image file name part (e.g. symbols for CMD.EXE could be stripped
  4122. // and placed in CMD.DBG).  This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
  4123. // flag in the Characteristics field of the file header.  The beginning of
  4124. // the .DBG file contains the following structure which captures certain
  4125. // information from the image file.  This allows a debug to proceed even if
  4126. // the original image file is not accessable.  This header is followed by
  4127. // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
  4128. // IMAGE_DEBUG_DIRECTORY structures.  The latter structures and those in
  4129. // the image file contain file offsets relative to the beginning of the
  4130. // .DBG file.
  4131. //
  4132. // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
  4133. // is left in the image file, but not mapped.  This allows a debugger to
  4134. // compute the name of the .DBG file, from the name of the image in the
  4135. // IMAGE_DEBUG_MISC structure.
  4136. //
  4137.  
  4138. typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
  4139.     WORD        Signature;
  4140.     WORD        Flags;
  4141.     WORD        Machine;
  4142.     WORD        Characteristics;
  4143.     DWORD       TimeDateStamp;
  4144.     DWORD       CheckSum;
  4145.     DWORD       ImageBase;
  4146.     DWORD       SizeOfImage;
  4147.     DWORD       NumberOfSections;
  4148.     DWORD       ExportedNamesSize;
  4149.     DWORD       DebugDirectorySize;
  4150.     DWORD       Reserved[ 3 ];          // Note: reserved[0] is actually the section alignment
  4151. } IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
  4152.  
  4153. #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
  4154.  
  4155. #include "poppack.h"
  4156.  
  4157. //
  4158. // End Image Format
  4159. //
  4160.  
  4161. //
  4162. // for move macros
  4163. //
  4164. #include <string.h>
  4165. #define HEAP_NO_SERIALIZE               0x00000001      
  4166. #define HEAP_GROWABLE                   0x00000002      
  4167. #define HEAP_GENERATE_EXCEPTIONS        0x00000004      
  4168. #define HEAP_ZERO_MEMORY                0x00000008      
  4169. #define HEAP_REALLOC_IN_PLACE_ONLY      0x00000010      
  4170. #define HEAP_TAIL_CHECKING_ENABLED      0x00000020      
  4171. #define HEAP_FREE_CHECKING_ENABLED      0x00000040      
  4172. #define HEAP_DISABLE_COALESCE_ON_FREE   0x00000080      
  4173. #define HEAP_CREATE_ALIGN_16            0x00010000      
  4174. #define HEAP_CREATE_ENABLE_TRACING      0x00020000      
  4175. #define HEAP_MAXIMUM_TAG                0x0FFF              
  4176. #define HEAP_PSEUDO_TAG_FLAG            0x8000              
  4177. #define HEAP_TAG_SHIFT                  16                  
  4178. #define HEAP_MAKE_TAG_FLAGS( b, o ) ((DWORD)((b) + ((o) << 16)))  
  4179.  
  4180. #define IS_TEXT_UNICODE_ASCII16               0x0001
  4181. #define IS_TEXT_UNICODE_REVERSE_ASCII16       0x0010
  4182.  
  4183. #define IS_TEXT_UNICODE_STATISTICS            0x0002
  4184. #define IS_TEXT_UNICODE_REVERSE_STATISTICS    0x0020
  4185.  
  4186. #define IS_TEXT_UNICODE_CONTROLS              0x0004
  4187. #define IS_TEXT_UNICODE_REVERSE_CONTROLS      0x0040
  4188.  
  4189. #define IS_TEXT_UNICODE_SIGNATURE             0x0008
  4190. #define IS_TEXT_UNICODE_REVERSE_SIGNATURE     0x0080
  4191.  
  4192. #define IS_TEXT_UNICODE_ILLEGAL_CHARS         0x0100
  4193. #define IS_TEXT_UNICODE_ODD_LENGTH            0x0200
  4194. #define IS_TEXT_UNICODE_DBCS_LEADBYTE         0x0400
  4195. #define IS_TEXT_UNICODE_NULL_BYTES            0x1000
  4196.  
  4197. #define IS_TEXT_UNICODE_UNICODE_MASK          0x000F
  4198. #define IS_TEXT_UNICODE_REVERSE_MASK          0x00F0
  4199. #define IS_TEXT_UNICODE_NOT_UNICODE_MASK      0x0F00
  4200. #define IS_TEXT_UNICODE_NOT_ASCII_MASK        0xF000
  4201.  
  4202. #define COMPRESSION_FORMAT_NONE          (0x0000)   
  4203. #define COMPRESSION_FORMAT_DEFAULT       (0x0001)   
  4204. #define COMPRESSION_FORMAT_LZNT1         (0x0002)   
  4205. #define COMPRESSION_ENGINE_STANDARD      (0x0000)   
  4206. #define COMPRESSION_ENGINE_MAXIMUM       (0x0100)   
  4207. #if defined(_M_IX86) || defined(_M_MRX000) || defined(_M_ALPHA)
  4208. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  4209. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  4210. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  4211. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  4212. #else
  4213.  
  4214. NTSYSAPI
  4215. VOID
  4216. NTAPI
  4217. RtlCopyMemory (
  4218.    VOID UNALIGNED *Destination,
  4219.    CONST VOID UNALIGNED *Source,
  4220.    DWORD Length
  4221.    );
  4222.  
  4223. NTSYSAPI
  4224. VOID
  4225. NTAPI
  4226. RtlMoveMemory (
  4227.    VOID UNALIGNED *Destination,
  4228.    CONST VOID UNALIGNED *Source,
  4229.    DWORD Length
  4230.    );
  4231.  
  4232. NTSYSAPI
  4233. VOID
  4234. NTAPI
  4235. RtlFillMemory (
  4236.    VOID UNALIGNED *Destination,
  4237.    DWORD Length,
  4238.    BYTE  Fill
  4239.    );
  4240.  
  4241. NTSYSAPI
  4242. VOID
  4243. NTAPI
  4244. RtlZeroMemory (
  4245.    VOID UNALIGNED *Destination,
  4246.    DWORD Length
  4247.    );
  4248. #endif
  4249.  
  4250. typedef struct _MESSAGE_RESOURCE_ENTRY {
  4251.     WORD   Length;
  4252.     WORD   Flags;
  4253.     BYTE  Text[ 1 ];
  4254. } MESSAGE_RESOURCE_ENTRY, *PMESSAGE_RESOURCE_ENTRY;
  4255.  
  4256. #define MESSAGE_RESOURCE_UNICODE 0x0001
  4257.  
  4258. typedef struct _MESSAGE_RESOURCE_BLOCK {
  4259.     DWORD LowId;
  4260.     DWORD HighId;
  4261.     DWORD OffsetToEntries;
  4262. } MESSAGE_RESOURCE_BLOCK, *PMESSAGE_RESOURCE_BLOCK;
  4263.  
  4264. typedef struct _MESSAGE_RESOURCE_DATA {
  4265.     DWORD NumberOfBlocks;
  4266.     MESSAGE_RESOURCE_BLOCK Blocks[ 1 ];
  4267. } MESSAGE_RESOURCE_DATA, *PMESSAGE_RESOURCE_DATA;
  4268.  
  4269.  
  4270. typedef struct _RTL_CRITICAL_SECTION_DEBUG {
  4271.     WORD   Type;
  4272.     WORD   CreatorBackTraceIndex;
  4273.     struct _RTL_CRITICAL_SECTION *CriticalSection;
  4274.     LIST_ENTRY ProcessLocksList;
  4275.     DWORD EntryCount;
  4276.     DWORD ContentionCount;
  4277.     DWORD Spare[ 2 ];
  4278. } RTL_CRITICAL_SECTION_DEBUG, *PRTL_CRITICAL_SECTION_DEBUG;
  4279.  
  4280. #define RTL_CRITSECT_TYPE 0
  4281. #define RTL_RESOURCE_TYPE 1
  4282.  
  4283. typedef struct _RTL_CRITICAL_SECTION {
  4284.     PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
  4285.  
  4286.     //
  4287.     //  The following three fields control entering and exiting the critical
  4288.     //  section for the resource
  4289.     //
  4290.  
  4291.     LONG LockCount;
  4292.     LONG RecursionCount;
  4293.     HANDLE OwningThread;        // from the thread's ClientId->UniqueThread
  4294.     HANDLE LockSemaphore;
  4295.     DWORD Reserved;
  4296. } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
  4297. #define DLL_PROCESS_ATTACH 1    
  4298. #define DLL_THREAD_ATTACH  2    
  4299. #define DLL_THREAD_DETACH  3    
  4300. #define DLL_PROCESS_DETACH 0    
  4301.  
  4302. //
  4303. // Defines for the READ flags for Eventlogging
  4304. //
  4305. #define EVENTLOG_SEQUENTIAL_READ        0X0001
  4306. #define EVENTLOG_SEEK_READ              0X0002
  4307. #define EVENTLOG_FORWARDS_READ          0X0004
  4308. #define EVENTLOG_BACKWARDS_READ         0X0008
  4309.  
  4310. //
  4311. // The types of events that can be logged.
  4312. //
  4313. #define EVENTLOG_SUCCESS                0X0000
  4314. #define EVENTLOG_ERROR_TYPE             0x0001
  4315. #define EVENTLOG_WARNING_TYPE           0x0002
  4316. #define EVENTLOG_INFORMATION_TYPE       0x0004
  4317. #define EVENTLOG_AUDIT_SUCCESS          0x0008
  4318. #define EVENTLOG_AUDIT_FAILURE          0x0010
  4319.  
  4320. //
  4321. // Defines for the WRITE flags used by Auditing for paired events
  4322. // These are not implemented in Product 1
  4323. //
  4324.  
  4325. #define EVENTLOG_START_PAIRED_EVENT    0x0001
  4326. #define EVENTLOG_END_PAIRED_EVENT      0x0002
  4327. #define EVENTLOG_END_ALL_PAIRED_EVENTS 0x0004
  4328. #define EVENTLOG_PAIRED_EVENT_ACTIVE   0x0008
  4329. #define EVENTLOG_PAIRED_EVENT_INACTIVE 0x0010
  4330.  
  4331. //
  4332. // Structure that defines the header of the Eventlog record. This is the
  4333. // fixed-sized portion before all the variable-length strings, binary
  4334. // data and pad bytes.
  4335. //
  4336. // TimeGenerated is the time it was generated at the client.
  4337. // TimeWritten is the time it was put into the log at the server end.
  4338. //
  4339.  
  4340. typedef struct _EVENTLOGRECORD {
  4341.     DWORD  Length;        // Length of full record
  4342.     DWORD  Reserved;      // Used by the service
  4343.     DWORD  RecordNumber;  // Absolute record number
  4344.     DWORD  TimeGenerated; // Seconds since 1-1-1970
  4345.     DWORD  TimeWritten;   // Seconds since 1-1-1970
  4346.     DWORD  EventID;
  4347.     WORD   EventType;
  4348.     WORD   NumStrings;
  4349.     WORD   EventCategory;
  4350.     WORD   ReservedFlags; // For use with paired events (auditing)
  4351.     DWORD  ClosingRecordNumber; // For use with paired events (auditing)
  4352.     DWORD  StringOffset;  // Offset from beginning of record
  4353.     DWORD  UserSidLength;
  4354.     DWORD  UserSidOffset;
  4355.     DWORD  DataLength;
  4356.     DWORD  DataOffset;    // Offset from beginning of record
  4357.     //
  4358.     // Then follow:
  4359.     //
  4360.     // WCHAR SourceName[]
  4361.     // WCHAR Computername[]
  4362.     // SID   UserSid
  4363.     // WCHAR Strings[]
  4364.     // BYTE  Data[]
  4365.     // CHAR  Pad[]
  4366.     // DWORD Length;
  4367.     //
  4368. } EVENTLOGRECORD, *PEVENTLOGRECORD;
  4369.  
  4370. #define DBG_CONTINUE                    ((DWORD   )0x00010002L) 
  4371. #define DBG_TERMINATE_THREAD            ((DWORD   )0x40010003L) 
  4372. #define DBG_TERMINATE_PROCESS           ((DWORD   )0x40010004L) 
  4373. #define DBG_CONTROL_C                   ((DWORD   )0x40010005L) 
  4374. #define DBG_CONTROL_BREAK               ((DWORD   )0x40010008L) 
  4375. #define DBG_EXCEPTION_NOT_HANDLED       ((DWORD   )0x80010001L) 
  4376. //
  4377.  
  4378. // begin_ntddk begin_nthal
  4379. //
  4380. // Registry Specific Access Rights.
  4381. //
  4382.  
  4383. #define KEY_QUERY_VALUE         (0x0001)
  4384. #define KEY_SET_VALUE           (0x0002)
  4385. #define KEY_CREATE_SUB_KEY      (0x0004)
  4386. #define KEY_ENUMERATE_SUB_KEYS  (0x0008)
  4387. #define KEY_NOTIFY              (0x0010)
  4388. #define KEY_CREATE_LINK         (0x0020)
  4389.  
  4390. #define KEY_READ                ((STANDARD_RIGHTS_READ       |\
  4391.                                   KEY_QUERY_VALUE            |\
  4392.                                   KEY_ENUMERATE_SUB_KEYS     |\
  4393.                                   KEY_NOTIFY)                 \
  4394.                                   &                           \
  4395.                                  (~SYNCHRONIZE))
  4396.  
  4397.  
  4398. #define KEY_WRITE               ((STANDARD_RIGHTS_WRITE      |\
  4399.                                   KEY_SET_VALUE              |\
  4400.                                   KEY_CREATE_SUB_KEY)         \
  4401.                                   &                           \
  4402.                                  (~SYNCHRONIZE))
  4403.  
  4404. #define KEY_EXECUTE             ((KEY_READ)                   \
  4405.                                   &                           \
  4406.                                  (~SYNCHRONIZE))
  4407.  
  4408. #define KEY_ALL_ACCESS          ((STANDARD_RIGHTS_ALL        |\
  4409.                                   KEY_QUERY_VALUE            |\
  4410.                                   KEY_SET_VALUE              |\
  4411.                                   KEY_CREATE_SUB_KEY         |\
  4412.                                   KEY_ENUMERATE_SUB_KEYS     |\
  4413.                                   KEY_NOTIFY                 |\
  4414.                                   KEY_CREATE_LINK)            \
  4415.                                   &                           \
  4416.                                  (~SYNCHRONIZE))
  4417.  
  4418. //
  4419. // Open/Create Options
  4420. //
  4421.  
  4422. #define REG_OPTION_RESERVED         (0x00000000L)   // Parameter is reserved
  4423.  
  4424. #define REG_OPTION_NON_VOLATILE     (0x00000000L)   // Key is preserved
  4425.                                                     // when system is rebooted
  4426.  
  4427. #define REG_OPTION_VOLATILE         (0x00000001L)   // Key is not preserved
  4428.                                                     // when system is rebooted
  4429.  
  4430. #define REG_OPTION_CREATE_LINK      (0x00000002L)   // Created key is a
  4431.                                                     // symbolic link
  4432.  
  4433. #define REG_OPTION_BACKUP_RESTORE   (0x00000004L)   // open for backup or restore
  4434.                                                     // special access rules
  4435.                                                     // privilege required
  4436.  
  4437. #define REG_LEGAL_OPTION            \
  4438.                 (REG_OPTION_RESERVED            |\
  4439.                  REG_OPTION_NON_VOLATILE        |\
  4440.                  REG_OPTION_VOLATILE            |\
  4441.                  REG_OPTION_CREATE_LINK         |\
  4442.                  REG_OPTION_BACKUP_RESTORE)
  4443.  
  4444. //
  4445. // Key creation/open disposition
  4446. //
  4447.  
  4448. #define REG_CREATED_NEW_KEY         (0x00000001L)   // New Registry Key created
  4449. #define REG_OPENED_EXISTING_KEY     (0x00000002L)   // Existing Key opened
  4450.  
  4451. //
  4452. // Key restore flags
  4453. //
  4454.  
  4455. #define REG_WHOLE_HIVE_VOLATILE     (0x00000001L)   // Restore whole hive volatile
  4456. #define REG_REFRESH_HIVE            (0x00000002L)   // Unwind changes to last flush
  4457.  
  4458. // end_ntddk end_nthal
  4459.  
  4460. //
  4461. // Notify filter values
  4462. //
  4463. #define REG_NOTIFY_CHANGE_NAME          (0x00000001L) // Create or delete (child)
  4464. #define REG_NOTIFY_CHANGE_ATTRIBUTES    (0x00000002L)
  4465. #define REG_NOTIFY_CHANGE_LAST_SET      (0x00000004L) // time stamp
  4466. #define REG_NOTIFY_CHANGE_SECURITY      (0x00000008L)
  4467.  
  4468. #define REG_LEGAL_CHANGE_FILTER                 \
  4469.                 (REG_NOTIFY_CHANGE_NAME          |\
  4470.                  REG_NOTIFY_CHANGE_ATTRIBUTES    |\
  4471.                  REG_NOTIFY_CHANGE_LAST_SET      |\
  4472.                  REG_NOTIFY_CHANGE_SECURITY)
  4473.  
  4474. //
  4475. //
  4476. // Predefined Value Types.
  4477. //
  4478.  
  4479. #define REG_NONE                    ( 0 )   // No value type
  4480. #define REG_SZ                      ( 1 )   // Unicode nul terminated string
  4481. #define REG_EXPAND_SZ               ( 2 )   // Unicode nul terminated string
  4482.                                             // (with environment variable references)
  4483. #define REG_BINARY                  ( 3 )   // Free form binary
  4484. #define REG_DWORD                   ( 4 )   // 32-bit number
  4485. #define REG_DWORD_LITTLE_ENDIAN     ( 4 )   // 32-bit number (same as REG_DWORD)
  4486. #define REG_DWORD_BIG_ENDIAN        ( 5 )   // 32-bit number
  4487. #define REG_LINK                    ( 6 )   // Symbolic Link (unicode)
  4488. #define REG_MULTI_SZ                ( 7 )   // Multiple Unicode strings
  4489. #define REG_RESOURCE_LIST           ( 8 )   // Resource list in the resource map
  4490. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 )  // Resource list in the hardware description
  4491. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  4492.  
  4493. // end_ntddk end_nthal
  4494.  
  4495. // begin_ntddk begin_nthal
  4496. //
  4497. // Service Types (Bit Mask)
  4498. //
  4499. #define SERVICE_KERNEL_DRIVER          0x00000001
  4500. #define SERVICE_FILE_SYSTEM_DRIVER     0x00000002
  4501. #define SERVICE_ADAPTER                0x00000004
  4502. #define SERVICE_RECOGNIZER_DRIVER      0x00000008
  4503.  
  4504. #define SERVICE_DRIVER                 (SERVICE_KERNEL_DRIVER | \
  4505.                                         SERVICE_FILE_SYSTEM_DRIVER | \
  4506.                                         SERVICE_RECOGNIZER_DRIVER)
  4507.  
  4508. #define SERVICE_WIN32_OWN_PROCESS      0x00000010
  4509. #define SERVICE_WIN32_SHARE_PROCESS    0x00000020
  4510. #define SERVICE_WIN32                  (SERVICE_WIN32_OWN_PROCESS | \
  4511.                                         SERVICE_WIN32_SHARE_PROCESS)
  4512.  
  4513. #define SERVICE_INTERACTIVE_PROCESS    0x00000100
  4514.  
  4515. #define SERVICE_TYPE_ALL               (SERVICE_WIN32  | \
  4516.                                         SERVICE_ADAPTER | \
  4517.                                         SERVICE_DRIVER  | \
  4518.                                         SERVICE_INTERACTIVE_PROCESS)
  4519.  
  4520. //
  4521. // Start Type
  4522. //
  4523.  
  4524. #define SERVICE_BOOT_START             0x00000000
  4525. #define SERVICE_SYSTEM_START           0x00000001
  4526. #define SERVICE_AUTO_START             0x00000002
  4527. #define SERVICE_DEMAND_START           0x00000003
  4528. #define SERVICE_DISABLED               0x00000004
  4529.  
  4530. //
  4531. // Error control type
  4532. //
  4533. #define SERVICE_ERROR_IGNORE           0x00000000
  4534. #define SERVICE_ERROR_NORMAL           0x00000001
  4535. #define SERVICE_ERROR_SEVERE           0x00000002
  4536. #define SERVICE_ERROR_CRITICAL         0x00000003
  4537.  
  4538. //
  4539. //
  4540. // Define the registry driver node enumerations
  4541. //
  4542.  
  4543. typedef enum _CM_SERVICE_NODE_TYPE {
  4544.     DriverType               = SERVICE_KERNEL_DRIVER,
  4545.     FileSystemType           = SERVICE_FILE_SYSTEM_DRIVER,
  4546.     Win32ServiceOwnProcess   = SERVICE_WIN32_OWN_PROCESS,
  4547.     Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  4548.     AdapterType              = SERVICE_ADAPTER,
  4549.     RecognizerType           = SERVICE_RECOGNIZER_DRIVER
  4550. } SERVICE_NODE_TYPE;
  4551.  
  4552. typedef enum _CM_SERVICE_LOAD_TYPE {
  4553.     BootLoad    = SERVICE_BOOT_START,
  4554.     SystemLoad  = SERVICE_SYSTEM_START,
  4555.     AutoLoad    = SERVICE_AUTO_START,
  4556.     DemandLoad  = SERVICE_DEMAND_START,
  4557.     DisableLoad = SERVICE_DISABLED
  4558. } SERVICE_LOAD_TYPE;
  4559.  
  4560. typedef enum _CM_ERROR_CONTROL_TYPE {
  4561.     IgnoreError   = SERVICE_ERROR_IGNORE,
  4562.     NormalError   = SERVICE_ERROR_NORMAL,
  4563.     SevereError   = SERVICE_ERROR_SEVERE,
  4564.     CriticalError = SERVICE_ERROR_CRITICAL
  4565. } SERVICE_ERROR_TYPE;
  4566.  
  4567.  
  4568. //
  4569. // IOCTL_TAPE_ERASE definitions
  4570. //
  4571.  
  4572. #define TAPE_ERASE_SHORT            0L
  4573. #define TAPE_ERASE_LONG             1L
  4574.  
  4575. typedef struct _TAPE_ERASE {
  4576.     DWORD Type;
  4577.     BOOLEAN Immediate;
  4578. } TAPE_ERASE, *PTAPE_ERASE;
  4579.  
  4580. //
  4581. // IOCTL_TAPE_PREPARE definitions
  4582. //
  4583.  
  4584. #define TAPE_LOAD                   0L
  4585. #define TAPE_UNLOAD                 1L
  4586. #define TAPE_TENSION                2L
  4587. #define TAPE_LOCK                   3L
  4588. #define TAPE_UNLOCK                 4L
  4589. #define TAPE_FORMAT                 5L
  4590.  
  4591. typedef struct _TAPE_PREPARE {
  4592.     DWORD Operation;
  4593.     BOOLEAN Immediate;
  4594. } TAPE_PREPARE, *PTAPE_PREPARE;
  4595.  
  4596. //
  4597. // IOCTL_TAPE_WRITE_MARKS definitions
  4598. //
  4599.  
  4600. #define TAPE_SETMARKS               0L
  4601. #define TAPE_FILEMARKS              1L
  4602. #define TAPE_SHORT_FILEMARKS        2L
  4603. #define TAPE_LONG_FILEMARKS         3L
  4604.  
  4605. typedef struct _TAPE_WRITE_MARKS {
  4606.     DWORD Type;
  4607.     DWORD Count;
  4608.     BOOLEAN Immediate;
  4609. } TAPE_WRITE_MARKS, *PTAPE_WRITE_MARKS;
  4610.  
  4611. //
  4612. // IOCTL_TAPE_GET_POSITION definitions
  4613. //
  4614.  
  4615. #define TAPE_ABSOLUTE_POSITION       0L
  4616. #define TAPE_LOGICAL_POSITION        1L
  4617. #define TAPE_PSEUDO_LOGICAL_POSITION 2L
  4618.  
  4619. typedef struct _TAPE_GET_POSITION {
  4620.     DWORD Type;
  4621.     DWORD Partition;
  4622.     LARGE_INTEGER Offset;
  4623. } TAPE_GET_POSITION, *PTAPE_GET_POSITION;
  4624.  
  4625. //
  4626. // IOCTL_TAPE_SET_POSITION definitions
  4627. //
  4628.  
  4629. #define TAPE_REWIND                 0L
  4630. #define TAPE_ABSOLUTE_BLOCK         1L
  4631. #define TAPE_LOGICAL_BLOCK          2L
  4632. #define TAPE_PSEUDO_LOGICAL_BLOCK   3L
  4633. #define TAPE_SPACE_END_OF_DATA      4L
  4634. #define TAPE_SPACE_RELATIVE_BLOCKS  5L
  4635. #define TAPE_SPACE_FILEMARKS        6L
  4636. #define TAPE_SPACE_SEQUENTIAL_FMKS  7L
  4637. #define TAPE_SPACE_SETMARKS         8L
  4638. #define TAPE_SPACE_SEQUENTIAL_SMKS  9L
  4639.  
  4640. typedef struct _TAPE_SET_POSITION {
  4641.     DWORD Method;
  4642.     DWORD Partition;
  4643.     LARGE_INTEGER Offset;
  4644.     BOOLEAN Immediate;
  4645. } TAPE_SET_POSITION, *PTAPE_SET_POSITION;
  4646.  
  4647. //
  4648. // IOCTL_TAPE_GET_DRIVE_PARAMS definitions
  4649. //
  4650.  
  4651. //
  4652. // Definitions for FeaturesLow parameter
  4653. //
  4654.  
  4655. #define TAPE_DRIVE_FIXED            0x00000001
  4656. #define TAPE_DRIVE_SELECT           0x00000002
  4657. #define TAPE_DRIVE_INITIATOR        0x00000004
  4658.  
  4659. #define TAPE_DRIVE_ERASE_SHORT      0x00000010
  4660. #define TAPE_DRIVE_ERASE_LONG       0x00000020
  4661. #define TAPE_DRIVE_ERASE_BOP_ONLY   0x00000040
  4662. #define TAPE_DRIVE_ERASE_IMMEDIATE  0x00000080
  4663.  
  4664. #define TAPE_DRIVE_TAPE_CAPACITY    0x00000100
  4665. #define TAPE_DRIVE_TAPE_REMAINING   0x00000200
  4666. #define TAPE_DRIVE_FIXED_BLOCK      0x00000400
  4667. #define TAPE_DRIVE_VARIABLE_BLOCK   0x00000800
  4668.  
  4669. #define TAPE_DRIVE_WRITE_PROTECT    0x00001000
  4670. #define TAPE_DRIVE_EOT_WZ_SIZE      0x00002000
  4671.  
  4672. #define TAPE_DRIVE_ECC              0x00010000
  4673. #define TAPE_DRIVE_COMPRESSION      0x00020000
  4674. #define TAPE_DRIVE_PADDING          0x00040000
  4675. #define TAPE_DRIVE_REPORT_SMKS      0x00080000
  4676.  
  4677. #define TAPE_DRIVE_GET_ABSOLUTE_BLK 0x00100000
  4678. #define TAPE_DRIVE_GET_LOGICAL_BLK  0x00200000
  4679. #define TAPE_DRIVE_SET_EOT_WZ_SIZE  0x00400000
  4680.  
  4681. #define TAPE_DRIVE_RESERVED_BIT     0x80000000  //don't use this bit!
  4682. //                                              //can't be a low features bit!
  4683. //                                              //reserved; high features only
  4684.  
  4685. //
  4686. // Definitions for FeaturesHigh parameter
  4687. //
  4688.  
  4689. #define TAPE_DRIVE_LOAD_UNLOAD      0x80000001
  4690. #define TAPE_DRIVE_TENSION          0x80000002
  4691. #define TAPE_DRIVE_LOCK_UNLOCK      0x80000004
  4692. #define TAPE_DRIVE_REWIND_IMMEDIATE 0x80000008
  4693.  
  4694. #define TAPE_DRIVE_SET_BLOCK_SIZE   0x80000010
  4695. #define TAPE_DRIVE_LOAD_UNLD_IMMED  0x80000020
  4696. #define TAPE_DRIVE_TENSION_IMMED    0x80000040
  4697. #define TAPE_DRIVE_LOCK_UNLK_IMMED  0x80000080
  4698.  
  4699. #define TAPE_DRIVE_SET_ECC          0x80000100
  4700. #define TAPE_DRIVE_SET_COMPRESSION  0x80000200
  4701. #define TAPE_DRIVE_SET_PADDING      0x80000400
  4702. #define TAPE_DRIVE_SET_REPORT_SMKS  0x80000800
  4703.  
  4704. #define TAPE_DRIVE_ABSOLUTE_BLK     0x80001000
  4705. #define TAPE_DRIVE_ABS_BLK_IMMED    0x80002000
  4706. #define TAPE_DRIVE_LOGICAL_BLK      0x80004000
  4707. #define TAPE_DRIVE_LOG_BLK_IMMED    0x80008000
  4708.  
  4709. #define TAPE_DRIVE_END_OF_DATA      0x80010000
  4710. #define TAPE_DRIVE_RELATIVE_BLKS    0x80020000
  4711. #define TAPE_DRIVE_FILEMARKS        0x80040000
  4712. #define TAPE_DRIVE_SEQUENTIAL_FMKS  0x80080000
  4713.  
  4714. #define TAPE_DRIVE_SETMARKS         0x80100000
  4715. #define TAPE_DRIVE_SEQUENTIAL_SMKS  0x80200000
  4716. #define TAPE_DRIVE_REVERSE_POSITION 0x80400000
  4717. #define TAPE_DRIVE_SPACE_IMMEDIATE  0x80800000
  4718.  
  4719. #define TAPE_DRIVE_WRITE_SETMARKS   0x81000000
  4720. #define TAPE_DRIVE_WRITE_FILEMARKS  0x82000000
  4721. #define TAPE_DRIVE_WRITE_SHORT_FMKS 0x84000000
  4722. #define TAPE_DRIVE_WRITE_LONG_FMKS  0x88000000
  4723.  
  4724. #define TAPE_DRIVE_WRITE_MARK_IMMED 0x90000000
  4725. #define TAPE_DRIVE_FORMAT           0xA0000000
  4726. #define TAPE_DRIVE_FORMAT_IMMEDIATE 0xC0000000
  4727. #define TAPE_DRIVE_HIGH_FEATURES    0x80000000  //mask for high features flag
  4728.  
  4729. typedef struct _TAPE_GET_DRIVE_PARAMETERS {
  4730.     BOOLEAN ECC;
  4731.     BOOLEAN Compression;
  4732.     BOOLEAN DataPadding;
  4733.     BOOLEAN ReportSetmarks;
  4734.     DWORD DefaultBlockSize;
  4735.     DWORD MaximumBlockSize;
  4736.     DWORD MinimumBlockSize;
  4737.     DWORD MaximumPartitionCount;
  4738.     DWORD FeaturesLow;
  4739.     DWORD FeaturesHigh;
  4740.     DWORD EOTWarningZoneSize;
  4741. } TAPE_GET_DRIVE_PARAMETERS, *PTAPE_GET_DRIVE_PARAMETERS;
  4742.  
  4743. //
  4744. // IOCTL_TAPE_SET_DRIVE_PARAMETERS definitions
  4745. //
  4746.  
  4747. typedef struct _TAPE_SET_DRIVE_PARAMETERS {
  4748.     BOOLEAN ECC;
  4749.     BOOLEAN Compression;
  4750.     BOOLEAN DataPadding;
  4751.     BOOLEAN ReportSetmarks;
  4752.     DWORD EOTWarningZoneSize;
  4753. } TAPE_SET_DRIVE_PARAMETERS, *PTAPE_SET_DRIVE_PARAMETERS;
  4754.  
  4755. //
  4756. // IOCTL_TAPE_GET_MEDIA_PARAMETERS definitions
  4757. //
  4758.  
  4759. typedef struct _TAPE_GET_MEDIA_PARAMETERS {
  4760.     LARGE_INTEGER Capacity;
  4761.     LARGE_INTEGER Remaining;
  4762.     DWORD BlockSize;
  4763.     DWORD PartitionCount;
  4764.     BOOLEAN WriteProtected;
  4765. } TAPE_GET_MEDIA_PARAMETERS, *PTAPE_GET_MEDIA_PARAMETERS;
  4766.  
  4767. //
  4768. // IOCTL_TAPE_SET_MEDIA_PARAMETERS definitions
  4769. //
  4770.  
  4771. typedef struct _TAPE_SET_MEDIA_PARAMETERS {
  4772.     DWORD BlockSize;
  4773. } TAPE_SET_MEDIA_PARAMETERS, *PTAPE_SET_MEDIA_PARAMETERS;
  4774.  
  4775. //
  4776. // IOCTL_TAPE_CREATE_PARTITION definitions
  4777. //
  4778.  
  4779. #define TAPE_FIXED_PARTITIONS       0L
  4780. #define TAPE_SELECT_PARTITIONS      1L
  4781. #define TAPE_INITIATOR_PARTITIONS   2L
  4782.  
  4783. typedef struct _TAPE_CREATE_PARTITION {
  4784.     DWORD Method;
  4785.     DWORD Count;
  4786.     DWORD Size;
  4787. } TAPE_CREATE_PARTITION, *PTAPE_CREATE_PARTITION;
  4788.  
  4789.  
  4790. #ifdef __cplusplus
  4791. }
  4792. #endif
  4793.  
  4794. #endif /* _WINNT_ */
  4795.