WinNT.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:293k
源码类别:

模拟服务器

开发平台:

C/C++

  1. // end_ntddk end_nthal
  2. //
  3. // Stack frame header
  4. //
  5. //   Order of appearance in stack frame:
  6. //      Header (six words)
  7. //      Parameters (at least eight words)
  8. //      Local variables
  9. //      Saved GPRs
  10. //      Saved FPRs
  11. //
  12. //   Minimum alignment is 8 bytes
  13. typedef struct _STACK_FRAME_HEADER {    // GPR 1 points here
  14.     DWORD BackChain;                    // Addr of previous frame
  15.     DWORD GlueSaved1;                   // Used by glue code
  16.     DWORD GlueSaved2;
  17.     DWORD Reserved1;                    // Reserved
  18.     DWORD Spare1;                       // Used by tracing, profiling, ...
  19.     DWORD Spare2;
  20.     DWORD Parameter0;                   // First 8 parameter words are
  21.     DWORD Parameter1;                   //   always present
  22.     DWORD Parameter2;
  23.     DWORD Parameter3;
  24.     DWORD Parameter4;
  25.     DWORD Parameter5;
  26.     DWORD Parameter6;
  27.     DWORD Parameter7;
  28. } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
  29. VOID
  30. __jump_unwind (
  31.     PVOID Fp,
  32.     PVOID TargetPc
  33.     );
  34. #endif // defined(_MPPC_)
  35. #if !defined(__midl) && !defined(GENUTIL) && !defined(_GENIA64_) && defined(_IA64_)
  36. void * _cdecl _rdteb(void);
  37. #if defined(_M_IA64)                    // winnt
  38. #pragma intrinsic(_rdteb)               // winnt
  39. #endif                                  // winnt
  40. #if defined(_M_IA64)
  41. #define NtCurrentTeb()      ((struct _TEB *)_rdteb())
  42. #else
  43. struct _TEB *
  44. NtCurrentTeb(void);
  45. #endif
  46. //
  47. // Define functions to get the address of the current fiber and the
  48. // current fiber data.
  49. //
  50. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  51. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  52. #endif  // !defined(__midl) && !defined(GENUTIL) && !defined(_GENIA64_) && defined(_M_IA64)
  53. #ifdef _IA64_
  54. // begin_ntddk begin_nthal
  55. //
  56. // The following flags control the contents of the CONTEXT structure.
  57. //
  58. #if !defined(RC_INVOKED)
  59. #define CONTEXT_IA64                    0x00080000
  60. #define CONTEXT_CONTROL                 (CONTEXT_IA64 | 0x00000001L)
  61. #define CONTEXT_LOWER_FLOATING_POINT    (CONTEXT_IA64 | 0x00000002L)
  62. #define CONTEXT_HIGHER_FLOATING_POINT   (CONTEXT_IA64 | 0x00000004L)
  63. #define CONTEXT_INTEGER                 (CONTEXT_IA64 | 0x00000008L)
  64. #define CONTEXT_DEBUG                   (CONTEXT_IA64 | 0x00000010L)
  65. #define CONTEXT_IA32_CONTROL            (CONTEXT_IA64 | 0x00000020L)  // Includes StIPSR
  66. #define CONTEXT_FLOATING_POINT          (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
  67. #define CONTEXT_FULL                    (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
  68. #endif // !defined(RC_INVOKED)
  69. //
  70. // Context Frame
  71. //
  72. //  This frame has a several purposes: 1) it is used as an argument to
  73. //  NtContinue, 2) it is used to construct a call frame for APC delivery,
  74. //  3) it is used to construct a call frame for exception dispatching
  75. //  in user mode, 4) it is used in the user level thread creation
  76. //  routines, and 5) it is used to to pass thread state to debuggers.
  77. //
  78. //  N.B. Because this record is used as a call frame, it must be EXACTLY
  79. //  a multiple of 16 bytes in length and aligned on a 16-byte boundary.
  80. //
  81. typedef struct _CONTEXT {
  82.     //
  83.     // The flags values within this flag control the contents of
  84.     // a CONTEXT record.
  85.     //
  86.     // If the context record is used as an input parameter, then
  87.     // for each portion of the context record controlled by a flag
  88.     // whose value is set, it is assumed that that portion of the
  89.     // context record contains valid context. If the context record
  90.     // is being used to modify a thread's context, then only that
  91.     // portion of the threads context will be modified.
  92.     //
  93.     // If the context record is used as an IN OUT parameter to capture
  94.     // the context of a thread, then only those portions of the thread's
  95.     // context corresponding to set flags will be returned.
  96.     //
  97.     // The context record is never used as an OUT only parameter.
  98.     //
  99.     DWORD ContextFlags;
  100.     DWORD Fill1[3];         // for alignment of following on 16-byte boundary
  101.     //
  102.     // This section is specified/returned if the ContextFlags word contains
  103.     // the flag CONTEXT_DEBUG.
  104.     //
  105.     // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
  106.     //
  107.     ULONGLONG DbI0;
  108.     ULONGLONG DbI1;
  109.     ULONGLONG DbI2;
  110.     ULONGLONG DbI3;
  111.     ULONGLONG DbI4;
  112.     ULONGLONG DbI5;
  113.     ULONGLONG DbI6;
  114.     ULONGLONG DbI7;
  115.     ULONGLONG DbD0;
  116.     ULONGLONG DbD1;
  117.     ULONGLONG DbD2;
  118.     ULONGLONG DbD3;
  119.     ULONGLONG DbD4;
  120.     ULONGLONG DbD5;
  121.     ULONGLONG DbD6;
  122.     ULONGLONG DbD7;
  123.     //
  124.     // This section is specified/returned if the ContextFlags word contains
  125.     // the flag CONTEXT_LOWER_FLOATING_POINT.
  126.     //
  127.     FLOAT128 FltS0;
  128.     FLOAT128 FltS1;
  129.     FLOAT128 FltS2;
  130.     FLOAT128 FltS3;
  131.     FLOAT128 FltT0;
  132.     FLOAT128 FltT1;
  133.     FLOAT128 FltT2;
  134.     FLOAT128 FltT3;
  135.     FLOAT128 FltT4;
  136.     FLOAT128 FltT5;
  137.     FLOAT128 FltT6;
  138.     FLOAT128 FltT7;
  139.     FLOAT128 FltT8;
  140.     FLOAT128 FltT9;
  141.     //
  142.     // This section is specified/returned if the ContextFlags word contains
  143.     // the flag CONTEXT_HIGHER_FLOATING_POINT.
  144.     //
  145.     FLOAT128 FltS4;
  146.     FLOAT128 FltS5;
  147.     FLOAT128 FltS6;
  148.     FLOAT128 FltS7;
  149.     FLOAT128 FltS8;
  150.     FLOAT128 FltS9;
  151.     FLOAT128 FltS10;
  152.     FLOAT128 FltS11;
  153.     FLOAT128 FltS12;
  154.     FLOAT128 FltS13;
  155.     FLOAT128 FltS14;
  156.     FLOAT128 FltS15;
  157.     FLOAT128 FltS16;
  158.     FLOAT128 FltS17;
  159.     FLOAT128 FltS18;
  160.     FLOAT128 FltS19;
  161.     FLOAT128 FltF32;
  162.     FLOAT128 FltF33;
  163.     FLOAT128 FltF34;
  164.     FLOAT128 FltF35;
  165.     FLOAT128 FltF36;
  166.     FLOAT128 FltF37;
  167.     FLOAT128 FltF38;
  168.     FLOAT128 FltF39;
  169.     FLOAT128 FltF40;
  170.     FLOAT128 FltF41;
  171.     FLOAT128 FltF42;
  172.     FLOAT128 FltF43;
  173.     FLOAT128 FltF44;
  174.     FLOAT128 FltF45;
  175.     FLOAT128 FltF46;
  176.     FLOAT128 FltF47;
  177.     FLOAT128 FltF48;
  178.     FLOAT128 FltF49;
  179.     FLOAT128 FltF50;
  180.     FLOAT128 FltF51;
  181.     FLOAT128 FltF52;
  182.     FLOAT128 FltF53;
  183.     FLOAT128 FltF54;
  184.     FLOAT128 FltF55;
  185.     FLOAT128 FltF56;
  186.     FLOAT128 FltF57;
  187.     FLOAT128 FltF58;
  188.     FLOAT128 FltF59;
  189.     FLOAT128 FltF60;
  190.     FLOAT128 FltF61;
  191.     FLOAT128 FltF62;
  192.     FLOAT128 FltF63;
  193.     FLOAT128 FltF64;
  194.     FLOAT128 FltF65;
  195.     FLOAT128 FltF66;
  196.     FLOAT128 FltF67;
  197.     FLOAT128 FltF68;
  198.     FLOAT128 FltF69;
  199.     FLOAT128 FltF70;
  200.     FLOAT128 FltF71;
  201.     FLOAT128 FltF72;
  202.     FLOAT128 FltF73;
  203.     FLOAT128 FltF74;
  204.     FLOAT128 FltF75;
  205.     FLOAT128 FltF76;
  206.     FLOAT128 FltF77;
  207.     FLOAT128 FltF78;
  208.     FLOAT128 FltF79;
  209.     FLOAT128 FltF80;
  210.     FLOAT128 FltF81;
  211.     FLOAT128 FltF82;
  212.     FLOAT128 FltF83;
  213.     FLOAT128 FltF84;
  214.     FLOAT128 FltF85;
  215.     FLOAT128 FltF86;
  216.     FLOAT128 FltF87;
  217.     FLOAT128 FltF88;
  218.     FLOAT128 FltF89;
  219.     FLOAT128 FltF90;
  220.     FLOAT128 FltF91;
  221.     FLOAT128 FltF92;
  222.     FLOAT128 FltF93;
  223.     FLOAT128 FltF94;
  224.     FLOAT128 FltF95;
  225.     FLOAT128 FltF96;
  226.     FLOAT128 FltF97;
  227.     FLOAT128 FltF98;
  228.     FLOAT128 FltF99;
  229.     FLOAT128 FltF100;
  230.     FLOAT128 FltF101;
  231.     FLOAT128 FltF102;
  232.     FLOAT128 FltF103;
  233.     FLOAT128 FltF104;
  234.     FLOAT128 FltF105;
  235.     FLOAT128 FltF106;
  236.     FLOAT128 FltF107;
  237.     FLOAT128 FltF108;
  238.     FLOAT128 FltF109;
  239.     FLOAT128 FltF110;
  240.     FLOAT128 FltF111;
  241.     FLOAT128 FltF112;
  242.     FLOAT128 FltF113;
  243.     FLOAT128 FltF114;
  244.     FLOAT128 FltF115;
  245.     FLOAT128 FltF116;
  246.     FLOAT128 FltF117;
  247.     FLOAT128 FltF118;
  248.     FLOAT128 FltF119;
  249.     FLOAT128 FltF120;
  250.     FLOAT128 FltF121;
  251.     FLOAT128 FltF122;
  252.     FLOAT128 FltF123;
  253.     FLOAT128 FltF124;
  254.     FLOAT128 FltF125;
  255.     FLOAT128 FltF126;
  256.     FLOAT128 FltF127;
  257.     //
  258.     // This section is specified/returned if the ContextFlags word contains
  259.     // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
  260.     //
  261.     ULONGLONG StFPSR;       //  FP status
  262.     //
  263.     // This section is specified/returned if the ContextFlags word contains
  264.     // the flag CONTEXT_INTEGER.
  265.     //
  266.     // N.B. The registers gp, sp, rp are part of the control context
  267.     //
  268.     ULONGLONG IntGp;        //  r1, volatile
  269.     ULONGLONG IntT0;        //  r2-r3, volatile
  270.     ULONGLONG IntT1;        //
  271.     ULONGLONG IntS0;        //  r4-r7, preserved
  272.     ULONGLONG IntS1;
  273.     ULONGLONG IntS2;
  274.     ULONGLONG IntS3;
  275.     ULONGLONG IntV0;        //  r8, volatile
  276.     ULONGLONG IntT2;        //  r9-r11, volatile
  277.     ULONGLONG IntT3;
  278.     ULONGLONG IntT4;
  279.     ULONGLONG IntSp;        //  stack pointer (r12), special
  280.     ULONGLONG IntTeb;       //  teb (r13), special
  281.     ULONGLONG IntT5;        //  r14-r31, volatile
  282.     ULONGLONG IntT6;
  283.     ULONGLONG IntT7;
  284.     ULONGLONG IntT8;
  285.     ULONGLONG IntT9;
  286.     ULONGLONG IntT10;
  287.     ULONGLONG IntT11;
  288.     ULONGLONG IntT12;
  289.     ULONGLONG IntT13;
  290.     ULONGLONG IntT14;
  291.     ULONGLONG IntT15;
  292.     ULONGLONG IntT16;
  293.     ULONGLONG IntT17;
  294.     ULONGLONG IntT18;
  295.     ULONGLONG IntT19;
  296.     ULONGLONG IntT20;
  297.     ULONGLONG IntT21;
  298.     ULONGLONG IntT22;
  299.     ULONGLONG IntNats;      //  Nat bits for r1-r31
  300.                             //  r1-r31 in bits 1 thru 31.
  301.     ULONGLONG Preds;        //  predicates, preserved
  302.     ULONGLONG BrRp;         //  return pointer, b0, preserved
  303.     ULONGLONG BrS0;         //  b1-b5, preserved
  304.     ULONGLONG BrS1;
  305.     ULONGLONG BrS2;
  306.     ULONGLONG BrS3;
  307.     ULONGLONG BrS4;
  308.     ULONGLONG BrT0;         //  b6-b7, volatile
  309.     ULONGLONG BrT1;
  310.     //
  311.     // This section is specified/returned if the ContextFlags word contains
  312.     // the flag CONTEXT_CONTROL.
  313.     //
  314.     // Other application registers
  315.     ULONGLONG ApUNAT;       //  User Nat collection register, preserved
  316.     ULONGLONG ApLC;         //  Loop counter register, preserved
  317.     ULONGLONG ApEC;         //  Epilog counter register, preserved
  318.     ULONGLONG ApCCV;        //  CMPXCHG value register, volatile
  319.     ULONGLONG ApDCR;        //  Default control register (TBD)
  320.     // Register stack info
  321.     ULONGLONG RsPFS;        //  Previous function state, preserved
  322.     ULONGLONG RsBSP;        //  Backing store pointer, preserved
  323.     ULONGLONG RsBSPSTORE;
  324.     ULONGLONG RsRSC;        //  RSE configuration, volatile
  325.     ULONGLONG RsRNAT;       //  RSE Nat collection register, preserved
  326.     // Trap Status Information
  327.     ULONGLONG StIPSR;       //  Interruption Processor Status
  328.     ULONGLONG StIIP;        //  Interruption IP
  329.     ULONGLONG StIFS;        //  Interruption Function State
  330.     // iA32 related control registers
  331.     ULONGLONG StFCR;        //  copy of Ar21
  332.     ULONGLONG Eflag;        //  Eflag copy of Ar24
  333.     ULONGLONG SegCSD;       //  iA32 CSDescriptor (Ar25)
  334.     ULONGLONG SegSSD;       //  iA32 SSDescriptor (Ar26)
  335.     ULONGLONG Cflag;        //  Cr0+Cr4 copy of Ar27
  336.     ULONGLONG StFSR;        //  x86 FP status (copy of AR28)
  337.     ULONGLONG StFIR;        //  x86 FP status (copy of AR29)
  338.     ULONGLONG StFDR;        //  x86 FP status (copy of AR30)
  339.       ULONGLONG UNUSEDPACK;   //  added to pack StFDR to 16-bytes
  340. } CONTEXT, *PCONTEXT;
  341. // begin_winnt
  342. //
  343. // Plabel descriptor structure definition
  344. //
  345. typedef struct _PLABEL_DESCRIPTOR {
  346.    ULONGLONG EntryPoint;
  347.    ULONGLONG GlobalPointer;
  348. } PLABEL_DESCRIPTOR, *PPLABEL_DESCRIPTOR;
  349. #endif // _IA64_
  350. #ifdef _IA64_
  351. VOID
  352. __jump_unwind (
  353.     ULONGLONG TargetMsFrame,
  354.     ULONGLONG TargetBsFrame,
  355.     ULONGLONG TargetPc
  356.     );
  357. #endif // _IA64_
  358. #define EXCEPTION_NONCONTINUABLE 0x1    // Noncontinuable exception
  359. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  360. //
  361. // Exception record definition.
  362. //
  363. typedef struct _EXCEPTION_RECORD {
  364.     DWORD    ExceptionCode;
  365.     DWORD ExceptionFlags;
  366.     struct _EXCEPTION_RECORD *ExceptionRecord;
  367.     PVOID ExceptionAddress;
  368.     DWORD NumberParameters;
  369.     ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  370.     } EXCEPTION_RECORD;
  371. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  372. typedef struct _EXCEPTION_RECORD32 {
  373.     DWORD    ExceptionCode;
  374.     DWORD ExceptionFlags;
  375.     DWORD ExceptionRecord;
  376.     DWORD ExceptionAddress;
  377.     DWORD NumberParameters;
  378.     DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  379. } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
  380. typedef struct _EXCEPTION_RECORD64 {
  381.     DWORD    ExceptionCode;
  382.     DWORD ExceptionFlags;
  383.     DWORD64 ExceptionRecord;
  384.     DWORD64 ExceptionAddress;
  385.     DWORD NumberParameters;
  386.     DWORD __unusedAlignment;
  387.     DWORD64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  388. } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
  389. //
  390. // Typedef for pointer returned by exception_info()
  391. //
  392. typedef struct _EXCEPTION_POINTERS {
  393.     PEXCEPTION_RECORD ExceptionRecord;
  394.     PCONTEXT ContextRecord;
  395. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  396. typedef PVOID PACCESS_TOKEN;            
  397. typedef PVOID PSECURITY_DESCRIPTOR;     
  398. typedef PVOID PSID;     
  399. ////////////////////////////////////////////////////////////////////////
  400. //                                                                    //
  401. //                             ACCESS MASK                            //
  402. //                                                                    //
  403. ////////////////////////////////////////////////////////////////////////
  404. //
  405. //  Define the access mask as a longword sized structure divided up as
  406. //  follows:
  407. //
  408. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  409. //       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
  410. //      +---------------+---------------+-------------------------------+
  411. //      |G|G|G|G|Res'd|A| StandardRights|         SpecificRights        |
  412. //      |R|W|E|A|     |S|               |                               |
  413. //      +-+-------------+---------------+-------------------------------+
  414. //
  415. //      typedef struct _ACCESS_MASK {
  416. //          WORD   SpecificRights;
  417. //          BYTE  StandardRights;
  418. //          BYTE  AccessSystemAcl : 1;
  419. //          BYTE  Reserved : 3;
  420. //          BYTE  GenericAll : 1;
  421. //          BYTE  GenericExecute : 1;
  422. //          BYTE  GenericWrite : 1;
  423. //          BYTE  GenericRead : 1;
  424. //      } ACCESS_MASK;
  425. //      typedef ACCESS_MASK *PACCESS_MASK;
  426. //
  427. //  but to make life simple for programmer's we'll allow them to specify
  428. //  a desired access mask by simply OR'ing together mulitple single rights
  429. //  and treat an access mask as a DWORD.  For example
  430. //
  431. //      DesiredAccess = DELETE | READ_CONTROL
  432. //
  433. //  So we'll declare ACCESS_MASK as DWORD
  434. //
  435. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  436. typedef DWORD ACCESS_MASK;
  437. typedef ACCESS_MASK *PACCESS_MASK;
  438. ////////////////////////////////////////////////////////////////////////
  439. //                                                                    //
  440. //                             ACCESS TYPES                           //
  441. //                                                                    //
  442. ////////////////////////////////////////////////////////////////////////
  443. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  444. //
  445. //  The following are masks for the predefined standard access types
  446. //
  447. #define DELETE                           (0x00010000L)
  448. #define READ_CONTROL                     (0x00020000L)
  449. #define WRITE_DAC                        (0x00040000L)
  450. #define WRITE_OWNER                      (0x00080000L)
  451. #define SYNCHRONIZE                      (0x00100000L)
  452. #define STANDARD_RIGHTS_REQUIRED         (0x000F0000L)
  453. #define STANDARD_RIGHTS_READ             (READ_CONTROL)
  454. #define STANDARD_RIGHTS_WRITE            (READ_CONTROL)
  455. #define STANDARD_RIGHTS_EXECUTE          (READ_CONTROL)
  456. #define STANDARD_RIGHTS_ALL              (0x001F0000L)
  457. #define SPECIFIC_RIGHTS_ALL              (0x0000FFFFL)
  458. //
  459. // AccessSystemAcl access type
  460. //
  461. #define ACCESS_SYSTEM_SECURITY           (0x01000000L)
  462. //
  463. // MaximumAllowed access type
  464. //
  465. #define MAXIMUM_ALLOWED                  (0x02000000L)
  466. //
  467. //  These are the generic rights.
  468. //
  469. #define GENERIC_READ                     (0x80000000L)
  470. #define GENERIC_WRITE                    (0x40000000L)
  471. #define GENERIC_EXECUTE                  (0x20000000L)
  472. #define GENERIC_ALL                      (0x10000000L)
  473. //
  474. //  Define the generic mapping array.  This is used to denote the
  475. //  mapping of each generic access right to a specific access mask.
  476. //
  477. typedef struct _GENERIC_MAPPING {
  478.     ACCESS_MASK GenericRead;
  479.     ACCESS_MASK GenericWrite;
  480.     ACCESS_MASK GenericExecute;
  481.     ACCESS_MASK GenericAll;
  482. } GENERIC_MAPPING;
  483. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  484. ////////////////////////////////////////////////////////////////////////
  485. //                                                                    //
  486. //                        LUID_AND_ATTRIBUTES                         //
  487. //                                                                    //
  488. ////////////////////////////////////////////////////////////////////////
  489. //
  490. //
  491. #include <pshpack4.h>
  492. typedef struct _LUID_AND_ATTRIBUTES {
  493.     LUID Luid;
  494.     DWORD Attributes;
  495.     } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  496. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  497. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  498. #include <poppack.h>
  499. ////////////////////////////////////////////////////////////////////////
  500. //                                                                    //
  501. //              Security Id     (SID)                                 //
  502. //                                                                    //
  503. ////////////////////////////////////////////////////////////////////////
  504. //
  505. //
  506. // Pictorially the structure of an SID is as follows:
  507. //
  508. //         1   1   1   1   1   1
  509. //         5   4   3   2   1   0   9   8   7   6   5   4   3   2   1   0
  510. //      +---------------------------------------------------------------+
  511. //      |      SubAuthorityCount        |Reserved1 (SBZ)|   Revision    |
  512. //      +---------------------------------------------------------------+
  513. //      |                   IdentifierAuthority[0]                      |
  514. //      +---------------------------------------------------------------+
  515. //      |                   IdentifierAuthority[1]                      |
  516. //      +---------------------------------------------------------------+
  517. //      |                   IdentifierAuthority[2]                      |
  518. //      +---------------------------------------------------------------+
  519. //      |                                                               |
  520. //      +- -  -  -  -  -  -  -  SubAuthority[]  -  -  -  -  -  -  -  - -+
  521. //      |                                                               |
  522. //      +---------------------------------------------------------------+
  523. //
  524. //
  525. // begin_ntifs
  526. #ifndef SID_IDENTIFIER_AUTHORITY_DEFINED
  527. #define SID_IDENTIFIER_AUTHORITY_DEFINED
  528. typedef struct _SID_IDENTIFIER_AUTHORITY {
  529.     BYTE  Value[6];
  530. } SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY;
  531. #endif
  532. #ifndef SID_DEFINED
  533. #define SID_DEFINED
  534. typedef struct _SID {
  535.    BYTE  Revision;
  536.    BYTE  SubAuthorityCount;
  537.    SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
  538. #ifdef MIDL_PASS
  539.    [size_is(SubAuthorityCount)] DWORD SubAuthority[*];
  540. #else // MIDL_PASS
  541.    DWORD SubAuthority[ANYSIZE_ARRAY];
  542. #endif // MIDL_PASS
  543. } SID, *PISID;
  544. #endif
  545. #define SID_REVISION                     (1)    // Current revision level
  546. #define SID_MAX_SUB_AUTHORITIES          (15)
  547. #define SID_RECOMMENDED_SUB_AUTHORITIES  (1)    // Will change to around 6
  548.                                                 // in a future release.
  549. #ifndef MIDL_PASS
  550. #define SECURITY_MAX_SID_SIZE  
  551.       (sizeof(SID) - sizeof(DWORD) + (SID_MAX_SUB_AUTHORITIES * sizeof(DWORD)))
  552. #endif // MIDL_PASS
  553. typedef enum _SID_NAME_USE {
  554.     SidTypeUser = 1,
  555.     SidTypeGroup,
  556.     SidTypeDomain,
  557.     SidTypeAlias,
  558.     SidTypeWellKnownGroup,
  559.     SidTypeDeletedAccount,
  560.     SidTypeInvalid,
  561.     SidTypeUnknown,
  562.     SidTypeComputer
  563. } SID_NAME_USE, *PSID_NAME_USE;
  564. typedef struct _SID_AND_ATTRIBUTES {
  565.     PSID Sid;
  566.     DWORD Attributes;
  567.     } SID_AND_ATTRIBUTES, * PSID_AND_ATTRIBUTES;
  568. typedef SID_AND_ATTRIBUTES SID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  569. typedef SID_AND_ATTRIBUTES_ARRAY *PSID_AND_ATTRIBUTES_ARRAY;
  570. /////////////////////////////////////////////////////////////////////////////
  571. //                                                                         //
  572. // Universal well-known SIDs                                               //
  573. //                                                                         //
  574. //     Null SID                     S-1-0-0                                //
  575. //     World                        S-1-1-0                                //
  576. //     Local                        S-1-2-0                                //
  577. //     Creator Owner ID             S-1-3-0                                //
  578. //     Creator Group ID             S-1-3-1                                //
  579. //     Creator Owner Server ID      S-1-3-2                                //
  580. //     Creator Group Server ID      S-1-3-3                                //
  581. //                                                                         //
  582. //     (Non-unique IDs)             S-1-4                                  //
  583. //                                                                         //
  584. /////////////////////////////////////////////////////////////////////////////
  585. #define SECURITY_NULL_SID_AUTHORITY         {0,0,0,0,0,0}
  586. #define SECURITY_WORLD_SID_AUTHORITY        {0,0,0,0,0,1}
  587. #define SECURITY_LOCAL_SID_AUTHORITY        {0,0,0,0,0,2}
  588. #define SECURITY_CREATOR_SID_AUTHORITY      {0,0,0,0,0,3}
  589. #define SECURITY_NON_UNIQUE_AUTHORITY       {0,0,0,0,0,4}
  590. #define SECURITY_RESOURCE_MANAGER_AUTHORITY {0,0,0,0,0,9}
  591. #define SECURITY_NULL_RID                 (0x00000000L)
  592. #define SECURITY_WORLD_RID                (0x00000000L)
  593. #define SECURITY_LOCAL_RID                (0x00000000L)
  594. #define SECURITY_CREATOR_OWNER_RID        (0x00000000L)
  595. #define SECURITY_CREATOR_GROUP_RID        (0x00000001L)
  596. #define SECURITY_CREATOR_OWNER_SERVER_RID (0x00000002L)
  597. #define SECURITY_CREATOR_GROUP_SERVER_RID (0x00000003L)
  598. /////////////////////////////////////////////////////////////////////////////
  599. //                                                                         //
  600. // NT well-known SIDs                                                      //
  601. //                                                                         //
  602. //     NT Authority          S-1-5                                         //
  603. //     Dialup                S-1-5-1                                       //
  604. //                                                                         //
  605. //     Network               S-1-5-2                                       //
  606. //     Batch                 S-1-5-3                                       //
  607. //     Interactive           S-1-5-4                                       //
  608. //     Service               S-1-5-6                                       //
  609. //     AnonymousLogon        S-1-5-7       (aka null logon session)        //
  610. //     Proxy                 S-1-5-8                                       //
  611. //     ServerLogon           S-1-5-9       (aka domain controller account) //
  612. //     Self                  S-1-5-10      (self RID)                      //
  613. //     Authenticated User    S-1-5-11      (Authenticated user somewhere)  //
  614. //     Restricted Code       S-1-5-12      (Running restricted code)       //
  615. //     Terminal Server       S-1-5-13      (Running on Terminal Server)    //
  616. //     Remote Logon          S-1-5-14      (Remote Interactive Logon)      //
  617. //                                                                         //
  618. //     (Logon IDs)           S-1-5-5-X-Y                                   //
  619. //                                                                         //
  620. //     (NT non-unique IDs)   S-1-5-0x15-...                                //
  621. //                                                                         //
  622. //     (Built-in domain)     s-1-5-0x20                                    //
  623. //                                                                         //
  624. /////////////////////////////////////////////////////////////////////////////
  625. #define SECURITY_NT_AUTHORITY           {0,0,0,0,0,5}   // ntifs
  626. #define SECURITY_DIALUP_RID             (0x00000001L)
  627. #define SECURITY_NETWORK_RID            (0x00000002L)
  628. #define SECURITY_BATCH_RID              (0x00000003L)
  629. #define SECURITY_INTERACTIVE_RID        (0x00000004L)
  630. #define SECURITY_SERVICE_RID            (0x00000006L)
  631. #define SECURITY_ANONYMOUS_LOGON_RID    (0x00000007L)
  632. #define SECURITY_PROXY_RID              (0x00000008L)
  633. #define SECURITY_ENTERPRISE_CONTROLLERS_RID (0x00000009L)
  634. #define SECURITY_SERVER_LOGON_RID       SECURITY_ENTERPRISE_CONTROLLERS_RID
  635. #define SECURITY_PRINCIPAL_SELF_RID     (0x0000000AL)
  636. #define SECURITY_AUTHENTICATED_USER_RID (0x0000000BL)
  637. #define SECURITY_RESTRICTED_CODE_RID    (0x0000000CL)
  638. #define SECURITY_TERMINAL_SERVER_RID    (0x0000000DL)
  639. #define SECURITY_REMOTE_LOGON_RID       (0x0000000EL)
  640. #define SECURITY_LOGON_IDS_RID          (0x00000005L)
  641. #define SECURITY_LOGON_IDS_RID_COUNT    (3L)
  642. #define SECURITY_LOCAL_SYSTEM_RID       (0x00000012L)
  643. #define SECURITY_LOCAL_SERVICE_RID      (0x00000013L)
  644. #define SECURITY_NETWORK_SERVICE_RID    (0x00000014L)
  645. #define SECURITY_NT_NON_UNIQUE                 (0x00000015L)
  646. #define SECURITY_NT_NON_UNIQUE_SUB_AUTH_COUNT  (3L)
  647. #define SECURITY_BUILTIN_DOMAIN_RID     (0x00000020L)
  648. /////////////////////////////////////////////////////////////////////////////
  649. //                                                                         //
  650. // well-known domain relative sub-authority values (RIDs)...               //
  651. //                                                                         //
  652. /////////////////////////////////////////////////////////////////////////////
  653. // Well-known users ...
  654. #define DOMAIN_USER_RID_ADMIN          (0x000001F4L)
  655. #define DOMAIN_USER_RID_GUEST          (0x000001F5L)
  656. #define DOMAIN_USER_RID_KRBTGT         (0x000001F6L)
  657. // well-known groups ...
  658. #define DOMAIN_GROUP_RID_ADMINS        (0x00000200L)
  659. #define DOMAIN_GROUP_RID_USERS         (0x00000201L)
  660. #define DOMAIN_GROUP_RID_GUESTS        (0x00000202L)
  661. #define DOMAIN_GROUP_RID_COMPUTERS     (0x00000203L)
  662. #define DOMAIN_GROUP_RID_CONTROLLERS   (0x00000204L)
  663. #define DOMAIN_GROUP_RID_CERT_ADMINS   (0x00000205L)
  664. #define DOMAIN_GROUP_RID_SCHEMA_ADMINS (0x00000206L)
  665. #define DOMAIN_GROUP_RID_ENTERPRISE_ADMINS (0x00000207L)
  666. #define DOMAIN_GROUP_RID_POLICY_ADMINS (0x00000208L)
  667. // well-known aliases ...
  668. #define DOMAIN_ALIAS_RID_ADMINS        (0x00000220L)
  669. #define DOMAIN_ALIAS_RID_USERS         (0x00000221L)
  670. #define DOMAIN_ALIAS_RID_GUESTS        (0x00000222L)
  671. #define DOMAIN_ALIAS_RID_POWER_USERS   (0x00000223L)
  672. #define DOMAIN_ALIAS_RID_ACCOUNT_OPS   (0x00000224L)
  673. #define DOMAIN_ALIAS_RID_SYSTEM_OPS    (0x00000225L)
  674. #define DOMAIN_ALIAS_RID_PRINT_OPS     (0x00000226L)
  675. #define DOMAIN_ALIAS_RID_BACKUP_OPS    (0x00000227L)
  676. #define DOMAIN_ALIAS_RID_REPLICATOR    (0x00000228L)
  677. #define DOMAIN_ALIAS_RID_RAS_SERVERS   (0x00000229L)
  678. #define DOMAIN_ALIAS_RID_PREW2KCOMPACCESS (0x0000022AL)
  679. #define DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS (0x0000022BL)
  680. #define DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS (0x0000022CL)
  681. //
  682. // Allocate the System Luid.  The first 1000 LUIDs are reserved.
  683. // Use #999 here (0x3E7 = 999)
  684. //
  685. #define SYSTEM_LUID                     { 0x3E7, 0x0 }
  686. #define ANONYMOUS_LOGON_LUID            { 0x3e6, 0x0 }
  687. #define LOCALSERVICE_LUID               { 0x3e5, 0x0 }
  688. #define NETWORKSERVICE_LUID             { 0x3e4, 0x0 }
  689. // end_ntifs
  690. ////////////////////////////////////////////////////////////////////////
  691. //                                                                    //
  692. //                          User and Group related SID attributes     //
  693. //                                                                    //
  694. ////////////////////////////////////////////////////////////////////////
  695. //
  696. // Group attributes
  697. //
  698. #define SE_GROUP_MANDATORY              (0x00000001L)
  699. #define SE_GROUP_ENABLED_BY_DEFAULT     (0x00000002L)
  700. #define SE_GROUP_ENABLED                (0x00000004L)
  701. #define SE_GROUP_OWNER                  (0x00000008L)
  702. #define SE_GROUP_USE_FOR_DENY_ONLY      (0x00000010L)
  703. #define SE_GROUP_LOGON_ID               (0xC0000000L)
  704. #define SE_GROUP_RESOURCE               (0x20000000L)
  705. //
  706. // User attributes
  707. //
  708. // (None yet defined.)
  709. ////////////////////////////////////////////////////////////////////////
  710. //                                                                    //
  711. //                         ACL  and  ACE                              //
  712. //                                                                    //
  713. ////////////////////////////////////////////////////////////////////////
  714. //
  715. //  Define an ACL and the ACE format.  The structure of an ACL header
  716. //  followed by one or more ACEs.  Pictorally the structure of an ACL header
  717. //  is as follows:
  718. //
  719. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  720. //       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
  721. //      +-------------------------------+---------------+---------------+
  722. //      |            AclSize            |      Sbz1     |  AclRevision  |
  723. //      +-------------------------------+---------------+---------------+
  724. //      |              Sbz2             |           AceCount            |
  725. //      +-------------------------------+-------------------------------+
  726. //
  727. //  The current AclRevision is defined to be ACL_REVISION.
  728. //
  729. //  AclSize is the size, in bytes, allocated for the ACL.  This includes
  730. //  the ACL header, ACES, and remaining free space in the buffer.
  731. //
  732. //  AceCount is the number of ACES in the ACL.
  733. //
  734. // begin_ntddk begin_wdm begin_ntifs
  735. // This is the *current* ACL revision
  736. #define ACL_REVISION     (2)
  737. #define ACL_REVISION_DS  (4)
  738. // This is the history of ACL revisions.  Add a new one whenever
  739. // ACL_REVISION is updated
  740. #define ACL_REVISION1   (1)
  741. #define MIN_ACL_REVISION ACL_REVISION2
  742. #define ACL_REVISION2   (2)
  743. #define ACL_REVISION3   (3)
  744. #define ACL_REVISION4   (4)
  745. #define MAX_ACL_REVISION ACL_REVISION4
  746. typedef struct _ACL {
  747.     BYTE  AclRevision;
  748.     BYTE  Sbz1;
  749.     WORD   AclSize;
  750.     WORD   AceCount;
  751.     WORD   Sbz2;
  752. } ACL;
  753. typedef ACL *PACL;
  754. // end_ntddk end_wdm
  755. //
  756. //  The structure of an ACE is a common ace header followed by ace type
  757. //  specific data.  Pictorally the structure of the common ace header is
  758. //  as follows:
  759. //
  760. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  761. //       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
  762. //      +---------------+-------+-------+---------------+---------------+
  763. //      |            AceSize            |    AceFlags   |     AceType   |
  764. //      +---------------+-------+-------+---------------+---------------+
  765. //
  766. //  AceType denotes the type of the ace, there are some predefined ace
  767. //  types
  768. //
  769. //  AceSize is the size, in bytes, of ace.
  770. //
  771. //  AceFlags are the Ace flags for audit and inheritance, defined shortly.
  772. typedef struct _ACE_HEADER {
  773.     BYTE  AceType;
  774.     BYTE  AceFlags;
  775.     WORD   AceSize;
  776. } ACE_HEADER;
  777. typedef ACE_HEADER *PACE_HEADER;
  778. //
  779. //  The following are the predefined ace types that go into the AceType
  780. //  field of an Ace header.
  781. //
  782. #define ACCESS_MIN_MS_ACE_TYPE                  (0x0)
  783. #define ACCESS_ALLOWED_ACE_TYPE                 (0x0)
  784. #define ACCESS_DENIED_ACE_TYPE                  (0x1)
  785. #define SYSTEM_AUDIT_ACE_TYPE                   (0x2)
  786. #define SYSTEM_ALARM_ACE_TYPE                   (0x3)
  787. #define ACCESS_MAX_MS_V2_ACE_TYPE               (0x3)
  788. #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE        (0x4)
  789. #define ACCESS_MAX_MS_V3_ACE_TYPE               (0x4)
  790. #define ACCESS_MIN_MS_OBJECT_ACE_TYPE           (0x5)
  791. #define ACCESS_ALLOWED_OBJECT_ACE_TYPE          (0x5)
  792. #define ACCESS_DENIED_OBJECT_ACE_TYPE           (0x6)
  793. #define SYSTEM_AUDIT_OBJECT_ACE_TYPE            (0x7)
  794. #define SYSTEM_ALARM_OBJECT_ACE_TYPE            (0x8)
  795. #define ACCESS_MAX_MS_OBJECT_ACE_TYPE           (0x8)
  796. #define ACCESS_MAX_MS_V4_ACE_TYPE               (0x8)
  797. #define ACCESS_MAX_MS_ACE_TYPE                  (0x8)
  798. #define ACCESS_ALLOWED_CALLBACK_ACE_TYPE        (0x9)
  799. #define ACCESS_DENIED_CALLBACK_ACE_TYPE         (0xA)
  800. #define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE (0xB)
  801. #define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE  (0xC)
  802. #define SYSTEM_AUDIT_CALLBACK_ACE_TYPE          (0xD)
  803. #define SYSTEM_ALARM_CALLBACK_ACE_TYPE          (0xE)
  804. #define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE   (0xF)
  805. #define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE   (0x10)
  806. #define ACCESS_MAX_MS_V5_ACE_TYPE               (0x10)
  807. //
  808. //  The following are the inherit flags that go into the AceFlags field
  809. //  of an Ace header.
  810. //
  811. #define OBJECT_INHERIT_ACE                (0x1)
  812. #define CONTAINER_INHERIT_ACE             (0x2)
  813. #define NO_PROPAGATE_INHERIT_ACE          (0x4)
  814. #define INHERIT_ONLY_ACE                  (0x8)
  815. #define INHERITED_ACE                     (0x10)
  816. #define VALID_INHERIT_FLAGS               (0x1F)
  817. //  The following are the currently defined ACE flags that go into the
  818. //  AceFlags field of an ACE header.  Each ACE type has its own set of
  819. //  AceFlags.
  820. //
  821. //  SUCCESSFUL_ACCESS_ACE_FLAG - used only with system audit and alarm ACE
  822. //  types to indicate that a message is generated for successful accesses.
  823. //
  824. //  FAILED_ACCESS_ACE_FLAG - used only with system audit and alarm ACE types
  825. //  to indicate that a message is generated for failed accesses.
  826. //
  827. //
  828. //  SYSTEM_AUDIT and SYSTEM_ALARM AceFlags
  829. //
  830. //  These control the signaling of audit and alarms for success or failure.
  831. //
  832. #define SUCCESSFUL_ACCESS_ACE_FLAG       (0x40)
  833. #define FAILED_ACCESS_ACE_FLAG           (0x80)
  834. //
  835. //  We'll define the structure of the predefined ACE types.  Pictorally
  836. //  the structure of the predefined ACE's is as follows:
  837. //
  838. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  839. //       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
  840. //      +---------------+-------+-------+---------------+---------------+
  841. //      |    AceFlags   | Resd  |Inherit|    AceSize    |     AceType   |
  842. //      +---------------+-------+-------+---------------+---------------+
  843. //      |                              Mask                             |
  844. //      +---------------------------------------------------------------+
  845. //      |                                                               |
  846. //      +                                                               +
  847. //      |                                                               |
  848. //      +                              Sid                              +
  849. //      |                                                               |
  850. //      +                                                               +
  851. //      |                                                               |
  852. //      +---------------------------------------------------------------+
  853. //
  854. //  Mask is the access mask associated with the ACE.  This is either the
  855. //  access allowed, access denied, audit, or alarm mask.
  856. //
  857. //  Sid is the Sid associated with the ACE.
  858. //
  859. //  The following are the four predefined ACE types.
  860. //  Examine the AceType field in the Header to determine
  861. //  which structure is appropriate to use for casting.
  862. typedef struct _ACCESS_ALLOWED_ACE {
  863.     ACE_HEADER Header;
  864.     ACCESS_MASK Mask;
  865.     DWORD SidStart;
  866. } ACCESS_ALLOWED_ACE;
  867. typedef ACCESS_ALLOWED_ACE *PACCESS_ALLOWED_ACE;
  868. typedef struct _ACCESS_DENIED_ACE {
  869.     ACE_HEADER Header;
  870.     ACCESS_MASK Mask;
  871.     DWORD SidStart;
  872. } ACCESS_DENIED_ACE;
  873. typedef ACCESS_DENIED_ACE *PACCESS_DENIED_ACE;
  874. typedef struct _SYSTEM_AUDIT_ACE {
  875.     ACE_HEADER Header;
  876.     ACCESS_MASK Mask;
  877.     DWORD SidStart;
  878. } SYSTEM_AUDIT_ACE;
  879. typedef SYSTEM_AUDIT_ACE *PSYSTEM_AUDIT_ACE;
  880. typedef struct _SYSTEM_ALARM_ACE {
  881.     ACE_HEADER Header;
  882.     ACCESS_MASK Mask;
  883.     DWORD SidStart;
  884. } SYSTEM_ALARM_ACE;
  885. typedef SYSTEM_ALARM_ACE *PSYSTEM_ALARM_ACE;
  886. // end_ntifs
  887. typedef struct _ACCESS_ALLOWED_OBJECT_ACE {
  888.     ACE_HEADER Header;
  889.     ACCESS_MASK Mask;
  890.     DWORD Flags;
  891.     GUID ObjectType;
  892.     GUID InheritedObjectType;
  893.     DWORD SidStart;
  894. } ACCESS_ALLOWED_OBJECT_ACE, *PACCESS_ALLOWED_OBJECT_ACE;
  895. typedef struct _ACCESS_DENIED_OBJECT_ACE {
  896.     ACE_HEADER Header;
  897.     ACCESS_MASK Mask;
  898.     DWORD Flags;
  899.     GUID ObjectType;
  900.     GUID InheritedObjectType;
  901.     DWORD SidStart;
  902. } ACCESS_DENIED_OBJECT_ACE, *PACCESS_DENIED_OBJECT_ACE;
  903. typedef struct _SYSTEM_AUDIT_OBJECT_ACE {
  904.     ACE_HEADER Header;
  905.     ACCESS_MASK Mask;
  906.     DWORD Flags;
  907.     GUID ObjectType;
  908.     GUID InheritedObjectType;
  909.     DWORD SidStart;
  910. } SYSTEM_AUDIT_OBJECT_ACE, *PSYSTEM_AUDIT_OBJECT_ACE;
  911. typedef struct _SYSTEM_ALARM_OBJECT_ACE {
  912.     ACE_HEADER Header;
  913.     ACCESS_MASK Mask;
  914.     DWORD Flags;
  915.     GUID ObjectType;
  916.     GUID InheritedObjectType;
  917.     DWORD SidStart;
  918. } SYSTEM_ALARM_OBJECT_ACE, *PSYSTEM_ALARM_OBJECT_ACE;
  919. //
  920. // Callback ace support in post Win2000.
  921. // Resource managers can put their own data after Sidstart + Length of the sid
  922. //
  923. typedef struct _ACCESS_ALLOWED_CALLBACK_ACE {
  924.     ACE_HEADER Header;
  925.     ACCESS_MASK Mask;
  926.     DWORD SidStart;
  927.     // Opaque resouce manager specific data
  928. } ACCESS_ALLOWED_CALLBACK_ACE, *PACCESS_ALLOWED_CALLBACK_ACE;
  929. typedef struct _ACCESS_DENIED_CALLBACK_ACE {
  930.     ACE_HEADER Header;
  931.     ACCESS_MASK Mask;
  932.     DWORD SidStart;
  933.     // Opaque resouce manager specific data
  934. } ACCESS_DENIED_CALLBACK_ACE, *PACCESS_DENIED_CALLBACK_ACE;
  935. typedef struct _SYSTEM_AUDIT_CALLBACK_ACE {
  936.     ACE_HEADER Header;
  937.     ACCESS_MASK Mask;
  938.     DWORD SidStart;
  939.     // Opaque resouce manager specific data
  940. } SYSTEM_AUDIT_CALLBACK_ACE, *PSYSTEM_AUDIT_CALLBACK_ACE;
  941. typedef struct _SYSTEM_ALARM_CALLBACK_ACE {
  942.     ACE_HEADER Header;
  943.     ACCESS_MASK Mask;
  944.     DWORD SidStart;
  945.     // Opaque resouce manager specific data
  946. } SYSTEM_ALARM_CALLBACK_ACE, *PSYSTEM_ALARM_CALLBACK_ACE;
  947. typedef struct _ACCESS_ALLOWED_CALLBACK_OBJECT_ACE {
  948.     ACE_HEADER Header;
  949.     ACCESS_MASK Mask;
  950.     DWORD Flags;
  951.     GUID ObjectType;
  952.     GUID InheritedObjectType;
  953.     DWORD SidStart;
  954.     // Opaque resouce manager specific data
  955. } ACCESS_ALLOWED_CALLBACK_OBJECT_ACE, *PACCESS_ALLOWED_CALLBACK_OBJECT_ACE;
  956. typedef struct _ACCESS_DENIED_CALLBACK_OBJECT_ACE {
  957.     ACE_HEADER Header;
  958.     ACCESS_MASK Mask;
  959.     DWORD Flags;
  960.     GUID ObjectType;
  961.     GUID InheritedObjectType;
  962.     DWORD SidStart;
  963.     // Opaque resouce manager specific data
  964. } ACCESS_DENIED_CALLBACK_OBJECT_ACE, *PACCESS_DENIED_CALLBACK_OBJECT_ACE;
  965. typedef struct _SYSTEM_AUDIT_CALLBACK_OBJECT_ACE {
  966.     ACE_HEADER Header;
  967.     ACCESS_MASK Mask;
  968.     DWORD Flags;
  969.     GUID ObjectType;
  970.     GUID InheritedObjectType;
  971.     DWORD SidStart;
  972.     // Opaque resouce manager specific data
  973. } SYSTEM_AUDIT_CALLBACK_OBJECT_ACE, *PSYSTEM_AUDIT_CALLBACK_OBJECT_ACE;
  974. typedef struct _SYSTEM_ALARM_CALLBACK_OBJECT_ACE {
  975.     ACE_HEADER Header;
  976.     ACCESS_MASK Mask;
  977.     DWORD Flags;
  978.     GUID ObjectType;
  979.     GUID InheritedObjectType;
  980.     DWORD SidStart;
  981.     // Opaque resouce manager specific data
  982. } SYSTEM_ALARM_CALLBACK_OBJECT_ACE, *PSYSTEM_ALARM_CALLBACK_OBJECT_ACE;
  983. //
  984. // Currently define Flags for "OBJECT" ACE types.
  985. //
  986. #define ACE_OBJECT_TYPE_PRESENT           0x1
  987. #define ACE_INHERITED_OBJECT_TYPE_PRESENT 0x2
  988. //
  989. //  The following declarations are used for setting and querying information
  990. //  about and ACL.  First are the various information classes available to
  991. //  the user.
  992. //
  993. typedef enum _ACL_INFORMATION_CLASS {
  994.     AclRevisionInformation = 1,
  995.     AclSizeInformation
  996. } ACL_INFORMATION_CLASS;
  997. //
  998. //  This record is returned/sent if the user is requesting/setting the
  999. //  AclRevisionInformation
  1000. //
  1001. typedef struct _ACL_REVISION_INFORMATION {
  1002.     DWORD AclRevision;
  1003. } ACL_REVISION_INFORMATION;
  1004. typedef ACL_REVISION_INFORMATION *PACL_REVISION_INFORMATION;
  1005. //
  1006. //  This record is returned if the user is requesting AclSizeInformation
  1007. //
  1008. typedef struct _ACL_SIZE_INFORMATION {
  1009.     DWORD AceCount;
  1010.     DWORD AclBytesInUse;
  1011.     DWORD AclBytesFree;
  1012. } ACL_SIZE_INFORMATION;
  1013. typedef ACL_SIZE_INFORMATION *PACL_SIZE_INFORMATION;
  1014. ////////////////////////////////////////////////////////////////////////
  1015. //                                                                    //
  1016. //                             SECURITY_DESCRIPTOR                    //
  1017. //                                                                    //
  1018. ////////////////////////////////////////////////////////////////////////
  1019. //
  1020. //  Define the Security Descriptor and related data types.
  1021. //  This is an opaque data structure.
  1022. //
  1023. // begin_wdm begin_ntddk begin_ntifs
  1024. //
  1025. // Current security descriptor revision value
  1026. //
  1027. #define SECURITY_DESCRIPTOR_REVISION     (1)
  1028. #define SECURITY_DESCRIPTOR_REVISION1    (1)
  1029. // end_wdm end_ntddk
  1030. #define SECURITY_DESCRIPTOR_MIN_LENGTH   (sizeof(SECURITY_DESCRIPTOR))
  1031. typedef WORD   SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
  1032. #define SE_OWNER_DEFAULTED               (0x0001)
  1033. #define SE_GROUP_DEFAULTED               (0x0002)
  1034. #define SE_DACL_PRESENT                  (0x0004)
  1035. #define SE_DACL_DEFAULTED                (0x0008)
  1036. #define SE_SACL_PRESENT                  (0x0010)
  1037. #define SE_SACL_DEFAULTED                (0x0020)
  1038. #define SE_DACL_AUTO_INHERIT_REQ         (0x0100)
  1039. #define SE_SACL_AUTO_INHERIT_REQ         (0x0200)
  1040. #define SE_DACL_AUTO_INHERITED           (0x0400)
  1041. #define SE_SACL_AUTO_INHERITED           (0x0800)
  1042. #define SE_DACL_PROTECTED                (0x1000)
  1043. #define SE_SACL_PROTECTED                (0x2000)
  1044. #define SE_RM_CONTROL_VALID              (0x4000)
  1045. #define SE_SELF_RELATIVE                 (0x8000)
  1046. //
  1047. //  Where:
  1048. //
  1049. //      SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the
  1050. //          SID pointed to by the Owner field was provided by a
  1051. //          defaulting mechanism rather than explicitly provided by the
  1052. //          original provider of the security descriptor.  This may
  1053. //          affect the treatment of the SID with respect to inheritence
  1054. //          of an owner.
  1055. //
  1056. //      SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the
  1057. //          SID in the Group field was provided by a defaulting mechanism
  1058. //          rather than explicitly provided by the original provider of
  1059. //          the security descriptor.  This may affect the treatment of
  1060. //          the SID with respect to inheritence of a primary group.
  1061. //
  1062. //      SE_DACL_PRESENT - This boolean flag, when set, indicates that the
  1063. //          security descriptor contains a discretionary ACL.  If this
  1064. //          flag is set and the Dacl field of the SECURITY_DESCRIPTOR is
  1065. //          null, then a null ACL is explicitly being specified.
  1066. //
  1067. //      SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the
  1068. //          ACL pointed to by the Dacl field was provided by a defaulting
  1069. //          mechanism rather than explicitly provided by the original
  1070. //          provider of the security descriptor.  This may affect the
  1071. //          treatment of the ACL with respect to inheritence of an ACL.
  1072. //          This flag is ignored if the DaclPresent flag is not set.
  1073. //
  1074. //      SE_SACL_PRESENT - This boolean flag, when set,  indicates that the
  1075. //          security descriptor contains a system ACL pointed to by the
  1076. //          Sacl field.  If this flag is set and the Sacl field of the
  1077. //          SECURITY_DESCRIPTOR is null, then an empty (but present)
  1078. //          ACL is being specified.
  1079. //
  1080. //      SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the
  1081. //          ACL pointed to by the Sacl field was provided by a defaulting
  1082. //          mechanism rather than explicitly provided by the original
  1083. //          provider of the security descriptor.  This may affect the
  1084. //          treatment of the ACL with respect to inheritence of an ACL.
  1085. //          This flag is ignored if the SaclPresent flag is not set.
  1086. //
  1087. //      SE_SELF_RELATIVE - This boolean flag, when set, indicates that the
  1088. //          security descriptor is in self-relative form.  In this form,
  1089. //          all fields of the security descriptor are contiguous in memory
  1090. //          and all pointer fields are expressed as offsets from the
  1091. //          beginning of the security descriptor.  This form is useful
  1092. //          for treating security descriptors as opaque data structures
  1093. //          for transmission in communication protocol or for storage on
  1094. //          secondary media.
  1095. //
  1096. //
  1097. //
  1098. // Pictorially the structure of a security descriptor is as follows:
  1099. //
  1100. //       3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  1101. //       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
  1102. //      +---------------------------------------------------------------+
  1103. //      |            Control            |Reserved1 (SBZ)|   Revision    |
  1104. //      +---------------------------------------------------------------+
  1105. //      |                            Owner                              |
  1106. //      +---------------------------------------------------------------+
  1107. //      |                            Group                              |
  1108. //      +---------------------------------------------------------------+
  1109. //      |                            Sacl                               |
  1110. //      +---------------------------------------------------------------+
  1111. //      |                            Dacl                               |
  1112. //      +---------------------------------------------------------------+
  1113. //
  1114. // In general, this data structure should be treated opaquely to ensure future
  1115. // compatibility.
  1116. //
  1117. //
  1118. typedef struct _SECURITY_DESCRIPTOR_RELATIVE {
  1119.     BYTE  Revision;
  1120.     BYTE  Sbz1;
  1121.     SECURITY_DESCRIPTOR_CONTROL Control;
  1122.     DWORD Owner;
  1123.     DWORD Group;
  1124.     DWORD Sacl;
  1125.     DWORD Dacl;
  1126.     } SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
  1127. typedef struct _SECURITY_DESCRIPTOR {
  1128.    BYTE  Revision;
  1129.    BYTE  Sbz1;
  1130.    SECURITY_DESCRIPTOR_CONTROL Control;
  1131.    PSID Owner;
  1132.    PSID Group;
  1133.    PACL Sacl;
  1134.    PACL Dacl;
  1135.    } SECURITY_DESCRIPTOR, *PISECURITY_DESCRIPTOR;
  1136. // end_ntifs
  1137. // Where:
  1138. //
  1139. //     Revision - Contains the revision level of the security
  1140. //         descriptor.  This allows this structure to be passed between
  1141. //         systems or stored on disk even though it is expected to
  1142. //         change in the future.
  1143. //
  1144. //     Control - A set of flags which qualify the meaning of the
  1145. //         security descriptor or individual fields of the security
  1146. //         descriptor.
  1147. //
  1148. //     Owner - is a pointer to an SID representing an object's owner.
  1149. //         If this field is null, then no owner SID is present in the
  1150. //         security descriptor.  If the security descriptor is in
  1151. //         self-relative form, then this field contains an offset to
  1152. //         the SID, rather than a pointer.
  1153. //
  1154. //     Group - is a pointer to an SID representing an object's primary
  1155. //         group.  If this field is null, then no primary group SID is
  1156. //         present in the security descriptor.  If the security descriptor
  1157. //         is in self-relative form, then this field contains an offset to
  1158. //         the SID, rather than a pointer.
  1159. //
  1160. //     Sacl - is a pointer to a system ACL.  This field value is only
  1161. //         valid if the DaclPresent control flag is set.  If the
  1162. //         SaclPresent flag is set and this field is null, then a null
  1163. //         ACL  is specified.  If the security descriptor is in
  1164. //         self-relative form, then this field contains an offset to
  1165. //         the ACL, rather than a pointer.
  1166. //
  1167. //     Dacl - is a pointer to a discretionary ACL.  This field value is
  1168. //         only valid if the DaclPresent control flag is set.  If the
  1169. //         DaclPresent flag is set and this field is null, then a null
  1170. //         ACL (unconditionally granting access) is specified.  If the
  1171. //         security descriptor is in self-relative form, then this field
  1172. //         contains an offset to the ACL, rather than a pointer.
  1173. //
  1174. ////////////////////////////////////////////////////////////////////////
  1175. //                                                                    //
  1176. //               Object Type list for AccessCheckByType               //
  1177. //                                                                    //
  1178. ////////////////////////////////////////////////////////////////////////
  1179. typedef struct _OBJECT_TYPE_LIST {
  1180.     WORD   Level;
  1181.     WORD   Sbz;
  1182.     GUID *ObjectType;
  1183. } OBJECT_TYPE_LIST, *POBJECT_TYPE_LIST;
  1184. //
  1185. // DS values for Level
  1186. //
  1187. #define ACCESS_OBJECT_GUID       0
  1188. #define ACCESS_PROPERTY_SET_GUID 1
  1189. #define ACCESS_PROPERTY_GUID     2
  1190. #define ACCESS_MAX_LEVEL         4
  1191. //
  1192. // Parameters to NtAccessCheckByTypeAndAditAlarm
  1193. //
  1194. typedef enum _AUDIT_EVENT_TYPE {
  1195.     AuditEventObjectAccess,
  1196.     AuditEventDirectoryServiceAccess
  1197. } AUDIT_EVENT_TYPE, *PAUDIT_EVENT_TYPE;
  1198. #define AUDIT_ALLOW_NO_PRIVILEGE 0x1
  1199. //
  1200. // DS values for Source and ObjectTypeName
  1201. //
  1202. #define ACCESS_DS_SOURCE_A "DS"
  1203. #define ACCESS_DS_SOURCE_W L"DS"
  1204. #define ACCESS_DS_OBJECT_TYPE_NAME_A "Directory Service Object"
  1205. #define ACCESS_DS_OBJECT_TYPE_NAME_W L"Directory Service Object"
  1206. ////////////////////////////////////////////////////////////////////////
  1207. //                                                                    //
  1208. //               Privilege Related Data Structures                    //
  1209. //                                                                    //
  1210. ////////////////////////////////////////////////////////////////////////
  1211. // begin_wdm begin_ntddk begin_nthal
  1212. //
  1213. // Privilege attributes
  1214. //
  1215. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  1216. #define SE_PRIVILEGE_ENABLED            (0x00000002L)
  1217. #define SE_PRIVILEGE_USED_FOR_ACCESS    (0x80000000L)
  1218. //
  1219. // Privilege Set Control flags
  1220. //
  1221. #define PRIVILEGE_SET_ALL_NECESSARY    (1)
  1222. //
  1223. //  Privilege Set - This is defined for a privilege set of one.
  1224. //                  If more than one privilege is needed, then this structure
  1225. //                  will need to be allocated with more space.
  1226. //
  1227. //  Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  1228. //  structure (defined in se.h)
  1229. //
  1230. typedef struct _PRIVILEGE_SET {
  1231.     DWORD PrivilegeCount;
  1232.     DWORD Control;
  1233.     LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  1234.     } PRIVILEGE_SET, * PPRIVILEGE_SET;
  1235. ////////////////////////////////////////////////////////////////////////
  1236. //                                                                    //
  1237. //               NT Defined Privileges                                //
  1238. //                                                                    //
  1239. ////////////////////////////////////////////////////////////////////////
  1240. #define SE_CREATE_TOKEN_NAME              TEXT("SeCreateTokenPrivilege")
  1241. #define SE_ASSIGNPRIMARYTOKEN_NAME        TEXT("SeAssignPrimaryTokenPrivilege")
  1242. #define SE_LOCK_MEMORY_NAME               TEXT("SeLockMemoryPrivilege")
  1243. #define SE_INCREASE_QUOTA_NAME            TEXT("SeIncreaseQuotaPrivilege")
  1244. #define SE_UNSOLICITED_INPUT_NAME         TEXT("SeUnsolicitedInputPrivilege")
  1245. #define SE_MACHINE_ACCOUNT_NAME           TEXT("SeMachineAccountPrivilege")
  1246. #define SE_TCB_NAME                       TEXT("SeTcbPrivilege")
  1247. #define SE_SECURITY_NAME                  TEXT("SeSecurityPrivilege")
  1248. #define SE_TAKE_OWNERSHIP_NAME            TEXT("SeTakeOwnershipPrivilege")
  1249. #define SE_LOAD_DRIVER_NAME               TEXT("SeLoadDriverPrivilege")
  1250. #define SE_SYSTEM_PROFILE_NAME            TEXT("SeSystemProfilePrivilege")
  1251. #define SE_SYSTEMTIME_NAME                TEXT("SeSystemtimePrivilege")
  1252. #define SE_PROF_SINGLE_PROCESS_NAME       TEXT("SeProfileSingleProcessPrivilege")
  1253. #define SE_INC_BASE_PRIORITY_NAME         TEXT("SeIncreaseBasePriorityPrivilege")
  1254. #define SE_CREATE_PAGEFILE_NAME           TEXT("SeCreatePagefilePrivilege")
  1255. #define SE_CREATE_PERMANENT_NAME          TEXT("SeCreatePermanentPrivilege")
  1256. #define SE_BACKUP_NAME                    TEXT("SeBackupPrivilege")
  1257. #define SE_RESTORE_NAME                   TEXT("SeRestorePrivilege")
  1258. #define SE_SHUTDOWN_NAME                  TEXT("SeShutdownPrivilege")
  1259. #define SE_DEBUG_NAME                     TEXT("SeDebugPrivilege")
  1260. #define SE_AUDIT_NAME                     TEXT("SeAuditPrivilege")
  1261. #define SE_SYSTEM_ENVIRONMENT_NAME        TEXT("SeSystemEnvironmentPrivilege")
  1262. #define SE_CHANGE_NOTIFY_NAME             TEXT("SeChangeNotifyPrivilege")
  1263. #define SE_REMOTE_SHUTDOWN_NAME           TEXT("SeRemoteShutdownPrivilege")
  1264. #define SE_UNDOCK_NAME                    TEXT("SeUndockPrivilege")
  1265. #define SE_SYNC_AGENT_NAME                TEXT("SeSyncAgentPrivilege")
  1266. #define SE_ENABLE_DELEGATION_NAME         TEXT("SeEnableDelegationPrivilege")
  1267. #define SE_MANAGE_VOLUME_NAME             TEXT("SeManageVolumePrivilege")
  1268. ////////////////////////////////////////////////////////////////////
  1269. //                                                                //
  1270. //           Security Quality Of Service                          //
  1271. //                                                                //
  1272. //                                                                //
  1273. ////////////////////////////////////////////////////////////////////
  1274. // begin_wdm begin_ntddk begin_nthal begin_ntifs
  1275. //
  1276. // Impersonation Level
  1277. //
  1278. // Impersonation level is represented by a pair of bits in Windows.
  1279. // If a new impersonation level is added or lowest value is changed from
  1280. // 0 to something else, fix the Windows CreateFile call.
  1281. //
  1282. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  1283.     SecurityAnonymous,
  1284.     SecurityIdentification,
  1285.     SecurityImpersonation,
  1286.     SecurityDelegation
  1287.     } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  1288. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  1289. #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
  1290. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  1291. #define VALID_IMPERSONATION_LEVEL(L) (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL))
  1292. ////////////////////////////////////////////////////////////////////
  1293. //                                                                //
  1294. //           Token Object Definitions                             //
  1295. //                                                                //
  1296. //                                                                //
  1297. ////////////////////////////////////////////////////////////////////
  1298. //
  1299. // Token Specific Access Rights.
  1300. //
  1301. #define TOKEN_ASSIGN_PRIMARY    (0x0001)
  1302. #define TOKEN_DUPLICATE         (0x0002)
  1303. #define TOKEN_IMPERSONATE       (0x0004)
  1304. #define TOKEN_QUERY             (0x0008)
  1305. #define TOKEN_QUERY_SOURCE      (0x0010)
  1306. #define TOKEN_ADJUST_PRIVILEGES (0x0020)
  1307. #define TOKEN_ADJUST_GROUPS     (0x0040)
  1308. #define TOKEN_ADJUST_DEFAULT    (0x0080)
  1309. #define TOKEN_ADJUST_SESSIONID  (0x0100)
  1310. #define TOKEN_ALL_ACCESS_P (STANDARD_RIGHTS_REQUIRED  |
  1311.                           TOKEN_ASSIGN_PRIMARY      |
  1312.                           TOKEN_DUPLICATE           |
  1313.                           TOKEN_IMPERSONATE         |
  1314.                           TOKEN_QUERY               |
  1315.                           TOKEN_QUERY_SOURCE        |
  1316.                           TOKEN_ADJUST_PRIVILEGES   |
  1317.                           TOKEN_ADJUST_GROUPS       |
  1318.                           TOKEN_ADJUST_DEFAULT )
  1319. #if ((defined(_WIN32_WINNT) && (_WIN32_WINNT > 0x0400)) || (!defined(_WIN32_WINNT)))
  1320. #define TOKEN_ALL_ACCESS  (TOKEN_ALL_ACCESS_P |
  1321.                           TOKEN_ADJUST_SESSIONID )
  1322. #else
  1323. #define TOKEN_ALL_ACCESS  (TOKEN_ALL_ACCESS_P)
  1324. #endif
  1325. #define TOKEN_READ       (STANDARD_RIGHTS_READ      |
  1326.                           TOKEN_QUERY)
  1327. #define TOKEN_WRITE      (STANDARD_RIGHTS_WRITE     |
  1328.                           TOKEN_ADJUST_PRIVILEGES   |
  1329.                           TOKEN_ADJUST_GROUPS       |
  1330.                           TOKEN_ADJUST_DEFAULT)
  1331. #define TOKEN_EXECUTE    (STANDARD_RIGHTS_EXECUTE)
  1332. //
  1333. //
  1334. // Token Types
  1335. //
  1336. typedef enum _TOKEN_TYPE {
  1337.     TokenPrimary = 1,
  1338.     TokenImpersonation
  1339.     } TOKEN_TYPE;
  1340. typedef TOKEN_TYPE *PTOKEN_TYPE;
  1341. //
  1342. // Token Information Classes.
  1343. //
  1344. typedef enum _TOKEN_INFORMATION_CLASS {
  1345.     TokenUser = 1,
  1346.     TokenGroups,
  1347.     TokenPrivileges,
  1348.     TokenOwner,
  1349.     TokenPrimaryGroup,
  1350.     TokenDefaultDacl,
  1351.     TokenSource,
  1352.     TokenType,
  1353.     TokenImpersonationLevel,
  1354.     TokenStatistics,
  1355.     TokenRestrictedSids,
  1356.     TokenSessionId,
  1357.     TokenGroupsAndPrivileges,
  1358.     TokenSessionReference,
  1359.     TokenSandBoxInert
  1360. } TOKEN_INFORMATION_CLASS, *PTOKEN_INFORMATION_CLASS;
  1361. //
  1362. // Token information class structures
  1363. //
  1364. typedef struct _TOKEN_USER {
  1365.     SID_AND_ATTRIBUTES User;
  1366. } TOKEN_USER, *PTOKEN_USER;
  1367. typedef struct _TOKEN_GROUPS {
  1368.     DWORD GroupCount;
  1369.     SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
  1370. } TOKEN_GROUPS, *PTOKEN_GROUPS;
  1371. typedef struct _TOKEN_PRIVILEGES {
  1372.     DWORD PrivilegeCount;
  1373.     LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
  1374. } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
  1375. typedef struct _TOKEN_OWNER {
  1376.     PSID Owner;
  1377. } TOKEN_OWNER, *PTOKEN_OWNER;
  1378. typedef struct _TOKEN_PRIMARY_GROUP {
  1379.     PSID PrimaryGroup;
  1380. } TOKEN_PRIMARY_GROUP, *PTOKEN_PRIMARY_GROUP;
  1381. typedef struct _TOKEN_DEFAULT_DACL {
  1382.     PACL DefaultDacl;
  1383. } TOKEN_DEFAULT_DACL, *PTOKEN_DEFAULT_DACL;
  1384. typedef struct _TOKEN_GROUPS_AND_PRIVILEGES {
  1385.     DWORD SidCount;
  1386.     DWORD SidLength;
  1387.     PSID_AND_ATTRIBUTES Sids;
  1388.     DWORD RestrictedSidCount;
  1389.     DWORD RestrictedSidLength;
  1390.     PSID_AND_ATTRIBUTES RestrictedSids;
  1391.     DWORD PrivilegeCount;
  1392.     DWORD PrivilegeLength;
  1393.     PLUID_AND_ATTRIBUTES Privileges;
  1394.     LUID AuthenticationId;
  1395. } TOKEN_GROUPS_AND_PRIVILEGES, *PTOKEN_GROUPS_AND_PRIVILEGES;
  1396. #define TOKEN_SOURCE_LENGTH 8
  1397. typedef struct _TOKEN_SOURCE {
  1398.     CHAR SourceName[TOKEN_SOURCE_LENGTH];
  1399.     LUID SourceIdentifier;
  1400. } TOKEN_SOURCE, *PTOKEN_SOURCE;
  1401. typedef struct _TOKEN_STATISTICS {
  1402.     LUID TokenId;
  1403.     LUID AuthenticationId;
  1404.     LARGE_INTEGER ExpirationTime;
  1405.     TOKEN_TYPE TokenType;
  1406.     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  1407.     DWORD DynamicCharged;
  1408.     DWORD DynamicAvailable;
  1409.     DWORD GroupCount;
  1410.     DWORD PrivilegeCount;
  1411.     LUID ModifiedId;
  1412. } TOKEN_STATISTICS, *PTOKEN_STATISTICS;
  1413. typedef struct _TOKEN_CONTROL {
  1414.     LUID TokenId;
  1415.     LUID AuthenticationId;
  1416.     LUID ModifiedId;
  1417.     TOKEN_SOURCE TokenSource;
  1418.     } TOKEN_CONTROL, *PTOKEN_CONTROL;
  1419. //
  1420. // Security Tracking Mode
  1421. //
  1422. #define SECURITY_DYNAMIC_TRACKING      (TRUE)
  1423. #define SECURITY_STATIC_TRACKING       (FALSE)
  1424. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  1425.                     * PSECURITY_CONTEXT_TRACKING_MODE;
  1426. //
  1427. // Quality Of Service
  1428. //
  1429. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  1430.     DWORD Length;
  1431.     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  1432.     SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  1433.     BOOLEAN EffectiveOnly;
  1434.     } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  1435. //
  1436. // Used to represent information related to a thread impersonation
  1437. //
  1438. typedef struct _SE_IMPERSONATION_STATE {
  1439.     PACCESS_TOKEN Token;
  1440.     BOOLEAN CopyOnOpen;
  1441.     BOOLEAN EffectiveOnly;
  1442.     SECURITY_IMPERSONATION_LEVEL Level;
  1443. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  1444. #define DISABLE_MAX_PRIVILEGE   0x1 
  1445. #define SANDBOX_INERT           0x2 
  1446. typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  1447. #define OWNER_SECURITY_INFORMATION       (0x00000001L)
  1448. #define GROUP_SECURITY_INFORMATION       (0x00000002L)
  1449. #define DACL_SECURITY_INFORMATION        (0x00000004L)
  1450. #define SACL_SECURITY_INFORMATION        (0x00000008L)
  1451. #define PROTECTED_DACL_SECURITY_INFORMATION     (0x80000000L)
  1452. #define PROTECTED_SACL_SECURITY_INFORMATION     (0x40000000L)
  1453. #define UNPROTECTED_DACL_SECURITY_INFORMATION   (0x20000000L)
  1454. #define UNPROTECTED_SACL_SECURITY_INFORMATION   (0x10000000L)
  1455. #define PROCESS_TERMINATE         (0x0001)  
  1456. #define PROCESS_CREATE_THREAD     (0x0002)  
  1457. #define PROCESS_SET_SESSIONID     (0x0004)  
  1458. #define PROCESS_VM_OPERATION      (0x0008)  
  1459. #define PROCESS_VM_READ           (0x0010)  
  1460. #define PROCESS_VM_WRITE          (0x0020)  
  1461. #define PROCESS_DUP_HANDLE        (0x0040)  
  1462. #define PROCESS_CREATE_PROCESS    (0x0080)  
  1463. #define PROCESS_SET_QUOTA         (0x0100)  
  1464. #define PROCESS_SET_INFORMATION   (0x0200)  
  1465. #define PROCESS_QUERY_INFORMATION (0x0400)  
  1466. #define PROCESS_SUSPEND_RESUME    (0x0800)  
  1467. #define PROCESS_ALL_ACCESS        (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 
  1468.                                    0xFFF)
  1469. // begin_nthal
  1470. #if defined(_WIN64)
  1471. #define MAXIMUM_PROCESSORS 64
  1472. #else
  1473. #define MAXIMUM_PROCESSORS 32
  1474. #endif
  1475. // end_nthal
  1476. #define THREAD_TERMINATE               (0x0001)  
  1477. #define THREAD_SUSPEND_RESUME          (0x0002)  
  1478. #define THREAD_GET_CONTEXT             (0x0008)  
  1479. #define THREAD_SET_CONTEXT             (0x0010)  
  1480. #define THREAD_SET_INFORMATION         (0x0020)  
  1481. #define THREAD_QUERY_INFORMATION       (0x0040)  
  1482. #define THREAD_SET_THREAD_TOKEN        (0x0080)
  1483. #define THREAD_IMPERSONATE             (0x0100)
  1484. #define THREAD_DIRECT_IMPERSONATION    (0x0200)
  1485. // begin_ntddk begin_wdm begin_ntifs
  1486. #define THREAD_ALL_ACCESS         (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 
  1487.                                    0x3FF)
  1488. // end_ntddk end_wdm end_ntifs
  1489. #define JOB_OBJECT_ASSIGN_PROCESS           (0x0001)
  1490. #define JOB_OBJECT_SET_ATTRIBUTES           (0x0002)
  1491. #define JOB_OBJECT_QUERY                    (0x0004)
  1492. #define JOB_OBJECT_TERMINATE                (0x0008)
  1493. #define JOB_OBJECT_SET_SECURITY_ATTRIBUTES  (0x0010)
  1494. #define JOB_OBJECT_ALL_ACCESS       (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 
  1495.                                         0x1F )
  1496. typedef struct _JOB_SET_ARRAY {
  1497.     HANDLE JobHandle;   // Handle to job object to insert
  1498.     DWORD MemberLevel;  // Level of this job in the set. Must be > 0. Can be sparse.
  1499.     DWORD Flags;        // Unused. Must be zero
  1500. } JOB_SET_ARRAY, *PJOB_SET_ARRAY;
  1501. #define TLS_MINIMUM_AVAILABLE 64    
  1502. typedef struct _NT_TIB {
  1503.     struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
  1504.     PVOID StackBase;
  1505.     PVOID StackLimit;
  1506.     PVOID SubSystemTib;
  1507.     union {
  1508.         PVOID FiberData;
  1509.         DWORD Version;
  1510.     };
  1511.     PVOID ArbitraryUserPointer;
  1512.     struct _NT_TIB *Self;
  1513. } NT_TIB;
  1514. typedef NT_TIB *PNT_TIB;
  1515. //
  1516. // 32 and 64 bit specific version for wow64 and the debugger
  1517. //
  1518. typedef struct _NT_TIB32 {
  1519.     DWORD ExceptionList;
  1520.     DWORD StackBase;
  1521.     DWORD StackLimit;
  1522.     DWORD SubSystemTib;
  1523.     union {
  1524.         DWORD FiberData;
  1525.         DWORD Version;
  1526.     };
  1527.     DWORD ArbitraryUserPointer;
  1528.     DWORD Self;
  1529. } NT_TIB32, *PNT_TIB32;
  1530. typedef struct _NT_TIB64 {
  1531.     DWORD64 ExceptionList;
  1532.     DWORD64 StackBase;
  1533.     DWORD64 StackLimit;
  1534.     DWORD64 SubSystemTib;
  1535.     union {
  1536.         DWORD64 FiberData;
  1537.         DWORD Version;
  1538.     };
  1539.     DWORD64 ArbitraryUserPointer;
  1540.     DWORD64 Self;
  1541. } NT_TIB64, *PNT_TIB64;
  1542. #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_)
  1543. #define WX86
  1544. #endif
  1545. #define THREAD_BASE_PRIORITY_LOWRT  15  // value that gets a thread to LowRealtime-1
  1546. #define THREAD_BASE_PRIORITY_MAX    2   // maximum thread base priority boost
  1547. #define THREAD_BASE_PRIORITY_MIN    (-2)  // minimum thread base priority boost
  1548. #define THREAD_BASE_PRIORITY_IDLE   (-15) // value that gets a thread to idle
  1549. typedef struct _QUOTA_LIMITS {
  1550.     SIZE_T PagedPoolLimit;
  1551.     SIZE_T NonPagedPoolLimit;
  1552.     SIZE_T MinimumWorkingSetSize;
  1553.     SIZE_T MaximumWorkingSetSize;
  1554.     SIZE_T PagefileLimit;
  1555.     LARGE_INTEGER TimeLimit;
  1556. } QUOTA_LIMITS;
  1557. typedef QUOTA_LIMITS *PQUOTA_LIMITS;
  1558. typedef struct _IO_COUNTERS {
  1559.     ULONGLONG  ReadOperationCount;
  1560.     ULONGLONG  WriteOperationCount;
  1561.     ULONGLONG  OtherOperationCount;
  1562.     ULONGLONG ReadTransferCount;
  1563.     ULONGLONG WriteTransferCount;
  1564.     ULONGLONG OtherTransferCount;
  1565. } IO_COUNTERS;
  1566. typedef IO_COUNTERS *PIO_COUNTERS;
  1567. //
  1568. typedef struct _JOBOBJECT_BASIC_ACCOUNTING_INFORMATION {
  1569.     LARGE_INTEGER TotalUserTime;
  1570.     LARGE_INTEGER TotalKernelTime;
  1571.     LARGE_INTEGER ThisPeriodTotalUserTime;
  1572.     LARGE_INTEGER ThisPeriodTotalKernelTime;
  1573.     DWORD TotalPageFaultCount;
  1574.     DWORD TotalProcesses;
  1575.     DWORD ActiveProcesses;
  1576.     DWORD TotalTerminatedProcesses;
  1577. } JOBOBJECT_BASIC_ACCOUNTING_INFORMATION, *PJOBOBJECT_BASIC_ACCOUNTING_INFORMATION;
  1578. typedef struct _JOBOBJECT_BASIC_LIMIT_INFORMATION {
  1579.     LARGE_INTEGER PerProcessUserTimeLimit;
  1580.     LARGE_INTEGER PerJobUserTimeLimit;
  1581.     DWORD LimitFlags;
  1582.     SIZE_T MinimumWorkingSetSize;
  1583.     SIZE_T MaximumWorkingSetSize;
  1584.     DWORD ActiveProcessLimit;
  1585.     ULONG_PTR Affinity;
  1586.     DWORD PriorityClass;
  1587.     DWORD SchedulingClass;
  1588. } JOBOBJECT_BASIC_LIMIT_INFORMATION, *PJOBOBJECT_BASIC_LIMIT_INFORMATION;
  1589. typedef struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
  1590.     JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
  1591.     IO_COUNTERS IoInfo;
  1592.     SIZE_T ProcessMemoryLimit;
  1593.     SIZE_T JobMemoryLimit;
  1594.     SIZE_T PeakProcessMemoryUsed;
  1595.     SIZE_T PeakJobMemoryUsed;
  1596. } JOBOBJECT_EXTENDED_LIMIT_INFORMATION, *PJOBOBJECT_EXTENDED_LIMIT_INFORMATION;
  1597. typedef struct _JOBOBJECT_BASIC_PROCESS_ID_LIST {
  1598.     DWORD NumberOfAssignedProcesses;
  1599.     DWORD NumberOfProcessIdsInList;
  1600.     ULONG_PTR ProcessIdList[1];
  1601. } JOBOBJECT_BASIC_PROCESS_ID_LIST, *PJOBOBJECT_BASIC_PROCESS_ID_LIST;
  1602. typedef struct _JOBOBJECT_BASIC_UI_RESTRICTIONS {
  1603.     DWORD UIRestrictionsClass;
  1604. } JOBOBJECT_BASIC_UI_RESTRICTIONS, *PJOBOBJECT_BASIC_UI_RESTRICTIONS;
  1605. typedef struct _JOBOBJECT_SECURITY_LIMIT_INFORMATION {
  1606.     DWORD SecurityLimitFlags ;
  1607.     HANDLE JobToken ;
  1608.     PTOKEN_GROUPS SidsToDisable ;
  1609.     PTOKEN_PRIVILEGES PrivilegesToDelete ;
  1610.     PTOKEN_GROUPS RestrictedSids ;
  1611. } JOBOBJECT_SECURITY_LIMIT_INFORMATION, *PJOBOBJECT_SECURITY_LIMIT_INFORMATION ;
  1612. typedef struct _JOBOBJECT_END_OF_JOB_TIME_INFORMATION {
  1613.     DWORD EndOfJobTimeAction;
  1614. } JOBOBJECT_END_OF_JOB_TIME_INFORMATION, *PJOBOBJECT_END_OF_JOB_TIME_INFORMATION;
  1615. typedef struct _JOBOBJECT_ASSOCIATE_COMPLETION_PORT {
  1616.     PVOID CompletionKey;
  1617.     HANDLE CompletionPort;
  1618. } JOBOBJECT_ASSOCIATE_COMPLETION_PORT, *PJOBOBJECT_ASSOCIATE_COMPLETION_PORT;
  1619. typedef struct _JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION {
  1620.     JOBOBJECT_BASIC_ACCOUNTING_INFORMATION BasicInfo;
  1621.     IO_COUNTERS IoInfo;
  1622. } JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION, *PJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION;
  1623. typedef struct _JOBOBJECT_JOBSET_INFORMATION {
  1624.     DWORD MemberLevel;
  1625. } JOBOBJECT_JOBSET_INFORMATION, *PJOBOBJECT_JOBSET_INFORMATION;
  1626. #define JOB_OBJECT_TERMINATE_AT_END_OF_JOB  0
  1627. #define JOB_OBJECT_POST_AT_END_OF_JOB       1
  1628. //
  1629. // Completion Port Messages for job objects
  1630. //
  1631. // These values are returned via the lpNumberOfBytesTransferred parameter
  1632. //
  1633. #define JOB_OBJECT_MSG_END_OF_JOB_TIME          1
  1634. #define JOB_OBJECT_MSG_END_OF_PROCESS_TIME      2
  1635. #define JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT     3
  1636. #define JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO      4
  1637. #define JOB_OBJECT_MSG_NEW_PROCESS              6
  1638. #define JOB_OBJECT_MSG_EXIT_PROCESS             7
  1639. #define JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS    8
  1640. #define JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT     9
  1641. #define JOB_OBJECT_MSG_JOB_MEMORY_LIMIT         10
  1642. //
  1643. // Basic Limits
  1644. //
  1645. #define JOB_OBJECT_LIMIT_WORKINGSET                 0x00000001
  1646. #define JOB_OBJECT_LIMIT_PROCESS_TIME               0x00000002
  1647. #define JOB_OBJECT_LIMIT_JOB_TIME                   0x00000004
  1648. #define JOB_OBJECT_LIMIT_ACTIVE_PROCESS             0x00000008
  1649. #define JOB_OBJECT_LIMIT_AFFINITY                   0x00000010
  1650. #define JOB_OBJECT_LIMIT_PRIORITY_CLASS             0x00000020
  1651. #define JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME          0x00000040
  1652. #define JOB_OBJECT_LIMIT_SCHEDULING_CLASS           0x00000080
  1653. //
  1654. // Extended Limits
  1655. //
  1656. #define JOB_OBJECT_LIMIT_PROCESS_MEMORY             0x00000100
  1657. #define JOB_OBJECT_LIMIT_JOB_MEMORY                 0x00000200
  1658. #define JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION 0x00000400
  1659. #define JOB_OBJECT_LIMIT_BREAKAWAY_OK               0x00000800
  1660. #define JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK        0x00001000
  1661. #define JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE          0x00002000
  1662. #define JOB_OBJECT_LIMIT_RESERVED2                  0x00004000
  1663. #define JOB_OBJECT_LIMIT_RESERVED3                  0x00008000
  1664. #define JOB_OBJECT_LIMIT_RESERVED4                  0x00010000
  1665. #define JOB_OBJECT_LIMIT_RESERVED5                  0x00020000
  1666. #define JOB_OBJECT_LIMIT_RESERVED6                  0x00040000
  1667. #define JOB_OBJECT_LIMIT_VALID_FLAGS            0x0007ffff
  1668. #define JOB_OBJECT_BASIC_LIMIT_VALID_FLAGS      0x000000ff
  1669. #define JOB_OBJECT_EXTENDED_LIMIT_VALID_FLAGS   0x00003fff
  1670. #define JOB_OBJECT_RESERVED_LIMIT_VALID_FLAGS   0x0007ffff
  1671. //
  1672. // UI restrictions for jobs
  1673. //
  1674. #define JOB_OBJECT_UILIMIT_NONE             0x00000000
  1675. #define JOB_OBJECT_UILIMIT_HANDLES          0x00000001
  1676. #define JOB_OBJECT_UILIMIT_READCLIPBOARD    0x00000002
  1677. #define JOB_OBJECT_UILIMIT_WRITECLIPBOARD   0x00000004
  1678. #define JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS 0x00000008
  1679. #define JOB_OBJECT_UILIMIT_DISPLAYSETTINGS  0x00000010
  1680. #define JOB_OBJECT_UILIMIT_GLOBALATOMS      0x00000020
  1681. #define JOB_OBJECT_UILIMIT_DESKTOP          0x00000040
  1682. #define JOB_OBJECT_UILIMIT_EXITWINDOWS      0x00000080
  1683. #define JOB_OBJECT_UILIMIT_ALL              0x000000FF
  1684. #define JOB_OBJECT_UI_VALID_FLAGS           0x000000FF
  1685. #define JOB_OBJECT_SECURITY_NO_ADMIN            0x00000001
  1686. #define JOB_OBJECT_SECURITY_RESTRICTED_TOKEN    0x00000002
  1687. #define JOB_OBJECT_SECURITY_ONLY_TOKEN          0x00000004
  1688. #define JOB_OBJECT_SECURITY_FILTER_TOKENS       0x00000008
  1689. #define JOB_OBJECT_SECURITY_VALID_FLAGS         0x0000000f
  1690. typedef enum _JOBOBJECTINFOCLASS {
  1691.     JobObjectBasicAccountingInformation = 1,
  1692.     JobObjectBasicLimitInformation,
  1693.     JobObjectBasicProcessIdList,
  1694.     JobObjectBasicUIRestrictions,
  1695.     JobObjectSecurityLimitInformation,
  1696.     JobObjectEndOfJobTimeInformation,
  1697.     JobObjectAssociateCompletionPortInformation,
  1698.     JobObjectBasicAndIoAccountingInformation,
  1699.     JobObjectExtendedLimitInformation,
  1700.     JobObjectJobSetInformation,
  1701.     MaxJobObjectInfoClass
  1702.     } JOBOBJECTINFOCLASS;
  1703. //
  1704. #define EVENT_MODIFY_STATE      0x0002  
  1705. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  1706. #define MUTANT_QUERY_STATE      0x0001
  1707. #define MUTANT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|
  1708.                           MUTANT_QUERY_STATE)
  1709. #define SEMAPHORE_MODIFY_STATE      0x0002  
  1710. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  1711. //
  1712. // Timer Specific Access Rights.
  1713. //
  1714. #define TIMER_QUERY_STATE       0x0001
  1715. #define TIMER_MODIFY_STATE      0x0002
  1716. #define TIMER_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|
  1717.                           TIMER_QUERY_STATE|TIMER_MODIFY_STATE)
  1718. #define TIME_ZONE_ID_UNKNOWN  0
  1719. #define TIME_ZONE_ID_STANDARD 1
  1720. #define TIME_ZONE_ID_DAYLIGHT 2
  1721. #define MAXIMUM_NUMA_NODES 16
  1722. typedef struct _SYSTEM_NUMA_INFORMATION {
  1723.     DWORD       HighestNodeNumber;
  1724.     DWORD       Reserved;
  1725.     union {
  1726.         ULONGLONG   ActiveProcessorsAffinityMask[MAXIMUM_NUMA_NODES];
  1727.         ULONGLONG   AvailableMemory[MAXIMUM_NUMA_NODES];
  1728.     };
  1729. } SYSTEM_NUMA_INFORMATION, *PSYSTEM_NUMA_INFORMATION;
  1730. #define PROCESSOR_INTEL_386     386
  1731. #define PROCESSOR_INTEL_486     486
  1732. #define PROCESSOR_INTEL_PENTIUM 586
  1733. #define PROCESSOR_INTEL_IA64    2200
  1734. #define PROCESSOR_MIPS_R4000    4000    // incl R4101 & R3910 for Windows CE
  1735. #define PROCESSOR_ALPHA_21064   21064
  1736. #define PROCESSOR_PPC_601       601
  1737. #define PROCESSOR_PPC_603       603
  1738. #define PROCESSOR_PPC_604       604
  1739. #define PROCESSOR_PPC_620       620
  1740. #define PROCESSOR_HITACHI_SH3   10003   // Windows CE
  1741. #define PROCESSOR_HITACHI_SH3E  10004   // Windows CE
  1742. #define PROCESSOR_HITACHI_SH4   10005   // Windows CE
  1743. #define PROCESSOR_MOTOROLA_821  821     // Windows CE
  1744. #define PROCESSOR_SHx_SH3       103     // Windows CE
  1745. #define PROCESSOR_SHx_SH4       104     // Windows CE
  1746. #define PROCESSOR_STRONGARM     2577    // Windows CE - 0xA11
  1747. #define PROCESSOR_ARM720        1824    // Windows CE - 0x720
  1748. #define PROCESSOR_ARM820        2080    // Windows CE - 0x820
  1749. #define PROCESSOR_ARM920        2336    // Windows CE - 0x920
  1750. #define PROCESSOR_ARM_7TDMI     70001   // Windows CE
  1751. #define PROCESSOR_OPTIL         0x494f  // MSIL
  1752. #define PROCESSOR_ARCHITECTURE_INTEL            0
  1753. #define PROCESSOR_ARCHITECTURE_MIPS             1
  1754. #define PROCESSOR_ARCHITECTURE_ALPHA            2
  1755. #define PROCESSOR_ARCHITECTURE_PPC              3
  1756. #define PROCESSOR_ARCHITECTURE_SHX              4
  1757. #define PROCESSOR_ARCHITECTURE_ARM              5
  1758. #define PROCESSOR_ARCHITECTURE_IA64             6
  1759. #define PROCESSOR_ARCHITECTURE_ALPHA64          7
  1760. #define PROCESSOR_ARCHITECTURE_MSIL             8
  1761. #define PROCESSOR_ARCHITECTURE_AMD64            9
  1762. #define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64    10
  1763. #define PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF
  1764. #define PF_FLOATING_POINT_PRECISION_ERRATA  0   
  1765. #define PF_FLOATING_POINT_EMULATED          1   
  1766. #define PF_COMPARE_EXCHANGE_DOUBLE          2   
  1767. #define PF_MMX_INSTRUCTIONS_AVAILABLE       3   
  1768. #define PF_PPC_MOVEMEM_64BIT_OK             4   
  1769. #define PF_ALPHA_BYTE_INSTRUCTIONS          5   
  1770. #define PF_XMMI_INSTRUCTIONS_AVAILABLE      6   
  1771. #define PF_3DNOW_INSTRUCTIONS_AVAILABLE     7   
  1772. #define PF_RDTSC_INSTRUCTION_AVAILABLE      8   
  1773. #define PF_PAE_ENABLED                      9   
  1774. #define PF_XMMI64_INSTRUCTIONS_AVAILABLE   10   
  1775. typedef struct _MEMORY_BASIC_INFORMATION {
  1776.     PVOID BaseAddress;
  1777.     PVOID AllocationBase;
  1778.     DWORD AllocationProtect;
  1779.     SIZE_T RegionSize;
  1780.     DWORD State;
  1781.     DWORD Protect;
  1782.     DWORD Type;
  1783. } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
  1784. typedef struct _MEMORY_BASIC_INFORMATION32 {
  1785.     DWORD BaseAddress;
  1786.     DWORD AllocationBase;
  1787.     DWORD AllocationProtect;
  1788.     DWORD RegionSize;
  1789.     DWORD State;
  1790.     DWORD Protect;
  1791.     DWORD Type;
  1792. } MEMORY_BASIC_INFORMATION32, *PMEMORY_BASIC_INFORMATION32;
  1793. typedef struct _MEMORY_BASIC_INFORMATION64 {
  1794.     ULONGLONG BaseAddress;
  1795.     ULONGLONG AllocationBase;
  1796.     DWORD     AllocationProtect;
  1797.     DWORD     __alignment1;
  1798.     ULONGLONG RegionSize;
  1799.     DWORD     State;
  1800.     DWORD     Protect;
  1801.     DWORD     Type;
  1802.     DWORD     __alignment2;
  1803. } MEMORY_BASIC_INFORMATION64, *PMEMORY_BASIC_INFORMATION64;
  1804. #define SECTION_QUERY       0x0001
  1805. #define SECTION_MAP_WRITE   0x0002
  1806. #define SECTION_MAP_READ    0x0004
  1807. #define SECTION_MAP_EXECUTE 0x0008
  1808. #define SECTION_EXTEND_SIZE 0x0010
  1809. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|
  1810.                             SECTION_MAP_WRITE |      
  1811.                             SECTION_MAP_READ |       
  1812.                             SECTION_MAP_EXECUTE |    
  1813.                             SECTION_EXTEND_SIZE)
  1814. #define PAGE_NOACCESS          0x01     
  1815. #define PAGE_READONLY          0x02     
  1816. #define PAGE_READWRITE         0x04     
  1817. #define PAGE_WRITECOPY         0x08     
  1818. #define PAGE_EXECUTE           0x10     
  1819. #define PAGE_EXECUTE_READ      0x20     
  1820. #define PAGE_EXECUTE_READWRITE 0x40     
  1821. #define PAGE_EXECUTE_WRITECOPY 0x80     
  1822. #define PAGE_GUARD            0x100     
  1823. #define PAGE_NOCACHE          0x200     
  1824. #define PAGE_WRITECOMBINE     0x400     
  1825. #define MEM_COMMIT           0x1000     
  1826. #define MEM_RESERVE          0x2000     
  1827. #define MEM_DECOMMIT         0x4000     
  1828. #define MEM_RELEASE          0x8000     
  1829. #define MEM_FREE            0x10000     
  1830. #define MEM_PRIVATE         0x20000     
  1831. #define MEM_MAPPED          0x40000     
  1832. #define MEM_RESET           0x80000     
  1833. #define MEM_TOP_DOWN       0x100000     
  1834. #define MEM_WRITE_WATCH    0x200000     
  1835. #define MEM_PHYSICAL       0x400000     
  1836. #define MEM_4MB_PAGES    0x80000000     
  1837. #define SEC_FILE           0x800000     
  1838. #define SEC_IMAGE         0x1000000     
  1839. #define SEC_RESERVE       0x4000000     
  1840. #define SEC_COMMIT        0x8000000     
  1841. #define SEC_NOCACHE      0x10000000     
  1842. #define MEM_IMAGE         SEC_IMAGE     
  1843. #define WRITE_WATCH_FLAG_RESET 0x01     
  1844. //
  1845. // Define access rights to files and directories
  1846. //
  1847. //
  1848. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  1849. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  1850. // constants *MUST* always be in sync.
  1851. // The values are redefined in devioctl.h because they must be available to
  1852. // both DOS and NT.
  1853. //
  1854. #define FILE_READ_DATA            ( 0x0001 )    // file & pipe
  1855. #define FILE_LIST_DIRECTORY       ( 0x0001 )    // directory
  1856. #define FILE_WRITE_DATA           ( 0x0002 )    // file & pipe
  1857. #define FILE_ADD_FILE             ( 0x0002 )    // directory
  1858. #define FILE_APPEND_DATA          ( 0x0004 )    // file
  1859. #define FILE_ADD_SUBDIRECTORY     ( 0x0004 )    // directory
  1860. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 )    // named pipe
  1861. #define FILE_READ_EA              ( 0x0008 )    // file & directory
  1862. #define FILE_WRITE_EA             ( 0x0010 )    // file & directory
  1863. #define FILE_EXECUTE              ( 0x0020 )    // file
  1864. #define FILE_TRAVERSE             ( 0x0020 )    // directory
  1865. #define FILE_DELETE_CHILD         ( 0x0040 )    // directory
  1866. #define FILE_READ_ATTRIBUTES      ( 0x0080 )    // all
  1867. #define FILE_WRITE_ATTRIBUTES     ( 0x0100 )    // all
  1868. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  1869. #define FILE_GENERIC_READ         (STANDARD_RIGHTS_READ     |
  1870.                                    FILE_READ_DATA           |
  1871.                                    FILE_READ_ATTRIBUTES     |
  1872.                                    FILE_READ_EA             |
  1873.                                    SYNCHRONIZE)
  1874. #define FILE_GENERIC_WRITE        (STANDARD_RIGHTS_WRITE    |
  1875.                                    FILE_WRITE_DATA          |
  1876.                                    FILE_WRITE_ATTRIBUTES    |
  1877.                                    FILE_WRITE_EA            |
  1878.                                    FILE_APPEND_DATA         |
  1879.                                    SYNCHRONIZE)
  1880. #define FILE_GENERIC_EXECUTE      (STANDARD_RIGHTS_EXECUTE  |
  1881.                                    FILE_READ_ATTRIBUTES     |
  1882.                                    FILE_EXECUTE             |
  1883.                                    SYNCHRONIZE)
  1884. #define FILE_SHARE_READ                 0x00000001  
  1885. #define FILE_SHARE_WRITE                0x00000002  
  1886. #define FILE_SHARE_DELETE               0x00000004  
  1887. #define FILE_ATTRIBUTE_READONLY             0x00000001  
  1888. #define FILE_ATTRIBUTE_HIDDEN               0x00000002  
  1889. #define FILE_ATTRIBUTE_SYSTEM               0x00000004  
  1890. #define FILE_ATTRIBUTE_DIRECTORY            0x00000010  
  1891. #define FILE_ATTRIBUTE_ARCHIVE              0x00000020  
  1892. #define FILE_ATTRIBUTE_DEVICE               0x00000040  
  1893. #define FILE_ATTRIBUTE_NORMAL               0x00000080  
  1894. #define FILE_ATTRIBUTE_TEMPORARY            0x00000100  
  1895. #define FILE_ATTRIBUTE_SPARSE_FILE          0x00000200  
  1896. #define FILE_ATTRIBUTE_REPARSE_POINT        0x00000400  
  1897. #define FILE_ATTRIBUTE_COMPRESSED           0x00000800  
  1898. #define FILE_ATTRIBUTE_OFFLINE              0x00001000  
  1899. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000  
  1900. #define FILE_ATTRIBUTE_ENCRYPTED            0x00004000  
  1901. #define FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001   
  1902. #define FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002   
  1903. #define FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004   
  1904. #define FILE_NOTIFY_CHANGE_SIZE         0x00000008   
  1905. #define FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010   
  1906. #define FILE_NOTIFY_CHANGE_LAST_ACCESS  0x00000020   
  1907. #define FILE_NOTIFY_CHANGE_CREATION     0x00000040   
  1908. #define FILE_NOTIFY_CHANGE_SECURITY     0x00000100   
  1909. #define FILE_ACTION_ADDED                   0x00000001   
  1910. #define FILE_ACTION_REMOVED                 0x00000002   
  1911. #define FILE_ACTION_MODIFIED                0x00000003   
  1912. #define FILE_ACTION_RENAMED_OLD_NAME        0x00000004   
  1913. #define FILE_ACTION_RENAMED_NEW_NAME        0x00000005   
  1914. #define MAILSLOT_NO_MESSAGE             ((DWORD)-1) 
  1915. #define MAILSLOT_WAIT_FOREVER           ((DWORD)-1) 
  1916. #define FILE_CASE_SENSITIVE_SEARCH      0x00000001  
  1917. #define FILE_CASE_PRESERVED_NAMES       0x00000002  
  1918. #define FILE_UNICODE_ON_DISK            0x00000004  
  1919. #define FILE_PERSISTENT_ACLS            0x00000008  
  1920. #define FILE_FILE_COMPRESSION           0x00000010  
  1921. #define FILE_VOLUME_QUOTAS              0x00000020  
  1922. #define FILE_SUPPORTS_SPARSE_FILES      0x00000040  
  1923. #define FILE_SUPPORTS_REPARSE_POINTS    0x00000080  
  1924. #define FILE_SUPPORTS_REMOTE_STORAGE    0x00000100  
  1925. #define FILE_VOLUME_IS_COMPRESSED       0x00008000  
  1926. #define FILE_SUPPORTS_OBJECT_IDS        0x00010000  
  1927. #define FILE_SUPPORTS_ENCRYPTION        0x00020000  
  1928. #define FILE_NAMED_STREAMS              0x00040000  
  1929. #define FILE_READ_ONLY_VOLUME           0x00080000  
  1930. //
  1931. // Define the file notification information structure
  1932. //
  1933. typedef struct _FILE_NOTIFY_INFORMATION {
  1934.     DWORD NextEntryOffset;
  1935.     DWORD Action;
  1936.     DWORD FileNameLength;
  1937.     WCHAR FileName[1];
  1938. } FILE_NOTIFY_INFORMATION, *PFILE_NOTIFY_INFORMATION;
  1939. //
  1940. // Define segement buffer structure for scatter/gather read/write.
  1941. //
  1942. typedef union _FILE_SEGMENT_ELEMENT {
  1943.     PVOID64 Buffer;
  1944.     ULONGLONG Alignment;
  1945. }FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
  1946. //
  1947. // The reparse GUID structure is used by all 3rd party layered drivers to
  1948. // store data in a reparse point. For non-Microsoft tags, The GUID field
  1949. // cannot be GUID_NULL.
  1950. // The constraints on reparse tags are defined below.
  1951. // Microsoft tags can also be used with this format of the reparse point buffer.
  1952. //
  1953. typedef struct _REPARSE_GUID_DATA_BUFFER {
  1954.     DWORD  ReparseTag;
  1955.     WORD   ReparseDataLength;
  1956.     WORD   Reserved;
  1957.     GUID   ReparseGuid;
  1958.     struct {
  1959.         BYTE   DataBuffer[1];
  1960.     } GenericReparseBuffer;
  1961. } REPARSE_GUID_DATA_BUFFER, *PREPARSE_GUID_DATA_BUFFER;
  1962. #define REPARSE_GUID_DATA_BUFFER_HEADER_SIZE   FIELD_OFFSET(REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer)
  1963. //
  1964. // Maximum allowed size of the reparse data.
  1965. //
  1966. #define MAXIMUM_REPARSE_DATA_BUFFER_SIZE      ( 16 * 1024 )
  1967. //
  1968. // Predefined reparse tags.
  1969. // These tags need to avoid conflicting with IO_REMOUNT defined in ntosincio.h
  1970. //
  1971. #define IO_REPARSE_TAG_RESERVED_ZERO             (0)
  1972. #define IO_REPARSE_TAG_RESERVED_ONE              (1)
  1973. //
  1974. // The value of the following constant needs to satisfy the following conditions:
  1975. //  (1) Be at least as large as the largest of the reserved tags.
  1976. //  (2) Be strictly smaller than all the tags in use.
  1977. //
  1978. #define IO_REPARSE_TAG_RESERVED_RANGE            IO_REPARSE_TAG_RESERVED_ONE
  1979. //
  1980. // The reparse tags are a DWORD. The 32 bits are laid out as follows:
  1981. //
  1982. //   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  1983. //   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
  1984. //  +-+-+-+-+-----------------------+-------------------------------+
  1985. //  |M|R|N|R|     Reserved bits     |       Reparse Tag Value       |
  1986. //  +-+-+-+-+-----------------------+-------------------------------+
  1987. //
  1988. // M is the Microsoft bit. When set to 1, it denotes a tag owned by Microsoft.
  1989. //   All ISVs must use a tag with a 0 in this position.
  1990. //   Note: If a Microsoft tag is used by non-Microsoft software, the
  1991. //   behavior is not defined.
  1992. //
  1993. // R is reserved.  Must be zero for non-Microsoft tags.
  1994. //
  1995. // N is name surrogate. When set to 1, the file represents another named
  1996. //   entity in the system.
  1997. //
  1998. // The M and N bits are OR-able.
  1999. // The following macros check for the M and N bit values:
  2000. //
  2001. //
  2002. // Macro to determine whether a reparse point tag corresponds to a tag
  2003. // owned by Microsoft.
  2004. //
  2005. #define IsReparseTagMicrosoft(_tag) (              
  2006.                            ((_tag) & 0x80000000)   
  2007.                            )
  2008. //
  2009. // Macro to determine whether a reparse point tag is a name surrogate
  2010. //
  2011. #define IsReparseTagNameSurrogate(_tag) (          
  2012.                            ((_tag) & 0x20000000)   
  2013.                            )
  2014. #define IO_REPARSE_TAG_MOUNT_POINT               (0xA0000003L)        
  2015. #define IO_REPARSE_TAG_HSM                       (0xC0000004L)        
  2016. #define IO_REPARSE_TAG_SIS                       (0x80000007L)        
  2017. #define IO_REPARSE_TAG_FILTER_MANAGER            (0x8000000BL)        
  2018. #define IO_COMPLETION_MODIFY_STATE  0x0002  
  2019. #define IO_COMPLETION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) 
  2020. #define DUPLICATE_CLOSE_SOURCE      0x00000001  
  2021. #define DUPLICATE_SAME_ACCESS       0x00000002  
  2022. typedef enum _SYSTEM_POWER_STATE {
  2023.     PowerSystemUnspecified = 0,
  2024.     PowerSystemWorking     = 1,
  2025.     PowerSystemSleeping1   = 2,
  2026.     PowerSystemSleeping2   = 3,
  2027.     PowerSystemSleeping3   = 4,
  2028.     PowerSystemHibernate   = 5,
  2029.     PowerSystemShutdown    = 6,
  2030.     PowerSystemMaximum     = 7
  2031. } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
  2032. #define POWER_SYSTEM_MAXIMUM 7
  2033. typedef enum {
  2034.     PowerActionNone = 0,
  2035.     PowerActionReserved,
  2036.     PowerActionSleep,
  2037.     PowerActionHibernate,
  2038.     PowerActionShutdown,
  2039.     PowerActionShutdownReset,
  2040.     PowerActionShutdownOff,
  2041.     PowerActionWarmEject
  2042. } POWER_ACTION, *PPOWER_ACTION;
  2043. typedef enum _DEVICE_POWER_STATE {
  2044.     PowerDeviceUnspecified = 0,
  2045.     PowerDeviceD0,
  2046.     PowerDeviceD1,
  2047.     PowerDeviceD2,
  2048.     PowerDeviceD3,
  2049.     PowerDeviceMaximum
  2050. } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
  2051. #define ES_SYSTEM_REQUIRED  ((DWORD)0x00000001)
  2052. #define ES_DISPLAY_REQUIRED ((DWORD)0x00000002)
  2053. #define ES_USER_PRESENT     ((DWORD)0x00000004)
  2054. #define ES_CONTINUOUS       ((DWORD)0x80000000)
  2055. typedef DWORD EXECUTION_STATE;
  2056. typedef enum {
  2057.     LT_DONT_CARE,
  2058.     LT_LOWEST_LATENCY
  2059. } LATENCY_TIME;
  2060. // end_ntminiport end_ntifs end_wdm end_ntddk
  2061. //-----------------------------------------------------------------------------
  2062. // Device Power Information
  2063. // Accessable via CM_Get_DevInst_Registry_Property_Ex(CM_DRP_DEVICE_POWER_DATA)
  2064. //-----------------------------------------------------------------------------
  2065. #define PDCAP_D0_SUPPORTED              0x00000001
  2066. #define PDCAP_D1_SUPPORTED              0x00000002
  2067. #define PDCAP_D2_SUPPORTED              0x00000004
  2068. #define PDCAP_D3_SUPPORTED              0x00000008
  2069. #define PDCAP_WAKE_FROM_D0_SUPPORTED    0x00000010
  2070. #define PDCAP_WAKE_FROM_D1_SUPPORTED    0x00000020
  2071. #define PDCAP_WAKE_FROM_D2_SUPPORTED    0x00000040
  2072. #define PDCAP_WAKE_FROM_D3_SUPPORTED    0x00000080
  2073. #define PDCAP_WARM_EJECT_SUPPORTED      0x00000100
  2074. typedef struct CM_Power_Data_s {
  2075.     DWORD               PD_Size;
  2076.     DEVICE_POWER_STATE  PD_MostRecentPowerState;
  2077.     DWORD               PD_Capabilities;
  2078.     DWORD               PD_D1Latency;
  2079.     DWORD               PD_D2Latency;
  2080.     DWORD               PD_D3Latency;
  2081.     DEVICE_POWER_STATE  PD_PowerStateMapping[POWER_SYSTEM_MAXIMUM];
  2082.     SYSTEM_POWER_STATE  PD_DeepestSystemWake;
  2083. } CM_POWER_DATA, *PCM_POWER_DATA;
  2084. // begin_ntddk
  2085. typedef enum {
  2086.     SystemPowerPolicyAc,
  2087.     SystemPowerPolicyDc,
  2088.     VerifySystemPolicyAc,
  2089.     VerifySystemPolicyDc,
  2090.     SystemPowerCapabilities,
  2091.     SystemBatteryState,
  2092.     SystemPowerStateHandler,
  2093.     ProcessorStateHandler,
  2094.     SystemPowerPolicyCurrent,
  2095.     AdministratorPowerPolicy,
  2096.     SystemReserveHiberFile,
  2097.     ProcessorInformation,
  2098.     SystemPowerInformation,
  2099.     ProcessorStateHandler2,
  2100.     LastWakeTime,                                   // Compare with KeQueryInterruptTime()
  2101.     LastSleepTime,                                  // Compare with KeQueryInterruptTime()
  2102.     SystemExecutionState,
  2103.     SystemPowerStateNotifyHandler,
  2104.     ProcessorPowerPolicyAc,
  2105.     ProcessorPowerPolicyDc,
  2106.     VerifyProcessorPowerPolicyAc,
  2107.     VerifyProcessorPowerPolicyDc,
  2108.     ProcessorPowerPolicyCurrent
  2109. } POWER_INFORMATION_LEVEL;
  2110. // begin_wdm
  2111. //
  2112. // System power manager capabilities
  2113. //
  2114. typedef struct {
  2115.     DWORD       Granularity;
  2116.     DWORD       Capacity;
  2117. } BATTERY_REPORTING_SCALE, *PBATTERY_REPORTING_SCALE;
  2118. //
  2119. // Power Policy Management interfaces
  2120. //
  2121. typedef struct {
  2122.     POWER_ACTION    Action;
  2123.     DWORD           Flags;
  2124.     DWORD           EventCode;
  2125. } POWER_ACTION_POLICY, *PPOWER_ACTION_POLICY;
  2126. // POWER_ACTION_POLICY->Flags:
  2127. #define POWER_ACTION_QUERY_ALLOWED      0x00000001
  2128. #define POWER_ACTION_UI_ALLOWED         0x00000002
  2129. #define POWER_ACTION_OVERRIDE_APPS      0x00000004
  2130. #define POWER_ACTION_LIGHTEST_FIRST     0x10000000
  2131. #define POWER_ACTION_LOCK_CONSOLE       0x20000000
  2132. #define POWER_ACTION_DISABLE_WAKES      0x40000000
  2133. #define POWER_ACTION_CRITICAL           0x80000000
  2134. // POWER_ACTION_POLICY->EventCode flags
  2135. #define POWER_LEVEL_USER_NOTIFY_TEXT    0x00000001
  2136. #define POWER_LEVEL_USER_NOTIFY_SOUND   0x00000002
  2137. #define POWER_LEVEL_USER_NOTIFY_EXEC    0x00000004
  2138. #define POWER_USER_NOTIFY_BUTTON        0x00000008
  2139. #define POWER_USER_NOTIFY_SHUTDOWN      0x00000010
  2140. #define POWER_FORCE_TRIGGER_RESET       0x80000000
  2141. // system battery drain policies
  2142. typedef struct {
  2143.     BOOLEAN                 Enable;
  2144.     BYTE                    Spare[3];
  2145.     DWORD                   BatteryLevel;
  2146.     POWER_ACTION_POLICY     PowerPolicy;
  2147.     SYSTEM_POWER_STATE      MinSystemState;
  2148. } SYSTEM_POWER_LEVEL, *PSYSTEM_POWER_LEVEL;
  2149. // Discharge policy constants
  2150. #define NUM_DISCHARGE_POLICIES      4
  2151. #define DISCHARGE_POLICY_CRITICAL   0
  2152. #define DISCHARGE_POLICY_LOW        1
  2153. //
  2154. // Throttling policies
  2155. //
  2156. #define PO_THROTTLE_NONE            0
  2157. #define PO_THROTTLE_CONSTANT        1
  2158. #define PO_THROTTLE_DEGRADE         2
  2159. #define PO_THROTTLE_ADAPTIVE        3
  2160. #define PO_THROTTLE_MAXIMUM         4   // not a policy, just a limit
  2161. // system power policies
  2162. typedef struct _SYSTEM_POWER_POLICY {
  2163.     DWORD                   Revision;       // 1
  2164.     // events
  2165.     POWER_ACTION_POLICY     PowerButton;
  2166.     POWER_ACTION_POLICY     SleepButton;
  2167.     POWER_ACTION_POLICY     LidClose;
  2168.     SYSTEM_POWER_STATE      LidOpenWake;
  2169.     DWORD                   Reserved;
  2170.     // "system idle" detection
  2171.     POWER_ACTION_POLICY     Idle;
  2172.     DWORD                   IdleTimeout;
  2173.     BYTE                    IdleSensitivity;
  2174.     // dynamic throttling policy
  2175.     //      PO_THROTTLE_NONE, PO_THROTTLE_CONSTANT, PO_THROTTLE_DEGRADE, or PO_THROTTLE_ADAPTIVE
  2176.     BYTE                    DynamicThrottle;
  2177.     BYTE                    Spare2[2];
  2178.     // meaning of power action "sleep"
  2179.     SYSTEM_POWER_STATE      MinSleep;
  2180.     SYSTEM_POWER_STATE      MaxSleep;
  2181.     SYSTEM_POWER_STATE      ReducedLatencySleep;
  2182.     DWORD                   WinLogonFlags;
  2183.     // parameters for dozing
  2184.     DWORD                   Spare3;
  2185.     DWORD                   DozeS4Timeout;
  2186.     // battery policies
  2187.     DWORD                   BroadcastCapacityResolution;
  2188.     SYSTEM_POWER_LEVEL      DischargePolicy[NUM_DISCHARGE_POLICIES];
  2189.     // video policies
  2190.     DWORD                   VideoTimeout;
  2191.     BOOLEAN                 VideoDimDisplay;
  2192.     DWORD                   VideoReserved[3];
  2193.     // hard disk policies
  2194.     DWORD                   SpindownTimeout;
  2195.     // processor policies
  2196.     BOOLEAN                 OptimizeForPower;
  2197.     BYTE                    FanThrottleTolerance;
  2198.     BYTE                    ForcedThrottle;
  2199.     BYTE                    MinThrottle;
  2200.     POWER_ACTION_POLICY     OverThrottled;
  2201. } SYSTEM_POWER_POLICY, *PSYSTEM_POWER_POLICY;
  2202. // processor power policy state
  2203. typedef struct _PROCESSOR_POWER_POLICY_INFO {
  2204.     // Time based information (will be converted to kernel units)
  2205.     DWORD                   TimeCheck;                      // in US
  2206.     DWORD                   DemoteLimit;                    // in US
  2207.     DWORD                   PromoteLimit;                   // in US
  2208.     // Percentage based information
  2209.     BYTE                    DemotePercent;
  2210.     BYTE                    PromotePercent;
  2211.     BYTE                    Spare[2];
  2212.     // Flags
  2213.     DWORD                   AllowDemotion:1;
  2214.     DWORD                   AllowPromotion:1;
  2215.     DWORD                   Reserved:30;
  2216. } PROCESSOR_POWER_POLICY_INFO, *PPROCESSOR_POWER_POLICY_INFO;
  2217. // processor power policy
  2218. typedef struct _PROCESSOR_POWER_POLICY {
  2219.     DWORD                       Revision;       // 1
  2220.     // Dynamic Throttling Policy
  2221.     BYTE                        DynamicThrottle;
  2222.     BYTE                        Spare[3];
  2223.     // Flags
  2224.     DWORD                       Reserved;
  2225.     // System policy information
  2226.     // The Array is last, in case it needs to be grown and the structure
  2227.     // revision incremented.
  2228.     DWORD                       PolicyCount;
  2229.     PROCESSOR_POWER_POLICY_INFO Policy[3];
  2230. } PROCESSOR_POWER_POLICY, *PPROCESSOR_POWER_POLICY;
  2231. // administrator power policy overrides
  2232. typedef struct _ADMINISTRATOR_POWER_POLICY {
  2233.     // meaning of power action "sleep"
  2234.     SYSTEM_POWER_STATE      MinSleep;
  2235.     SYSTEM_POWER_STATE      MaxSleep;
  2236.     // video policies
  2237.     DWORD                   MinVideoTimeout;
  2238.     DWORD                   MaxVideoTimeout;
  2239.     // disk policies
  2240.     DWORD                   MinSpindownTimeout;
  2241.     DWORD                   MaxSpindownTimeout;
  2242. } ADMINISTRATOR_POWER_POLICY, *PADMINISTRATOR_POWER_POLICY;
  2243. typedef struct {
  2244.     // Misc supported system features
  2245.     BOOLEAN             PowerButtonPresent;
  2246.     BOOLEAN             SleepButtonPresent;
  2247.     BOOLEAN             LidPresent;
  2248.     BOOLEAN             SystemS1;
  2249.     BOOLEAN             SystemS2;
  2250.     BOOLEAN             SystemS3;
  2251.     BOOLEAN             SystemS4;           // hibernate
  2252.     BOOLEAN             SystemS5;           // off
  2253.     BOOLEAN             HiberFilePresent;
  2254.     BOOLEAN             FullWake;
  2255.     BOOLEAN             VideoDimPresent;
  2256.     BOOLEAN             ApmPresent;
  2257.     BOOLEAN             UpsPresent;
  2258.     // Processors
  2259.     BOOLEAN             ThermalControl;
  2260.     BOOLEAN             ProcessorThrottle;
  2261.     BYTE                ProcessorMinThrottle;
  2262.     BYTE                ProcessorMaxThrottle;
  2263.     BYTE                spare2[4];
  2264.     // Disk
  2265.     BOOLEAN             DiskSpinDown;
  2266.     BYTE                spare3[8];
  2267.     // System Battery
  2268.     BOOLEAN             SystemBatteriesPresent;
  2269.     BOOLEAN             BatteriesAreShortTerm;
  2270.     BATTERY_REPORTING_SCALE BatteryScale[3];
  2271.     // Wake
  2272.     SYSTEM_POWER_STATE  AcOnLineWake;
  2273.     SYSTEM_POWER_STATE  SoftLidWake;
  2274.     SYSTEM_POWER_STATE  RtcWake;
  2275.     SYSTEM_POWER_STATE  MinDeviceWakeState; // note this may change on driver load
  2276.     SYSTEM_POWER_STATE  DefaultLowLatencyWake;
  2277. } SYSTEM_POWER_CAPABILITIES, *PSYSTEM_POWER_CAPABILITIES;
  2278. typedef struct {
  2279.     BOOLEAN             AcOnLine;
  2280.     BOOLEAN             BatteryPresent;
  2281.     BOOLEAN             Charging;
  2282.     BOOLEAN             Discharging;
  2283.     BOOLEAN             Spare1[4];
  2284.     DWORD               MaxCapacity;
  2285.     DWORD               RemainingCapacity;
  2286.     DWORD               Rate;
  2287.     DWORD               EstimatedTime;
  2288.     DWORD               DefaultAlert1;
  2289.     DWORD               DefaultAlert2;
  2290. } SYSTEM_BATTERY_STATE, *PSYSTEM_BATTERY_STATE;
  2291. //
  2292. // Image Format
  2293. //
  2294. #ifndef _MAC
  2295. #include "pshpack4.h"                   // 4 byte packing is the default
  2296. #define IMAGE_DOS_SIGNATURE                 0x5A4D      // MZ
  2297. #define IMAGE_OS2_SIGNATURE                 0x454E      // NE
  2298. #define IMAGE_OS2_SIGNATURE_LE              0x454C      // LE
  2299. #define IMAGE_VXD_SIGNATURE                 0x454C      // LE
  2300. #define IMAGE_NT_SIGNATURE                  0x00004550  // PE00
  2301. #include "pshpack2.h"                   // 16 bit headers are 2 byte packed
  2302. #else
  2303. #include "pshpack1.h"
  2304. #define IMAGE_DOS_SIGNATURE                 0x4D5A      // MZ
  2305. #define IMAGE_OS2_SIGNATURE                 0x4E45      // NE
  2306. #define IMAGE_OS2_SIGNATURE_LE              0x4C45      // LE
  2307. #define IMAGE_NT_SIGNATURE                  0x50450000  // PE00
  2308. #endif
  2309. typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
  2310.     WORD   e_magic;                     // Magic number
  2311.     WORD   e_cblp;                      // Bytes on last page of file
  2312.     WORD   e_cp;                        // Pages in file
  2313.     WORD   e_crlc;                      // Relocations
  2314.     WORD   e_cparhdr;                   // Size of header in paragraphs
  2315.     WORD   e_minalloc;                  // Minimum extra paragraphs needed
  2316.     WORD   e_maxalloc;                  // Maximum extra paragraphs needed
  2317.     WORD   e_ss;                        // Initial (relative) SS value
  2318.     WORD   e_sp;                        // Initial SP value
  2319.     WORD   e_csum;                      // Checksum
  2320.     WORD   e_ip;                        // Initial IP value
  2321.     WORD   e_cs;                        // Initial (relative) CS value
  2322.     WORD   e_lfarlc;                    // File address of relocation table
  2323.     WORD   e_ovno;                      // Overlay number
  2324.     WORD   e_res[4];                    // Reserved words
  2325.     WORD   e_oemid;                     // OEM identifier (for e_oeminfo)
  2326.     WORD   e_oeminfo;                   // OEM information; e_oemid specific
  2327.     WORD   e_res2[10];                  // Reserved words
  2328.     LONG   e_lfanew;                    // File address of new exe header
  2329.   } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
  2330. typedef struct _IMAGE_OS2_HEADER {      // OS/2 .EXE header
  2331.     WORD   ne_magic;                    // Magic number
  2332.     CHAR   ne_ver;                      // Version number
  2333.     CHAR   ne_rev;                      // Revision number
  2334.     WORD   ne_enttab;                   // Offset of Entry Table
  2335.     WORD   ne_cbenttab;                 // Number of bytes in Entry Table
  2336.     LONG   ne_crc;                      // Checksum of whole file
  2337.     WORD   ne_flags;                    // Flag word
  2338.     WORD   ne_autodata;                 // Automatic data segment number
  2339.     WORD   ne_heap;                     // Initial heap allocation
  2340.     WORD   ne_stack;                    // Initial stack allocation
  2341.     LONG   ne_csip;                     // Initial CS:IP setting
  2342.     LONG   ne_sssp;                     // Initial SS:SP setting
  2343.     WORD   ne_cseg;                     // Count of file segments
  2344.     WORD   ne_cmod;                     // Entries in Module Reference Table
  2345.     WORD   ne_cbnrestab;                // Size of non-resident name table
  2346.     WORD   ne_segtab;                   // Offset of Segment Table
  2347.     WORD   ne_rsrctab;                  // Offset of Resource Table
  2348.     WORD   ne_restab;                   // Offset of resident name table
  2349.     WORD   ne_modtab;                   // Offset of Module Reference Table
  2350.     WORD   ne_imptab;                   // Offset of Imported Names Table
  2351.     LONG   ne_nrestab;                  // Offset of Non-resident Names Table
  2352.     WORD   ne_cmovent;                  // Count of movable entries
  2353.     WORD   ne_align;                    // Segment alignment shift count
  2354.     WORD   ne_cres;                     // Count of resource segments
  2355.     BYTE   ne_exetyp;                   // Target Operating system
  2356.     BYTE   ne_flagsothers;              // Other .EXE flags
  2357.     WORD   ne_pretthunks;               // offset to return thunks
  2358.     WORD   ne_psegrefbytes;             // offset to segment ref. bytes
  2359.     WORD   ne_swaparea;                 // Minimum code swap area size
  2360.     WORD   ne_expver;                   // Expected Windows version number
  2361.   } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
  2362. typedef struct _IMAGE_VXD_HEADER {      // Windows VXD header
  2363.     WORD   e32_magic;                   // Magic number
  2364.     BYTE   e32_border;                  // The byte ordering for the VXD
  2365.     BYTE   e32_worder;                  // The word ordering for the VXD
  2366.     DWORD  e32_level;                   // The EXE format level for now = 0
  2367.     WORD   e32_cpu;                     // The CPU type
  2368.     WORD   e32_os;                      // The OS type
  2369.     DWORD  e32_ver;                     // Module version
  2370.     DWORD  e32_mflags;                  // Module flags
  2371.     DWORD  e32_mpages;                  // Module # pages
  2372.     DWORD  e32_startobj;                // Object # for instruction pointer
  2373.     DWORD  e32_eip;                     // Extended instruction pointer
  2374.     DWORD  e32_stackobj;                // Object # for stack pointer
  2375.     DWORD  e32_esp;                     // Extended stack pointer
  2376.     DWORD  e32_pagesize;                // VXD page size
  2377.     DWORD  e32_lastpagesize;            // Last page size in VXD
  2378.     DWORD  e32_fixupsize;               // Fixup section size
  2379.     DWORD  e32_fixupsum;                // Fixup section checksum
  2380.     DWORD  e32_ldrsize;                 // Loader section size
  2381.     DWORD  e32_ldrsum;                  // Loader section checksum
  2382.     DWORD  e32_objtab;                  // Object table offset
  2383.     DWORD  e32_objcnt;                  // Number of objects in module
  2384.     DWORD  e32_objmap;                  // Object page map offset
  2385.     DWORD  e32_itermap;                 // Object iterated data map offset
  2386.     DWORD  e32_rsrctab;                 // Offset of Resource Table
  2387.     DWORD  e32_rsrccnt;                 // Number of resource entries
  2388.     DWORD  e32_restab;                  // Offset of resident name table
  2389.     DWORD  e32_enttab;                  // Offset of Entry Table
  2390.     DWORD  e32_dirtab;                  // Offset of Module Directive Table
  2391.     DWORD  e32_dircnt;                  // Number of module directives
  2392.     DWORD  e32_fpagetab;                // Offset of Fixup Page Table
  2393.     DWORD  e32_frectab;                 // Offset of Fixup Record Table
  2394.     DWORD  e32_impmod;                  // Offset of Import Module Name Table
  2395.     DWORD  e32_impmodcnt;               // Number of entries in Import Module Name Table
  2396.     DWORD  e32_impproc;                 // Offset of Import Procedure Name Table
  2397.     DWORD  e32_pagesum;                 // Offset of Per-Page Checksum Table