home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 14.ddi / GENINC.PAK / WINNT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  134.4 KB  |  3,950 lines

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