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