Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9515 lines
316 KiB

  1. /*++ BUILD Version: 0092 Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. winnt.h
  5. Abstract:
  6. This module defines the 32-Bit Windows types and constants that are
  7. defined by NT, but exposed through the Win32 API.
  8. Revision History:
  9. --*/
  10. #ifndef _WINNT_
  11. #define _WINNT_
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include <ctype.h>
  16. #define ANYSIZE_ARRAY 1
  17. #if defined(_M_MRX000) && !(defined(MIDL_PASS) || defined(RC_INVOKED)) && defined(ENABLE_RESTRICTED)
  18. #define RESTRICTED_POINTER __restrict
  19. #else
  20. #define RESTRICTED_POINTER
  21. #endif
  22. #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64) || defined(_M_AMD64)
  23. #define UNALIGNED __unaligned
  24. #if defined(_WIN64)
  25. #define UNALIGNED64 __unaligned
  26. #else
  27. #define UNALIGNED64
  28. #endif
  29. #else
  30. #define UNALIGNED
  31. #define UNALIGNED64
  32. #endif
  33. #if defined(_WIN64) || defined(_M_ALPHA)
  34. #define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG)
  35. #define MEMORY_ALLOCATION_ALIGNMENT 16
  36. #else
  37. #define MAX_NATURAL_ALIGNMENT sizeof(DWORD)
  38. #define MEMORY_ALLOCATION_ALIGNMENT 8
  39. #endif
  40. //
  41. // TYPE_ALIGNMENT will return the alignment requirements of a given type for
  42. // the current platform.
  43. //
  44. #ifdef __cplusplus
  45. #if _MSC_VER >= 1300
  46. #define TYPE_ALIGNMENT( t ) __alignof(t)
  47. #endif
  48. #else
  49. #define TYPE_ALIGNMENT( t ) \
  50. FIELD_OFFSET( struct { char x; t test; }, test )
  51. #endif
  52. #if defined(_WIN64)
  53. #define PROBE_ALIGNMENT( _s ) (TYPE_ALIGNMENT( _s ) > TYPE_ALIGNMENT( DWORD ) ? \
  54. TYPE_ALIGNMENT( _s ) : TYPE_ALIGNMENT( DWORD ))
  55. #define PROBE_ALIGNMENT32( _s ) TYPE_ALIGNMENT( DWORD )
  56. #else
  57. #define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( DWORD )
  58. #endif
  59. //
  60. // C_ASSERT() can be used to perform many compile-time assertions:
  61. // type sizes, field offsets, etc.
  62. //
  63. // An assertion failure results in error C2118: negative subscript.
  64. //
  65. #define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
  66. #if !defined(_MAC) && (defined(_M_MRX000) || defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_VER >= 1100) && !(defined(MIDL_PASS) || defined(RC_INVOKED))
  67. #define POINTER_64 __ptr64
  68. typedef unsigned __int64 POINTER_64_INT;
  69. #if defined(_WIN64)
  70. #define POINTER_32 __ptr32
  71. #else
  72. #define POINTER_32
  73. #endif
  74. #else
  75. #if defined(_MAC) && defined(_MAC_INT_64)
  76. #define POINTER_64 __ptr64
  77. typedef unsigned __int64 POINTER_64_INT;
  78. #else
  79. #define POINTER_64
  80. typedef unsigned long POINTER_64_INT;
  81. #endif
  82. #define POINTER_32
  83. #endif
  84. #if defined(_IA64_) || defined(_AMD64_)
  85. #define FIRMWARE_PTR
  86. #else
  87. #define FIRMWARE_PTR POINTER_32
  88. #endif
  89. #include <basetsd.h>
  90. #if (defined(_M_IX86) || defined(_M_IA64) || defined(_M_AMD64)) && !defined(MIDL_PASS)
  91. #define DECLSPEC_IMPORT __declspec(dllimport)
  92. #else
  93. #define DECLSPEC_IMPORT
  94. #endif
  95. #ifndef DECLSPEC_NORETURN
  96. #if (_MSC_VER >= 1200) && !defined(MIDL_PASS)
  97. #define DECLSPEC_NORETURN __declspec(noreturn)
  98. #else
  99. #define DECLSPEC_NORETURN
  100. #endif
  101. #endif
  102. #ifndef DECLSPEC_ALIGN
  103. #if (_MSC_VER >= 1300) && !defined(MIDL_PASS)
  104. #define DECLSPEC_ALIGN(x) __declspec(align(x))
  105. #else
  106. #define DECLSPEC_ALIGN(x)
  107. #endif
  108. #endif
  109. #ifndef DECLSPEC_CACHEALIGN
  110. #define DECLSPEC_CACHEALIGN DECLSPEC_ALIGN(128)
  111. #endif
  112. #ifndef DECLSPEC_UUID
  113. #if (_MSC_VER >= 1100) && defined (__cplusplus)
  114. #define DECLSPEC_UUID(x) __declspec(uuid(x))
  115. #else
  116. #define DECLSPEC_UUID(x)
  117. #endif
  118. #endif
  119. #ifndef DECLSPEC_NOVTABLE
  120. #if (_MSC_VER >= 1100) && defined(__cplusplus)
  121. #define DECLSPEC_NOVTABLE __declspec(novtable)
  122. #else
  123. #define DECLSPEC_NOVTABLE
  124. #endif
  125. #endif
  126. #ifndef DECLSPEC_SELECTANY
  127. #if (_MSC_VER >= 1100)
  128. #define DECLSPEC_SELECTANY __declspec(selectany)
  129. #else
  130. #define DECLSPEC_SELECTANY
  131. #endif
  132. #endif
  133. #ifndef NOP_FUNCTION
  134. #if (_MSC_VER >= 1210)
  135. #define NOP_FUNCTION __noop
  136. #else
  137. #define NOP_FUNCTION (void)0
  138. #endif
  139. #endif
  140. #ifndef DECLSPEC_ADDRSAFE
  141. #if (_MSC_VER >= 1200) && (defined(_M_ALPHA) || defined(_M_AXP64))
  142. #define DECLSPEC_ADDRSAFE __declspec(address_safe)
  143. #else
  144. #define DECLSPEC_ADDRSAFE
  145. #endif
  146. #endif
  147. #ifndef DECLSPEC_NOINLINE
  148. #if (_MSC_VER >= 1300)
  149. #define DECLSPEC_NOINLINE __declspec(noinline)
  150. #else
  151. #define DECLSPEC_NOINLINE
  152. #endif
  153. #endif
  154. #ifndef FORCEINLINE
  155. #if (_MSC_VER >= 1200)
  156. #define FORCEINLINE __forceinline
  157. #else
  158. #define FORCEINLINE __inline
  159. #endif
  160. #endif
  161. #ifndef DECLSPEC_DEPRECATED
  162. #if (_MSC_VER >= 1300) && !defined(MIDL_PASS)
  163. #define DECLSPEC_DEPRECATED __declspec(deprecated)
  164. #define DEPRECATE_SUPPORTED
  165. #else
  166. #define DECLSPEC_DEPRECATED
  167. #undef DEPRECATE_SUPPORTED
  168. #endif
  169. #endif
  170. #ifdef DEPRECATE_DDK_FUNCTIONS
  171. #ifdef _NTDDK_
  172. #define DECLSPEC_DEPRECATED_DDK DECLSPEC_DEPRECATED
  173. #ifdef DEPRECATE_SUPPORTED
  174. #define PRAGMA_DEPRECATED_DDK 1
  175. #endif
  176. #else
  177. #define DECLSPEC_DEPRECATED_DDK
  178. #define PRAGMA_DEPRECATED_DDK 1
  179. #endif
  180. #else
  181. #define DECLSPEC_DEPRECATED_DDK
  182. #define PRAGMA_DEPRECATED_DDK 0
  183. #endif
  184. //
  185. // Void
  186. //
  187. typedef void *PVOID;
  188. typedef void * POINTER_64 PVOID64;
  189. #if ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)) && !defined(_M_AMD64)
  190. #define NTAPI __stdcall
  191. #else
  192. #define _cdecl
  193. #define NTAPI
  194. #endif
  195. //
  196. // Define API decoration for direct importing system DLL references.
  197. //
  198. #if !defined(_NTSYSTEM_)
  199. #define NTSYSAPI DECLSPEC_IMPORT
  200. #define NTSYSCALLAPI DECLSPEC_IMPORT
  201. #else
  202. #define NTSYSAPI
  203. #if defined(_NTDLLBUILD_)
  204. #define NTSYSCALLAPI
  205. #else
  206. #define NTSYSCALLAPI DECLSPEC_ADDRSAFE
  207. #endif
  208. #endif
  209. //
  210. // Basics
  211. //
  212. #ifndef VOID
  213. #define VOID void
  214. typedef char CHAR;
  215. typedef short SHORT;
  216. typedef long LONG;
  217. #endif
  218. //
  219. // UNICODE (Wide Character) types
  220. //
  221. #ifndef _MAC
  222. typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
  223. #else
  224. // some Macintosh compilers don't define wchar_t in a convenient location, or define it as a char
  225. typedef unsigned short WCHAR; // wc, 16-bit UNICODE character
  226. #endif
  227. typedef WCHAR *PWCHAR;
  228. typedef WCHAR *LPWCH, *PWCH;
  229. typedef CONST WCHAR *LPCWCH, *PCWCH;
  230. typedef WCHAR *NWPSTR;
  231. typedef WCHAR *LPWSTR, *PWSTR;
  232. typedef WCHAR UNALIGNED *LPUWSTR, *PUWSTR;
  233. typedef CONST WCHAR *LPCWSTR, *PCWSTR;
  234. typedef CONST WCHAR UNALIGNED *LPCUWSTR, *PCUWSTR;
  235. //
  236. // ANSI (Multi-byte Character) types
  237. //
  238. typedef CHAR *PCHAR;
  239. typedef CHAR *LPCH, *PCH;
  240. typedef CONST CHAR *LPCCH, *PCCH;
  241. typedef CHAR *NPSTR;
  242. typedef CHAR *LPSTR, *PSTR;
  243. typedef CONST CHAR *LPCSTR, *PCSTR;
  244. //
  245. // Neutral ANSI/UNICODE types and macros
  246. //
  247. #ifdef UNICODE // r_winnt
  248. #ifndef _TCHAR_DEFINED
  249. typedef WCHAR TCHAR, *PTCHAR;
  250. typedef WCHAR TBYTE , *PTBYTE ;
  251. #define _TCHAR_DEFINED
  252. #endif /* !_TCHAR_DEFINED */
  253. typedef LPWSTR LPTCH, PTCH;
  254. typedef LPWSTR PTSTR, LPTSTR;
  255. typedef LPCWSTR PCTSTR, LPCTSTR;
  256. typedef LPUWSTR PUTSTR, LPUTSTR;
  257. typedef LPCUWSTR PCUTSTR, LPCUTSTR;
  258. typedef LPWSTR LP;
  259. #define __TEXT(quote) L##quote // r_winnt
  260. #else /* UNICODE */ // r_winnt
  261. #ifndef _TCHAR_DEFINED
  262. typedef char TCHAR, *PTCHAR;
  263. typedef unsigned char TBYTE , *PTBYTE ;
  264. #define _TCHAR_DEFINED
  265. #endif /* !_TCHAR_DEFINED */
  266. typedef LPSTR LPTCH, PTCH;
  267. typedef LPSTR PTSTR, LPTSTR, PUTSTR, LPUTSTR;
  268. typedef LPCSTR PCTSTR, LPCTSTR, PCUTSTR, LPCUTSTR;
  269. #define __TEXT(quote) quote // r_winnt
  270. #endif /* UNICODE */ // r_winnt
  271. #define TEXT(quote) __TEXT(quote) // r_winnt
  272. typedef SHORT *PSHORT;
  273. typedef LONG *PLONG;
  274. #ifdef STRICT
  275. typedef void *HANDLE;
  276. #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
  277. #else
  278. typedef PVOID HANDLE;
  279. #define DECLARE_HANDLE(name) typedef HANDLE name
  280. #endif
  281. typedef HANDLE *PHANDLE;
  282. //
  283. // Flag (bit) fields
  284. //
  285. typedef BYTE FCHAR;
  286. typedef WORD FSHORT;
  287. typedef DWORD FLONG;
  288. // Component Object Model defines, and macros
  289. #ifndef _HRESULT_DEFINED
  290. #define _HRESULT_DEFINED
  291. typedef LONG HRESULT;
  292. #endif // !_HRESULT_DEFINED
  293. #ifdef __cplusplus
  294. #define EXTERN_C extern "C"
  295. #else
  296. #define EXTERN_C extern
  297. #endif
  298. #if defined(_WIN32) || defined(_MPPC_)
  299. // Win32 doesn't support __export
  300. #ifdef _68K_
  301. #define STDMETHODCALLTYPE __cdecl
  302. #else
  303. #define STDMETHODCALLTYPE __stdcall
  304. #endif
  305. #define STDMETHODVCALLTYPE __cdecl
  306. #define STDAPICALLTYPE __stdcall
  307. #define STDAPIVCALLTYPE __cdecl
  308. #else
  309. #define STDMETHODCALLTYPE __export __stdcall
  310. #define STDMETHODVCALLTYPE __export __cdecl
  311. #define STDAPICALLTYPE __export __stdcall
  312. #define STDAPIVCALLTYPE __export __cdecl
  313. #endif
  314. #define STDAPI EXTERN_C HRESULT STDAPICALLTYPE
  315. #define STDAPI_(type) EXTERN_C type STDAPICALLTYPE
  316. #define STDMETHODIMP HRESULT STDMETHODCALLTYPE
  317. #define STDMETHODIMP_(type) type STDMETHODCALLTYPE
  318. // The 'V' versions allow Variable Argument lists.
  319. #define STDAPIV EXTERN_C HRESULT STDAPIVCALLTYPE
  320. #define STDAPIV_(type) EXTERN_C type STDAPIVCALLTYPE
  321. #define STDMETHODIMPV HRESULT STDMETHODVCALLTYPE
  322. #define STDMETHODIMPV_(type) type STDMETHODVCALLTYPE
  323. typedef char CCHAR;
  324. typedef DWORD LCID;
  325. typedef PDWORD PLCID;
  326. typedef WORD LANGID;
  327. #define APPLICATION_ERROR_MASK 0x20000000
  328. #define ERROR_SEVERITY_SUCCESS 0x00000000
  329. #define ERROR_SEVERITY_INFORMATIONAL 0x40000000
  330. #define ERROR_SEVERITY_WARNING 0x80000000
  331. #define ERROR_SEVERITY_ERROR 0xC0000000
  332. //
  333. // _M_IX86 included so that EM CONTEXT structure compiles with
  334. // x86 programs. *** TBD should this be for all architectures?
  335. //
  336. //
  337. // 16 byte aligned type for 128 bit floats
  338. //
  339. //
  340. // For we define a 128 bit structure and use __declspec(align(16)) pragma to
  341. // align to 128 bits.
  342. //
  343. #if defined(_M_IA64) && !defined(MIDL_PASS)
  344. __declspec(align(16))
  345. #endif
  346. typedef struct _FLOAT128 {
  347. __int64 LowPart;
  348. __int64 HighPart;
  349. } FLOAT128;
  350. typedef FLOAT128 *PFLOAT128;
  351. //
  352. // __int64 is only supported by 2.0 and later midl.
  353. // __midl is set by the 2.0 midl and not by 1.0 midl.
  354. //
  355. #define _ULONGLONG_
  356. #if (!defined (_MAC) && (!defined(MIDL_PASS) || defined(__midl)) && (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64)))
  357. typedef __int64 LONGLONG;
  358. typedef unsigned __int64 ULONGLONG;
  359. #define MAXLONGLONG (0x7fffffffffffffff)
  360. #else
  361. #if defined(_MAC) && defined(_MAC_INT_64)
  362. typedef __int64 LONGLONG;
  363. typedef unsigned __int64 ULONGLONG;
  364. #define MAXLONGLONG (0x7fffffffffffffff)
  365. #else
  366. typedef double LONGLONG;
  367. typedef double ULONGLONG;
  368. #endif //_MAC and int64
  369. #endif
  370. typedef LONGLONG *PLONGLONG;
  371. typedef ULONGLONG *PULONGLONG;
  372. // Update Sequence Number
  373. typedef LONGLONG USN;
  374. #if defined(MIDL_PASS)
  375. typedef struct _LARGE_INTEGER {
  376. #else // MIDL_PASS
  377. typedef union _LARGE_INTEGER {
  378. struct {
  379. DWORD LowPart;
  380. LONG HighPart;
  381. };
  382. struct {
  383. DWORD LowPart;
  384. LONG HighPart;
  385. } u;
  386. #endif //MIDL_PASS
  387. LONGLONG QuadPart;
  388. } LARGE_INTEGER;
  389. typedef LARGE_INTEGER *PLARGE_INTEGER;
  390. #if defined(MIDL_PASS)
  391. typedef struct _ULARGE_INTEGER {
  392. #else // MIDL_PASS
  393. typedef union _ULARGE_INTEGER {
  394. struct {
  395. DWORD LowPart;
  396. DWORD HighPart;
  397. };
  398. struct {
  399. DWORD LowPart;
  400. DWORD HighPart;
  401. } u;
  402. #endif //MIDL_PASS
  403. ULONGLONG QuadPart;
  404. } ULARGE_INTEGER;
  405. typedef ULARGE_INTEGER *PULARGE_INTEGER;
  406. // end_ntminiport end_ntndis end_ntminitape
  407. //
  408. // Locally Unique Identifier
  409. //
  410. typedef struct _LUID {
  411. DWORD LowPart;
  412. LONG HighPart;
  413. } LUID, *PLUID;
  414. #define _DWORDLONG_
  415. typedef ULONGLONG DWORDLONG;
  416. typedef DWORDLONG *PDWORDLONG;
  417. //
  418. // Define operations to logically shift an int64 by 0..31 bits and to multiply
  419. // 32-bits by 32-bits to form a 64-bit product.
  420. //
  421. #if defined(MIDL_PASS) || defined(RC_INVOKED)
  422. //
  423. // Midl does not understand inline assembler. Therefore, the Rtl functions
  424. // are used for shifts by 0.31 and multiplies of 32-bits times 32-bits to
  425. // form a 64-bit product.
  426. //
  427. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  428. #define UInt32x32To64(a, b) ((ULONGLONG)((DWORD)(a)) * (ULONGLONG)((DWORD)(b)))
  429. #define Int64ShllMod32(a, b) ((ULONGLONG)(a) << (b))
  430. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  431. #define Int64ShrlMod32(a, b) ((ULONGLONG)(a) >> (b))
  432. #elif defined(_M_IX86)
  433. //
  434. // The x86 C compiler understands inline assembler. Therefore, inline functions
  435. // that employ inline assembler are used for shifts of 0..31. The multiplies
  436. // rely on the compiler recognizing the cast of the multiplicand to int64 to
  437. // generate the optimal code inline.
  438. //
  439. #define Int32x32To64( a, b ) (LONGLONG)((LONGLONG)(LONG)(a) * (LONG)(b))
  440. #define UInt32x32To64( a, b ) (ULONGLONG)((ULONGLONG)(DWORD)(a) * (DWORD)(b))
  441. ULONGLONG
  442. NTAPI
  443. Int64ShllMod32 (
  444. ULONGLONG Value,
  445. DWORD ShiftCount
  446. );
  447. LONGLONG
  448. NTAPI
  449. Int64ShraMod32 (
  450. LONGLONG Value,
  451. DWORD ShiftCount
  452. );
  453. ULONGLONG
  454. NTAPI
  455. Int64ShrlMod32 (
  456. ULONGLONG Value,
  457. DWORD ShiftCount
  458. );
  459. #if _MSC_VER >= 1200
  460. #pragma warning(push)
  461. #endif
  462. #pragma warning(disable:4035) // re-enable below
  463. __inline ULONGLONG
  464. NTAPI
  465. Int64ShllMod32 (
  466. ULONGLONG Value,
  467. DWORD ShiftCount
  468. )
  469. {
  470. __asm {
  471. mov ecx, ShiftCount
  472. mov eax, dword ptr [Value]
  473. mov edx, dword ptr [Value+4]
  474. shld edx, eax, cl
  475. shl eax, cl
  476. }
  477. }
  478. __inline LONGLONG
  479. NTAPI
  480. Int64ShraMod32 (
  481. LONGLONG Value,
  482. DWORD ShiftCount
  483. )
  484. {
  485. __asm {
  486. mov ecx, ShiftCount
  487. mov eax, dword ptr [Value]
  488. mov edx, dword ptr [Value+4]
  489. shrd eax, edx, cl
  490. sar edx, cl
  491. }
  492. }
  493. __inline ULONGLONG
  494. NTAPI
  495. Int64ShrlMod32 (
  496. ULONGLONG Value,
  497. DWORD ShiftCount
  498. )
  499. {
  500. __asm {
  501. mov ecx, ShiftCount
  502. mov eax, dword ptr [Value]
  503. mov edx, dword ptr [Value+4]
  504. shrd eax, edx, cl
  505. shr edx, cl
  506. }
  507. }
  508. #if _MSC_VER >= 1200
  509. #pragma warning(pop)
  510. #else
  511. #pragma warning(default:4035)
  512. #endif
  513. #elif defined(_68K_) || defined(_MPPC_)
  514. //
  515. // The Macintosh 68K and PowerPC compilers do not currently support int64.
  516. //
  517. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  518. #define UInt32x32To64(a, b) ((DWORDLONG)((DWORD)(a)) * (DWORDLONG)((DWORD)(b)))
  519. #define Int64ShllMod32(a, b) ((DWORDLONG)(a) << (b))
  520. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  521. #define Int64ShrlMod32(a, b) ((DWORDLONG)(a) >> (b))
  522. #elif defined(_M_IA64) || defined(_M_AMD64)
  523. //
  524. // IA64 and AMD64 have native 64-bit operations that are just as fast as their
  525. // 32-bit counter parts. Therefore, the int64 data type is used directly to form
  526. // shifts of 0..31 and multiplies of 32-bits times 32-bits to form a 64-bit
  527. // product.
  528. //
  529. #define Int32x32To64(a, b) ((LONGLONG)((LONG)(a)) * (LONGLONG)((LONG)(b)))
  530. #define UInt32x32To64(a, b) ((ULONGLONG)((DWORD)(a)) * (ULONGLONG)((DWORD)(b)))
  531. #define Int64ShllMod32(a, b) ((ULONGLONG)(a) << (b))
  532. #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
  533. #define Int64ShrlMod32(a, b) ((ULONGLONG)(a) >> (b))
  534. #else
  535. #error Must define a target architecture.
  536. #endif
  537. #define ANSI_NULL ((CHAR)0)
  538. #define UNICODE_NULL ((WCHAR)0)
  539. #define UNICODE_STRING_MAX_BYTES ((WORD ) 65534)
  540. #define UNICODE_STRING_MAX_CHARS (32767)
  541. typedef BYTE BOOLEAN;
  542. typedef BOOLEAN *PBOOLEAN;
  543. //
  544. // Doubly linked list structure. Can be used as either a list head, or
  545. // as link words.
  546. //
  547. typedef struct _LIST_ENTRY {
  548. struct _LIST_ENTRY *Flink;
  549. struct _LIST_ENTRY *Blink;
  550. } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;
  551. //
  552. // Singly linked list structure. Can be used as either a list head, or
  553. // as link words.
  554. //
  555. typedef struct _SINGLE_LIST_ENTRY {
  556. struct _SINGLE_LIST_ENTRY *Next;
  557. } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
  558. //
  559. // These are needed for portable debugger support.
  560. //
  561. typedef struct LIST_ENTRY32 {
  562. DWORD Flink;
  563. DWORD Blink;
  564. } LIST_ENTRY32;
  565. typedef LIST_ENTRY32 *PLIST_ENTRY32;
  566. typedef struct LIST_ENTRY64 {
  567. ULONGLONG Flink;
  568. ULONGLONG Blink;
  569. } LIST_ENTRY64;
  570. typedef LIST_ENTRY64 *PLIST_ENTRY64;
  571. #include <guiddef.h>
  572. #ifndef __OBJECTID_DEFINED
  573. #define __OBJECTID_DEFINED
  574. typedef struct _OBJECTID { // size is 20
  575. GUID Lineage;
  576. DWORD Uniquifier;
  577. } OBJECTID;
  578. #endif // !_OBJECTID_DEFINED
  579. #define MINCHAR 0x80
  580. #define MAXCHAR 0x7f
  581. #define MINSHORT 0x8000
  582. #define MAXSHORT 0x7fff
  583. #define MINLONG 0x80000000
  584. #define MAXLONG 0x7fffffff
  585. #define MAXBYTE 0xff
  586. #define MAXWORD 0xffff
  587. #define MAXDWORD 0xffffffff
  588. //
  589. // Calculate the byte offset of a field in a structure of type type.
  590. //
  591. #define FIELD_OFFSET(type, field) ((LONG)(LONG_PTR)&(((type *)0)->field))
  592. //
  593. // Calculate the size of a field in a structure of type type, without
  594. // knowing or stating the type of the field.
  595. //
  596. #define RTL_FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
  597. //
  598. // Calculate the size of a structure of type type up through and
  599. // including a field.
  600. //
  601. #define RTL_SIZEOF_THROUGH_FIELD(type, field) \
  602. (FIELD_OFFSET(type, field) + RTL_FIELD_SIZE(type, field))
  603. //
  604. // RTL_CONTAINS_FIELD usage:
  605. //
  606. // if (RTL_CONTAINS_FIELD(pBlock, pBlock->cbSize, dwMumble)) { // safe to use pBlock->dwMumble
  607. //
  608. #define RTL_CONTAINS_FIELD(Struct, Size, Field) \
  609. ( (((PCHAR)(&(Struct)->Field)) + sizeof((Struct)->Field)) <= (((PCHAR)(Struct))+(Size)) )
  610. //
  611. // Return the number of elements in a statically sized array.
  612. // DWORD Buffer[100];
  613. // RTL_NUMBER_OF(Buffer) == 100
  614. // This is also popularly known as: NUMBER_OF, ARRSIZE, _countof, NELEM, etc.
  615. //
  616. #define RTL_NUMBER_OF(A) (sizeof(A)/sizeof((A)[0]))
  617. //
  618. // An expression that yields the type of a field in a struct.
  619. //
  620. #define RTL_FIELD_TYPE(type, field) (((type*)0)->field)
  621. // RTL_ to avoid collisions in the global namespace.
  622. //
  623. // Given typedef struct _FOO { BYTE Bar[123]; } FOO;
  624. // RTL_NUMBER_OF_FIELD(FOO, Bar) == 123
  625. //
  626. #define RTL_NUMBER_OF_FIELD(type, field) (RTL_NUMBER_OF(RTL_FIELD_TYPE(type, field)))
  627. //
  628. // eg:
  629. // typedef struct FOO {
  630. // DWORD Integer;
  631. // PVOID Pointer;
  632. // } FOO;
  633. //
  634. // RTL_PADDING_BETWEEN_FIELDS(FOO, Integer, Pointer) == 0 for Win32, 4 for Win64
  635. //
  636. #define RTL_PADDING_BETWEEN_FIELDS(T, F1, F2) \
  637. ((FIELD_OFFSET(T, F2) > FIELD_OFFSET(T, F1)) \
  638. ? (FIELD_OFFSET(T, F2) - FIELD_OFFSET(T, F1) - RTL_FIELD_SIZE(T, F1)) \
  639. : (FIELD_OFFSET(T, F1) - FIELD_OFFSET(T, F2) - RTL_FIELD_SIZE(T, F2)))
  640. // RTL_ to avoid collisions in the global namespace.
  641. #if defined(__cplusplus)
  642. #define RTL_CONST_CAST(type) const_cast<type>
  643. #else
  644. #define RTL_CONST_CAST(type) (type)
  645. #endif
  646. // like sizeof
  647. // usually this would be * CHAR_BIT, but we don't necessarily have #include <limits.h>
  648. #define RTL_BITS_OF(sizeOfArg) (sizeof(sizeOfArg) * 8)
  649. #define RTL_BITS_OF_FIELD(type, field) (RTL_BITS_OF(RTL_FIELD_TYPE(type, field)))
  650. //
  651. // Calculate the address of the base of the structure given its type, and an
  652. // address of a field within the structure.
  653. //
  654. #define CONTAINING_RECORD(address, type, field) ((type *)( \
  655. (PCHAR)(address) - \
  656. (ULONG_PTR)(&((type *)0)->field)))
  657. #define VER_SERVER_NT 0x80000000
  658. #define VER_WORKSTATION_NT 0x40000000
  659. #define VER_SUITE_SMALLBUSINESS 0x00000001
  660. #define VER_SUITE_ENTERPRISE 0x00000002
  661. #define VER_SUITE_BACKOFFICE 0x00000004
  662. #define VER_SUITE_COMMUNICATIONS 0x00000008
  663. #define VER_SUITE_TERMINAL 0x00000010
  664. #define VER_SUITE_SMALLBUSINESS_RESTRICTED 0x00000020
  665. #define VER_SUITE_EMBEDDEDNT 0x00000040
  666. #define VER_SUITE_DATACENTER 0x00000080
  667. #define VER_SUITE_SINGLEUSERTS 0x00000100
  668. #define VER_SUITE_PERSONAL 0x00000200
  669. #define VER_SUITE_BLADE 0x00000400
  670. #define VER_SUITE_EMBEDDED_RESTRICTED 0x00000800
  671. #define VER_SUITE_SECURITY_APPLIANCE 0x00001000
  672. //
  673. // Language IDs.
  674. //
  675. // The following two combinations of primary language ID and
  676. // sublanguage ID have special semantics:
  677. //
  678. // Primary Language ID Sublanguage ID Result
  679. // ------------------- --------------- ------------------------
  680. // LANG_NEUTRAL SUBLANG_NEUTRAL Language neutral
  681. // LANG_NEUTRAL SUBLANG_DEFAULT User default language
  682. // LANG_NEUTRAL SUBLANG_SYS_DEFAULT System default language
  683. // LANG_INVARIANT SUBLANG_NEUTRAL Invariant locale
  684. //
  685. //
  686. // Primary language IDs.
  687. //
  688. #define LANG_NEUTRAL 0x00
  689. #define LANG_INVARIANT 0x7f
  690. #define LANG_AFRIKAANS 0x36
  691. #define LANG_ALBANIAN 0x1c
  692. #define LANG_ARABIC 0x01
  693. #define LANG_ARMENIAN 0x2b
  694. #define LANG_ASSAMESE 0x4d
  695. #define LANG_AZERI 0x2c
  696. #define LANG_BASQUE 0x2d
  697. #define LANG_BELARUSIAN 0x23
  698. #define LANG_BENGALI 0x45
  699. #define LANG_BULGARIAN 0x02
  700. #define LANG_CATALAN 0x03
  701. #define LANG_CHINESE 0x04
  702. #define LANG_CROATIAN 0x1a
  703. #define LANG_CZECH 0x05
  704. #define LANG_DANISH 0x06
  705. #define LANG_DIVEHI 0x65
  706. #define LANG_DUTCH 0x13
  707. #define LANG_ENGLISH 0x09
  708. #define LANG_ESTONIAN 0x25
  709. #define LANG_FAEROESE 0x38
  710. #define LANG_FARSI 0x29
  711. #define LANG_FINNISH 0x0b
  712. #define LANG_FRENCH 0x0c
  713. #define LANG_GALICIAN 0x56
  714. #define LANG_GEORGIAN 0x37
  715. #define LANG_GERMAN 0x07
  716. #define LANG_GREEK 0x08
  717. #define LANG_GUJARATI 0x47
  718. #define LANG_HEBREW 0x0d
  719. #define LANG_HINDI 0x39
  720. #define LANG_HUNGARIAN 0x0e
  721. #define LANG_ICELANDIC 0x0f
  722. #define LANG_INDONESIAN 0x21
  723. #define LANG_ITALIAN 0x10
  724. #define LANG_JAPANESE 0x11
  725. #define LANG_KANNADA 0x4b
  726. #define LANG_KASHMIRI 0x60
  727. #define LANG_KAZAK 0x3f
  728. #define LANG_KONKANI 0x57
  729. #define LANG_KOREAN 0x12
  730. #define LANG_KYRGYZ 0x40
  731. #define LANG_LATVIAN 0x26
  732. #define LANG_LITHUANIAN 0x27
  733. #define LANG_MACEDONIAN 0x2f // the Former Yugoslav Republic of Macedonia
  734. #define LANG_MALAY 0x3e
  735. #define LANG_MALAYALAM 0x4c
  736. #define LANG_MANIPURI 0x58
  737. #define LANG_MARATHI 0x4e
  738. #define LANG_MONGOLIAN 0x50
  739. #define LANG_NEPALI 0x61
  740. #define LANG_NORWEGIAN 0x14
  741. #define LANG_ORIYA 0x48
  742. #define LANG_POLISH 0x15
  743. #define LANG_PORTUGUESE 0x16
  744. #define LANG_PUNJABI 0x46
  745. #define LANG_ROMANIAN 0x18
  746. #define LANG_RUSSIAN 0x19
  747. #define LANG_SANSKRIT 0x4f
  748. #define LANG_SERBIAN 0x1a
  749. #define LANG_SINDHI 0x59
  750. #define LANG_SLOVAK 0x1b
  751. #define LANG_SLOVENIAN 0x24
  752. #define LANG_SPANISH 0x0a
  753. #define LANG_SWAHILI 0x41
  754. #define LANG_SWEDISH 0x1d
  755. #define LANG_SYRIAC 0x5a
  756. #define LANG_TAMIL 0x49
  757. #define LANG_TATAR 0x44
  758. #define LANG_TELUGU 0x4a
  759. #define LANG_THAI 0x1e
  760. #define LANG_TURKISH 0x1f
  761. #define LANG_UKRAINIAN 0x22
  762. #define LANG_URDU 0x20
  763. #define LANG_UZBEK 0x43
  764. #define LANG_VIETNAMESE 0x2a
  765. //
  766. // Sublanguage IDs.
  767. //
  768. // The name immediately following SUBLANG_ dictates which primary
  769. // language ID that sublanguage ID can be combined with to form a
  770. // valid language ID.
  771. //
  772. #define SUBLANG_NEUTRAL 0x00 // language neutral
  773. #define SUBLANG_DEFAULT 0x01 // user default
  774. #define SUBLANG_SYS_DEFAULT 0x02 // system default
  775. #define SUBLANG_ARABIC_SAUDI_ARABIA 0x01 // Arabic (Saudi Arabia)
  776. #define SUBLANG_ARABIC_IRAQ 0x02 // Arabic (Iraq)
  777. #define SUBLANG_ARABIC_EGYPT 0x03 // Arabic (Egypt)
  778. #define SUBLANG_ARABIC_LIBYA 0x04 // Arabic (Libya)
  779. #define SUBLANG_ARABIC_ALGERIA 0x05 // Arabic (Algeria)
  780. #define SUBLANG_ARABIC_MOROCCO 0x06 // Arabic (Morocco)
  781. #define SUBLANG_ARABIC_TUNISIA 0x07 // Arabic (Tunisia)
  782. #define SUBLANG_ARABIC_OMAN 0x08 // Arabic (Oman)
  783. #define SUBLANG_ARABIC_YEMEN 0x09 // Arabic (Yemen)
  784. #define SUBLANG_ARABIC_SYRIA 0x0a // Arabic (Syria)
  785. #define SUBLANG_ARABIC_JORDAN 0x0b // Arabic (Jordan)
  786. #define SUBLANG_ARABIC_LEBANON 0x0c // Arabic (Lebanon)
  787. #define SUBLANG_ARABIC_KUWAIT 0x0d // Arabic (Kuwait)
  788. #define SUBLANG_ARABIC_UAE 0x0e // Arabic (U.A.E)
  789. #define SUBLANG_ARABIC_BAHRAIN 0x0f // Arabic (Bahrain)
  790. #define SUBLANG_ARABIC_QATAR 0x10 // Arabic (Qatar)
  791. #define SUBLANG_AZERI_LATIN 0x01 // Azeri (Latin)
  792. #define SUBLANG_AZERI_CYRILLIC 0x02 // Azeri (Cyrillic)
  793. #define SUBLANG_CHINESE_TRADITIONAL 0x01 // Chinese (Taiwan)
  794. #define SUBLANG_CHINESE_SIMPLIFIED 0x02 // Chinese (PR China)
  795. #define SUBLANG_CHINESE_HONGKONG 0x03 // Chinese (Hong Kong S.A.R., P.R.C.)
  796. #define SUBLANG_CHINESE_SINGAPORE 0x04 // Chinese (Singapore)
  797. #define SUBLANG_CHINESE_MACAU 0x05 // Chinese (Macau S.A.R.)
  798. #define SUBLANG_DUTCH 0x01 // Dutch
  799. #define SUBLANG_DUTCH_BELGIAN 0x02 // Dutch (Belgian)
  800. #define SUBLANG_ENGLISH_US 0x01 // English (USA)
  801. #define SUBLANG_ENGLISH_UK 0x02 // English (UK)
  802. #define SUBLANG_ENGLISH_AUS 0x03 // English (Australian)
  803. #define SUBLANG_ENGLISH_CAN 0x04 // English (Canadian)
  804. #define SUBLANG_ENGLISH_NZ 0x05 // English (New Zealand)
  805. #define SUBLANG_ENGLISH_EIRE 0x06 // English (Irish)
  806. #define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07 // English (South Africa)
  807. #define SUBLANG_ENGLISH_JAMAICA 0x08 // English (Jamaica)
  808. #define SUBLANG_ENGLISH_CARIBBEAN 0x09 // English (Caribbean)
  809. #define SUBLANG_ENGLISH_BELIZE 0x0a // English (Belize)
  810. #define SUBLANG_ENGLISH_TRINIDAD 0x0b // English (Trinidad)
  811. #define SUBLANG_ENGLISH_ZIMBABWE 0x0c // English (Zimbabwe)
  812. #define SUBLANG_ENGLISH_PHILIPPINES 0x0d // English (Philippines)
  813. #define SUBLANG_FRENCH 0x01 // French
  814. #define SUBLANG_FRENCH_BELGIAN 0x02 // French (Belgian)
  815. #define SUBLANG_FRENCH_CANADIAN 0x03 // French (Canadian)
  816. #define SUBLANG_FRENCH_SWISS 0x04 // French (Swiss)
  817. #define SUBLANG_FRENCH_LUXEMBOURG 0x05 // French (Luxembourg)
  818. #define SUBLANG_FRENCH_MONACO 0x06 // French (Monaco)
  819. #define SUBLANG_GERMAN 0x01 // German
  820. #define SUBLANG_GERMAN_SWISS 0x02 // German (Swiss)
  821. #define SUBLANG_GERMAN_AUSTRIAN 0x03 // German (Austrian)
  822. #define SUBLANG_GERMAN_LUXEMBOURG 0x04 // German (Luxembourg)
  823. #define SUBLANG_GERMAN_LIECHTENSTEIN 0x05 // German (Liechtenstein)
  824. #define SUBLANG_ITALIAN 0x01 // Italian
  825. #define SUBLANG_ITALIAN_SWISS 0x02 // Italian (Swiss)
  826. #if _WIN32_WINNT >= 0x0501
  827. #define SUBLANG_KASHMIRI_SASIA 0x02 // Kashmiri (South Asia)
  828. #endif
  829. #define SUBLANG_KASHMIRI_INDIA 0x02 // For app compatibility only
  830. #define SUBLANG_KOREAN 0x01 // Korean (Extended Wansung)
  831. #define SUBLANG_LITHUANIAN 0x01 // Lithuanian
  832. #define SUBLANG_MALAY_MALAYSIA 0x01 // Malay (Malaysia)
  833. #define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02 // Malay (Brunei Darussalam)
  834. #define SUBLANG_NEPALI_INDIA 0x02 // Nepali (India)
  835. #define SUBLANG_NORWEGIAN_BOKMAL 0x01 // Norwegian (Bokmal)
  836. #define SUBLANG_NORWEGIAN_NYNORSK 0x02 // Norwegian (Nynorsk)
  837. #define SUBLANG_PORTUGUESE 0x02 // Portuguese
  838. #define SUBLANG_PORTUGUESE_BRAZILIAN 0x01 // Portuguese (Brazilian)
  839. #define SUBLANG_SERBIAN_LATIN 0x02 // Serbian (Latin)
  840. #define SUBLANG_SERBIAN_CYRILLIC 0x03 // Serbian (Cyrillic)
  841. #define SUBLANG_SPANISH 0x01 // Spanish (Castilian)
  842. #define SUBLANG_SPANISH_MEXICAN 0x02 // Spanish (Mexican)
  843. #define SUBLANG_SPANISH_MODERN 0x03 // Spanish (Spain)
  844. #define SUBLANG_SPANISH_GUATEMALA 0x04 // Spanish (Guatemala)
  845. #define SUBLANG_SPANISH_COSTA_RICA 0x05 // Spanish (Costa Rica)
  846. #define SUBLANG_SPANISH_PANAMA 0x06 // Spanish (Panama)
  847. #define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07 // Spanish (Dominican Republic)
  848. #define SUBLANG_SPANISH_VENEZUELA 0x08 // Spanish (Venezuela)
  849. #define SUBLANG_SPANISH_COLOMBIA 0x09 // Spanish (Colombia)
  850. #define SUBLANG_SPANISH_PERU 0x0a // Spanish (Peru)
  851. #define SUBLANG_SPANISH_ARGENTINA 0x0b // Spanish (Argentina)
  852. #define SUBLANG_SPANISH_ECUADOR 0x0c // Spanish (Ecuador)
  853. #define SUBLANG_SPANISH_CHILE 0x0d // Spanish (Chile)
  854. #define SUBLANG_SPANISH_URUGUAY 0x0e // Spanish (Uruguay)
  855. #define SUBLANG_SPANISH_PARAGUAY 0x0f // Spanish (Paraguay)
  856. #define SUBLANG_SPANISH_BOLIVIA 0x10 // Spanish (Bolivia)
  857. #define SUBLANG_SPANISH_EL_SALVADOR 0x11 // Spanish (El Salvador)
  858. #define SUBLANG_SPANISH_HONDURAS 0x12 // Spanish (Honduras)
  859. #define SUBLANG_SPANISH_NICARAGUA 0x13 // Spanish (Nicaragua)
  860. #define SUBLANG_SPANISH_PUERTO_RICO 0x14 // Spanish (Puerto Rico)
  861. #define SUBLANG_SWEDISH 0x01 // Swedish
  862. #define SUBLANG_SWEDISH_FINLAND 0x02 // Swedish (Finland)
  863. #define SUBLANG_URDU_PAKISTAN 0x01 // Urdu (Pakistan)
  864. #define SUBLANG_URDU_INDIA 0x02 // Urdu (India)
  865. #define SUBLANG_UZBEK_LATIN 0x01 // Uzbek (Latin)
  866. #define SUBLANG_UZBEK_CYRILLIC 0x02 // Uzbek (Cyrillic)
  867. //
  868. // Sorting IDs.
  869. //
  870. #define SORT_DEFAULT 0x0 // sorting default
  871. #define SORT_JAPANESE_XJIS 0x0 // Japanese XJIS order
  872. #define SORT_JAPANESE_UNICODE 0x1 // Japanese Unicode order
  873. #define SORT_CHINESE_BIG5 0x0 // Chinese BIG5 order
  874. #define SORT_CHINESE_PRCP 0x0 // PRC Chinese Phonetic order
  875. #define SORT_CHINESE_UNICODE 0x1 // Chinese Unicode order
  876. #define SORT_CHINESE_PRC 0x2 // PRC Chinese Stroke Count order
  877. #define SORT_CHINESE_BOPOMOFO 0x3 // Traditional Chinese Bopomofo order
  878. #define SORT_KOREAN_KSC 0x0 // Korean KSC order
  879. #define SORT_KOREAN_UNICODE 0x1 // Korean Unicode order
  880. #define SORT_GERMAN_PHONE_BOOK 0x1 // German Phone Book order
  881. #define SORT_HUNGARIAN_DEFAULT 0x0 // Hungarian Default order
  882. #define SORT_HUNGARIAN_TECHNICAL 0x1 // Hungarian Technical order
  883. #define SORT_GEORGIAN_TRADITIONAL 0x0 // Georgian Traditional order
  884. #define SORT_GEORGIAN_MODERN 0x1 // Georgian Modern order
  885. // end_r_winnt
  886. //
  887. // A language ID is a 16 bit value which is the combination of a
  888. // primary language ID and a secondary language ID. The bits are
  889. // allocated as follows:
  890. //
  891. // +-----------------------+-------------------------+
  892. // | Sublanguage ID | Primary Language ID |
  893. // +-----------------------+-------------------------+
  894. // 15 10 9 0 bit
  895. //
  896. //
  897. // Language ID creation/extraction macros:
  898. //
  899. // MAKELANGID - construct language id from a primary language id and
  900. // a sublanguage id.
  901. // PRIMARYLANGID - extract primary language id from a language id.
  902. // SUBLANGID - extract sublanguage id from a language id.
  903. //
  904. #define MAKELANGID(p, s) ((((WORD )(s)) << 10) | (WORD )(p))
  905. #define PRIMARYLANGID(lgid) ((WORD )(lgid) & 0x3ff)
  906. #define SUBLANGID(lgid) ((WORD )(lgid) >> 10)
  907. //
  908. // A locale ID is a 32 bit value which is the combination of a
  909. // language ID, a sort ID, and a reserved area. The bits are
  910. // allocated as follows:
  911. //
  912. // +-------------+---------+-------------------------+
  913. // | Reserved | Sort ID | Language ID |
  914. // +-------------+---------+-------------------------+
  915. // 31 20 19 16 15 0 bit
  916. //
  917. //
  918. // Locale ID creation/extraction macros:
  919. //
  920. // MAKELCID - construct the locale id from a language id and a sort id.
  921. // MAKESORTLCID - construct the locale id from a language id, sort id, and sort version.
  922. // LANGIDFROMLCID - extract the language id from a locale id.
  923. // SORTIDFROMLCID - extract the sort id from a locale id.
  924. // SORTVERSIONFROMLCID - extract the sort version from a locale id.
  925. //
  926. #define NLS_VALID_LOCALE_MASK 0x000fffff
  927. #define MAKELCID(lgid, srtid) ((DWORD)((((DWORD)((WORD )(srtid))) << 16) | \
  928. ((DWORD)((WORD )(lgid)))))
  929. #define MAKESORTLCID(lgid, srtid, ver) \
  930. ((DWORD)((MAKELCID(lgid, srtid)) | \
  931. (((DWORD)((WORD )(ver))) << 20)))
  932. #define LANGIDFROMLCID(lcid) ((WORD )(lcid))
  933. #define SORTIDFROMLCID(lcid) ((WORD )((((DWORD)(lcid)) >> 16) & 0xf))
  934. #define SORTVERSIONFROMLCID(lcid) ((WORD )((((DWORD)(lcid)) >> 20) & 0xf))
  935. //
  936. // Default System and User IDs for language and locale.
  937. //
  938. #define LANG_SYSTEM_DEFAULT (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
  939. #define LANG_USER_DEFAULT (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
  940. #define LOCALE_SYSTEM_DEFAULT (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
  941. #define LOCALE_USER_DEFAULT (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT))
  942. #define LOCALE_NEUTRAL \
  943. (MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT))
  944. #define LOCALE_INVARIANT \
  945. (MAKELCID(MAKELANGID(LANG_INVARIANT, SUBLANG_NEUTRAL), SORT_DEFAULT))
  946. // begin_ntminiport begin_ntndis begin_ntminitape
  947. //
  948. // Macros used to eliminate compiler warning generated when formal
  949. // parameters or local variables are not declared.
  950. //
  951. // Use DBG_UNREFERENCED_PARAMETER() when a parameter is not yet
  952. // referenced but will be once the module is completely developed.
  953. //
  954. // Use DBG_UNREFERENCED_LOCAL_VARIABLE() when a local variable is not yet
  955. // referenced but will be once the module is completely developed.
  956. //
  957. // Use UNREFERENCED_PARAMETER() if a parameter will never be referenced.
  958. //
  959. // DBG_UNREFERENCED_PARAMETER and DBG_UNREFERENCED_LOCAL_VARIABLE will
  960. // eventually be made into a null macro to help determine whether there
  961. // is unfinished work.
  962. //
  963. #if ! defined(lint)
  964. #define UNREFERENCED_PARAMETER(P) (P)
  965. #define DBG_UNREFERENCED_PARAMETER(P) (P)
  966. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) (V)
  967. #else // lint
  968. // Note: lint -e530 says don't complain about uninitialized variables for
  969. // this varible. Error 527 has to do with unreachable code.
  970. // -restore restores checking to the -save state
  971. #define UNREFERENCED_PARAMETER(P) \
  972. /*lint -save -e527 -e530 */ \
  973. { \
  974. (P) = (P); \
  975. } \
  976. /*lint -restore */
  977. #define DBG_UNREFERENCED_PARAMETER(P) \
  978. /*lint -save -e527 -e530 */ \
  979. { \
  980. (P) = (P); \
  981. } \
  982. /*lint -restore */
  983. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) \
  984. /*lint -save -e527 -e530 */ \
  985. { \
  986. (V) = (V); \
  987. } \
  988. /*lint -restore */
  989. #endif // lint
  990. //
  991. // Macro used to eliminate compiler warning 4715 within a switch statement
  992. // when all possible cases have already been accounted for.
  993. //
  994. // switch (a & 3) {
  995. // case 0: return 1;
  996. // case 1: return Foo();
  997. // case 2: return Bar();
  998. // case 3: return 1;
  999. // DEFAULT_UNREACHABLE;
  1000. //
  1001. #if (_MSC_VER > 1200)
  1002. #define DEFAULT_UNREACHABLE default: __assume(0)
  1003. #else
  1004. //
  1005. // Older compilers do not support __assume(), and there is no other free
  1006. // method of eliminating the warning.
  1007. //
  1008. #define DEFAULT_UNREACHABLE
  1009. #endif
  1010. #ifndef WIN32_NO_STATUS
  1011. /*lint -save -e767 */
  1012. #define STATUS_WAIT_0 ((DWORD )0x00000000L)
  1013. #define STATUS_ABANDONED_WAIT_0 ((DWORD )0x00000080L)
  1014. #define STATUS_USER_APC ((DWORD )0x000000C0L)
  1015. #define STATUS_TIMEOUT ((DWORD )0x00000102L)
  1016. #define STATUS_PENDING ((DWORD )0x00000103L)
  1017. #define DBG_EXCEPTION_HANDLED ((DWORD )0x00010001L)
  1018. #define DBG_CONTINUE ((DWORD )0x00010002L)
  1019. #define STATUS_SEGMENT_NOTIFICATION ((DWORD )0x40000005L)
  1020. #define DBG_TERMINATE_THREAD ((DWORD )0x40010003L)
  1021. #define DBG_TERMINATE_PROCESS ((DWORD )0x40010004L)
  1022. #define DBG_CONTROL_C ((DWORD )0x40010005L)
  1023. #define DBG_CONTROL_BREAK ((DWORD )0x40010008L)
  1024. #define DBG_COMMAND_EXCEPTION ((DWORD )0x40010009L)
  1025. #define STATUS_GUARD_PAGE_VIOLATION ((DWORD )0x80000001L)
  1026. #define STATUS_DATATYPE_MISALIGNMENT ((DWORD )0x80000002L)
  1027. #define STATUS_BREAKPOINT ((DWORD )0x80000003L)
  1028. #define STATUS_SINGLE_STEP ((DWORD )0x80000004L)
  1029. #define DBG_EXCEPTION_NOT_HANDLED ((DWORD )0x80010001L)
  1030. #define STATUS_ACCESS_VIOLATION ((DWORD )0xC0000005L)
  1031. #define STATUS_IN_PAGE_ERROR ((DWORD )0xC0000006L)
  1032. #define STATUS_INVALID_HANDLE ((DWORD )0xC0000008L)
  1033. #define STATUS_NO_MEMORY ((DWORD )0xC0000017L)
  1034. #define STATUS_ILLEGAL_INSTRUCTION ((DWORD )0xC000001DL)
  1035. #define STATUS_NONCONTINUABLE_EXCEPTION ((DWORD )0xC0000025L)
  1036. #define STATUS_INVALID_DISPOSITION ((DWORD )0xC0000026L)
  1037. #define STATUS_ARRAY_BOUNDS_EXCEEDED ((DWORD )0xC000008CL)
  1038. #define STATUS_FLOAT_DENORMAL_OPERAND ((DWORD )0xC000008DL)
  1039. #define STATUS_FLOAT_DIVIDE_BY_ZERO ((DWORD )0xC000008EL)
  1040. #define STATUS_FLOAT_INEXACT_RESULT ((DWORD )0xC000008FL)
  1041. #define STATUS_FLOAT_INVALID_OPERATION ((DWORD )0xC0000090L)
  1042. #define STATUS_FLOAT_OVERFLOW ((DWORD )0xC0000091L)
  1043. #define STATUS_FLOAT_STACK_CHECK ((DWORD )0xC0000092L)
  1044. #define STATUS_FLOAT_UNDERFLOW ((DWORD )0xC0000093L)
  1045. #define STATUS_INTEGER_DIVIDE_BY_ZERO ((DWORD )0xC0000094L)
  1046. #define STATUS_INTEGER_OVERFLOW ((DWORD )0xC0000095L)
  1047. #define STATUS_PRIVILEGED_INSTRUCTION ((DWORD )0xC0000096L)
  1048. #define STATUS_STACK_OVERFLOW ((DWORD )0xC00000FDL)
  1049. #define STATUS_CONTROL_C_EXIT ((DWORD )0xC000013AL)
  1050. #define STATUS_FLOAT_MULTIPLE_FAULTS ((DWORD )0xC00002B4L)
  1051. #define STATUS_FLOAT_MULTIPLE_TRAPS ((DWORD )0xC00002B5L)
  1052. #define STATUS_REG_NAT_CONSUMPTION ((DWORD )0xC00002C9L)
  1053. #if defined(STATUS_SUCCESS) || (_WIN32_WINNT > 0x0500) || (_WIN32_FUSION >= 0x0100)
  1054. #define STATUS_SXS_EARLY_DEACTIVATION ((DWORD )0xC015000FL)
  1055. #define STATUS_SXS_INVALID_DEACTIVATION ((DWORD )0xC0150010L)
  1056. #endif
  1057. /*lint -restore */
  1058. #endif
  1059. #define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
  1060. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  1061. typedef ULONG_PTR KSPIN_LOCK;
  1062. typedef KSPIN_LOCK *PKSPIN_LOCK;
  1063. #if defined(_AMD64_)
  1064. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  1065. //
  1066. // Define bit test intrinsics.
  1067. //
  1068. #ifdef __cplusplus
  1069. extern "C" {
  1070. #endif
  1071. #define BitTest _bittest
  1072. #define BitTestAndComplement _bittestandcomplement
  1073. #define BitTestAndSet _bittestandset
  1074. #define BitTestAndReset _bittestandreset
  1075. #define InterlockedBitTestAndSet _interlockedbittestandset
  1076. #define InterlockedBitTestAndReset _interlockedbittestandreset
  1077. #define BitTest64 _bittest64
  1078. #define BitTestAndComplement64 _bittestandcomplement64
  1079. #define BitTestAndSet64 _bittestandset64
  1080. #define BitTestAndReset64 _bittestandreset64
  1081. #define InterlockedBitTestAndSet64 _interlockedbittestandset64
  1082. #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
  1083. BOOLEAN
  1084. _bittest (
  1085. IN LONG *Base,
  1086. IN LONG Offset
  1087. );
  1088. BOOLEAN
  1089. _bittestandcomplement (
  1090. IN LONG *Base,
  1091. IN LONG Offset
  1092. );
  1093. BOOLEAN
  1094. _bittestandset (
  1095. IN LONG *Base,
  1096. IN LONG Offset
  1097. );
  1098. BOOLEAN
  1099. _bittestandreset (
  1100. IN LONG *Base,
  1101. IN LONG Offset
  1102. );
  1103. BOOLEAN
  1104. _interlockedbittestandset (
  1105. IN LONG *Base,
  1106. IN LONG Offset
  1107. );
  1108. BOOLEAN
  1109. _interlockedbittestandreset (
  1110. IN LONG *Base,
  1111. IN LONG Offset
  1112. );
  1113. BOOLEAN
  1114. _bittest64 (
  1115. IN LONG64 *Base,
  1116. IN LONG64 Offset
  1117. );
  1118. BOOLEAN
  1119. _bittestandcomplement64 (
  1120. IN LONG64 *Base,
  1121. IN LONG64 Offset
  1122. );
  1123. BOOLEAN
  1124. _bittestandset64 (
  1125. IN LONG64 *Base,
  1126. IN LONG64 Offset
  1127. );
  1128. BOOLEAN
  1129. _bittestandreset64 (
  1130. IN LONG64 *Base,
  1131. IN LONG64 Offset
  1132. );
  1133. BOOLEAN
  1134. _interlockedbittestandset64 (
  1135. IN LONG64 *Base,
  1136. IN LONG64 Offset
  1137. );
  1138. BOOLEAN
  1139. _interlockedbittestandreset64 (
  1140. IN LONG64 *Base,
  1141. IN LONG64 Offset
  1142. );
  1143. #pragma intrinsic(_bittest)
  1144. #pragma intrinsic(_bittestandcomplement)
  1145. #pragma intrinsic(_bittestandset)
  1146. #pragma intrinsic(_bittestandreset)
  1147. #pragma intrinsic(_interlockedbittestandset)
  1148. #pragma intrinsic(_interlockedbittestandreset)
  1149. #pragma intrinsic(_bittest64)
  1150. #pragma intrinsic(_bittestandcomplement64)
  1151. #pragma intrinsic(_bittestandset64)
  1152. #pragma intrinsic(_bittestandreset64)
  1153. #pragma intrinsic(_interlockedbittestandset64)
  1154. #pragma intrinsic(_interlockedbittestandreset64)
  1155. //
  1156. // Define bit scan intrinsics.
  1157. //
  1158. #define BitScanForward _BitScanForward
  1159. #define BitScanReverse _BitScanReverse
  1160. #define BitScanForward64 _BitScanForward64
  1161. #define BitScanReverse64 _BitScanReverse64
  1162. BOOLEAN
  1163. _BitScanForward (
  1164. OUT DWORD *Index,
  1165. IN DWORD Mask
  1166. );
  1167. BOOLEAN
  1168. _BitScanReverse (
  1169. OUT DWORD *Index,
  1170. IN DWORD Mask
  1171. );
  1172. BOOLEAN
  1173. _BitScanForward64 (
  1174. OUT DWORD *Index,
  1175. IN DWORD64 Mask
  1176. );
  1177. BOOLEAN
  1178. _BitScanReverse64 (
  1179. OUT DWORD *Index,
  1180. IN DWORD64 Mask
  1181. );
  1182. #pragma intrinsic(_BitScanForward)
  1183. #pragma intrinsic(_BitScanReverse)
  1184. #pragma intrinsic(_BitScanForward64)
  1185. #pragma intrinsic(_BitScanReverse64)
  1186. //
  1187. // Define function to flush a cache line.
  1188. //
  1189. #define CacheLineFlush(Address) _mm_clflush(Address)
  1190. VOID
  1191. _mm_clflush (
  1192. PVOID Address
  1193. );
  1194. #pragma intrinsic(_mm_clflush)
  1195. //
  1196. // Define memory fence intrinsics
  1197. //
  1198. #define LoadFence _mm_lfence
  1199. #define MemoryFence _mm_mfence
  1200. #define StoreFence _mm_sfence
  1201. VOID
  1202. _mm_lfence (
  1203. VOID
  1204. );
  1205. VOID
  1206. _mm_mfence (
  1207. VOID
  1208. );
  1209. VOID
  1210. _mm_sfence (
  1211. VOID
  1212. );
  1213. void
  1214. _mm_prefetch(
  1215. CHAR CONST *a,
  1216. int sel
  1217. );
  1218. /* constants for use with _mm_prefetch */
  1219. #define _MM_HINT_T0 1
  1220. #define _MM_HINT_T1 2
  1221. #define _MM_HINT_T2 3
  1222. #define _MM_HINT_NTA 0
  1223. #pragma intrinsic(_mm_prefetch)
  1224. #pragma intrinsic(_mm_lfence)
  1225. #pragma intrinsic(_mm_mfence)
  1226. #pragma intrinsic(_mm_sfence)
  1227. #define YieldProcessor()
  1228. #define MemoryBarrier _mm_mfence
  1229. #define PreFetchCacheLine(l, a) _mm_prefetch((CHAR CONST *) a, l)
  1230. //
  1231. // PreFetchCacheLine level defines.
  1232. //
  1233. #define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0
  1234. #define PF_NON_TEMPORAL_LEVEL_ALL _MM_HINT_NTA
  1235. //
  1236. // Define function to get the caller's EFLAGs value.
  1237. //
  1238. #define GetCallersEflags() __getcallerseflags()
  1239. unsigned __int32
  1240. __getcallerseflags (
  1241. VOID
  1242. );
  1243. #pragma intrinsic(__getcallerseflags)
  1244. //
  1245. // Define function to read the value of the time stamp counter
  1246. //
  1247. #define ReadTimeStampCounter() __rdtsc()
  1248. DWORD64
  1249. __rdtsc (
  1250. VOID
  1251. );
  1252. #pragma intrinsic(__rdtsc)
  1253. //
  1254. // Define functions to move strings as bytes, words, dwords, and qwords.
  1255. //
  1256. VOID
  1257. __movsb (
  1258. IN PBYTE Destination,
  1259. IN PBYTE Source,
  1260. IN SIZE_T Count
  1261. );
  1262. VOID
  1263. __movsw (
  1264. IN PWORD Destination,
  1265. IN PWORD Source,
  1266. IN SIZE_T Count
  1267. );
  1268. VOID
  1269. __movsd (
  1270. IN PDWORD Destination,
  1271. IN PDWORD Source,
  1272. IN SIZE_T Count
  1273. );
  1274. VOID
  1275. __movsq (
  1276. IN PULONGLONG Destination,
  1277. IN PULONGLONG Source,
  1278. IN SIZE_T Count
  1279. );
  1280. #pragma intrinsic(__movsb)
  1281. #pragma intrinsic(__movsw)
  1282. #pragma intrinsic(__movsd)
  1283. #pragma intrinsic(__movsq)
  1284. //
  1285. // Define functions to store strings as bytes, words, dwords, and qwords.
  1286. //
  1287. VOID
  1288. __stosb (
  1289. IN PBYTE Destination,
  1290. IN BYTE Value,
  1291. IN SIZE_T Count
  1292. );
  1293. VOID
  1294. __stosw (
  1295. IN PWORD Destination,
  1296. IN WORD Value,
  1297. IN SIZE_T Count
  1298. );
  1299. VOID
  1300. __stosd (
  1301. IN PDWORD Destination,
  1302. IN DWORD Value,
  1303. IN SIZE_T Count
  1304. );
  1305. VOID
  1306. __stosq (
  1307. IN PDWORD64 Destination,
  1308. IN DWORD64 Value,
  1309. IN SIZE_T Count
  1310. );
  1311. #pragma intrinsic(__stosb)
  1312. #pragma intrinsic(__stosw)
  1313. #pragma intrinsic(__stosd)
  1314. #pragma intrinsic(__stosq)
  1315. //
  1316. // Define functions to capture the high 64-bits of a 128-bit multiply.
  1317. //
  1318. #define MultiplyHigh __mulh
  1319. #define UnsignedMultiplyHigh __umulh
  1320. LONGLONG
  1321. MultiplyHigh (
  1322. IN LONGLONG Multiplier,
  1323. IN LONGLONG Multiplicand
  1324. );
  1325. ULONGLONG
  1326. UnsignedMultiplyHigh (
  1327. IN ULONGLONG Multiplier,
  1328. IN ULONGLONG Multiplicand
  1329. );
  1330. #pragma intrinsic(__mulh)
  1331. #pragma intrinsic(__umulh)
  1332. //
  1333. // Define functions to read and write the uer TEB and the system PCR/PRCB.
  1334. //
  1335. BYTE
  1336. __readgsbyte (
  1337. IN DWORD Offset
  1338. );
  1339. WORD
  1340. __readgsword (
  1341. IN DWORD Offset
  1342. );
  1343. DWORD
  1344. __readgsdword (
  1345. IN DWORD Offset
  1346. );
  1347. DWORD64
  1348. __readgsqword (
  1349. IN DWORD Offset
  1350. );
  1351. VOID
  1352. __writegsbyte (
  1353. IN DWORD Offset,
  1354. IN BYTE Data
  1355. );
  1356. VOID
  1357. __writegsword (
  1358. IN DWORD Offset,
  1359. IN WORD Data
  1360. );
  1361. VOID
  1362. __writegsdword (
  1363. IN DWORD Offset,
  1364. IN DWORD Data
  1365. );
  1366. VOID
  1367. __writegsqword (
  1368. IN DWORD Offset,
  1369. IN DWORD64 Data
  1370. );
  1371. #pragma intrinsic(__readgsbyte)
  1372. #pragma intrinsic(__readgsword)
  1373. #pragma intrinsic(__readgsdword)
  1374. #pragma intrinsic(__readgsqword)
  1375. #pragma intrinsic(__writegsbyte)
  1376. #pragma intrinsic(__writegsword)
  1377. #pragma intrinsic(__writegsdword)
  1378. #pragma intrinsic(__writegsqword)
  1379. #ifdef __cplusplus
  1380. }
  1381. #endif
  1382. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  1383. //
  1384. // The following flags control the contents of the CONTEXT structure.
  1385. //
  1386. #if !defined(RC_INVOKED)
  1387. #define CONTEXT_AMD64 0x100000
  1388. // end_wx86
  1389. #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
  1390. #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
  1391. #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
  1392. #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
  1393. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
  1394. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  1395. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
  1396. // begin_wx86
  1397. #endif // !defined(RC_INVOKED)
  1398. //
  1399. // Define initial MxCsr control.
  1400. //
  1401. #define INITIAL_MXCSR 0x1f80 // initial MXCSR value
  1402. //
  1403. // Define 128-bit 16-byte aligned xmm register type.
  1404. //
  1405. typedef struct DECLSPEC_ALIGN(16) _M128 {
  1406. ULONGLONG Low;
  1407. LONGLONG High;
  1408. } M128, *PM128;
  1409. //
  1410. // Format of data for fnsave/frstor instructions.
  1411. //
  1412. // This structure is used to store the legacy floating point state.
  1413. //
  1414. typedef struct _LEGACY_SAVE_AREA {
  1415. WORD ControlWord;
  1416. WORD Reserved0;
  1417. WORD StatusWord;
  1418. WORD Reserved1;
  1419. WORD TagWord;
  1420. WORD Reserved2;
  1421. DWORD ErrorOffset;
  1422. WORD ErrorSelector;
  1423. WORD ErrorOpcode;
  1424. DWORD DataOffset;
  1425. WORD DataSelector;
  1426. WORD Reserved3;
  1427. BYTE FloatRegisters[8 * 10];
  1428. } LEGACY_SAVE_AREA, *PLEGACY_SAVE_AREA;
  1429. #define LEGACY_SAVE_AREA_LENGTH ((sizeof(LEGACY_SAVE_AREA) + 15) & ~15)
  1430. //
  1431. // Context Frame
  1432. //
  1433. // This frame has a several purposes: 1) it is used as an argument to
  1434. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1435. // and 3) it is used in the user level thread creation routines.
  1436. //
  1437. //
  1438. // The flags field within this record controls the contents of a CONTEXT
  1439. // record.
  1440. //
  1441. // If the context record is used as an input parameter, then for each
  1442. // portion of the context record controlled by a flag whose value is
  1443. // set, it is assumed that that portion of the context record contains
  1444. // valid context. If the context record is being used to modify a threads
  1445. // context, then only that portion of the threads context is modified.
  1446. //
  1447. // If the context record is used as an output parameter to capture the
  1448. // context of a thread, then only those portions of the thread's context
  1449. // corresponding to set flags will be returned.
  1450. //
  1451. // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
  1452. //
  1453. // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
  1454. //
  1455. // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
  1456. //
  1457. // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
  1458. //
  1459. // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
  1460. // Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
  1461. //
  1462. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
  1463. //
  1464. // Register parameter home addresses.
  1465. //
  1466. DWORD64 P1Home;
  1467. DWORD64 P2Home;
  1468. DWORD64 P3Home;
  1469. DWORD64 P4Home;
  1470. DWORD64 P5Home;
  1471. DWORD64 P6Home;
  1472. //
  1473. // Control flags.
  1474. //
  1475. DWORD ContextFlags;
  1476. DWORD MxCsr;
  1477. //
  1478. // Segment Registers and processor flags.
  1479. //
  1480. WORD SegCs;
  1481. WORD SegDs;
  1482. WORD SegEs;
  1483. WORD SegFs;
  1484. WORD SegGs;
  1485. WORD SegSs;
  1486. DWORD EFlags;
  1487. //
  1488. // Debug registers
  1489. //
  1490. DWORD64 Dr0;
  1491. DWORD64 Dr1;
  1492. DWORD64 Dr2;
  1493. DWORD64 Dr3;
  1494. DWORD64 Dr6;
  1495. DWORD64 Dr7;
  1496. //
  1497. // Integer registers.
  1498. //
  1499. DWORD64 Rax;
  1500. DWORD64 Rcx;
  1501. DWORD64 Rdx;
  1502. DWORD64 Rbx;
  1503. DWORD64 Rsp;
  1504. DWORD64 Rbp;
  1505. DWORD64 Rsi;
  1506. DWORD64 Rdi;
  1507. DWORD64 R8;
  1508. DWORD64 R9;
  1509. DWORD64 R10;
  1510. DWORD64 R11;
  1511. DWORD64 R12;
  1512. DWORD64 R13;
  1513. DWORD64 R14;
  1514. DWORD64 R15;
  1515. //
  1516. // Program counter.
  1517. //
  1518. DWORD64 Rip;
  1519. //
  1520. // MMX/floating point state.
  1521. //
  1522. M128 Xmm0;
  1523. M128 Xmm1;
  1524. M128 Xmm2;
  1525. M128 Xmm3;
  1526. M128 Xmm4;
  1527. M128 Xmm5;
  1528. M128 Xmm6;
  1529. M128 Xmm7;
  1530. M128 Xmm8;
  1531. M128 Xmm9;
  1532. M128 Xmm10;
  1533. M128 Xmm11;
  1534. M128 Xmm12;
  1535. M128 Xmm13;
  1536. M128 Xmm14;
  1537. M128 Xmm15;
  1538. //
  1539. // Legacy floating point state.
  1540. //
  1541. LEGACY_SAVE_AREA FltSave;
  1542. DWORD Fill;
  1543. //
  1544. // Special debug control registers.
  1545. //
  1546. DWORD64 DebugControl;
  1547. DWORD64 LastBranchToRip;
  1548. DWORD64 LastBranchFromRip;
  1549. DWORD64 LastExceptionToRip;
  1550. DWORD64 LastExceptionFromRip;
  1551. DWORD64 Fill1;
  1552. } CONTEXT, *PCONTEXT;
  1553. //
  1554. // Define function table entry - a function table entry is generated for
  1555. // each frame function.
  1556. //
  1557. typedef struct _RUNTIME_FUNCTION {
  1558. DWORD BeginAddress;
  1559. DWORD EndAddress;
  1560. DWORD UnwindData;
  1561. } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
  1562. //
  1563. // Define dynamic function table entry.
  1564. //
  1565. typedef
  1566. PRUNTIME_FUNCTION
  1567. (*PGET_RUNTIME_FUNCTION_CALLBACK) (
  1568. IN DWORD64 ControlPc,
  1569. IN PVOID Context
  1570. );
  1571. typedef
  1572. DWORD
  1573. (*POUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK) (
  1574. IN HANDLE Process,
  1575. IN PVOID TableAddress,
  1576. OUT PDWORD Entries,
  1577. OUT PRUNTIME_FUNCTION* Functions
  1578. );
  1579. #define OUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK_EXPORT_NAME \
  1580. "OutOfProcessFunctionTableCallback"
  1581. //
  1582. // Define runtime exception handling prototypes.
  1583. //
  1584. VOID
  1585. RtlRestoreContext (
  1586. IN PCONTEXT ContextRecord,
  1587. IN struct _EXCEPTION_RECORD *ExceptionRecord OPTIONAL
  1588. );
  1589. BOOLEAN
  1590. RtlAddFunctionTable (
  1591. IN PRUNTIME_FUNCTION FunctionTable,
  1592. IN DWORD EntryCount,
  1593. IN DWORD64 BaseAddress
  1594. );
  1595. BOOLEAN
  1596. RtlInstallFunctionTableCallback (
  1597. IN DWORD64 TableIdentifier,
  1598. IN DWORD64 BaseAddress,
  1599. IN DWORD Length,
  1600. IN PGET_RUNTIME_FUNCTION_CALLBACK Callback,
  1601. IN PVOID Context,
  1602. IN PCWSTR OutOfProcessCallbackDll OPTIONAL
  1603. );
  1604. BOOLEAN
  1605. RtlDeleteFunctionTable (
  1606. IN PRUNTIME_FUNCTION FunctionTable
  1607. );
  1608. #endif // _AMD64_
  1609. //
  1610. // Define function to return the current Thread Environment Block
  1611. //
  1612. #ifdef _ALPHA_ // winnt
  1613. void *_rdteb(void); // winnt
  1614. #if defined(_M_ALPHA) // winnt
  1615. #pragma intrinsic(_rdteb) // winnt
  1616. #endif // winnt
  1617. #endif // winnt
  1618. #if defined(_M_ALPHA)
  1619. #define NtCurrentTeb() ((struct _TEB *)_rdteb())
  1620. #else
  1621. struct _TEB *
  1622. NtCurrentTeb(void);
  1623. #endif
  1624. //
  1625. // Define functions to get the address of the current fiber and the
  1626. // current fiber data.
  1627. //
  1628. #ifdef _ALPHA_
  1629. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  1630. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  1631. // begin_ntddk begin_nthal
  1632. //
  1633. // The following flags control the contents of the CONTEXT structure.
  1634. //
  1635. #if !defined(RC_INVOKED)
  1636. #define CONTEXT_ALPHA 0x00020000
  1637. #define CONTEXT_CONTROL (CONTEXT_ALPHA | 0x00000001L)
  1638. #define CONTEXT_FLOATING_POINT (CONTEXT_ALPHA | 0x00000002L)
  1639. #define CONTEXT_INTEGER (CONTEXT_ALPHA | 0x00000004L)
  1640. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  1641. #endif
  1642. #ifndef _PORTABLE_32BIT_CONTEXT
  1643. //
  1644. // Context Frame
  1645. //
  1646. // This frame has a several purposes: 1) it is used as an argument to
  1647. // NtContinue, 2) it is used to construct a call frame for APC delivery,
  1648. // 3) it is used to construct a call frame for exception dispatching
  1649. // in user mode, 4) it is used in the user level thread creation
  1650. // routines, and 5) it is used to to pass thread state to debuggers.
  1651. //
  1652. // N.B. Because this record is used as a call frame, it must be EXACTLY
  1653. // a multiple of 16 bytes in length.
  1654. //
  1655. // There are two variations of the context structure. This is the real one.
  1656. //
  1657. typedef struct _CONTEXT {
  1658. //
  1659. // This section is specified/returned if the ContextFlags word contains
  1660. // the flag CONTEXT_FLOATING_POINT.
  1661. //
  1662. ULONGLONG FltF0;
  1663. ULONGLONG FltF1;
  1664. ULONGLONG FltF2;
  1665. ULONGLONG FltF3;
  1666. ULONGLONG FltF4;
  1667. ULONGLONG FltF5;
  1668. ULONGLONG FltF6;
  1669. ULONGLONG FltF7;
  1670. ULONGLONG FltF8;
  1671. ULONGLONG FltF9;
  1672. ULONGLONG FltF10;
  1673. ULONGLONG FltF11;
  1674. ULONGLONG FltF12;
  1675. ULONGLONG FltF13;
  1676. ULONGLONG FltF14;
  1677. ULONGLONG FltF15;
  1678. ULONGLONG FltF16;
  1679. ULONGLONG FltF17;
  1680. ULONGLONG FltF18;
  1681. ULONGLONG FltF19;
  1682. ULONGLONG FltF20;
  1683. ULONGLONG FltF21;
  1684. ULONGLONG FltF22;
  1685. ULONGLONG FltF23;
  1686. ULONGLONG FltF24;
  1687. ULONGLONG FltF25;
  1688. ULONGLONG FltF26;
  1689. ULONGLONG FltF27;
  1690. ULONGLONG FltF28;
  1691. ULONGLONG FltF29;
  1692. ULONGLONG FltF30;
  1693. ULONGLONG FltF31;
  1694. //
  1695. // This section is specified/returned if the ContextFlags word contains
  1696. // the flag CONTEXT_INTEGER.
  1697. //
  1698. // N.B. The registers gp, sp, and ra are defined in this section, but are
  1699. // considered part of the control context rather than part of the integer
  1700. // context.
  1701. //
  1702. ULONGLONG IntV0; // $0: return value register, v0
  1703. ULONGLONG IntT0; // $1: temporary registers, t0 - t7
  1704. ULONGLONG IntT1; // $2:
  1705. ULONGLONG IntT2; // $3:
  1706. ULONGLONG IntT3; // $4:
  1707. ULONGLONG IntT4; // $5:
  1708. ULONGLONG IntT5; // $6:
  1709. ULONGLONG IntT6; // $7:
  1710. ULONGLONG IntT7; // $8:
  1711. ULONGLONG IntS0; // $9: nonvolatile registers, s0 - s5
  1712. ULONGLONG IntS1; // $10:
  1713. ULONGLONG IntS2; // $11:
  1714. ULONGLONG IntS3; // $12:
  1715. ULONGLONG IntS4; // $13:
  1716. ULONGLONG IntS5; // $14:
  1717. ULONGLONG IntFp; // $15: frame pointer register, fp/s6
  1718. ULONGLONG IntA0; // $16: argument registers, a0 - a5
  1719. ULONGLONG IntA1; // $17:
  1720. ULONGLONG IntA2; // $18:
  1721. ULONGLONG IntA3; // $19:
  1722. ULONGLONG IntA4; // $20:
  1723. ULONGLONG IntA5; // $21:
  1724. ULONGLONG IntT8; // $22: temporary registers, t8 - t11
  1725. ULONGLONG IntT9; // $23:
  1726. ULONGLONG IntT10; // $24:
  1727. ULONGLONG IntT11; // $25:
  1728. ULONGLONG IntRa; // $26: return address register, ra
  1729. ULONGLONG IntT12; // $27: temporary register, t12
  1730. ULONGLONG IntAt; // $28: assembler temp register, at
  1731. ULONGLONG IntGp; // $29: global pointer register, gp
  1732. ULONGLONG IntSp; // $30: stack pointer register, sp
  1733. ULONGLONG IntZero; // $31: zero register, zero
  1734. //
  1735. // This section is specified/returned if the ContextFlags word contains
  1736. // the flag CONTEXT_FLOATING_POINT.
  1737. //
  1738. ULONGLONG Fpcr; // floating point control register
  1739. ULONGLONG SoftFpcr; // software extension to FPCR
  1740. //
  1741. // This section is specified/returned if the ContextFlags word contains
  1742. // the flag CONTEXT_CONTROL.
  1743. //
  1744. // N.B. The registers gp, sp, and ra are defined in the integer section,
  1745. // but are considered part of the control context rather than part of
  1746. // the integer context.
  1747. //
  1748. ULONGLONG Fir; // (fault instruction) continuation address
  1749. DWORD Psr; // processor status
  1750. //
  1751. // The flags values within this flag control the contents of
  1752. // a CONTEXT record.
  1753. //
  1754. // If the context record is used as an input parameter, then
  1755. // for each portion of the context record controlled by a flag
  1756. // whose value is set, it is assumed that that portion of the
  1757. // context record contains valid context. If the context record
  1758. // is being used to modify a thread's context, then only that
  1759. // portion of the threads context will be modified.
  1760. //
  1761. // If the context record is used as an IN OUT parameter to capture
  1762. // the context of a thread, then only those portions of the thread's
  1763. // context corresponding to set flags will be returned.
  1764. //
  1765. // The context record is never used as an OUT only parameter.
  1766. //
  1767. DWORD ContextFlags;
  1768. DWORD Fill[4]; // padding for 16-byte stack frame alignment
  1769. } CONTEXT, *PCONTEXT;
  1770. #else
  1771. #error _PORTABLE_32BIT_CONTEXT no longer supported on Alpha.
  1772. #endif // _PORTABLE_32BIT_CONTEXT
  1773. // end_ntddk end_nthal
  1774. #endif // _ALPHA_
  1775. #ifdef _ALPHA_
  1776. VOID
  1777. __jump_unwind (
  1778. PVOID VirtualFramePointer,
  1779. PVOID TargetPc
  1780. );
  1781. #endif // _ALPHA_
  1782. #ifdef _X86_
  1783. //
  1784. // Disable these two pragmas that evaluate to "sti" "cli" on x86 so that driver
  1785. // writers to not leave them inadvertantly in their code.
  1786. //
  1787. #if !defined(MIDL_PASS)
  1788. #if !defined(RC_INVOKED)
  1789. #if _MSC_VER >= 1200
  1790. #pragma warning(push)
  1791. #endif
  1792. #pragma warning(disable:4164) // disable C4164 warning so that apps that
  1793. // build with /Od don't get weird errors !
  1794. #ifdef _M_IX86
  1795. #pragma function(_enable)
  1796. #pragma function(_disable)
  1797. #endif
  1798. #if _MSC_VER >= 1200
  1799. #pragma warning(pop)
  1800. #else
  1801. #pragma warning(default:4164) // reenable C4164 warning
  1802. #endif
  1803. #endif
  1804. #endif
  1805. #if !defined(MIDL_PASS) || defined(_M_IX86)
  1806. #if (_MSC_FULL_VER >= 13012035)
  1807. //
  1808. // Define bit scan intrinsics.
  1809. //
  1810. //#define BitScanForward _BitScanForward
  1811. //#define BitScanReverse _BitScanReverse
  1812. //BOOLEAN
  1813. //_BitScanForward (
  1814. // OUT DWORD *Index,
  1815. // IN DWORD Mask
  1816. // );
  1817. //BOOLEAN
  1818. //_BitScanReverse (
  1819. // OUT DWORD *Index,
  1820. // IN DWORD Mask
  1821. // );
  1822. //#pragma intrinsic(_BitScanForward)
  1823. //#pragma intrinsic(_BitScanReverse)
  1824. //
  1825. // Define FS referencing intrinsics
  1826. //
  1827. #ifdef __cplusplus
  1828. extern "C" {
  1829. #endif
  1830. BYTE
  1831. __readfsbyte (
  1832. IN DWORD Offset
  1833. );
  1834. WORD
  1835. __readfsword (
  1836. IN DWORD Offset
  1837. );
  1838. DWORD
  1839. __readfsdword (
  1840. IN DWORD Offset
  1841. );
  1842. VOID
  1843. __writefsbyte (
  1844. IN DWORD Offset,
  1845. IN BYTE Data
  1846. );
  1847. VOID
  1848. __writefsword (
  1849. IN DWORD Offset,
  1850. IN WORD Data
  1851. );
  1852. VOID
  1853. __writefsdword (
  1854. IN DWORD Offset,
  1855. IN DWORD Data
  1856. );
  1857. #ifdef __cplusplus
  1858. }
  1859. #endif
  1860. #pragma intrinsic(__readfsbyte)
  1861. #pragma intrinsic(__readfsword)
  1862. #pragma intrinsic(__readfsdword)
  1863. #pragma intrinsic(__writefsbyte)
  1864. #pragma intrinsic(__writefsword)
  1865. #pragma intrinsic(__writefsdword)
  1866. #endif
  1867. #endif
  1868. #if !defined(MIDL_PASS) && defined(_M_IX86)
  1869. FORCEINLINE
  1870. VOID
  1871. MemoryBarrier (
  1872. VOID
  1873. )
  1874. {
  1875. LONG Barrier;
  1876. __asm {
  1877. xchg Barrier, eax
  1878. }
  1879. }
  1880. #define YieldProcessor() __asm { rep nop }
  1881. //
  1882. // Prefetch is not supported on all x86 procssors.
  1883. //
  1884. #define PreFetchCacheLine(l, a)
  1885. //
  1886. // PreFetchCacheLine level defines.
  1887. //
  1888. #define PF_TEMPORAL_LEVEL_1
  1889. #define PF_NON_TEMPORAL_LEVEL_ALL
  1890. // end_ntddk
  1891. #if (_MSC_FULL_VER >= 13012035)
  1892. _inline PVOID GetFiberData( void ) { return *(PVOID *) (ULONG_PTR) __readfsdword (0x10);}
  1893. _inline PVOID GetCurrentFiber( void ) { return (PVOID) (ULONG_PTR) __readfsdword (0x10);}
  1894. #else
  1895. #if _MSC_VER >= 1200
  1896. #pragma warning(push)
  1897. #endif
  1898. #pragma warning (disable:4035) // disable 4035 (function must return something)
  1899. _inline PVOID GetFiberData( void ) { __asm {
  1900. mov eax, fs:[0x10]
  1901. mov eax,[eax]
  1902. }
  1903. }
  1904. _inline PVOID GetCurrentFiber( void ) { __asm mov eax, fs:[0x10] }
  1905. #if _MSC_VER >= 1200
  1906. #pragma warning(pop)
  1907. #else
  1908. #pragma warning (default:4035) // Reenable it
  1909. #endif
  1910. #endif
  1911. // begin_ntddk
  1912. #endif
  1913. // begin_wx86
  1914. //
  1915. // Define the size of the 80387 save area, which is in the context frame.
  1916. //
  1917. #define SIZE_OF_80387_REGISTERS 80
  1918. //
  1919. // The following flags control the contents of the CONTEXT structure.
  1920. //
  1921. #if !defined(RC_INVOKED)
  1922. #define CONTEXT_i386 0x00010000 // this assumes that i386 and
  1923. #define CONTEXT_i486 0x00010000 // i486 have identical context records
  1924. // end_wx86
  1925. #define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  1926. #define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  1927. #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  1928. #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
  1929. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  1930. #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
  1931. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  1932. CONTEXT_SEGMENTS)
  1933. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
  1934. // begin_wx86
  1935. #endif
  1936. #define MAXIMUM_SUPPORTED_EXTENSION 512
  1937. typedef struct _FLOATING_SAVE_AREA {
  1938. DWORD ControlWord;
  1939. DWORD StatusWord;
  1940. DWORD TagWord;
  1941. DWORD ErrorOffset;
  1942. DWORD ErrorSelector;
  1943. DWORD DataOffset;
  1944. DWORD DataSelector;
  1945. BYTE RegisterArea[SIZE_OF_80387_REGISTERS];
  1946. DWORD Cr0NpxState;
  1947. } FLOATING_SAVE_AREA;
  1948. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  1949. //
  1950. // Context Frame
  1951. //
  1952. // This frame has a several purposes: 1) it is used as an argument to
  1953. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1954. // and 3) it is used in the user level thread creation routines.
  1955. //
  1956. // The layout of the record conforms to a standard call frame.
  1957. //
  1958. typedef struct _CONTEXT {
  1959. //
  1960. // The flags values within this flag control the contents of
  1961. // a CONTEXT record.
  1962. //
  1963. // If the context record is used as an input parameter, then
  1964. // for each portion of the context record controlled by a flag
  1965. // whose value is set, it is assumed that that portion of the
  1966. // context record contains valid context. If the context record
  1967. // is being used to modify a threads context, then only that
  1968. // portion of the threads context will be modified.
  1969. //
  1970. // If the context record is used as an IN OUT parameter to capture
  1971. // the context of a thread, then only those portions of the thread's
  1972. // context corresponding to set flags will be returned.
  1973. //
  1974. // The context record is never used as an OUT only parameter.
  1975. //
  1976. DWORD ContextFlags;
  1977. //
  1978. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  1979. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  1980. // included in CONTEXT_FULL.
  1981. //
  1982. DWORD Dr0;
  1983. DWORD Dr1;
  1984. DWORD Dr2;
  1985. DWORD Dr3;
  1986. DWORD Dr6;
  1987. DWORD Dr7;
  1988. //
  1989. // This section is specified/returned if the
  1990. // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  1991. //
  1992. FLOATING_SAVE_AREA FloatSave;
  1993. //
  1994. // This section is specified/returned if the
  1995. // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  1996. //
  1997. DWORD SegGs;
  1998. DWORD SegFs;
  1999. DWORD SegEs;
  2000. DWORD SegDs;
  2001. //
  2002. // This section is specified/returned if the
  2003. // ContextFlags word contians the flag CONTEXT_INTEGER.
  2004. //
  2005. DWORD Edi;
  2006. DWORD Esi;
  2007. DWORD Ebx;
  2008. DWORD Edx;
  2009. DWORD Ecx;
  2010. DWORD Eax;
  2011. //
  2012. // This section is specified/returned if the
  2013. // ContextFlags word contians the flag CONTEXT_CONTROL.
  2014. //
  2015. DWORD Ebp;
  2016. DWORD Eip;
  2017. DWORD SegCs; // MUST BE SANITIZED
  2018. DWORD EFlags; // MUST BE SANITIZED
  2019. DWORD Esp;
  2020. DWORD SegSs;
  2021. //
  2022. // This section is specified/returned if the ContextFlags word
  2023. // contains the flag CONTEXT_EXTENDED_REGISTERS.
  2024. // The format and contexts are processor specific
  2025. //
  2026. BYTE ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  2027. } CONTEXT;
  2028. typedef CONTEXT *PCONTEXT;
  2029. // begin_ntminiport
  2030. #endif //_X86_
  2031. #ifndef _LDT_ENTRY_DEFINED
  2032. #define _LDT_ENTRY_DEFINED
  2033. typedef struct _LDT_ENTRY {
  2034. WORD LimitLow;
  2035. WORD BaseLow;
  2036. union {
  2037. struct {
  2038. BYTE BaseMid;
  2039. BYTE Flags1; // Declare as bytes to avoid alignment
  2040. BYTE Flags2; // Problems.
  2041. BYTE BaseHi;
  2042. } Bytes;
  2043. struct {
  2044. DWORD BaseMid : 8;
  2045. DWORD Type : 5;
  2046. DWORD Dpl : 2;
  2047. DWORD Pres : 1;
  2048. DWORD LimitHi : 4;
  2049. DWORD Sys : 1;
  2050. DWORD Reserved_0 : 1;
  2051. DWORD Default_Big : 1;
  2052. DWORD Granularity : 1;
  2053. DWORD BaseHi : 8;
  2054. } Bits;
  2055. } HighWord;
  2056. } LDT_ENTRY, *PLDT_ENTRY;
  2057. #endif
  2058. #if defined(_MIPS_)
  2059. //
  2060. // Define functions to get the address of the current fiber and the
  2061. // current fiber data.
  2062. //
  2063. #define GetCurrentFiber() ((*(PNT_TIB *)0x7ffff4a8)->FiberData)
  2064. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  2065. // begin_ntddk begin_nthal
  2066. //
  2067. // The following flags control the contents of the CONTEXT structure.
  2068. //
  2069. #if !defined(RC_INVOKED)
  2070. #define CONTEXT_R4000 0x00010000 // r4000 context
  2071. #define CONTEXT_CONTROL (CONTEXT_R4000 | 0x00000001)
  2072. #define CONTEXT_FLOATING_POINT (CONTEXT_R4000 | 0x00000002)
  2073. #define CONTEXT_INTEGER (CONTEXT_R4000 | 0x00000004)
  2074. #define CONTEXT_EXTENDED_FLOAT (CONTEXT_FLOATING_POINT | 0x00000008)
  2075. #define CONTEXT_EXTENDED_INTEGER (CONTEXT_INTEGER | 0x00000010)
  2076. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | \
  2077. CONTEXT_INTEGER | CONTEXT_EXTENDED_INTEGER)
  2078. #endif
  2079. //
  2080. // Context Frame
  2081. //
  2082. // N.B. This frame must be exactly a multiple of 16 bytes in length.
  2083. //
  2084. // This frame has a several purposes: 1) it is used as an argument to
  2085. // NtContinue, 2) it is used to constuct a call frame for APC delivery,
  2086. // 3) it is used to construct a call frame for exception dispatching
  2087. // in user mode, and 4) it is used in the user level thread creation
  2088. // routines.
  2089. //
  2090. // The layout of the record conforms to a standard call frame.
  2091. //
  2092. typedef struct _CONTEXT {
  2093. //
  2094. // This section is always present and is used as an argument build
  2095. // area.
  2096. //
  2097. // N.B. Context records are 0 mod 8 aligned starting with NT 4.0.
  2098. //
  2099. union {
  2100. DWORD Argument[4];
  2101. ULONGLONG Alignment;
  2102. };
  2103. //
  2104. // The following union defines the 32-bit and 64-bit register context.
  2105. //
  2106. union {
  2107. //
  2108. // 32-bit context.
  2109. //
  2110. struct {
  2111. //
  2112. // This section is specified/returned if the ContextFlags contains
  2113. // the flag CONTEXT_FLOATING_POINT.
  2114. //
  2115. // N.B. This section contains the 16 double floating registers f0,
  2116. // f2, ..., f30.
  2117. //
  2118. DWORD FltF0;
  2119. DWORD FltF1;
  2120. DWORD FltF2;
  2121. DWORD FltF3;
  2122. DWORD FltF4;
  2123. DWORD FltF5;
  2124. DWORD FltF6;
  2125. DWORD FltF7;
  2126. DWORD FltF8;
  2127. DWORD FltF9;
  2128. DWORD FltF10;
  2129. DWORD FltF11;
  2130. DWORD FltF12;
  2131. DWORD FltF13;
  2132. DWORD FltF14;
  2133. DWORD FltF15;
  2134. DWORD FltF16;
  2135. DWORD FltF17;
  2136. DWORD FltF18;
  2137. DWORD FltF19;
  2138. DWORD FltF20;
  2139. DWORD FltF21;
  2140. DWORD FltF22;
  2141. DWORD FltF23;
  2142. DWORD FltF24;
  2143. DWORD FltF25;
  2144. DWORD FltF26;
  2145. DWORD FltF27;
  2146. DWORD FltF28;
  2147. DWORD FltF29;
  2148. DWORD FltF30;
  2149. DWORD FltF31;
  2150. //
  2151. // This section is specified/returned if the ContextFlags contains
  2152. // the flag CONTEXT_INTEGER.
  2153. //
  2154. // N.B. The registers gp, sp, and ra are defined in this section,
  2155. // but are considered part of the control context rather than
  2156. // part of the integer context.
  2157. //
  2158. // N.B. Register zero is not stored in the frame.
  2159. //
  2160. DWORD IntZero;
  2161. DWORD IntAt;
  2162. DWORD IntV0;
  2163. DWORD IntV1;
  2164. DWORD IntA0;
  2165. DWORD IntA1;
  2166. DWORD IntA2;
  2167. DWORD IntA3;
  2168. DWORD IntT0;
  2169. DWORD IntT1;
  2170. DWORD IntT2;
  2171. DWORD IntT3;
  2172. DWORD IntT4;
  2173. DWORD IntT5;
  2174. DWORD IntT6;
  2175. DWORD IntT7;
  2176. DWORD IntS0;
  2177. DWORD IntS1;
  2178. DWORD IntS2;
  2179. DWORD IntS3;
  2180. DWORD IntS4;
  2181. DWORD IntS5;
  2182. DWORD IntS6;
  2183. DWORD IntS7;
  2184. DWORD IntT8;
  2185. DWORD IntT9;
  2186. DWORD IntK0;
  2187. DWORD IntK1;
  2188. DWORD IntGp;
  2189. DWORD IntSp;
  2190. DWORD IntS8;
  2191. DWORD IntRa;
  2192. DWORD IntLo;
  2193. DWORD IntHi;
  2194. //
  2195. // This section is specified/returned if the ContextFlags word contains
  2196. // the flag CONTEXT_FLOATING_POINT.
  2197. //
  2198. DWORD Fsr;
  2199. //
  2200. // This section is specified/returned if the ContextFlags word contains
  2201. // the flag CONTEXT_CONTROL.
  2202. //
  2203. // N.B. The registers gp, sp, and ra are defined in the integer section,
  2204. // but are considered part of the control context rather than part of
  2205. // the integer context.
  2206. //
  2207. DWORD Fir;
  2208. DWORD Psr;
  2209. //
  2210. // The flags values within this flag control the contents of
  2211. // a CONTEXT record.
  2212. //
  2213. // If the context record is used as an input parameter, then
  2214. // for each portion of the context record controlled by a flag
  2215. // whose value is set, it is assumed that that portion of the
  2216. // context record contains valid context. If the context record
  2217. // is being used to modify a thread's context, then only that
  2218. // portion of the threads context will be modified.
  2219. //
  2220. // If the context record is used as an IN OUT parameter to capture
  2221. // the context of a thread, then only those portions of the thread's
  2222. // context corresponding to set flags will be returned.
  2223. //
  2224. // The context record is never used as an OUT only parameter.
  2225. //
  2226. DWORD ContextFlags;
  2227. };
  2228. //
  2229. // 64-bit context.
  2230. //
  2231. struct {
  2232. //
  2233. // This section is specified/returned if the ContextFlags contains
  2234. // the flag CONTEXT_EXTENDED_FLOAT.
  2235. //
  2236. // N.B. This section contains the 32 double floating registers f0,
  2237. // f1, ..., f31.
  2238. //
  2239. ULONGLONG XFltF0;
  2240. ULONGLONG XFltF1;
  2241. ULONGLONG XFltF2;
  2242. ULONGLONG XFltF3;
  2243. ULONGLONG XFltF4;
  2244. ULONGLONG XFltF5;
  2245. ULONGLONG XFltF6;
  2246. ULONGLONG XFltF7;
  2247. ULONGLONG XFltF8;
  2248. ULONGLONG XFltF9;
  2249. ULONGLONG XFltF10;
  2250. ULONGLONG XFltF11;
  2251. ULONGLONG XFltF12;
  2252. ULONGLONG XFltF13;
  2253. ULONGLONG XFltF14;
  2254. ULONGLONG XFltF15;
  2255. ULONGLONG XFltF16;
  2256. ULONGLONG XFltF17;
  2257. ULONGLONG XFltF18;
  2258. ULONGLONG XFltF19;
  2259. ULONGLONG XFltF20;
  2260. ULONGLONG XFltF21;
  2261. ULONGLONG XFltF22;
  2262. ULONGLONG XFltF23;
  2263. ULONGLONG XFltF24;
  2264. ULONGLONG XFltF25;
  2265. ULONGLONG XFltF26;
  2266. ULONGLONG XFltF27;
  2267. ULONGLONG XFltF28;
  2268. ULONGLONG XFltF29;
  2269. ULONGLONG XFltF30;
  2270. ULONGLONG XFltF31;
  2271. //
  2272. // The following sections must exactly overlay the 32-bit context.
  2273. //
  2274. DWORD Fill1;
  2275. DWORD Fill2;
  2276. //
  2277. // This section is specified/returned if the ContextFlags contains
  2278. // the flag CONTEXT_FLOATING_POINT.
  2279. //
  2280. DWORD XFsr;
  2281. //
  2282. // This section is specified/returned if the ContextFlags contains
  2283. // the flag CONTEXT_CONTROL.
  2284. //
  2285. // N.B. The registers gp, sp, and ra are defined in the integer
  2286. // section, but are considered part of the control context
  2287. // rather than part of the integer context.
  2288. //
  2289. DWORD XFir;
  2290. DWORD XPsr;
  2291. //
  2292. // The flags values within this flag control the contents of
  2293. // a CONTEXT record.
  2294. //
  2295. // If the context record is used as an input parameter, then
  2296. // for each portion of the context record controlled by a flag
  2297. // whose value is set, it is assumed that that portion of the
  2298. // context record contains valid context. If the context record
  2299. // is being used to modify a thread's context, then only that
  2300. // portion of the threads context will be modified.
  2301. //
  2302. // If the context record is used as an IN OUT parameter to capture
  2303. // the context of a thread, then only those portions of the thread's
  2304. // context corresponding to set flags will be returned.
  2305. //
  2306. // The context record is never used as an OUT only parameter.
  2307. //
  2308. DWORD XContextFlags;
  2309. //
  2310. // This section is specified/returned if the ContextFlags contains
  2311. // the flag CONTEXT_EXTENDED_INTEGER.
  2312. //
  2313. // N.B. The registers gp, sp, and ra are defined in this section,
  2314. // but are considered part of the control context rather than
  2315. // part of the integer context.
  2316. //
  2317. // N.B. Register zero is not stored in the frame.
  2318. //
  2319. ULONGLONG XIntZero;
  2320. ULONGLONG XIntAt;
  2321. ULONGLONG XIntV0;
  2322. ULONGLONG XIntV1;
  2323. ULONGLONG XIntA0;
  2324. ULONGLONG XIntA1;
  2325. ULONGLONG XIntA2;
  2326. ULONGLONG XIntA3;
  2327. ULONGLONG XIntT0;
  2328. ULONGLONG XIntT1;
  2329. ULONGLONG XIntT2;
  2330. ULONGLONG XIntT3;
  2331. ULONGLONG XIntT4;
  2332. ULONGLONG XIntT5;
  2333. ULONGLONG XIntT6;
  2334. ULONGLONG XIntT7;
  2335. ULONGLONG XIntS0;
  2336. ULONGLONG XIntS1;
  2337. ULONGLONG XIntS2;
  2338. ULONGLONG XIntS3;
  2339. ULONGLONG XIntS4;
  2340. ULONGLONG XIntS5;
  2341. ULONGLONG XIntS6;
  2342. ULONGLONG XIntS7;
  2343. ULONGLONG XIntT8;
  2344. ULONGLONG XIntT9;
  2345. ULONGLONG XIntK0;
  2346. ULONGLONG XIntK1;
  2347. ULONGLONG XIntGp;
  2348. ULONGLONG XIntSp;
  2349. ULONGLONG XIntS8;
  2350. ULONGLONG XIntRa;
  2351. ULONGLONG XIntLo;
  2352. ULONGLONG XIntHi;
  2353. };
  2354. };
  2355. } CONTEXT, *PCONTEXT;
  2356. // end_ntddk end_nthal
  2357. #define CONTEXT32_LENGTH 0x130 // The original 32-bit Context length (pre NT 4.0)
  2358. #endif // MIPS
  2359. #if defined(_MIPS_)
  2360. VOID
  2361. __jump_unwind (
  2362. PVOID Fp,
  2363. PVOID TargetPc
  2364. );
  2365. #endif // MIPS
  2366. #if defined(_PPC_)
  2367. //
  2368. // The address of the TEB is placed into GPR 13 at context switch time
  2369. // and should never be destroyed. To get the address of the TEB use
  2370. // the compiler intrinsic to access it directly from GPR 13.
  2371. //
  2372. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  2373. unsigned __gregister_get( unsigned const regnum );
  2374. #define NtCurrentTeb() ((struct _TEB *)__gregister_get(13))
  2375. #elif defined(_M_PPC)
  2376. struct _TEB * __builtin_get_gpr13(VOID);
  2377. #define NtCurrentTeb() ((struct _TEB *)__builtin_get_gpr13())
  2378. #endif
  2379. //
  2380. // Define functions to get the address of the current fiber and the
  2381. // current fiber data.
  2382. //
  2383. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  2384. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  2385. // begin_ntddk begin_nthal
  2386. //
  2387. // The following flags control the contents of the CONTEXT structure.
  2388. //
  2389. #if !defined(RC_INVOKED)
  2390. #define CONTEXT_CONTROL 0x00000001L
  2391. #define CONTEXT_FLOATING_POINT 0x00000002L
  2392. #define CONTEXT_INTEGER 0x00000004L
  2393. #define CONTEXT_DEBUG_REGISTERS 0x00000008L
  2394. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  2395. #endif
  2396. //
  2397. // Context Frame
  2398. //
  2399. // N.B. This frame must be exactly a multiple of 16 bytes in length.
  2400. //
  2401. // This frame has a several purposes: 1) it is used as an argument to
  2402. // NtContinue, 2) it is used to constuct a call frame for APC delivery,
  2403. // 3) it is used to construct a call frame for exception dispatching
  2404. // in user mode, and 4) it is used in the user level thread creation
  2405. // routines.
  2406. //
  2407. // Requires at least 8-byte alignment (double)
  2408. //
  2409. typedef struct _CONTEXT {
  2410. //
  2411. // This section is specified/returned if the ContextFlags word contains
  2412. // the flag CONTEXT_FLOATING_POINT.
  2413. //
  2414. double Fpr0; // Floating registers 0..31
  2415. double Fpr1;
  2416. double Fpr2;
  2417. double Fpr3;
  2418. double Fpr4;
  2419. double Fpr5;
  2420. double Fpr6;
  2421. double Fpr7;
  2422. double Fpr8;
  2423. double Fpr9;
  2424. double Fpr10;
  2425. double Fpr11;
  2426. double Fpr12;
  2427. double Fpr13;
  2428. double Fpr14;
  2429. double Fpr15;
  2430. double Fpr16;
  2431. double Fpr17;
  2432. double Fpr18;
  2433. double Fpr19;
  2434. double Fpr20;
  2435. double Fpr21;
  2436. double Fpr22;
  2437. double Fpr23;
  2438. double Fpr24;
  2439. double Fpr25;
  2440. double Fpr26;
  2441. double Fpr27;
  2442. double Fpr28;
  2443. double Fpr29;
  2444. double Fpr30;
  2445. double Fpr31;
  2446. double Fpscr; // Floating point status/control reg
  2447. //
  2448. // This section is specified/returned if the ContextFlags word contains
  2449. // the flag CONTEXT_INTEGER.
  2450. //
  2451. DWORD Gpr0; // General registers 0..31
  2452. DWORD Gpr1;
  2453. DWORD Gpr2;
  2454. DWORD Gpr3;
  2455. DWORD Gpr4;
  2456. DWORD Gpr5;
  2457. DWORD Gpr6;
  2458. DWORD Gpr7;
  2459. DWORD Gpr8;
  2460. DWORD Gpr9;
  2461. DWORD Gpr10;
  2462. DWORD Gpr11;
  2463. DWORD Gpr12;
  2464. DWORD Gpr13;
  2465. DWORD Gpr14;
  2466. DWORD Gpr15;
  2467. DWORD Gpr16;
  2468. DWORD Gpr17;
  2469. DWORD Gpr18;
  2470. DWORD Gpr19;
  2471. DWORD Gpr20;
  2472. DWORD Gpr21;
  2473. DWORD Gpr22;
  2474. DWORD Gpr23;
  2475. DWORD Gpr24;
  2476. DWORD Gpr25;
  2477. DWORD Gpr26;
  2478. DWORD Gpr27;
  2479. DWORD Gpr28;
  2480. DWORD Gpr29;
  2481. DWORD Gpr30;
  2482. DWORD Gpr31;
  2483. DWORD Cr; // Condition register
  2484. DWORD Xer; // Fixed point exception register
  2485. //
  2486. // This section is specified/returned if the ContextFlags word contains
  2487. // the flag CONTEXT_CONTROL.
  2488. //
  2489. DWORD Msr; // Machine status register
  2490. DWORD Iar; // Instruction address register
  2491. DWORD Lr; // Link register
  2492. DWORD Ctr; // Count register
  2493. //
  2494. // The flags values within this flag control the contents of
  2495. // a CONTEXT record.
  2496. //
  2497. // If the context record is used as an input parameter, then
  2498. // for each portion of the context record controlled by a flag
  2499. // whose value is set, it is assumed that that portion of the
  2500. // context record contains valid context. If the context record
  2501. // is being used to modify a thread's context, then only that
  2502. // portion of the threads context will be modified.
  2503. //
  2504. // If the context record is used as an IN OUT parameter to capture
  2505. // the context of a thread, then only those portions of the thread's
  2506. // context corresponding to set flags will be returned.
  2507. //
  2508. // The context record is never used as an OUT only parameter.
  2509. //
  2510. DWORD ContextFlags;
  2511. DWORD Fill[3]; // Pad out to multiple of 16 bytes
  2512. //
  2513. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  2514. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  2515. // included in CONTEXT_FULL.
  2516. //
  2517. DWORD Dr0; // Breakpoint Register 1
  2518. DWORD Dr1; // Breakpoint Register 2
  2519. DWORD Dr2; // Breakpoint Register 3
  2520. DWORD Dr3; // Breakpoint Register 4
  2521. DWORD Dr4; // Breakpoint Register 5
  2522. DWORD Dr5; // Breakpoint Register 6
  2523. DWORD Dr6; // Debug Status Register
  2524. DWORD Dr7; // Debug Control Register
  2525. } CONTEXT, *PCONTEXT;
  2526. // end_ntddk end_nthal
  2527. //
  2528. // Stack frame header
  2529. //
  2530. // Order of appearance in stack frame:
  2531. // Header (six words)
  2532. // Parameters (at least eight words)
  2533. // Local variables
  2534. // Saved GPRs
  2535. // Saved FPRs
  2536. //
  2537. // Minimum alignment is 8 bytes
  2538. typedef struct _STACK_FRAME_HEADER { // GPR 1 points here
  2539. DWORD BackChain; // Addr of previous frame
  2540. DWORD GlueSaved1; // Used by glue code
  2541. DWORD GlueSaved2;
  2542. DWORD Reserved1; // Reserved
  2543. DWORD Spare1; // Used by tracing, profiling, ...
  2544. DWORD Spare2;
  2545. DWORD Parameter0; // First 8 parameter words are
  2546. DWORD Parameter1; // always present
  2547. DWORD Parameter2;
  2548. DWORD Parameter3;
  2549. DWORD Parameter4;
  2550. DWORD Parameter5;
  2551. DWORD Parameter6;
  2552. DWORD Parameter7;
  2553. } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
  2554. VOID
  2555. __jump_unwind (
  2556. PVOID Fp,
  2557. PVOID TargetPc
  2558. );
  2559. #endif // defined(_PPC_)
  2560. #if defined(_MPPC_)
  2561. //
  2562. // The address of the TEB is placed into GPR 13 at context switch time
  2563. // and should never be destroyed. To get the address of the TEB use
  2564. // the compiler intrinsic to access it directly from GPR 13.
  2565. //
  2566. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  2567. unsigned __gregister_get( unsigned const regnum );
  2568. #define NtCurrentTeb() ((struct _TEB *)__gregister_get(13))
  2569. #elif defined(_M_PPC)
  2570. struct _TEB * __builtin_get_gpr13(VOID);
  2571. #define NtCurrentTeb() ((struct _TEB *)__builtin_get_gpr13())
  2572. #endif
  2573. //
  2574. // Define functions to get the address of the current fiber and the
  2575. // current fiber data.
  2576. //
  2577. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  2578. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  2579. // begin_ntddk begin_nthal
  2580. //
  2581. // The following flags control the contents of the CONTEXT structure.
  2582. //
  2583. #if !defined(RC_INVOKED)
  2584. #define CONTEXT_CONTROL 0x00000001L
  2585. #define CONTEXT_FLOATING_POINT 0x00000002L
  2586. #define CONTEXT_INTEGER 0x00000004L
  2587. #define CONTEXT_DEBUG_REGISTERS 0x00000008L
  2588. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  2589. #endif
  2590. //
  2591. // Context Frame
  2592. //
  2593. // N.B. This frame must be exactly a multiple of 16 bytes in length.
  2594. //
  2595. // This frame has a several purposes: 1) it is used as an argument to
  2596. // NtContinue, 2) it is used to constuct a call frame for APC delivery,
  2597. // 3) it is used to construct a call frame for exception dispatching
  2598. // in user mode, and 4) it is used in the user level thread creation
  2599. // routines.
  2600. //
  2601. // Requires at least 8-byte alignment (double)
  2602. //
  2603. typedef struct _CONTEXT {
  2604. //
  2605. // This section is specified/returned if the ContextFlags word contains
  2606. // the flag CONTEXT_FLOATING_POINT.
  2607. //
  2608. double Fpr0; // Floating registers 0..31
  2609. double Fpr1;
  2610. double Fpr2;
  2611. double Fpr3;
  2612. double Fpr4;
  2613. double Fpr5;
  2614. double Fpr6;
  2615. double Fpr7;
  2616. double Fpr8;
  2617. double Fpr9;
  2618. double Fpr10;
  2619. double Fpr11;
  2620. double Fpr12;
  2621. double Fpr13;
  2622. double Fpr14;
  2623. double Fpr15;
  2624. double Fpr16;
  2625. double Fpr17;
  2626. double Fpr18;
  2627. double Fpr19;
  2628. double Fpr20;
  2629. double Fpr21;
  2630. double Fpr22;
  2631. double Fpr23;
  2632. double Fpr24;
  2633. double Fpr25;
  2634. double Fpr26;
  2635. double Fpr27;
  2636. double Fpr28;
  2637. double Fpr29;
  2638. double Fpr30;
  2639. double Fpr31;
  2640. double Fpscr; // Floating point status/control reg
  2641. //
  2642. // This section is specified/returned if the ContextFlags word contains
  2643. // the flag CONTEXT_INTEGER.
  2644. //
  2645. DWORD Gpr0; // General registers 0..31
  2646. DWORD Gpr1;
  2647. DWORD Gpr2;
  2648. DWORD Gpr3;
  2649. DWORD Gpr4;
  2650. DWORD Gpr5;
  2651. DWORD Gpr6;
  2652. DWORD Gpr7;
  2653. DWORD Gpr8;
  2654. DWORD Gpr9;
  2655. DWORD Gpr10;
  2656. DWORD Gpr11;
  2657. DWORD Gpr12;
  2658. DWORD Gpr13;
  2659. DWORD Gpr14;
  2660. DWORD Gpr15;
  2661. DWORD Gpr16;
  2662. DWORD Gpr17;
  2663. DWORD Gpr18;
  2664. DWORD Gpr19;
  2665. DWORD Gpr20;
  2666. DWORD Gpr21;
  2667. DWORD Gpr22;
  2668. DWORD Gpr23;
  2669. DWORD Gpr24;
  2670. DWORD Gpr25;
  2671. DWORD Gpr26;
  2672. DWORD Gpr27;
  2673. DWORD Gpr28;
  2674. DWORD Gpr29;
  2675. DWORD Gpr30;
  2676. DWORD Gpr31;
  2677. DWORD Cr; // Condition register
  2678. DWORD Xer; // Fixed point exception register
  2679. //
  2680. // This section is specified/returned if the ContextFlags word contains
  2681. // the flag CONTEXT_CONTROL.
  2682. //
  2683. DWORD Msr; // Machine status register
  2684. DWORD Iar; // Instruction address register
  2685. DWORD Lr; // Link register
  2686. DWORD Ctr; // Count register
  2687. //
  2688. // The flags values within this flag control the contents of
  2689. // a CONTEXT record.
  2690. //
  2691. // If the context record is used as an input parameter, then
  2692. // for each portion of the context record controlled by a flag
  2693. // whose value is set, it is assumed that that portion of the
  2694. // context record contains valid context. If the context record
  2695. // is being used to modify a thread's context, then only that
  2696. // portion of the threads context will be modified.
  2697. //
  2698. // If the context record is used as an IN OUT parameter to capture
  2699. // the context of a thread, then only those portions of the thread's
  2700. // context corresponding to set flags will be returned.
  2701. //
  2702. // The context record is never used as an OUT only parameter.
  2703. //
  2704. DWORD ContextFlags;
  2705. DWORD Fill[3]; // Pad out to multiple of 16 bytes
  2706. //
  2707. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  2708. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  2709. // included in CONTEXT_FULL.
  2710. //
  2711. DWORD Dr0; // Breakpoint Register 1
  2712. DWORD Dr1; // Breakpoint Register 2
  2713. DWORD Dr2; // Breakpoint Register 3
  2714. DWORD Dr3; // Breakpoint Register 4
  2715. DWORD Dr4; // Breakpoint Register 5
  2716. DWORD Dr5; // Breakpoint Register 6
  2717. DWORD Dr6; // Debug Status Register
  2718. DWORD Dr7; // Debug Control Register
  2719. } CONTEXT, *PCONTEXT;
  2720. // end_ntddk end_nthal
  2721. //
  2722. // Stack frame header
  2723. //
  2724. // Order of appearance in stack frame:
  2725. // Header (six words)
  2726. // Parameters (at least eight words)
  2727. // Local variables
  2728. // Saved GPRs
  2729. // Saved FPRs
  2730. //
  2731. // Minimum alignment is 8 bytes
  2732. typedef struct _STACK_FRAME_HEADER { // GPR 1 points here
  2733. DWORD BackChain; // Addr of previous frame
  2734. DWORD GlueSaved1; // Used by glue code
  2735. DWORD GlueSaved2;
  2736. DWORD Reserved1; // Reserved
  2737. DWORD Spare1; // Used by tracing, profiling, ...
  2738. DWORD Spare2;
  2739. DWORD Parameter0; // First 8 parameter words are
  2740. DWORD Parameter1; // always present
  2741. DWORD Parameter2;
  2742. DWORD Parameter3;
  2743. DWORD Parameter4;
  2744. DWORD Parameter5;
  2745. DWORD Parameter6;
  2746. DWORD Parameter7;
  2747. } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
  2748. VOID
  2749. __jump_unwind (
  2750. PVOID Fp,
  2751. PVOID TargetPc
  2752. );
  2753. #endif // defined(_MPPC_)
  2754. #if !defined(__midl) && !defined(GENUTIL) && !defined(_GENIA64_) && defined(_IA64_)
  2755. void * _cdecl _rdteb(void);
  2756. #if defined(_M_IA64)
  2757. #pragma intrinsic(_rdteb)
  2758. #define NtCurrentTeb() ((struct _TEB *)_rdteb())
  2759. //
  2760. // Define functions to get the address of the current fiber and the
  2761. // current fiber data.
  2762. //
  2763. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  2764. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  2765. // begin_ntddk begin_nthal
  2766. void
  2767. __yield(
  2768. void
  2769. );
  2770. void
  2771. __mf(
  2772. void
  2773. );
  2774. void
  2775. __lfetch(
  2776. int Level,
  2777. VOID CONST *Address
  2778. );
  2779. void
  2780. __lfetchfault(
  2781. int Level,
  2782. VOID CONST *Address
  2783. );
  2784. //
  2785. // __lfetch control defines.
  2786. //
  2787. #define MD_LFHINT_NONE 0x00
  2788. #define MD_LFHINT_NT1 0x01
  2789. #define MD_LFHINT_NT2 0x02
  2790. #define MD_LFHINT_NTA 0x03
  2791. #pragma intrinsic (__yield)
  2792. #pragma intrinsic (__lfetch)
  2793. #pragma intrinsic (__lfetchfault)
  2794. #pragma intrinsic (__mf)
  2795. #define YieldProcessor __yield
  2796. #define MemoryBarrier __mf
  2797. #define PreFetchCacheLine __lfetch
  2798. //
  2799. // PreFetchCacheLine level defines.
  2800. //
  2801. #define PF_TEMPORAL_LEVEL_1 MD_LFHINT_NONE
  2802. #define PF_NON_TEMPORAL_LEVEL_ALL MD_LFHINT_NTA
  2803. // end_ntddk end_nthal
  2804. #else
  2805. struct _TEB *
  2806. NtCurrentTeb(void);
  2807. #endif
  2808. #endif // !defined(__midl) && !defined(GENUTIL) && !defined(_GENIA64_) && defined(_M_IA64)
  2809. #ifdef _IA64_
  2810. // begin_ntddk begin_nthal
  2811. //
  2812. // The following flags control the contents of the CONTEXT structure.
  2813. //
  2814. #if !defined(RC_INVOKED)
  2815. #define CONTEXT_IA64 0x00080000
  2816. #define CONTEXT_CONTROL (CONTEXT_IA64 | 0x00000001L)
  2817. #define CONTEXT_LOWER_FLOATING_POINT (CONTEXT_IA64 | 0x00000002L)
  2818. #define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004L)
  2819. #define CONTEXT_INTEGER (CONTEXT_IA64 | 0x00000008L)
  2820. #define CONTEXT_DEBUG (CONTEXT_IA64 | 0x00000010L)
  2821. #define CONTEXT_IA32_CONTROL (CONTEXT_IA64 | 0x00000020L) // Includes StIPSR
  2822. #define CONTEXT_FLOATING_POINT (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
  2823. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
  2824. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_DEBUG | CONTEXT_IA32_CONTROL)
  2825. #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
  2826. #define CONTEXT_SERVICE_ACTIVE 0x10000000
  2827. #define CONTEXT_EXCEPTION_REQUEST 0x40000000
  2828. #define CONTEXT_EXCEPTION_REPORTING 0x80000000
  2829. #endif // !defined(RC_INVOKED)
  2830. //
  2831. // Context Frame
  2832. //
  2833. // This frame has a several purposes: 1) it is used as an argument to
  2834. // NtContinue, 2) it is used to construct a call frame for APC delivery,
  2835. // 3) it is used to construct a call frame for exception dispatching
  2836. // in user mode, 4) it is used in the user level thread creation
  2837. // routines, and 5) it is used to to pass thread state to debuggers.
  2838. //
  2839. // N.B. Because this record is used as a call frame, it must be EXACTLY
  2840. // a multiple of 16 bytes in length and aligned on a 16-byte boundary.
  2841. //
  2842. typedef struct _CONTEXT {
  2843. //
  2844. // The flags values within this flag control the contents of
  2845. // a CONTEXT record.
  2846. //
  2847. // If the context record is used as an input parameter, then
  2848. // for each portion of the context record controlled by a flag
  2849. // whose value is set, it is assumed that that portion of the
  2850. // context record contains valid context. If the context record
  2851. // is being used to modify a thread's context, then only that
  2852. // portion of the threads context will be modified.
  2853. //
  2854. // If the context record is used as an IN OUT parameter to capture
  2855. // the context of a thread, then only those portions of the thread's
  2856. // context corresponding to set flags will be returned.
  2857. //
  2858. // The context record is never used as an OUT only parameter.
  2859. //
  2860. DWORD ContextFlags;
  2861. DWORD Fill1[3]; // for alignment of following on 16-byte boundary
  2862. //
  2863. // This section is specified/returned if the ContextFlags word contains
  2864. // the flag CONTEXT_DEBUG.
  2865. //
  2866. // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
  2867. //
  2868. ULONGLONG DbI0;
  2869. ULONGLONG DbI1;
  2870. ULONGLONG DbI2;
  2871. ULONGLONG DbI3;
  2872. ULONGLONG DbI4;
  2873. ULONGLONG DbI5;
  2874. ULONGLONG DbI6;
  2875. ULONGLONG DbI7;
  2876. ULONGLONG DbD0;
  2877. ULONGLONG DbD1;
  2878. ULONGLONG DbD2;
  2879. ULONGLONG DbD3;
  2880. ULONGLONG DbD4;
  2881. ULONGLONG DbD5;
  2882. ULONGLONG DbD6;
  2883. ULONGLONG DbD7;
  2884. //
  2885. // This section is specified/returned if the ContextFlags word contains
  2886. // the flag CONTEXT_LOWER_FLOATING_POINT.
  2887. //
  2888. FLOAT128 FltS0;
  2889. FLOAT128 FltS1;
  2890. FLOAT128 FltS2;
  2891. FLOAT128 FltS3;
  2892. FLOAT128 FltT0;
  2893. FLOAT128 FltT1;
  2894. FLOAT128 FltT2;
  2895. FLOAT128 FltT3;
  2896. FLOAT128 FltT4;
  2897. FLOAT128 FltT5;
  2898. FLOAT128 FltT6;
  2899. FLOAT128 FltT7;
  2900. FLOAT128 FltT8;
  2901. FLOAT128 FltT9;
  2902. //
  2903. // This section is specified/returned if the ContextFlags word contains
  2904. // the flag CONTEXT_HIGHER_FLOATING_POINT.
  2905. //
  2906. FLOAT128 FltS4;
  2907. FLOAT128 FltS5;
  2908. FLOAT128 FltS6;
  2909. FLOAT128 FltS7;
  2910. FLOAT128 FltS8;
  2911. FLOAT128 FltS9;
  2912. FLOAT128 FltS10;
  2913. FLOAT128 FltS11;
  2914. FLOAT128 FltS12;
  2915. FLOAT128 FltS13;
  2916. FLOAT128 FltS14;
  2917. FLOAT128 FltS15;
  2918. FLOAT128 FltS16;
  2919. FLOAT128 FltS17;
  2920. FLOAT128 FltS18;
  2921. FLOAT128 FltS19;
  2922. FLOAT128 FltF32;
  2923. FLOAT128 FltF33;
  2924. FLOAT128 FltF34;
  2925. FLOAT128 FltF35;
  2926. FLOAT128 FltF36;
  2927. FLOAT128 FltF37;
  2928. FLOAT128 FltF38;
  2929. FLOAT128 FltF39;
  2930. FLOAT128 FltF40;
  2931. FLOAT128 FltF41;
  2932. FLOAT128 FltF42;
  2933. FLOAT128 FltF43;
  2934. FLOAT128 FltF44;
  2935. FLOAT128 FltF45;
  2936. FLOAT128 FltF46;
  2937. FLOAT128 FltF47;
  2938. FLOAT128 FltF48;
  2939. FLOAT128 FltF49;
  2940. FLOAT128 FltF50;
  2941. FLOAT128 FltF51;
  2942. FLOAT128 FltF52;
  2943. FLOAT128 FltF53;
  2944. FLOAT128 FltF54;
  2945. FLOAT128 FltF55;
  2946. FLOAT128 FltF56;
  2947. FLOAT128 FltF57;
  2948. FLOAT128 FltF58;
  2949. FLOAT128 FltF59;
  2950. FLOAT128 FltF60;
  2951. FLOAT128 FltF61;
  2952. FLOAT128 FltF62;
  2953. FLOAT128 FltF63;
  2954. FLOAT128 FltF64;
  2955. FLOAT128 FltF65;
  2956. FLOAT128 FltF66;
  2957. FLOAT128 FltF67;
  2958. FLOAT128 FltF68;
  2959. FLOAT128 FltF69;
  2960. FLOAT128 FltF70;
  2961. FLOAT128 FltF71;
  2962. FLOAT128 FltF72;
  2963. FLOAT128 FltF73;
  2964. FLOAT128 FltF74;
  2965. FLOAT128 FltF75;
  2966. FLOAT128 FltF76;
  2967. FLOAT128 FltF77;
  2968. FLOAT128 FltF78;
  2969. FLOAT128 FltF79;
  2970. FLOAT128 FltF80;
  2971. FLOAT128 FltF81;
  2972. FLOAT128 FltF82;
  2973. FLOAT128 FltF83;
  2974. FLOAT128 FltF84;
  2975. FLOAT128 FltF85;
  2976. FLOAT128 FltF86;
  2977. FLOAT128 FltF87;
  2978. FLOAT128 FltF88;
  2979. FLOAT128 FltF89;
  2980. FLOAT128 FltF90;
  2981. FLOAT128 FltF91;
  2982. FLOAT128 FltF92;
  2983. FLOAT128 FltF93;
  2984. FLOAT128 FltF94;
  2985. FLOAT128 FltF95;
  2986. FLOAT128 FltF96;
  2987. FLOAT128 FltF97;
  2988. FLOAT128 FltF98;
  2989. FLOAT128 FltF99;
  2990. FLOAT128 FltF100;
  2991. FLOAT128 FltF101;
  2992. FLOAT128 FltF102;
  2993. FLOAT128 FltF103;
  2994. FLOAT128 FltF104;
  2995. FLOAT128 FltF105;
  2996. FLOAT128 FltF106;
  2997. FLOAT128 FltF107;
  2998. FLOAT128 FltF108;
  2999. FLOAT128 FltF109;
  3000. FLOAT128 FltF110;
  3001. FLOAT128 FltF111;
  3002. FLOAT128 FltF112;
  3003. FLOAT128 FltF113;
  3004. FLOAT128 FltF114;
  3005. FLOAT128 FltF115;
  3006. FLOAT128 FltF116;
  3007. FLOAT128 FltF117;
  3008. FLOAT128 FltF118;
  3009. FLOAT128 FltF119;
  3010. FLOAT128 FltF120;
  3011. FLOAT128 FltF121;
  3012. FLOAT128 FltF122;
  3013. FLOAT128 FltF123;
  3014. FLOAT128 FltF124;
  3015. FLOAT128 FltF125;
  3016. FLOAT128 FltF126;
  3017. FLOAT128 FltF127;
  3018. //
  3019. // This section is specified/returned if the ContextFlags word contains
  3020. // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
  3021. //
  3022. ULONGLONG StFPSR; // FP status
  3023. //
  3024. // This section is specified/returned if the ContextFlags word contains
  3025. // the flag CONTEXT_INTEGER.
  3026. //
  3027. // N.B. The registers gp, sp, rp are part of the control context
  3028. //
  3029. ULONGLONG IntGp; // r1, volatile
  3030. ULONGLONG IntT0; // r2-r3, volatile
  3031. ULONGLONG IntT1; //
  3032. ULONGLONG IntS0; // r4-r7, preserved
  3033. ULONGLONG IntS1;
  3034. ULONGLONG IntS2;
  3035. ULONGLONG IntS3;
  3036. ULONGLONG IntV0; // r8, volatile
  3037. ULONGLONG IntT2; // r9-r11, volatile
  3038. ULONGLONG IntT3;
  3039. ULONGLONG IntT4;
  3040. ULONGLONG IntSp; // stack pointer (r12), special
  3041. ULONGLONG IntTeb; // teb (r13), special
  3042. ULONGLONG IntT5; // r14-r31, volatile
  3043. ULONGLONG IntT6;
  3044. ULONGLONG IntT7;
  3045. ULONGLONG IntT8;
  3046. ULONGLONG IntT9;
  3047. ULONGLONG IntT10;
  3048. ULONGLONG IntT11;
  3049. ULONGLONG IntT12;
  3050. ULONGLONG IntT13;
  3051. ULONGLONG IntT14;
  3052. ULONGLONG IntT15;
  3053. ULONGLONG IntT16;
  3054. ULONGLONG IntT17;
  3055. ULONGLONG IntT18;
  3056. ULONGLONG IntT19;
  3057. ULONGLONG IntT20;
  3058. ULONGLONG IntT21;
  3059. ULONGLONG IntT22;
  3060. ULONGLONG IntNats; // Nat bits for r1-r31
  3061. // r1-r31 in bits 1 thru 31.
  3062. ULONGLONG Preds; // predicates, preserved
  3063. ULONGLONG BrRp; // return pointer, b0, preserved
  3064. ULONGLONG BrS0; // b1-b5, preserved
  3065. ULONGLONG BrS1;
  3066. ULONGLONG BrS2;
  3067. ULONGLONG BrS3;
  3068. ULONGLONG BrS4;
  3069. ULONGLONG BrT0; // b6-b7, volatile
  3070. ULONGLONG BrT1;
  3071. //
  3072. // This section is specified/returned if the ContextFlags word contains
  3073. // the flag CONTEXT_CONTROL.
  3074. //
  3075. // Other application registers
  3076. ULONGLONG ApUNAT; // User Nat collection register, preserved
  3077. ULONGLONG ApLC; // Loop counter register, preserved
  3078. ULONGLONG ApEC; // Epilog counter register, preserved
  3079. ULONGLONG ApCCV; // CMPXCHG value register, volatile
  3080. ULONGLONG ApDCR; // Default control register (TBD)
  3081. // Register stack info
  3082. ULONGLONG RsPFS; // Previous function state, preserved
  3083. ULONGLONG RsBSP; // Backing store pointer, preserved
  3084. ULONGLONG RsBSPSTORE;
  3085. ULONGLONG RsRSC; // RSE configuration, volatile
  3086. ULONGLONG RsRNAT; // RSE Nat collection register, preserved
  3087. // Trap Status Information
  3088. ULONGLONG StIPSR; // Interruption Processor Status
  3089. ULONGLONG StIIP; // Interruption IP
  3090. ULONGLONG StIFS; // Interruption Function State
  3091. // iA32 related control registers
  3092. ULONGLONG StFCR; // copy of Ar21
  3093. ULONGLONG Eflag; // Eflag copy of Ar24
  3094. ULONGLONG SegCSD; // iA32 CSDescriptor (Ar25)
  3095. ULONGLONG SegSSD; // iA32 SSDescriptor (Ar26)
  3096. ULONGLONG Cflag; // Cr0+Cr4 copy of Ar27
  3097. ULONGLONG StFSR; // x86 FP status (copy of AR28)
  3098. ULONGLONG StFIR; // x86 FP status (copy of AR29)
  3099. ULONGLONG StFDR; // x86 FP status (copy of AR30)
  3100. ULONGLONG UNUSEDPACK; // added to pack StFDR to 16-bytes
  3101. } CONTEXT, *PCONTEXT;
  3102. //
  3103. // Plabel descriptor structure definition
  3104. //
  3105. typedef struct _PLABEL_DESCRIPTOR {
  3106. ULONGLONG EntryPoint;
  3107. ULONGLONG GlobalPointer;
  3108. } PLABEL_DESCRIPTOR, *PPLABEL_DESCRIPTOR;
  3109. //
  3110. // Function table entry structure definition.
  3111. //
  3112. typedef struct _RUNTIME_FUNCTION {
  3113. DWORD BeginAddress;
  3114. DWORD EndAddress;
  3115. DWORD UnwindInfoAddress;
  3116. } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
  3117. //
  3118. // Define dynamic function table entry.
  3119. //
  3120. typedef
  3121. PRUNTIME_FUNCTION
  3122. (*PGET_RUNTIME_FUNCTION_CALLBACK) (
  3123. IN DWORD64 ControlPc,
  3124. IN PVOID Context
  3125. );
  3126. typedef
  3127. DWORD
  3128. (*POUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK) (
  3129. IN HANDLE Process,
  3130. IN PVOID TableAddress,
  3131. OUT PDWORD Entries,
  3132. OUT PRUNTIME_FUNCTION* Functions
  3133. );
  3134. #define OUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK_EXPORT_NAME \
  3135. "OutOfProcessFunctionTableCallback"
  3136. BOOLEAN
  3137. RtlAddFunctionTable(
  3138. IN PRUNTIME_FUNCTION FunctionTable,
  3139. IN DWORD EntryCount,
  3140. IN ULONGLONG BaseAddress,
  3141. IN ULONGLONG TargetGp
  3142. );
  3143. BOOLEAN
  3144. RtlInstallFunctionTableCallback (
  3145. IN DWORD64 TableIdentifier,
  3146. IN DWORD64 BaseAddress,
  3147. IN DWORD Length,
  3148. IN DWORD64 TargetGp,
  3149. IN PGET_RUNTIME_FUNCTION_CALLBACK Callback,
  3150. IN PVOID Context,
  3151. IN PCWSTR OutOfProcessCallbackDll OPTIONAL
  3152. );
  3153. BOOLEAN
  3154. RtlDeleteFunctionTable (
  3155. IN PRUNTIME_FUNCTION FunctionTable
  3156. );
  3157. VOID
  3158. RtlRestoreContext (
  3159. IN PCONTEXT ContextRecord,
  3160. IN struct _EXCEPTION_RECORD *ExceptionRecord OPTIONAL
  3161. );
  3162. VOID
  3163. __jump_unwind (
  3164. ULONGLONG TargetMsFrame,
  3165. ULONGLONG TargetBsFrame,
  3166. ULONGLONG TargetPc
  3167. );
  3168. #endif // _IA64_
  3169. #define EXCEPTION_NONCONTINUABLE 0x1 // Noncontinuable exception
  3170. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  3171. //
  3172. // Exception record definition.
  3173. //
  3174. typedef struct _EXCEPTION_RECORD {
  3175. DWORD ExceptionCode;
  3176. DWORD ExceptionFlags;
  3177. struct _EXCEPTION_RECORD *ExceptionRecord;
  3178. PVOID ExceptionAddress;
  3179. DWORD NumberParameters;
  3180. ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  3181. } EXCEPTION_RECORD;
  3182. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  3183. typedef struct _EXCEPTION_RECORD32 {
  3184. DWORD ExceptionCode;
  3185. DWORD ExceptionFlags;
  3186. DWORD ExceptionRecord;
  3187. DWORD ExceptionAddress;
  3188. DWORD NumberParameters;
  3189. DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  3190. } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
  3191. typedef struct _EXCEPTION_RECORD64 {
  3192. DWORD ExceptionCode;
  3193. DWORD ExceptionFlags;
  3194. DWORD64 ExceptionRecord;
  3195. DWORD64 ExceptionAddress;
  3196. DWORD NumberParameters;
  3197. DWORD __unusedAlignment;
  3198. DWORD64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  3199. } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
  3200. //
  3201. // Typedef for pointer returned by exception_info()
  3202. //
  3203. typedef struct _EXCEPTION_POINTERS {
  3204. PEXCEPTION_RECORD ExceptionRecord;
  3205. PCONTEXT ContextRecord;
  3206. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  3207. typedef PVOID PACCESS_TOKEN;
  3208. typedef PVOID PSECURITY_DESCRIPTOR;
  3209. typedef PVOID PSID;
  3210. ////////////////////////////////////////////////////////////////////////
  3211. // //
  3212. // ACCESS MASK //
  3213. // //
  3214. ////////////////////////////////////////////////////////////////////////
  3215. //
  3216. // Define the access mask as a longword sized structure divided up as
  3217. // follows:
  3218. //
  3219. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  3220. // 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
  3221. // +---------------+---------------+-------------------------------+
  3222. // |G|G|G|G|Res'd|A| StandardRights| SpecificRights |
  3223. // |R|W|E|A| |S| | |
  3224. // +-+-------------+---------------+-------------------------------+
  3225. //
  3226. // typedef struct _ACCESS_MASK {
  3227. // WORD SpecificRights;
  3228. // BYTE StandardRights;
  3229. // BYTE AccessSystemAcl : 1;
  3230. // BYTE Reserved : 3;
  3231. // BYTE GenericAll : 1;
  3232. // BYTE GenericExecute : 1;
  3233. // BYTE GenericWrite : 1;
  3234. // BYTE GenericRead : 1;
  3235. // } ACCESS_MASK;
  3236. // typedef ACCESS_MASK *PACCESS_MASK;
  3237. //
  3238. // but to make life simple for programmer's we'll allow them to specify
  3239. // a desired access mask by simply OR'ing together mulitple single rights
  3240. // and treat an access mask as a DWORD. For example
  3241. //
  3242. // DesiredAccess = DELETE | READ_CONTROL
  3243. //
  3244. // So we'll declare ACCESS_MASK as DWORD
  3245. //
  3246. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  3247. typedef DWORD ACCESS_MASK;
  3248. typedef ACCESS_MASK *PACCESS_MASK;
  3249. ////////////////////////////////////////////////////////////////////////
  3250. // //
  3251. // ACCESS TYPES //
  3252. // //
  3253. ////////////////////////////////////////////////////////////////////////
  3254. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  3255. //
  3256. // The following are masks for the predefined standard access types
  3257. //
  3258. #define DELETE (0x00010000L)
  3259. #define READ_CONTROL (0x00020000L)
  3260. #define WRITE_DAC (0x00040000L)
  3261. #define WRITE_OWNER (0x00080000L)
  3262. #define SYNCHRONIZE (0x00100000L)
  3263. #define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
  3264. #define STANDARD_RIGHTS_READ (READ_CONTROL)
  3265. #define STANDARD_RIGHTS_WRITE (READ_CONTROL)
  3266. #define STANDARD_RIGHTS_EXECUTE (READ_CONTROL)
  3267. #define STANDARD_RIGHTS_ALL (0x001F0000L)
  3268. #define SPECIFIC_RIGHTS_ALL (0x0000FFFFL)
  3269. //
  3270. // AccessSystemAcl access type
  3271. //
  3272. #define ACCESS_SYSTEM_SECURITY (0x01000000L)
  3273. //
  3274. // MaximumAllowed access type
  3275. //
  3276. #define MAXIMUM_ALLOWED (0x02000000L)
  3277. //
  3278. // These are the generic rights.
  3279. //
  3280. #define GENERIC_READ (0x80000000L)
  3281. #define GENERIC_WRITE (0x40000000L)
  3282. #define GENERIC_EXECUTE (0x20000000L)
  3283. #define GENERIC_ALL (0x10000000L)
  3284. //
  3285. // Define the generic mapping array. This is used to denote the
  3286. // mapping of each generic access right to a specific access mask.
  3287. //
  3288. typedef struct _GENERIC_MAPPING {
  3289. ACCESS_MASK GenericRead;
  3290. ACCESS_MASK GenericWrite;
  3291. ACCESS_MASK GenericExecute;
  3292. ACCESS_MASK GenericAll;
  3293. } GENERIC_MAPPING;
  3294. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  3295. ////////////////////////////////////////////////////////////////////////
  3296. // //
  3297. // LUID_AND_ATTRIBUTES //
  3298. // //
  3299. ////////////////////////////////////////////////////////////////////////
  3300. //
  3301. //
  3302. #include <pshpack4.h>
  3303. typedef struct _LUID_AND_ATTRIBUTES {
  3304. LUID Luid;
  3305. DWORD Attributes;
  3306. } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  3307. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  3308. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  3309. #include <poppack.h>
  3310. ////////////////////////////////////////////////////////////////////////
  3311. // //
  3312. // Security Id (SID) //
  3313. // //
  3314. ////////////////////////////////////////////////////////////////////////
  3315. //
  3316. //
  3317. // Pictorially the structure of an SID is as follows:
  3318. //
  3319. // 1 1 1 1 1 1
  3320. // 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  3321. // +---------------------------------------------------------------+
  3322. // | SubAuthorityCount |Reserved1 (SBZ)| Revision |
  3323. // +---------------------------------------------------------------+
  3324. // | IdentifierAuthority[0] |
  3325. // +---------------------------------------------------------------+
  3326. // | IdentifierAuthority[1] |
  3327. // +---------------------------------------------------------------+
  3328. // | IdentifierAuthority[2] |
  3329. // +---------------------------------------------------------------+
  3330. // | |
  3331. // +- - - - - - - - SubAuthority[] - - - - - - - - -+
  3332. // | |
  3333. // +---------------------------------------------------------------+
  3334. //
  3335. //
  3336. // begin_ntifs
  3337. #ifndef SID_IDENTIFIER_AUTHORITY_DEFINED
  3338. #define SID_IDENTIFIER_AUTHORITY_DEFINED
  3339. typedef struct _SID_IDENTIFIER_AUTHORITY {
  3340. BYTE Value[6];
  3341. } SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY;
  3342. #endif
  3343. #ifndef SID_DEFINED
  3344. #define SID_DEFINED
  3345. typedef struct _SID {
  3346. BYTE Revision;
  3347. BYTE SubAuthorityCount;
  3348. SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
  3349. #ifdef MIDL_PASS
  3350. [size_is(SubAuthorityCount)] DWORD SubAuthority[*];
  3351. #else // MIDL_PASS
  3352. DWORD SubAuthority[ANYSIZE_ARRAY];
  3353. #endif // MIDL_PASS
  3354. } SID, *PISID;
  3355. #endif
  3356. #define SID_REVISION (1) // Current revision level
  3357. #define SID_MAX_SUB_AUTHORITIES (15)
  3358. #define SID_RECOMMENDED_SUB_AUTHORITIES (1) // Will change to around 6
  3359. // in a future release.
  3360. #ifndef MIDL_PASS
  3361. #define SECURITY_MAX_SID_SIZE \
  3362. (sizeof(SID) - sizeof(DWORD) + (SID_MAX_SUB_AUTHORITIES * sizeof(DWORD)))
  3363. #endif // MIDL_PASS
  3364. typedef enum _SID_NAME_USE {
  3365. SidTypeUser = 1,
  3366. SidTypeGroup,
  3367. SidTypeDomain,
  3368. SidTypeAlias,
  3369. SidTypeWellKnownGroup,
  3370. SidTypeDeletedAccount,
  3371. SidTypeInvalid,
  3372. SidTypeUnknown,
  3373. SidTypeComputer
  3374. } SID_NAME_USE, *PSID_NAME_USE;
  3375. typedef struct _SID_AND_ATTRIBUTES {
  3376. PSID Sid;
  3377. DWORD Attributes;
  3378. } SID_AND_ATTRIBUTES, * PSID_AND_ATTRIBUTES;
  3379. typedef SID_AND_ATTRIBUTES SID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  3380. typedef SID_AND_ATTRIBUTES_ARRAY *PSID_AND_ATTRIBUTES_ARRAY;
  3381. /////////////////////////////////////////////////////////////////////////////
  3382. // //
  3383. // Universal well-known SIDs //
  3384. // //
  3385. // Null SID S-1-0-0 //
  3386. // World S-1-1-0 //
  3387. // Local S-1-2-0 //
  3388. // Creator Owner ID S-1-3-0 //
  3389. // Creator Group ID S-1-3-1 //
  3390. // Creator Owner Server ID S-1-3-2 //
  3391. // Creator Group Server ID S-1-3-3 //
  3392. // //
  3393. // (Non-unique IDs) S-1-4 //
  3394. // //
  3395. /////////////////////////////////////////////////////////////////////////////
  3396. #define SECURITY_NULL_SID_AUTHORITY {0,0,0,0,0,0}
  3397. #define SECURITY_WORLD_SID_AUTHORITY {0,0,0,0,0,1}
  3398. #define SECURITY_LOCAL_SID_AUTHORITY {0,0,0,0,0,2}
  3399. #define SECURITY_CREATOR_SID_AUTHORITY {0,0,0,0,0,3}
  3400. #define SECURITY_NON_UNIQUE_AUTHORITY {0,0,0,0,0,4}
  3401. #define SECURITY_RESOURCE_MANAGER_AUTHORITY {0,0,0,0,0,9}
  3402. #define SECURITY_NULL_RID (0x00000000L)
  3403. #define SECURITY_WORLD_RID (0x00000000L)
  3404. #define SECURITY_LOCAL_RID (0x00000000L)
  3405. #define SECURITY_CREATOR_OWNER_RID (0x00000000L)
  3406. #define SECURITY_CREATOR_GROUP_RID (0x00000001L)
  3407. #define SECURITY_CREATOR_OWNER_SERVER_RID (0x00000002L)
  3408. #define SECURITY_CREATOR_GROUP_SERVER_RID (0x00000003L)
  3409. ///////////////////////////////////////////////////////////////////////////////
  3410. // //
  3411. // NT well-known SIDs //
  3412. // //
  3413. // NT Authority S-1-5 //
  3414. // Dialup S-1-5-1 //
  3415. // //
  3416. // Network S-1-5-2 //
  3417. // Batch S-1-5-3 //
  3418. // Interactive S-1-5-4 //
  3419. // (Logon IDs) S-1-5-5-X-Y //
  3420. // Service S-1-5-6 //
  3421. // AnonymousLogon S-1-5-7 (aka null logon session) //
  3422. // Proxy S-1-5-8 //
  3423. // Enterprise DC (EDC) S-1-5-9 (aka domain controller account) //
  3424. // Self S-1-5-10 (self RID) //
  3425. // Authenticated User S-1-5-11 (Authenticated user somewhere) //
  3426. // Restricted Code S-1-5-12 (Running restricted code) //
  3427. // Terminal Server S-1-5-13 (Running on Terminal Server) //
  3428. // Remote Logon S-1-5-14 (Remote Interactive Logon) //
  3429. // This Organization S-1-5-15 //
  3430. // //
  3431. // Local System S-1-5-18 //
  3432. // Local Service S-1-5-19 //
  3433. // Network Service S-1-5-20 //
  3434. // //
  3435. // (NT non-unique IDs) S-1-5-0x15-... (NT Domain Sids) //
  3436. // //
  3437. // (Built-in domain) S-1-5-0x20 //
  3438. // //
  3439. // (Security Package IDs) S-1-5-0x40 //
  3440. // NTLM Authentication S-1-5-0x40-10 //
  3441. // SChannel Authentication S-1-5-0x40-14 //
  3442. // Digest Authentication S-1-5-0x40-21 //
  3443. // //
  3444. // Other Organization S-1-5-1000 (>=1000 can not be filtered) //
  3445. // //
  3446. // //
  3447. // NOTE: the relative identifier values (RIDs) determine which security //
  3448. // boundaries the SID is allowed to cross. Before adding new RIDs, //
  3449. // a determination needs to be made regarding which range they should //
  3450. // be added to in order to ensure proper "SID filtering" //
  3451. // //
  3452. ///////////////////////////////////////////////////////////////////////////////
  3453. #define SECURITY_NT_AUTHORITY {0,0,0,0,0,5} // ntifs
  3454. #define SECURITY_DIALUP_RID (0x00000001L)
  3455. #define SECURITY_NETWORK_RID (0x00000002L)
  3456. #define SECURITY_BATCH_RID (0x00000003L)
  3457. #define SECURITY_INTERACTIVE_RID (0x00000004L)
  3458. #define SECURITY_LOGON_IDS_RID (0x00000005L)
  3459. #define SECURITY_LOGON_IDS_RID_COUNT (3L)
  3460. #define SECURITY_SERVICE_RID (0x00000006L)
  3461. #define SECURITY_ANONYMOUS_LOGON_RID (0x00000007L)
  3462. #define SECURITY_PROXY_RID (0x00000008L)
  3463. #define SECURITY_ENTERPRISE_CONTROLLERS_RID (0x00000009L)
  3464. #define SECURITY_SERVER_LOGON_RID SECURITY_ENTERPRISE_CONTROLLERS_RID
  3465. #define SECURITY_PRINCIPAL_SELF_RID (0x0000000AL)
  3466. #define SECURITY_AUTHENTICATED_USER_RID (0x0000000BL)
  3467. #define SECURITY_RESTRICTED_CODE_RID (0x0000000CL)
  3468. #define SECURITY_TERMINAL_SERVER_RID (0x0000000DL)
  3469. #define SECURITY_REMOTE_LOGON_RID (0x0000000EL)
  3470. #define SECURITY_THIS_ORGANIZATION_RID (0x0000000FL)
  3471. #define SECURITY_LOCAL_SYSTEM_RID (0x00000012L)
  3472. #define SECURITY_LOCAL_SERVICE_RID (0x00000013L)
  3473. #define SECURITY_NETWORK_SERVICE_RID (0x00000014L)
  3474. #define SECURITY_NT_NON_UNIQUE (0x00000015L)
  3475. #define SECURITY_NT_NON_UNIQUE_SUB_AUTH_COUNT (3L)
  3476. #define SECURITY_BUILTIN_DOMAIN_RID (0x00000020L)
  3477. #define SECURITY_PACKAGE_BASE_RID (0x00000040L)
  3478. #define SECURITY_PACKAGE_RID_COUNT (2L)
  3479. #define SECURITY_PACKAGE_NTLM_RID (0x0000000AL)
  3480. #define SECURITY_PACKAGE_SCHANNEL_RID (0x0000000EL)
  3481. #define SECURITY_PACKAGE_DIGEST_RID (0x00000015L)
  3482. #define SECURITY_MAX_ALWAYS_FILTERED (0x000003E7L)
  3483. #define SECURITY_MIN_NEVER_FILTERED (0x000003E8L)
  3484. #define SECURITY_OTHER_ORGANIZATION_RID (0x000003E8L)
  3485. /////////////////////////////////////////////////////////////////////////////
  3486. // //
  3487. // well-known domain relative sub-authority values (RIDs)... //
  3488. // //
  3489. /////////////////////////////////////////////////////////////////////////////
  3490. // Well-known users ...
  3491. #define FOREST_USER_RID_MAX (0x000001F3L)
  3492. #define DOMAIN_USER_RID_ADMIN (0x000001F4L)
  3493. #define DOMAIN_USER_RID_GUEST (0x000001F5L)
  3494. #define DOMAIN_USER_RID_KRBTGT (0x000001F6L)
  3495. #define DOMAIN_USER_RID_MAX (0x000003E7L)
  3496. // well-known groups ...
  3497. #define DOMAIN_GROUP_RID_ADMINS (0x00000200L)
  3498. #define DOMAIN_GROUP_RID_USERS (0x00000201L)
  3499. #define DOMAIN_GROUP_RID_GUESTS (0x00000202L)
  3500. #define DOMAIN_GROUP_RID_COMPUTERS (0x00000203L)
  3501. #define DOMAIN_GROUP_RID_CONTROLLERS (0x00000204L)
  3502. #define DOMAIN_GROUP_RID_CERT_ADMINS (0x00000205L)
  3503. #define DOMAIN_GROUP_RID_SCHEMA_ADMINS (0x00000206L)
  3504. #define DOMAIN_GROUP_RID_ENTERPRISE_ADMINS (0x00000207L)
  3505. #define DOMAIN_GROUP_RID_POLICY_ADMINS (0x00000208L)
  3506. // well-known aliases ...
  3507. #define DOMAIN_ALIAS_RID_ADMINS (0x00000220L)
  3508. #define DOMAIN_ALIAS_RID_USERS (0x00000221L)
  3509. #define DOMAIN_ALIAS_RID_GUESTS (0x00000222L)
  3510. #define DOMAIN_ALIAS_RID_POWER_USERS (0x00000223L)
  3511. #define DOMAIN_ALIAS_RID_ACCOUNT_OPS (0x00000224L)
  3512. #define DOMAIN_ALIAS_RID_SYSTEM_OPS (0x00000225L)
  3513. #define DOMAIN_ALIAS_RID_PRINT_OPS (0x00000226L)
  3514. #define DOMAIN_ALIAS_RID_BACKUP_OPS (0x00000227L)
  3515. #define DOMAIN_ALIAS_RID_REPLICATOR (0x00000228L)
  3516. #define DOMAIN_ALIAS_RID_RAS_SERVERS (0x00000229L)
  3517. #define DOMAIN_ALIAS_RID_PREW2KCOMPACCESS (0x0000022AL)
  3518. #define DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS (0x0000022BL)
  3519. #define DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS (0x0000022CL)
  3520. #define DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS (0x0000022DL)
  3521. #define DOMAIN_ALIAS_RID_MONITORING_USERS (0x0000022EL)
  3522. #define DOMAIN_ALIAS_RID_LOGGING_USERS (0x0000022FL)
  3523. #define DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS (0x00000230L)
  3524. #define DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS (0x00000231L)
  3525. typedef enum {
  3526. WinNullSid = 0,
  3527. WinWorldSid = 1,
  3528. WinLocalSid = 2,
  3529. WinCreatorOwnerSid = 3,
  3530. WinCreatorGroupSid = 4,
  3531. WinCreatorOwnerServerSid = 5,
  3532. WinCreatorGroupServerSid = 6,
  3533. WinNtAuthoritySid = 7,
  3534. WinDialupSid = 8,
  3535. WinNetworkSid = 9,
  3536. WinBatchSid = 10,
  3537. WinInteractiveSid = 11,
  3538. WinServiceSid = 12,
  3539. WinAnonymousSid = 13,
  3540. WinProxySid = 14,
  3541. WinEnterpriseControllersSid = 15,
  3542. WinSelfSid = 16,
  3543. WinAuthenticatedUserSid = 17,
  3544. WinRestrictedCodeSid = 18,
  3545. WinTerminalServerSid = 19,
  3546. WinRemoteLogonIdSid = 20,
  3547. WinLogonIdsSid = 21,
  3548. WinLocalSystemSid = 22,
  3549. WinLocalServiceSid = 23,
  3550. WinNetworkServiceSid = 24,
  3551. WinBuiltinDomainSid = 25,
  3552. WinBuiltinAdministratorsSid = 26,
  3553. WinBuiltinUsersSid = 27,
  3554. WinBuiltinGuestsSid = 28,
  3555. WinBuiltinPowerUsersSid = 29,
  3556. WinBuiltinAccountOperatorsSid = 30,
  3557. WinBuiltinSystemOperatorsSid = 31,
  3558. WinBuiltinPrintOperatorsSid = 32,
  3559. WinBuiltinBackupOperatorsSid = 33,
  3560. WinBuiltinReplicatorSid = 34,
  3561. WinBuiltinPreWindows2000CompatibleAccessSid = 35,
  3562. WinBuiltinRemoteDesktopUsersSid = 36,
  3563. WinBuiltinNetworkConfigurationOperatorsSid = 37,
  3564. WinAccountAdministratorSid = 38,
  3565. WinAccountGuestSid = 39,
  3566. WinAccountKrbtgtSid = 40,
  3567. WinAccountDomainAdminsSid = 41,
  3568. WinAccountDomainUsersSid = 42,
  3569. WinAccountDomainGuestsSid = 43,
  3570. WinAccountComputersSid = 44,
  3571. WinAccountControllersSid = 45,
  3572. WinAccountCertAdminsSid = 46,
  3573. WinAccountSchemaAdminsSid = 47,
  3574. WinAccountEnterpriseAdminsSid = 48,
  3575. WinAccountPolicyAdminsSid = 49,
  3576. WinAccountRasAndIasServersSid = 50,
  3577. WinNTLMAuthenticationSid = 51,
  3578. WinDigestAuthenticationSid = 52,
  3579. WinSChannelAuthenticationSid = 53,
  3580. WinThisOrganizationSid = 54,
  3581. WinOtherOrganizationSid = 55,
  3582. WinBuiltinIncomingForestTrustBuildersSid = 56,
  3583. WinBuiltinPerfMonitoringUsersSid = 57,
  3584. WinBuiltinPerfLoggingUsersSid = 58,
  3585. WinBuiltinAuthorizationAccessSid = 59,
  3586. WinBuiltinTerminalServerLicenseServersSid = 60,
  3587. } WELL_KNOWN_SID_TYPE;
  3588. //
  3589. // Allocate the System Luid. The first 1000 LUIDs are reserved.
  3590. // Use #999 here (0x3E7 = 999)
  3591. //
  3592. #define SYSTEM_LUID { 0x3E7, 0x0 }
  3593. #define ANONYMOUS_LOGON_LUID { 0x3e6, 0x0 }
  3594. #define LOCALSERVICE_LUID { 0x3e5, 0x0 }
  3595. #define NETWORKSERVICE_LUID { 0x3e4, 0x0 }
  3596. // end_ntifs
  3597. ////////////////////////////////////////////////////////////////////////
  3598. // //
  3599. // User and Group related SID attributes //
  3600. // //
  3601. ////////////////////////////////////////////////////////////////////////
  3602. //
  3603. // Group attributes
  3604. //
  3605. #define SE_GROUP_MANDATORY (0x00000001L)
  3606. #define SE_GROUP_ENABLED_BY_DEFAULT (0x00000002L)
  3607. #define SE_GROUP_ENABLED (0x00000004L)
  3608. #define SE_GROUP_OWNER (0x00000008L)
  3609. #define SE_GROUP_USE_FOR_DENY_ONLY (0x00000010L)
  3610. #define SE_GROUP_LOGON_ID (0xC0000000L)
  3611. #define SE_GROUP_RESOURCE (0x20000000L)
  3612. //
  3613. // User attributes
  3614. //
  3615. // (None yet defined.)
  3616. ////////////////////////////////////////////////////////////////////////
  3617. // //
  3618. // ACL and ACE //
  3619. // //
  3620. ////////////////////////////////////////////////////////////////////////
  3621. //
  3622. // Define an ACL and the ACE format. The structure of an ACL header
  3623. // followed by one or more ACEs. Pictorally the structure of an ACL header
  3624. // is as follows:
  3625. //
  3626. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  3627. // 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
  3628. // +-------------------------------+---------------+---------------+
  3629. // | AclSize | Sbz1 | AclRevision |
  3630. // +-------------------------------+---------------+---------------+
  3631. // | Sbz2 | AceCount |
  3632. // +-------------------------------+-------------------------------+
  3633. //
  3634. // The current AclRevision is defined to be ACL_REVISION.
  3635. //
  3636. // AclSize is the size, in bytes, allocated for the ACL. This includes
  3637. // the ACL header, ACES, and remaining free space in the buffer.
  3638. //
  3639. // AceCount is the number of ACES in the ACL.
  3640. //
  3641. // begin_ntddk begin_wdm begin_ntifs
  3642. // This is the *current* ACL revision
  3643. #define ACL_REVISION (2)
  3644. #define ACL_REVISION_DS (4)
  3645. // This is the history of ACL revisions. Add a new one whenever
  3646. // ACL_REVISION is updated
  3647. #define ACL_REVISION1 (1)
  3648. #define MIN_ACL_REVISION ACL_REVISION2
  3649. #define ACL_REVISION2 (2)
  3650. #define ACL_REVISION3 (3)
  3651. #define ACL_REVISION4 (4)
  3652. #define MAX_ACL_REVISION ACL_REVISION4
  3653. typedef struct _ACL {
  3654. BYTE AclRevision;
  3655. BYTE Sbz1;
  3656. WORD AclSize;
  3657. WORD AceCount;
  3658. WORD Sbz2;
  3659. } ACL;
  3660. typedef ACL *PACL;
  3661. // end_ntddk end_wdm
  3662. //
  3663. // The structure of an ACE is a common ace header followed by ace type
  3664. // specific data. Pictorally the structure of the common ace header is
  3665. // as follows:
  3666. //
  3667. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  3668. // 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
  3669. // +---------------+-------+-------+---------------+---------------+
  3670. // | AceSize | AceFlags | AceType |
  3671. // +---------------+-------+-------+---------------+---------------+
  3672. //
  3673. // AceType denotes the type of the ace, there are some predefined ace
  3674. // types
  3675. //
  3676. // AceSize is the size, in bytes, of ace.
  3677. //
  3678. // AceFlags are the Ace flags for audit and inheritance, defined shortly.
  3679. typedef struct _ACE_HEADER {
  3680. BYTE AceType;
  3681. BYTE AceFlags;
  3682. WORD AceSize;
  3683. } ACE_HEADER;
  3684. typedef ACE_HEADER *PACE_HEADER;
  3685. //
  3686. // The following are the predefined ace types that go into the AceType
  3687. // field of an Ace header.
  3688. //
  3689. #define ACCESS_MIN_MS_ACE_TYPE (0x0)
  3690. #define ACCESS_ALLOWED_ACE_TYPE (0x0)
  3691. #define ACCESS_DENIED_ACE_TYPE (0x1)
  3692. #define SYSTEM_AUDIT_ACE_TYPE (0x2)
  3693. #define SYSTEM_ALARM_ACE_TYPE (0x3)
  3694. #define ACCESS_MAX_MS_V2_ACE_TYPE (0x3)
  3695. #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE (0x4)
  3696. #define ACCESS_MAX_MS_V3_ACE_TYPE (0x4)
  3697. #define ACCESS_MIN_MS_OBJECT_ACE_TYPE (0x5)
  3698. #define ACCESS_ALLOWED_OBJECT_ACE_TYPE (0x5)
  3699. #define ACCESS_DENIED_OBJECT_ACE_TYPE (0x6)
  3700. #define SYSTEM_AUDIT_OBJECT_ACE_TYPE (0x7)
  3701. #define SYSTEM_ALARM_OBJECT_ACE_TYPE (0x8)
  3702. #define ACCESS_MAX_MS_OBJECT_ACE_TYPE (0x8)
  3703. #define ACCESS_MAX_MS_V4_ACE_TYPE (0x8)
  3704. #define ACCESS_MAX_MS_ACE_TYPE (0x8)
  3705. #define ACCESS_ALLOWED_CALLBACK_ACE_TYPE (0x9)
  3706. #define ACCESS_DENIED_CALLBACK_ACE_TYPE (0xA)
  3707. #define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE (0xB)
  3708. #define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE (0xC)
  3709. #define SYSTEM_AUDIT_CALLBACK_ACE_TYPE (0xD)
  3710. #define SYSTEM_ALARM_CALLBACK_ACE_TYPE (0xE)
  3711. #define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE (0xF)
  3712. #define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE (0x10)
  3713. #define ACCESS_MAX_MS_V5_ACE_TYPE (0x10)
  3714. //
  3715. // The following are the inherit flags that go into the AceFlags field
  3716. // of an Ace header.
  3717. //
  3718. #define OBJECT_INHERIT_ACE (0x1)
  3719. #define CONTAINER_INHERIT_ACE (0x2)
  3720. #define NO_PROPAGATE_INHERIT_ACE (0x4)
  3721. #define INHERIT_ONLY_ACE (0x8)
  3722. #define INHERITED_ACE (0x10)
  3723. #define VALID_INHERIT_FLAGS (0x1F)
  3724. // The following are the currently defined ACE flags that go into the
  3725. // AceFlags field of an ACE header. Each ACE type has its own set of
  3726. // AceFlags.
  3727. //
  3728. // SUCCESSFUL_ACCESS_ACE_FLAG - used only with system audit and alarm ACE
  3729. // types to indicate that a message is generated for successful accesses.
  3730. //
  3731. // FAILED_ACCESS_ACE_FLAG - used only with system audit and alarm ACE types
  3732. // to indicate that a message is generated for failed accesses.
  3733. //
  3734. //
  3735. // SYSTEM_AUDIT and SYSTEM_ALARM AceFlags
  3736. //
  3737. // These control the signaling of audit and alarms for success or failure.
  3738. //
  3739. #define SUCCESSFUL_ACCESS_ACE_FLAG (0x40)
  3740. #define FAILED_ACCESS_ACE_FLAG (0x80)
  3741. //
  3742. // We'll define the structure of the predefined ACE types. Pictorally
  3743. // the structure of the predefined ACE's is as follows:
  3744. //
  3745. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  3746. // 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
  3747. // +---------------+-------+-------+---------------+---------------+
  3748. // | AceFlags | Resd |Inherit| AceSize | AceType |
  3749. // +---------------+-------+-------+---------------+---------------+
  3750. // | Mask |
  3751. // +---------------------------------------------------------------+
  3752. // | |
  3753. // + +
  3754. // | |
  3755. // + Sid +
  3756. // | |
  3757. // + +
  3758. // | |
  3759. // +---------------------------------------------------------------+
  3760. //
  3761. // Mask is the access mask associated with the ACE. This is either the
  3762. // access allowed, access denied, audit, or alarm mask.
  3763. //
  3764. // Sid is the Sid associated with the ACE.
  3765. //
  3766. // The following are the four predefined ACE types.
  3767. // Examine the AceType field in the Header to determine
  3768. // which structure is appropriate to use for casting.
  3769. typedef struct _ACCESS_ALLOWED_ACE {
  3770. ACE_HEADER Header;
  3771. ACCESS_MASK Mask;
  3772. DWORD SidStart;
  3773. } ACCESS_ALLOWED_ACE;
  3774. typedef ACCESS_ALLOWED_ACE *PACCESS_ALLOWED_ACE;
  3775. typedef struct _ACCESS_DENIED_ACE {
  3776. ACE_HEADER Header;
  3777. ACCESS_MASK Mask;
  3778. DWORD SidStart;
  3779. } ACCESS_DENIED_ACE;
  3780. typedef ACCESS_DENIED_ACE *PACCESS_DENIED_ACE;
  3781. typedef struct _SYSTEM_AUDIT_ACE {
  3782. ACE_HEADER Header;
  3783. ACCESS_MASK Mask;
  3784. DWORD SidStart;
  3785. } SYSTEM_AUDIT_ACE;
  3786. typedef SYSTEM_AUDIT_ACE *PSYSTEM_AUDIT_ACE;
  3787. typedef struct _SYSTEM_ALARM_ACE {
  3788. ACE_HEADER Header;
  3789. ACCESS_MASK Mask;
  3790. DWORD SidStart;
  3791. } SYSTEM_ALARM_ACE;
  3792. typedef SYSTEM_ALARM_ACE *PSYSTEM_ALARM_ACE;
  3793. // end_ntifs
  3794. typedef struct _ACCESS_ALLOWED_OBJECT_ACE {
  3795. ACE_HEADER Header;
  3796. ACCESS_MASK Mask;
  3797. DWORD Flags;
  3798. GUID ObjectType;
  3799. GUID InheritedObjectType;
  3800. DWORD SidStart;
  3801. } ACCESS_ALLOWED_OBJECT_ACE, *PACCESS_ALLOWED_OBJECT_ACE;
  3802. typedef struct _ACCESS_DENIED_OBJECT_ACE {
  3803. ACE_HEADER Header;
  3804. ACCESS_MASK Mask;
  3805. DWORD Flags;
  3806. GUID ObjectType;
  3807. GUID InheritedObjectType;
  3808. DWORD SidStart;
  3809. } ACCESS_DENIED_OBJECT_ACE, *PACCESS_DENIED_OBJECT_ACE;
  3810. typedef struct _SYSTEM_AUDIT_OBJECT_ACE {
  3811. ACE_HEADER Header;
  3812. ACCESS_MASK Mask;
  3813. DWORD Flags;
  3814. GUID ObjectType;
  3815. GUID InheritedObjectType;
  3816. DWORD SidStart;
  3817. } SYSTEM_AUDIT_OBJECT_ACE, *PSYSTEM_AUDIT_OBJECT_ACE;
  3818. typedef struct _SYSTEM_ALARM_OBJECT_ACE {
  3819. ACE_HEADER Header;
  3820. ACCESS_MASK Mask;
  3821. DWORD Flags;
  3822. GUID ObjectType;
  3823. GUID InheritedObjectType;
  3824. DWORD SidStart;
  3825. } SYSTEM_ALARM_OBJECT_ACE, *PSYSTEM_ALARM_OBJECT_ACE;
  3826. //
  3827. // Callback ace support in post Win2000.
  3828. // Resource managers can put their own data after Sidstart + Length of the sid
  3829. //
  3830. typedef struct _ACCESS_ALLOWED_CALLBACK_ACE {
  3831. ACE_HEADER Header;
  3832. ACCESS_MASK Mask;
  3833. DWORD SidStart;
  3834. // Opaque resouce manager specific data
  3835. } ACCESS_ALLOWED_CALLBACK_ACE, *PACCESS_ALLOWED_CALLBACK_ACE;
  3836. typedef struct _ACCESS_DENIED_CALLBACK_ACE {
  3837. ACE_HEADER Header;
  3838. ACCESS_MASK Mask;
  3839. DWORD SidStart;
  3840. // Opaque resouce manager specific data
  3841. } ACCESS_DENIED_CALLBACK_ACE, *PACCESS_DENIED_CALLBACK_ACE;
  3842. typedef struct _SYSTEM_AUDIT_CALLBACK_ACE {
  3843. ACE_HEADER Header;
  3844. ACCESS_MASK Mask;
  3845. DWORD SidStart;
  3846. // Opaque resouce manager specific data
  3847. } SYSTEM_AUDIT_CALLBACK_ACE, *PSYSTEM_AUDIT_CALLBACK_ACE;
  3848. typedef struct _SYSTEM_ALARM_CALLBACK_ACE {
  3849. ACE_HEADER Header;
  3850. ACCESS_MASK Mask;
  3851. DWORD SidStart;
  3852. // Opaque resouce manager specific data
  3853. } SYSTEM_ALARM_CALLBACK_ACE, *PSYSTEM_ALARM_CALLBACK_ACE;
  3854. typedef struct _ACCESS_ALLOWED_CALLBACK_OBJECT_ACE {
  3855. ACE_HEADER Header;
  3856. ACCESS_MASK Mask;
  3857. DWORD Flags;
  3858. GUID ObjectType;
  3859. GUID InheritedObjectType;
  3860. DWORD SidStart;
  3861. // Opaque resouce manager specific data
  3862. } ACCESS_ALLOWED_CALLBACK_OBJECT_ACE, *PACCESS_ALLOWED_CALLBACK_OBJECT_ACE;
  3863. typedef struct _ACCESS_DENIED_CALLBACK_OBJECT_ACE {
  3864. ACE_HEADER Header;
  3865. ACCESS_MASK Mask;
  3866. DWORD Flags;
  3867. GUID ObjectType;
  3868. GUID InheritedObjectType;
  3869. DWORD SidStart;
  3870. // Opaque resouce manager specific data
  3871. } ACCESS_DENIED_CALLBACK_OBJECT_ACE, *PACCESS_DENIED_CALLBACK_OBJECT_ACE;
  3872. typedef struct _SYSTEM_AUDIT_CALLBACK_OBJECT_ACE {
  3873. ACE_HEADER Header;
  3874. ACCESS_MASK Mask;
  3875. DWORD Flags;
  3876. GUID ObjectType;
  3877. GUID InheritedObjectType;
  3878. DWORD SidStart;
  3879. // Opaque resouce manager specific data
  3880. } SYSTEM_AUDIT_CALLBACK_OBJECT_ACE, *PSYSTEM_AUDIT_CALLBACK_OBJECT_ACE;
  3881. typedef struct _SYSTEM_ALARM_CALLBACK_OBJECT_ACE {
  3882. ACE_HEADER Header;
  3883. ACCESS_MASK Mask;
  3884. DWORD Flags;
  3885. GUID ObjectType;
  3886. GUID InheritedObjectType;
  3887. DWORD SidStart;
  3888. // Opaque resouce manager specific data
  3889. } SYSTEM_ALARM_CALLBACK_OBJECT_ACE, *PSYSTEM_ALARM_CALLBACK_OBJECT_ACE;
  3890. //
  3891. // Currently define Flags for "OBJECT" ACE types.
  3892. //
  3893. #define ACE_OBJECT_TYPE_PRESENT 0x1
  3894. #define ACE_INHERITED_OBJECT_TYPE_PRESENT 0x2
  3895. //
  3896. // The following declarations are used for setting and querying information
  3897. // about and ACL. First are the various information classes available to
  3898. // the user.
  3899. //
  3900. typedef enum _ACL_INFORMATION_CLASS {
  3901. AclRevisionInformation = 1,
  3902. AclSizeInformation
  3903. } ACL_INFORMATION_CLASS;
  3904. //
  3905. // This record is returned/sent if the user is requesting/setting the
  3906. // AclRevisionInformation
  3907. //
  3908. typedef struct _ACL_REVISION_INFORMATION {
  3909. DWORD AclRevision;
  3910. } ACL_REVISION_INFORMATION;
  3911. typedef ACL_REVISION_INFORMATION *PACL_REVISION_INFORMATION;
  3912. //
  3913. // This record is returned if the user is requesting AclSizeInformation
  3914. //
  3915. typedef struct _ACL_SIZE_INFORMATION {
  3916. DWORD AceCount;
  3917. DWORD AclBytesInUse;
  3918. DWORD AclBytesFree;
  3919. } ACL_SIZE_INFORMATION;
  3920. typedef ACL_SIZE_INFORMATION *PACL_SIZE_INFORMATION;
  3921. ////////////////////////////////////////////////////////////////////////
  3922. // //
  3923. // SECURITY_DESCRIPTOR //
  3924. // //
  3925. ////////////////////////////////////////////////////////////////////////
  3926. //
  3927. // Define the Security Descriptor and related data types.
  3928. // This is an opaque data structure.
  3929. //
  3930. // begin_wdm begin_ntddk begin_ntifs
  3931. //
  3932. // Current security descriptor revision value
  3933. //
  3934. #define SECURITY_DESCRIPTOR_REVISION (1)
  3935. #define SECURITY_DESCRIPTOR_REVISION1 (1)
  3936. // end_wdm end_ntddk
  3937. #define SECURITY_DESCRIPTOR_MIN_LENGTH (sizeof(SECURITY_DESCRIPTOR))
  3938. typedef WORD SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
  3939. #define SE_OWNER_DEFAULTED (0x0001)
  3940. #define SE_GROUP_DEFAULTED (0x0002)
  3941. #define SE_DACL_PRESENT (0x0004)
  3942. #define SE_DACL_DEFAULTED (0x0008)
  3943. #define SE_SACL_PRESENT (0x0010)
  3944. #define SE_SACL_DEFAULTED (0x0020)
  3945. #define SE_DACL_AUTO_INHERIT_REQ (0x0100)
  3946. #define SE_SACL_AUTO_INHERIT_REQ (0x0200)
  3947. #define SE_DACL_AUTO_INHERITED (0x0400)
  3948. #define SE_SACL_AUTO_INHERITED (0x0800)
  3949. #define SE_DACL_PROTECTED (0x1000)
  3950. #define SE_SACL_PROTECTED (0x2000)
  3951. #define SE_RM_CONTROL_VALID (0x4000)
  3952. #define SE_SELF_RELATIVE (0x8000)
  3953. //
  3954. // Where:
  3955. //
  3956. // SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the
  3957. // SID pointed to by the Owner field was provided by a
  3958. // defaulting mechanism rather than explicitly provided by the
  3959. // original provider of the security descriptor. This may
  3960. // affect the treatment of the SID with respect to inheritence
  3961. // of an owner.
  3962. //
  3963. // SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the
  3964. // SID in the Group field was provided by a defaulting mechanism
  3965. // rather than explicitly provided by the original provider of
  3966. // the security descriptor. This may affect the treatment of
  3967. // the SID with respect to inheritence of a primary group.
  3968. //
  3969. // SE_DACL_PRESENT - This boolean flag, when set, indicates that the
  3970. // security descriptor contains a discretionary ACL. If this
  3971. // flag is set and the Dacl field of the SECURITY_DESCRIPTOR is
  3972. // null, then a null ACL is explicitly being specified.
  3973. //
  3974. // SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the
  3975. // ACL pointed to by the Dacl field was provided by a defaulting
  3976. // mechanism rather than explicitly provided by the original
  3977. // provider of the security descriptor. This may affect the
  3978. // treatment of the ACL with respect to inheritence of an ACL.
  3979. // This flag is ignored if the DaclPresent flag is not set.
  3980. //
  3981. // SE_SACL_PRESENT - This boolean flag, when set, indicates that the
  3982. // security descriptor contains a system ACL pointed to by the
  3983. // Sacl field. If this flag is set and the Sacl field of the
  3984. // SECURITY_DESCRIPTOR is null, then an empty (but present)
  3985. // ACL is being specified.
  3986. //
  3987. // SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the
  3988. // ACL pointed to by the Sacl field was provided by a defaulting
  3989. // mechanism rather than explicitly provided by the original
  3990. // provider of the security descriptor. This may affect the
  3991. // treatment of the ACL with respect to inheritence of an ACL.
  3992. // This flag is ignored if the SaclPresent flag is not set.
  3993. //
  3994. // SE_SELF_RELATIVE - This boolean flag, when set, indicates that the
  3995. // security descriptor is in self-relative form. In this form,
  3996. // all fields of the security descriptor are contiguous in memory
  3997. // and all pointer fields are expressed as offsets from the
  3998. // beginning of the security descriptor. This form is useful
  3999. // for treating security descriptors as opaque data structures
  4000. // for transmission in communication protocol or for storage on
  4001. // secondary media.
  4002. //
  4003. //
  4004. //
  4005. // Pictorially the structure of a security descriptor is as follows:
  4006. //
  4007. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  4008. // 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
  4009. // +---------------------------------------------------------------+
  4010. // | Control |Reserved1 (SBZ)| Revision |
  4011. // +---------------------------------------------------------------+
  4012. // | Owner |
  4013. // +---------------------------------------------------------------+
  4014. // | Group |
  4015. // +---------------------------------------------------------------+
  4016. // | Sacl |
  4017. // +---------------------------------------------------------------+
  4018. // | Dacl |
  4019. // +---------------------------------------------------------------+
  4020. //
  4021. // In general, this data structure should be treated opaquely to ensure future
  4022. // compatibility.
  4023. //
  4024. //
  4025. typedef struct _SECURITY_DESCRIPTOR_RELATIVE {
  4026. BYTE Revision;
  4027. BYTE Sbz1;
  4028. SECURITY_DESCRIPTOR_CONTROL Control;
  4029. DWORD Owner;
  4030. DWORD Group;
  4031. DWORD Sacl;
  4032. DWORD Dacl;
  4033. } SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
  4034. typedef struct _SECURITY_DESCRIPTOR {
  4035. BYTE Revision;
  4036. BYTE Sbz1;
  4037. SECURITY_DESCRIPTOR_CONTROL Control;
  4038. PSID Owner;
  4039. PSID Group;
  4040. PACL Sacl;
  4041. PACL Dacl;
  4042. } SECURITY_DESCRIPTOR, *PISECURITY_DESCRIPTOR;
  4043. // end_ntifs
  4044. // Where:
  4045. //
  4046. // Revision - Contains the revision level of the security
  4047. // descriptor. This allows this structure to be passed between
  4048. // systems or stored on disk even though it is expected to
  4049. // change in the future.
  4050. //
  4051. // Control - A set of flags which qualify the meaning of the
  4052. // security descriptor or individual fields of the security
  4053. // descriptor.
  4054. //
  4055. // Owner - is a pointer to an SID representing an object's owner.
  4056. // If this field is null, then no owner SID is present in the
  4057. // security descriptor. If the security descriptor is in
  4058. // self-relative form, then this field contains an offset to
  4059. // the SID, rather than a pointer.
  4060. //
  4061. // Group - is a pointer to an SID representing an object's primary
  4062. // group. If this field is null, then no primary group SID is
  4063. // present in the security descriptor. If the security descriptor
  4064. // is in self-relative form, then this field contains an offset to
  4065. // the SID, rather than a pointer.
  4066. //
  4067. // Sacl - is a pointer to a system ACL. This field value is only
  4068. // valid if the DaclPresent control flag is set. If the
  4069. // SaclPresent flag is set and this field is null, then a null
  4070. // ACL is specified. If the security descriptor is in
  4071. // self-relative form, then this field contains an offset to
  4072. // the ACL, rather than a pointer.
  4073. //
  4074. // Dacl - is a pointer to a discretionary ACL. This field value is
  4075. // only valid if the DaclPresent control flag is set. If the
  4076. // DaclPresent flag is set and this field is null, then a null
  4077. // ACL (unconditionally granting access) is specified. If the
  4078. // security descriptor is in self-relative form, then this field
  4079. // contains an offset to the ACL, rather than a pointer.
  4080. //
  4081. ////////////////////////////////////////////////////////////////////////
  4082. // //
  4083. // Object Type list for AccessCheckByType //
  4084. // //
  4085. ////////////////////////////////////////////////////////////////////////
  4086. typedef struct _OBJECT_TYPE_LIST {
  4087. WORD Level;
  4088. WORD Sbz;
  4089. GUID *ObjectType;
  4090. } OBJECT_TYPE_LIST, *POBJECT_TYPE_LIST;
  4091. //
  4092. // DS values for Level
  4093. //
  4094. #define ACCESS_OBJECT_GUID 0
  4095. #define ACCESS_PROPERTY_SET_GUID 1
  4096. #define ACCESS_PROPERTY_GUID 2
  4097. #define ACCESS_MAX_LEVEL 4
  4098. //
  4099. // Parameters to NtAccessCheckByTypeAndAditAlarm
  4100. //
  4101. typedef enum _AUDIT_EVENT_TYPE {
  4102. AuditEventObjectAccess,
  4103. AuditEventDirectoryServiceAccess
  4104. } AUDIT_EVENT_TYPE, *PAUDIT_EVENT_TYPE;
  4105. #define AUDIT_ALLOW_NO_PRIVILEGE 0x1
  4106. //
  4107. // DS values for Source and ObjectTypeName
  4108. //
  4109. #define ACCESS_DS_SOURCE_A "DS"
  4110. #define ACCESS_DS_SOURCE_W L"DS"
  4111. #define ACCESS_DS_OBJECT_TYPE_NAME_A "Directory Service Object"
  4112. #define ACCESS_DS_OBJECT_TYPE_NAME_W L"Directory Service Object"
  4113. ////////////////////////////////////////////////////////////////////////
  4114. // //
  4115. // Privilege Related Data Structures //
  4116. // //
  4117. ////////////////////////////////////////////////////////////////////////
  4118. // begin_wdm begin_ntddk begin_nthal
  4119. //
  4120. // Privilege attributes
  4121. //
  4122. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  4123. #define SE_PRIVILEGE_ENABLED (0x00000002L)
  4124. #define SE_PRIVILEGE_REMOVED (0X00000004L)
  4125. #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
  4126. //
  4127. // Privilege Set Control flags
  4128. //
  4129. #define PRIVILEGE_SET_ALL_NECESSARY (1)
  4130. //
  4131. // Privilege Set - This is defined for a privilege set of one.
  4132. // If more than one privilege is needed, then this structure
  4133. // will need to be allocated with more space.
  4134. //
  4135. // Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  4136. // structure (defined in se.h)
  4137. //
  4138. typedef struct _PRIVILEGE_SET {
  4139. DWORD PrivilegeCount;
  4140. DWORD Control;
  4141. LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  4142. } PRIVILEGE_SET, * PPRIVILEGE_SET;
  4143. ////////////////////////////////////////////////////////////////////////
  4144. // //
  4145. // NT Defined Privileges //
  4146. // //
  4147. ////////////////////////////////////////////////////////////////////////
  4148. #define SE_CREATE_TOKEN_NAME TEXT("SeCreateTokenPrivilege")
  4149. #define SE_ASSIGNPRIMARYTOKEN_NAME TEXT("SeAssignPrimaryTokenPrivilege")
  4150. #define SE_LOCK_MEMORY_NAME TEXT("SeLockMemoryPrivilege")
  4151. #define SE_INCREASE_QUOTA_NAME TEXT("SeIncreaseQuotaPrivilege")
  4152. #define SE_UNSOLICITED_INPUT_NAME TEXT("SeUnsolicitedInputPrivilege")
  4153. #define SE_MACHINE_ACCOUNT_NAME TEXT("SeMachineAccountPrivilege")
  4154. #define SE_TCB_NAME TEXT("SeTcbPrivilege")
  4155. #define SE_SECURITY_NAME TEXT("SeSecurityPrivilege")
  4156. #define SE_TAKE_OWNERSHIP_NAME TEXT("SeTakeOwnershipPrivilege")
  4157. #define SE_LOAD_DRIVER_NAME TEXT("SeLoadDriverPrivilege")
  4158. #define SE_SYSTEM_PROFILE_NAME TEXT("SeSystemProfilePrivilege")
  4159. #define SE_SYSTEMTIME_NAME TEXT("SeSystemtimePrivilege")
  4160. #define SE_PROF_SINGLE_PROCESS_NAME TEXT("SeProfileSingleProcessPrivilege")
  4161. #define SE_INC_BASE_PRIORITY_NAME TEXT("SeIncreaseBasePriorityPrivilege")
  4162. #define SE_CREATE_PAGEFILE_NAME TEXT("SeCreatePagefilePrivilege")
  4163. #define SE_CREATE_PERMANENT_NAME TEXT("SeCreatePermanentPrivilege")
  4164. #define SE_BACKUP_NAME TEXT("SeBackupPrivilege")
  4165. #define SE_RESTORE_NAME TEXT("SeRestorePrivilege")
  4166. #define SE_SHUTDOWN_NAME TEXT("SeShutdownPrivilege")
  4167. #define SE_DEBUG_NAME TEXT("SeDebugPrivilege")
  4168. #define SE_AUDIT_NAME TEXT("SeAuditPrivilege")
  4169. #define SE_SYSTEM_ENVIRONMENT_NAME TEXT("SeSystemEnvironmentPrivilege")
  4170. #define SE_CHANGE_NOTIFY_NAME TEXT("SeChangeNotifyPrivilege")
  4171. #define SE_REMOTE_SHUTDOWN_NAME TEXT("SeRemoteShutdownPrivilege")
  4172. #define SE_UNDOCK_NAME TEXT("SeUndockPrivilege")
  4173. #define SE_SYNC_AGENT_NAME TEXT("SeSyncAgentPrivilege")
  4174. #define SE_ENABLE_DELEGATION_NAME TEXT("SeEnableDelegationPrivilege")
  4175. #define SE_MANAGE_VOLUME_NAME TEXT("SeManageVolumePrivilege")
  4176. #define SE_IMPERSONATE_NAME TEXT("SeImpersonatePrivilege")
  4177. #define SE_CREATE_GLOBAL_NAME TEXT("SeCreateGlobalPrivilege")
  4178. ////////////////////////////////////////////////////////////////////
  4179. // //
  4180. // Security Quality Of Service //
  4181. // //
  4182. // //
  4183. ////////////////////////////////////////////////////////////////////
  4184. // begin_wdm begin_ntddk begin_nthal begin_ntifs
  4185. //
  4186. // Impersonation Level
  4187. //
  4188. // Impersonation level is represented by a pair of bits in Windows.
  4189. // If a new impersonation level is added or lowest value is changed from
  4190. // 0 to something else, fix the Windows CreateFile call.
  4191. //
  4192. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  4193. SecurityAnonymous,
  4194. SecurityIdentification,
  4195. SecurityImpersonation,
  4196. SecurityDelegation
  4197. } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  4198. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  4199. #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
  4200. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  4201. #define VALID_IMPERSONATION_LEVEL(L) (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL))
  4202. ////////////////////////////////////////////////////////////////////
  4203. // //
  4204. // Token Object Definitions //
  4205. // //
  4206. // //
  4207. ////////////////////////////////////////////////////////////////////
  4208. //
  4209. // Token Specific Access Rights.
  4210. //
  4211. #define TOKEN_ASSIGN_PRIMARY (0x0001)
  4212. #define TOKEN_DUPLICATE (0x0002)
  4213. #define TOKEN_IMPERSONATE (0x0004)
  4214. #define TOKEN_QUERY (0x0008)
  4215. #define TOKEN_QUERY_SOURCE (0x0010)
  4216. #define TOKEN_ADJUST_PRIVILEGES (0x0020)
  4217. #define TOKEN_ADJUST_GROUPS (0x0040)
  4218. #define TOKEN_ADJUST_DEFAULT (0x0080)
  4219. #define TOKEN_ADJUST_SESSIONID (0x0100)
  4220. #define TOKEN_ALL_ACCESS_P (STANDARD_RIGHTS_REQUIRED |\
  4221. TOKEN_ASSIGN_PRIMARY |\
  4222. TOKEN_DUPLICATE |\
  4223. TOKEN_IMPERSONATE |\
  4224. TOKEN_QUERY |\
  4225. TOKEN_QUERY_SOURCE |\
  4226. TOKEN_ADJUST_PRIVILEGES |\
  4227. TOKEN_ADJUST_GROUPS |\
  4228. TOKEN_ADJUST_DEFAULT )
  4229. #if ((defined(_WIN32_WINNT) && (_WIN32_WINNT > 0x0400)) || (!defined(_WIN32_WINNT)))
  4230. #define TOKEN_ALL_ACCESS (TOKEN_ALL_ACCESS_P |\
  4231. TOKEN_ADJUST_SESSIONID )
  4232. #else
  4233. #define TOKEN_ALL_ACCESS (TOKEN_ALL_ACCESS_P)
  4234. #endif
  4235. #define TOKEN_READ (STANDARD_RIGHTS_READ |\
  4236. TOKEN_QUERY)
  4237. #define TOKEN_WRITE (STANDARD_RIGHTS_WRITE |\
  4238. TOKEN_ADJUST_PRIVILEGES |\
  4239. TOKEN_ADJUST_GROUPS |\
  4240. TOKEN_ADJUST_DEFAULT)
  4241. #define TOKEN_EXECUTE (STANDARD_RIGHTS_EXECUTE)
  4242. //
  4243. //
  4244. // Token Types
  4245. //
  4246. typedef enum _TOKEN_TYPE {
  4247. TokenPrimary = 1,
  4248. TokenImpersonation
  4249. } TOKEN_TYPE;
  4250. typedef TOKEN_TYPE *PTOKEN_TYPE;
  4251. //
  4252. // Token Information Classes.
  4253. //
  4254. typedef enum _TOKEN_INFORMATION_CLASS {
  4255. TokenUser = 1,
  4256. TokenGroups,
  4257. TokenPrivileges,
  4258. TokenOwner,
  4259. TokenPrimaryGroup,
  4260. TokenDefaultDacl,
  4261. TokenSource,
  4262. TokenType,
  4263. TokenImpersonationLevel,
  4264. TokenStatistics,
  4265. TokenRestrictedSids,
  4266. TokenSessionId,
  4267. TokenGroupsAndPrivileges,
  4268. TokenSessionReference,
  4269. TokenSandBoxInert,
  4270. TokenAuditPolicy,
  4271. TokenOrigin,
  4272. MaxTokenInfoClass // MaxTokenInfoClass should always be the last enum
  4273. } TOKEN_INFORMATION_CLASS, *PTOKEN_INFORMATION_CLASS;
  4274. //
  4275. // Token information class structures
  4276. //
  4277. typedef struct _TOKEN_USER {
  4278. SID_AND_ATTRIBUTES User;
  4279. } TOKEN_USER, *PTOKEN_USER;
  4280. typedef struct _TOKEN_GROUPS {
  4281. DWORD GroupCount;
  4282. SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
  4283. } TOKEN_GROUPS, *PTOKEN_GROUPS;
  4284. typedef struct _TOKEN_PRIVILEGES {
  4285. DWORD PrivilegeCount;
  4286. LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
  4287. } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
  4288. typedef struct _TOKEN_OWNER {
  4289. PSID Owner;
  4290. } TOKEN_OWNER, *PTOKEN_OWNER;
  4291. typedef struct _TOKEN_PRIMARY_GROUP {
  4292. PSID PrimaryGroup;
  4293. } TOKEN_PRIMARY_GROUP, *PTOKEN_PRIMARY_GROUP;
  4294. typedef struct _TOKEN_DEFAULT_DACL {
  4295. PACL DefaultDacl;
  4296. } TOKEN_DEFAULT_DACL, *PTOKEN_DEFAULT_DACL;
  4297. typedef struct _TOKEN_GROUPS_AND_PRIVILEGES {
  4298. DWORD SidCount;
  4299. DWORD SidLength;
  4300. PSID_AND_ATTRIBUTES Sids;
  4301. DWORD RestrictedSidCount;
  4302. DWORD RestrictedSidLength;
  4303. PSID_AND_ATTRIBUTES RestrictedSids;
  4304. DWORD PrivilegeCount;
  4305. DWORD PrivilegeLength;
  4306. PLUID_AND_ATTRIBUTES Privileges;
  4307. LUID AuthenticationId;
  4308. } TOKEN_GROUPS_AND_PRIVILEGES, *PTOKEN_GROUPS_AND_PRIVILEGES;
  4309. //
  4310. // Valid bits for each TOKEN_AUDIT_POLICY policy mask field.
  4311. //
  4312. #define TOKEN_AUDIT_SUCCESS_INCLUDE 0x1
  4313. #define TOKEN_AUDIT_SUCCESS_EXCLUDE 0x2
  4314. #define TOKEN_AUDIT_FAILURE_INCLUDE 0x4
  4315. #define TOKEN_AUDIT_FAILURE_EXCLUDE 0x8
  4316. #define VALID_AUDIT_POLICY_BITS (TOKEN_AUDIT_SUCCESS_INCLUDE | \
  4317. TOKEN_AUDIT_SUCCESS_EXCLUDE | \
  4318. TOKEN_AUDIT_FAILURE_INCLUDE | \
  4319. TOKEN_AUDIT_FAILURE_EXCLUDE)
  4320. #define VALID_TOKEN_AUDIT_POLICY_ELEMENT(P) ((((P).PolicyMask & ~VALID_AUDIT_POLICY_BITS) == 0) && \
  4321. ((P).Category <= AuditEventMaxType))
  4322. typedef struct _TOKEN_AUDIT_POLICY_ELEMENT {
  4323. DWORD Category;
  4324. DWORD PolicyMask;
  4325. } TOKEN_AUDIT_POLICY_ELEMENT, *PTOKEN_AUDIT_POLICY_ELEMENT;
  4326. typedef struct _TOKEN_AUDIT_POLICY {
  4327. DWORD PolicyCount;
  4328. TOKEN_AUDIT_POLICY_ELEMENT Policy[ANYSIZE_ARRAY];
  4329. } TOKEN_AUDIT_POLICY, *PTOKEN_AUDIT_POLICY;
  4330. #define PER_USER_AUDITING_POLICY_SIZE(p) \
  4331. ( sizeof(TOKEN_AUDIT_POLICY) + (((p)->PolicyCount > ANYSIZE_ARRAY) ? (sizeof(TOKEN_AUDIT_POLICY_ELEMENT) * ((p)->PolicyCount - ANYSIZE_ARRAY)) : 0) )
  4332. #define PER_USER_AUDITING_POLICY_SIZE_BY_COUNT(C) \
  4333. ( sizeof(TOKEN_AUDIT_POLICY) + (((C) > ANYSIZE_ARRAY) ? (sizeof(TOKEN_AUDIT_POLICY_ELEMENT) * ((C) - ANYSIZE_ARRAY)) : 0) )
  4334. #define TOKEN_SOURCE_LENGTH 8
  4335. typedef struct _TOKEN_SOURCE {
  4336. CHAR SourceName[TOKEN_SOURCE_LENGTH];
  4337. LUID SourceIdentifier;
  4338. } TOKEN_SOURCE, *PTOKEN_SOURCE;
  4339. typedef struct _TOKEN_STATISTICS {
  4340. LUID TokenId;
  4341. LUID AuthenticationId;
  4342. LARGE_INTEGER ExpirationTime;
  4343. TOKEN_TYPE TokenType;
  4344. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  4345. DWORD DynamicCharged;
  4346. DWORD DynamicAvailable;
  4347. DWORD GroupCount;
  4348. DWORD PrivilegeCount;
  4349. LUID ModifiedId;
  4350. } TOKEN_STATISTICS, *PTOKEN_STATISTICS;
  4351. typedef struct _TOKEN_CONTROL {
  4352. LUID TokenId;
  4353. LUID AuthenticationId;
  4354. LUID ModifiedId;
  4355. TOKEN_SOURCE TokenSource;
  4356. } TOKEN_CONTROL, *PTOKEN_CONTROL;
  4357. typedef struct _TOKEN_ORIGIN {
  4358. LUID OriginatingLogonSession ;
  4359. } TOKEN_ORIGIN, * PTOKEN_ORIGIN ;
  4360. //
  4361. // Security Tracking Mode
  4362. //
  4363. #define SECURITY_DYNAMIC_TRACKING (TRUE)
  4364. #define SECURITY_STATIC_TRACKING (FALSE)
  4365. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  4366. * PSECURITY_CONTEXT_TRACKING_MODE;
  4367. //
  4368. // Quality Of Service
  4369. //
  4370. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  4371. DWORD Length;
  4372. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  4373. SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  4374. BOOLEAN EffectiveOnly;
  4375. } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  4376. //
  4377. // Used to represent information related to a thread impersonation
  4378. //
  4379. typedef struct _SE_IMPERSONATION_STATE {
  4380. PACCESS_TOKEN Token;
  4381. BOOLEAN CopyOnOpen;
  4382. BOOLEAN EffectiveOnly;
  4383. SECURITY_IMPERSONATION_LEVEL Level;
  4384. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  4385. #define DISABLE_MAX_PRIVILEGE 0x1
  4386. #define SANDBOX_INERT 0x2
  4387. typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  4388. #define OWNER_SECURITY_INFORMATION (0x00000001L)
  4389. #define GROUP_SECURITY_INFORMATION (0x00000002L)
  4390. #define DACL_SECURITY_INFORMATION (0x00000004L)
  4391. #define SACL_SECURITY_INFORMATION (0x00000008L)
  4392. #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
  4393. #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
  4394. #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
  4395. #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
  4396. #define PROCESS_TERMINATE (0x0001)
  4397. #define PROCESS_CREATE_THREAD (0x0002)
  4398. #define PROCESS_SET_SESSIONID (0x0004)
  4399. #define PROCESS_VM_OPERATION (0x0008)
  4400. #define PROCESS_VM_READ (0x0010)
  4401. #define PROCESS_VM_WRITE (0x0020)
  4402. #define PROCESS_DUP_HANDLE (0x0040)
  4403. #define PROCESS_CREATE_PROCESS (0x0080)
  4404. #define PROCESS_SET_QUOTA (0x0100)
  4405. #define PROCESS_SET_INFORMATION (0x0200)
  4406. #define PROCESS_QUERY_INFORMATION (0x0400)
  4407. #define PROCESS_SUSPEND_RESUME (0x0800)
  4408. #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4409. 0xFFF)
  4410. // begin_nthal
  4411. #if defined(_WIN64)
  4412. #define MAXIMUM_PROCESSORS 64
  4413. #else
  4414. #define MAXIMUM_PROCESSORS 32
  4415. #endif
  4416. // end_nthal
  4417. #define THREAD_TERMINATE (0x0001)
  4418. #define THREAD_SUSPEND_RESUME (0x0002)
  4419. #define THREAD_GET_CONTEXT (0x0008)
  4420. #define THREAD_SET_CONTEXT (0x0010)
  4421. #define THREAD_SET_INFORMATION (0x0020)
  4422. #define THREAD_QUERY_INFORMATION (0x0040)
  4423. #define THREAD_SET_THREAD_TOKEN (0x0080)
  4424. #define THREAD_IMPERSONATE (0x0100)
  4425. #define THREAD_DIRECT_IMPERSONATION (0x0200)
  4426. // begin_ntddk begin_wdm begin_ntifs
  4427. #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4428. 0x3FF)
  4429. // end_ntddk end_wdm end_ntifs
  4430. #define JOB_OBJECT_ASSIGN_PROCESS (0x0001)
  4431. #define JOB_OBJECT_SET_ATTRIBUTES (0x0002)
  4432. #define JOB_OBJECT_QUERY (0x0004)
  4433. #define JOB_OBJECT_TERMINATE (0x0008)
  4434. #define JOB_OBJECT_SET_SECURITY_ATTRIBUTES (0x0010)
  4435. #define JOB_OBJECT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  4436. 0x1F )
  4437. typedef struct _JOB_SET_ARRAY {
  4438. HANDLE JobHandle; // Handle to job object to insert
  4439. DWORD MemberLevel; // Level of this job in the set. Must be > 0. Can be sparse.
  4440. DWORD Flags; // Unused. Must be zero
  4441. } JOB_SET_ARRAY, *PJOB_SET_ARRAY;
  4442. #define FLS_MAXIMUM_AVAILABLE 128
  4443. #define TLS_MINIMUM_AVAILABLE 64
  4444. typedef struct _NT_TIB {
  4445. struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
  4446. PVOID StackBase;
  4447. PVOID StackLimit;
  4448. PVOID SubSystemTib;
  4449. union {
  4450. PVOID FiberData;
  4451. DWORD Version;
  4452. };
  4453. PVOID ArbitraryUserPointer;
  4454. struct _NT_TIB *Self;
  4455. } NT_TIB;
  4456. typedef NT_TIB *PNT_TIB;
  4457. //
  4458. // 32 and 64 bit specific version for wow64 and the debugger
  4459. //
  4460. typedef struct _NT_TIB32 {
  4461. DWORD ExceptionList;
  4462. DWORD StackBase;
  4463. DWORD StackLimit;
  4464. DWORD SubSystemTib;
  4465. union {
  4466. DWORD FiberData;
  4467. DWORD Version;
  4468. };
  4469. DWORD ArbitraryUserPointer;
  4470. DWORD Self;
  4471. } NT_TIB32, *PNT_TIB32;
  4472. typedef struct _NT_TIB64 {
  4473. DWORD64 ExceptionList;
  4474. DWORD64 StackBase;
  4475. DWORD64 StackLimit;
  4476. DWORD64 SubSystemTib;
  4477. union {
  4478. DWORD64 FiberData;
  4479. DWORD Version;
  4480. };
  4481. DWORD64 ArbitraryUserPointer;
  4482. DWORD64 Self;
  4483. } NT_TIB64, *PNT_TIB64;
  4484. #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_)
  4485. #define WX86
  4486. #endif
  4487. #define THREAD_BASE_PRIORITY_LOWRT 15 // value that gets a thread to LowRealtime-1
  4488. #define THREAD_BASE_PRIORITY_MAX 2 // maximum thread base priority boost
  4489. #define THREAD_BASE_PRIORITY_MIN (-2) // minimum thread base priority boost
  4490. #define THREAD_BASE_PRIORITY_IDLE (-15) // value that gets a thread to idle
  4491. typedef struct _QUOTA_LIMITS {
  4492. SIZE_T PagedPoolLimit;
  4493. SIZE_T NonPagedPoolLimit;
  4494. SIZE_T MinimumWorkingSetSize;
  4495. SIZE_T MaximumWorkingSetSize;
  4496. SIZE_T PagefileLimit;
  4497. LARGE_INTEGER TimeLimit;
  4498. } QUOTA_LIMITS, *PQUOTA_LIMITS;
  4499. #define QUOTA_LIMITS_HARDWS_MIN_ENABLE 0x00000001
  4500. #define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002
  4501. #define QUOTA_LIMITS_HARDWS_MAX_ENABLE 0x00000004
  4502. #define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008
  4503. typedef struct _QUOTA_LIMITS_EX {
  4504. SIZE_T PagedPoolLimit;
  4505. SIZE_T NonPagedPoolLimit;
  4506. SIZE_T MinimumWorkingSetSize;
  4507. SIZE_T MaximumWorkingSetSize;
  4508. SIZE_T PagefileLimit;
  4509. LARGE_INTEGER TimeLimit;
  4510. SIZE_T Reserved1;
  4511. SIZE_T Reserved2;
  4512. SIZE_T Reserved3;
  4513. SIZE_T Reserved4;
  4514. DWORD Flags;
  4515. DWORD Reserved5;
  4516. } QUOTA_LIMITS_EX, *PQUOTA_LIMITS_EX;
  4517. typedef struct _IO_COUNTERS {
  4518. ULONGLONG ReadOperationCount;
  4519. ULONGLONG WriteOperationCount;
  4520. ULONGLONG OtherOperationCount;
  4521. ULONGLONG ReadTransferCount;
  4522. ULONGLONG WriteTransferCount;
  4523. ULONGLONG OtherTransferCount;
  4524. } IO_COUNTERS;
  4525. typedef IO_COUNTERS *PIO_COUNTERS;
  4526. typedef struct _JOBOBJECT_BASIC_ACCOUNTING_INFORMATION {
  4527. LARGE_INTEGER TotalUserTime;
  4528. LARGE_INTEGER TotalKernelTime;
  4529. LARGE_INTEGER ThisPeriodTotalUserTime;
  4530. LARGE_INTEGER ThisPeriodTotalKernelTime;
  4531. DWORD TotalPageFaultCount;
  4532. DWORD TotalProcesses;
  4533. DWORD ActiveProcesses;
  4534. DWORD TotalTerminatedProcesses;
  4535. } JOBOBJECT_BASIC_ACCOUNTING_INFORMATION, *PJOBOBJECT_BASIC_ACCOUNTING_INFORMATION;
  4536. typedef struct _JOBOBJECT_BASIC_LIMIT_INFORMATION {
  4537. LARGE_INTEGER PerProcessUserTimeLimit;
  4538. LARGE_INTEGER PerJobUserTimeLimit;
  4539. DWORD LimitFlags;
  4540. SIZE_T MinimumWorkingSetSize;
  4541. SIZE_T MaximumWorkingSetSize;
  4542. DWORD ActiveProcessLimit;
  4543. ULONG_PTR Affinity;
  4544. DWORD PriorityClass;
  4545. DWORD SchedulingClass;
  4546. } JOBOBJECT_BASIC_LIMIT_INFORMATION, *PJOBOBJECT_BASIC_LIMIT_INFORMATION;
  4547. typedef struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
  4548. JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
  4549. IO_COUNTERS IoInfo;
  4550. SIZE_T ProcessMemoryLimit;
  4551. SIZE_T JobMemoryLimit;
  4552. SIZE_T PeakProcessMemoryUsed;
  4553. SIZE_T PeakJobMemoryUsed;
  4554. } JOBOBJECT_EXTENDED_LIMIT_INFORMATION, *PJOBOBJECT_EXTENDED_LIMIT_INFORMATION;
  4555. typedef struct _JOBOBJECT_BASIC_PROCESS_ID_LIST {
  4556. DWORD NumberOfAssignedProcesses;
  4557. DWORD NumberOfProcessIdsInList;
  4558. ULONG_PTR ProcessIdList[1];
  4559. } JOBOBJECT_BASIC_PROCESS_ID_LIST, *PJOBOBJECT_BASIC_PROCESS_ID_LIST;
  4560. typedef struct _JOBOBJECT_BASIC_UI_RESTRICTIONS {
  4561. DWORD UIRestrictionsClass;
  4562. } JOBOBJECT_BASIC_UI_RESTRICTIONS, *PJOBOBJECT_BASIC_UI_RESTRICTIONS;
  4563. typedef struct _JOBOBJECT_SECURITY_LIMIT_INFORMATION {
  4564. DWORD SecurityLimitFlags ;
  4565. HANDLE JobToken ;
  4566. PTOKEN_GROUPS SidsToDisable ;
  4567. PTOKEN_PRIVILEGES PrivilegesToDelete ;
  4568. PTOKEN_GROUPS RestrictedSids ;
  4569. } JOBOBJECT_SECURITY_LIMIT_INFORMATION, *PJOBOBJECT_SECURITY_LIMIT_INFORMATION ;
  4570. typedef struct _JOBOBJECT_END_OF_JOB_TIME_INFORMATION {
  4571. DWORD EndOfJobTimeAction;
  4572. } JOBOBJECT_END_OF_JOB_TIME_INFORMATION, *PJOBOBJECT_END_OF_JOB_TIME_INFORMATION;
  4573. typedef struct _JOBOBJECT_ASSOCIATE_COMPLETION_PORT {
  4574. PVOID CompletionKey;
  4575. HANDLE CompletionPort;
  4576. } JOBOBJECT_ASSOCIATE_COMPLETION_PORT, *PJOBOBJECT_ASSOCIATE_COMPLETION_PORT;
  4577. typedef struct _JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION {
  4578. JOBOBJECT_BASIC_ACCOUNTING_INFORMATION BasicInfo;
  4579. IO_COUNTERS IoInfo;
  4580. } JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION, *PJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION;
  4581. typedef struct _JOBOBJECT_JOBSET_INFORMATION {
  4582. DWORD MemberLevel;
  4583. } JOBOBJECT_JOBSET_INFORMATION, *PJOBOBJECT_JOBSET_INFORMATION;
  4584. #define JOB_OBJECT_TERMINATE_AT_END_OF_JOB 0
  4585. #define JOB_OBJECT_POST_AT_END_OF_JOB 1
  4586. //
  4587. // Completion Port Messages for job objects
  4588. //
  4589. // These values are returned via the lpNumberOfBytesTransferred parameter
  4590. //
  4591. #define JOB_OBJECT_MSG_END_OF_JOB_TIME 1
  4592. #define JOB_OBJECT_MSG_END_OF_PROCESS_TIME 2
  4593. #define JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT 3
  4594. #define JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO 4
  4595. #define JOB_OBJECT_MSG_NEW_PROCESS 6
  4596. #define JOB_OBJECT_MSG_EXIT_PROCESS 7
  4597. #define JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS 8
  4598. #define JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT 9
  4599. #define JOB_OBJECT_MSG_JOB_MEMORY_LIMIT 10
  4600. //
  4601. // Basic Limits
  4602. //
  4603. #define JOB_OBJECT_LIMIT_WORKINGSET 0x00000001
  4604. #define JOB_OBJECT_LIMIT_PROCESS_TIME 0x00000002
  4605. #define JOB_OBJECT_LIMIT_JOB_TIME 0x00000004
  4606. #define JOB_OBJECT_LIMIT_ACTIVE_PROCESS 0x00000008
  4607. #define JOB_OBJECT_LIMIT_AFFINITY 0x00000010
  4608. #define JOB_OBJECT_LIMIT_PRIORITY_CLASS 0x00000020
  4609. #define JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME 0x00000040
  4610. #define JOB_OBJECT_LIMIT_SCHEDULING_CLASS 0x00000080
  4611. //
  4612. // Extended Limits
  4613. //
  4614. #define JOB_OBJECT_LIMIT_PROCESS_MEMORY 0x00000100
  4615. #define JOB_OBJECT_LIMIT_JOB_MEMORY 0x00000200
  4616. #define JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION 0x00000400
  4617. #define JOB_OBJECT_LIMIT_BREAKAWAY_OK 0x00000800
  4618. #define JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK 0x00001000
  4619. #define JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE 0x00002000
  4620. #define JOB_OBJECT_LIMIT_RESERVED2 0x00004000
  4621. #define JOB_OBJECT_LIMIT_RESERVED3 0x00008000
  4622. #define JOB_OBJECT_LIMIT_RESERVED4 0x00010000
  4623. #define JOB_OBJECT_LIMIT_RESERVED5 0x00020000
  4624. #define JOB_OBJECT_LIMIT_RESERVED6 0x00040000
  4625. #define JOB_OBJECT_LIMIT_VALID_FLAGS 0x0007ffff
  4626. #define JOB_OBJECT_BASIC_LIMIT_VALID_FLAGS 0x000000ff
  4627. #define JOB_OBJECT_EXTENDED_LIMIT_VALID_FLAGS 0x00003fff
  4628. #define JOB_OBJECT_RESERVED_LIMIT_VALID_FLAGS 0x0007ffff
  4629. //
  4630. // UI restrictions for jobs
  4631. //
  4632. #define JOB_OBJECT_UILIMIT_NONE 0x00000000
  4633. #define JOB_OBJECT_UILIMIT_HANDLES 0x00000001
  4634. #define JOB_OBJECT_UILIMIT_READCLIPBOARD 0x00000002
  4635. #define JOB_OBJECT_UILIMIT_WRITECLIPBOARD 0x00000004
  4636. #define JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS 0x00000008
  4637. #define JOB_OBJECT_UILIMIT_DISPLAYSETTINGS 0x00000010
  4638. #define JOB_OBJECT_UILIMIT_GLOBALATOMS 0x00000020
  4639. #define JOB_OBJECT_UILIMIT_DESKTOP 0x00000040
  4640. #define JOB_OBJECT_UILIMIT_EXITWINDOWS 0x00000080
  4641. #define JOB_OBJECT_UILIMIT_ALL 0x000000FF
  4642. #define JOB_OBJECT_UI_VALID_FLAGS 0x000000FF
  4643. #define JOB_OBJECT_SECURITY_NO_ADMIN 0x00000001
  4644. #define JOB_OBJECT_SECURITY_RESTRICTED_TOKEN 0x00000002
  4645. #define JOB_OBJECT_SECURITY_ONLY_TOKEN 0x00000004
  4646. #define JOB_OBJECT_SECURITY_FILTER_TOKENS 0x00000008
  4647. #define JOB_OBJECT_SECURITY_VALID_FLAGS 0x0000000f
  4648. typedef enum _JOBOBJECTINFOCLASS {
  4649. JobObjectBasicAccountingInformation = 1,
  4650. JobObjectBasicLimitInformation,
  4651. JobObjectBasicProcessIdList,
  4652. JobObjectBasicUIRestrictions,
  4653. JobObjectSecurityLimitInformation,
  4654. JobObjectEndOfJobTimeInformation,
  4655. JobObjectAssociateCompletionPortInformation,
  4656. JobObjectBasicAndIoAccountingInformation,
  4657. JobObjectExtendedLimitInformation,
  4658. JobObjectJobSetInformation,
  4659. MaxJobObjectInfoClass
  4660. } JOBOBJECTINFOCLASS;
  4661. //
  4662. #define EVENT_MODIFY_STATE 0x0002
  4663. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
  4664. #define MUTANT_QUERY_STATE 0x0001
  4665. #define MUTANT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|\
  4666. MUTANT_QUERY_STATE)
  4667. #define SEMAPHORE_MODIFY_STATE 0x0002
  4668. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
  4669. //
  4670. // Timer Specific Access Rights.
  4671. //
  4672. #define TIMER_QUERY_STATE 0x0001
  4673. #define TIMER_MODIFY_STATE 0x0002
  4674. #define TIMER_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|\
  4675. TIMER_QUERY_STATE|TIMER_MODIFY_STATE)
  4676. #define TIME_ZONE_ID_UNKNOWN 0
  4677. #define TIME_ZONE_ID_STANDARD 1
  4678. #define TIME_ZONE_ID_DAYLIGHT 2
  4679. typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP {
  4680. RelationProcessorCore,
  4681. RelationNumaNode
  4682. } LOGICAL_PROCESSOR_RELATIONSHIP;
  4683. #define LTP_PC_SMT 0x1
  4684. typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION {
  4685. ULONG_PTR ProcessorMask;
  4686. LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
  4687. union {
  4688. struct {
  4689. BYTE Flags;
  4690. } ProcessorCore;
  4691. struct {
  4692. DWORD NodeNumber;
  4693. } NumaNode;
  4694. ULONGLONG Reserved[2];
  4695. };
  4696. } SYSTEM_LOGICAL_PROCESSOR_INFORMATION, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION;
  4697. #define PROCESSOR_INTEL_386 386
  4698. #define PROCESSOR_INTEL_486 486
  4699. #define PROCESSOR_INTEL_PENTIUM 586
  4700. #define PROCESSOR_INTEL_IA64 2200
  4701. #define PROCESSOR_AMD_X8664 8664
  4702. #define PROCESSOR_MIPS_R4000 4000 // incl R4101 & R3910 for Windows CE
  4703. #define PROCESSOR_ALPHA_21064 21064
  4704. #define PROCESSOR_PPC_601 601
  4705. #define PROCESSOR_PPC_603 603
  4706. #define PROCESSOR_PPC_604 604
  4707. #define PROCESSOR_PPC_620 620
  4708. #define PROCESSOR_HITACHI_SH3 10003 // Windows CE
  4709. #define PROCESSOR_HITACHI_SH3E 10004 // Windows CE
  4710. #define PROCESSOR_HITACHI_SH4 10005 // Windows CE
  4711. #define PROCESSOR_MOTOROLA_821 821 // Windows CE
  4712. #define PROCESSOR_SHx_SH3 103 // Windows CE
  4713. #define PROCESSOR_SHx_SH4 104 // Windows CE
  4714. #define PROCESSOR_STRONGARM 2577 // Windows CE - 0xA11
  4715. #define PROCESSOR_ARM720 1824 // Windows CE - 0x720
  4716. #define PROCESSOR_ARM820 2080 // Windows CE - 0x820
  4717. #define PROCESSOR_ARM920 2336 // Windows CE - 0x920
  4718. #define PROCESSOR_ARM_7TDMI 70001 // Windows CE
  4719. #define PROCESSOR_OPTIL 0x494f // MSIL
  4720. #define PROCESSOR_ARCHITECTURE_INTEL 0
  4721. #define PROCESSOR_ARCHITECTURE_MIPS 1
  4722. #define PROCESSOR_ARCHITECTURE_ALPHA 2
  4723. #define PROCESSOR_ARCHITECTURE_PPC 3
  4724. #define PROCESSOR_ARCHITECTURE_SHX 4
  4725. #define PROCESSOR_ARCHITECTURE_ARM 5
  4726. #define PROCESSOR_ARCHITECTURE_IA64 6
  4727. #define PROCESSOR_ARCHITECTURE_ALPHA64 7
  4728. #define PROCESSOR_ARCHITECTURE_MSIL 8
  4729. #define PROCESSOR_ARCHITECTURE_AMD64 9
  4730. #define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 10
  4731. #define PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF
  4732. #define PF_FLOATING_POINT_PRECISION_ERRATA 0
  4733. #define PF_FLOATING_POINT_EMULATED 1
  4734. #define PF_COMPARE_EXCHANGE_DOUBLE 2
  4735. #define PF_MMX_INSTRUCTIONS_AVAILABLE 3
  4736. #define PF_PPC_MOVEMEM_64BIT_OK 4
  4737. #define PF_ALPHA_BYTE_INSTRUCTIONS 5
  4738. #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
  4739. #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
  4740. #define PF_RDTSC_INSTRUCTION_AVAILABLE 8
  4741. #define PF_PAE_ENABLED 9
  4742. #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
  4743. typedef struct _MEMORY_BASIC_INFORMATION {
  4744. PVOID BaseAddress;
  4745. PVOID AllocationBase;
  4746. DWORD AllocationProtect;
  4747. SIZE_T RegionSize;
  4748. DWORD State;
  4749. DWORD Protect;
  4750. DWORD Type;
  4751. } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
  4752. typedef struct _MEMORY_BASIC_INFORMATION32 {
  4753. DWORD BaseAddress;
  4754. DWORD AllocationBase;
  4755. DWORD AllocationProtect;
  4756. DWORD RegionSize;
  4757. DWORD State;
  4758. DWORD Protect;
  4759. DWORD Type;
  4760. } MEMORY_BASIC_INFORMATION32, *PMEMORY_BASIC_INFORMATION32;
  4761. typedef struct DECLSPEC_ALIGN(16) _MEMORY_BASIC_INFORMATION64 {
  4762. ULONGLONG BaseAddress;
  4763. ULONGLONG AllocationBase;
  4764. DWORD AllocationProtect;
  4765. DWORD __alignment1;
  4766. ULONGLONG RegionSize;
  4767. DWORD State;
  4768. DWORD Protect;
  4769. DWORD Type;
  4770. DWORD __alignment2;
  4771. } MEMORY_BASIC_INFORMATION64, *PMEMORY_BASIC_INFORMATION64;
  4772. #define SECTION_QUERY 0x0001
  4773. #define SECTION_MAP_WRITE 0x0002
  4774. #define SECTION_MAP_READ 0x0004
  4775. #define SECTION_MAP_EXECUTE 0x0008
  4776. #define SECTION_EXTEND_SIZE 0x0010
  4777. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  4778. SECTION_MAP_WRITE | \
  4779. SECTION_MAP_READ | \
  4780. SECTION_MAP_EXECUTE | \
  4781. SECTION_EXTEND_SIZE)
  4782. #define PAGE_NOACCESS 0x01
  4783. #define PAGE_READONLY 0x02
  4784. #define PAGE_READWRITE 0x04
  4785. #define PAGE_WRITECOPY 0x08
  4786. #define PAGE_EXECUTE 0x10
  4787. #define PAGE_EXECUTE_READ 0x20
  4788. #define PAGE_EXECUTE_READWRITE 0x40
  4789. #define PAGE_EXECUTE_WRITECOPY 0x80
  4790. #define PAGE_GUARD 0x100
  4791. #define PAGE_NOCACHE 0x200
  4792. #define PAGE_WRITECOMBINE 0x400
  4793. #define MEM_COMMIT 0x1000
  4794. #define MEM_RESERVE 0x2000
  4795. #define MEM_DECOMMIT 0x4000
  4796. #define MEM_RELEASE 0x8000
  4797. #define MEM_FREE 0x10000
  4798. #define MEM_PRIVATE 0x20000
  4799. #define MEM_MAPPED 0x40000
  4800. #define MEM_RESET 0x80000
  4801. #define MEM_TOP_DOWN 0x100000
  4802. #define MEM_WRITE_WATCH 0x200000
  4803. #define MEM_PHYSICAL 0x400000
  4804. #define MEM_LARGE_PAGES 0x20000000
  4805. #define MEM_4MB_PAGES 0x80000000
  4806. #define SEC_FILE 0x800000
  4807. #define SEC_IMAGE 0x1000000
  4808. #define SEC_RESERVE 0x4000000
  4809. #define SEC_COMMIT 0x8000000
  4810. #define SEC_NOCACHE 0x10000000
  4811. #define MEM_IMAGE SEC_IMAGE
  4812. #define WRITE_WATCH_FLAG_RESET 0x01
  4813. //
  4814. // Define access rights to files and directories
  4815. //
  4816. //
  4817. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  4818. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  4819. // constants *MUST* always be in sync.
  4820. // The values are redefined in devioctl.h because they must be available to
  4821. // both DOS and NT.
  4822. //
  4823. #define FILE_READ_DATA ( 0x0001 ) // file & pipe
  4824. #define FILE_LIST_DIRECTORY ( 0x0001 ) // directory
  4825. #define FILE_WRITE_DATA ( 0x0002 ) // file & pipe
  4826. #define FILE_ADD_FILE ( 0x0002 ) // directory
  4827. #define FILE_APPEND_DATA ( 0x0004 ) // file
  4828. #define FILE_ADD_SUBDIRECTORY ( 0x0004 ) // directory
  4829. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 ) // named pipe
  4830. #define FILE_READ_EA ( 0x0008 ) // file & directory
  4831. #define FILE_WRITE_EA ( 0x0010 ) // file & directory
  4832. #define FILE_EXECUTE ( 0x0020 ) // file
  4833. #define FILE_TRAVERSE ( 0x0020 ) // directory
  4834. #define FILE_DELETE_CHILD ( 0x0040 ) // directory
  4835. #define FILE_READ_ATTRIBUTES ( 0x0080 ) // all
  4836. #define FILE_WRITE_ATTRIBUTES ( 0x0100 ) // all
  4837. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  4838. #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\
  4839. FILE_READ_DATA |\
  4840. FILE_READ_ATTRIBUTES |\
  4841. FILE_READ_EA |\
  4842. SYNCHRONIZE)
  4843. #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE |\
  4844. FILE_WRITE_DATA |\
  4845. FILE_WRITE_ATTRIBUTES |\
  4846. FILE_WRITE_EA |\
  4847. FILE_APPEND_DATA |\
  4848. SYNCHRONIZE)
  4849. #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE |\
  4850. FILE_READ_ATTRIBUTES |\
  4851. FILE_EXECUTE |\
  4852. SYNCHRONIZE)
  4853. #define FILE_SHARE_READ 0x00000001
  4854. #define FILE_SHARE_WRITE 0x00000002
  4855. #define FILE_SHARE_DELETE 0x00000004
  4856. #define FILE_ATTRIBUTE_READONLY 0x00000001
  4857. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  4858. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  4859. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  4860. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  4861. #define FILE_ATTRIBUTE_DEVICE 0x00000040
  4862. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  4863. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
  4864. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
  4865. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
  4866. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
  4867. #define FILE_ATTRIBUTE_OFFLINE 0x00001000
  4868. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
  4869. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
  4870. #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
  4871. #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
  4872. #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
  4873. #define FILE_NOTIFY_CHANGE_SIZE 0x00000008
  4874. #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
  4875. #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
  4876. #define FILE_NOTIFY_CHANGE_CREATION 0x00000040
  4877. #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
  4878. #define FILE_ACTION_ADDED 0x00000001
  4879. #define FILE_ACTION_REMOVED 0x00000002
  4880. #define FILE_ACTION_MODIFIED 0x00000003
  4881. #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
  4882. #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
  4883. #define MAILSLOT_NO_MESSAGE ((DWORD)-1)
  4884. #define MAILSLOT_WAIT_FOREVER ((DWORD)-1)
  4885. #define FILE_CASE_SENSITIVE_SEARCH 0x00000001
  4886. #define FILE_CASE_PRESERVED_NAMES 0x00000002
  4887. #define FILE_UNICODE_ON_DISK 0x00000004
  4888. #define FILE_PERSISTENT_ACLS 0x00000008
  4889. #define FILE_FILE_COMPRESSION 0x00000010
  4890. #define FILE_VOLUME_QUOTAS 0x00000020
  4891. #define FILE_SUPPORTS_SPARSE_FILES 0x00000040
  4892. #define FILE_SUPPORTS_REPARSE_POINTS 0x00000080
  4893. #define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100
  4894. #define FILE_VOLUME_IS_COMPRESSED 0x00008000
  4895. #define FILE_SUPPORTS_OBJECT_IDS 0x00010000
  4896. #define FILE_SUPPORTS_ENCRYPTION 0x00020000
  4897. #define FILE_NAMED_STREAMS 0x00040000
  4898. #define FILE_READ_ONLY_VOLUME 0x00080000
  4899. //
  4900. // Define the file notification information structure
  4901. //
  4902. typedef struct _FILE_NOTIFY_INFORMATION {
  4903. DWORD NextEntryOffset;
  4904. DWORD Action;
  4905. DWORD FileNameLength;
  4906. WCHAR FileName[1];
  4907. } FILE_NOTIFY_INFORMATION, *PFILE_NOTIFY_INFORMATION;
  4908. //
  4909. // Define segement buffer structure for scatter/gather read/write.
  4910. //
  4911. typedef union _FILE_SEGMENT_ELEMENT {
  4912. PVOID64 Buffer;
  4913. ULONGLONG Alignment;
  4914. }FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
  4915. //
  4916. // The reparse GUID structure is used by all 3rd party layered drivers to
  4917. // store data in a reparse point. For non-Microsoft tags, The GUID field
  4918. // cannot be GUID_NULL.
  4919. // The constraints on reparse tags are defined below.
  4920. // Microsoft tags can also be used with this format of the reparse point buffer.
  4921. //
  4922. typedef struct _REPARSE_GUID_DATA_BUFFER {
  4923. DWORD ReparseTag;
  4924. WORD ReparseDataLength;
  4925. WORD Reserved;
  4926. GUID ReparseGuid;
  4927. struct {
  4928. BYTE DataBuffer[1];
  4929. } GenericReparseBuffer;
  4930. } REPARSE_GUID_DATA_BUFFER, *PREPARSE_GUID_DATA_BUFFER;
  4931. #define REPARSE_GUID_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer)
  4932. //
  4933. // Maximum allowed size of the reparse data.
  4934. //
  4935. #define MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 )
  4936. //
  4937. // Predefined reparse tags.
  4938. // These tags need to avoid conflicting with IO_REMOUNT defined in ntos\inc\io.h
  4939. //
  4940. #define IO_REPARSE_TAG_RESERVED_ZERO (0)
  4941. #define IO_REPARSE_TAG_RESERVED_ONE (1)
  4942. //
  4943. // The value of the following constant needs to satisfy the following conditions:
  4944. // (1) Be at least as large as the largest of the reserved tags.
  4945. // (2) Be strictly smaller than all the tags in use.
  4946. //
  4947. #define IO_REPARSE_TAG_RESERVED_RANGE IO_REPARSE_TAG_RESERVED_ONE
  4948. //
  4949. // The reparse tags are a DWORD. The 32 bits are laid out as follows:
  4950. //
  4951. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  4952. // 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
  4953. // +-+-+-+-+-----------------------+-------------------------------+
  4954. // |M|R|N|R| Reserved bits | Reparse Tag Value |
  4955. // +-+-+-+-+-----------------------+-------------------------------+
  4956. //
  4957. // M is the Microsoft bit. When set to 1, it denotes a tag owned by Microsoft.
  4958. // All ISVs must use a tag with a 0 in this position.
  4959. // Note: If a Microsoft tag is used by non-Microsoft software, the
  4960. // behavior is not defined.
  4961. //
  4962. // R is reserved. Must be zero for non-Microsoft tags.
  4963. //
  4964. // N is name surrogate. When set to 1, the file represents another named
  4965. // entity in the system.
  4966. //
  4967. // The M and N bits are OR-able.
  4968. // The following macros check for the M and N bit values:
  4969. //
  4970. //
  4971. // Macro to determine whether a reparse point tag corresponds to a tag
  4972. // owned by Microsoft.
  4973. //
  4974. #define IsReparseTagMicrosoft(_tag) ( \
  4975. ((_tag) & 0x80000000) \
  4976. )
  4977. //
  4978. // Macro to determine whether a reparse point tag is a name surrogate
  4979. //
  4980. #define IsReparseTagNameSurrogate(_tag) ( \
  4981. ((_tag) & 0x20000000) \
  4982. )
  4983. #define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
  4984. #define IO_REPARSE_TAG_HSM (0xC0000004L)
  4985. #define IO_REPARSE_TAG_SIS (0x80000007L)
  4986. #define IO_REPARSE_TAG_DFS (0x8000000AL)
  4987. #define IO_REPARSE_TAG_FILTER_MANAGER (0x8000000BL)
  4988. #define IO_COMPLETION_MODIFY_STATE 0x0002
  4989. #define IO_COMPLETION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
  4990. #define DUPLICATE_CLOSE_SOURCE 0x00000001
  4991. #define DUPLICATE_SAME_ACCESS 0x00000002
  4992. typedef enum _SYSTEM_POWER_STATE {
  4993. PowerSystemUnspecified = 0,
  4994. PowerSystemWorking = 1,
  4995. PowerSystemSleeping1 = 2,
  4996. PowerSystemSleeping2 = 3,
  4997. PowerSystemSleeping3 = 4,
  4998. PowerSystemHibernate = 5,
  4999. PowerSystemShutdown = 6,
  5000. PowerSystemMaximum = 7
  5001. } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
  5002. #define POWER_SYSTEM_MAXIMUM 7
  5003. typedef enum {
  5004. PowerActionNone = 0,
  5005. PowerActionReserved,
  5006. PowerActionSleep,
  5007. PowerActionHibernate,
  5008. PowerActionShutdown,
  5009. PowerActionShutdownReset,
  5010. PowerActionShutdownOff,
  5011. PowerActionWarmEject
  5012. } POWER_ACTION, *PPOWER_ACTION;
  5013. typedef enum _DEVICE_POWER_STATE {
  5014. PowerDeviceUnspecified = 0,
  5015. PowerDeviceD0,
  5016. PowerDeviceD1,
  5017. PowerDeviceD2,
  5018. PowerDeviceD3,
  5019. PowerDeviceMaximum
  5020. } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
  5021. #define ES_SYSTEM_REQUIRED ((DWORD)0x00000001)
  5022. #define ES_DISPLAY_REQUIRED ((DWORD)0x00000002)
  5023. #define ES_USER_PRESENT ((DWORD)0x00000004)
  5024. #define ES_CONTINUOUS ((DWORD)0x80000000)
  5025. typedef DWORD EXECUTION_STATE;
  5026. typedef enum {
  5027. LT_DONT_CARE,
  5028. LT_LOWEST_LATENCY
  5029. } LATENCY_TIME;
  5030. // end_ntminiport end_ntifs end_wdm end_ntddk
  5031. //-----------------------------------------------------------------------------
  5032. // Device Power Information
  5033. // Accessable via CM_Get_DevInst_Registry_Property_Ex(CM_DRP_DEVICE_POWER_DATA)
  5034. //-----------------------------------------------------------------------------
  5035. #define PDCAP_D0_SUPPORTED 0x00000001
  5036. #define PDCAP_D1_SUPPORTED 0x00000002
  5037. #define PDCAP_D2_SUPPORTED 0x00000004
  5038. #define PDCAP_D3_SUPPORTED 0x00000008
  5039. #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
  5040. #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
  5041. #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
  5042. #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
  5043. #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
  5044. typedef struct CM_Power_Data_s {
  5045. DWORD PD_Size;
  5046. DEVICE_POWER_STATE PD_MostRecentPowerState;
  5047. DWORD PD_Capabilities;
  5048. DWORD PD_D1Latency;
  5049. DWORD PD_D2Latency;
  5050. DWORD PD_D3Latency;
  5051. DEVICE_POWER_STATE PD_PowerStateMapping[POWER_SYSTEM_MAXIMUM];
  5052. SYSTEM_POWER_STATE PD_DeepestSystemWake;
  5053. } CM_POWER_DATA, *PCM_POWER_DATA;
  5054. // begin_ntddk
  5055. typedef enum {
  5056. SystemPowerPolicyAc,
  5057. SystemPowerPolicyDc,
  5058. VerifySystemPolicyAc,
  5059. VerifySystemPolicyDc,
  5060. SystemPowerCapabilities,
  5061. SystemBatteryState,
  5062. SystemPowerStateHandler,
  5063. ProcessorStateHandler,
  5064. SystemPowerPolicyCurrent,
  5065. AdministratorPowerPolicy,
  5066. SystemReserveHiberFile,
  5067. ProcessorInformation,
  5068. SystemPowerInformation,
  5069. ProcessorStateHandler2,
  5070. LastWakeTime, // Compare with KeQueryInterruptTime()
  5071. LastSleepTime, // Compare with KeQueryInterruptTime()
  5072. SystemExecutionState,
  5073. SystemPowerStateNotifyHandler,
  5074. ProcessorPowerPolicyAc,
  5075. ProcessorPowerPolicyDc,
  5076. VerifyProcessorPowerPolicyAc,
  5077. VerifyProcessorPowerPolicyDc,
  5078. ProcessorPowerPolicyCurrent,
  5079. SystemPowerStateLogging,
  5080. SystemPowerLoggingEntry
  5081. } POWER_INFORMATION_LEVEL;
  5082. // begin_wdm
  5083. //
  5084. // System power manager capabilities
  5085. //
  5086. typedef struct {
  5087. DWORD Granularity;
  5088. DWORD Capacity;
  5089. } BATTERY_REPORTING_SCALE, *PBATTERY_REPORTING_SCALE;
  5090. //
  5091. // Power Policy Management interfaces
  5092. //
  5093. typedef struct {
  5094. POWER_ACTION Action;
  5095. DWORD Flags;
  5096. DWORD EventCode;
  5097. } POWER_ACTION_POLICY, *PPOWER_ACTION_POLICY;
  5098. // POWER_ACTION_POLICY->Flags:
  5099. #define POWER_ACTION_QUERY_ALLOWED 0x00000001
  5100. #define POWER_ACTION_UI_ALLOWED 0x00000002
  5101. #define POWER_ACTION_OVERRIDE_APPS 0x00000004
  5102. #define POWER_ACTION_LIGHTEST_FIRST 0x10000000
  5103. #define POWER_ACTION_LOCK_CONSOLE 0x20000000
  5104. #define POWER_ACTION_DISABLE_WAKES 0x40000000
  5105. #define POWER_ACTION_CRITICAL 0x80000000
  5106. // POWER_ACTION_POLICY->EventCode flags
  5107. #define POWER_LEVEL_USER_NOTIFY_TEXT 0x00000001
  5108. #define POWER_LEVEL_USER_NOTIFY_SOUND 0x00000002
  5109. #define POWER_LEVEL_USER_NOTIFY_EXEC 0x00000004
  5110. #define POWER_USER_NOTIFY_BUTTON 0x00000008
  5111. #define POWER_USER_NOTIFY_SHUTDOWN 0x00000010
  5112. #define POWER_FORCE_TRIGGER_RESET 0x80000000
  5113. // system battery drain policies
  5114. typedef struct {
  5115. BOOLEAN Enable;
  5116. BYTE Spare[3];
  5117. DWORD BatteryLevel;
  5118. POWER_ACTION_POLICY PowerPolicy;
  5119. SYSTEM_POWER_STATE MinSystemState;
  5120. } SYSTEM_POWER_LEVEL, *PSYSTEM_POWER_LEVEL;
  5121. // Discharge policy constants
  5122. #define NUM_DISCHARGE_POLICIES 4
  5123. #define DISCHARGE_POLICY_CRITICAL 0
  5124. #define DISCHARGE_POLICY_LOW 1
  5125. //
  5126. // Throttling policies
  5127. //
  5128. #define PO_THROTTLE_NONE 0
  5129. #define PO_THROTTLE_CONSTANT 1
  5130. #define PO_THROTTLE_DEGRADE 2
  5131. #define PO_THROTTLE_ADAPTIVE 3
  5132. #define PO_THROTTLE_MAXIMUM 4 // not a policy, just a limit
  5133. // system power policies
  5134. typedef struct _SYSTEM_POWER_POLICY {
  5135. DWORD Revision; // 1
  5136. // events
  5137. POWER_ACTION_POLICY PowerButton;
  5138. POWER_ACTION_POLICY SleepButton;
  5139. POWER_ACTION_POLICY LidClose;
  5140. SYSTEM_POWER_STATE LidOpenWake;
  5141. DWORD Reserved;
  5142. // "system idle" detection
  5143. POWER_ACTION_POLICY Idle;
  5144. DWORD IdleTimeout;
  5145. BYTE IdleSensitivity;
  5146. // dynamic throttling policy
  5147. // PO_THROTTLE_NONE, PO_THROTTLE_CONSTANT, PO_THROTTLE_DEGRADE, or PO_THROTTLE_ADAPTIVE
  5148. BYTE DynamicThrottle;
  5149. BYTE Spare2[2];
  5150. // meaning of power action "sleep"
  5151. SYSTEM_POWER_STATE MinSleep;
  5152. SYSTEM_POWER_STATE MaxSleep;
  5153. SYSTEM_POWER_STATE ReducedLatencySleep;
  5154. DWORD WinLogonFlags;
  5155. // parameters for dozing
  5156. DWORD Spare3;
  5157. DWORD DozeS4Timeout;
  5158. // battery policies
  5159. DWORD BroadcastCapacityResolution;
  5160. SYSTEM_POWER_LEVEL DischargePolicy[NUM_DISCHARGE_POLICIES];
  5161. // video policies
  5162. DWORD VideoTimeout;
  5163. BOOLEAN VideoDimDisplay;
  5164. DWORD VideoReserved[3];
  5165. // hard disk policies
  5166. DWORD SpindownTimeout;
  5167. // processor policies
  5168. BOOLEAN OptimizeForPower;
  5169. BYTE FanThrottleTolerance;
  5170. BYTE ForcedThrottle;
  5171. BYTE MinThrottle;
  5172. POWER_ACTION_POLICY OverThrottled;
  5173. } SYSTEM_POWER_POLICY, *PSYSTEM_POWER_POLICY;
  5174. // processor power policy state
  5175. typedef struct _PROCESSOR_POWER_POLICY_INFO {
  5176. // Time based information (will be converted to kernel units)
  5177. DWORD TimeCheck; // in US
  5178. DWORD DemoteLimit; // in US
  5179. DWORD PromoteLimit; // in US
  5180. // Percentage based information
  5181. BYTE DemotePercent;
  5182. BYTE PromotePercent;
  5183. BYTE Spare[2];
  5184. // Flags
  5185. DWORD AllowDemotion:1;
  5186. DWORD AllowPromotion:1;
  5187. DWORD Reserved:30;
  5188. } PROCESSOR_POWER_POLICY_INFO, *PPROCESSOR_POWER_POLICY_INFO;
  5189. // processor power policy
  5190. typedef struct _PROCESSOR_POWER_POLICY {
  5191. DWORD Revision; // 1
  5192. // Dynamic Throttling Policy
  5193. BYTE DynamicThrottle;
  5194. BYTE Spare[3];
  5195. // Flags
  5196. DWORD DisableCStates:1;
  5197. DWORD Reserved:31;
  5198. // System policy information
  5199. // The Array is last, in case it needs to be grown and the structure
  5200. // revision incremented.
  5201. DWORD PolicyCount;
  5202. PROCESSOR_POWER_POLICY_INFO Policy[3];
  5203. } PROCESSOR_POWER_POLICY, *PPROCESSOR_POWER_POLICY;
  5204. // administrator power policy overrides
  5205. typedef struct _ADMINISTRATOR_POWER_POLICY {
  5206. // meaning of power action "sleep"
  5207. SYSTEM_POWER_STATE MinSleep;
  5208. SYSTEM_POWER_STATE MaxSleep;
  5209. // video policies
  5210. DWORD MinVideoTimeout;
  5211. DWORD MaxVideoTimeout;
  5212. // disk policies
  5213. DWORD MinSpindownTimeout;
  5214. DWORD MaxSpindownTimeout;
  5215. } ADMINISTRATOR_POWER_POLICY, *PADMINISTRATOR_POWER_POLICY;
  5216. typedef struct {
  5217. // Misc supported system features
  5218. BOOLEAN PowerButtonPresent;
  5219. BOOLEAN SleepButtonPresent;
  5220. BOOLEAN LidPresent;
  5221. BOOLEAN SystemS1;
  5222. BOOLEAN SystemS2;
  5223. BOOLEAN SystemS3;
  5224. BOOLEAN SystemS4; // hibernate
  5225. BOOLEAN SystemS5; // off
  5226. BOOLEAN HiberFilePresent;
  5227. BOOLEAN FullWake;
  5228. BOOLEAN VideoDimPresent;
  5229. BOOLEAN ApmPresent;
  5230. BOOLEAN UpsPresent;
  5231. // Processors
  5232. BOOLEAN ThermalControl;
  5233. BOOLEAN ProcessorThrottle;
  5234. BYTE ProcessorMinThrottle;
  5235. BYTE ProcessorMaxThrottle;
  5236. BYTE spare2[4];
  5237. // Disk
  5238. BOOLEAN DiskSpinDown;
  5239. BYTE spare3[8];
  5240. // System Battery
  5241. BOOLEAN SystemBatteriesPresent;
  5242. BOOLEAN BatteriesAreShortTerm;
  5243. BATTERY_REPORTING_SCALE BatteryScale[3];
  5244. // Wake
  5245. SYSTEM_POWER_STATE AcOnLineWake;
  5246. SYSTEM_POWER_STATE SoftLidWake;
  5247. SYSTEM_POWER_STATE RtcWake;
  5248. SYSTEM_POWER_STATE MinDeviceWakeState; // note this may change on driver load
  5249. SYSTEM_POWER_STATE DefaultLowLatencyWake;
  5250. } SYSTEM_POWER_CAPABILITIES, *PSYSTEM_POWER_CAPABILITIES;
  5251. typedef struct {
  5252. BOOLEAN AcOnLine;
  5253. BOOLEAN BatteryPresent;
  5254. BOOLEAN Charging;
  5255. BOOLEAN Discharging;
  5256. BOOLEAN Spare1[4];
  5257. DWORD MaxCapacity;
  5258. DWORD RemainingCapacity;
  5259. DWORD Rate;
  5260. DWORD EstimatedTime;
  5261. DWORD DefaultAlert1;
  5262. DWORD DefaultAlert2;
  5263. } SYSTEM_BATTERY_STATE, *PSYSTEM_BATTERY_STATE;
  5264. //
  5265. // Image Format
  5266. //
  5267. #ifndef _MAC
  5268. #include "pshpack4.h" // 4 byte packing is the default
  5269. #define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
  5270. #define IMAGE_OS2_SIGNATURE 0x454E // NE
  5271. #define IMAGE_OS2_SIGNATURE_LE 0x454C // LE
  5272. #define IMAGE_VXD_SIGNATURE 0x454C // LE
  5273. #define IMAGE_NT_SIGNATURE 0x00004550 // PE00
  5274. #include "pshpack2.h" // 16 bit headers are 2 byte packed
  5275. #else
  5276. #include "pshpack1.h"
  5277. #define IMAGE_DOS_SIGNATURE 0x4D5A // MZ
  5278. #define IMAGE_OS2_SIGNATURE 0x4E45 // NE
  5279. #define IMAGE_OS2_SIGNATURE_LE 0x4C45 // LE
  5280. #define IMAGE_NT_SIGNATURE 0x50450000 // PE00
  5281. #endif
  5282. typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
  5283. WORD e_magic; // Magic number
  5284. WORD e_cblp; // Bytes on last page of file
  5285. WORD e_cp; // Pages in file
  5286. WORD e_crlc; // Relocations
  5287. WORD e_cparhdr; // Size of header in paragraphs
  5288. WORD e_minalloc; // Minimum extra paragraphs needed
  5289. WORD e_maxalloc; // Maximum extra paragraphs needed
  5290. WORD e_ss; // Initial (relative) SS value
  5291. WORD e_sp; // Initial SP value
  5292. WORD e_csum; // Checksum
  5293. WORD e_ip; // Initial IP value
  5294. WORD e_cs; // Initial (relative) CS value
  5295. WORD e_lfarlc; // File address of relocation table
  5296. WORD e_ovno; // Overlay number
  5297. WORD e_res[4]; // Reserved words
  5298. WORD e_oemid; // OEM identifier (for e_oeminfo)
  5299. WORD e_oeminfo; // OEM information; e_oemid specific
  5300. WORD e_res2[10]; // Reserved words
  5301. LONG e_lfanew; // File address of new exe header
  5302. } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
  5303. typedef struct _IMAGE_OS2_HEADER { // OS/2 .EXE header
  5304. WORD ne_magic; // Magic number
  5305. CHAR ne_ver; // Version number
  5306. CHAR ne_rev; // Revision number
  5307. WORD ne_enttab; // Offset of Entry Table
  5308. WORD ne_cbenttab; // Number of bytes in Entry Table
  5309. LONG ne_crc; // Checksum of whole file
  5310. WORD ne_flags; // Flag word
  5311. WORD ne_autodata; // Automatic data segment number
  5312. WORD ne_heap; // Initial heap allocation
  5313. WORD ne_stack; // Initial stack allocation
  5314. LONG ne_csip; // Initial CS:IP setting
  5315. LONG ne_sssp; // Initial SS:SP setting
  5316. WORD ne_cseg; // Count of file segments
  5317. WORD ne_cmod; // Entries in Module Reference Table
  5318. WORD ne_cbnrestab; // Size of non-resident name table
  5319. WORD ne_segtab; // Offset of Segment Table
  5320. WORD ne_rsrctab; // Offset of Resource Table
  5321. WORD ne_restab; // Offset of resident name table
  5322. WORD ne_modtab; // Offset of Module Reference Table
  5323. WORD ne_imptab; // Offset of Imported Names Table
  5324. LONG ne_nrestab; // Offset of Non-resident Names Table
  5325. WORD ne_cmovent; // Count of movable entries
  5326. WORD ne_align; // Segment alignment shift count
  5327. WORD ne_cres; // Count of resource segments
  5328. BYTE ne_exetyp; // Target Operating system
  5329. BYTE ne_flagsothers; // Other .EXE flags
  5330. WORD ne_pretthunks; // offset to return thunks
  5331. WORD ne_psegrefbytes; // offset to segment ref. bytes
  5332. WORD ne_swaparea; // Minimum code swap area size
  5333. WORD ne_expver; // Expected Windows version number
  5334. } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
  5335. typedef struct _IMAGE_VXD_HEADER { // Windows VXD header
  5336. WORD e32_magic; // Magic number
  5337. BYTE e32_border; // The byte ordering for the VXD
  5338. BYTE e32_worder; // The word ordering for the VXD
  5339. DWORD e32_level; // The EXE format level for now = 0
  5340. WORD e32_cpu; // The CPU type
  5341. WORD e32_os; // The OS type
  5342. DWORD e32_ver; // Module version
  5343. DWORD e32_mflags; // Module flags
  5344. DWORD e32_mpages; // Module # pages
  5345. DWORD e32_startobj; // Object # for instruction pointer
  5346. DWORD e32_eip; // Extended instruction pointer
  5347. DWORD e32_stackobj; // Object # for stack pointer
  5348. DWORD e32_esp; // Extended stack pointer
  5349. DWORD e32_pagesize; // VXD page size
  5350. DWORD e32_lastpagesize; // Last page size in VXD
  5351. DWORD e32_fixupsize; // Fixup section size
  5352. DWORD e32_fixupsum; // Fixup section checksum
  5353. DWORD e32_ldrsize; // Loader section size
  5354. DWORD e32_ldrsum; // Loader section checksum
  5355. DWORD e32_objtab; // Object table offset
  5356. DWORD e32_objcnt; // Number of objects in module
  5357. DWORD e32_objmap; // Object page map offset
  5358. DWORD e32_itermap; // Object iterated data map offset
  5359. DWORD e32_rsrctab; // Offset of Resource Table
  5360. DWORD e32_rsrccnt; // Number of resource entries
  5361. DWORD e32_restab; // Offset of resident name table
  5362. DWORD e32_enttab; // Offset of Entry Table
  5363. DWORD e32_dirtab; // Offset of Module Directive Table
  5364. DWORD e32_dircnt; // Number of module directives
  5365. DWORD e32_fpagetab; // Offset of Fixup Page Table
  5366. DWORD e32_frectab; // Offset of Fixup Record Table
  5367. DWORD e32_impmod; // Offset of Import Module Name Table
  5368. DWORD e32_impmodcnt; // Number of entries in Import Module Name Table
  5369. DWORD e32_impproc; // Offset of Import Procedure Name Table
  5370. DWORD e32_pagesum; // Offset of Per-Page Checksum Table
  5371. DWORD e32_datapage; // Offset of Enumerated Data Pages
  5372. DWORD e32_preload; // Number of preload pages
  5373. DWORD e32_nrestab; // Offset of Non-resident Names Table
  5374. DWORD e32_cbnrestab; // Size of Non-resident Name Table
  5375. DWORD e32_nressum; // Non-resident Name Table Checksum
  5376. DWORD e32_autodata; // Object # for automatic data object
  5377. DWORD e32_debuginfo; // Offset of the debugging information
  5378. DWORD e32_debuglen; // The length of the debugging info. in bytes
  5379. DWORD e32_instpreload; // Number of instance pages in preload section of VXD file
  5380. DWORD e32_instdemand; // Number of instance pages in demand load section of VXD file
  5381. DWORD e32_heapsize; // Size of heap - for 16-bit apps
  5382. BYTE e32_res3[12]; // Reserved words
  5383. DWORD e32_winresoff;
  5384. DWORD e32_winreslen;
  5385. WORD e32_devid; // Device ID for VxD
  5386. WORD e32_ddkver; // DDK version for VxD
  5387. } IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
  5388. #ifndef _MAC
  5389. #include "poppack.h" // Back to 4 byte packing
  5390. #endif
  5391. //
  5392. // File header format.
  5393. //
  5394. typedef struct _IMAGE_FILE_HEADER {
  5395. WORD Machine;
  5396. WORD NumberOfSections;
  5397. DWORD TimeDateStamp;
  5398. DWORD PointerToSymbolTable;
  5399. DWORD NumberOfSymbols;
  5400. WORD SizeOfOptionalHeader;
  5401. WORD Characteristics;
  5402. } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
  5403. #define IMAGE_SIZEOF_FILE_HEADER 20
  5404. #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
  5405. #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
  5406. #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
  5407. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
  5408. #define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010 // Agressively trim working set
  5409. #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 // App can handle >2gb addresses
  5410. #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
  5411. #define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
  5412. #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
  5413. #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 // If Image is on removable media, copy and run from the swap file.
  5414. #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 // If Image is on Net, copy and run from the swap file.
  5415. #define IMAGE_FILE_SYSTEM 0x1000 // System File.
  5416. #define IMAGE_FILE_DLL 0x2000 // File is a DLL.
  5417. #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 // File should only be run on a UP machine
  5418. #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
  5419. #define IMAGE_FILE_MACHINE_UNKNOWN 0
  5420. #define IMAGE_FILE_MACHINE_I386 0x014c // Intel 386.
  5421. #define IMAGE_FILE_MACHINE_R3000 0x0162 // MIPS little-endian, 0x160 big-endian
  5422. #define IMAGE_FILE_MACHINE_R4000 0x0166 // MIPS little-endian
  5423. #define IMAGE_FILE_MACHINE_R10000 0x0168 // MIPS little-endian
  5424. #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 // MIPS little-endian WCE v2
  5425. #define IMAGE_FILE_MACHINE_ALPHA 0x0184 // Alpha_AXP
  5426. #define IMAGE_FILE_MACHINE_SH3 0x01a2 // SH3 little-endian
  5427. #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
  5428. #define IMAGE_FILE_MACHINE_SH3E 0x01a4 // SH3E little-endian
  5429. #define IMAGE_FILE_MACHINE_SH4 0x01a6 // SH4 little-endian
  5430. #define IMAGE_FILE_MACHINE_SH5 0x01a8 // SH5
  5431. #define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian
  5432. #define IMAGE_FILE_MACHINE_THUMB 0x01c2
  5433. #define IMAGE_FILE_MACHINE_AM33 0x01d3
  5434. #define IMAGE_FILE_MACHINE_POWERPC 0x01F0 // IBM PowerPC Little-Endian
  5435. #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
  5436. #define IMAGE_FILE_MACHINE_IA64 0x0200 // Intel 64
  5437. #define IMAGE_FILE_MACHINE_MIPS16 0x0266 // MIPS
  5438. #define IMAGE_FILE_MACHINE_ALPHA64 0x0284 // ALPHA64
  5439. #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 // MIPS
  5440. #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 // MIPS
  5441. #define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64
  5442. #define IMAGE_FILE_MACHINE_TRICORE 0x0520 // Infineon
  5443. #define IMAGE_FILE_MACHINE_CEF 0x0CEF
  5444. #define IMAGE_FILE_MACHINE_EBC 0x0EBC // EFI Byte Code
  5445. #define IMAGE_FILE_MACHINE_AMD64 0x8664 // AMD64 (K8)
  5446. #define IMAGE_FILE_MACHINE_M32R 0x9041 // M32R little-endian
  5447. #define IMAGE_FILE_MACHINE_CEE 0xC0EE
  5448. //
  5449. // Directory format.
  5450. //
  5451. typedef struct _IMAGE_DATA_DIRECTORY {
  5452. DWORD VirtualAddress;
  5453. DWORD Size;
  5454. } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
  5455. #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
  5456. //
  5457. // Optional header format.
  5458. //
  5459. typedef struct _IMAGE_OPTIONAL_HEADER {
  5460. //
  5461. // Standard fields.
  5462. //
  5463. WORD Magic;
  5464. BYTE MajorLinkerVersion;
  5465. BYTE MinorLinkerVersion;
  5466. DWORD SizeOfCode;
  5467. DWORD SizeOfInitializedData;
  5468. DWORD SizeOfUninitializedData;
  5469. DWORD AddressOfEntryPoint;
  5470. DWORD BaseOfCode;
  5471. DWORD BaseOfData;
  5472. //
  5473. // NT additional fields.
  5474. //
  5475. DWORD ImageBase;
  5476. DWORD SectionAlignment;
  5477. DWORD FileAlignment;
  5478. WORD MajorOperatingSystemVersion;
  5479. WORD MinorOperatingSystemVersion;
  5480. WORD MajorImageVersion;
  5481. WORD MinorImageVersion;
  5482. WORD MajorSubsystemVersion;
  5483. WORD MinorSubsystemVersion;
  5484. DWORD Win32VersionValue;
  5485. DWORD SizeOfImage;
  5486. DWORD SizeOfHeaders;
  5487. DWORD CheckSum;
  5488. WORD Subsystem;
  5489. WORD DllCharacteristics;
  5490. DWORD SizeOfStackReserve;
  5491. DWORD SizeOfStackCommit;
  5492. DWORD SizeOfHeapReserve;
  5493. DWORD SizeOfHeapCommit;
  5494. DWORD LoaderFlags;
  5495. DWORD NumberOfRvaAndSizes;
  5496. IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  5497. } IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;
  5498. typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
  5499. WORD Magic;
  5500. BYTE MajorLinkerVersion;
  5501. BYTE MinorLinkerVersion;
  5502. DWORD SizeOfCode;
  5503. DWORD SizeOfInitializedData;
  5504. DWORD SizeOfUninitializedData;
  5505. DWORD AddressOfEntryPoint;
  5506. DWORD BaseOfCode;
  5507. DWORD BaseOfData;
  5508. DWORD BaseOfBss;
  5509. DWORD GprMask;
  5510. DWORD CprMask[4];
  5511. DWORD GpValue;
  5512. } IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
  5513. typedef struct _IMAGE_OPTIONAL_HEADER64 {
  5514. WORD Magic;
  5515. BYTE MajorLinkerVersion;
  5516. BYTE MinorLinkerVersion;
  5517. DWORD SizeOfCode;
  5518. DWORD SizeOfInitializedData;
  5519. DWORD SizeOfUninitializedData;
  5520. DWORD AddressOfEntryPoint;
  5521. DWORD BaseOfCode;
  5522. ULONGLONG ImageBase;
  5523. DWORD SectionAlignment;
  5524. DWORD FileAlignment;
  5525. WORD MajorOperatingSystemVersion;
  5526. WORD MinorOperatingSystemVersion;
  5527. WORD MajorImageVersion;
  5528. WORD MinorImageVersion;
  5529. WORD MajorSubsystemVersion;
  5530. WORD MinorSubsystemVersion;
  5531. DWORD Win32VersionValue;
  5532. DWORD SizeOfImage;
  5533. DWORD SizeOfHeaders;
  5534. DWORD CheckSum;
  5535. WORD Subsystem;
  5536. WORD DllCharacteristics;
  5537. ULONGLONG SizeOfStackReserve;
  5538. ULONGLONG SizeOfStackCommit;
  5539. ULONGLONG SizeOfHeapReserve;
  5540. ULONGLONG SizeOfHeapCommit;
  5541. DWORD LoaderFlags;
  5542. DWORD NumberOfRvaAndSizes;
  5543. IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  5544. } IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64;
  5545. #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER 56
  5546. #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER 28
  5547. #define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224
  5548. #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240
  5549. #define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
  5550. #define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
  5551. #define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
  5552. #ifdef _WIN64
  5553. typedef IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER;
  5554. typedef PIMAGE_OPTIONAL_HEADER64 PIMAGE_OPTIONAL_HEADER;
  5555. #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
  5556. #define IMAGE_NT_OPTIONAL_HDR_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
  5557. #else
  5558. typedef IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER;
  5559. typedef PIMAGE_OPTIONAL_HEADER32 PIMAGE_OPTIONAL_HEADER;
  5560. #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
  5561. #define IMAGE_NT_OPTIONAL_HDR_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
  5562. #endif
  5563. typedef struct _IMAGE_NT_HEADERS64 {
  5564. DWORD Signature;
  5565. IMAGE_FILE_HEADER FileHeader;
  5566. IMAGE_OPTIONAL_HEADER64 OptionalHeader;
  5567. } IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64;
  5568. typedef struct _IMAGE_NT_HEADERS {
  5569. DWORD Signature;
  5570. IMAGE_FILE_HEADER FileHeader;
  5571. IMAGE_OPTIONAL_HEADER32 OptionalHeader;
  5572. } IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
  5573. typedef struct _IMAGE_ROM_HEADERS {
  5574. IMAGE_FILE_HEADER FileHeader;
  5575. IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
  5576. } IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
  5577. #ifdef _WIN64
  5578. typedef IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS;
  5579. typedef PIMAGE_NT_HEADERS64 PIMAGE_NT_HEADERS;
  5580. #else
  5581. typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS;
  5582. typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS;
  5583. #endif
  5584. // IMAGE_FIRST_SECTION doesn't need 32/64 versions since the file header is the same either way.
  5585. #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER) \
  5586. ((ULONG_PTR)ntheader + \
  5587. FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) + \
  5588. ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader \
  5589. ))
  5590. // Subsystem Values
  5591. #define IMAGE_SUBSYSTEM_UNKNOWN 0 // Unknown subsystem.
  5592. #define IMAGE_SUBSYSTEM_NATIVE 1 // Image doesn't require a subsystem.
  5593. #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 // Image runs in the Windows GUI subsystem.
  5594. #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 // Image runs in the Windows character subsystem.
  5595. #define IMAGE_SUBSYSTEM_OS2_CUI 5 // image runs in the OS/2 character subsystem.
  5596. #define IMAGE_SUBSYSTEM_POSIX_CUI 7 // image runs in the Posix character subsystem.
  5597. #define IMAGE_SUBSYSTEM_NATIVE_WINDOWS 8 // image is a native Win9x driver.
  5598. #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 // Image runs in the Windows CE subsystem.
  5599. #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 //
  5600. #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 //
  5601. #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 //
  5602. #define IMAGE_SUBSYSTEM_EFI_ROM 13
  5603. #define IMAGE_SUBSYSTEM_XBOX 14
  5604. // DllCharacteristics Entries
  5605. // IMAGE_LIBRARY_PROCESS_INIT 0x0001 // Reserved.
  5606. // IMAGE_LIBRARY_PROCESS_TERM 0x0002 // Reserved.
  5607. // IMAGE_LIBRARY_THREAD_INIT 0x0004 // Reserved.
  5608. // IMAGE_LIBRARY_THREAD_TERM 0x0008 // Reserved.
  5609. #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200 // Image understands isolation and doesn't want it
  5610. #define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 // Image does not use SEH. No SE handler may reside in this image
  5611. #define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 // Do not bind this image.
  5612. // 0x1000 // Reserved.
  5613. #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 // Driver uses WDM model
  5614. // 0x4000 // Reserved.
  5615. #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
  5616. // Directory Entries
  5617. #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
  5618. #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory
  5619. #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory
  5620. #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory
  5621. #define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory
  5622. #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table
  5623. #define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory
  5624. // IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // (X86 usage)
  5625. #define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 // Architecture Specific Data
  5626. #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // RVA of GP
  5627. #define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory
  5628. #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory
  5629. #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers
  5630. #define IMAGE_DIRECTORY_ENTRY_IAT 12 // Import Address Table
  5631. #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 // Delay Load Import Descriptors
  5632. #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 // COM Runtime descriptor
  5633. //
  5634. // Non-COFF Object file header
  5635. //
  5636. typedef struct ANON_OBJECT_HEADER {
  5637. WORD Sig1; // Must be IMAGE_FILE_MACHINE_UNKNOWN
  5638. WORD Sig2; // Must be 0xffff
  5639. WORD Version; // >= 1 (implies the CLSID field is present)
  5640. WORD Machine;
  5641. DWORD TimeDateStamp;
  5642. CLSID ClassID; // Used to invoke CoCreateInstance
  5643. DWORD SizeOfData; // Size of data that follows the header
  5644. } ANON_OBJECT_HEADER;
  5645. //
  5646. // Section header format.
  5647. //
  5648. #define IMAGE_SIZEOF_SHORT_NAME 8
  5649. typedef struct _IMAGE_SECTION_HEADER {
  5650. BYTE Name[IMAGE_SIZEOF_SHORT_NAME];
  5651. union {
  5652. DWORD PhysicalAddress;
  5653. DWORD VirtualSize;
  5654. } Misc;
  5655. DWORD VirtualAddress;
  5656. DWORD SizeOfRawData;
  5657. DWORD PointerToRawData;
  5658. DWORD PointerToRelocations;
  5659. DWORD PointerToLinenumbers;
  5660. WORD NumberOfRelocations;
  5661. WORD NumberOfLinenumbers;
  5662. DWORD Characteristics;
  5663. } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
  5664. #define IMAGE_SIZEOF_SECTION_HEADER 40
  5665. //
  5666. // Section characteristics.
  5667. //
  5668. // IMAGE_SCN_TYPE_REG 0x00000000 // Reserved.
  5669. // IMAGE_SCN_TYPE_DSECT 0x00000001 // Reserved.
  5670. // IMAGE_SCN_TYPE_NOLOAD 0x00000002 // Reserved.
  5671. // IMAGE_SCN_TYPE_GROUP 0x00000004 // Reserved.
  5672. #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved.
  5673. // IMAGE_SCN_TYPE_COPY 0x00000010 // Reserved.
  5674. #define IMAGE_SCN_CNT_CODE 0x00000020 // Section contains code.
  5675. #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 // Section contains initialized data.
  5676. #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 // Section contains uninitialized data.
  5677. #define IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved.
  5678. #define IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information.
  5679. // IMAGE_SCN_TYPE_OVER 0x00000400 // Reserved.
  5680. #define IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image.
  5681. #define IMAGE_SCN_LNK_COMDAT 0x00001000 // Section contents comdat.
  5682. // 0x00002000 // Reserved.
  5683. // IMAGE_SCN_MEM_PROTECTED - Obsolete 0x00004000
  5684. #define IMAGE_SCN_NO_DEFER_SPEC_EXC 0x00004000 // Reset speculative exceptions handling bits in the TLB entries for this section.
  5685. #define IMAGE_SCN_GPREL 0x00008000 // Section content can be accessed relative to GP
  5686. #define IMAGE_SCN_MEM_FARDATA 0x00008000
  5687. // IMAGE_SCN_MEM_SYSHEAP - Obsolete 0x00010000
  5688. #define IMAGE_SCN_MEM_PURGEABLE 0x00020000
  5689. #define IMAGE_SCN_MEM_16BIT 0x00020000
  5690. #define IMAGE_SCN_MEM_LOCKED 0x00040000
  5691. #define IMAGE_SCN_MEM_PRELOAD 0x00080000
  5692. #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 //
  5693. #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 //
  5694. #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 //
  5695. #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 //
  5696. #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 // Default alignment if no others are specified.
  5697. #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 //
  5698. #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 //
  5699. #define IMAGE_SCN_ALIGN_128BYTES 0x00800000 //
  5700. #define IMAGE_SCN_ALIGN_256BYTES 0x00900000 //
  5701. #define IMAGE_SCN_ALIGN_512BYTES 0x00A00000 //
  5702. #define IMAGE_SCN_ALIGN_1024BYTES 0x00B00000 //
  5703. #define IMAGE_SCN_ALIGN_2048BYTES 0x00C00000 //
  5704. #define IMAGE_SCN_ALIGN_4096BYTES 0x00D00000 //
  5705. #define IMAGE_SCN_ALIGN_8192BYTES 0x00E00000 //
  5706. // Unused 0x00F00000
  5707. #define IMAGE_SCN_ALIGN_MASK 0x00F00000
  5708. #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 // Section contains extended relocations.
  5709. #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 // Section can be discarded.
  5710. #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 // Section is not cachable.
  5711. #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 // Section is not pageable.
  5712. #define IMAGE_SCN_MEM_SHARED 0x10000000 // Section is shareable.
  5713. #define IMAGE_SCN_MEM_EXECUTE 0x20000000 // Section is executable.
  5714. #define IMAGE_SCN_MEM_READ 0x40000000 // Section is readable.
  5715. #define IMAGE_SCN_MEM_WRITE 0x80000000 // Section is writeable.
  5716. //
  5717. // TLS Chaacteristic Flags
  5718. //
  5719. #define IMAGE_SCN_SCALE_INDEX 0x00000001 // Tls index is scaled
  5720. #ifndef _MAC
  5721. #include "pshpack2.h" // Symbols, relocs, and linenumbers are 2 byte packed
  5722. #endif
  5723. //
  5724. // Symbol format.
  5725. //
  5726. typedef struct _IMAGE_SYMBOL {
  5727. union {
  5728. BYTE ShortName[8];
  5729. struct {
  5730. DWORD Short; // if 0, use LongName
  5731. DWORD Long; // offset into string table
  5732. } Name;
  5733. DWORD LongName[2]; // PBYTE [2]
  5734. } N;
  5735. DWORD Value;
  5736. SHORT SectionNumber;
  5737. WORD Type;
  5738. BYTE StorageClass;
  5739. BYTE NumberOfAuxSymbols;
  5740. } IMAGE_SYMBOL;
  5741. typedef IMAGE_SYMBOL UNALIGNED *PIMAGE_SYMBOL;
  5742. #define IMAGE_SIZEOF_SYMBOL 18
  5743. //
  5744. // Section values.
  5745. //
  5746. // Symbols have a section number of the section in which they are
  5747. // defined. Otherwise, section numbers have the following meanings:
  5748. //
  5749. #define IMAGE_SYM_UNDEFINED (SHORT)0 // Symbol is undefined or is common.
  5750. #define IMAGE_SYM_ABSOLUTE (SHORT)-1 // Symbol is an absolute value.
  5751. #define IMAGE_SYM_DEBUG (SHORT)-2 // Symbol is a special debug item.
  5752. #define IMAGE_SYM_SECTION_MAX 0xFEFF // Values 0xFF00-0xFFFF are special
  5753. //
  5754. // Type (fundamental) values.
  5755. //
  5756. #define IMAGE_SYM_TYPE_NULL 0x0000 // no type.
  5757. #define IMAGE_SYM_TYPE_VOID 0x0001 //
  5758. #define IMAGE_SYM_TYPE_CHAR 0x0002 // type character.
  5759. #define IMAGE_SYM_TYPE_SHORT 0x0003 // type short integer.
  5760. #define IMAGE_SYM_TYPE_INT 0x0004 //
  5761. #define IMAGE_SYM_TYPE_LONG 0x0005 //
  5762. #define IMAGE_SYM_TYPE_FLOAT 0x0006 //
  5763. #define IMAGE_SYM_TYPE_DOUBLE 0x0007 //
  5764. #define IMAGE_SYM_TYPE_STRUCT 0x0008 //
  5765. #define IMAGE_SYM_TYPE_UNION 0x0009 //
  5766. #define IMAGE_SYM_TYPE_ENUM 0x000A // enumeration.
  5767. #define IMAGE_SYM_TYPE_MOE 0x000B // member of enumeration.
  5768. #define IMAGE_SYM_TYPE_BYTE 0x000C //
  5769. #define IMAGE_SYM_TYPE_WORD 0x000D //
  5770. #define IMAGE_SYM_TYPE_UINT 0x000E //
  5771. #define IMAGE_SYM_TYPE_DWORD 0x000F //
  5772. #define IMAGE_SYM_TYPE_PCODE 0x8000 //
  5773. //
  5774. // Type (derived) values.
  5775. //
  5776. #define IMAGE_SYM_DTYPE_NULL 0 // no derived type.
  5777. #define IMAGE_SYM_DTYPE_POINTER 1 // pointer.
  5778. #define IMAGE_SYM_DTYPE_FUNCTION 2 // function.
  5779. #define IMAGE_SYM_DTYPE_ARRAY 3 // array.
  5780. //
  5781. // Storage classes.
  5782. //
  5783. #define IMAGE_SYM_CLASS_END_OF_FUNCTION (BYTE )-1
  5784. #define IMAGE_SYM_CLASS_NULL 0x0000
  5785. #define IMAGE_SYM_CLASS_AUTOMATIC 0x0001
  5786. #define IMAGE_SYM_CLASS_EXTERNAL 0x0002
  5787. #define IMAGE_SYM_CLASS_STATIC 0x0003
  5788. #define IMAGE_SYM_CLASS_REGISTER 0x0004
  5789. #define IMAGE_SYM_CLASS_EXTERNAL_DEF 0x0005
  5790. #define IMAGE_SYM_CLASS_LABEL 0x0006
  5791. #define IMAGE_SYM_CLASS_UNDEFINED_LABEL 0x0007
  5792. #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 0x0008
  5793. #define IMAGE_SYM_CLASS_ARGUMENT 0x0009
  5794. #define IMAGE_SYM_CLASS_STRUCT_TAG 0x000A
  5795. #define IMAGE_SYM_CLASS_MEMBER_OF_UNION 0x000B
  5796. #define IMAGE_SYM_CLASS_UNION_TAG 0x000C
  5797. #define IMAGE_SYM_CLASS_TYPE_DEFINITION 0x000D
  5798. #define IMAGE_SYM_CLASS_UNDEFINED_STATIC 0x000E
  5799. #define IMAGE_SYM_CLASS_ENUM_TAG 0x000F
  5800. #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 0x0010
  5801. #define IMAGE_SYM_CLASS_REGISTER_PARAM 0x0011
  5802. #define IMAGE_SYM_CLASS_BIT_FIELD 0x0012
  5803. #define IMAGE_SYM_CLASS_FAR_EXTERNAL 0x0044 //
  5804. #define IMAGE_SYM_CLASS_BLOCK 0x0064
  5805. #define IMAGE_SYM_CLASS_FUNCTION 0x0065
  5806. #define IMAGE_SYM_CLASS_END_OF_STRUCT 0x0066
  5807. #define IMAGE_SYM_CLASS_FILE 0x0067
  5808. // new
  5809. #define IMAGE_SYM_CLASS_SECTION 0x0068
  5810. #define IMAGE_SYM_CLASS_WEAK_EXTERNAL 0x0069
  5811. #define IMAGE_SYM_CLASS_CLR_TOKEN 0x006B
  5812. // type packing constants
  5813. #define N_BTMASK 0x000F
  5814. #define N_TMASK 0x0030
  5815. #define N_TMASK1 0x00C0
  5816. #define N_TMASK2 0x00F0
  5817. #define N_BTSHFT 4
  5818. #define N_TSHIFT 2
  5819. // MACROS
  5820. // Basic Type of x
  5821. #define BTYPE(x) ((x) & N_BTMASK)
  5822. // Is x a pointer?
  5823. #ifndef ISPTR
  5824. #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
  5825. #endif
  5826. // Is x a function?
  5827. #ifndef ISFCN
  5828. #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
  5829. #endif
  5830. // Is x an array?
  5831. #ifndef ISARY
  5832. #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
  5833. #endif
  5834. // Is x a structure, union, or enumeration TAG?
  5835. #ifndef ISTAG
  5836. #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
  5837. #endif
  5838. #ifndef INCREF
  5839. #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
  5840. #endif
  5841. #ifndef DECREF
  5842. #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  5843. #endif
  5844. //
  5845. // Auxiliary entry format.
  5846. //
  5847. typedef union _IMAGE_AUX_SYMBOL {
  5848. struct {
  5849. DWORD TagIndex; // struct, union, or enum tag index
  5850. union {
  5851. struct {
  5852. WORD Linenumber; // declaration line number
  5853. WORD Size; // size of struct, union, or enum
  5854. } LnSz;
  5855. DWORD TotalSize;
  5856. } Misc;
  5857. union {
  5858. struct { // if ISFCN, tag, or .bb
  5859. DWORD PointerToLinenumber;
  5860. DWORD PointerToNextFunction;
  5861. } Function;
  5862. struct { // if ISARY, up to 4 dimen.
  5863. WORD Dimension[4];
  5864. } Array;
  5865. } FcnAry;
  5866. WORD TvIndex; // tv index
  5867. } Sym;
  5868. struct {
  5869. BYTE Name[IMAGE_SIZEOF_SYMBOL];
  5870. } File;
  5871. struct {
  5872. DWORD Length; // section length
  5873. WORD NumberOfRelocations; // number of relocation entries
  5874. WORD NumberOfLinenumbers; // number of line numbers
  5875. DWORD CheckSum; // checksum for communal
  5876. SHORT Number; // section number to associate with
  5877. BYTE Selection; // communal selection type
  5878. } Section;
  5879. } IMAGE_AUX_SYMBOL;
  5880. typedef IMAGE_AUX_SYMBOL UNALIGNED *PIMAGE_AUX_SYMBOL;
  5881. #define IMAGE_SIZEOF_AUX_SYMBOL 18
  5882. typedef enum IMAGE_AUX_SYMBOL_TYPE {
  5883. IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF = 1,
  5884. } IMAGE_AUX_SYMBOL_TYPE;
  5885. #include <pshpack2.h>
  5886. typedef struct IMAGE_AUX_SYMBOL_TOKEN_DEF {
  5887. BYTE bAuxType; // IMAGE_AUX_SYMBOL_TYPE
  5888. BYTE bReserved; // Must be 0
  5889. DWORD SymbolTableIndex;
  5890. BYTE rgbReserved[12]; // Must be 0
  5891. } IMAGE_AUX_SYMBOL_TOKEN_DEF;
  5892. typedef IMAGE_AUX_SYMBOL_TOKEN_DEF UNALIGNED *PIMAGE_AUX_SYMBOL_TOKEN_DEF;
  5893. #include <poppack.h>
  5894. //
  5895. // Communal selection types.
  5896. //
  5897. #define IMAGE_COMDAT_SELECT_NODUPLICATES 1
  5898. #define IMAGE_COMDAT_SELECT_ANY 2
  5899. #define IMAGE_COMDAT_SELECT_SAME_SIZE 3
  5900. #define IMAGE_COMDAT_SELECT_EXACT_MATCH 4
  5901. #define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
  5902. #define IMAGE_COMDAT_SELECT_LARGEST 6
  5903. #define IMAGE_COMDAT_SELECT_NEWEST 7
  5904. #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
  5905. #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
  5906. #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
  5907. //
  5908. // Relocation format.
  5909. //
  5910. typedef struct _IMAGE_RELOCATION {
  5911. union {
  5912. DWORD VirtualAddress;
  5913. DWORD RelocCount; // Set to the real count when IMAGE_SCN_LNK_NRELOC_OVFL is set
  5914. };
  5915. DWORD SymbolTableIndex;
  5916. WORD Type;
  5917. } IMAGE_RELOCATION;
  5918. typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION;
  5919. #define IMAGE_SIZEOF_RELOCATION 10
  5920. //
  5921. // I386 relocation types.
  5922. //
  5923. #define IMAGE_REL_I386_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
  5924. #define IMAGE_REL_I386_DIR16 0x0001 // Direct 16-bit reference to the symbols virtual address
  5925. #define IMAGE_REL_I386_REL16 0x0002 // PC-relative 16-bit reference to the symbols virtual address
  5926. #define IMAGE_REL_I386_DIR32 0x0006 // Direct 32-bit reference to the symbols virtual address
  5927. #define IMAGE_REL_I386_DIR32NB 0x0007 // Direct 32-bit reference to the symbols virtual address, base not included
  5928. #define IMAGE_REL_I386_SEG12 0x0009 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
  5929. #define IMAGE_REL_I386_SECTION 0x000A
  5930. #define IMAGE_REL_I386_SECREL 0x000B
  5931. #define IMAGE_REL_I386_TOKEN 0x000C // clr token
  5932. #define IMAGE_REL_I386_SECREL7 0x000D // 7 bit offset from base of section containing target
  5933. #define IMAGE_REL_I386_REL32 0x0014 // PC-relative 32-bit reference to the symbols virtual address
  5934. //
  5935. // MIPS relocation types.
  5936. //
  5937. #define IMAGE_REL_MIPS_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
  5938. #define IMAGE_REL_MIPS_REFHALF 0x0001
  5939. #define IMAGE_REL_MIPS_REFWORD 0x0002
  5940. #define IMAGE_REL_MIPS_JMPADDR 0x0003
  5941. #define IMAGE_REL_MIPS_REFHI 0x0004
  5942. #define IMAGE_REL_MIPS_REFLO 0x0005
  5943. #define IMAGE_REL_MIPS_GPREL 0x0006
  5944. #define IMAGE_REL_MIPS_LITERAL 0x0007
  5945. #define IMAGE_REL_MIPS_SECTION 0x000A
  5946. #define IMAGE_REL_MIPS_SECREL 0x000B
  5947. #define IMAGE_REL_MIPS_SECRELLO 0x000C // Low 16-bit section relative referemce (used for >32k TLS)
  5948. #define IMAGE_REL_MIPS_SECRELHI 0x000D // High 16-bit section relative reference (used for >32k TLS)
  5949. #define IMAGE_REL_MIPS_TOKEN 0x000E // clr token
  5950. #define IMAGE_REL_MIPS_JMPADDR16 0x0010
  5951. #define IMAGE_REL_MIPS_REFWORDNB 0x0022
  5952. #define IMAGE_REL_MIPS_PAIR 0x0025
  5953. //
  5954. // Alpha Relocation types.
  5955. //
  5956. #define IMAGE_REL_ALPHA_ABSOLUTE 0x0000
  5957. #define IMAGE_REL_ALPHA_REFLONG 0x0001
  5958. #define IMAGE_REL_ALPHA_REFQUAD 0x0002
  5959. #define IMAGE_REL_ALPHA_GPREL32 0x0003
  5960. #define IMAGE_REL_ALPHA_LITERAL 0x0004
  5961. #define IMAGE_REL_ALPHA_LITUSE 0x0005
  5962. #define IMAGE_REL_ALPHA_GPDISP 0x0006
  5963. #define IMAGE_REL_ALPHA_BRADDR 0x0007
  5964. #define IMAGE_REL_ALPHA_HINT 0x0008
  5965. #define IMAGE_REL_ALPHA_INLINE_REFLONG 0x0009
  5966. #define IMAGE_REL_ALPHA_REFHI 0x000A
  5967. #define IMAGE_REL_ALPHA_REFLO 0x000B
  5968. #define IMAGE_REL_ALPHA_PAIR 0x000C
  5969. #define IMAGE_REL_ALPHA_MATCH 0x000D
  5970. #define IMAGE_REL_ALPHA_SECTION 0x000E
  5971. #define IMAGE_REL_ALPHA_SECREL 0x000F
  5972. #define IMAGE_REL_ALPHA_REFLONGNB 0x0010
  5973. #define IMAGE_REL_ALPHA_SECRELLO 0x0011 // Low 16-bit section relative reference
  5974. #define IMAGE_REL_ALPHA_SECRELHI 0x0012 // High 16-bit section relative reference
  5975. #define IMAGE_REL_ALPHA_REFQ3 0x0013 // High 16 bits of 48 bit reference
  5976. #define IMAGE_REL_ALPHA_REFQ2 0x0014 // Middle 16 bits of 48 bit reference
  5977. #define IMAGE_REL_ALPHA_REFQ1 0x0015 // Low 16 bits of 48 bit reference
  5978. #define IMAGE_REL_ALPHA_GPRELLO 0x0016 // Low 16-bit GP relative reference
  5979. #define IMAGE_REL_ALPHA_GPRELHI 0x0017 // High 16-bit GP relative reference
  5980. //
  5981. // IBM PowerPC relocation types.
  5982. //
  5983. #define IMAGE_REL_PPC_ABSOLUTE 0x0000 // NOP
  5984. #define IMAGE_REL_PPC_ADDR64 0x0001 // 64-bit address
  5985. #define IMAGE_REL_PPC_ADDR32 0x0002 // 32-bit address
  5986. #define IMAGE_REL_PPC_ADDR24 0x0003 // 26-bit address, shifted left 2 (branch absolute)
  5987. #define IMAGE_REL_PPC_ADDR16 0x0004 // 16-bit address
  5988. #define IMAGE_REL_PPC_ADDR14 0x0005 // 16-bit address, shifted left 2 (load doubleword)
  5989. #define IMAGE_REL_PPC_REL24 0x0006 // 26-bit PC-relative offset, shifted left 2 (branch relative)
  5990. #define IMAGE_REL_PPC_REL14 0x0007 // 16-bit PC-relative offset, shifted left 2 (br cond relative)
  5991. #define IMAGE_REL_PPC_TOCREL16 0x0008 // 16-bit offset from TOC base
  5992. #define IMAGE_REL_PPC_TOCREL14 0x0009 // 16-bit offset from TOC base, shifted left 2 (load doubleword)
  5993. #define IMAGE_REL_PPC_ADDR32NB 0x000A // 32-bit addr w/o image base
  5994. #define IMAGE_REL_PPC_SECREL 0x000B // va of containing section (as in an image sectionhdr)
  5995. #define IMAGE_REL_PPC_SECTION 0x000C // sectionheader number
  5996. #define IMAGE_REL_PPC_IFGLUE 0x000D // substitute TOC restore instruction iff symbol is glue code
  5997. #define IMAGE_REL_PPC_IMGLUE 0x000E // symbol is glue code; virtual address is TOC restore instruction
  5998. #define IMAGE_REL_PPC_SECREL16 0x000F // va of containing section (limited to 16 bits)
  5999. #define IMAGE_REL_PPC_REFHI 0x0010
  6000. #define IMAGE_REL_PPC_REFLO 0x0011
  6001. #define IMAGE_REL_PPC_PAIR 0x0012
  6002. #define IMAGE_REL_PPC_SECRELLO 0x0013 // Low 16-bit section relative reference (used for >32k TLS)
  6003. #define IMAGE_REL_PPC_SECRELHI 0x0014 // High 16-bit section relative reference (used for >32k TLS)
  6004. #define IMAGE_REL_PPC_GPREL 0x0015
  6005. #define IMAGE_REL_PPC_TOKEN 0x0016 // clr token
  6006. #define IMAGE_REL_PPC_TYPEMASK 0x00FF // mask to isolate above values in IMAGE_RELOCATION.Type
  6007. // Flag bits in IMAGE_RELOCATION.TYPE
  6008. #define IMAGE_REL_PPC_NEG 0x0100 // subtract reloc value rather than adding it
  6009. #define IMAGE_REL_PPC_BRTAKEN 0x0200 // fix branch prediction bit to predict branch taken
  6010. #define IMAGE_REL_PPC_BRNTAKEN 0x0400 // fix branch prediction bit to predict branch not taken
  6011. #define IMAGE_REL_PPC_TOCDEFN 0x0800 // toc slot defined in file (or, data in toc)
  6012. //
  6013. // Hitachi SH3 relocation types.
  6014. //
  6015. #define IMAGE_REL_SH3_ABSOLUTE 0x0000 // No relocation
  6016. #define IMAGE_REL_SH3_DIRECT16 0x0001 // 16 bit direct
  6017. #define IMAGE_REL_SH3_DIRECT32 0x0002 // 32 bit direct
  6018. #define IMAGE_REL_SH3_DIRECT8 0x0003 // 8 bit direct, -128..255
  6019. #define IMAGE_REL_SH3_DIRECT8_WORD 0x0004 // 8 bit direct .W (0 ext.)
  6020. #define IMAGE_REL_SH3_DIRECT8_LONG 0x0005 // 8 bit direct .L (0 ext.)
  6021. #define IMAGE_REL_SH3_DIRECT4 0x0006 // 4 bit direct (0 ext.)
  6022. #define IMAGE_REL_SH3_DIRECT4_WORD 0x0007 // 4 bit direct .W (0 ext.)
  6023. #define IMAGE_REL_SH3_DIRECT4_LONG 0x0008 // 4 bit direct .L (0 ext.)
  6024. #define IMAGE_REL_SH3_PCREL8_WORD 0x0009 // 8 bit PC relative .W
  6025. #define IMAGE_REL_SH3_PCREL8_LONG 0x000A // 8 bit PC relative .L
  6026. #define IMAGE_REL_SH3_PCREL12_WORD 0x000B // 12 LSB PC relative .W
  6027. #define IMAGE_REL_SH3_STARTOF_SECTION 0x000C // Start of EXE section
  6028. #define IMAGE_REL_SH3_SIZEOF_SECTION 0x000D // Size of EXE section
  6029. #define IMAGE_REL_SH3_SECTION 0x000E // Section table index
  6030. #define IMAGE_REL_SH3_SECREL 0x000F // Offset within section
  6031. #define IMAGE_REL_SH3_DIRECT32_NB 0x0010 // 32 bit direct not based
  6032. #define IMAGE_REL_SH3_GPREL4_LONG 0x0011 // GP-relative addressing
  6033. #define IMAGE_REL_SH3_TOKEN 0x0012 // clr token
  6034. #define IMAGE_REL_ARM_ABSOLUTE 0x0000 // No relocation required
  6035. #define IMAGE_REL_ARM_ADDR32 0x0001 // 32 bit address
  6036. #define IMAGE_REL_ARM_ADDR32NB 0x0002 // 32 bit address w/o image base
  6037. #define IMAGE_REL_ARM_BRANCH24 0x0003 // 24 bit offset << 2 & sign ext.
  6038. #define IMAGE_REL_ARM_BRANCH11 0x0004 // Thumb: 2 11 bit offsets
  6039. #define IMAGE_REL_ARM_TOKEN 0x0005 // clr token
  6040. #define IMAGE_REL_ARM_GPREL12 0x0006 // GP-relative addressing (ARM)
  6041. #define IMAGE_REL_ARM_GPREL7 0x0007 // GP-relative addressing (Thumb)
  6042. #define IMAGE_REL_ARM_BLX24 0x0008
  6043. #define IMAGE_REL_ARM_BLX11 0x0009
  6044. #define IMAGE_REL_ARM_SECTION 0x000E // Section table index
  6045. #define IMAGE_REL_ARM_SECREL 0x000F // Offset within section
  6046. #define IMAGE_REL_AM_ABSOLUTE 0x0000
  6047. #define IMAGE_REL_AM_ADDR32 0x0001
  6048. #define IMAGE_REL_AM_ADDR32NB 0x0002
  6049. #define IMAGE_REL_AM_CALL32 0x0003
  6050. #define IMAGE_REL_AM_FUNCINFO 0x0004
  6051. #define IMAGE_REL_AM_REL32_1 0x0005
  6052. #define IMAGE_REL_AM_REL32_2 0x0006
  6053. #define IMAGE_REL_AM_SECREL 0x0007
  6054. #define IMAGE_REL_AM_SECTION 0x0008
  6055. #define IMAGE_REL_AM_TOKEN 0x0009
  6056. //
  6057. // X86-64 relocations
  6058. //
  6059. #define IMAGE_REL_AMD64_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
  6060. #define IMAGE_REL_AMD64_ADDR64 0x0001 // 64-bit address (VA).
  6061. #define IMAGE_REL_AMD64_ADDR32 0x0002 // 32-bit address (VA).
  6062. #define IMAGE_REL_AMD64_ADDR32NB 0x0003 // 32-bit address w/o image base (RVA).
  6063. #define IMAGE_REL_AMD64_REL32 0x0004 // 32-bit relative address from byte following reloc
  6064. #define IMAGE_REL_AMD64_REL32_1 0x0005 // 32-bit relative address from byte distance 1 from reloc
  6065. #define IMAGE_REL_AMD64_REL32_2 0x0006 // 32-bit relative address from byte distance 2 from reloc
  6066. #define IMAGE_REL_AMD64_REL32_3 0x0007 // 32-bit relative address from byte distance 3 from reloc
  6067. #define IMAGE_REL_AMD64_REL32_4 0x0008 // 32-bit relative address from byte distance 4 from reloc
  6068. #define IMAGE_REL_AMD64_REL32_5 0x0009 // 32-bit relative address from byte distance 5 from reloc
  6069. #define IMAGE_REL_AMD64_SECTION 0x000A // Section index
  6070. #define IMAGE_REL_AMD64_SECREL 0x000B // 32 bit offset from base of section containing target
  6071. #define IMAGE_REL_AMD64_SECREL7 0x000C // 7 bit unsigned offset from base of section containing target
  6072. #define IMAGE_REL_AMD64_TOKEN 0x000D // 32 bit metadata token
  6073. #define IMAGE_REL_AMD64_SREL32 0x000E // 32 bit signed span-dependent value emitted into object
  6074. #define IMAGE_REL_AMD64_PAIR 0x000F
  6075. #define IMAGE_REL_AMD64_SSPAN32 0x0010 // 32 bit signed span-dependent value applied at link time
  6076. //
  6077. // IA64 relocation types.
  6078. //
  6079. #define IMAGE_REL_IA64_ABSOLUTE 0x0000
  6080. #define IMAGE_REL_IA64_IMM14 0x0001
  6081. #define IMAGE_REL_IA64_IMM22 0x0002
  6082. #define IMAGE_REL_IA64_IMM64 0x0003
  6083. #define IMAGE_REL_IA64_DIR32 0x0004
  6084. #define IMAGE_REL_IA64_DIR64 0x0005
  6085. #define IMAGE_REL_IA64_PCREL21B 0x0006
  6086. #define IMAGE_REL_IA64_PCREL21M 0x0007
  6087. #define IMAGE_REL_IA64_PCREL21F 0x0008
  6088. #define IMAGE_REL_IA64_GPREL22 0x0009
  6089. #define IMAGE_REL_IA64_LTOFF22 0x000A
  6090. #define IMAGE_REL_IA64_SECTION 0x000B
  6091. #define IMAGE_REL_IA64_SECREL22 0x000C
  6092. #define IMAGE_REL_IA64_SECREL64I 0x000D
  6093. #define IMAGE_REL_IA64_SECREL32 0x000E
  6094. //
  6095. #define IMAGE_REL_IA64_DIR32NB 0x0010
  6096. #define IMAGE_REL_IA64_SREL14 0x0011
  6097. #define IMAGE_REL_IA64_SREL22 0x0012
  6098. #define IMAGE_REL_IA64_SREL32 0x0013
  6099. #define IMAGE_REL_IA64_UREL32 0x0014
  6100. #define IMAGE_REL_IA64_PCREL60X 0x0015 // This is always a BRL and never converted
  6101. #define IMAGE_REL_IA64_PCREL60B 0x0016 // If possible, convert to MBB bundle with NOP.B in slot 1
  6102. #define IMAGE_REL_IA64_PCREL60F 0x0017 // If possible, convert to MFB bundle with NOP.F in slot 1
  6103. #define IMAGE_REL_IA64_PCREL60I 0x0018 // If possible, convert to MIB bundle with NOP.I in slot 1
  6104. #define IMAGE_REL_IA64_PCREL60M 0x0019 // If possible, convert to MMB bundle with NOP.M in slot 1
  6105. #define IMAGE_REL_IA64_IMMGPREL64 0x001A
  6106. #define IMAGE_REL_IA64_TOKEN 0x001B // clr token
  6107. #define IMAGE_REL_IA64_GPREL32 0x001C
  6108. #define IMAGE_REL_IA64_ADDEND 0x001F
  6109. //
  6110. // CEF relocation types.
  6111. //
  6112. #define IMAGE_REL_CEF_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
  6113. #define IMAGE_REL_CEF_ADDR32 0x0001 // 32-bit address (VA).
  6114. #define IMAGE_REL_CEF_ADDR64 0x0002 // 64-bit address (VA).
  6115. #define IMAGE_REL_CEF_ADDR32NB 0x0003 // 32-bit address w/o image base (RVA).
  6116. #define IMAGE_REL_CEF_SECTION 0x0004 // Section index
  6117. #define IMAGE_REL_CEF_SECREL 0x0005 // 32 bit offset from base of section containing target
  6118. #define IMAGE_REL_CEF_TOKEN 0x0006 // 32 bit metadata token
  6119. //
  6120. // clr relocation types.
  6121. //
  6122. #define IMAGE_REL_CEE_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
  6123. #define IMAGE_REL_CEE_ADDR32 0x0001 // 32-bit address (VA).
  6124. #define IMAGE_REL_CEE_ADDR64 0x0002 // 64-bit address (VA).
  6125. #define IMAGE_REL_CEE_ADDR32NB 0x0003 // 32-bit address w/o image base (RVA).
  6126. #define IMAGE_REL_CEE_SECTION 0x0004 // Section index
  6127. #define IMAGE_REL_CEE_SECREL 0x0005 // 32 bit offset from base of section containing target
  6128. #define IMAGE_REL_CEE_TOKEN 0x0006 // 32 bit metadata token
  6129. #define IMAGE_REL_M32R_ABSOLUTE 0x0000 // No relocation required
  6130. #define IMAGE_REL_M32R_ADDR32 0x0001 // 32 bit address
  6131. #define IMAGE_REL_M32R_ADDR32NB 0x0002 // 32 bit address w/o image base
  6132. #define IMAGE_REL_M32R_ADDR24 0x0003 // 24 bit address
  6133. #define IMAGE_REL_M32R_GPREL16 0x0004 // GP relative addressing
  6134. #define IMAGE_REL_M32R_PCREL24 0x0005 // 24 bit offset << 2 & sign ext.
  6135. #define IMAGE_REL_M32R_PCREL16 0x0006 // 16 bit offset << 2 & sign ext.
  6136. #define IMAGE_REL_M32R_PCREL8 0x0007 // 8 bit offset << 2 & sign ext.
  6137. #define IMAGE_REL_M32R_REFHALF 0x0008 // 16 MSBs
  6138. #define IMAGE_REL_M32R_REFHI 0x0009 // 16 MSBs; adj for LSB sign ext.
  6139. #define IMAGE_REL_M32R_REFLO 0x000A // 16 LSBs
  6140. #define IMAGE_REL_M32R_PAIR 0x000B // Link HI and LO
  6141. #define IMAGE_REL_M32R_SECTION 0x000C // Section table index
  6142. #define IMAGE_REL_M32R_SECREL32 0x000D // 32 bit section relative reference
  6143. #define IMAGE_REL_M32R_TOKEN 0x000E // clr token
  6144. #define EXT_IMM64(Value, Address, Size, InstPos, ValPos) /* Intel-IA64-Filler */ \
  6145. Value |= (((ULONGLONG)((*(Address) >> InstPos) & (((ULONGLONG)1 << Size) - 1))) << ValPos) // Intel-IA64-Filler
  6146. #define INS_IMM64(Value, Address, Size, InstPos, ValPos) /* Intel-IA64-Filler */\
  6147. *(PDWORD)Address = (*(PDWORD)Address & ~(((1 << Size) - 1) << InstPos)) | /* Intel-IA64-Filler */\
  6148. ((DWORD)((((ULONGLONG)Value >> ValPos) & (((ULONGLONG)1 << Size) - 1))) << InstPos) // Intel-IA64-Filler
  6149. #define EMARCH_ENC_I17_IMM7B_INST_WORD_X 3 // Intel-IA64-Filler
  6150. #define EMARCH_ENC_I17_IMM7B_SIZE_X 7 // Intel-IA64-Filler
  6151. #define EMARCH_ENC_I17_IMM7B_INST_WORD_POS_X 4 // Intel-IA64-Filler
  6152. #define EMARCH_ENC_I17_IMM7B_VAL_POS_X 0 // Intel-IA64-Filler
  6153. #define EMARCH_ENC_I17_IMM9D_INST_WORD_X 3 // Intel-IA64-Filler
  6154. #define EMARCH_ENC_I17_IMM9D_SIZE_X 9 // Intel-IA64-Filler
  6155. #define EMARCH_ENC_I17_IMM9D_INST_WORD_POS_X 18 // Intel-IA64-Filler
  6156. #define EMARCH_ENC_I17_IMM9D_VAL_POS_X 7 // Intel-IA64-Filler
  6157. #define EMARCH_ENC_I17_IMM5C_INST_WORD_X 3 // Intel-IA64-Filler
  6158. #define EMARCH_ENC_I17_IMM5C_SIZE_X 5 // Intel-IA64-Filler
  6159. #define EMARCH_ENC_I17_IMM5C_INST_WORD_POS_X 13 // Intel-IA64-Filler
  6160. #define EMARCH_ENC_I17_IMM5C_VAL_POS_X 16 // Intel-IA64-Filler
  6161. #define EMARCH_ENC_I17_IC_INST_WORD_X 3 // Intel-IA64-Filler
  6162. #define EMARCH_ENC_I17_IC_SIZE_X 1 // Intel-IA64-Filler
  6163. #define EMARCH_ENC_I17_IC_INST_WORD_POS_X 12 // Intel-IA64-Filler
  6164. #define EMARCH_ENC_I17_IC_VAL_POS_X 21 // Intel-IA64-Filler
  6165. #define EMARCH_ENC_I17_IMM41a_INST_WORD_X 1 // Intel-IA64-Filler
  6166. #define EMARCH_ENC_I17_IMM41a_SIZE_X 10 // Intel-IA64-Filler
  6167. #define EMARCH_ENC_I17_IMM41a_INST_WORD_POS_X 14 // Intel-IA64-Filler
  6168. #define EMARCH_ENC_I17_IMM41a_VAL_POS_X 22 // Intel-IA64-Filler
  6169. #define EMARCH_ENC_I17_IMM41b_INST_WORD_X 1 // Intel-IA64-Filler
  6170. #define EMARCH_ENC_I17_IMM41b_SIZE_X 8 // Intel-IA64-Filler
  6171. #define EMARCH_ENC_I17_IMM41b_INST_WORD_POS_X 24 // Intel-IA64-Filler
  6172. #define EMARCH_ENC_I17_IMM41b_VAL_POS_X 32 // Intel-IA64-Filler
  6173. #define EMARCH_ENC_I17_IMM41c_INST_WORD_X 2 // Intel-IA64-Filler
  6174. #define EMARCH_ENC_I17_IMM41c_SIZE_X 23 // Intel-IA64-Filler
  6175. #define EMARCH_ENC_I17_IMM41c_INST_WORD_POS_X 0 // Intel-IA64-Filler
  6176. #define EMARCH_ENC_I17_IMM41c_VAL_POS_X 40 // Intel-IA64-Filler
  6177. #define EMARCH_ENC_I17_SIGN_INST_WORD_X 3 // Intel-IA64-Filler
  6178. #define EMARCH_ENC_I17_SIGN_SIZE_X 1 // Intel-IA64-Filler
  6179. #define EMARCH_ENC_I17_SIGN_INST_WORD_POS_X 27 // Intel-IA64-Filler
  6180. #define EMARCH_ENC_I17_SIGN_VAL_POS_X 63 // Intel-IA64-Filler
  6181. //
  6182. // Line number format.
  6183. //
  6184. typedef struct _IMAGE_LINENUMBER {
  6185. union {
  6186. DWORD SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.
  6187. DWORD VirtualAddress; // Virtual address of line number.
  6188. } Type;
  6189. WORD Linenumber; // Line number.
  6190. } IMAGE_LINENUMBER;
  6191. typedef IMAGE_LINENUMBER UNALIGNED *PIMAGE_LINENUMBER;
  6192. #define IMAGE_SIZEOF_LINENUMBER 6
  6193. #ifndef _MAC
  6194. #include "poppack.h" // Back to 4 byte packing
  6195. #endif
  6196. //
  6197. // Based relocation format.
  6198. //
  6199. typedef struct _IMAGE_BASE_RELOCATION {
  6200. DWORD VirtualAddress;
  6201. DWORD SizeOfBlock;
  6202. // WORD TypeOffset[1];
  6203. } IMAGE_BASE_RELOCATION;
  6204. typedef IMAGE_BASE_RELOCATION UNALIGNED * PIMAGE_BASE_RELOCATION;
  6205. #define IMAGE_SIZEOF_BASE_RELOCATION 8
  6206. //
  6207. // Based relocation types.
  6208. //
  6209. #define IMAGE_REL_BASED_ABSOLUTE 0
  6210. #define IMAGE_REL_BASED_HIGH 1
  6211. #define IMAGE_REL_BASED_LOW 2
  6212. #define IMAGE_REL_BASED_HIGHLOW 3
  6213. #define IMAGE_REL_BASED_HIGHADJ 4
  6214. #define IMAGE_REL_BASED_MIPS_JMPADDR 5
  6215. #define IMAGE_REL_BASED_MIPS_JMPADDR16 9
  6216. #define IMAGE_REL_BASED_IA64_IMM64 9
  6217. #define IMAGE_REL_BASED_DIR64 10
  6218. //
  6219. // Archive format.
  6220. //
  6221. #define IMAGE_ARCHIVE_START_SIZE 8
  6222. #define IMAGE_ARCHIVE_START "!<arch>\n"
  6223. #define IMAGE_ARCHIVE_END "`\n"
  6224. #define IMAGE_ARCHIVE_PAD "\n"
  6225. #define IMAGE_ARCHIVE_LINKER_MEMBER "/ "
  6226. #define IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
  6227. typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
  6228. BYTE Name[16]; // File member name - `/' terminated.
  6229. BYTE Date[12]; // File member date - decimal.
  6230. BYTE UserID[6]; // File member user id - decimal.
  6231. BYTE GroupID[6]; // File member group id - decimal.
  6232. BYTE Mode[8]; // File member mode - octal.
  6233. BYTE Size[10]; // File member size - decimal.
  6234. BYTE EndHeader[2]; // String to end header.
  6235. } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
  6236. #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
  6237. //
  6238. // DLL support.
  6239. //
  6240. //
  6241. // Export Format
  6242. //
  6243. typedef struct _IMAGE_EXPORT_DIRECTORY {
  6244. DWORD Characteristics;
  6245. DWORD TimeDateStamp;
  6246. WORD MajorVersion;
  6247. WORD MinorVersion;
  6248. DWORD Name;
  6249. DWORD Base;
  6250. DWORD NumberOfFunctions;
  6251. DWORD NumberOfNames;
  6252. DWORD AddressOfFunctions; // RVA from base of image
  6253. DWORD AddressOfNames; // RVA from base of image
  6254. DWORD AddressOfNameOrdinals; // RVA from base of image
  6255. } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
  6256. //
  6257. // Import Format
  6258. //
  6259. typedef struct _IMAGE_IMPORT_BY_NAME {
  6260. WORD Hint;
  6261. BYTE Name[1];
  6262. } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
  6263. #include "pshpack8.h" // Use align 8 for the 64-bit IAT.
  6264. typedef struct _IMAGE_THUNK_DATA64 {
  6265. union {
  6266. ULONGLONG ForwarderString; // PBYTE
  6267. ULONGLONG Function; // PDWORD
  6268. ULONGLONG Ordinal;
  6269. ULONGLONG AddressOfData; // PIMAGE_IMPORT_BY_NAME
  6270. } u1;
  6271. } IMAGE_THUNK_DATA64;
  6272. typedef IMAGE_THUNK_DATA64 * PIMAGE_THUNK_DATA64;
  6273. #include "poppack.h" // Back to 4 byte packing
  6274. typedef struct _IMAGE_THUNK_DATA32 {
  6275. union {
  6276. DWORD ForwarderString; // PBYTE
  6277. DWORD Function; // PDWORD
  6278. DWORD Ordinal;
  6279. DWORD AddressOfData; // PIMAGE_IMPORT_BY_NAME
  6280. } u1;
  6281. } IMAGE_THUNK_DATA32;
  6282. typedef IMAGE_THUNK_DATA32 * PIMAGE_THUNK_DATA32;
  6283. #define IMAGE_ORDINAL_FLAG64 0x8000000000000000
  6284. #define IMAGE_ORDINAL_FLAG32 0x80000000
  6285. #define IMAGE_ORDINAL64(Ordinal) (Ordinal & 0xffff)
  6286. #define IMAGE_ORDINAL32(Ordinal) (Ordinal & 0xffff)
  6287. #define IMAGE_SNAP_BY_ORDINAL64(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG64) != 0)
  6288. #define IMAGE_SNAP_BY_ORDINAL32(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG32) != 0)
  6289. //
  6290. // Thread Local Storage
  6291. //
  6292. typedef VOID
  6293. (NTAPI *PIMAGE_TLS_CALLBACK) (
  6294. PVOID DllHandle,
  6295. DWORD Reason,
  6296. PVOID Reserved
  6297. );
  6298. typedef struct _IMAGE_TLS_DIRECTORY64 {
  6299. ULONGLONG StartAddressOfRawData;
  6300. ULONGLONG EndAddressOfRawData;
  6301. ULONGLONG AddressOfIndex; // PDWORD
  6302. ULONGLONG AddressOfCallBacks; // PIMAGE_TLS_CALLBACK *;
  6303. DWORD SizeOfZeroFill;
  6304. DWORD Characteristics;
  6305. } IMAGE_TLS_DIRECTORY64;
  6306. typedef IMAGE_TLS_DIRECTORY64 * PIMAGE_TLS_DIRECTORY64;
  6307. typedef struct _IMAGE_TLS_DIRECTORY32 {
  6308. DWORD StartAddressOfRawData;
  6309. DWORD EndAddressOfRawData;
  6310. DWORD AddressOfIndex; // PDWORD
  6311. DWORD AddressOfCallBacks; // PIMAGE_TLS_CALLBACK *
  6312. DWORD SizeOfZeroFill;
  6313. DWORD Characteristics;
  6314. } IMAGE_TLS_DIRECTORY32;
  6315. typedef IMAGE_TLS_DIRECTORY32 * PIMAGE_TLS_DIRECTORY32;
  6316. #ifdef _WIN64
  6317. #define IMAGE_ORDINAL_FLAG IMAGE_ORDINAL_FLAG64
  6318. #define IMAGE_ORDINAL(Ordinal) IMAGE_ORDINAL64(Ordinal)
  6319. typedef IMAGE_THUNK_DATA64 IMAGE_THUNK_DATA;
  6320. typedef PIMAGE_THUNK_DATA64 PIMAGE_THUNK_DATA;
  6321. #define IMAGE_SNAP_BY_ORDINAL(Ordinal) IMAGE_SNAP_BY_ORDINAL64(Ordinal)
  6322. typedef IMAGE_TLS_DIRECTORY64 IMAGE_TLS_DIRECTORY;
  6323. typedef PIMAGE_TLS_DIRECTORY64 PIMAGE_TLS_DIRECTORY;
  6324. #else
  6325. #define IMAGE_ORDINAL_FLAG IMAGE_ORDINAL_FLAG32
  6326. #define IMAGE_ORDINAL(Ordinal) IMAGE_ORDINAL32(Ordinal)
  6327. typedef IMAGE_THUNK_DATA32 IMAGE_THUNK_DATA;
  6328. typedef PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA;
  6329. #define IMAGE_SNAP_BY_ORDINAL(Ordinal) IMAGE_SNAP_BY_ORDINAL32(Ordinal)
  6330. typedef IMAGE_TLS_DIRECTORY32 IMAGE_TLS_DIRECTORY;
  6331. typedef PIMAGE_TLS_DIRECTORY32 PIMAGE_TLS_DIRECTORY;
  6332. #endif
  6333. typedef struct _IMAGE_IMPORT_DESCRIPTOR {
  6334. union {
  6335. DWORD Characteristics; // 0 for terminating null import descriptor
  6336. DWORD OriginalFirstThunk; // RVA to original unbound IAT (PIMAGE_THUNK_DATA)
  6337. };
  6338. DWORD TimeDateStamp; // 0 if not bound,
  6339. // -1 if bound, and real date\time stamp
  6340. // in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
  6341. // O.W. date/time stamp of DLL bound to (Old BIND)
  6342. DWORD ForwarderChain; // -1 if no forwarders
  6343. DWORD Name;
  6344. DWORD FirstThunk; // RVA to IAT (if bound this IAT has actual addresses)
  6345. } IMAGE_IMPORT_DESCRIPTOR;
  6346. typedef IMAGE_IMPORT_DESCRIPTOR UNALIGNED *PIMAGE_IMPORT_DESCRIPTOR;
  6347. //
  6348. // New format import descriptors pointed to by DataDirectory[ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT ]
  6349. //
  6350. typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR {
  6351. DWORD TimeDateStamp;
  6352. WORD OffsetModuleName;
  6353. WORD NumberOfModuleForwarderRefs;
  6354. // Array of zero or more IMAGE_BOUND_FORWARDER_REF follows
  6355. } IMAGE_BOUND_IMPORT_DESCRIPTOR, *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
  6356. typedef struct _IMAGE_BOUND_FORWARDER_REF {
  6357. DWORD TimeDateStamp;
  6358. WORD OffsetModuleName;
  6359. WORD Reserved;
  6360. } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
  6361. //
  6362. // Resource Format.
  6363. //
  6364. //
  6365. // Resource directory consists of two counts, following by a variable length
  6366. // array of directory entries. The first count is the number of entries at
  6367. // beginning of the array that have actual names associated with each entry.
  6368. // The entries are in ascending order, case insensitive strings. The second
  6369. // count is the number of entries that immediately follow the named entries.
  6370. // This second count identifies the number of entries that have 16-bit integer
  6371. // Ids as their name. These entries are also sorted in ascending order.
  6372. //
  6373. // This structure allows fast lookup by either name or number, but for any
  6374. // given resource entry only one form of lookup is supported, not both.
  6375. // This is consistant with the syntax of the .RC file and the .RES file.
  6376. //
  6377. typedef struct _IMAGE_RESOURCE_DIRECTORY {
  6378. DWORD Characteristics;
  6379. DWORD TimeDateStamp;
  6380. WORD MajorVersion;
  6381. WORD MinorVersion;
  6382. WORD NumberOfNamedEntries;
  6383. WORD NumberOfIdEntries;
  6384. // IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[];
  6385. } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
  6386. #define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
  6387. #define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
  6388. //
  6389. // Each directory contains the 32-bit Name of the entry and an offset,
  6390. // relative to the beginning of the resource directory of the data associated
  6391. // with this directory entry. If the name of the entry is an actual text
  6392. // string instead of an integer Id, then the high order bit of the name field
  6393. // is set to one and the low order 31-bits are an offset, relative to the
  6394. // beginning of the resource directory of the string, which is of type
  6395. // IMAGE_RESOURCE_DIRECTORY_STRING. Otherwise the high bit is clear and the
  6396. // low-order 16-bits are the integer Id that identify this resource directory
  6397. // entry. If the directory entry is yet another resource directory (i.e. a
  6398. // subdirectory), then the high order bit of the offset field will be
  6399. // set to indicate this. Otherwise the high bit is clear and the offset
  6400. // field points to a resource data entry.
  6401. //
  6402. typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
  6403. union {
  6404. struct {
  6405. DWORD NameOffset:31;
  6406. DWORD NameIsString:1;
  6407. };
  6408. DWORD Name;
  6409. WORD Id;
  6410. };
  6411. union {
  6412. DWORD OffsetToData;
  6413. struct {
  6414. DWORD OffsetToDirectory:31;
  6415. DWORD DataIsDirectory:1;
  6416. };
  6417. };
  6418. } IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
  6419. //
  6420. // For resource directory entries that have actual string names, the Name
  6421. // field of the directory entry points to an object of the following type.
  6422. // All of these string objects are stored together after the last resource
  6423. // directory entry and before the first resource data object. This minimizes
  6424. // the impact of these variable length objects on the alignment of the fixed
  6425. // size directory entry objects.
  6426. //
  6427. typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
  6428. WORD Length;
  6429. CHAR NameString[ 1 ];
  6430. } IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
  6431. typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
  6432. WORD Length;
  6433. WCHAR NameString[ 1 ];
  6434. } IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
  6435. //
  6436. // Each resource data entry describes a leaf node in the resource directory
  6437. // tree. It contains an offset, relative to the beginning of the resource
  6438. // directory of the data for the resource, a size field that gives the number
  6439. // of bytes of data at that offset, a CodePage that should be used when
  6440. // decoding code point values within the resource data. Typically for new
  6441. // applications the code page would be the unicode code page.
  6442. //
  6443. typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
  6444. DWORD OffsetToData;
  6445. DWORD Size;
  6446. DWORD CodePage;
  6447. DWORD Reserved;
  6448. } IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
  6449. //
  6450. // Load Configuration Directory Entry
  6451. //
  6452. typedef struct {
  6453. DWORD Size;
  6454. DWORD TimeDateStamp;
  6455. WORD MajorVersion;
  6456. WORD MinorVersion;
  6457. DWORD GlobalFlagsClear;
  6458. DWORD GlobalFlagsSet;
  6459. DWORD CriticalSectionDefaultTimeout;
  6460. DWORD DeCommitFreeBlockThreshold;
  6461. DWORD DeCommitTotalFreeThreshold;
  6462. DWORD LockPrefixTable; // VA
  6463. DWORD MaximumAllocationSize;
  6464. DWORD VirtualMemoryThreshold;
  6465. DWORD ProcessHeapFlags;
  6466. DWORD ProcessAffinityMask;
  6467. WORD CSDVersion;
  6468. WORD Reserved1;
  6469. DWORD EditList; // VA
  6470. DWORD SecurityCookie; // VA
  6471. DWORD SEHandlerTable; // VA
  6472. DWORD SEHandlerCount;
  6473. } IMAGE_LOAD_CONFIG_DIRECTORY32, *PIMAGE_LOAD_CONFIG_DIRECTORY32;
  6474. typedef struct {
  6475. DWORD Size;
  6476. DWORD TimeDateStamp;
  6477. WORD MajorVersion;
  6478. WORD MinorVersion;
  6479. DWORD GlobalFlagsClear;
  6480. DWORD GlobalFlagsSet;
  6481. DWORD CriticalSectionDefaultTimeout;
  6482. ULONGLONG DeCommitFreeBlockThreshold;
  6483. ULONGLONG DeCommitTotalFreeThreshold;
  6484. ULONGLONG LockPrefixTable; // VA
  6485. ULONGLONG MaximumAllocationSize;
  6486. ULONGLONG VirtualMemoryThreshold;
  6487. ULONGLONG ProcessAffinityMask;
  6488. DWORD ProcessHeapFlags;
  6489. WORD CSDVersion;
  6490. WORD Reserved1;
  6491. ULONGLONG EditList; // VA
  6492. ULONGLONG SecurityCookie; // VA
  6493. ULONGLONG SEHandlerTable; // VA
  6494. ULONGLONG SEHandlerCount;
  6495. } IMAGE_LOAD_CONFIG_DIRECTORY64, *PIMAGE_LOAD_CONFIG_DIRECTORY64;
  6496. #ifdef _WIN64
  6497. typedef IMAGE_LOAD_CONFIG_DIRECTORY64 IMAGE_LOAD_CONFIG_DIRECTORY;
  6498. typedef PIMAGE_LOAD_CONFIG_DIRECTORY64 PIMAGE_LOAD_CONFIG_DIRECTORY;
  6499. #else
  6500. typedef IMAGE_LOAD_CONFIG_DIRECTORY32 IMAGE_LOAD_CONFIG_DIRECTORY;
  6501. typedef PIMAGE_LOAD_CONFIG_DIRECTORY32 PIMAGE_LOAD_CONFIG_DIRECTORY;
  6502. #endif
  6503. //
  6504. // WIN CE Exception table format
  6505. //
  6506. //
  6507. // Function table entry format. Function table is pointed to by the
  6508. // IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
  6509. //
  6510. typedef struct _IMAGE_CE_RUNTIME_FUNCTION_ENTRY {
  6511. DWORD FuncStart;
  6512. DWORD PrologLen : 8;
  6513. DWORD FuncLen : 22;
  6514. DWORD ThirtyTwoBit : 1;
  6515. DWORD ExceptionFlag : 1;
  6516. } IMAGE_CE_RUNTIME_FUNCTION_ENTRY, * PIMAGE_CE_RUNTIME_FUNCTION_ENTRY;
  6517. typedef struct _IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY {
  6518. ULONGLONG BeginAddress;
  6519. ULONGLONG EndAddress;
  6520. ULONGLONG ExceptionHandler;
  6521. ULONGLONG HandlerData;
  6522. ULONGLONG PrologEndAddress;
  6523. } IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY, *PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY;
  6524. typedef struct _IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY {
  6525. DWORD BeginAddress;
  6526. DWORD EndAddress;
  6527. DWORD ExceptionHandler;
  6528. DWORD HandlerData;
  6529. DWORD PrologEndAddress;
  6530. } IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY, *PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY;
  6531. typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY {
  6532. DWORD BeginAddress;
  6533. DWORD EndAddress;
  6534. DWORD UnwindInfoAddress;
  6535. } _IMAGE_RUNTIME_FUNCTION_ENTRY, *_PIMAGE_RUNTIME_FUNCTION_ENTRY;
  6536. typedef _IMAGE_RUNTIME_FUNCTION_ENTRY IMAGE_IA64_RUNTIME_FUNCTION_ENTRY;
  6537. typedef _PIMAGE_RUNTIME_FUNCTION_ENTRY PIMAGE_IA64_RUNTIME_FUNCTION_ENTRY;
  6538. #if defined(_AXP64_)
  6539. typedef IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY IMAGE_AXP64_RUNTIME_FUNCTION_ENTRY;
  6540. typedef PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY PIMAGE_AXP64_RUNTIME_FUNCTION_ENTRY;
  6541. typedef IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY IMAGE_RUNTIME_FUNCTION_ENTRY;
  6542. typedef PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
  6543. #elif defined(_ALPHA_)
  6544. typedef IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY IMAGE_RUNTIME_FUNCTION_ENTRY;
  6545. typedef PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
  6546. #else
  6547. typedef _IMAGE_RUNTIME_FUNCTION_ENTRY IMAGE_RUNTIME_FUNCTION_ENTRY;
  6548. typedef _PIMAGE_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
  6549. #endif
  6550. //
  6551. // Debug Format
  6552. //
  6553. typedef struct _IMAGE_DEBUG_DIRECTORY {
  6554. DWORD Characteristics;
  6555. DWORD TimeDateStamp;
  6556. WORD MajorVersion;
  6557. WORD MinorVersion;
  6558. DWORD Type;
  6559. DWORD SizeOfData;
  6560. DWORD AddressOfRawData;
  6561. DWORD PointerToRawData;
  6562. } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
  6563. #define IMAGE_DEBUG_TYPE_UNKNOWN 0
  6564. #define IMAGE_DEBUG_TYPE_COFF 1
  6565. #define IMAGE_DEBUG_TYPE_CODEVIEW 2
  6566. #define IMAGE_DEBUG_TYPE_FPO 3
  6567. #define IMAGE_DEBUG_TYPE_MISC 4
  6568. #define IMAGE_DEBUG_TYPE_EXCEPTION 5
  6569. #define IMAGE_DEBUG_TYPE_FIXUP 6
  6570. #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
  6571. #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
  6572. #define IMAGE_DEBUG_TYPE_BORLAND 9
  6573. #define IMAGE_DEBUG_TYPE_RESERVED10 10
  6574. #define IMAGE_DEBUG_TYPE_CLSID 11
  6575. typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
  6576. DWORD NumberOfSymbols;
  6577. DWORD LvaToFirstSymbol;
  6578. DWORD NumberOfLinenumbers;
  6579. DWORD LvaToFirstLinenumber;
  6580. DWORD RvaToFirstByteOfCode;
  6581. DWORD RvaToLastByteOfCode;
  6582. DWORD RvaToFirstByteOfData;
  6583. DWORD RvaToLastByteOfData;
  6584. } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
  6585. #define FRAME_FPO 0
  6586. #define FRAME_TRAP 1
  6587. #define FRAME_TSS 2
  6588. #define FRAME_NONFPO 3
  6589. typedef struct _FPO_DATA {
  6590. DWORD ulOffStart; // offset 1st byte of function code
  6591. DWORD cbProcSize; // # bytes in function
  6592. DWORD cdwLocals; // # bytes in locals/4
  6593. WORD cdwParams; // # bytes in params/4
  6594. WORD cbProlog : 8; // # bytes in prolog
  6595. WORD cbRegs : 3; // # regs saved
  6596. WORD fHasSEH : 1; // TRUE if SEH in func
  6597. WORD fUseBP : 1; // TRUE if EBP has been allocated
  6598. WORD reserved : 1; // reserved for future use
  6599. WORD cbFrame : 2; // frame type
  6600. } FPO_DATA, *PFPO_DATA;
  6601. #define SIZEOF_RFPO_DATA 16
  6602. #define IMAGE_DEBUG_MISC_EXENAME 1
  6603. typedef struct _IMAGE_DEBUG_MISC {
  6604. DWORD DataType; // type of misc data, see defines
  6605. DWORD Length; // total length of record, rounded to four
  6606. // byte multiple.
  6607. BOOLEAN Unicode; // TRUE if data is unicode string
  6608. BYTE Reserved[ 3 ];
  6609. BYTE Data[ 1 ]; // Actual data
  6610. } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
  6611. //
  6612. // Function table extracted from MIPS/ALPHA/IA64 images. Does not contain
  6613. // information needed only for runtime support. Just those fields for
  6614. // each entry needed by a debugger.
  6615. //
  6616. typedef struct _IMAGE_FUNCTION_ENTRY {
  6617. DWORD StartingAddress;
  6618. DWORD EndingAddress;
  6619. DWORD EndOfPrologue;
  6620. } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
  6621. typedef struct _IMAGE_FUNCTION_ENTRY64 {
  6622. ULONGLONG StartingAddress;
  6623. ULONGLONG EndingAddress;
  6624. union {
  6625. ULONGLONG EndOfPrologue;
  6626. ULONGLONG UnwindInfoAddress;
  6627. };
  6628. } IMAGE_FUNCTION_ENTRY64, *PIMAGE_FUNCTION_ENTRY64;
  6629. //
  6630. // Debugging information can be stripped from an image file and placed
  6631. // in a separate .DBG file, whose file name part is the same as the
  6632. // image file name part (e.g. symbols for CMD.EXE could be stripped
  6633. // and placed in CMD.DBG). This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
  6634. // flag in the Characteristics field of the file header. The beginning of
  6635. // the .DBG file contains the following structure which captures certain
  6636. // information from the image file. This allows a debug to proceed even if
  6637. // the original image file is not accessable. This header is followed by
  6638. // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
  6639. // IMAGE_DEBUG_DIRECTORY structures. The latter structures and those in
  6640. // the image file contain file offsets relative to the beginning of the
  6641. // .DBG file.
  6642. //
  6643. // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
  6644. // is left in the image file, but not mapped. This allows a debugger to
  6645. // compute the name of the .DBG file, from the name of the image in the
  6646. // IMAGE_DEBUG_MISC structure.
  6647. //
  6648. typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
  6649. WORD Signature;
  6650. WORD Flags;
  6651. WORD Machine;
  6652. WORD Characteristics;
  6653. DWORD TimeDateStamp;
  6654. DWORD CheckSum;
  6655. DWORD ImageBase;
  6656. DWORD SizeOfImage;
  6657. DWORD NumberOfSections;
  6658. DWORD ExportedNamesSize;
  6659. DWORD DebugDirectorySize;
  6660. DWORD SectionAlignment;
  6661. DWORD Reserved[2];
  6662. } IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
  6663. typedef struct _NON_PAGED_DEBUG_INFO {
  6664. WORD Signature;
  6665. WORD Flags;
  6666. DWORD Size;
  6667. WORD Machine;
  6668. WORD Characteristics;
  6669. DWORD TimeDateStamp;
  6670. DWORD CheckSum;
  6671. DWORD SizeOfImage;
  6672. ULONGLONG ImageBase;
  6673. //DebugDirectorySize
  6674. //IMAGE_DEBUG_DIRECTORY
  6675. } NON_PAGED_DEBUG_INFO, *PNON_PAGED_DEBUG_INFO;
  6676. #ifndef _MAC
  6677. #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
  6678. #define NON_PAGED_DEBUG_SIGNATURE 0x494E
  6679. #else
  6680. #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4449 // DI
  6681. #define NON_PAGED_DEBUG_SIGNATURE 0x4E49 // NI
  6682. #endif
  6683. #define IMAGE_SEPARATE_DEBUG_FLAGS_MASK 0x8000
  6684. #define IMAGE_SEPARATE_DEBUG_MISMATCH 0x8000 // when DBG was updated, the
  6685. // old checksum didn't match.
  6686. //
  6687. // The .arch section is made up of headers, each describing an amask position/value
  6688. // pointing to an array of IMAGE_ARCHITECTURE_ENTRY's. Each "array" (both the header
  6689. // and entry arrays) are terminiated by a quadword of 0xffffffffL.
  6690. //
  6691. // NOTE: There may be quadwords of 0 sprinkled around and must be skipped.
  6692. //
  6693. typedef struct _ImageArchitectureHeader {
  6694. unsigned int AmaskValue: 1; // 1 -> code section depends on mask bit
  6695. // 0 -> new instruction depends on mask bit
  6696. int :7; // MBZ
  6697. unsigned int AmaskShift: 8; // Amask bit in question for this fixup
  6698. int :16; // MBZ
  6699. DWORD FirstEntryRVA; // RVA into .arch section to array of ARCHITECTURE_ENTRY's
  6700. } IMAGE_ARCHITECTURE_HEADER, *PIMAGE_ARCHITECTURE_HEADER;
  6701. typedef struct _ImageArchitectureEntry {
  6702. DWORD FixupInstRVA; // RVA of instruction to fixup
  6703. DWORD NewInst; // fixup instruction (see alphaops.h)
  6704. } IMAGE_ARCHITECTURE_ENTRY, *PIMAGE_ARCHITECTURE_ENTRY;
  6705. #include "poppack.h" // Back to the initial value
  6706. // The following structure defines the new import object. Note the values of the first two fields,
  6707. // which must be set as stated in order to differentiate old and new import members.
  6708. // Following this structure, the linker emits two null-terminated strings used to recreate the
  6709. // import at the time of use. The first string is the import's name, the second is the dll's name.
  6710. #define IMPORT_OBJECT_HDR_SIG2 0xffff
  6711. typedef struct IMPORT_OBJECT_HEADER {
  6712. WORD Sig1; // Must be IMAGE_FILE_MACHINE_UNKNOWN
  6713. WORD Sig2; // Must be IMPORT_OBJECT_HDR_SIG2.
  6714. WORD Version;
  6715. WORD Machine;
  6716. DWORD TimeDateStamp; // Time/date stamp
  6717. DWORD SizeOfData; // particularly useful for incremental links
  6718. union {
  6719. WORD Ordinal; // if grf & IMPORT_OBJECT_ORDINAL
  6720. WORD Hint;
  6721. };
  6722. WORD Type : 2; // IMPORT_TYPE
  6723. WORD NameType : 3; // IMPORT_NAME_TYPE
  6724. WORD Reserved : 11; // Reserved. Must be zero.
  6725. } IMPORT_OBJECT_HEADER;
  6726. typedef enum IMPORT_OBJECT_TYPE
  6727. {
  6728. IMPORT_OBJECT_CODE = 0,
  6729. IMPORT_OBJECT_DATA = 1,
  6730. IMPORT_OBJECT_CONST = 2,
  6731. } IMPORT_OBJECT_TYPE;
  6732. typedef enum IMPORT_OBJECT_NAME_TYPE
  6733. {
  6734. IMPORT_OBJECT_ORDINAL = 0, // Import by ordinal
  6735. IMPORT_OBJECT_NAME = 1, // Import name == public symbol name.
  6736. IMPORT_OBJECT_NAME_NO_PREFIX = 2, // Import name == public symbol name skipping leading ?, @, or optionally _.
  6737. IMPORT_OBJECT_NAME_UNDECORATE = 3, // Import name == public symbol name skipping leading ?, @, or optionally _
  6738. // and truncating at first @
  6739. } IMPORT_OBJECT_NAME_TYPE;
  6740. #ifndef __IMAGE_COR20_HEADER_DEFINED__
  6741. #define __IMAGE_COR20_HEADER_DEFINED__
  6742. typedef enum ReplacesCorHdrNumericDefines
  6743. {
  6744. // COM+ Header entry point flags.
  6745. COMIMAGE_FLAGS_ILONLY =0x00000001,
  6746. COMIMAGE_FLAGS_32BITREQUIRED =0x00000002,
  6747. COMIMAGE_FLAGS_IL_LIBRARY =0x00000004,
  6748. COMIMAGE_FLAGS_STRONGNAMESIGNED =0x00000008,
  6749. COMIMAGE_FLAGS_TRACKDEBUGDATA =0x00010000,
  6750. // Version flags for image.
  6751. COR_VERSION_MAJOR_V2 =2,
  6752. COR_VERSION_MAJOR =COR_VERSION_MAJOR_V2,
  6753. COR_VERSION_MINOR =0,
  6754. COR_DELETED_NAME_LENGTH =8,
  6755. COR_VTABLEGAP_NAME_LENGTH =8,
  6756. // Maximum size of a NativeType descriptor.
  6757. NATIVE_TYPE_MAX_CB =1,
  6758. COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE=0xFF,
  6759. // #defines for the MIH FLAGS
  6760. IMAGE_COR_MIH_METHODRVA =0x01,
  6761. IMAGE_COR_MIH_EHRVA =0x02,
  6762. IMAGE_COR_MIH_BASICBLOCK =0x08,
  6763. // V-table constants
  6764. COR_VTABLE_32BIT =0x01, // V-table slots are 32-bits in size.
  6765. COR_VTABLE_64BIT =0x02, // V-table slots are 64-bits in size.
  6766. COR_VTABLE_FROM_UNMANAGED =0x04, // If set, transition from unmanaged.
  6767. COR_VTABLE_CALL_MOST_DERIVED =0x10, // Call most derived method described by
  6768. // EATJ constants
  6769. IMAGE_COR_EATJ_THUNK_SIZE =32, // Size of a jump thunk reserved range.
  6770. // Max name lengths
  6771. //@todo: Change to unlimited name lengths.
  6772. MAX_CLASS_NAME =1024,
  6773. MAX_PACKAGE_NAME =1024,
  6774. } ReplacesCorHdrNumericDefines;
  6775. // COM+ 2.0 header structure.
  6776. typedef struct IMAGE_COR20_HEADER
  6777. {
  6778. // Header versioning
  6779. DWORD cb;
  6780. WORD MajorRuntimeVersion;
  6781. WORD MinorRuntimeVersion;
  6782. // Symbol table and startup information
  6783. IMAGE_DATA_DIRECTORY MetaData;
  6784. DWORD Flags;
  6785. DWORD EntryPointToken;
  6786. // Binding information
  6787. IMAGE_DATA_DIRECTORY Resources;
  6788. IMAGE_DATA_DIRECTORY StrongNameSignature;
  6789. // Regular fixup and binding information
  6790. IMAGE_DATA_DIRECTORY CodeManagerTable;
  6791. IMAGE_DATA_DIRECTORY VTableFixups;
  6792. IMAGE_DATA_DIRECTORY ExportAddressTableJumps;
  6793. // Precompiled image info (internal use only - set to zero)
  6794. IMAGE_DATA_DIRECTORY ManagedNativeHeader;
  6795. } IMAGE_COR20_HEADER, *PIMAGE_COR20_HEADER;
  6796. #endif // __IMAGE_COR20_HEADER_DEFINED__
  6797. //
  6798. // End Image Format
  6799. //
  6800. //
  6801. // for move macros
  6802. //
  6803. #ifdef _MAC
  6804. #ifndef _INC_STRING
  6805. #include <string.h>
  6806. #endif /* _INC_STRING */
  6807. #else
  6808. #include <string.h>
  6809. #endif // _MAC
  6810. #ifndef _SLIST_HEADER_
  6811. #define _SLIST_HEADER_
  6812. #if defined(_WIN64)
  6813. //
  6814. // The type SINGLE_LIST_ENTRY is not suitable for use with SLISTs. For
  6815. // WIN64, an entry on an SLIST is required to be 16-byte aligned, while a
  6816. // SINGLE_LIST_ENTRY structure has only 8 byte alignment.
  6817. //
  6818. // Therefore, all SLIST code should use the SLIST_ENTRY type instead of the
  6819. // SINGLE_LIST_ENTRY type.
  6820. //
  6821. #pragma warning(push)
  6822. #pragma warning(disable:4324) // structure padded due to align()
  6823. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
  6824. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
  6825. PSLIST_ENTRY Next;
  6826. } SLIST_ENTRY;
  6827. #pragma warning(pop)
  6828. #else
  6829. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  6830. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  6831. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  6832. #endif
  6833. #if defined(_WIN64)
  6834. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  6835. ULONGLONG Alignment;
  6836. ULONGLONG Region;
  6837. } SLIST_HEADER;
  6838. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  6839. #else
  6840. typedef union _SLIST_HEADER {
  6841. ULONGLONG Alignment;
  6842. struct {
  6843. SLIST_ENTRY Next;
  6844. WORD Depth;
  6845. WORD Sequence;
  6846. };
  6847. } SLIST_HEADER, *PSLIST_HEADER;
  6848. #endif
  6849. #endif
  6850. NTSYSAPI
  6851. VOID
  6852. NTAPI
  6853. RtlInitializeSListHead (
  6854. IN PSLIST_HEADER ListHead
  6855. );
  6856. NTSYSAPI
  6857. PSLIST_ENTRY
  6858. RtlFirstEntrySList (
  6859. IN const SLIST_HEADER *ListHead
  6860. );
  6861. NTSYSAPI
  6862. PSLIST_ENTRY
  6863. NTAPI
  6864. RtlInterlockedPopEntrySList (
  6865. IN PSLIST_HEADER ListHead
  6866. );
  6867. NTSYSAPI
  6868. PSLIST_ENTRY
  6869. NTAPI
  6870. RtlInterlockedPushEntrySList (
  6871. IN PSLIST_HEADER ListHead,
  6872. IN PSLIST_ENTRY ListEntry
  6873. );
  6874. NTSYSAPI
  6875. PSLIST_ENTRY
  6876. NTAPI
  6877. RtlInterlockedFlushSList (
  6878. IN PSLIST_HEADER ListHead
  6879. );
  6880. NTSYSAPI
  6881. WORD
  6882. NTAPI
  6883. RtlQueryDepthSList (
  6884. IN PSLIST_HEADER ListHead
  6885. );
  6886. #define HEAP_NO_SERIALIZE 0x00000001
  6887. #define HEAP_GROWABLE 0x00000002
  6888. #define HEAP_GENERATE_EXCEPTIONS 0x00000004
  6889. #define HEAP_ZERO_MEMORY 0x00000008
  6890. #define HEAP_REALLOC_IN_PLACE_ONLY 0x00000010
  6891. #define HEAP_TAIL_CHECKING_ENABLED 0x00000020
  6892. #define HEAP_FREE_CHECKING_ENABLED 0x00000040
  6893. #define HEAP_DISABLE_COALESCE_ON_FREE 0x00000080
  6894. #define HEAP_CREATE_ALIGN_16 0x00010000
  6895. #define HEAP_CREATE_ENABLE_TRACING 0x00020000
  6896. #define HEAP_MAXIMUM_TAG 0x0FFF
  6897. #define HEAP_PSEUDO_TAG_FLAG 0x8000
  6898. #define HEAP_TAG_SHIFT 18
  6899. #define HEAP_MAKE_TAG_FLAGS( b, o ) ((DWORD)((b) + ((o) << 18)))
  6900. NTSYSAPI
  6901. VOID
  6902. NTAPI
  6903. RtlCaptureContext (
  6904. OUT PCONTEXT ContextRecord
  6905. );
  6906. #define IS_TEXT_UNICODE_ASCII16 0x0001
  6907. #define IS_TEXT_UNICODE_REVERSE_ASCII16 0x0010
  6908. #define IS_TEXT_UNICODE_STATISTICS 0x0002
  6909. #define IS_TEXT_UNICODE_REVERSE_STATISTICS 0x0020
  6910. #define IS_TEXT_UNICODE_CONTROLS 0x0004
  6911. #define IS_TEXT_UNICODE_REVERSE_CONTROLS 0x0040
  6912. #define IS_TEXT_UNICODE_SIGNATURE 0x0008
  6913. #define IS_TEXT_UNICODE_REVERSE_SIGNATURE 0x0080
  6914. #define IS_TEXT_UNICODE_ILLEGAL_CHARS 0x0100
  6915. #define IS_TEXT_UNICODE_ODD_LENGTH 0x0200
  6916. #define IS_TEXT_UNICODE_DBCS_LEADBYTE 0x0400
  6917. #define IS_TEXT_UNICODE_NULL_BYTES 0x1000
  6918. #define IS_TEXT_UNICODE_UNICODE_MASK 0x000F
  6919. #define IS_TEXT_UNICODE_REVERSE_MASK 0x00F0
  6920. #define IS_TEXT_UNICODE_NOT_UNICODE_MASK 0x0F00
  6921. #define IS_TEXT_UNICODE_NOT_ASCII_MASK 0xF000
  6922. #define COMPRESSION_FORMAT_NONE (0x0000)
  6923. #define COMPRESSION_FORMAT_DEFAULT (0x0001)
  6924. #define COMPRESSION_FORMAT_LZNT1 (0x0002)
  6925. #define COMPRESSION_ENGINE_STANDARD (0x0000)
  6926. #define COMPRESSION_ENGINE_MAXIMUM (0x0100)
  6927. #define COMPRESSION_ENGINE_HIBER (0x0200)
  6928. NTSYSAPI
  6929. SIZE_T
  6930. NTAPI
  6931. RtlCompareMemory (
  6932. const VOID *Source1,
  6933. const VOID *Source2,
  6934. SIZE_T Length
  6935. );
  6936. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  6937. #if defined(_M_AMD64)
  6938. NTSYSAPI
  6939. VOID
  6940. NTAPI
  6941. RtlCopyMemory (
  6942. VOID UNALIGNED *Destination,
  6943. CONST VOID UNALIGNED *Source,
  6944. SIZE_T Length
  6945. );
  6946. NTSYSAPI
  6947. VOID
  6948. NTAPI
  6949. RtlMoveMemory (
  6950. VOID UNALIGNED *Destination,
  6951. CONST VOID UNALIGNED *Source,
  6952. SIZE_T Length
  6953. );
  6954. NTSYSAPI
  6955. VOID
  6956. NTAPI
  6957. RtlFillMemory (
  6958. VOID UNALIGNED *Destination,
  6959. SIZE_T Length,
  6960. IN BYTE Fill
  6961. );
  6962. NTSYSAPI
  6963. VOID
  6964. NTAPI
  6965. RtlZeroMemory (
  6966. VOID UNALIGNED *Destination,
  6967. SIZE_T Length
  6968. );
  6969. #else
  6970. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  6971. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  6972. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  6973. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  6974. #endif
  6975. #if !defined(MIDL_PASS)
  6976. FORCEINLINE
  6977. PVOID
  6978. RtlSecureZeroMemory(
  6979. IN PVOID ptr,
  6980. IN SIZE_T cnt
  6981. )
  6982. {
  6983. volatile char *vptr = (volatile char *)ptr;
  6984. while (cnt) {
  6985. *vptr = 0;
  6986. vptr++;
  6987. cnt--;
  6988. }
  6989. return ptr;
  6990. }
  6991. #endif
  6992. typedef struct _MESSAGE_RESOURCE_ENTRY {
  6993. WORD Length;
  6994. WORD Flags;
  6995. BYTE Text[ 1 ];
  6996. } MESSAGE_RESOURCE_ENTRY, *PMESSAGE_RESOURCE_ENTRY;
  6997. #define MESSAGE_RESOURCE_UNICODE 0x0001
  6998. typedef struct _MESSAGE_RESOURCE_BLOCK {
  6999. DWORD LowId;
  7000. DWORD HighId;
  7001. DWORD OffsetToEntries;
  7002. } MESSAGE_RESOURCE_BLOCK, *PMESSAGE_RESOURCE_BLOCK;
  7003. typedef struct _MESSAGE_RESOURCE_DATA {
  7004. DWORD NumberOfBlocks;
  7005. MESSAGE_RESOURCE_BLOCK Blocks[ 1 ];
  7006. } MESSAGE_RESOURCE_DATA, *PMESSAGE_RESOURCE_DATA;
  7007. typedef struct _OSVERSIONINFOA {
  7008. DWORD dwOSVersionInfoSize;
  7009. DWORD dwMajorVersion;
  7010. DWORD dwMinorVersion;
  7011. DWORD dwBuildNumber;
  7012. DWORD dwPlatformId;
  7013. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  7014. } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
  7015. typedef struct _OSVERSIONINFOW {
  7016. DWORD dwOSVersionInfoSize;
  7017. DWORD dwMajorVersion;
  7018. DWORD dwMinorVersion;
  7019. DWORD dwBuildNumber;
  7020. DWORD dwPlatformId;
  7021. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  7022. } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;
  7023. #ifdef UNICODE
  7024. typedef OSVERSIONINFOW OSVERSIONINFO;
  7025. typedef POSVERSIONINFOW POSVERSIONINFO;
  7026. typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
  7027. #else
  7028. typedef OSVERSIONINFOA OSVERSIONINFO;
  7029. typedef POSVERSIONINFOA POSVERSIONINFO;
  7030. typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
  7031. #endif // UNICODE
  7032. typedef struct _OSVERSIONINFOEXA {
  7033. DWORD dwOSVersionInfoSize;
  7034. DWORD dwMajorVersion;
  7035. DWORD dwMinorVersion;
  7036. DWORD dwBuildNumber;
  7037. DWORD dwPlatformId;
  7038. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  7039. WORD wServicePackMajor;
  7040. WORD wServicePackMinor;
  7041. WORD wSuiteMask;
  7042. BYTE wProductType;
  7043. BYTE wReserved;
  7044. } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
  7045. typedef struct _OSVERSIONINFOEXW {
  7046. DWORD dwOSVersionInfoSize;
  7047. DWORD dwMajorVersion;
  7048. DWORD dwMinorVersion;
  7049. DWORD dwBuildNumber;
  7050. DWORD dwPlatformId;
  7051. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  7052. WORD wServicePackMajor;
  7053. WORD wServicePackMinor;
  7054. WORD wSuiteMask;
  7055. BYTE wProductType;
  7056. BYTE wReserved;
  7057. } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW, RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
  7058. #ifdef UNICODE
  7059. typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
  7060. typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
  7061. typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
  7062. #else
  7063. typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
  7064. typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
  7065. typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
  7066. #endif // UNICODE
  7067. //
  7068. // RtlVerifyVersionInfo() conditions
  7069. //
  7070. #define VER_EQUAL 1
  7071. #define VER_GREATER 2
  7072. #define VER_GREATER_EQUAL 3
  7073. #define VER_LESS 4
  7074. #define VER_LESS_EQUAL 5
  7075. #define VER_AND 6
  7076. #define VER_OR 7
  7077. #define VER_CONDITION_MASK 7
  7078. #define VER_NUM_BITS_PER_CONDITION_MASK 3
  7079. //
  7080. // RtlVerifyVersionInfo() type mask bits
  7081. //
  7082. #define VER_MINORVERSION 0x0000001
  7083. #define VER_MAJORVERSION 0x0000002
  7084. #define VER_BUILDNUMBER 0x0000004
  7085. #define VER_PLATFORMID 0x0000008
  7086. #define VER_SERVICEPACKMINOR 0x0000010
  7087. #define VER_SERVICEPACKMAJOR 0x0000020
  7088. #define VER_SUITENAME 0x0000040
  7089. #define VER_PRODUCT_TYPE 0x0000080
  7090. //
  7091. // RtlVerifyVersionInfo() os product type values
  7092. //
  7093. #define VER_NT_WORKSTATION 0x0000001
  7094. #define VER_NT_DOMAIN_CONTROLLER 0x0000002
  7095. #define VER_NT_SERVER 0x0000003
  7096. //
  7097. // dwPlatformId defines:
  7098. //
  7099. #define VER_PLATFORM_WIN32s 0
  7100. #define VER_PLATFORM_WIN32_WINDOWS 1
  7101. #define VER_PLATFORM_WIN32_NT 2
  7102. //
  7103. //
  7104. // VerifyVersionInfo() macro to set the condition mask
  7105. //
  7106. // For documentation sakes here's the old version of the macro that got
  7107. // changed to call an API
  7108. // #define VER_SET_CONDITION(_m_,_t_,_c_) _m_=(_m_|(_c_<<(1<<_t_)))
  7109. //
  7110. #define VER_SET_CONDITION(_m_,_t_,_c_) \
  7111. ((_m_)=VerSetConditionMask((_m_),(_t_),(_c_)))
  7112. ULONGLONG
  7113. NTAPI
  7114. VerSetConditionMask(
  7115. IN ULONGLONG ConditionMask,
  7116. IN DWORD TypeMask,
  7117. IN BYTE Condition
  7118. );
  7119. //
  7120. typedef struct _RTL_CRITICAL_SECTION_DEBUG {
  7121. WORD Type;
  7122. WORD CreatorBackTraceIndex;
  7123. struct _RTL_CRITICAL_SECTION *CriticalSection;
  7124. LIST_ENTRY ProcessLocksList;
  7125. DWORD EntryCount;
  7126. DWORD ContentionCount;
  7127. DWORD Spare[ 2 ];
  7128. } RTL_CRITICAL_SECTION_DEBUG, *PRTL_CRITICAL_SECTION_DEBUG, RTL_RESOURCE_DEBUG, *PRTL_RESOURCE_DEBUG;
  7129. #define RTL_CRITSECT_TYPE 0
  7130. #define RTL_RESOURCE_TYPE 1
  7131. typedef struct _RTL_CRITICAL_SECTION {
  7132. PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
  7133. //
  7134. // The following three fields control entering and exiting the critical
  7135. // section for the resource
  7136. //
  7137. LONG LockCount;
  7138. LONG RecursionCount;
  7139. HANDLE OwningThread; // from the thread's ClientId->UniqueThread
  7140. HANDLE LockSemaphore;
  7141. ULONG_PTR SpinCount; // force size on 64-bit systems when packed
  7142. } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
  7143. typedef VOID (NTAPI * RTL_VERIFIER_DLL_LOAD_CALLBACK) (
  7144. PWSTR DllName,
  7145. PVOID DllBase,
  7146. SIZE_T DllSize,
  7147. PVOID Reserved
  7148. );
  7149. typedef VOID (NTAPI * RTL_VERIFIER_DLL_UNLOAD_CALLBACK) (
  7150. PWSTR DllName,
  7151. PVOID DllBase,
  7152. SIZE_T DllSize,
  7153. PVOID Reserved
  7154. );
  7155. typedef VOID (NTAPI * RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK) (
  7156. PVOID AllocationBase,
  7157. SIZE_T AllocationSize
  7158. );
  7159. typedef struct _RTL_VERIFIER_THUNK_DESCRIPTOR {
  7160. PCHAR ThunkName;
  7161. PVOID ThunkOldAddress;
  7162. PVOID ThunkNewAddress;
  7163. } RTL_VERIFIER_THUNK_DESCRIPTOR, *PRTL_VERIFIER_THUNK_DESCRIPTOR;
  7164. typedef struct _RTL_VERIFIER_DLL_DESCRIPTOR {
  7165. PWCHAR DllName;
  7166. DWORD DllFlags;
  7167. PVOID DllAddress;
  7168. PRTL_VERIFIER_THUNK_DESCRIPTOR DllThunks;
  7169. } RTL_VERIFIER_DLL_DESCRIPTOR, *PRTL_VERIFIER_DLL_DESCRIPTOR;
  7170. typedef struct _RTL_VERIFIER_PROVIDER_DESCRIPTOR {
  7171. //
  7172. // Filled by verifier provider DLL
  7173. //
  7174. DWORD Length;
  7175. PRTL_VERIFIER_DLL_DESCRIPTOR ProviderDlls;
  7176. RTL_VERIFIER_DLL_LOAD_CALLBACK ProviderDllLoadCallback;
  7177. RTL_VERIFIER_DLL_UNLOAD_CALLBACK ProviderDllUnloadCallback;
  7178. //
  7179. // Filled by verifier engine
  7180. //
  7181. PWSTR VerifierImage;
  7182. DWORD VerifierFlags;
  7183. DWORD VerifierDebug;
  7184. PVOID RtlpGetStackTraceAddress;
  7185. PVOID RtlpDebugPageHeapCreate;
  7186. PVOID RtlpDebugPageHeapDestroy;
  7187. //
  7188. // Filled by verifier provider DLL
  7189. //
  7190. RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK ProviderNtdllHeapFreeCallback;
  7191. } RTL_VERIFIER_PROVIDER_DESCRIPTOR, *PRTL_VERIFIER_PROVIDER_DESCRIPTOR;
  7192. //
  7193. // Application verifier standard flags
  7194. //
  7195. #define RTL_VRF_FLG_FULL_PAGE_HEAP 0x00000001
  7196. #define RTL_VRF_FLG_RESERVED_DONOTUSE 0x00000002 // old RTL_VRF_FLG_LOCK_CHECKS
  7197. #define RTL_VRF_FLG_HANDLE_CHECKS 0x00000004
  7198. #define RTL_VRF_FLG_STACK_CHECKS 0x00000008
  7199. #define RTL_VRF_FLG_APPCOMPAT_CHECKS 0x00000010
  7200. #define RTL_VRF_FLG_TLS_CHECKS 0x00000020
  7201. #define RTL_VRF_FLG_DIRTY_STACKS 0x00000040
  7202. #define RTL_VRF_FLG_RPC_CHECKS 0x00000080
  7203. #define RTL_VRF_FLG_COM_CHECKS 0x00000100
  7204. #define RTL_VRF_FLG_DANGEROUS_APIS 0x00000200
  7205. #define RTL_VRF_FLG_RACE_CHECKS 0x00000400
  7206. #define RTL_VRF_FLG_DEADLOCK_CHECKS 0x00000800
  7207. #define RTL_VRF_FLG_FIRST_CHANCE_EXCEPTION_CHECKS 0x00001000
  7208. #define RTL_VRF_FLG_VIRTUAL_MEM_CHECKS 0x00002000
  7209. #define RTL_VRF_FLG_ENABLE_LOGGING 0x00004000
  7210. #define RTL_VRF_FLG_FAST_FILL_HEAP 0x00008000
  7211. #define RTL_VRF_FLG_VIRTUAL_SPACE_TRACKING 0x00010000
  7212. #define RTL_VRF_FLG_ENABLED_SYSTEM_WIDE 0x00020000
  7213. #define RTL_VRF_FLG_MISCELLANEOUS_CHECKS 0x00020000
  7214. #define RTL_VRF_FLG_LOCK_CHECKS 0x00040000
  7215. //
  7216. // Application verifier standard stop codes
  7217. //
  7218. #define APPLICATION_VERIFIER_INTERNAL_ERROR 0x80000000
  7219. #define APPLICATION_VERIFIER_INTERNAL_WARNING 0x40000000
  7220. #define APPLICATION_VERIFIER_NO_BREAK 0x20000000
  7221. #define APPLICATION_VERIFIER_CONTINUABLE_BREAK 0x10000000
  7222. #define APPLICATION_VERIFIER_UNKNOWN_ERROR 0x0001
  7223. #define APPLICATION_VERIFIER_ACCESS_VIOLATION 0x0002
  7224. #define APPLICATION_VERIFIER_UNSYNCHRONIZED_ACCESS 0x0003
  7225. #define APPLICATION_VERIFIER_EXTREME_SIZE_REQUEST 0x0004
  7226. #define APPLICATION_VERIFIER_BAD_HEAP_HANDLE 0x0005
  7227. #define APPLICATION_VERIFIER_SWITCHED_HEAP_HANDLE 0x0006
  7228. #define APPLICATION_VERIFIER_DOUBLE_FREE 0x0007
  7229. #define APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK 0x0008
  7230. #define APPLICATION_VERIFIER_DESTROY_PROCESS_HEAP 0x0009
  7231. #define APPLICATION_VERIFIER_UNEXPECTED_EXCEPTION 0x000A
  7232. #define APPLICATION_VERIFIER_STACK_OVERFLOW 0x000B
  7233. #define APPLICATION_VERIFIER_TERMINATE_THREAD_CALL 0x0100
  7234. #define APPLICATION_VERIFIER_INVALID_EXIT_PROCESS_CALL 0x0101
  7235. #define APPLICATION_VERIFIER_EXIT_THREAD_OWNS_LOCK 0x0200
  7236. #define APPLICATION_VERIFIER_LOCK_IN_UNLOADED_DLL 0x0201
  7237. #define APPLICATION_VERIFIER_LOCK_IN_FREED_HEAP 0x0202
  7238. #define APPLICATION_VERIFIER_LOCK_DOUBLE_INITIALIZE 0x0203
  7239. #define APPLICATION_VERIFIER_LOCK_IN_FREED_MEMORY 0x0204
  7240. #define APPLICATION_VERIFIER_LOCK_CORRUPTED 0x0205
  7241. #define APPLICATION_VERIFIER_LOCK_INVALID_OWNER 0x0206
  7242. #define APPLICATION_VERIFIER_LOCK_INVALID_RECURSION_COUNT 0x0207
  7243. #define APPLICATION_VERIFIER_LOCK_INVALID_LOCK_COUNT 0x0208
  7244. #define APPLICATION_VERIFIER_LOCK_OVER_RELEASED 0x0209
  7245. #define APPLICATION_VERIFIER_LOCK_NOT_INITIALIZED 0x0210
  7246. #define APPLICATION_VERIFIER_LOCK_ALREADY_INITIALIZED 0x0211
  7247. #define APPLICATION_VERIFIER_INVALID_HANDLE 0x0300
  7248. #define APPLICATION_VERIFIER_INVALID_TLS_VALUE 0x0301
  7249. #define APPLICATION_VERIFIER_INCORRECT_WAIT_CALL 0x0302
  7250. #define APPLICATION_VERIFIER_NULL_HANDLE 0x0303
  7251. #define APPLICATION_VERIFIER_WAIT_IN_DLLMAIN 0x0304
  7252. #define APPLICATION_VERIFIER_COM_ERROR 0x0400
  7253. #define APPLICATION_VERIFIER_COM_API_IN_DLLMAIN 0x0401
  7254. #define APPLICATION_VERIFIER_COM_UNHANDLED_EXCEPTION 0x0402
  7255. #define APPLICATION_VERIFIER_COM_UNBALANCED_COINIT 0x0403
  7256. #define APPLICATION_VERIFIER_COM_UNBALANCED_OLEINIT 0x0404
  7257. #define APPLICATION_VERIFIER_COM_UNBALANCED_SWC 0x0405
  7258. #define APPLICATION_VERIFIER_COM_NULL_DACL 0x0406
  7259. #define APPLICATION_VERIFIER_COM_UNSAFE_IMPERSONATION 0x0407
  7260. #define APPLICATION_VERIFIER_COM_SMUGGLED_WRAPPER 0x0408
  7261. #define APPLICATION_VERIFIER_COM_SMUGGLED_PROXY 0x0409
  7262. #define APPLICATION_VERIFIER_COM_CF_SUCCESS_WITH_NULL 0x040A
  7263. #define APPLICATION_VERIFIER_COM_GCO_SUCCESS_WITH_NULL 0x040B
  7264. #define APPLICATION_VERIFIER_COM_OBJECT_IN_FREED_MEMORY 0x040C
  7265. #define APPLICATION_VERIFIER_COM_OBJECT_IN_UNLOADED_DLL 0x040D
  7266. #define APPLICATION_VERIFIER_COM_VTBL_IN_FREED_MEMORY 0x040E
  7267. #define APPLICATION_VERIFIER_COM_VTBL_IN_UNLOADED_DLL 0x040F
  7268. #define APPLICATION_VERIFIER_COM_HOLDING_LOCKS_ON_CALL 0x0410
  7269. #define APPLICATION_VERIFIER_RPC_ERROR 0x0500
  7270. #define APPLICATION_VERIFIER_INVALID_FREEMEM 0x0600
  7271. #define APPLICATION_VERIFIER_INVALID_ALLOCMEM 0x0601
  7272. #define APPLICATION_VERIFIER_INVALID_MAPVIEW 0x0602
  7273. #define APPLICATION_VERIFIER_PROBE_INVALID_ADDRESS 0x0603
  7274. #define APPLICATION_VERIFIER_PROBE_FREE_MEM 0x0604
  7275. #define APPLICATION_VERIFIER_PROBE_GUARD_PAGE 0x0605
  7276. #define APPLICATION_VERIFIER_PROBE_NULL 0x0606
  7277. #define APPLICATION_VERIFIER_PROBE_INVALID_START_OR_SIZE 0x0607
  7278. #define VERIFIER_STOP(Code, Msg, P1, S1, P2, S2, P3, S3, P4, S4) { \
  7279. RtlApplicationVerifierStop ((Code), \
  7280. (Msg), \
  7281. (ULONG_PTR)(P1),(S1), \
  7282. (ULONG_PTR)(P2),(S2), \
  7283. (ULONG_PTR)(P3),(S3), \
  7284. (ULONG_PTR)(P4),(S4)); \
  7285. }
  7286. VOID
  7287. NTAPI
  7288. RtlApplicationVerifierStop (
  7289. ULONG_PTR Code,
  7290. PCHAR Message,
  7291. ULONG_PTR Param1, PCHAR Description1,
  7292. ULONG_PTR Param2, PCHAR Description2,
  7293. ULONG_PTR Param3, PCHAR Description3,
  7294. ULONG_PTR Param4, PCHAR Description4
  7295. );
  7296. typedef LONG (NTAPI *PVECTORED_EXCEPTION_HANDLER)(
  7297. struct _EXCEPTION_POINTERS *ExceptionInfo
  7298. );
  7299. #define SEF_DACL_AUTO_INHERIT 0x01
  7300. #define SEF_SACL_AUTO_INHERIT 0x02
  7301. #define SEF_DEFAULT_DESCRIPTOR_FOR_OBJECT 0x04
  7302. #define SEF_AVOID_PRIVILEGE_CHECK 0x08
  7303. #define SEF_AVOID_OWNER_CHECK 0x10
  7304. #define SEF_DEFAULT_OWNER_FROM_PARENT 0x20
  7305. #define SEF_DEFAULT_GROUP_FROM_PARENT 0x40
  7306. typedef enum _HEAP_INFORMATION_CLASS {
  7307. HeapCompatibilityInformation
  7308. } HEAP_INFORMATION_CLASS;
  7309. DWORD
  7310. NTAPI
  7311. RtlSetHeapInformation (
  7312. IN PVOID HeapHandle,
  7313. IN HEAP_INFORMATION_CLASS HeapInformationClass,
  7314. IN PVOID HeapInformation OPTIONAL,
  7315. IN SIZE_T HeapInformationLength OPTIONAL
  7316. );
  7317. DWORD
  7318. NTAPI
  7319. RtlQueryHeapInformation (
  7320. IN PVOID HeapHandle,
  7321. IN HEAP_INFORMATION_CLASS HeapInformationClass,
  7322. OUT PVOID HeapInformation OPTIONAL,
  7323. IN SIZE_T HeapInformationLength OPTIONAL,
  7324. OUT PSIZE_T ReturnLength OPTIONAL
  7325. );
  7326. //
  7327. // Multiple alloc-free APIS
  7328. //
  7329. DWORD
  7330. NTAPI
  7331. RtlMultipleAllocateHeap (
  7332. IN PVOID HeapHandle,
  7333. IN DWORD Flags,
  7334. IN SIZE_T Size,
  7335. IN DWORD Count,
  7336. OUT PVOID * Array
  7337. );
  7338. DWORD
  7339. NTAPI
  7340. RtlMultipleFreeHeap (
  7341. IN PVOID HeapHandle,
  7342. IN DWORD Flags,
  7343. IN DWORD Count,
  7344. OUT PVOID * Array
  7345. );
  7346. #define WT_EXECUTEDEFAULT 0x00000000
  7347. #define WT_EXECUTEINIOTHREAD 0x00000001
  7348. #define WT_EXECUTEINUITHREAD 0x00000002
  7349. #define WT_EXECUTEINWAITTHREAD 0x00000004
  7350. #define WT_EXECUTEONLYONCE 0x00000008
  7351. #define WT_EXECUTEINTIMERTHREAD 0x00000020
  7352. #define WT_EXECUTELONGFUNCTION 0x00000010
  7353. #define WT_EXECUTEINPERSISTENTIOTHREAD 0x00000040
  7354. #define WT_EXECUTEINPERSISTENTTHREAD 0x00000080
  7355. #define WT_TRANSFER_IMPERSONATION 0x00000100
  7356. #define WT_SET_MAX_THREADPOOL_THREADS(Flags, Limit) ((Flags) |= (Limit)<<16)
  7357. typedef VOID (NTAPI * WAITORTIMERCALLBACKFUNC) (PVOID, BOOLEAN );
  7358. typedef VOID (NTAPI * WORKERCALLBACKFUNC) (PVOID );
  7359. typedef VOID (NTAPI * APC_CALLBACK_FUNCTION) (DWORD , PVOID, PVOID);
  7360. #define WT_EXECUTEINLONGTHREAD 0x00000010
  7361. #define WT_EXECUTEDELETEWAIT 0x00000008
  7362. typedef enum _ACTIVATION_CONTEXT_INFO_CLASS {
  7363. ActivationContextBasicInformation = 1,
  7364. ActivationContextDetailedInformation = 2,
  7365. AssemblyDetailedInformationInActivationContext = 3,
  7366. FileInformationInAssemblyOfAssemblyInActivationContext = 4,
  7367. MaxActivationContextInfoClass,
  7368. //
  7369. // compatibility with old names
  7370. //
  7371. AssemblyDetailedInformationInActivationContxt = 3,
  7372. FileInformationInAssemblyOfAssemblyInActivationContxt = 4
  7373. } ACTIVATION_CONTEXT_INFO_CLASS;
  7374. #define ACTIVATIONCONTEXTINFOCLASS ACTIVATION_CONTEXT_INFO_CLASS
  7375. typedef struct _ACTIVATION_CONTEXT_QUERY_INDEX {
  7376. DWORD ulAssemblyIndex;
  7377. DWORD ulFileIndexInAssembly;
  7378. } ACTIVATION_CONTEXT_QUERY_INDEX, * PACTIVATION_CONTEXT_QUERY_INDEX;
  7379. typedef const struct _ACTIVATION_CONTEXT_QUERY_INDEX * PCACTIVATION_CONTEXT_QUERY_INDEX;
  7380. #define ACTIVATION_CONTEXT_PATH_TYPE_NONE (1)
  7381. #define ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE (2)
  7382. #define ACTIVATION_CONTEXT_PATH_TYPE_URL (3)
  7383. #define ACTIVATION_CONTEXT_PATH_TYPE_ASSEMBLYREF (4)
  7384. typedef struct _ASSEMBLY_FILE_DETAILED_INFORMATION {
  7385. DWORD ulFlags;
  7386. DWORD ulFilenameLength;
  7387. DWORD ulPathLength;
  7388. PCWSTR lpFileName;
  7389. PCWSTR lpFilePath;
  7390. } ASSEMBLY_FILE_DETAILED_INFORMATION, *PASSEMBLY_FILE_DETAILED_INFORMATION;
  7391. typedef const ASSEMBLY_FILE_DETAILED_INFORMATION *PCASSEMBLY_FILE_DETAILED_INFORMATION;
  7392. //
  7393. // compatibility with old names
  7394. // The new names use "file" consistently.
  7395. //
  7396. #define _ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION _ASSEMBLY_FILE_DETAILED_INFORMATION
  7397. #define ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION ASSEMBLY_FILE_DETAILED_INFORMATION
  7398. #define PASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION PASSEMBLY_FILE_DETAILED_INFORMATION
  7399. #define PCASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION PCASSEMBLY_FILE_DETAILED_INFORMATION
  7400. typedef struct _ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION {
  7401. DWORD ulFlags;
  7402. DWORD ulEncodedAssemblyIdentityLength; // in bytes
  7403. DWORD ulManifestPathType; // ACTIVATION_CONTEXT_PATH_TYPE_*
  7404. DWORD ulManifestPathLength; // in bytes
  7405. LARGE_INTEGER liManifestLastWriteTime; // FILETIME
  7406. DWORD ulPolicyPathType; // ACTIVATION_CONTEXT_PATH_TYPE_*
  7407. DWORD ulPolicyPathLength; // in bytes
  7408. LARGE_INTEGER liPolicyLastWriteTime; // FILETIME
  7409. DWORD ulMetadataSatelliteRosterIndex;
  7410. DWORD ulManifestVersionMajor; // 1
  7411. DWORD ulManifestVersionMinor; // 0
  7412. DWORD ulPolicyVersionMajor; // 0
  7413. DWORD ulPolicyVersionMinor; // 0
  7414. DWORD ulAssemblyDirectoryNameLength; // in bytes
  7415. PCWSTR lpAssemblyEncodedAssemblyIdentity;
  7416. PCWSTR lpAssemblyManifestPath;
  7417. PCWSTR lpAssemblyPolicyPath;
  7418. PCWSTR lpAssemblyDirectoryName;
  7419. DWORD ulFileCount;
  7420. } ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION, * PACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION;
  7421. typedef const struct _ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION * PCACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION ;
  7422. typedef struct _ACTIVATION_CONTEXT_DETAILED_INFORMATION {
  7423. DWORD dwFlags;
  7424. DWORD ulFormatVersion;
  7425. DWORD ulAssemblyCount;
  7426. DWORD ulRootManifestPathType;
  7427. DWORD ulRootManifestPathChars;
  7428. DWORD ulRootConfigurationPathType;
  7429. DWORD ulRootConfigurationPathChars;
  7430. DWORD ulAppDirPathType;
  7431. DWORD ulAppDirPathChars;
  7432. PCWSTR lpRootManifestPath;
  7433. PCWSTR lpRootConfigurationPath;
  7434. PCWSTR lpAppDirPath;
  7435. } ACTIVATION_CONTEXT_DETAILED_INFORMATION, *PACTIVATION_CONTEXT_DETAILED_INFORMATION;
  7436. typedef const struct _ACTIVATION_CONTEXT_DETAILED_INFORMATION *PCACTIVATION_CONTEXT_DETAILED_INFORMATION;
  7437. #define DLL_PROCESS_ATTACH 1
  7438. #define DLL_THREAD_ATTACH 2
  7439. #define DLL_THREAD_DETACH 3
  7440. #define DLL_PROCESS_DETACH 0
  7441. #define DLL_PROCESS_VERIFIER 4
  7442. //
  7443. // Defines for the READ flags for Eventlogging
  7444. //
  7445. #define EVENTLOG_SEQUENTIAL_READ 0x0001
  7446. #define EVENTLOG_SEEK_READ 0x0002
  7447. #define EVENTLOG_FORWARDS_READ 0x0004
  7448. #define EVENTLOG_BACKWARDS_READ 0x0008
  7449. //
  7450. // The types of events that can be logged.
  7451. //
  7452. #define EVENTLOG_SUCCESS 0x0000
  7453. #define EVENTLOG_ERROR_TYPE 0x0001
  7454. #define EVENTLOG_WARNING_TYPE 0x0002
  7455. #define EVENTLOG_INFORMATION_TYPE 0x0004
  7456. #define EVENTLOG_AUDIT_SUCCESS 0x0008
  7457. #define EVENTLOG_AUDIT_FAILURE 0x0010
  7458. //
  7459. // Defines for the WRITE flags used by Auditing for paired events
  7460. // These are not implemented in Product 1
  7461. //
  7462. #define EVENTLOG_START_PAIRED_EVENT 0x0001
  7463. #define EVENTLOG_END_PAIRED_EVENT 0x0002
  7464. #define EVENTLOG_END_ALL_PAIRED_EVENTS 0x0004
  7465. #define EVENTLOG_PAIRED_EVENT_ACTIVE 0x0008
  7466. #define EVENTLOG_PAIRED_EVENT_INACTIVE 0x0010
  7467. //
  7468. // Structure that defines the header of the Eventlog record. This is the
  7469. // fixed-sized portion before all the variable-length strings, binary
  7470. // data and pad bytes.
  7471. //
  7472. // TimeGenerated is the time it was generated at the client.
  7473. // TimeWritten is the time it was put into the log at the server end.
  7474. //
  7475. typedef struct _EVENTLOGRECORD {
  7476. DWORD Length; // Length of full record
  7477. DWORD Reserved; // Used by the service
  7478. DWORD RecordNumber; // Absolute record number
  7479. DWORD TimeGenerated; // Seconds since 1-1-1970
  7480. DWORD TimeWritten; // Seconds since 1-1-1970
  7481. DWORD EventID;
  7482. WORD EventType;
  7483. WORD NumStrings;
  7484. WORD EventCategory;
  7485. WORD ReservedFlags; // For use with paired events (auditing)
  7486. DWORD ClosingRecordNumber; // For use with paired events (auditing)
  7487. DWORD StringOffset; // Offset from beginning of record
  7488. DWORD UserSidLength;
  7489. DWORD UserSidOffset;
  7490. DWORD DataLength;
  7491. DWORD DataOffset; // Offset from beginning of record
  7492. //
  7493. // Then follow:
  7494. //
  7495. // WCHAR SourceName[]
  7496. // WCHAR Computername[]
  7497. // SID UserSid
  7498. // WCHAR Strings[]
  7499. // BYTE Data[]
  7500. // CHAR Pad[]
  7501. // DWORD Length;
  7502. //
  7503. } EVENTLOGRECORD, *PEVENTLOGRECORD;
  7504. //SS: start of changes to support clustering
  7505. //SS: ideally the
  7506. #define MAXLOGICALLOGNAMESIZE 256
  7507. #if _MSC_VER >= 1200
  7508. #pragma warning(push)
  7509. #endif
  7510. #pragma warning(disable : 4200)
  7511. typedef struct _EVENTSFORLOGFILE{
  7512. DWORD ulSize;
  7513. WCHAR szLogicalLogFile[MAXLOGICALLOGNAMESIZE]; //name of the logical file-security/application/system
  7514. DWORD ulNumRecords;
  7515. EVENTLOGRECORD pEventLogRecords[];
  7516. }EVENTSFORLOGFILE, *PEVENTSFORLOGFILE;
  7517. typedef struct _PACKEDEVENTINFO{
  7518. DWORD ulSize; //total size of the structure
  7519. DWORD ulNumEventsForLogFile; //number of EventsForLogFile structure that follow
  7520. DWORD ulOffsets[]; //the offsets from the start of this structure to the EVENTSFORLOGFILE structure
  7521. }PACKEDEVENTINFO, *PPACKEDEVENTINFO;
  7522. #if _MSC_VER >= 1200
  7523. #pragma warning(pop)
  7524. #else
  7525. #pragma warning(default : 4200)
  7526. #endif
  7527. //SS: end of changes to support clustering
  7528. //
  7529. // begin_ntddk begin_wdm begin_nthal
  7530. //
  7531. // Registry Specific Access Rights.
  7532. //
  7533. #define KEY_QUERY_VALUE (0x0001)
  7534. #define KEY_SET_VALUE (0x0002)
  7535. #define KEY_CREATE_SUB_KEY (0x0004)
  7536. #define KEY_ENUMERATE_SUB_KEYS (0x0008)
  7537. #define KEY_NOTIFY (0x0010)
  7538. #define KEY_CREATE_LINK (0x0020)
  7539. #define KEY_WOW64_32KEY (0x0200)
  7540. #define KEY_WOW64_64KEY (0x0100)
  7541. #define KEY_WOW64_RES (0x0300)
  7542. #define KEY_READ ((STANDARD_RIGHTS_READ |\
  7543. KEY_QUERY_VALUE |\
  7544. KEY_ENUMERATE_SUB_KEYS |\
  7545. KEY_NOTIFY) \
  7546. & \
  7547. (~SYNCHRONIZE))
  7548. #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
  7549. KEY_SET_VALUE |\
  7550. KEY_CREATE_SUB_KEY) \
  7551. & \
  7552. (~SYNCHRONIZE))
  7553. #define KEY_EXECUTE ((KEY_READ) \
  7554. & \
  7555. (~SYNCHRONIZE))
  7556. #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
  7557. KEY_QUERY_VALUE |\
  7558. KEY_SET_VALUE |\
  7559. KEY_CREATE_SUB_KEY |\
  7560. KEY_ENUMERATE_SUB_KEYS |\
  7561. KEY_NOTIFY |\
  7562. KEY_CREATE_LINK) \
  7563. & \
  7564. (~SYNCHRONIZE))
  7565. //
  7566. // Open/Create Options
  7567. //
  7568. #define REG_OPTION_RESERVED (0x00000000L) // Parameter is reserved
  7569. #define REG_OPTION_NON_VOLATILE (0x00000000L) // Key is preserved
  7570. // when system is rebooted
  7571. #define REG_OPTION_VOLATILE (0x00000001L) // Key is not preserved
  7572. // when system is rebooted
  7573. #define REG_OPTION_CREATE_LINK (0x00000002L) // Created key is a
  7574. // symbolic link
  7575. #define REG_OPTION_BACKUP_RESTORE (0x00000004L) // open for backup or restore
  7576. // special access rules
  7577. // privilege required
  7578. #define REG_OPTION_OPEN_LINK (0x00000008L) // Open symbolic link
  7579. #define REG_LEGAL_OPTION \
  7580. (REG_OPTION_RESERVED |\
  7581. REG_OPTION_NON_VOLATILE |\
  7582. REG_OPTION_VOLATILE |\
  7583. REG_OPTION_CREATE_LINK |\
  7584. REG_OPTION_BACKUP_RESTORE |\
  7585. REG_OPTION_OPEN_LINK)
  7586. //
  7587. // Key creation/open disposition
  7588. //
  7589. #define REG_CREATED_NEW_KEY (0x00000001L) // New Registry Key created
  7590. #define REG_OPENED_EXISTING_KEY (0x00000002L) // Existing Key opened
  7591. //
  7592. // hive format to be used by Reg(Nt)SaveKeyEx
  7593. //
  7594. #define REG_STANDARD_FORMAT 1
  7595. #define REG_LATEST_FORMAT 2
  7596. #define REG_NO_COMPRESSION 4
  7597. //
  7598. // Key restore flags
  7599. //
  7600. #define REG_WHOLE_HIVE_VOLATILE (0x00000001L) // Restore whole hive volatile
  7601. #define REG_REFRESH_HIVE (0x00000002L) // Unwind changes to last flush
  7602. #define REG_NO_LAZY_FLUSH (0x00000004L) // Never lazy flush this hive
  7603. #define REG_FORCE_RESTORE (0x00000008L) // Force the restore process even when we have open handles on subkeys
  7604. //
  7605. // Unload Flags
  7606. //
  7607. #define REG_FORCE_UNLOAD 1
  7608. // end_ntddk end_wdm end_nthal
  7609. //
  7610. // Notify filter values
  7611. //
  7612. #define REG_NOTIFY_CHANGE_NAME (0x00000001L) // Create or delete (child)
  7613. #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
  7614. #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L) // time stamp
  7615. #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
  7616. #define REG_LEGAL_CHANGE_FILTER \
  7617. (REG_NOTIFY_CHANGE_NAME |\
  7618. REG_NOTIFY_CHANGE_ATTRIBUTES |\
  7619. REG_NOTIFY_CHANGE_LAST_SET |\
  7620. REG_NOTIFY_CHANGE_SECURITY)
  7621. //
  7622. //
  7623. // Predefined Value Types.
  7624. //
  7625. #define REG_NONE ( 0 ) // No value type
  7626. #define REG_SZ ( 1 ) // Unicode nul terminated string
  7627. #define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string
  7628. // (with environment variable references)
  7629. #define REG_BINARY ( 3 ) // Free form binary
  7630. #define REG_DWORD ( 4 ) // 32-bit number
  7631. #define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD)
  7632. #define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
  7633. #define REG_LINK ( 6 ) // Symbolic Link (unicode)
  7634. #define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings
  7635. #define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
  7636. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
  7637. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  7638. #define REG_QWORD ( 11 ) // 64-bit number
  7639. #define REG_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as REG_QWORD)
  7640. // end_ntddk end_wdm end_nthal
  7641. // begin_ntddk begin_wdm begin_nthal
  7642. //
  7643. // Service Types (Bit Mask)
  7644. //
  7645. #define SERVICE_KERNEL_DRIVER 0x00000001
  7646. #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
  7647. #define SERVICE_ADAPTER 0x00000004
  7648. #define SERVICE_RECOGNIZER_DRIVER 0x00000008
  7649. #define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | \
  7650. SERVICE_FILE_SYSTEM_DRIVER | \
  7651. SERVICE_RECOGNIZER_DRIVER)
  7652. #define SERVICE_WIN32_OWN_PROCESS 0x00000010
  7653. #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
  7654. #define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | \
  7655. SERVICE_WIN32_SHARE_PROCESS)
  7656. #define SERVICE_INTERACTIVE_PROCESS 0x00000100
  7657. #define SERVICE_TYPE_ALL (SERVICE_WIN32 | \
  7658. SERVICE_ADAPTER | \
  7659. SERVICE_DRIVER | \
  7660. SERVICE_INTERACTIVE_PROCESS)
  7661. //
  7662. // Start Type
  7663. //
  7664. #define SERVICE_BOOT_START 0x00000000
  7665. #define SERVICE_SYSTEM_START 0x00000001
  7666. #define SERVICE_AUTO_START 0x00000002
  7667. #define SERVICE_DEMAND_START 0x00000003
  7668. #define SERVICE_DISABLED 0x00000004
  7669. //
  7670. // Error control type
  7671. //
  7672. #define SERVICE_ERROR_IGNORE 0x00000000
  7673. #define SERVICE_ERROR_NORMAL 0x00000001
  7674. #define SERVICE_ERROR_SEVERE 0x00000002
  7675. #define SERVICE_ERROR_CRITICAL 0x00000003
  7676. //
  7677. //
  7678. // Define the registry driver node enumerations
  7679. //
  7680. typedef enum _CM_SERVICE_NODE_TYPE {
  7681. DriverType = SERVICE_KERNEL_DRIVER,
  7682. FileSystemType = SERVICE_FILE_SYSTEM_DRIVER,
  7683. Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS,
  7684. Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  7685. AdapterType = SERVICE_ADAPTER,
  7686. RecognizerType = SERVICE_RECOGNIZER_DRIVER
  7687. } SERVICE_NODE_TYPE;
  7688. typedef enum _CM_SERVICE_LOAD_TYPE {
  7689. BootLoad = SERVICE_BOOT_START,
  7690. SystemLoad = SERVICE_SYSTEM_START,
  7691. AutoLoad = SERVICE_AUTO_START,
  7692. DemandLoad = SERVICE_DEMAND_START,
  7693. DisableLoad = SERVICE_DISABLED
  7694. } SERVICE_LOAD_TYPE;
  7695. typedef enum _CM_ERROR_CONTROL_TYPE {
  7696. IgnoreError = SERVICE_ERROR_IGNORE,
  7697. NormalError = SERVICE_ERROR_NORMAL,
  7698. SevereError = SERVICE_ERROR_SEVERE,
  7699. CriticalError = SERVICE_ERROR_CRITICAL
  7700. } SERVICE_ERROR_TYPE;
  7701. //
  7702. // IOCTL_TAPE_ERASE definitions
  7703. //
  7704. #define TAPE_ERASE_SHORT 0L
  7705. #define TAPE_ERASE_LONG 1L
  7706. typedef struct _TAPE_ERASE {
  7707. DWORD Type;
  7708. BOOLEAN Immediate;
  7709. } TAPE_ERASE, *PTAPE_ERASE;
  7710. //
  7711. // IOCTL_TAPE_PREPARE definitions
  7712. //
  7713. #define TAPE_LOAD 0L
  7714. #define TAPE_UNLOAD 1L
  7715. #define TAPE_TENSION 2L
  7716. #define TAPE_LOCK 3L
  7717. #define TAPE_UNLOCK 4L
  7718. #define TAPE_FORMAT 5L
  7719. typedef struct _TAPE_PREPARE {
  7720. DWORD Operation;
  7721. BOOLEAN Immediate;
  7722. } TAPE_PREPARE, *PTAPE_PREPARE;
  7723. //
  7724. // IOCTL_TAPE_WRITE_MARKS definitions
  7725. //
  7726. #define TAPE_SETMARKS 0L
  7727. #define TAPE_FILEMARKS 1L
  7728. #define TAPE_SHORT_FILEMARKS 2L
  7729. #define TAPE_LONG_FILEMARKS 3L
  7730. typedef struct _TAPE_WRITE_MARKS {
  7731. DWORD Type;
  7732. DWORD Count;
  7733. BOOLEAN Immediate;
  7734. } TAPE_WRITE_MARKS, *PTAPE_WRITE_MARKS;
  7735. //
  7736. // IOCTL_TAPE_GET_POSITION definitions
  7737. //
  7738. #define TAPE_ABSOLUTE_POSITION 0L
  7739. #define TAPE_LOGICAL_POSITION 1L
  7740. #define TAPE_PSEUDO_LOGICAL_POSITION 2L
  7741. typedef struct _TAPE_GET_POSITION {
  7742. DWORD Type;
  7743. DWORD Partition;
  7744. LARGE_INTEGER Offset;
  7745. } TAPE_GET_POSITION, *PTAPE_GET_POSITION;
  7746. //
  7747. // IOCTL_TAPE_SET_POSITION definitions
  7748. //
  7749. #define TAPE_REWIND 0L
  7750. #define TAPE_ABSOLUTE_BLOCK 1L
  7751. #define TAPE_LOGICAL_BLOCK 2L
  7752. #define TAPE_PSEUDO_LOGICAL_BLOCK 3L
  7753. #define TAPE_SPACE_END_OF_DATA 4L
  7754. #define TAPE_SPACE_RELATIVE_BLOCKS 5L
  7755. #define TAPE_SPACE_FILEMARKS 6L
  7756. #define TAPE_SPACE_SEQUENTIAL_FMKS 7L
  7757. #define TAPE_SPACE_SETMARKS 8L
  7758. #define TAPE_SPACE_SEQUENTIAL_SMKS 9L
  7759. typedef struct _TAPE_SET_POSITION {
  7760. DWORD Method;
  7761. DWORD Partition;
  7762. LARGE_INTEGER Offset;
  7763. BOOLEAN Immediate;
  7764. } TAPE_SET_POSITION, *PTAPE_SET_POSITION;
  7765. //
  7766. // IOCTL_TAPE_GET_DRIVE_PARAMS definitions
  7767. //
  7768. //
  7769. // Definitions for FeaturesLow parameter
  7770. //
  7771. #define TAPE_DRIVE_FIXED 0x00000001
  7772. #define TAPE_DRIVE_SELECT 0x00000002
  7773. #define TAPE_DRIVE_INITIATOR 0x00000004
  7774. #define TAPE_DRIVE_ERASE_SHORT 0x00000010
  7775. #define TAPE_DRIVE_ERASE_LONG 0x00000020
  7776. #define TAPE_DRIVE_ERASE_BOP_ONLY 0x00000040
  7777. #define TAPE_DRIVE_ERASE_IMMEDIATE 0x00000080
  7778. #define TAPE_DRIVE_TAPE_CAPACITY 0x00000100
  7779. #define TAPE_DRIVE_TAPE_REMAINING 0x00000200
  7780. #define TAPE_DRIVE_FIXED_BLOCK 0x00000400
  7781. #define TAPE_DRIVE_VARIABLE_BLOCK 0x00000800
  7782. #define TAPE_DRIVE_WRITE_PROTECT 0x00001000
  7783. #define TAPE_DRIVE_EOT_WZ_SIZE 0x00002000
  7784. #define TAPE_DRIVE_ECC 0x00010000
  7785. #define TAPE_DRIVE_COMPRESSION 0x00020000
  7786. #define TAPE_DRIVE_PADDING 0x00040000
  7787. #define TAPE_DRIVE_REPORT_SMKS 0x00080000
  7788. #define TAPE_DRIVE_GET_ABSOLUTE_BLK 0x00100000
  7789. #define TAPE_DRIVE_GET_LOGICAL_BLK 0x00200000
  7790. #define TAPE_DRIVE_SET_EOT_WZ_SIZE 0x00400000
  7791. #define TAPE_DRIVE_EJECT_MEDIA 0x01000000
  7792. #define TAPE_DRIVE_CLEAN_REQUESTS 0x02000000
  7793. #define TAPE_DRIVE_SET_CMP_BOP_ONLY 0x04000000
  7794. #define TAPE_DRIVE_RESERVED_BIT 0x80000000 //don't use this bit!
  7795. // //can't be a low features bit!
  7796. // //reserved; high features only
  7797. //
  7798. // Definitions for FeaturesHigh parameter
  7799. //
  7800. #define TAPE_DRIVE_LOAD_UNLOAD 0x80000001
  7801. #define TAPE_DRIVE_TENSION 0x80000002
  7802. #define TAPE_DRIVE_LOCK_UNLOCK 0x80000004
  7803. #define TAPE_DRIVE_REWIND_IMMEDIATE 0x80000008
  7804. #define TAPE_DRIVE_SET_BLOCK_SIZE 0x80000010
  7805. #define TAPE_DRIVE_LOAD_UNLD_IMMED 0x80000020
  7806. #define TAPE_DRIVE_TENSION_IMMED 0x80000040
  7807. #define TAPE_DRIVE_LOCK_UNLK_IMMED 0x80000080
  7808. #define TAPE_DRIVE_SET_ECC 0x80000100
  7809. #define TAPE_DRIVE_SET_COMPRESSION 0x80000200
  7810. #define TAPE_DRIVE_SET_PADDING 0x80000400
  7811. #define TAPE_DRIVE_SET_REPORT_SMKS 0x80000800
  7812. #define TAPE_DRIVE_ABSOLUTE_BLK 0x80001000
  7813. #define TAPE_DRIVE_ABS_BLK_IMMED 0x80002000
  7814. #define TAPE_DRIVE_LOGICAL_BLK 0x80004000
  7815. #define TAPE_DRIVE_LOG_BLK_IMMED 0x80008000
  7816. #define TAPE_DRIVE_END_OF_DATA 0x80010000
  7817. #define TAPE_DRIVE_RELATIVE_BLKS 0x80020000
  7818. #define TAPE_DRIVE_FILEMARKS 0x80040000
  7819. #define TAPE_DRIVE_SEQUENTIAL_FMKS 0x80080000
  7820. #define TAPE_DRIVE_SETMARKS 0x80100000
  7821. #define TAPE_DRIVE_SEQUENTIAL_SMKS 0x80200000
  7822. #define TAPE_DRIVE_REVERSE_POSITION 0x80400000
  7823. #define TAPE_DRIVE_SPACE_IMMEDIATE 0x80800000
  7824. #define TAPE_DRIVE_WRITE_SETMARKS 0x81000000
  7825. #define TAPE_DRIVE_WRITE_FILEMARKS 0x82000000
  7826. #define TAPE_DRIVE_WRITE_SHORT_FMKS 0x84000000
  7827. #define TAPE_DRIVE_WRITE_LONG_FMKS 0x88000000
  7828. #define TAPE_DRIVE_WRITE_MARK_IMMED 0x90000000
  7829. #define TAPE_DRIVE_FORMAT 0xA0000000
  7830. #define TAPE_DRIVE_FORMAT_IMMEDIATE 0xC0000000
  7831. #define TAPE_DRIVE_HIGH_FEATURES 0x80000000 //mask for high features flag
  7832. typedef struct _TAPE_GET_DRIVE_PARAMETERS {
  7833. BOOLEAN ECC;
  7834. BOOLEAN Compression;
  7835. BOOLEAN DataPadding;
  7836. BOOLEAN ReportSetmarks;
  7837. DWORD DefaultBlockSize;
  7838. DWORD MaximumBlockSize;
  7839. DWORD MinimumBlockSize;
  7840. DWORD MaximumPartitionCount;
  7841. DWORD FeaturesLow;
  7842. DWORD FeaturesHigh;
  7843. DWORD EOTWarningZoneSize;
  7844. } TAPE_GET_DRIVE_PARAMETERS, *PTAPE_GET_DRIVE_PARAMETERS;
  7845. //
  7846. // IOCTL_TAPE_SET_DRIVE_PARAMETERS definitions
  7847. //
  7848. typedef struct _TAPE_SET_DRIVE_PARAMETERS {
  7849. BOOLEAN ECC;
  7850. BOOLEAN Compression;
  7851. BOOLEAN DataPadding;
  7852. BOOLEAN ReportSetmarks;
  7853. DWORD EOTWarningZoneSize;
  7854. } TAPE_SET_DRIVE_PARAMETERS, *PTAPE_SET_DRIVE_PARAMETERS;
  7855. //
  7856. // IOCTL_TAPE_GET_MEDIA_PARAMETERS definitions
  7857. //
  7858. typedef struct _TAPE_GET_MEDIA_PARAMETERS {
  7859. LARGE_INTEGER Capacity;
  7860. LARGE_INTEGER Remaining;
  7861. DWORD BlockSize;
  7862. DWORD PartitionCount;
  7863. BOOLEAN WriteProtected;
  7864. } TAPE_GET_MEDIA_PARAMETERS, *PTAPE_GET_MEDIA_PARAMETERS;
  7865. //
  7866. // IOCTL_TAPE_SET_MEDIA_PARAMETERS definitions
  7867. //
  7868. typedef struct _TAPE_SET_MEDIA_PARAMETERS {
  7869. DWORD BlockSize;
  7870. } TAPE_SET_MEDIA_PARAMETERS, *PTAPE_SET_MEDIA_PARAMETERS;
  7871. //
  7872. // IOCTL_TAPE_CREATE_PARTITION definitions
  7873. //
  7874. #define TAPE_FIXED_PARTITIONS 0L
  7875. #define TAPE_SELECT_PARTITIONS 1L
  7876. #define TAPE_INITIATOR_PARTITIONS 2L
  7877. typedef struct _TAPE_CREATE_PARTITION {
  7878. DWORD Method;
  7879. DWORD Count;
  7880. DWORD Size;
  7881. } TAPE_CREATE_PARTITION, *PTAPE_CREATE_PARTITION;
  7882. //
  7883. // WMI Methods
  7884. //
  7885. #define TAPE_QUERY_DRIVE_PARAMETERS 0L
  7886. #define TAPE_QUERY_MEDIA_CAPACITY 1L
  7887. #define TAPE_CHECK_FOR_DRIVE_PROBLEM 2L
  7888. #define TAPE_QUERY_IO_ERROR_DATA 3L
  7889. #define TAPE_QUERY_DEVICE_ERROR_DATA 4L
  7890. typedef struct _TAPE_WMI_OPERATIONS {
  7891. DWORD Method;
  7892. DWORD DataBufferSize;
  7893. PVOID DataBuffer;
  7894. } TAPE_WMI_OPERATIONS, *PTAPE_WMI_OPERATIONS;
  7895. //
  7896. // Type of drive errors
  7897. //
  7898. typedef enum _TAPE_DRIVE_PROBLEM_TYPE {
  7899. TapeDriveProblemNone, TapeDriveReadWriteWarning,
  7900. TapeDriveReadWriteError, TapeDriveReadWarning,
  7901. TapeDriveWriteWarning, TapeDriveReadError,
  7902. TapeDriveWriteError, TapeDriveHardwareError,
  7903. TapeDriveUnsupportedMedia, TapeDriveScsiConnectionError,
  7904. TapeDriveTimetoClean, TapeDriveCleanDriveNow,
  7905. TapeDriveMediaLifeExpired, TapeDriveSnappedTape
  7906. } TAPE_DRIVE_PROBLEM_TYPE;
  7907. #if defined(_M_AMD64) && !defined(__midl)
  7908. __forceinline
  7909. PVOID
  7910. GetCurrentFiber (
  7911. VOID
  7912. )
  7913. {
  7914. return (PVOID)__readgsqword(FIELD_OFFSET(NT_TIB, FiberData));
  7915. }
  7916. __forceinline
  7917. PVOID
  7918. GetFiberData (
  7919. VOID
  7920. )
  7921. {
  7922. return *(PVOID *)GetCurrentFiber();
  7923. }
  7924. #endif // _M_AMD64 && !defined(__midl)
  7925. #if (_WIN32_WINNT > 0x0500) || (_WIN32_FUSION >= 0x0100) || ISOLATION_AWARE_ENABLED // winnt_only
  7926. #define ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION (1)
  7927. #define ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION (2)
  7928. #define ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION (3)
  7929. #define ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION (4)
  7930. #define ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION (5)
  7931. #define ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION (6)
  7932. #define ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION (7)
  7933. #define ACTIVATION_CONTEXT_SECTION_GLOBAL_OBJECT_RENAME_TABLE (8)
  7934. #define ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES (9)
  7935. #endif // winnt_only
  7936. #ifdef __cplusplus
  7937. }
  7938. #endif
  7939. #endif /* _WINNT_ */