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