Source code of Windows XP (NT5)
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.

29746 lines
723 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. ntifs.h
  5. Abstract:
  6. This module defines the NT types, constants, and functions that are
  7. exposed to file system drivers.
  8. Revision History:
  9. --*/
  10. #ifndef _NTIFS_
  11. #define _NTIFS_
  12. #ifndef RC_INVOKED
  13. #if _MSC_VER < 1300
  14. #error Compiler version not supported by Windows DDK
  15. #endif
  16. #endif // RC_INVOKED
  17. #ifndef __cplusplus
  18. #pragma warning(disable:4116) // TYPE_ALIGNMENT generates this - move it
  19. // outside the warning push/pop scope.
  20. #endif
  21. #define NT_INCLUDED
  22. #define _NTMSV1_0_
  23. #define _CTYPE_DISABLE_MACROS
  24. #include <excpt.h>
  25. #include <ntdef.h>
  26. #include <ntnls.h>
  27. #include <ntstatus.h>
  28. #include <bugcodes.h>
  29. #include <ntiologc.h>
  30. //
  31. // Kernel Mutex Level Numbers (must be globallly assigned within executive)
  32. // The third token in the name is the sub-component name that defines and
  33. // uses the level number.
  34. //
  35. //
  36. // Used by Vdm for protecting io simulation structures
  37. //
  38. #define MUTEX_LEVEL_VDM_IO (ULONG)0x00000001
  39. #define MUTEX_LEVEL_EX_PROFILE (ULONG)0x00000040
  40. //
  41. // The LANMAN Redirector uses the file system major function, but defines
  42. // it's own mutex levels. We can do this safely because we know that the
  43. // local filesystem will never call the remote filesystem and vice versa.
  44. //
  45. #define MUTEX_LEVEL_RDR_FILESYS_DATABASE (ULONG)0x10100000
  46. #define MUTEX_LEVEL_RDR_FILESYS_SECURITY (ULONG)0x10100001
  47. //
  48. // File System levels.
  49. //
  50. #define MUTEX_LEVEL_FILESYSTEM_RAW_VCB (ULONG)0x11000006
  51. //
  52. // In the NT STREAMS environment, a mutex is used to serialize open, close
  53. // and Scheduler threads executing in a subsystem-parallelized stack.
  54. //
  55. #define MUTEX_LEVEL_STREAMS_SUBSYS (ULONG)0x11001001
  56. //
  57. // Mutex level used by LDT support on x86
  58. //
  59. #define MUTEX_LEVEL_PS_LDT (ULONG)0x1F000000
  60. //
  61. // These macros are used to test, set and clear flags respectivly
  62. //
  63. #ifndef FlagOn
  64. #define FlagOn(_F,_SF) ((_F) & (_SF))
  65. #endif
  66. #ifndef BooleanFlagOn
  67. #define BooleanFlagOn(F,SF) ((BOOLEAN)(((F) & (SF)) != 0))
  68. #endif
  69. #ifndef SetFlag
  70. #define SetFlag(_F,_SF) ((_F) |= (_SF))
  71. #endif
  72. #ifndef ClearFlag
  73. #define ClearFlag(_F,_SF) ((_F) &= ~(_SF))
  74. #endif
  75. //
  76. // Define types that are not exported.
  77. //
  78. typedef struct _BUS_HANDLER *PBUS_HANDLER;
  79. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  80. typedef struct _DEVICE_HANDLER_OBJECT *PDEVICE_HANDLER_OBJECT;
  81. typedef struct _IO_TIMER *PIO_TIMER;
  82. typedef struct _KINTERRUPT *PKINTERRUPT;
  83. typedef struct _KPROCESS *PKPROCESS ,*PRKPROCESS, *PEPROCESS;
  84. typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD, *PETHREAD;
  85. typedef struct _OBJECT_TYPE *POBJECT_TYPE;
  86. typedef struct _PEB *PPEB;
  87. #if defined(_M_AMD64)
  88. PKTHREAD
  89. NTAPI
  90. KeGetCurrentThread(
  91. VOID
  92. );
  93. #endif // defined(_M_AMD64)
  94. #if defined(_M_IX86)
  95. PKTHREAD NTAPI KeGetCurrentThread();
  96. #endif // defined(_M_IX86)
  97. #if defined(_M_IA64)
  98. //
  99. // Define Address of Processor Control Registers.
  100. //
  101. #define KIPCR ((ULONG_PTR)(KADDRESS_BASE + 0xffff0000)) // kernel address of first PCR
  102. //
  103. // Define Pointer to Processor Control Registers.
  104. //
  105. #define PCR ((volatile KPCR * const)KIPCR)
  106. PKTHREAD NTAPI KeGetCurrentThread();
  107. #endif // defined(_M_IA64)
  108. #define PsGetCurrentProcess() IoGetCurrentProcess()
  109. #define PsGetCurrentThread() ((PETHREAD) (KeGetCurrentThread()))
  110. extern NTSYSAPI CCHAR KeNumberProcessors;
  111. //
  112. // Define an access token from a programmer's viewpoint. The structure is
  113. // completely opaque and the programer is only allowed to have pointers
  114. // to tokens.
  115. //
  116. typedef PVOID PACCESS_TOKEN; // winnt
  117. //
  118. // Pointer to a SECURITY_DESCRIPTOR opaque data type.
  119. //
  120. typedef PVOID PSECURITY_DESCRIPTOR; // winnt
  121. //
  122. // Define a pointer to the Security ID data type (an opaque data type)
  123. //
  124. typedef PVOID PSID; // winnt
  125. typedef ULONG ACCESS_MASK;
  126. typedef ACCESS_MASK *PACCESS_MASK;
  127. // end_winnt
  128. //
  129. // The following are masks for the predefined standard access types
  130. //
  131. #define DELETE (0x00010000L)
  132. #define READ_CONTROL (0x00020000L)
  133. #define WRITE_DAC (0x00040000L)
  134. #define WRITE_OWNER (0x00080000L)
  135. #define SYNCHRONIZE (0x00100000L)
  136. #define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
  137. #define STANDARD_RIGHTS_READ (READ_CONTROL)
  138. #define STANDARD_RIGHTS_WRITE (READ_CONTROL)
  139. #define STANDARD_RIGHTS_EXECUTE (READ_CONTROL)
  140. #define STANDARD_RIGHTS_ALL (0x001F0000L)
  141. #define SPECIFIC_RIGHTS_ALL (0x0000FFFFL)
  142. //
  143. // AccessSystemAcl access type
  144. //
  145. #define ACCESS_SYSTEM_SECURITY (0x01000000L)
  146. //
  147. // MaximumAllowed access type
  148. //
  149. #define MAXIMUM_ALLOWED (0x02000000L)
  150. //
  151. // These are the generic rights.
  152. //
  153. #define GENERIC_READ (0x80000000L)
  154. #define GENERIC_WRITE (0x40000000L)
  155. #define GENERIC_EXECUTE (0x20000000L)
  156. #define GENERIC_ALL (0x10000000L)
  157. //
  158. // Define the generic mapping array. This is used to denote the
  159. // mapping of each generic access right to a specific access mask.
  160. //
  161. typedef struct _GENERIC_MAPPING {
  162. ACCESS_MASK GenericRead;
  163. ACCESS_MASK GenericWrite;
  164. ACCESS_MASK GenericExecute;
  165. ACCESS_MASK GenericAll;
  166. } GENERIC_MAPPING;
  167. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  168. ////////////////////////////////////////////////////////////////////////
  169. // //
  170. // LUID_AND_ATTRIBUTES //
  171. // //
  172. ////////////////////////////////////////////////////////////////////////
  173. //
  174. //
  175. #include <pshpack4.h>
  176. typedef struct _LUID_AND_ATTRIBUTES {
  177. LUID Luid;
  178. ULONG Attributes;
  179. } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  180. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  181. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  182. #include <poppack.h>
  183. #ifndef SID_IDENTIFIER_AUTHORITY_DEFINED
  184. #define SID_IDENTIFIER_AUTHORITY_DEFINED
  185. typedef struct _SID_IDENTIFIER_AUTHORITY {
  186. UCHAR Value[6];
  187. } SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY;
  188. #endif
  189. #ifndef SID_DEFINED
  190. #define SID_DEFINED
  191. typedef struct _SID {
  192. UCHAR Revision;
  193. UCHAR SubAuthorityCount;
  194. SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
  195. #ifdef MIDL_PASS
  196. [size_is(SubAuthorityCount)] ULONG SubAuthority[*];
  197. #else // MIDL_PASS
  198. ULONG SubAuthority[ANYSIZE_ARRAY];
  199. #endif // MIDL_PASS
  200. } SID, *PISID;
  201. #endif
  202. #define SID_REVISION (1) // Current revision level
  203. #define SID_MAX_SUB_AUTHORITIES (15)
  204. #define SID_RECOMMENDED_SUB_AUTHORITIES (1) // Will change to around 6
  205. // in a future release.
  206. #ifndef MIDL_PASS
  207. #define SECURITY_MAX_SID_SIZE \
  208. (sizeof(SID) - sizeof(ULONG) + (SID_MAX_SUB_AUTHORITIES * sizeof(ULONG)))
  209. #endif // MIDL_PASS
  210. typedef enum _SID_NAME_USE {
  211. SidTypeUser = 1,
  212. SidTypeGroup,
  213. SidTypeDomain,
  214. SidTypeAlias,
  215. SidTypeWellKnownGroup,
  216. SidTypeDeletedAccount,
  217. SidTypeInvalid,
  218. SidTypeUnknown,
  219. SidTypeComputer
  220. } SID_NAME_USE, *PSID_NAME_USE;
  221. typedef struct _SID_AND_ATTRIBUTES {
  222. PSID Sid;
  223. ULONG Attributes;
  224. } SID_AND_ATTRIBUTES, * PSID_AND_ATTRIBUTES;
  225. typedef SID_AND_ATTRIBUTES SID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  226. typedef SID_AND_ATTRIBUTES_ARRAY *PSID_AND_ATTRIBUTES_ARRAY;
  227. /////////////////////////////////////////////////////////////////////////////
  228. // //
  229. // Universal well-known SIDs //
  230. // //
  231. // Null SID S-1-0-0 //
  232. // World S-1-1-0 //
  233. // Local S-1-2-0 //
  234. // Creator Owner ID S-1-3-0 //
  235. // Creator Group ID S-1-3-1 //
  236. // Creator Owner Server ID S-1-3-2 //
  237. // Creator Group Server ID S-1-3-3 //
  238. // //
  239. // (Non-unique IDs) S-1-4 //
  240. // //
  241. /////////////////////////////////////////////////////////////////////////////
  242. #define SECURITY_NULL_SID_AUTHORITY {0,0,0,0,0,0}
  243. #define SECURITY_WORLD_SID_AUTHORITY {0,0,0,0,0,1}
  244. #define SECURITY_LOCAL_SID_AUTHORITY {0,0,0,0,0,2}
  245. #define SECURITY_CREATOR_SID_AUTHORITY {0,0,0,0,0,3}
  246. #define SECURITY_NON_UNIQUE_AUTHORITY {0,0,0,0,0,4}
  247. #define SECURITY_RESOURCE_MANAGER_AUTHORITY {0,0,0,0,0,9}
  248. #define SECURITY_NULL_RID (0x00000000L)
  249. #define SECURITY_WORLD_RID (0x00000000L)
  250. #define SECURITY_LOCAL_RID (0x00000000L)
  251. #define SECURITY_CREATOR_OWNER_RID (0x00000000L)
  252. #define SECURITY_CREATOR_GROUP_RID (0x00000001L)
  253. #define SECURITY_CREATOR_OWNER_SERVER_RID (0x00000002L)
  254. #define SECURITY_CREATOR_GROUP_SERVER_RID (0x00000003L)
  255. /////////////////////////////////////////////////////////////////////////////
  256. // //
  257. // NT well-known SIDs //
  258. // //
  259. // NT Authority S-1-5 //
  260. // Dialup S-1-5-1 //
  261. // //
  262. // Network S-1-5-2 //
  263. // Batch S-1-5-3 //
  264. // Interactive S-1-5-4 //
  265. // Service S-1-5-6 //
  266. // AnonymousLogon S-1-5-7 (aka null logon session) //
  267. // Proxy S-1-5-8 //
  268. // ServerLogon S-1-5-9 (aka domain controller account) //
  269. // Self S-1-5-10 (self RID) //
  270. // Authenticated User S-1-5-11 (Authenticated user somewhere) //
  271. // Restricted Code S-1-5-12 (Running restricted code) //
  272. // Terminal Server S-1-5-13 (Running on Terminal Server) //
  273. // Remote Logon S-1-5-14 (Remote Interactive Logon) //
  274. // //
  275. // (Logon IDs) S-1-5-5-X-Y //
  276. // //
  277. // (NT non-unique IDs) S-1-5-0x15-... //
  278. // //
  279. // (Built-in domain) s-1-5-0x20 //
  280. // //
  281. /////////////////////////////////////////////////////////////////////////////
  282. #define SECURITY_NT_AUTHORITY {0,0,0,0,0,5} // ntifs
  283. #define SECURITY_DIALUP_RID (0x00000001L)
  284. #define SECURITY_NETWORK_RID (0x00000002L)
  285. #define SECURITY_BATCH_RID (0x00000003L)
  286. #define SECURITY_INTERACTIVE_RID (0x00000004L)
  287. #define SECURITY_SERVICE_RID (0x00000006L)
  288. #define SECURITY_ANONYMOUS_LOGON_RID (0x00000007L)
  289. #define SECURITY_PROXY_RID (0x00000008L)
  290. #define SECURITY_ENTERPRISE_CONTROLLERS_RID (0x00000009L)
  291. #define SECURITY_SERVER_LOGON_RID SECURITY_ENTERPRISE_CONTROLLERS_RID
  292. #define SECURITY_PRINCIPAL_SELF_RID (0x0000000AL)
  293. #define SECURITY_AUTHENTICATED_USER_RID (0x0000000BL)
  294. #define SECURITY_RESTRICTED_CODE_RID (0x0000000CL)
  295. #define SECURITY_TERMINAL_SERVER_RID (0x0000000DL)
  296. #define SECURITY_REMOTE_LOGON_RID (0x0000000EL)
  297. #define SECURITY_LOGON_IDS_RID (0x00000005L)
  298. #define SECURITY_LOGON_IDS_RID_COUNT (3L)
  299. #define SECURITY_LOCAL_SYSTEM_RID (0x00000012L)
  300. #define SECURITY_LOCAL_SERVICE_RID (0x00000013L)
  301. #define SECURITY_NETWORK_SERVICE_RID (0x00000014L)
  302. #define SECURITY_NT_NON_UNIQUE (0x00000015L)
  303. #define SECURITY_NT_NON_UNIQUE_SUB_AUTH_COUNT (3L)
  304. #define SECURITY_BUILTIN_DOMAIN_RID (0x00000020L)
  305. /////////////////////////////////////////////////////////////////////////////
  306. // //
  307. // well-known domain relative sub-authority values (RIDs)... //
  308. // //
  309. /////////////////////////////////////////////////////////////////////////////
  310. // Well-known users ...
  311. #define DOMAIN_USER_RID_ADMIN (0x000001F4L)
  312. #define DOMAIN_USER_RID_GUEST (0x000001F5L)
  313. #define DOMAIN_USER_RID_KRBTGT (0x000001F6L)
  314. // well-known groups ...
  315. #define DOMAIN_GROUP_RID_ADMINS (0x00000200L)
  316. #define DOMAIN_GROUP_RID_USERS (0x00000201L)
  317. #define DOMAIN_GROUP_RID_GUESTS (0x00000202L)
  318. #define DOMAIN_GROUP_RID_COMPUTERS (0x00000203L)
  319. #define DOMAIN_GROUP_RID_CONTROLLERS (0x00000204L)
  320. #define DOMAIN_GROUP_RID_CERT_ADMINS (0x00000205L)
  321. #define DOMAIN_GROUP_RID_SCHEMA_ADMINS (0x00000206L)
  322. #define DOMAIN_GROUP_RID_ENTERPRISE_ADMINS (0x00000207L)
  323. #define DOMAIN_GROUP_RID_POLICY_ADMINS (0x00000208L)
  324. // well-known aliases ...
  325. #define DOMAIN_ALIAS_RID_ADMINS (0x00000220L)
  326. #define DOMAIN_ALIAS_RID_USERS (0x00000221L)
  327. #define DOMAIN_ALIAS_RID_GUESTS (0x00000222L)
  328. #define DOMAIN_ALIAS_RID_POWER_USERS (0x00000223L)
  329. #define DOMAIN_ALIAS_RID_ACCOUNT_OPS (0x00000224L)
  330. #define DOMAIN_ALIAS_RID_SYSTEM_OPS (0x00000225L)
  331. #define DOMAIN_ALIAS_RID_PRINT_OPS (0x00000226L)
  332. #define DOMAIN_ALIAS_RID_BACKUP_OPS (0x00000227L)
  333. #define DOMAIN_ALIAS_RID_REPLICATOR (0x00000228L)
  334. #define DOMAIN_ALIAS_RID_RAS_SERVERS (0x00000229L)
  335. #define DOMAIN_ALIAS_RID_PREW2KCOMPACCESS (0x0000022AL)
  336. #define DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS (0x0000022BL)
  337. #define DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS (0x0000022CL)
  338. //
  339. // Allocate the System Luid. The first 1000 LUIDs are reserved.
  340. // Use #999 here (0x3E7 = 999)
  341. //
  342. #define SYSTEM_LUID { 0x3E7, 0x0 }
  343. #define ANONYMOUS_LOGON_LUID { 0x3e6, 0x0 }
  344. #define LOCALSERVICE_LUID { 0x3e5, 0x0 }
  345. #define NETWORKSERVICE_LUID { 0x3e4, 0x0 }
  346. // This is the *current* ACL revision
  347. #define ACL_REVISION (2)
  348. #define ACL_REVISION_DS (4)
  349. // This is the history of ACL revisions. Add a new one whenever
  350. // ACL_REVISION is updated
  351. #define ACL_REVISION1 (1)
  352. #define MIN_ACL_REVISION ACL_REVISION2
  353. #define ACL_REVISION2 (2)
  354. #define ACL_REVISION3 (3)
  355. #define ACL_REVISION4 (4)
  356. #define MAX_ACL_REVISION ACL_REVISION4
  357. typedef struct _ACL {
  358. UCHAR AclRevision;
  359. UCHAR Sbz1;
  360. USHORT AclSize;
  361. USHORT AceCount;
  362. USHORT Sbz2;
  363. } ACL;
  364. typedef ACL *PACL;
  365. // end_ntddk end_wdm
  366. //
  367. // The structure of an ACE is a common ace header followed by ace type
  368. // specific data. Pictorally the structure of the common ace header is
  369. // as follows:
  370. //
  371. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  372. // 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
  373. // +---------------+-------+-------+---------------+---------------+
  374. // | AceSize | AceFlags | AceType |
  375. // +---------------+-------+-------+---------------+---------------+
  376. //
  377. // AceType denotes the type of the ace, there are some predefined ace
  378. // types
  379. //
  380. // AceSize is the size, in bytes, of ace.
  381. //
  382. // AceFlags are the Ace flags for audit and inheritance, defined shortly.
  383. typedef struct _ACE_HEADER {
  384. UCHAR AceType;
  385. UCHAR AceFlags;
  386. USHORT AceSize;
  387. } ACE_HEADER;
  388. typedef ACE_HEADER *PACE_HEADER;
  389. //
  390. // The following are the predefined ace types that go into the AceType
  391. // field of an Ace header.
  392. //
  393. #define ACCESS_MIN_MS_ACE_TYPE (0x0)
  394. #define ACCESS_ALLOWED_ACE_TYPE (0x0)
  395. #define ACCESS_DENIED_ACE_TYPE (0x1)
  396. #define SYSTEM_AUDIT_ACE_TYPE (0x2)
  397. #define SYSTEM_ALARM_ACE_TYPE (0x3)
  398. #define ACCESS_MAX_MS_V2_ACE_TYPE (0x3)
  399. #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE (0x4)
  400. #define ACCESS_MAX_MS_V3_ACE_TYPE (0x4)
  401. #define ACCESS_MIN_MS_OBJECT_ACE_TYPE (0x5)
  402. #define ACCESS_ALLOWED_OBJECT_ACE_TYPE (0x5)
  403. #define ACCESS_DENIED_OBJECT_ACE_TYPE (0x6)
  404. #define SYSTEM_AUDIT_OBJECT_ACE_TYPE (0x7)
  405. #define SYSTEM_ALARM_OBJECT_ACE_TYPE (0x8)
  406. #define ACCESS_MAX_MS_OBJECT_ACE_TYPE (0x8)
  407. #define ACCESS_MAX_MS_V4_ACE_TYPE (0x8)
  408. #define ACCESS_MAX_MS_ACE_TYPE (0x8)
  409. #define ACCESS_ALLOWED_CALLBACK_ACE_TYPE (0x9)
  410. #define ACCESS_DENIED_CALLBACK_ACE_TYPE (0xA)
  411. #define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE (0xB)
  412. #define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE (0xC)
  413. #define SYSTEM_AUDIT_CALLBACK_ACE_TYPE (0xD)
  414. #define SYSTEM_ALARM_CALLBACK_ACE_TYPE (0xE)
  415. #define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE (0xF)
  416. #define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE (0x10)
  417. #define ACCESS_MAX_MS_V5_ACE_TYPE (0x10)
  418. // end_winnt
  419. // begin_winnt
  420. //
  421. // The following are the inherit flags that go into the AceFlags field
  422. // of an Ace header.
  423. //
  424. #define OBJECT_INHERIT_ACE (0x1)
  425. #define CONTAINER_INHERIT_ACE (0x2)
  426. #define NO_PROPAGATE_INHERIT_ACE (0x4)
  427. #define INHERIT_ONLY_ACE (0x8)
  428. #define INHERITED_ACE (0x10)
  429. #define VALID_INHERIT_FLAGS (0x1F)
  430. // The following are the currently defined ACE flags that go into the
  431. // AceFlags field of an ACE header. Each ACE type has its own set of
  432. // AceFlags.
  433. //
  434. // SUCCESSFUL_ACCESS_ACE_FLAG - used only with system audit and alarm ACE
  435. // types to indicate that a message is generated for successful accesses.
  436. //
  437. // FAILED_ACCESS_ACE_FLAG - used only with system audit and alarm ACE types
  438. // to indicate that a message is generated for failed accesses.
  439. //
  440. //
  441. // SYSTEM_AUDIT and SYSTEM_ALARM AceFlags
  442. //
  443. // These control the signaling of audit and alarms for success or failure.
  444. //
  445. #define SUCCESSFUL_ACCESS_ACE_FLAG (0x40)
  446. #define FAILED_ACCESS_ACE_FLAG (0x80)
  447. //
  448. // We'll define the structure of the predefined ACE types. Pictorally
  449. // the structure of the predefined ACE's is as follows:
  450. //
  451. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  452. // 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
  453. // +---------------+-------+-------+---------------+---------------+
  454. // | AceFlags | Resd |Inherit| AceSize | AceType |
  455. // +---------------+-------+-------+---------------+---------------+
  456. // | Mask |
  457. // +---------------------------------------------------------------+
  458. // | |
  459. // + +
  460. // | |
  461. // + Sid +
  462. // | |
  463. // + +
  464. // | |
  465. // +---------------------------------------------------------------+
  466. //
  467. // Mask is the access mask associated with the ACE. This is either the
  468. // access allowed, access denied, audit, or alarm mask.
  469. //
  470. // Sid is the Sid associated with the ACE.
  471. //
  472. // The following are the four predefined ACE types.
  473. // Examine the AceType field in the Header to determine
  474. // which structure is appropriate to use for casting.
  475. typedef struct _ACCESS_ALLOWED_ACE {
  476. ACE_HEADER Header;
  477. ACCESS_MASK Mask;
  478. ULONG SidStart;
  479. } ACCESS_ALLOWED_ACE;
  480. typedef ACCESS_ALLOWED_ACE *PACCESS_ALLOWED_ACE;
  481. typedef struct _ACCESS_DENIED_ACE {
  482. ACE_HEADER Header;
  483. ACCESS_MASK Mask;
  484. ULONG SidStart;
  485. } ACCESS_DENIED_ACE;
  486. typedef ACCESS_DENIED_ACE *PACCESS_DENIED_ACE;
  487. typedef struct _SYSTEM_AUDIT_ACE {
  488. ACE_HEADER Header;
  489. ACCESS_MASK Mask;
  490. ULONG SidStart;
  491. } SYSTEM_AUDIT_ACE;
  492. typedef SYSTEM_AUDIT_ACE *PSYSTEM_AUDIT_ACE;
  493. typedef struct _SYSTEM_ALARM_ACE {
  494. ACE_HEADER Header;
  495. ACCESS_MASK Mask;
  496. ULONG SidStart;
  497. } SYSTEM_ALARM_ACE;
  498. typedef SYSTEM_ALARM_ACE *PSYSTEM_ALARM_ACE;
  499. //
  500. // Current security descriptor revision value
  501. //
  502. #define SECURITY_DESCRIPTOR_REVISION (1)
  503. #define SECURITY_DESCRIPTOR_REVISION1 (1)
  504. // end_wdm end_ntddk
  505. #define SECURITY_DESCRIPTOR_MIN_LENGTH (sizeof(SECURITY_DESCRIPTOR))
  506. typedef USHORT SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
  507. #define SE_OWNER_DEFAULTED (0x0001)
  508. #define SE_GROUP_DEFAULTED (0x0002)
  509. #define SE_DACL_PRESENT (0x0004)
  510. #define SE_DACL_DEFAULTED (0x0008)
  511. #define SE_SACL_PRESENT (0x0010)
  512. #define SE_SACL_DEFAULTED (0x0020)
  513. // end_winnt
  514. #define SE_DACL_UNTRUSTED (0x0040)
  515. #define SE_SERVER_SECURITY (0x0080)
  516. // begin_winnt
  517. #define SE_DACL_AUTO_INHERIT_REQ (0x0100)
  518. #define SE_SACL_AUTO_INHERIT_REQ (0x0200)
  519. #define SE_DACL_AUTO_INHERITED (0x0400)
  520. #define SE_SACL_AUTO_INHERITED (0x0800)
  521. #define SE_DACL_PROTECTED (0x1000)
  522. #define SE_SACL_PROTECTED (0x2000)
  523. #define SE_RM_CONTROL_VALID (0x4000)
  524. #define SE_SELF_RELATIVE (0x8000)
  525. //
  526. // Where:
  527. //
  528. // SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the
  529. // SID pointed to by the Owner field was provided by a
  530. // defaulting mechanism rather than explicitly provided by the
  531. // original provider of the security descriptor. This may
  532. // affect the treatment of the SID with respect to inheritence
  533. // of an owner.
  534. //
  535. // SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the
  536. // SID in the Group field was provided by a defaulting mechanism
  537. // rather than explicitly provided by the original provider of
  538. // the security descriptor. This may affect the treatment of
  539. // the SID with respect to inheritence of a primary group.
  540. //
  541. // SE_DACL_PRESENT - This boolean flag, when set, indicates that the
  542. // security descriptor contains a discretionary ACL. If this
  543. // flag is set and the Dacl field of the SECURITY_DESCRIPTOR is
  544. // null, then a null ACL is explicitly being specified.
  545. //
  546. // SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the
  547. // ACL pointed to by the Dacl field was provided by a defaulting
  548. // mechanism rather than explicitly provided by the original
  549. // provider of the security descriptor. This may affect the
  550. // treatment of the ACL with respect to inheritence of an ACL.
  551. // This flag is ignored if the DaclPresent flag is not set.
  552. //
  553. // SE_SACL_PRESENT - This boolean flag, when set, indicates that the
  554. // security descriptor contains a system ACL pointed to by the
  555. // Sacl field. If this flag is set and the Sacl field of the
  556. // SECURITY_DESCRIPTOR is null, then an empty (but present)
  557. // ACL is being specified.
  558. //
  559. // SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the
  560. // ACL pointed to by the Sacl field was provided by a defaulting
  561. // mechanism rather than explicitly provided by the original
  562. // provider of the security descriptor. This may affect the
  563. // treatment of the ACL with respect to inheritence of an ACL.
  564. // This flag is ignored if the SaclPresent flag is not set.
  565. //
  566. // end_winnt
  567. // SE_DACL_TRUSTED - This boolean flag, when set, indicates that the
  568. // ACL pointed to by the Dacl field was provided by a trusted source
  569. // and does not require any editing of compound ACEs. If this flag
  570. // is not set and a compound ACE is encountered, the system will
  571. // substitute known valid SIDs for the server SIDs in the ACEs.
  572. //
  573. // SE_SERVER_SECURITY - This boolean flag, when set, indicates that the
  574. // caller wishes the system to create a Server ACL based on the
  575. // input ACL, regardess of its source (explicit or defaulting.
  576. // This is done by replacing all of the GRANT ACEs with compound
  577. // ACEs granting the current server. This flag is only
  578. // meaningful if the subject is impersonating.
  579. //
  580. // begin_winnt
  581. // SE_SELF_RELATIVE - This boolean flag, when set, indicates that the
  582. // security descriptor is in self-relative form. In this form,
  583. // all fields of the security descriptor are contiguous in memory
  584. // and all pointer fields are expressed as offsets from the
  585. // beginning of the security descriptor. This form is useful
  586. // for treating security descriptors as opaque data structures
  587. // for transmission in communication protocol or for storage on
  588. // secondary media.
  589. //
  590. //
  591. //
  592. // Pictorially the structure of a security descriptor is as follows:
  593. //
  594. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  595. // 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
  596. // +---------------------------------------------------------------+
  597. // | Control |Reserved1 (SBZ)| Revision |
  598. // +---------------------------------------------------------------+
  599. // | Owner |
  600. // +---------------------------------------------------------------+
  601. // | Group |
  602. // +---------------------------------------------------------------+
  603. // | Sacl |
  604. // +---------------------------------------------------------------+
  605. // | Dacl |
  606. // +---------------------------------------------------------------+
  607. //
  608. // In general, this data structure should be treated opaquely to ensure future
  609. // compatibility.
  610. //
  611. //
  612. typedef struct _SECURITY_DESCRIPTOR_RELATIVE {
  613. UCHAR Revision;
  614. UCHAR Sbz1;
  615. SECURITY_DESCRIPTOR_CONTROL Control;
  616. ULONG Owner;
  617. ULONG Group;
  618. ULONG Sacl;
  619. ULONG Dacl;
  620. } SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
  621. typedef struct _SECURITY_DESCRIPTOR {
  622. UCHAR Revision;
  623. UCHAR Sbz1;
  624. SECURITY_DESCRIPTOR_CONTROL Control;
  625. PSID Owner;
  626. PSID Group;
  627. PACL Sacl;
  628. PACL Dacl;
  629. } SECURITY_DESCRIPTOR, *PISECURITY_DESCRIPTOR;
  630. ////////////////////////////////////////////////////////////////////////
  631. // //
  632. // Object Type list for AccessCheckByType //
  633. // //
  634. ////////////////////////////////////////////////////////////////////////
  635. typedef struct _OBJECT_TYPE_LIST {
  636. USHORT Level;
  637. USHORT Sbz;
  638. GUID *ObjectType;
  639. } OBJECT_TYPE_LIST, *POBJECT_TYPE_LIST;
  640. //
  641. // DS values for Level
  642. //
  643. #define ACCESS_OBJECT_GUID 0
  644. #define ACCESS_PROPERTY_SET_GUID 1
  645. #define ACCESS_PROPERTY_GUID 2
  646. #define ACCESS_MAX_LEVEL 4
  647. //
  648. // Parameters to NtAccessCheckByTypeAndAditAlarm
  649. //
  650. typedef enum _AUDIT_EVENT_TYPE {
  651. AuditEventObjectAccess,
  652. AuditEventDirectoryServiceAccess
  653. } AUDIT_EVENT_TYPE, *PAUDIT_EVENT_TYPE;
  654. #define AUDIT_ALLOW_NO_PRIVILEGE 0x1
  655. //
  656. // DS values for Source and ObjectTypeName
  657. //
  658. #define ACCESS_DS_SOURCE_A "DS"
  659. #define ACCESS_DS_SOURCE_W L"DS"
  660. #define ACCESS_DS_OBJECT_TYPE_NAME_A "Directory Service Object"
  661. #define ACCESS_DS_OBJECT_TYPE_NAME_W L"Directory Service Object"
  662. ////////////////////////////////////////////////////////////////////////
  663. // //
  664. // Privilege Related Data Structures //
  665. // //
  666. ////////////////////////////////////////////////////////////////////////
  667. // begin_wdm begin_ntddk begin_nthal
  668. //
  669. // Privilege attributes
  670. //
  671. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  672. #define SE_PRIVILEGE_ENABLED (0x00000002L)
  673. #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
  674. //
  675. // Privilege Set Control flags
  676. //
  677. #define PRIVILEGE_SET_ALL_NECESSARY (1)
  678. //
  679. // Privilege Set - This is defined for a privilege set of one.
  680. // If more than one privilege is needed, then this structure
  681. // will need to be allocated with more space.
  682. //
  683. // Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  684. // structure (defined in se.h)
  685. //
  686. typedef struct _PRIVILEGE_SET {
  687. ULONG PrivilegeCount;
  688. ULONG Control;
  689. LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  690. } PRIVILEGE_SET, * PPRIVILEGE_SET;
  691. //
  692. // These must be converted to LUIDs before use.
  693. //
  694. #define SE_MIN_WELL_KNOWN_PRIVILEGE (2L)
  695. #define SE_CREATE_TOKEN_PRIVILEGE (2L)
  696. #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE (3L)
  697. #define SE_LOCK_MEMORY_PRIVILEGE (4L)
  698. #define SE_INCREASE_QUOTA_PRIVILEGE (5L)
  699. // end_wdm
  700. //
  701. // Unsolicited Input is obsolete and unused.
  702. //
  703. #define SE_UNSOLICITED_INPUT_PRIVILEGE (6L)
  704. // begin_wdm
  705. #define SE_MACHINE_ACCOUNT_PRIVILEGE (6L)
  706. #define SE_TCB_PRIVILEGE (7L)
  707. #define SE_SECURITY_PRIVILEGE (8L)
  708. #define SE_TAKE_OWNERSHIP_PRIVILEGE (9L)
  709. #define SE_LOAD_DRIVER_PRIVILEGE (10L)
  710. #define SE_SYSTEM_PROFILE_PRIVILEGE (11L)
  711. #define SE_SYSTEMTIME_PRIVILEGE (12L)
  712. #define SE_PROF_SINGLE_PROCESS_PRIVILEGE (13L)
  713. #define SE_INC_BASE_PRIORITY_PRIVILEGE (14L)
  714. #define SE_CREATE_PAGEFILE_PRIVILEGE (15L)
  715. #define SE_CREATE_PERMANENT_PRIVILEGE (16L)
  716. #define SE_BACKUP_PRIVILEGE (17L)
  717. #define SE_RESTORE_PRIVILEGE (18L)
  718. #define SE_SHUTDOWN_PRIVILEGE (19L)
  719. #define SE_DEBUG_PRIVILEGE (20L)
  720. #define SE_AUDIT_PRIVILEGE (21L)
  721. #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE (22L)
  722. #define SE_CHANGE_NOTIFY_PRIVILEGE (23L)
  723. #define SE_REMOTE_SHUTDOWN_PRIVILEGE (24L)
  724. #define SE_UNDOCK_PRIVILEGE (25L)
  725. #define SE_SYNC_AGENT_PRIVILEGE (26L)
  726. #define SE_ENABLE_DELEGATION_PRIVILEGE (27L)
  727. #define SE_MANAGE_VOLUME_PRIVILEGE (28L)
  728. #define SE_MAX_WELL_KNOWN_PRIVILEGE (SE_MANAGE_VOLUME_PRIVILEGE)
  729. //
  730. // Impersonation Level
  731. //
  732. // Impersonation level is represented by a pair of bits in Windows.
  733. // If a new impersonation level is added or lowest value is changed from
  734. // 0 to something else, fix the Windows CreateFile call.
  735. //
  736. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  737. SecurityAnonymous,
  738. SecurityIdentification,
  739. SecurityImpersonation,
  740. SecurityDelegation
  741. } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  742. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  743. #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
  744. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  745. #define VALID_IMPERSONATION_LEVEL(L) (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL))
  746. ////////////////////////////////////////////////////////////////////
  747. // //
  748. // Token Object Definitions //
  749. // //
  750. // //
  751. ////////////////////////////////////////////////////////////////////
  752. //
  753. // Token Specific Access Rights.
  754. //
  755. #define TOKEN_ASSIGN_PRIMARY (0x0001)
  756. #define TOKEN_DUPLICATE (0x0002)
  757. #define TOKEN_IMPERSONATE (0x0004)
  758. #define TOKEN_QUERY (0x0008)
  759. #define TOKEN_QUERY_SOURCE (0x0010)
  760. #define TOKEN_ADJUST_PRIVILEGES (0x0020)
  761. #define TOKEN_ADJUST_GROUPS (0x0040)
  762. #define TOKEN_ADJUST_DEFAULT (0x0080)
  763. #define TOKEN_ADJUST_SESSIONID (0x0100)
  764. #define TOKEN_ALL_ACCESS_P (STANDARD_RIGHTS_REQUIRED |\
  765. TOKEN_ASSIGN_PRIMARY |\
  766. TOKEN_DUPLICATE |\
  767. TOKEN_IMPERSONATE |\
  768. TOKEN_QUERY |\
  769. TOKEN_QUERY_SOURCE |\
  770. TOKEN_ADJUST_PRIVILEGES |\
  771. TOKEN_ADJUST_GROUPS |\
  772. TOKEN_ADJUST_DEFAULT )
  773. #if ((defined(_WIN32_WINNT) && (_WIN32_WINNT > 0x0400)) || (!defined(_WIN32_WINNT)))
  774. #define TOKEN_ALL_ACCESS (TOKEN_ALL_ACCESS_P |\
  775. TOKEN_ADJUST_SESSIONID )
  776. #else
  777. #define TOKEN_ALL_ACCESS (TOKEN_ALL_ACCESS_P)
  778. #endif
  779. #define TOKEN_READ (STANDARD_RIGHTS_READ |\
  780. TOKEN_QUERY)
  781. #define TOKEN_WRITE (STANDARD_RIGHTS_WRITE |\
  782. TOKEN_ADJUST_PRIVILEGES |\
  783. TOKEN_ADJUST_GROUPS |\
  784. TOKEN_ADJUST_DEFAULT)
  785. #define TOKEN_EXECUTE (STANDARD_RIGHTS_EXECUTE)
  786. //
  787. //
  788. // Token Types
  789. //
  790. typedef enum _TOKEN_TYPE {
  791. TokenPrimary = 1,
  792. TokenImpersonation
  793. } TOKEN_TYPE;
  794. typedef TOKEN_TYPE *PTOKEN_TYPE;
  795. //
  796. // Token Information Classes.
  797. //
  798. typedef enum _TOKEN_INFORMATION_CLASS {
  799. TokenUser = 1,
  800. TokenGroups,
  801. TokenPrivileges,
  802. TokenOwner,
  803. TokenPrimaryGroup,
  804. TokenDefaultDacl,
  805. TokenSource,
  806. TokenType,
  807. TokenImpersonationLevel,
  808. TokenStatistics,
  809. TokenRestrictedSids,
  810. TokenSessionId,
  811. TokenGroupsAndPrivileges,
  812. TokenSessionReference,
  813. TokenSandBoxInert
  814. } TOKEN_INFORMATION_CLASS, *PTOKEN_INFORMATION_CLASS;
  815. //
  816. // Token information class structures
  817. //
  818. typedef struct _TOKEN_USER {
  819. SID_AND_ATTRIBUTES User;
  820. } TOKEN_USER, *PTOKEN_USER;
  821. typedef struct _TOKEN_GROUPS {
  822. ULONG GroupCount;
  823. SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
  824. } TOKEN_GROUPS, *PTOKEN_GROUPS;
  825. typedef struct _TOKEN_PRIVILEGES {
  826. ULONG PrivilegeCount;
  827. LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
  828. } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
  829. typedef struct _TOKEN_OWNER {
  830. PSID Owner;
  831. } TOKEN_OWNER, *PTOKEN_OWNER;
  832. typedef struct _TOKEN_PRIMARY_GROUP {
  833. PSID PrimaryGroup;
  834. } TOKEN_PRIMARY_GROUP, *PTOKEN_PRIMARY_GROUP;
  835. typedef struct _TOKEN_DEFAULT_DACL {
  836. PACL DefaultDacl;
  837. } TOKEN_DEFAULT_DACL, *PTOKEN_DEFAULT_DACL;
  838. typedef struct _TOKEN_GROUPS_AND_PRIVILEGES {
  839. ULONG SidCount;
  840. ULONG SidLength;
  841. PSID_AND_ATTRIBUTES Sids;
  842. ULONG RestrictedSidCount;
  843. ULONG RestrictedSidLength;
  844. PSID_AND_ATTRIBUTES RestrictedSids;
  845. ULONG PrivilegeCount;
  846. ULONG PrivilegeLength;
  847. PLUID_AND_ATTRIBUTES Privileges;
  848. LUID AuthenticationId;
  849. } TOKEN_GROUPS_AND_PRIVILEGES, *PTOKEN_GROUPS_AND_PRIVILEGES;
  850. #define TOKEN_SOURCE_LENGTH 8
  851. typedef struct _TOKEN_SOURCE {
  852. CHAR SourceName[TOKEN_SOURCE_LENGTH];
  853. LUID SourceIdentifier;
  854. } TOKEN_SOURCE, *PTOKEN_SOURCE;
  855. typedef struct _TOKEN_STATISTICS {
  856. LUID TokenId;
  857. LUID AuthenticationId;
  858. LARGE_INTEGER ExpirationTime;
  859. TOKEN_TYPE TokenType;
  860. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  861. ULONG DynamicCharged;
  862. ULONG DynamicAvailable;
  863. ULONG GroupCount;
  864. ULONG PrivilegeCount;
  865. LUID ModifiedId;
  866. } TOKEN_STATISTICS, *PTOKEN_STATISTICS;
  867. typedef struct _TOKEN_CONTROL {
  868. LUID TokenId;
  869. LUID AuthenticationId;
  870. LUID ModifiedId;
  871. TOKEN_SOURCE TokenSource;
  872. } TOKEN_CONTROL, *PTOKEN_CONTROL;
  873. // end_winnt
  874. //
  875. // Security Tracking Mode
  876. //
  877. #define SECURITY_DYNAMIC_TRACKING (TRUE)
  878. #define SECURITY_STATIC_TRACKING (FALSE)
  879. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  880. * PSECURITY_CONTEXT_TRACKING_MODE;
  881. //
  882. // Quality Of Service
  883. //
  884. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  885. ULONG Length;
  886. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  887. SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  888. BOOLEAN EffectiveOnly;
  889. } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  890. //
  891. // Used to represent information related to a thread impersonation
  892. //
  893. typedef struct _SE_IMPERSONATION_STATE {
  894. PACCESS_TOKEN Token;
  895. BOOLEAN CopyOnOpen;
  896. BOOLEAN EffectiveOnly;
  897. SECURITY_IMPERSONATION_LEVEL Level;
  898. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  899. typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  900. #define OWNER_SECURITY_INFORMATION (0x00000001L)
  901. #define GROUP_SECURITY_INFORMATION (0x00000002L)
  902. #define DACL_SECURITY_INFORMATION (0x00000004L)
  903. #define SACL_SECURITY_INFORMATION (0x00000008L)
  904. #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
  905. #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
  906. #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
  907. #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
  908. NTSYSCALLAPI
  909. NTSTATUS
  910. NTAPI
  911. NtOpenThreadToken(
  912. IN HANDLE ThreadHandle,
  913. IN ACCESS_MASK DesiredAccess,
  914. IN BOOLEAN OpenAsSelf,
  915. OUT PHANDLE TokenHandle
  916. );
  917. NTSYSCALLAPI
  918. NTSTATUS
  919. NTAPI
  920. NtOpenThreadTokenEx(
  921. IN HANDLE ThreadHandle,
  922. IN ACCESS_MASK DesiredAccess,
  923. IN BOOLEAN OpenAsSelf,
  924. IN ULONG HandleAttributes,
  925. OUT PHANDLE TokenHandle
  926. );
  927. NTSYSCALLAPI
  928. NTSTATUS
  929. NTAPI
  930. NtOpenProcessToken(
  931. IN HANDLE ProcessHandle,
  932. IN ACCESS_MASK DesiredAccess,
  933. OUT PHANDLE TokenHandle
  934. );
  935. NTSYSCALLAPI
  936. NTSTATUS
  937. NTAPI
  938. NtOpenProcessTokenEx(
  939. IN HANDLE ProcessHandle,
  940. IN ACCESS_MASK DesiredAccess,
  941. IN ULONG HandleAttributes,
  942. OUT PHANDLE TokenHandle
  943. );
  944. NTSYSAPI
  945. NTSTATUS
  946. NTAPI
  947. NtOpenJobObjectToken(
  948. IN HANDLE JobHandle,
  949. IN ACCESS_MASK DesiredAccess,
  950. OUT PHANDLE TokenHandle
  951. );
  952. NTSYSCALLAPI
  953. NTSTATUS
  954. NTAPI
  955. NtDuplicateToken(
  956. IN HANDLE ExistingTokenHandle,
  957. IN ACCESS_MASK DesiredAccess,
  958. IN POBJECT_ATTRIBUTES ObjectAttributes,
  959. IN BOOLEAN EffectiveOnly,
  960. IN TOKEN_TYPE TokenType,
  961. OUT PHANDLE NewTokenHandle
  962. );
  963. NTSYSCALLAPI
  964. NTSTATUS
  965. NTAPI
  966. NtFilterToken (
  967. IN HANDLE ExistingTokenHandle,
  968. IN ULONG Flags,
  969. IN PTOKEN_GROUPS SidsToDisable OPTIONAL,
  970. IN PTOKEN_PRIVILEGES PrivilegesToDelete OPTIONAL,
  971. IN PTOKEN_GROUPS RestrictedSids OPTIONAL,
  972. OUT PHANDLE NewTokenHandle
  973. );
  974. NTSYSCALLAPI
  975. NTSTATUS
  976. NTAPI
  977. NtImpersonateAnonymousToken(
  978. IN HANDLE ThreadHandle
  979. );
  980. NTSYSCALLAPI
  981. NTSTATUS
  982. NTAPI
  983. NtQueryInformationToken (
  984. IN HANDLE TokenHandle,
  985. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  986. OUT PVOID TokenInformation,
  987. IN ULONG TokenInformationLength,
  988. OUT PULONG ReturnLength
  989. );
  990. NTSYSCALLAPI
  991. NTSTATUS
  992. NTAPI
  993. NtSetInformationToken (
  994. IN HANDLE TokenHandle,
  995. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  996. IN PVOID TokenInformation,
  997. IN ULONG TokenInformationLength
  998. );
  999. NTSYSCALLAPI
  1000. NTSTATUS
  1001. NTAPI
  1002. NtAdjustPrivilegesToken (
  1003. IN HANDLE TokenHandle,
  1004. IN BOOLEAN DisableAllPrivileges,
  1005. IN PTOKEN_PRIVILEGES NewState OPTIONAL,
  1006. IN ULONG BufferLength OPTIONAL,
  1007. OUT PTOKEN_PRIVILEGES PreviousState OPTIONAL,
  1008. OUT PULONG ReturnLength
  1009. );
  1010. NTSYSCALLAPI
  1011. NTSTATUS
  1012. NTAPI
  1013. NtAdjustGroupsToken (
  1014. IN HANDLE TokenHandle,
  1015. IN BOOLEAN ResetToDefault,
  1016. IN PTOKEN_GROUPS NewState OPTIONAL,
  1017. IN ULONG BufferLength OPTIONAL,
  1018. OUT PTOKEN_GROUPS PreviousState OPTIONAL,
  1019. OUT PULONG ReturnLength
  1020. );
  1021. NTSYSCALLAPI
  1022. NTSTATUS
  1023. NTAPI
  1024. NtPrivilegeCheck (
  1025. IN HANDLE ClientToken,
  1026. IN OUT PPRIVILEGE_SET RequiredPrivileges,
  1027. OUT PBOOLEAN Result
  1028. );
  1029. NTSYSCALLAPI
  1030. NTSTATUS
  1031. NTAPI
  1032. NtAccessCheckAndAuditAlarm (
  1033. IN PUNICODE_STRING SubsystemName,
  1034. IN PVOID HandleId,
  1035. IN PUNICODE_STRING ObjectTypeName,
  1036. IN PUNICODE_STRING ObjectName,
  1037. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  1038. IN ACCESS_MASK DesiredAccess,
  1039. IN PGENERIC_MAPPING GenericMapping,
  1040. IN BOOLEAN ObjectCreation,
  1041. OUT PACCESS_MASK GrantedAccess,
  1042. OUT PNTSTATUS AccessStatus,
  1043. OUT PBOOLEAN GenerateOnClose
  1044. );
  1045. NTSYSCALLAPI
  1046. NTSTATUS
  1047. NTAPI
  1048. NtAccessCheckByTypeAndAuditAlarm (
  1049. IN PUNICODE_STRING SubsystemName,
  1050. IN PVOID HandleId,
  1051. IN PUNICODE_STRING ObjectTypeName,
  1052. IN PUNICODE_STRING ObjectName,
  1053. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  1054. IN PSID PrincipalSelfSid,
  1055. IN ACCESS_MASK DesiredAccess,
  1056. IN AUDIT_EVENT_TYPE AuditType,
  1057. IN ULONG Flags,
  1058. IN POBJECT_TYPE_LIST ObjectTypeList OPTIONAL,
  1059. IN ULONG ObjectTypeListLength,
  1060. IN PGENERIC_MAPPING GenericMapping,
  1061. IN BOOLEAN ObjectCreation,
  1062. OUT PACCESS_MASK GrantedAccess,
  1063. OUT PNTSTATUS AccessStatus,
  1064. OUT PBOOLEAN GenerateOnClose
  1065. );
  1066. NTSYSCALLAPI
  1067. NTSTATUS
  1068. NTAPI
  1069. NtAccessCheckByTypeResultListAndAuditAlarm (
  1070. IN PUNICODE_STRING SubsystemName,
  1071. IN PVOID HandleId,
  1072. IN PUNICODE_STRING ObjectTypeName,
  1073. IN PUNICODE_STRING ObjectName,
  1074. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  1075. IN PSID PrincipalSelfSid,
  1076. IN ACCESS_MASK DesiredAccess,
  1077. IN AUDIT_EVENT_TYPE AuditType,
  1078. IN ULONG Flags,
  1079. IN POBJECT_TYPE_LIST ObjectTypeList OPTIONAL,
  1080. IN ULONG ObjectTypeListLength,
  1081. IN PGENERIC_MAPPING GenericMapping,
  1082. IN BOOLEAN ObjectCreation,
  1083. OUT PACCESS_MASK GrantedAccess,
  1084. OUT PNTSTATUS AccessStatus,
  1085. OUT PBOOLEAN GenerateOnClose
  1086. );
  1087. NTSYSCALLAPI
  1088. NTSTATUS
  1089. NTAPI
  1090. NtAccessCheckByTypeResultListAndAuditAlarmByHandle (
  1091. IN PUNICODE_STRING SubsystemName,
  1092. IN PVOID HandleId,
  1093. IN HANDLE ClientToken,
  1094. IN PUNICODE_STRING ObjectTypeName,
  1095. IN PUNICODE_STRING ObjectName,
  1096. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  1097. IN PSID PrincipalSelfSid,
  1098. IN ACCESS_MASK DesiredAccess,
  1099. IN AUDIT_EVENT_TYPE AuditType,
  1100. IN ULONG Flags,
  1101. IN POBJECT_TYPE_LIST ObjectTypeList OPTIONAL,
  1102. IN ULONG ObjectTypeListLength,
  1103. IN PGENERIC_MAPPING GenericMapping,
  1104. IN BOOLEAN ObjectCreation,
  1105. OUT PACCESS_MASK GrantedAccess,
  1106. OUT PNTSTATUS AccessStatus,
  1107. OUT PBOOLEAN GenerateOnClose
  1108. );
  1109. NTSYSCALLAPI
  1110. NTSTATUS
  1111. NTAPI
  1112. NtOpenObjectAuditAlarm (
  1113. IN PUNICODE_STRING SubsystemName,
  1114. IN PVOID HandleId OPTIONAL,
  1115. IN PUNICODE_STRING ObjectTypeName,
  1116. IN PUNICODE_STRING ObjectName,
  1117. IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
  1118. IN HANDLE ClientToken,
  1119. IN ACCESS_MASK DesiredAccess,
  1120. IN ACCESS_MASK GrantedAccess,
  1121. IN PPRIVILEGE_SET Privileges OPTIONAL,
  1122. IN BOOLEAN ObjectCreation,
  1123. IN BOOLEAN AccessGranted,
  1124. OUT PBOOLEAN GenerateOnClose
  1125. );
  1126. NTSYSCALLAPI
  1127. NTSTATUS
  1128. NTAPI
  1129. NtPrivilegeObjectAuditAlarm (
  1130. IN PUNICODE_STRING SubsystemName,
  1131. IN PVOID HandleId,
  1132. IN HANDLE ClientToken,
  1133. IN ACCESS_MASK DesiredAccess,
  1134. IN PPRIVILEGE_SET Privileges,
  1135. IN BOOLEAN AccessGranted
  1136. );
  1137. NTSYSCALLAPI
  1138. NTSTATUS
  1139. NTAPI
  1140. NtCloseObjectAuditAlarm (
  1141. IN PUNICODE_STRING SubsystemName,
  1142. IN PVOID HandleId,
  1143. IN BOOLEAN GenerateOnClose
  1144. );
  1145. NTSYSCALLAPI
  1146. NTSTATUS
  1147. NTAPI
  1148. NtDeleteObjectAuditAlarm (
  1149. IN PUNICODE_STRING SubsystemName,
  1150. IN PVOID HandleId,
  1151. IN BOOLEAN GenerateOnClose
  1152. );
  1153. NTSYSCALLAPI
  1154. NTSTATUS
  1155. NTAPI
  1156. NtPrivilegedServiceAuditAlarm (
  1157. IN PUNICODE_STRING SubsystemName,
  1158. IN PUNICODE_STRING ServiceName,
  1159. IN HANDLE ClientToken,
  1160. IN PPRIVILEGE_SET Privileges,
  1161. IN BOOLEAN AccessGranted
  1162. );
  1163. //
  1164. // Define alignment macros to align structure sizes and pointers up and down.
  1165. //
  1166. #define ALIGN_DOWN(length, type) \
  1167. ((ULONG)(length) & ~(sizeof(type) - 1))
  1168. #define ALIGN_UP(length, type) \
  1169. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  1170. #define ALIGN_DOWN_POINTER(address, type) \
  1171. ((PVOID)((ULONG_PTR)(address) & ~((ULONG_PTR)sizeof(type) - 1)))
  1172. #define ALIGN_UP_POINTER(address, type) \
  1173. (ALIGN_DOWN_POINTER(((ULONG_PTR)(address) + sizeof(type) - 1), type))
  1174. #define POOL_TAGGING 1
  1175. #ifndef DBG
  1176. #define DBG 0
  1177. #endif
  1178. #if DBG
  1179. #define IF_DEBUG if (TRUE)
  1180. #else
  1181. #define IF_DEBUG if (FALSE)
  1182. #endif
  1183. #if DEVL
  1184. extern ULONG NtGlobalFlag;
  1185. #define IF_NTOS_DEBUG( FlagName ) \
  1186. if (NtGlobalFlag & (FLG_ ## FlagName))
  1187. #else
  1188. #define IF_NTOS_DEBUG( FlagName ) if (FALSE)
  1189. #endif
  1190. //
  1191. // Kernel definitions that need to be here for forward reference purposes
  1192. //
  1193. // begin_ntndis
  1194. //
  1195. // Processor modes.
  1196. //
  1197. typedef CCHAR KPROCESSOR_MODE;
  1198. typedef enum _MODE {
  1199. KernelMode,
  1200. UserMode,
  1201. MaximumMode
  1202. } MODE;
  1203. // end_ntndis
  1204. //
  1205. // APC function types
  1206. //
  1207. //
  1208. // Put in an empty definition for the KAPC so that the
  1209. // routines can reference it before it is declared.
  1210. //
  1211. struct _KAPC;
  1212. typedef
  1213. VOID
  1214. (*PKNORMAL_ROUTINE) (
  1215. IN PVOID NormalContext,
  1216. IN PVOID SystemArgument1,
  1217. IN PVOID SystemArgument2
  1218. );
  1219. typedef
  1220. VOID
  1221. (*PKKERNEL_ROUTINE) (
  1222. IN struct _KAPC *Apc,
  1223. IN OUT PKNORMAL_ROUTINE *NormalRoutine,
  1224. IN OUT PVOID *NormalContext,
  1225. IN OUT PVOID *SystemArgument1,
  1226. IN OUT PVOID *SystemArgument2
  1227. );
  1228. typedef
  1229. VOID
  1230. (*PKRUNDOWN_ROUTINE) (
  1231. IN struct _KAPC *Apc
  1232. );
  1233. typedef
  1234. BOOLEAN
  1235. (*PKSYNCHRONIZE_ROUTINE) (
  1236. IN PVOID SynchronizeContext
  1237. );
  1238. typedef
  1239. BOOLEAN
  1240. (*PKTRANSFER_ROUTINE) (
  1241. VOID
  1242. );
  1243. //
  1244. //
  1245. // Asynchronous Procedure Call (APC) object
  1246. //
  1247. //
  1248. typedef struct _KAPC {
  1249. CSHORT Type;
  1250. CSHORT Size;
  1251. ULONG Spare0;
  1252. struct _KTHREAD *Thread;
  1253. LIST_ENTRY ApcListEntry;
  1254. PKKERNEL_ROUTINE KernelRoutine;
  1255. PKRUNDOWN_ROUTINE RundownRoutine;
  1256. PKNORMAL_ROUTINE NormalRoutine;
  1257. PVOID NormalContext;
  1258. //
  1259. // N.B. The following two members MUST be together.
  1260. //
  1261. PVOID SystemArgument1;
  1262. PVOID SystemArgument2;
  1263. CCHAR ApcStateIndex;
  1264. KPROCESSOR_MODE ApcMode;
  1265. BOOLEAN Inserted;
  1266. } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
  1267. // begin_ntndis
  1268. //
  1269. // DPC routine
  1270. //
  1271. struct _KDPC;
  1272. typedef
  1273. VOID
  1274. (*PKDEFERRED_ROUTINE) (
  1275. IN struct _KDPC *Dpc,
  1276. IN PVOID DeferredContext,
  1277. IN PVOID SystemArgument1,
  1278. IN PVOID SystemArgument2
  1279. );
  1280. //
  1281. // Define DPC importance.
  1282. //
  1283. // LowImportance - Queue DPC at end of target DPC queue.
  1284. // MediumImportance - Queue DPC at end of target DPC queue.
  1285. // HighImportance - Queue DPC at front of target DPC DPC queue.
  1286. //
  1287. // If there is currently a DPC active on the target processor, or a DPC
  1288. // interrupt has already been requested on the target processor when a
  1289. // DPC is queued, then no further action is necessary. The DPC will be
  1290. // executed on the target processor when its queue entry is processed.
  1291. //
  1292. // If there is not a DPC active on the target processor and a DPC interrupt
  1293. // has not been requested on the target processor, then the exact treatment
  1294. // of the DPC is dependent on whether the host system is a UP system or an
  1295. // MP system.
  1296. //
  1297. // UP system.
  1298. //
  1299. // If the DPC is of medium or high importance, the current DPC queue depth
  1300. // is greater than the maximum target depth, or current DPC request rate is
  1301. // less the minimum target rate, then a DPC interrupt is requested on the
  1302. // host processor and the DPC will be processed when the interrupt occurs.
  1303. // Otherwise, no DPC interupt is requested and the DPC execution will be
  1304. // delayed until the DPC queue depth is greater that the target depth or the
  1305. // minimum DPC rate is less than the target rate.
  1306. //
  1307. // MP system.
  1308. //
  1309. // If the DPC is being queued to another processor and the depth of the DPC
  1310. // queue on the target processor is greater than the maximum target depth or
  1311. // the DPC is of high importance, then a DPC interrupt is requested on the
  1312. // target processor and the DPC will be processed when the interrupt occurs.
  1313. // Otherwise, the DPC execution will be delayed on the target processor until
  1314. // the DPC queue depth on the target processor is greater that the maximum
  1315. // target depth or the minimum DPC rate on the target processor is less than
  1316. // the target mimimum rate.
  1317. //
  1318. // If the DPC is being queued to the current processor and the DPC is not of
  1319. // low importance, the current DPC queue depth is greater than the maximum
  1320. // target depth, or the minimum DPC rate is less than the minimum target rate,
  1321. // then a DPC interrupt is request on the current processor and the DPV will
  1322. // be processed whne the interrupt occurs. Otherwise, no DPC interupt is
  1323. // requested and the DPC execution will be delayed until the DPC queue depth
  1324. // is greater that the target depth or the minimum DPC rate is less than the
  1325. // target rate.
  1326. //
  1327. typedef enum _KDPC_IMPORTANCE {
  1328. LowImportance,
  1329. MediumImportance,
  1330. HighImportance
  1331. } KDPC_IMPORTANCE;
  1332. //
  1333. // Deferred Procedure Call (DPC) object
  1334. //
  1335. typedef struct _KDPC {
  1336. CSHORT Type;
  1337. UCHAR Number;
  1338. UCHAR Importance;
  1339. LIST_ENTRY DpcListEntry;
  1340. PKDEFERRED_ROUTINE DeferredRoutine;
  1341. PVOID DeferredContext;
  1342. PVOID SystemArgument1;
  1343. PVOID SystemArgument2;
  1344. PULONG_PTR Lock;
  1345. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  1346. //
  1347. // Interprocessor interrupt worker routine function prototype.
  1348. //
  1349. typedef PVOID PKIPI_CONTEXT;
  1350. typedef
  1351. VOID
  1352. (*PKIPI_WORKER)(
  1353. IN PKIPI_CONTEXT PacketContext,
  1354. IN PVOID Parameter1,
  1355. IN PVOID Parameter2,
  1356. IN PVOID Parameter3
  1357. );
  1358. //
  1359. // Define interprocessor interrupt performance counters.
  1360. //
  1361. typedef struct _KIPI_COUNTS {
  1362. ULONG Freeze;
  1363. ULONG Packet;
  1364. ULONG DPC;
  1365. ULONG APC;
  1366. ULONG FlushSingleTb;
  1367. ULONG FlushMultipleTb;
  1368. ULONG FlushEntireTb;
  1369. ULONG GenericCall;
  1370. ULONG ChangeColor;
  1371. ULONG SweepDcache;
  1372. ULONG SweepIcache;
  1373. ULONG SweepIcacheRange;
  1374. ULONG FlushIoBuffers;
  1375. ULONG GratuitousDPC;
  1376. } KIPI_COUNTS, *PKIPI_COUNTS;
  1377. #if defined(NT_UP)
  1378. #define HOT_STATISTIC(a) a
  1379. #else
  1380. #define HOT_STATISTIC(a) (KeGetCurrentPrcb()->a)
  1381. #endif
  1382. //
  1383. // I/O system definitions.
  1384. //
  1385. // Define a Memory Descriptor List (MDL)
  1386. //
  1387. // An MDL describes pages in a virtual buffer in terms of physical pages. The
  1388. // pages associated with the buffer are described in an array that is allocated
  1389. // just after the MDL header structure itself. In a future compiler this will
  1390. // be placed at:
  1391. //
  1392. // ULONG Pages[];
  1393. //
  1394. // Until this declaration is permitted, however, one simply calculates the
  1395. // base of the array by adding one to the base MDL pointer:
  1396. //
  1397. // Pages = (PULONG) (Mdl + 1);
  1398. //
  1399. // Notice that while in the context of the subject thread, the base virtual
  1400. // address of a buffer mapped by an MDL may be referenced using the following:
  1401. //
  1402. // Mdl->StartVa | Mdl->ByteOffset
  1403. //
  1404. typedef struct _MDL {
  1405. struct _MDL *Next;
  1406. CSHORT Size;
  1407. CSHORT MdlFlags;
  1408. struct _EPROCESS *Process;
  1409. PVOID MappedSystemVa;
  1410. PVOID StartVa;
  1411. ULONG ByteCount;
  1412. ULONG ByteOffset;
  1413. } MDL, *PMDL;
  1414. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  1415. #define MDL_PAGES_LOCKED 0x0002
  1416. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  1417. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  1418. #define MDL_PARTIAL 0x0010
  1419. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  1420. #define MDL_IO_PAGE_READ 0x0040
  1421. #define MDL_WRITE_OPERATION 0x0080
  1422. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  1423. #define MDL_FREE_EXTRA_PTES 0x0200
  1424. #define MDL_IO_SPACE 0x0800
  1425. #define MDL_NETWORK_HEADER 0x1000
  1426. #define MDL_MAPPING_CAN_FAIL 0x2000
  1427. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  1428. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  1429. MDL_PAGES_LOCKED | \
  1430. MDL_SOURCE_IS_NONPAGED_POOL | \
  1431. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  1432. MDL_PARENT_MAPPED_SYSTEM_VA | \
  1433. MDL_SYSTEM_VA | \
  1434. MDL_IO_SPACE )
  1435. // end_ntndis
  1436. //
  1437. // switch to DBG when appropriate
  1438. //
  1439. #if DBG
  1440. #define PAGED_CODE() \
  1441. { if (KeGetCurrentIrql() > APC_LEVEL) { \
  1442. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  1443. ASSERT(FALSE); \
  1444. } \
  1445. }
  1446. #else
  1447. #define PAGED_CODE() NOP_FUNCTION;
  1448. #endif
  1449. //
  1450. // Data structure used to represent client security context for a thread.
  1451. // This data structure is used to support impersonation.
  1452. //
  1453. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  1454. // BY ALL EXCEPT THE SECURITY ROUTINES.
  1455. //
  1456. typedef struct _SECURITY_CLIENT_CONTEXT {
  1457. SECURITY_QUALITY_OF_SERVICE SecurityQos;
  1458. PACCESS_TOKEN ClientToken;
  1459. BOOLEAN DirectlyAccessClientToken;
  1460. BOOLEAN DirectAccessEffectiveOnly;
  1461. BOOLEAN ServerIsRemote;
  1462. TOKEN_CONTROL ClientTokenControl;
  1463. } SECURITY_CLIENT_CONTEXT, *PSECURITY_CLIENT_CONTEXT;
  1464. //
  1465. // where
  1466. //
  1467. // SecurityQos - is the security quality of service information in effect
  1468. // for this client. This information is used when directly accessing
  1469. // the client's token. In this case, the information here over-rides
  1470. // the information in the client's token. If a copy of the client's
  1471. // token is requested, it must be generated using this information,
  1472. // not the information in the client's token. In all cases, this
  1473. // information may not provide greater access than the information
  1474. // in the client's token. In particular, if the client's token is
  1475. // an impersonation token with an impersonation level of
  1476. // "SecurityDelegation", but the information in this field indicates
  1477. // an impersonation level of "SecurityIdentification", then
  1478. // the server may only get a copy of the token with an Identification
  1479. // level of impersonation.
  1480. //
  1481. // ClientToken - If the DirectlyAccessClientToken field is FALSE,
  1482. // then this field contains a pointer to a duplicate of the
  1483. // client's token. Otherwise, this field points directly to
  1484. // the client's token.
  1485. //
  1486. // DirectlyAccessClientToken - This boolean flag indicates whether the
  1487. // token pointed to by ClientToken is a copy of the client's token
  1488. // or is a direct reference to the client's token. A value of TRUE
  1489. // indicates the client's token is directly accessed, FALSE indicates
  1490. // a copy has been made.
  1491. //
  1492. // DirectAccessEffectiveOnly - This boolean flag indicates whether the
  1493. // the disabled portions of the token that is currently directly
  1494. // referenced may be enabled. This field is only valid if the
  1495. // DirectlyAccessClientToken field is TRUE. In that case, this
  1496. // value supersedes the EffectiveOnly value in the SecurityQos
  1497. // FOR THE CURRENT TOKEN ONLY! If the client changes to impersonate
  1498. // another client, this value may change. This value is always
  1499. // minimized by the EffectiveOnly flag in the SecurityQos field.
  1500. //
  1501. // ServerIsRemote - If TRUE indicates that the server of the client's
  1502. // request is remote. This is used for determining the legitimacy
  1503. // of certain levels of impersonation and to determine how to
  1504. // track context.
  1505. //
  1506. // ClientTokenControl - If the ServerIsRemote flag is TRUE, and the
  1507. // tracking mode is DYNAMIC, then this field contains a copy of
  1508. // the TOKEN_SOURCE from the client's token to assist in deciding
  1509. // whether the information at the remote server needs to be
  1510. // updated to match the current state of the client's security
  1511. // context.
  1512. //
  1513. //
  1514. // NOTE: At some point, we may find it worthwhile to keep an array of
  1515. // elements in this data structure, where each element of the
  1516. // array contains {ClientToken, ClientTokenControl} fields.
  1517. // This would allow efficient handling of the case where a client
  1518. // thread was constantly switching between a couple different
  1519. // contexts - presumably impersonating client's of its own.
  1520. //
  1521. #define NTKERNELAPI DECLSPEC_IMPORT
  1522. #define NTHALAPI DECLSPEC_IMPORT
  1523. //
  1524. // Common dispatcher object header
  1525. //
  1526. // N.B. The size field contains the number of dwords in the structure.
  1527. //
  1528. typedef struct _DISPATCHER_HEADER {
  1529. UCHAR Type;
  1530. UCHAR Absolute;
  1531. UCHAR Size;
  1532. UCHAR Inserted;
  1533. LONG SignalState;
  1534. LIST_ENTRY WaitListHead;
  1535. } DISPATCHER_HEADER;
  1536. //
  1537. // Event object
  1538. //
  1539. typedef struct _KEVENT {
  1540. DISPATCHER_HEADER Header;
  1541. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  1542. //
  1543. // Timer object
  1544. //
  1545. typedef struct _KTIMER {
  1546. DISPATCHER_HEADER Header;
  1547. ULARGE_INTEGER DueTime;
  1548. LIST_ENTRY TimerListEntry;
  1549. struct _KDPC *Dpc;
  1550. LONG Period;
  1551. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  1552. #define LOW_PRIORITY 0 // Lowest thread priority level
  1553. #define LOW_REALTIME_PRIORITY 16 // Lowest realtime priority level
  1554. #define HIGH_PRIORITY 31 // Highest thread priority level
  1555. #define MAXIMUM_PRIORITY 32 // Number of thread priority levels
  1556. // begin_winnt
  1557. #define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
  1558. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  1559. // end_winnt
  1560. //
  1561. // Define system time structure.
  1562. //
  1563. typedef struct _KSYSTEM_TIME {
  1564. ULONG LowPart;
  1565. LONG High1Time;
  1566. LONG High2Time;
  1567. } KSYSTEM_TIME, *PKSYSTEM_TIME;
  1568. //
  1569. // Thread priority
  1570. //
  1571. typedef LONG KPRIORITY;
  1572. //
  1573. // Spin Lock
  1574. //
  1575. // begin_ntndis begin_winnt
  1576. typedef ULONG_PTR KSPIN_LOCK;
  1577. typedef KSPIN_LOCK *PKSPIN_LOCK;
  1578. // end_ntndis end_winnt end_wdm
  1579. //
  1580. // Define per processor lock queue structure.
  1581. //
  1582. // N.B. The lock field of the spin lock queue structure contains the address
  1583. // of the associated kernel spin lock, an owner bit, and a lock bit. Bit
  1584. // 0 of the spin lock address is the wait bit and bit 1 is the owner bit.
  1585. // The use of this field is such that the bits can be set and cleared
  1586. // noninterlocked, however, the back pointer must be preserved.
  1587. //
  1588. // The lock wait bit is set when a processor enqueues itself on the lock
  1589. // queue and it is not the only entry in the queue. The processor will
  1590. // spin on this bit waiting for the lock to be granted.
  1591. //
  1592. // The owner bit is set when the processor owns the respective lock.
  1593. //
  1594. // The next field of the spin lock queue structure is used to line the
  1595. // queued lock structures together in fifo order. It also can set set and
  1596. // cleared noninterlocked.
  1597. //
  1598. #define LOCK_QUEUE_WAIT 1
  1599. #define LOCK_QUEUE_OWNER 2
  1600. typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
  1601. LockQueueDispatcherLock,
  1602. LockQueueContextSwapLock,
  1603. LockQueuePfnLock,
  1604. LockQueueSystemSpaceLock,
  1605. LockQueueVacbLock,
  1606. LockQueueMasterLock,
  1607. LockQueueNonPagedPoolLock,
  1608. LockQueueIoCancelLock,
  1609. LockQueueWorkQueueLock,
  1610. LockQueueIoVpbLock,
  1611. LockQueueIoDatabaseLock,
  1612. LockQueueIoCompletionLock,
  1613. LockQueueNtfsStructLock,
  1614. LockQueueAfdWorkQueueLock,
  1615. LockQueueBcbLock,
  1616. LockQueueMaximumLock
  1617. } KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
  1618. typedef struct _KSPIN_LOCK_QUEUE {
  1619. struct _KSPIN_LOCK_QUEUE * volatile Next;
  1620. PKSPIN_LOCK volatile Lock;
  1621. } KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
  1622. typedef struct _KLOCK_QUEUE_HANDLE {
  1623. KSPIN_LOCK_QUEUE LockQueue;
  1624. KIRQL OldIrql;
  1625. } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
  1626. // begin_wdm
  1627. //
  1628. // Interrupt routine (first level dispatch)
  1629. //
  1630. typedef
  1631. VOID
  1632. (*PKINTERRUPT_ROUTINE) (
  1633. VOID
  1634. );
  1635. //
  1636. // Profile source types
  1637. //
  1638. typedef enum _KPROFILE_SOURCE {
  1639. ProfileTime,
  1640. ProfileAlignmentFixup,
  1641. ProfileTotalIssues,
  1642. ProfilePipelineDry,
  1643. ProfileLoadInstructions,
  1644. ProfilePipelineFrozen,
  1645. ProfileBranchInstructions,
  1646. ProfileTotalNonissues,
  1647. ProfileDcacheMisses,
  1648. ProfileIcacheMisses,
  1649. ProfileCacheMisses,
  1650. ProfileBranchMispredictions,
  1651. ProfileStoreInstructions,
  1652. ProfileFpInstructions,
  1653. ProfileIntegerInstructions,
  1654. Profile2Issue,
  1655. Profile3Issue,
  1656. Profile4Issue,
  1657. ProfileSpecialInstructions,
  1658. ProfileTotalCycles,
  1659. ProfileIcacheIssues,
  1660. ProfileDcacheAccesses,
  1661. ProfileMemoryBarrierCycles,
  1662. ProfileLoadLinkedIssues,
  1663. ProfileMaximum
  1664. } KPROFILE_SOURCE;
  1665. #ifdef _X86_
  1666. //
  1667. // Disable these two pragmas that evaluate to "sti" "cli" on x86 so that driver
  1668. // writers to not leave them inadvertantly in their code.
  1669. //
  1670. #if !defined(MIDL_PASS)
  1671. #if !defined(RC_INVOKED)
  1672. #if _MSC_VER >= 1200
  1673. #pragma warning(push)
  1674. #endif
  1675. #pragma warning(disable:4164) // disable C4164 warning so that apps that
  1676. // build with /Od don't get weird errors !
  1677. #ifdef _M_IX86
  1678. #pragma function(_enable)
  1679. #pragma function(_disable)
  1680. #endif
  1681. #if _MSC_VER >= 1200
  1682. #pragma warning(pop)
  1683. #else
  1684. #pragma warning(default:4164) // reenable C4164 warning
  1685. #endif
  1686. #endif
  1687. #endif
  1688. //
  1689. // Size of kernel mode stack.
  1690. //
  1691. #define KERNEL_STACK_SIZE 12288
  1692. //
  1693. // Define size of large kernel mode stack for callbacks.
  1694. //
  1695. #define KERNEL_LARGE_STACK_SIZE 61440
  1696. //
  1697. // Define number of pages to initialize in a large kernel stack.
  1698. //
  1699. #define KERNEL_LARGE_STACK_COMMIT 12288
  1700. #ifdef _X86_
  1701. //
  1702. // Define the size of the 80387 save area, which is in the context frame.
  1703. //
  1704. #define SIZE_OF_80387_REGISTERS 80
  1705. //
  1706. // The following flags control the contents of the CONTEXT structure.
  1707. //
  1708. #if !defined(RC_INVOKED)
  1709. #define CONTEXT_i386 0x00010000 // this assumes that i386 and
  1710. #define CONTEXT_i486 0x00010000 // i486 have identical context records
  1711. // end_wx86
  1712. #define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  1713. #define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  1714. #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  1715. #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
  1716. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  1717. #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
  1718. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  1719. CONTEXT_SEGMENTS)
  1720. // begin_wx86
  1721. #endif
  1722. #define MAXIMUM_SUPPORTED_EXTENSION 512
  1723. typedef struct _FLOATING_SAVE_AREA {
  1724. ULONG ControlWord;
  1725. ULONG StatusWord;
  1726. ULONG TagWord;
  1727. ULONG ErrorOffset;
  1728. ULONG ErrorSelector;
  1729. ULONG DataOffset;
  1730. ULONG DataSelector;
  1731. UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
  1732. ULONG Cr0NpxState;
  1733. } FLOATING_SAVE_AREA;
  1734. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  1735. //
  1736. // Context Frame
  1737. //
  1738. // This frame has a several purposes: 1) it is used as an argument to
  1739. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1740. // and 3) it is used in the user level thread creation routines.
  1741. //
  1742. // The layout of the record conforms to a standard call frame.
  1743. //
  1744. typedef struct _CONTEXT {
  1745. //
  1746. // The flags values within this flag control the contents of
  1747. // a CONTEXT record.
  1748. //
  1749. // If the context record is used as an input parameter, then
  1750. // for each portion of the context record controlled by a flag
  1751. // whose value is set, it is assumed that that portion of the
  1752. // context record contains valid context. If the context record
  1753. // is being used to modify a threads context, then only that
  1754. // portion of the threads context will be modified.
  1755. //
  1756. // If the context record is used as an IN OUT parameter to capture
  1757. // the context of a thread, then only those portions of the thread's
  1758. // context corresponding to set flags will be returned.
  1759. //
  1760. // The context record is never used as an OUT only parameter.
  1761. //
  1762. ULONG ContextFlags;
  1763. //
  1764. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  1765. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  1766. // included in CONTEXT_FULL.
  1767. //
  1768. ULONG Dr0;
  1769. ULONG Dr1;
  1770. ULONG Dr2;
  1771. ULONG Dr3;
  1772. ULONG Dr6;
  1773. ULONG Dr7;
  1774. //
  1775. // This section is specified/returned if the
  1776. // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  1777. //
  1778. FLOATING_SAVE_AREA FloatSave;
  1779. //
  1780. // This section is specified/returned if the
  1781. // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  1782. //
  1783. ULONG SegGs;
  1784. ULONG SegFs;
  1785. ULONG SegEs;
  1786. ULONG SegDs;
  1787. //
  1788. // This section is specified/returned if the
  1789. // ContextFlags word contians the flag CONTEXT_INTEGER.
  1790. //
  1791. ULONG Edi;
  1792. ULONG Esi;
  1793. ULONG Ebx;
  1794. ULONG Edx;
  1795. ULONG Ecx;
  1796. ULONG Eax;
  1797. //
  1798. // This section is specified/returned if the
  1799. // ContextFlags word contians the flag CONTEXT_CONTROL.
  1800. //
  1801. ULONG Ebp;
  1802. ULONG Eip;
  1803. ULONG SegCs; // MUST BE SANITIZED
  1804. ULONG EFlags; // MUST BE SANITIZED
  1805. ULONG Esp;
  1806. ULONG SegSs;
  1807. //
  1808. // This section is specified/returned if the ContextFlags word
  1809. // contains the flag CONTEXT_EXTENDED_REGISTERS.
  1810. // The format and contexts are processor specific
  1811. //
  1812. UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  1813. } CONTEXT;
  1814. typedef CONTEXT *PCONTEXT;
  1815. // begin_ntminiport
  1816. #endif //_X86_
  1817. #endif // _X86_
  1818. #if defined(_AMD64_)
  1819. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  1820. //
  1821. // Define function to get the caller's EFLAGs value.
  1822. //
  1823. #define GetCallersEflags() __getcallerseflags()
  1824. unsigned __int32
  1825. __getcallerseflags (
  1826. VOID
  1827. );
  1828. #pragma intrinsic(__getcallerseflags)
  1829. //
  1830. // Define function to read the value of the time stamp counter
  1831. //
  1832. #define ReadTimeStampCounter() __rdtsc()
  1833. ULONG64
  1834. __rdtsc (
  1835. VOID
  1836. );
  1837. #pragma intrinsic(__rdtsc)
  1838. //
  1839. // Define functions to move strings or bytes, words, dwords, and qwords.
  1840. //
  1841. VOID
  1842. __movsb (
  1843. IN PUCHAR Destination,
  1844. IN PUCHAR Source,
  1845. IN ULONG Count
  1846. );
  1847. VOID
  1848. __movsw (
  1849. IN PUSHORT Destination,
  1850. IN PUSHORT Source,
  1851. IN ULONG Count
  1852. );
  1853. VOID
  1854. __movsd (
  1855. IN PULONG Destination,
  1856. IN PULONG Source,
  1857. IN ULONG Count
  1858. );
  1859. VOID
  1860. __movsq (
  1861. IN PULONGLONG Destination,
  1862. IN PULONGLONG Source,
  1863. IN ULONG Count
  1864. );
  1865. #pragma intrinsic(__movsb)
  1866. #pragma intrinsic(__movsw)
  1867. #pragma intrinsic(__movsd)
  1868. #pragma intrinsic(__movsq)
  1869. //
  1870. // Define functions to capture the high 64-bits of a 128-bit multiply.
  1871. //
  1872. #define MultiplyHigh __mulh
  1873. #define UnsignedMultiplyHigh __umulh
  1874. LONGLONG
  1875. MultiplyHigh (
  1876. IN LONGLONG Multiplier,
  1877. IN LONGLONG Multiplicand
  1878. );
  1879. ULONGLONG
  1880. UnsignedMultiplyHigh (
  1881. IN ULONGLONG Multiplier,
  1882. IN ULONGLONG Multiplicand
  1883. );
  1884. #pragma intrinsic(__mulh)
  1885. #pragma intrinsic(__umulh)
  1886. //
  1887. // Define functions to read and write the uer TEB and the system PCR/PRCB.
  1888. //
  1889. UCHAR
  1890. __readgsbyte (
  1891. IN ULONG Offset
  1892. );
  1893. USHORT
  1894. __readgsword (
  1895. IN ULONG Offset
  1896. );
  1897. ULONG
  1898. __readgsdword (
  1899. IN ULONG Offset
  1900. );
  1901. ULONG64
  1902. __readgsqword (
  1903. IN ULONG Offset
  1904. );
  1905. VOID
  1906. __writegsbyte (
  1907. IN ULONG Offset,
  1908. IN UCHAR Data
  1909. );
  1910. VOID
  1911. __writegsword (
  1912. IN ULONG Offset,
  1913. IN USHORT Data
  1914. );
  1915. VOID
  1916. __writegsdword (
  1917. IN ULONG Offset,
  1918. IN ULONG Data
  1919. );
  1920. VOID
  1921. __writegsqword (
  1922. IN ULONG Offset,
  1923. IN ULONG64 Data
  1924. );
  1925. #pragma intrinsic(__readgsbyte)
  1926. #pragma intrinsic(__readgsword)
  1927. #pragma intrinsic(__readgsdword)
  1928. #pragma intrinsic(__readgsqword)
  1929. #pragma intrinsic(__writegsbyte)
  1930. #pragma intrinsic(__writegsword)
  1931. #pragma intrinsic(__writegsdword)
  1932. #pragma intrinsic(__writegsqword)
  1933. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  1934. //
  1935. // Size of kernel mode stack.
  1936. //
  1937. #define KERNEL_STACK_SIZE 0x5000
  1938. //
  1939. // Define size of large kernel mode stack for callbacks.
  1940. //
  1941. #define KERNEL_LARGE_STACK_SIZE 0xf000
  1942. //
  1943. // Define number of pages to initialize in a large kernel stack.
  1944. //
  1945. #define KERNEL_LARGE_STACK_COMMIT 0x5000
  1946. //
  1947. // Define the size of the stack used for processing an MCA exception.
  1948. //
  1949. #define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
  1950. //
  1951. // The following flags control the contents of the CONTEXT structure.
  1952. //
  1953. #if !defined(RC_INVOKED)
  1954. #define CONTEXT_AMD64 0x100000
  1955. // end_wx86
  1956. #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
  1957. #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
  1958. #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
  1959. #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
  1960. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
  1961. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  1962. // begin_wx86
  1963. #endif // !defined(RC_INVOKED)
  1964. //
  1965. // Define 128-bit 16-byte aligned xmm register type.
  1966. //
  1967. typedef struct DECLSPEC_ALIGN(16) _M128 {
  1968. ULONGLONG Low;
  1969. LONGLONG High;
  1970. } M128, *PM128;
  1971. //
  1972. // Format of data for fnsave/frstor instructions.
  1973. //
  1974. // This structure is used to store the legacy floating point state.
  1975. //
  1976. typedef struct _LEGACY_SAVE_AREA {
  1977. USHORT ControlWord;
  1978. USHORT Reserved0;
  1979. USHORT StatusWord;
  1980. USHORT Reserved1;
  1981. USHORT TagWord;
  1982. USHORT Reserved2;
  1983. ULONG ErrorOffset;
  1984. USHORT ErrorSelector;
  1985. USHORT ErrorOpcode;
  1986. ULONG DataOffset;
  1987. USHORT DataSelector;
  1988. USHORT Reserved3;
  1989. UCHAR FloatRegisters[8 * 10];
  1990. } LEGACY_SAVE_AREA, *PLEGACY_SAVE_AREA;
  1991. #define LEGACY_SAVE_AREA_LENGTH ((sizeof(LEGACY_SAVE_AREA) + 15) & ~15)
  1992. //
  1993. // Context Frame
  1994. //
  1995. // This frame has a several purposes: 1) it is used as an argument to
  1996. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1997. // and 3) it is used in the user level thread creation routines.
  1998. //
  1999. //
  2000. // The flags field within this record controls the contents of a CONTEXT
  2001. // record.
  2002. //
  2003. // If the context record is used as an input parameter, then for each
  2004. // portion of the context record controlled by a flag whose value is
  2005. // set, it is assumed that that portion of the context record contains
  2006. // valid context. If the context record is being used to modify a threads
  2007. // context, then only that portion of the threads context is modified.
  2008. //
  2009. // If the context record is used as an output parameter to capture the
  2010. // context of a thread, then only those portions of the thread's context
  2011. // corresponding to set flags will be returned.
  2012. //
  2013. // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
  2014. //
  2015. // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
  2016. //
  2017. // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
  2018. //
  2019. // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
  2020. //
  2021. // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
  2022. // Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
  2023. //
  2024. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
  2025. //
  2026. // Register parameter home addresses.
  2027. //
  2028. ULONG64 P1Home;
  2029. ULONG64 P2Home;
  2030. ULONG64 P3Home;
  2031. ULONG64 P4Home;
  2032. ULONG64 P5Home;
  2033. ULONG64 P6Home;
  2034. //
  2035. // Control flags.
  2036. //
  2037. ULONG ContextFlags;
  2038. ULONG MxCsr;
  2039. //
  2040. // Segment Registers and processor flags.
  2041. //
  2042. USHORT SegCs;
  2043. USHORT SegDs;
  2044. USHORT SegEs;
  2045. USHORT SegFs;
  2046. USHORT SegGs;
  2047. USHORT SegSs;
  2048. ULONG EFlags;
  2049. //
  2050. // Debug registers
  2051. //
  2052. ULONG64 Dr0;
  2053. ULONG64 Dr1;
  2054. ULONG64 Dr2;
  2055. ULONG64 Dr3;
  2056. ULONG64 Dr6;
  2057. ULONG64 Dr7;
  2058. //
  2059. // Integer registers.
  2060. //
  2061. ULONG64 Rax;
  2062. ULONG64 Rcx;
  2063. ULONG64 Rdx;
  2064. ULONG64 Rbx;
  2065. ULONG64 Rsp;
  2066. ULONG64 Rbp;
  2067. ULONG64 Rsi;
  2068. ULONG64 Rdi;
  2069. ULONG64 R8;
  2070. ULONG64 R9;
  2071. ULONG64 R10;
  2072. ULONG64 R11;
  2073. ULONG64 R12;
  2074. ULONG64 R13;
  2075. ULONG64 R14;
  2076. ULONG64 R15;
  2077. //
  2078. // Program counter.
  2079. //
  2080. ULONG64 Rip;
  2081. //
  2082. // MMX/floating point state.
  2083. //
  2084. M128 Xmm0;
  2085. M128 Xmm1;
  2086. M128 Xmm2;
  2087. M128 Xmm3;
  2088. M128 Xmm4;
  2089. M128 Xmm5;
  2090. M128 Xmm6;
  2091. M128 Xmm7;
  2092. M128 Xmm8;
  2093. M128 Xmm9;
  2094. M128 Xmm10;
  2095. M128 Xmm11;
  2096. M128 Xmm12;
  2097. M128 Xmm13;
  2098. M128 Xmm14;
  2099. M128 Xmm15;
  2100. //
  2101. // Legacy floating point state.
  2102. //
  2103. LEGACY_SAVE_AREA FltSave;
  2104. ULONG Fill;
  2105. } CONTEXT, *PCONTEXT;
  2106. #endif // _AMD64_
  2107. #ifdef _IA64_
  2108. //
  2109. // Define size of kernel mode stack.
  2110. //
  2111. #define KERNEL_STACK_SIZE 0x8000
  2112. //
  2113. // Define size of large kernel mode stack for callbacks.
  2114. //
  2115. #define KERNEL_LARGE_STACK_SIZE 0x1A000
  2116. //
  2117. // Define number of pages to initialize in a large kernel stack.
  2118. //
  2119. #define KERNEL_LARGE_STACK_COMMIT 0x8000
  2120. //
  2121. // Define size of kernel mode backing store stack.
  2122. //
  2123. #define KERNEL_BSTORE_SIZE 0x6000
  2124. //
  2125. // Define size of large kernel mode backing store for callbacks.
  2126. //
  2127. #define KERNEL_LARGE_BSTORE_SIZE 0x10000
  2128. //
  2129. // Define number of pages to initialize in a large kernel backing store.
  2130. //
  2131. #define KERNEL_LARGE_BSTORE_COMMIT 0x6000
  2132. //
  2133. // Define base address for kernel and user space.
  2134. //
  2135. #define UREGION_INDEX 0
  2136. #define KREGION_INDEX 7
  2137. #define UADDRESS_BASE ((ULONGLONG)UREGION_INDEX << 61)
  2138. #define KADDRESS_BASE ((ULONGLONG)KREGION_INDEX << 61)
  2139. //
  2140. // The following flags control the contents of the CONTEXT structure.
  2141. //
  2142. #if !defined(RC_INVOKED)
  2143. #define CONTEXT_IA64 0x00080000
  2144. #define CONTEXT_CONTROL (CONTEXT_IA64 | 0x00000001L)
  2145. #define CONTEXT_LOWER_FLOATING_POINT (CONTEXT_IA64 | 0x00000002L)
  2146. #define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004L)
  2147. #define CONTEXT_INTEGER (CONTEXT_IA64 | 0x00000008L)
  2148. #define CONTEXT_DEBUG (CONTEXT_IA64 | 0x00000010L)
  2149. #define CONTEXT_IA32_CONTROL (CONTEXT_IA64 | 0x00000020L) // Includes StIPSR
  2150. #define CONTEXT_FLOATING_POINT (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
  2151. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
  2152. #endif // !defined(RC_INVOKED)
  2153. //
  2154. // Context Frame
  2155. //
  2156. // This frame has a several purposes: 1) it is used as an argument to
  2157. // NtContinue, 2) it is used to construct a call frame for APC delivery,
  2158. // 3) it is used to construct a call frame for exception dispatching
  2159. // in user mode, 4) it is used in the user level thread creation
  2160. // routines, and 5) it is used to to pass thread state to debuggers.
  2161. //
  2162. // N.B. Because this record is used as a call frame, it must be EXACTLY
  2163. // a multiple of 16 bytes in length and aligned on a 16-byte boundary.
  2164. //
  2165. typedef struct _CONTEXT {
  2166. //
  2167. // The flags values within this flag control the contents of
  2168. // a CONTEXT record.
  2169. //
  2170. // If the context record is used as an input parameter, then
  2171. // for each portion of the context record controlled by a flag
  2172. // whose value is set, it is assumed that that portion of the
  2173. // context record contains valid context. If the context record
  2174. // is being used to modify a thread's context, then only that
  2175. // portion of the threads context will be modified.
  2176. //
  2177. // If the context record is used as an IN OUT parameter to capture
  2178. // the context of a thread, then only those portions of the thread's
  2179. // context corresponding to set flags will be returned.
  2180. //
  2181. // The context record is never used as an OUT only parameter.
  2182. //
  2183. ULONG ContextFlags;
  2184. ULONG Fill1[3]; // for alignment of following on 16-byte boundary
  2185. //
  2186. // This section is specified/returned if the ContextFlags word contains
  2187. // the flag CONTEXT_DEBUG.
  2188. //
  2189. // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
  2190. //
  2191. ULONGLONG DbI0;
  2192. ULONGLONG DbI1;
  2193. ULONGLONG DbI2;
  2194. ULONGLONG DbI3;
  2195. ULONGLONG DbI4;
  2196. ULONGLONG DbI5;
  2197. ULONGLONG DbI6;
  2198. ULONGLONG DbI7;
  2199. ULONGLONG DbD0;
  2200. ULONGLONG DbD1;
  2201. ULONGLONG DbD2;
  2202. ULONGLONG DbD3;
  2203. ULONGLONG DbD4;
  2204. ULONGLONG DbD5;
  2205. ULONGLONG DbD6;
  2206. ULONGLONG DbD7;
  2207. //
  2208. // This section is specified/returned if the ContextFlags word contains
  2209. // the flag CONTEXT_LOWER_FLOATING_POINT.
  2210. //
  2211. FLOAT128 FltS0;
  2212. FLOAT128 FltS1;
  2213. FLOAT128 FltS2;
  2214. FLOAT128 FltS3;
  2215. FLOAT128 FltT0;
  2216. FLOAT128 FltT1;
  2217. FLOAT128 FltT2;
  2218. FLOAT128 FltT3;
  2219. FLOAT128 FltT4;
  2220. FLOAT128 FltT5;
  2221. FLOAT128 FltT6;
  2222. FLOAT128 FltT7;
  2223. FLOAT128 FltT8;
  2224. FLOAT128 FltT9;
  2225. //
  2226. // This section is specified/returned if the ContextFlags word contains
  2227. // the flag CONTEXT_HIGHER_FLOATING_POINT.
  2228. //
  2229. FLOAT128 FltS4;
  2230. FLOAT128 FltS5;
  2231. FLOAT128 FltS6;
  2232. FLOAT128 FltS7;
  2233. FLOAT128 FltS8;
  2234. FLOAT128 FltS9;
  2235. FLOAT128 FltS10;
  2236. FLOAT128 FltS11;
  2237. FLOAT128 FltS12;
  2238. FLOAT128 FltS13;
  2239. FLOAT128 FltS14;
  2240. FLOAT128 FltS15;
  2241. FLOAT128 FltS16;
  2242. FLOAT128 FltS17;
  2243. FLOAT128 FltS18;
  2244. FLOAT128 FltS19;
  2245. FLOAT128 FltF32;
  2246. FLOAT128 FltF33;
  2247. FLOAT128 FltF34;
  2248. FLOAT128 FltF35;
  2249. FLOAT128 FltF36;
  2250. FLOAT128 FltF37;
  2251. FLOAT128 FltF38;
  2252. FLOAT128 FltF39;
  2253. FLOAT128 FltF40;
  2254. FLOAT128 FltF41;
  2255. FLOAT128 FltF42;
  2256. FLOAT128 FltF43;
  2257. FLOAT128 FltF44;
  2258. FLOAT128 FltF45;
  2259. FLOAT128 FltF46;
  2260. FLOAT128 FltF47;
  2261. FLOAT128 FltF48;
  2262. FLOAT128 FltF49;
  2263. FLOAT128 FltF50;
  2264. FLOAT128 FltF51;
  2265. FLOAT128 FltF52;
  2266. FLOAT128 FltF53;
  2267. FLOAT128 FltF54;
  2268. FLOAT128 FltF55;
  2269. FLOAT128 FltF56;
  2270. FLOAT128 FltF57;
  2271. FLOAT128 FltF58;
  2272. FLOAT128 FltF59;
  2273. FLOAT128 FltF60;
  2274. FLOAT128 FltF61;
  2275. FLOAT128 FltF62;
  2276. FLOAT128 FltF63;
  2277. FLOAT128 FltF64;
  2278. FLOAT128 FltF65;
  2279. FLOAT128 FltF66;
  2280. FLOAT128 FltF67;
  2281. FLOAT128 FltF68;
  2282. FLOAT128 FltF69;
  2283. FLOAT128 FltF70;
  2284. FLOAT128 FltF71;
  2285. FLOAT128 FltF72;
  2286. FLOAT128 FltF73;
  2287. FLOAT128 FltF74;
  2288. FLOAT128 FltF75;
  2289. FLOAT128 FltF76;
  2290. FLOAT128 FltF77;
  2291. FLOAT128 FltF78;
  2292. FLOAT128 FltF79;
  2293. FLOAT128 FltF80;
  2294. FLOAT128 FltF81;
  2295. FLOAT128 FltF82;
  2296. FLOAT128 FltF83;
  2297. FLOAT128 FltF84;
  2298. FLOAT128 FltF85;
  2299. FLOAT128 FltF86;
  2300. FLOAT128 FltF87;
  2301. FLOAT128 FltF88;
  2302. FLOAT128 FltF89;
  2303. FLOAT128 FltF90;
  2304. FLOAT128 FltF91;
  2305. FLOAT128 FltF92;
  2306. FLOAT128 FltF93;
  2307. FLOAT128 FltF94;
  2308. FLOAT128 FltF95;
  2309. FLOAT128 FltF96;
  2310. FLOAT128 FltF97;
  2311. FLOAT128 FltF98;
  2312. FLOAT128 FltF99;
  2313. FLOAT128 FltF100;
  2314. FLOAT128 FltF101;
  2315. FLOAT128 FltF102;
  2316. FLOAT128 FltF103;
  2317. FLOAT128 FltF104;
  2318. FLOAT128 FltF105;
  2319. FLOAT128 FltF106;
  2320. FLOAT128 FltF107;
  2321. FLOAT128 FltF108;
  2322. FLOAT128 FltF109;
  2323. FLOAT128 FltF110;
  2324. FLOAT128 FltF111;
  2325. FLOAT128 FltF112;
  2326. FLOAT128 FltF113;
  2327. FLOAT128 FltF114;
  2328. FLOAT128 FltF115;
  2329. FLOAT128 FltF116;
  2330. FLOAT128 FltF117;
  2331. FLOAT128 FltF118;
  2332. FLOAT128 FltF119;
  2333. FLOAT128 FltF120;
  2334. FLOAT128 FltF121;
  2335. FLOAT128 FltF122;
  2336. FLOAT128 FltF123;
  2337. FLOAT128 FltF124;
  2338. FLOAT128 FltF125;
  2339. FLOAT128 FltF126;
  2340. FLOAT128 FltF127;
  2341. //
  2342. // This section is specified/returned if the ContextFlags word contains
  2343. // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
  2344. //
  2345. ULONGLONG StFPSR; // FP status
  2346. //
  2347. // This section is specified/returned if the ContextFlags word contains
  2348. // the flag CONTEXT_INTEGER.
  2349. //
  2350. // N.B. The registers gp, sp, rp are part of the control context
  2351. //
  2352. ULONGLONG IntGp; // r1, volatile
  2353. ULONGLONG IntT0; // r2-r3, volatile
  2354. ULONGLONG IntT1; //
  2355. ULONGLONG IntS0; // r4-r7, preserved
  2356. ULONGLONG IntS1;
  2357. ULONGLONG IntS2;
  2358. ULONGLONG IntS3;
  2359. ULONGLONG IntV0; // r8, volatile
  2360. ULONGLONG IntT2; // r9-r11, volatile
  2361. ULONGLONG IntT3;
  2362. ULONGLONG IntT4;
  2363. ULONGLONG IntSp; // stack pointer (r12), special
  2364. ULONGLONG IntTeb; // teb (r13), special
  2365. ULONGLONG IntT5; // r14-r31, volatile
  2366. ULONGLONG IntT6;
  2367. ULONGLONG IntT7;
  2368. ULONGLONG IntT8;
  2369. ULONGLONG IntT9;
  2370. ULONGLONG IntT10;
  2371. ULONGLONG IntT11;
  2372. ULONGLONG IntT12;
  2373. ULONGLONG IntT13;
  2374. ULONGLONG IntT14;
  2375. ULONGLONG IntT15;
  2376. ULONGLONG IntT16;
  2377. ULONGLONG IntT17;
  2378. ULONGLONG IntT18;
  2379. ULONGLONG IntT19;
  2380. ULONGLONG IntT20;
  2381. ULONGLONG IntT21;
  2382. ULONGLONG IntT22;
  2383. ULONGLONG IntNats; // Nat bits for r1-r31
  2384. // r1-r31 in bits 1 thru 31.
  2385. ULONGLONG Preds; // predicates, preserved
  2386. ULONGLONG BrRp; // return pointer, b0, preserved
  2387. ULONGLONG BrS0; // b1-b5, preserved
  2388. ULONGLONG BrS1;
  2389. ULONGLONG BrS2;
  2390. ULONGLONG BrS3;
  2391. ULONGLONG BrS4;
  2392. ULONGLONG BrT0; // b6-b7, volatile
  2393. ULONGLONG BrT1;
  2394. //
  2395. // This section is specified/returned if the ContextFlags word contains
  2396. // the flag CONTEXT_CONTROL.
  2397. //
  2398. // Other application registers
  2399. ULONGLONG ApUNAT; // User Nat collection register, preserved
  2400. ULONGLONG ApLC; // Loop counter register, preserved
  2401. ULONGLONG ApEC; // Epilog counter register, preserved
  2402. ULONGLONG ApCCV; // CMPXCHG value register, volatile
  2403. ULONGLONG ApDCR; // Default control register (TBD)
  2404. // Register stack info
  2405. ULONGLONG RsPFS; // Previous function state, preserved
  2406. ULONGLONG RsBSP; // Backing store pointer, preserved
  2407. ULONGLONG RsBSPSTORE;
  2408. ULONGLONG RsRSC; // RSE configuration, volatile
  2409. ULONGLONG RsRNAT; // RSE Nat collection register, preserved
  2410. // Trap Status Information
  2411. ULONGLONG StIPSR; // Interruption Processor Status
  2412. ULONGLONG StIIP; // Interruption IP
  2413. ULONGLONG StIFS; // Interruption Function State
  2414. // iA32 related control registers
  2415. ULONGLONG StFCR; // copy of Ar21
  2416. ULONGLONG Eflag; // Eflag copy of Ar24
  2417. ULONGLONG SegCSD; // iA32 CSDescriptor (Ar25)
  2418. ULONGLONG SegSSD; // iA32 SSDescriptor (Ar26)
  2419. ULONGLONG Cflag; // Cr0+Cr4 copy of Ar27
  2420. ULONGLONG StFSR; // x86 FP status (copy of AR28)
  2421. ULONGLONG StFIR; // x86 FP status (copy of AR29)
  2422. ULONGLONG StFDR; // x86 FP status (copy of AR30)
  2423. ULONGLONG UNUSEDPACK; // added to pack StFDR to 16-bytes
  2424. } CONTEXT, *PCONTEXT;
  2425. // begin_winnt
  2426. //
  2427. // Plabel descriptor structure definition
  2428. //
  2429. typedef struct _PLABEL_DESCRIPTOR {
  2430. ULONGLONG EntryPoint;
  2431. ULONGLONG GlobalPointer;
  2432. } PLABEL_DESCRIPTOR, *PPLABEL_DESCRIPTOR;
  2433. // end_winnt
  2434. #endif // _IA64_
  2435. //
  2436. // for move macros
  2437. //
  2438. #ifdef _MAC
  2439. #ifndef _INC_STRING
  2440. #include <string.h>
  2441. #endif /* _INC_STRING */
  2442. #else
  2443. #include <string.h>
  2444. #endif // _MAC
  2445. #ifndef _SLIST_HEADER_
  2446. #define _SLIST_HEADER_
  2447. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  2448. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  2449. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  2450. #if defined(_WIN64)
  2451. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  2452. ULONGLONG Alignment;
  2453. ULONGLONG Region;
  2454. } SLIST_HEADER;
  2455. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  2456. #else
  2457. typedef union _SLIST_HEADER {
  2458. ULONGLONG Alignment;
  2459. struct {
  2460. SLIST_ENTRY Next;
  2461. USHORT Depth;
  2462. USHORT Sequence;
  2463. };
  2464. } SLIST_HEADER, *PSLIST_HEADER;
  2465. #endif
  2466. #endif
  2467. //
  2468. // If debugging support enabled, define an ASSERT macro that works. Otherwise
  2469. // define the ASSERT macro to expand to an empty expression.
  2470. //
  2471. // The ASSERT macro has been updated to be an expression instead of a statement.
  2472. //
  2473. #if DBG
  2474. NTSYSAPI
  2475. VOID
  2476. NTAPI
  2477. RtlAssert(
  2478. PVOID FailedAssertion,
  2479. PVOID FileName,
  2480. ULONG LineNumber,
  2481. PCHAR Message
  2482. );
  2483. #define ASSERT( exp ) \
  2484. ((!(exp)) ? \
  2485. (RtlAssert( #exp, __FILE__, __LINE__, NULL ),FALSE) : \
  2486. TRUE)
  2487. #define ASSERTMSG( msg, exp ) \
  2488. ((!(exp)) ? \
  2489. (RtlAssert( #exp, __FILE__, __LINE__, msg ),FALSE) : \
  2490. TRUE)
  2491. #define RTL_SOFT_ASSERT(_exp) \
  2492. ((!(_exp)) ? \
  2493. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #_exp),FALSE) : \
  2494. TRUE)
  2495. #define RTL_SOFT_ASSERTMSG(_msg, _exp) \
  2496. ((!(_exp)) ? \
  2497. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #_exp, (_msg)),FALSE) : \
  2498. TRUE)
  2499. #define RTL_VERIFY( exp ) ASSERT(exp)
  2500. #define RTL_VERIFYMSG( msg, exp ) ASSERT(msg, exp)
  2501. #define RTL_SOFT_VERIFY(_exp) RTL_SOFT_ASSERT(_exp)
  2502. #define RTL_SOFT_VERIFYMSG(_msg, _exp) RTL_SOFT_ASSERTMSG(_msg, _exp)
  2503. #else
  2504. #define ASSERT( exp ) ((void) 0)
  2505. #define ASSERTMSG( msg, exp ) ((void) 0)
  2506. #define RTL_SOFT_ASSERT(_exp) ((void) 0)
  2507. #define RTL_SOFT_ASSERTMSG(_msg, _exp) ((void) 0)
  2508. #define RTL_VERIFY( exp ) ((exp) ? TRUE : FALSE)
  2509. #define RTL_VERIFYMSG( msg, exp ) ((exp) ? TRUE : FALSE)
  2510. #define RTL_SOFT_VERIFY(_exp) ((_exp) ? TRUE : FALSE)
  2511. #define RTL_SOFT_VERIFYMSG(msg, _exp) ((_exp) ? TRUE : FALSE)
  2512. #endif // DBG
  2513. //
  2514. // Doubly-linked list manipulation routines.
  2515. //
  2516. //
  2517. // VOID
  2518. // InitializeListHead32(
  2519. // PLIST_ENTRY32 ListHead
  2520. // );
  2521. //
  2522. #define InitializeListHead32(ListHead) (\
  2523. (ListHead)->Flink = (ListHead)->Blink = PtrToUlong((ListHead)))
  2524. #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
  2525. VOID
  2526. FORCEINLINE
  2527. InitializeListHead(
  2528. IN PLIST_ENTRY ListHead
  2529. )
  2530. {
  2531. ListHead->Flink = ListHead->Blink = ListHead;
  2532. }
  2533. //
  2534. // BOOLEAN
  2535. // IsListEmpty(
  2536. // PLIST_ENTRY ListHead
  2537. // );
  2538. //
  2539. #define IsListEmpty(ListHead) \
  2540. ((ListHead)->Flink == (ListHead))
  2541. VOID
  2542. FORCEINLINE
  2543. RemoveEntryList(
  2544. IN PLIST_ENTRY Entry
  2545. )
  2546. {
  2547. PLIST_ENTRY Blink;
  2548. PLIST_ENTRY Flink;
  2549. Flink = Entry->Flink;
  2550. Blink = Entry->Blink;
  2551. Blink->Flink = Flink;
  2552. Flink->Blink = Blink;
  2553. }
  2554. PLIST_ENTRY
  2555. FORCEINLINE
  2556. RemoveHeadList(
  2557. IN PLIST_ENTRY ListHead
  2558. )
  2559. {
  2560. PLIST_ENTRY Flink;
  2561. PLIST_ENTRY Entry;
  2562. Entry = ListHead->Flink;
  2563. Flink = Entry->Flink;
  2564. ListHead->Flink = Flink;
  2565. Flink->Blink = ListHead;
  2566. return Entry;
  2567. }
  2568. PLIST_ENTRY
  2569. FORCEINLINE
  2570. RemoveTailList(
  2571. IN PLIST_ENTRY ListHead
  2572. )
  2573. {
  2574. PLIST_ENTRY Blink;
  2575. PLIST_ENTRY Entry;
  2576. Entry = ListHead->Blink;
  2577. Blink = Entry->Blink;
  2578. ListHead->Blink = Blink;
  2579. Blink->Flink = ListHead;
  2580. return Entry;
  2581. }
  2582. VOID
  2583. FORCEINLINE
  2584. InsertTailList(
  2585. IN PLIST_ENTRY ListHead,
  2586. IN PLIST_ENTRY Entry
  2587. )
  2588. {
  2589. PLIST_ENTRY Blink;
  2590. Blink = ListHead->Blink;
  2591. Entry->Flink = ListHead;
  2592. Entry->Blink = Blink;
  2593. Blink->Flink = Entry;
  2594. ListHead->Blink = Entry;
  2595. }
  2596. VOID
  2597. FORCEINLINE
  2598. InsertHeadList(
  2599. IN PLIST_ENTRY ListHead,
  2600. IN PLIST_ENTRY Entry
  2601. )
  2602. {
  2603. PLIST_ENTRY Flink;
  2604. Flink = ListHead->Flink;
  2605. Entry->Flink = Flink;
  2606. Entry->Blink = ListHead;
  2607. Flink->Blink = Entry;
  2608. ListHead->Flink = Entry;
  2609. }
  2610. //
  2611. //
  2612. // PSINGLE_LIST_ENTRY
  2613. // PopEntryList(
  2614. // PSINGLE_LIST_ENTRY ListHead
  2615. // );
  2616. //
  2617. #define PopEntryList(ListHead) \
  2618. (ListHead)->Next;\
  2619. {\
  2620. PSINGLE_LIST_ENTRY FirstEntry;\
  2621. FirstEntry = (ListHead)->Next;\
  2622. if (FirstEntry != NULL) { \
  2623. (ListHead)->Next = FirstEntry->Next;\
  2624. } \
  2625. }
  2626. //
  2627. // VOID
  2628. // PushEntryList(
  2629. // PSINGLE_LIST_ENTRY ListHead,
  2630. // PSINGLE_LIST_ENTRY Entry
  2631. // );
  2632. //
  2633. #define PushEntryList(ListHead,Entry) \
  2634. (Entry)->Next = (ListHead)->Next; \
  2635. (ListHead)->Next = (Entry)
  2636. #endif // !MIDL_PASS
  2637. //
  2638. // This enumerated type is used as the function return value of the function
  2639. // that is used to search the tree for a key. FoundNode indicates that the
  2640. // function found the key. Insert as left indicates that the key was not found
  2641. // and the node should be inserted as the left child of the parent. Insert as
  2642. // right indicates that the key was not found and the node should be inserted
  2643. // as the right child of the parent.
  2644. //
  2645. typedef enum _TABLE_SEARCH_RESULT{
  2646. TableEmptyTree,
  2647. TableFoundNode,
  2648. TableInsertAsLeft,
  2649. TableInsertAsRight
  2650. } TABLE_SEARCH_RESULT;
  2651. //
  2652. // The results of a compare can be less than, equal, or greater than.
  2653. //
  2654. typedef enum _RTL_GENERIC_COMPARE_RESULTS {
  2655. GenericLessThan,
  2656. GenericGreaterThan,
  2657. GenericEqual
  2658. } RTL_GENERIC_COMPARE_RESULTS;
  2659. //
  2660. // Define the Avl version of the generic table package. Note a generic table
  2661. // should really be an opaque type. We provide routines to manipulate the structure.
  2662. //
  2663. // A generic table is package for inserting, deleting, and looking up elements
  2664. // in a table (e.g., in a symbol table). To use this package the user
  2665. // defines the structure of the elements stored in the table, provides a
  2666. // comparison function, a memory allocation function, and a memory
  2667. // deallocation function.
  2668. //
  2669. // Note: the user compare function must impose a complete ordering among
  2670. // all of the elements, and the table does not allow for duplicate entries.
  2671. //
  2672. //
  2673. // Add an empty typedef so that functions can reference the
  2674. // a pointer to the generic table struct before it is declared.
  2675. //
  2676. struct _RTL_AVL_TABLE;
  2677. //
  2678. // The comparison function takes as input pointers to elements containing
  2679. // user defined structures and returns the results of comparing the two
  2680. // elements.
  2681. //
  2682. typedef
  2683. RTL_GENERIC_COMPARE_RESULTS
  2684. (NTAPI *PRTL_AVL_COMPARE_ROUTINE) (
  2685. struct _RTL_AVL_TABLE *Table,
  2686. PVOID FirstStruct,
  2687. PVOID SecondStruct
  2688. );
  2689. //
  2690. // The allocation function is called by the generic table package whenever
  2691. // it needs to allocate memory for the table.
  2692. //
  2693. typedef
  2694. PVOID
  2695. (NTAPI *PRTL_AVL_ALLOCATE_ROUTINE) (
  2696. struct _RTL_AVL_TABLE *Table,
  2697. CLONG ByteSize
  2698. );
  2699. //
  2700. // The deallocation function is called by the generic table package whenever
  2701. // it needs to deallocate memory from the table that was allocated by calling
  2702. // the user supplied allocation function.
  2703. //
  2704. typedef
  2705. VOID
  2706. (NTAPI *PRTL_AVL_FREE_ROUTINE) (
  2707. struct _RTL_AVL_TABLE *Table,
  2708. PVOID Buffer
  2709. );
  2710. //
  2711. // The match function takes as input the user data to be matched and a pointer
  2712. // to some match data, which was passed along with the function pointer. It
  2713. // returns TRUE for a match and FALSE for no match.
  2714. //
  2715. // RTL_AVL_MATCH_FUNCTION returns
  2716. // STATUS_SUCCESS if the IndexRow matches
  2717. // STATUS_NO_MATCH if the IndexRow does not match, but the enumeration should
  2718. // continue
  2719. // STATUS_NO_MORE_MATCHES if the IndexRow does not match, and the enumeration
  2720. // should terminate
  2721. //
  2722. typedef
  2723. NTSTATUS
  2724. (NTAPI *PRTL_AVL_MATCH_FUNCTION) (
  2725. struct _RTL_AVL_TABLE *Table,
  2726. PVOID UserData,
  2727. PVOID MatchData
  2728. );
  2729. //
  2730. // Define the balanced tree links and Balance field. (No Rank field
  2731. // defined at this time.)
  2732. //
  2733. // Callers should treat this structure as opaque!
  2734. //
  2735. // The root of a balanced binary tree is not a real node in the tree
  2736. // but rather points to a real node which is the root. It is always
  2737. // in the table below, and its fields are used as follows:
  2738. //
  2739. // Parent Pointer to self, to allow for detection of the root.
  2740. // LeftChild NULL
  2741. // RightChild Pointer to real root
  2742. // Balance Undefined, however it is set to a convenient value
  2743. // (depending on the algorithm) prior to rebalancing
  2744. // in insert and delete routines.
  2745. //
  2746. typedef struct _RTL_BALANCED_LINKS {
  2747. struct _RTL_BALANCED_LINKS *Parent;
  2748. struct _RTL_BALANCED_LINKS *LeftChild;
  2749. struct _RTL_BALANCED_LINKS *RightChild;
  2750. CHAR Balance;
  2751. UCHAR Reserved[3];
  2752. } RTL_BALANCED_LINKS;
  2753. typedef RTL_BALANCED_LINKS *PRTL_BALANCED_LINKS;
  2754. //
  2755. // To use the generic table package the user declares a variable of type
  2756. // GENERIC_TABLE and then uses the routines described below to initialize
  2757. // the table and to manipulate the table. Note that the generic table
  2758. // should really be an opaque type.
  2759. //
  2760. typedef struct _RTL_AVL_TABLE {
  2761. RTL_BALANCED_LINKS BalancedRoot;
  2762. PVOID OrderedPointer;
  2763. ULONG WhichOrderedElement;
  2764. ULONG NumberGenericTableElements;
  2765. ULONG DepthOfTree;
  2766. PRTL_BALANCED_LINKS RestartKey;
  2767. ULONG DeleteCount;
  2768. PRTL_AVL_COMPARE_ROUTINE CompareRoutine;
  2769. PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine;
  2770. PRTL_AVL_FREE_ROUTINE FreeRoutine;
  2771. PVOID TableContext;
  2772. } RTL_AVL_TABLE;
  2773. typedef RTL_AVL_TABLE *PRTL_AVL_TABLE;
  2774. //
  2775. // The procedure InitializeGenericTable takes as input an uninitialized
  2776. // generic table variable and pointers to the three user supplied routines.
  2777. // This must be called for every individual generic table variable before
  2778. // it can be used.
  2779. //
  2780. NTSYSAPI
  2781. VOID
  2782. NTAPI
  2783. RtlInitializeGenericTableAvl (
  2784. PRTL_AVL_TABLE Table,
  2785. PRTL_AVL_COMPARE_ROUTINE CompareRoutine,
  2786. PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine,
  2787. PRTL_AVL_FREE_ROUTINE FreeRoutine,
  2788. PVOID TableContext
  2789. );
  2790. //
  2791. // The function InsertElementGenericTable will insert a new element
  2792. // in a table. It does this by allocating space for the new element
  2793. // (this includes AVL links), inserting the element in the table, and
  2794. // then returning to the user a pointer to the new element. If an element
  2795. // with the same key already exists in the table the return value is a pointer
  2796. // to the old element. The optional output parameter NewElement is used
  2797. // to indicate if the element previously existed in the table. Note: the user
  2798. // supplied Buffer is only used for searching the table, upon insertion its
  2799. // contents are copied to the newly created element. This means that
  2800. // pointer to the input buffer will not point to the new element.
  2801. //
  2802. NTSYSAPI
  2803. PVOID
  2804. NTAPI
  2805. RtlInsertElementGenericTableAvl (
  2806. PRTL_AVL_TABLE Table,
  2807. PVOID Buffer,
  2808. CLONG BufferSize,
  2809. PBOOLEAN NewElement OPTIONAL
  2810. );
  2811. //
  2812. // The function InsertElementGenericTableFull will insert a new element
  2813. // in a table. It does this by allocating space for the new element
  2814. // (this includes AVL links), inserting the element in the table, and
  2815. // then returning to the user a pointer to the new element. If an element
  2816. // with the same key already exists in the table the return value is a pointer
  2817. // to the old element. The optional output parameter NewElement is used
  2818. // to indicate if the element previously existed in the table. Note: the user
  2819. // supplied Buffer is only used for searching the table, upon insertion its
  2820. // contents are copied to the newly created element. This means that
  2821. // pointer to the input buffer will not point to the new element.
  2822. // This routine is passed the NodeOrParent and SearchResult from a
  2823. // previous RtlLookupElementGenericTableFull.
  2824. //
  2825. NTSYSAPI
  2826. PVOID
  2827. NTAPI
  2828. RtlInsertElementGenericTableFullAvl (
  2829. PRTL_AVL_TABLE Table,
  2830. PVOID Buffer,
  2831. CLONG BufferSize,
  2832. PBOOLEAN NewElement OPTIONAL,
  2833. PVOID NodeOrParent,
  2834. TABLE_SEARCH_RESULT SearchResult
  2835. );
  2836. //
  2837. // The function DeleteElementGenericTable will find and delete an element
  2838. // from a generic table. If the element is located and deleted the return
  2839. // value is TRUE, otherwise if the element is not located the return value
  2840. // is FALSE. The user supplied input buffer is only used as a key in
  2841. // locating the element in the table.
  2842. //
  2843. NTSYSAPI
  2844. BOOLEAN
  2845. NTAPI
  2846. RtlDeleteElementGenericTableAvl (
  2847. PRTL_AVL_TABLE Table,
  2848. PVOID Buffer
  2849. );
  2850. //
  2851. // The function LookupElementGenericTable will find an element in a generic
  2852. // table. If the element is located the return value is a pointer to
  2853. // the user defined structure associated with the element, otherwise if
  2854. // the element is not located the return value is NULL. The user supplied
  2855. // input buffer is only used as a key in locating the element in the table.
  2856. //
  2857. NTSYSAPI
  2858. PVOID
  2859. NTAPI
  2860. RtlLookupElementGenericTableAvl (
  2861. PRTL_AVL_TABLE Table,
  2862. PVOID Buffer
  2863. );
  2864. //
  2865. // The function LookupElementGenericTableFull will find an element in a generic
  2866. // table. If the element is located the return value is a pointer to
  2867. // the user defined structure associated with the element. If the element is not
  2868. // located then a pointer to the parent for the insert location is returned. The
  2869. // user must look at the SearchResult value to determine which is being returned.
  2870. // The user can use the SearchResult and parent for a subsequent FullInsertElement
  2871. // call to optimize the insert.
  2872. //
  2873. NTSYSAPI
  2874. PVOID
  2875. NTAPI
  2876. RtlLookupElementGenericTableFullAvl (
  2877. PRTL_AVL_TABLE Table,
  2878. PVOID Buffer,
  2879. OUT PVOID *NodeOrParent,
  2880. OUT TABLE_SEARCH_RESULT *SearchResult
  2881. );
  2882. //
  2883. // The function EnumerateGenericTable will return to the caller one-by-one
  2884. // the elements of of a table. The return value is a pointer to the user
  2885. // defined structure associated with the element. The input parameter
  2886. // Restart indicates if the enumeration should start from the beginning
  2887. // or should return the next element. If the are no more new elements to
  2888. // return the return value is NULL. As an example of its use, to enumerate
  2889. // all of the elements in a table the user would write:
  2890. //
  2891. // for (ptr = EnumerateGenericTable(Table, TRUE);
  2892. // ptr != NULL;
  2893. // ptr = EnumerateGenericTable(Table, FALSE)) {
  2894. // :
  2895. // }
  2896. //
  2897. // NOTE: This routine does not modify the structure of the tree, but saves
  2898. // the last node returned in the generic table itself, and for this
  2899. // reason requires exclusive access to the table for the duration of
  2900. // the enumeration.
  2901. //
  2902. NTSYSAPI
  2903. PVOID
  2904. NTAPI
  2905. RtlEnumerateGenericTableAvl (
  2906. PRTL_AVL_TABLE Table,
  2907. BOOLEAN Restart
  2908. );
  2909. //
  2910. // The function EnumerateGenericTableWithoutSplaying will return to the
  2911. // caller one-by-one the elements of of a table. The return value is a
  2912. // pointer to the user defined structure associated with the element.
  2913. // The input parameter RestartKey indicates if the enumeration should
  2914. // start from the beginning or should return the next element. If the
  2915. // are no more new elements to return the return value is NULL. As an
  2916. // example of its use, to enumerate all of the elements in a table the
  2917. // user would write:
  2918. //
  2919. // RestartKey = NULL;
  2920. // for (ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey);
  2921. // ptr != NULL;
  2922. // ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey)) {
  2923. // :
  2924. // }
  2925. //
  2926. // If RestartKey is NULL, the package will start from the least entry in the
  2927. // table, otherwise it will start from the last entry returned.
  2928. //
  2929. // NOTE: This routine does not modify either the structure of the tree
  2930. // or the generic table itself, but must insure that no deletes
  2931. // occur for the duration of the enumeration, typically by having
  2932. // at least shared access to the table for the duration.
  2933. //
  2934. NTSYSAPI
  2935. PVOID
  2936. NTAPI
  2937. RtlEnumerateGenericTableWithoutSplayingAvl (
  2938. PRTL_AVL_TABLE Table,
  2939. PVOID *RestartKey
  2940. );
  2941. //
  2942. // The function EnumerateGenericTableLikeADirectory will return to the
  2943. // caller one-by-one the elements of of a table. The return value is a
  2944. // pointer to the user defined structure associated with the element.
  2945. // The input parameter RestartKey indicates if the enumeration should
  2946. // start from the beginning or should return the next element. If the
  2947. // are no more new elements to return the return value is NULL. As an
  2948. // example of its use, to enumerate all of the elements in a table the
  2949. // user would write:
  2950. //
  2951. // RestartKey = NULL;
  2952. // for (ptr = EnumerateGenericTableLikeADirectory(Table, &RestartKey, ...);
  2953. // ptr != NULL;
  2954. // ptr = EnumerateGenericTableLikeADirectory(Table, &RestartKey, ...)) {
  2955. // :
  2956. // }
  2957. //
  2958. // If RestartKey is NULL, the package will start from the least entry in the
  2959. // table, otherwise it will start from the last entry returned.
  2960. //
  2961. // NOTE: This routine does not modify either the structure of the tree
  2962. // or the generic table itself. The table must only be acquired
  2963. // shared for the duration of this call, and all synchronization
  2964. // may optionally be dropped between calls. Enumeration is always
  2965. // correctly resumed in the most efficient manner possible via the
  2966. // IN OUT parameters provided.
  2967. //
  2968. // ****** Explain NextFlag. Directory enumeration resumes from a key
  2969. // requires more thought. Also need the match pattern and IgnoreCase.
  2970. // Should some structure be introduced to carry it all?
  2971. //
  2972. NTSYSAPI
  2973. PVOID
  2974. NTAPI
  2975. RtlEnumerateGenericTableLikeADirectory (
  2976. IN PRTL_AVL_TABLE Table,
  2977. IN PRTL_AVL_MATCH_FUNCTION MatchFunction,
  2978. IN PVOID MatchData,
  2979. IN ULONG NextFlag,
  2980. IN OUT PVOID *RestartKey,
  2981. IN OUT PULONG DeleteCount,
  2982. IN OUT PVOID Buffer
  2983. );
  2984. //
  2985. // The function GetElementGenericTable will return the i'th element
  2986. // inserted in the generic table. I = 0 implies the first element,
  2987. // I = (RtlNumberGenericTableElements(Table)-1) will return the last element
  2988. // inserted into the generic table. The type of I is ULONG. Values
  2989. // of I > than (NumberGenericTableElements(Table)-1) will return NULL. If
  2990. // an arbitrary element is deleted from the generic table it will cause
  2991. // all elements inserted after the deleted element to "move up".
  2992. NTSYSAPI
  2993. PVOID
  2994. NTAPI
  2995. RtlGetElementGenericTableAvl (
  2996. PRTL_AVL_TABLE Table,
  2997. ULONG I
  2998. );
  2999. //
  3000. // The function NumberGenericTableElements returns a ULONG value
  3001. // which is the number of generic table elements currently inserted
  3002. // in the generic table.
  3003. NTSYSAPI
  3004. ULONG
  3005. NTAPI
  3006. RtlNumberGenericTableElementsAvl (
  3007. PRTL_AVL_TABLE Table
  3008. );
  3009. //
  3010. // The function IsGenericTableEmpty will return to the caller TRUE if
  3011. // the input table is empty (i.e., does not contain any elements) and
  3012. // FALSE otherwise.
  3013. //
  3014. NTSYSAPI
  3015. BOOLEAN
  3016. NTAPI
  3017. RtlIsGenericTableEmptyAvl (
  3018. PRTL_AVL_TABLE Table
  3019. );
  3020. //
  3021. // As an aid to allowing existing generic table users to do (in most
  3022. // cases) a single-line edit to switch over to Avl table use, we
  3023. // have the following defines and inline routine definitions which
  3024. // redirect calls and types. Note that the type override (performed
  3025. // by #define below) will not work in the unexpected event that someone
  3026. // has used a pointer or type specifier in their own #define, since
  3027. // #define processing is one pass and does not nest. The __inline
  3028. // declarations below do not have this limitation, however.
  3029. //
  3030. // To switch to using Avl tables, add the following line before your
  3031. // includes:
  3032. //
  3033. // #define RTL_USE_AVL_TABLES 0
  3034. //
  3035. #ifdef RTL_USE_AVL_TABLES
  3036. #undef PRTL_GENERIC_COMPARE_ROUTINE
  3037. #undef PRTL_GENERIC_ALLOCATE_ROUTINE
  3038. #undef PRTL_GENERIC_FREE_ROUTINE
  3039. #undef RTL_GENERIC_TABLE
  3040. #undef PRTL_GENERIC_TABLE
  3041. #define PRTL_GENERIC_COMPARE_ROUTINE PRTL_AVL_COMPARE_ROUTINE
  3042. #define PRTL_GENERIC_ALLOCATE_ROUTINE PRTL_AVL_ALLOCATE_ROUTINE
  3043. #define PRTL_GENERIC_FREE_ROUTINE PRTL_AVL_FREE_ROUTINE
  3044. #define RTL_GENERIC_TABLE RTL_AVL_TABLE
  3045. #define PRTL_GENERIC_TABLE PRTL_AVL_TABLE
  3046. #define RtlInitializeGenericTable RtlInitializeGenericTableAvl
  3047. #define RtlInsertElementGenericTable RtlInsertElementGenericTableAvl
  3048. #define RtlInsertElementGenericTableFull RtlInsertElementGenericTableFullAvl
  3049. #define RtlDeleteElementGenericTable RtlDeleteElementGenericTableAvl
  3050. #define RtlLookupElementGenericTable RtlLookupElementGenericTableAvl
  3051. #define RtlLookupElementGenericTableFull RtlLookupElementGenericTableFullAvl
  3052. #define RtlEnumerateGenericTable RtlEnumerateGenericTableAvl
  3053. #define RtlEnumerateGenericTableWithoutSplaying RtlEnumerateGenericTableWithoutSplayingAvl
  3054. #define RtlGetElementGenericTable RtlGetElementGenericTableAvl
  3055. #define RtlNumberGenericTableElement RtlNumberGenericTableElementAvl
  3056. #define RtlIsGenericTableEmpty RtlIsGenericTableEmptyAvl
  3057. #endif // RTL_USE_AVL_TABLES
  3058. //
  3059. // Define the splay links and the associated manipuliation macros and
  3060. // routines. Note that the splay_links should be an opaque type.
  3061. // Routine are provided to traverse and manipulate the structure.
  3062. //
  3063. typedef struct _RTL_SPLAY_LINKS {
  3064. struct _RTL_SPLAY_LINKS *Parent;
  3065. struct _RTL_SPLAY_LINKS *LeftChild;
  3066. struct _RTL_SPLAY_LINKS *RightChild;
  3067. } RTL_SPLAY_LINKS;
  3068. typedef RTL_SPLAY_LINKS *PRTL_SPLAY_LINKS;
  3069. //
  3070. // The macro procedure InitializeSplayLinks takes as input a pointer to
  3071. // splay link and initializes its substructure. All splay link nodes must
  3072. // be initialized before they are used in the different splay routines and
  3073. // macros.
  3074. //
  3075. // VOID
  3076. // RtlInitializeSplayLinks (
  3077. // PRTL_SPLAY_LINKS Links
  3078. // );
  3079. //
  3080. #define RtlInitializeSplayLinks(Links) { \
  3081. PRTL_SPLAY_LINKS _SplayLinks; \
  3082. _SplayLinks = (PRTL_SPLAY_LINKS)(Links); \
  3083. _SplayLinks->Parent = _SplayLinks; \
  3084. _SplayLinks->LeftChild = NULL; \
  3085. _SplayLinks->RightChild = NULL; \
  3086. }
  3087. //
  3088. // The macro function Parent takes as input a pointer to a splay link in a
  3089. // tree and returns a pointer to the splay link of the parent of the input
  3090. // node. If the input node is the root of the tree the return value is
  3091. // equal to the input value.
  3092. //
  3093. // PRTL_SPLAY_LINKS
  3094. // RtlParent (
  3095. // PRTL_SPLAY_LINKS Links
  3096. // );
  3097. //
  3098. #define RtlParent(Links) ( \
  3099. (PRTL_SPLAY_LINKS)(Links)->Parent \
  3100. )
  3101. //
  3102. // The macro function LeftChild takes as input a pointer to a splay link in
  3103. // a tree and returns a pointer to the splay link of the left child of the
  3104. // input node. If the left child does not exist, the return value is NULL.
  3105. //
  3106. // PRTL_SPLAY_LINKS
  3107. // RtlLeftChild (
  3108. // PRTL_SPLAY_LINKS Links
  3109. // );
  3110. //
  3111. #define RtlLeftChild(Links) ( \
  3112. (PRTL_SPLAY_LINKS)(Links)->LeftChild \
  3113. )
  3114. //
  3115. // The macro function RightChild takes as input a pointer to a splay link
  3116. // in a tree and returns a pointer to the splay link of the right child of
  3117. // the input node. If the right child does not exist, the return value is
  3118. // NULL.
  3119. //
  3120. // PRTL_SPLAY_LINKS
  3121. // RtlRightChild (
  3122. // PRTL_SPLAY_LINKS Links
  3123. // );
  3124. //
  3125. #define RtlRightChild(Links) ( \
  3126. (PRTL_SPLAY_LINKS)(Links)->RightChild \
  3127. )
  3128. //
  3129. // The macro function IsRoot takes as input a pointer to a splay link
  3130. // in a tree and returns TRUE if the input node is the root of the tree,
  3131. // otherwise it returns FALSE.
  3132. //
  3133. // BOOLEAN
  3134. // RtlIsRoot (
  3135. // PRTL_SPLAY_LINKS Links
  3136. // );
  3137. //
  3138. #define RtlIsRoot(Links) ( \
  3139. (RtlParent(Links) == (PRTL_SPLAY_LINKS)(Links)) \
  3140. )
  3141. //
  3142. // The macro function IsLeftChild takes as input a pointer to a splay link
  3143. // in a tree and returns TRUE if the input node is the left child of its
  3144. // parent, otherwise it returns FALSE.
  3145. //
  3146. // BOOLEAN
  3147. // RtlIsLeftChild (
  3148. // PRTL_SPLAY_LINKS Links
  3149. // );
  3150. //
  3151. #define RtlIsLeftChild(Links) ( \
  3152. (RtlLeftChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links)) \
  3153. )
  3154. //
  3155. // The macro function IsRightChild takes as input a pointer to a splay link
  3156. // in a tree and returns TRUE if the input node is the right child of its
  3157. // parent, otherwise it returns FALSE.
  3158. //
  3159. // BOOLEAN
  3160. // RtlIsRightChild (
  3161. // PRTL_SPLAY_LINKS Links
  3162. // );
  3163. //
  3164. #define RtlIsRightChild(Links) ( \
  3165. (RtlRightChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links)) \
  3166. )
  3167. //
  3168. // The macro procedure InsertAsLeftChild takes as input a pointer to a splay
  3169. // link in a tree and a pointer to a node not in a tree. It inserts the
  3170. // second node as the left child of the first node. The first node must not
  3171. // already have a left child, and the second node must not already have a
  3172. // parent.
  3173. //
  3174. // VOID
  3175. // RtlInsertAsLeftChild (
  3176. // PRTL_SPLAY_LINKS ParentLinks,
  3177. // PRTL_SPLAY_LINKS ChildLinks
  3178. // );
  3179. //
  3180. #define RtlInsertAsLeftChild(ParentLinks,ChildLinks) { \
  3181. PRTL_SPLAY_LINKS _SplayParent; \
  3182. PRTL_SPLAY_LINKS _SplayChild; \
  3183. _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
  3184. _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
  3185. _SplayParent->LeftChild = _SplayChild; \
  3186. _SplayChild->Parent = _SplayParent; \
  3187. }
  3188. //
  3189. // The macro procedure InsertAsRightChild takes as input a pointer to a splay
  3190. // link in a tree and a pointer to a node not in a tree. It inserts the
  3191. // second node as the right child of the first node. The first node must not
  3192. // already have a right child, and the second node must not already have a
  3193. // parent.
  3194. //
  3195. // VOID
  3196. // RtlInsertAsRightChild (
  3197. // PRTL_SPLAY_LINKS ParentLinks,
  3198. // PRTL_SPLAY_LINKS ChildLinks
  3199. // );
  3200. //
  3201. #define RtlInsertAsRightChild(ParentLinks,ChildLinks) { \
  3202. PRTL_SPLAY_LINKS _SplayParent; \
  3203. PRTL_SPLAY_LINKS _SplayChild; \
  3204. _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
  3205. _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
  3206. _SplayParent->RightChild = _SplayChild; \
  3207. _SplayChild->Parent = _SplayParent; \
  3208. }
  3209. //
  3210. // The Splay function takes as input a pointer to a splay link in a tree
  3211. // and splays the tree. Its function return value is a pointer to the
  3212. // root of the splayed tree.
  3213. //
  3214. NTSYSAPI
  3215. PRTL_SPLAY_LINKS
  3216. NTAPI
  3217. RtlSplay (
  3218. PRTL_SPLAY_LINKS Links
  3219. );
  3220. //
  3221. // The Delete function takes as input a pointer to a splay link in a tree
  3222. // and deletes that node from the tree. Its function return value is a
  3223. // pointer to the root of the tree. If the tree is now empty, the return
  3224. // value is NULL.
  3225. //
  3226. NTSYSAPI
  3227. PRTL_SPLAY_LINKS
  3228. NTAPI
  3229. RtlDelete (
  3230. PRTL_SPLAY_LINKS Links
  3231. );
  3232. //
  3233. // The DeleteNoSplay function takes as input a pointer to a splay link in a tree,
  3234. // the caller's pointer to the root of the tree and deletes that node from the
  3235. // tree. Upon return the caller's pointer to the root node will correctly point
  3236. // at the root of the tree.
  3237. //
  3238. // It operationally differs from RtlDelete only in that it will not splay the tree.
  3239. //
  3240. NTSYSAPI
  3241. VOID
  3242. NTAPI
  3243. RtlDeleteNoSplay (
  3244. PRTL_SPLAY_LINKS Links,
  3245. PRTL_SPLAY_LINKS *Root
  3246. );
  3247. //
  3248. // The SubtreeSuccessor function takes as input a pointer to a splay link
  3249. // in a tree and returns a pointer to the successor of the input node of
  3250. // the substree rooted at the input node. If there is not a successor, the
  3251. // return value is NULL.
  3252. //
  3253. NTSYSAPI
  3254. PRTL_SPLAY_LINKS
  3255. NTAPI
  3256. RtlSubtreeSuccessor (
  3257. PRTL_SPLAY_LINKS Links
  3258. );
  3259. //
  3260. // The SubtreePredecessor function takes as input a pointer to a splay link
  3261. // in a tree and returns a pointer to the predecessor of the input node of
  3262. // the substree rooted at the input node. If there is not a predecessor,
  3263. // the return value is NULL.
  3264. //
  3265. NTSYSAPI
  3266. PRTL_SPLAY_LINKS
  3267. NTAPI
  3268. RtlSubtreePredecessor (
  3269. PRTL_SPLAY_LINKS Links
  3270. );
  3271. //
  3272. // The RealSuccessor function takes as input a pointer to a splay link
  3273. // in a tree and returns a pointer to the successor of the input node within
  3274. // the entire tree. If there is not a successor, the return value is NULL.
  3275. //
  3276. NTSYSAPI
  3277. PRTL_SPLAY_LINKS
  3278. NTAPI
  3279. RtlRealSuccessor (
  3280. PRTL_SPLAY_LINKS Links
  3281. );
  3282. //
  3283. // The RealPredecessor function takes as input a pointer to a splay link
  3284. // in a tree and returns a pointer to the predecessor of the input node
  3285. // within the entire tree. If there is not a predecessor, the return value
  3286. // is NULL.
  3287. //
  3288. NTSYSAPI
  3289. PRTL_SPLAY_LINKS
  3290. NTAPI
  3291. RtlRealPredecessor (
  3292. PRTL_SPLAY_LINKS Links
  3293. );
  3294. //
  3295. // Define the generic table package. Note a generic table should really
  3296. // be an opaque type. We provide routines to manipulate the structure.
  3297. //
  3298. // A generic table is package for inserting, deleting, and looking up elements
  3299. // in a table (e.g., in a symbol table). To use this package the user
  3300. // defines the structure of the elements stored in the table, provides a
  3301. // comparison function, a memory allocation function, and a memory
  3302. // deallocation function.
  3303. //
  3304. // Note: the user compare function must impose a complete ordering among
  3305. // all of the elements, and the table does not allow for duplicate entries.
  3306. //
  3307. //
  3308. // Do not do the following defines if using Avl
  3309. //
  3310. #ifndef RTL_USE_AVL_TABLES
  3311. //
  3312. // Add an empty typedef so that functions can reference the
  3313. // a pointer to the generic table struct before it is declared.
  3314. //
  3315. struct _RTL_GENERIC_TABLE;
  3316. //
  3317. // The comparison function takes as input pointers to elements containing
  3318. // user defined structures and returns the results of comparing the two
  3319. // elements.
  3320. //
  3321. typedef
  3322. RTL_GENERIC_COMPARE_RESULTS
  3323. (NTAPI *PRTL_GENERIC_COMPARE_ROUTINE) (
  3324. struct _RTL_GENERIC_TABLE *Table,
  3325. PVOID FirstStruct,
  3326. PVOID SecondStruct
  3327. );
  3328. //
  3329. // The allocation function is called by the generic table package whenever
  3330. // it needs to allocate memory for the table.
  3331. //
  3332. typedef
  3333. PVOID
  3334. (NTAPI *PRTL_GENERIC_ALLOCATE_ROUTINE) (
  3335. struct _RTL_GENERIC_TABLE *Table,
  3336. CLONG ByteSize
  3337. );
  3338. //
  3339. // The deallocation function is called by the generic table package whenever
  3340. // it needs to deallocate memory from the table that was allocated by calling
  3341. // the user supplied allocation function.
  3342. //
  3343. typedef
  3344. VOID
  3345. (NTAPI *PRTL_GENERIC_FREE_ROUTINE) (
  3346. struct _RTL_GENERIC_TABLE *Table,
  3347. PVOID Buffer
  3348. );
  3349. //
  3350. // To use the generic table package the user declares a variable of type
  3351. // GENERIC_TABLE and then uses the routines described below to initialize
  3352. // the table and to manipulate the table. Note that the generic table
  3353. // should really be an opaque type.
  3354. //
  3355. typedef struct _RTL_GENERIC_TABLE {
  3356. PRTL_SPLAY_LINKS TableRoot;
  3357. LIST_ENTRY InsertOrderList;
  3358. PLIST_ENTRY OrderedPointer;
  3359. ULONG WhichOrderedElement;
  3360. ULONG NumberGenericTableElements;
  3361. PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine;
  3362. PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine;
  3363. PRTL_GENERIC_FREE_ROUTINE FreeRoutine;
  3364. PVOID TableContext;
  3365. } RTL_GENERIC_TABLE;
  3366. typedef RTL_GENERIC_TABLE *PRTL_GENERIC_TABLE;
  3367. //
  3368. // The procedure InitializeGenericTable takes as input an uninitialized
  3369. // generic table variable and pointers to the three user supplied routines.
  3370. // This must be called for every individual generic table variable before
  3371. // it can be used.
  3372. //
  3373. NTSYSAPI
  3374. VOID
  3375. NTAPI
  3376. RtlInitializeGenericTable (
  3377. PRTL_GENERIC_TABLE Table,
  3378. PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine,
  3379. PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine,
  3380. PRTL_GENERIC_FREE_ROUTINE FreeRoutine,
  3381. PVOID TableContext
  3382. );
  3383. //
  3384. // The function InsertElementGenericTable will insert a new element
  3385. // in a table. It does this by allocating space for the new element
  3386. // (this includes splay links), inserting the element in the table, and
  3387. // then returning to the user a pointer to the new element. If an element
  3388. // with the same key already exists in the table the return value is a pointer
  3389. // to the old element. The optional output parameter NewElement is used
  3390. // to indicate if the element previously existed in the table. Note: the user
  3391. // supplied Buffer is only used for searching the table, upon insertion its
  3392. // contents are copied to the newly created element. This means that
  3393. // pointer to the input buffer will not point to the new element.
  3394. //
  3395. NTSYSAPI
  3396. PVOID
  3397. NTAPI
  3398. RtlInsertElementGenericTable (
  3399. PRTL_GENERIC_TABLE Table,
  3400. PVOID Buffer,
  3401. CLONG BufferSize,
  3402. PBOOLEAN NewElement OPTIONAL
  3403. );
  3404. //
  3405. // The function InsertElementGenericTableFull will insert a new element
  3406. // in a table. It does this by allocating space for the new element
  3407. // (this includes splay links), inserting the element in the table, and
  3408. // then returning to the user a pointer to the new element. If an element
  3409. // with the same key already exists in the table the return value is a pointer
  3410. // to the old element. The optional output parameter NewElement is used
  3411. // to indicate if the element previously existed in the table. Note: the user
  3412. // supplied Buffer is only used for searching the table, upon insertion its
  3413. // contents are copied to the newly created element. This means that
  3414. // pointer to the input buffer will not point to the new element.
  3415. // This routine is passed the NodeOrParent and SearchResult from a
  3416. // previous RtlLookupElementGenericTableFull.
  3417. //
  3418. NTSYSAPI
  3419. PVOID
  3420. NTAPI
  3421. RtlInsertElementGenericTableFull (
  3422. PRTL_GENERIC_TABLE Table,
  3423. PVOID Buffer,
  3424. CLONG BufferSize,
  3425. PBOOLEAN NewElement OPTIONAL,
  3426. PVOID NodeOrParent,
  3427. TABLE_SEARCH_RESULT SearchResult
  3428. );
  3429. //
  3430. // The function DeleteElementGenericTable will find and delete an element
  3431. // from a generic table. If the element is located and deleted the return
  3432. // value is TRUE, otherwise if the element is not located the return value
  3433. // is FALSE. The user supplied input buffer is only used as a key in
  3434. // locating the element in the table.
  3435. //
  3436. NTSYSAPI
  3437. BOOLEAN
  3438. NTAPI
  3439. RtlDeleteElementGenericTable (
  3440. PRTL_GENERIC_TABLE Table,
  3441. PVOID Buffer
  3442. );
  3443. //
  3444. // The function LookupElementGenericTable will find an element in a generic
  3445. // table. If the element is located the return value is a pointer to
  3446. // the user defined structure associated with the element, otherwise if
  3447. // the element is not located the return value is NULL. The user supplied
  3448. // input buffer is only used as a key in locating the element in the table.
  3449. //
  3450. NTSYSAPI
  3451. PVOID
  3452. NTAPI
  3453. RtlLookupElementGenericTable (
  3454. PRTL_GENERIC_TABLE Table,
  3455. PVOID Buffer
  3456. );
  3457. //
  3458. // The function LookupElementGenericTableFull will find an element in a generic
  3459. // table. If the element is located the return value is a pointer to
  3460. // the user defined structure associated with the element. If the element is not
  3461. // located then a pointer to the parent for the insert location is returned. The
  3462. // user must look at the SearchResult value to determine which is being returned.
  3463. // The user can use the SearchResult and parent for a subsequent FullInsertElement
  3464. // call to optimize the insert.
  3465. //
  3466. NTSYSAPI
  3467. PVOID
  3468. NTAPI
  3469. RtlLookupElementGenericTableFull (
  3470. PRTL_GENERIC_TABLE Table,
  3471. PVOID Buffer,
  3472. OUT PVOID *NodeOrParent,
  3473. OUT TABLE_SEARCH_RESULT *SearchResult
  3474. );
  3475. //
  3476. // The function EnumerateGenericTable will return to the caller one-by-one
  3477. // the elements of of a table. The return value is a pointer to the user
  3478. // defined structure associated with the element. The input parameter
  3479. // Restart indicates if the enumeration should start from the beginning
  3480. // or should return the next element. If the are no more new elements to
  3481. // return the return value is NULL. As an example of its use, to enumerate
  3482. // all of the elements in a table the user would write:
  3483. //
  3484. // for (ptr = EnumerateGenericTable(Table, TRUE);
  3485. // ptr != NULL;
  3486. // ptr = EnumerateGenericTable(Table, FALSE)) {
  3487. // :
  3488. // }
  3489. //
  3490. //
  3491. // PLEASE NOTE:
  3492. //
  3493. // If you enumerate a GenericTable using RtlEnumerateGenericTable, you
  3494. // will flatten the table, turning it into a sorted linked list.
  3495. // To enumerate the table without perturbing the splay links, use
  3496. // RtlEnumerateGenericTableWithoutSplaying
  3497. NTSYSAPI
  3498. PVOID
  3499. NTAPI
  3500. RtlEnumerateGenericTable (
  3501. PRTL_GENERIC_TABLE Table,
  3502. BOOLEAN Restart
  3503. );
  3504. //
  3505. // The function EnumerateGenericTableWithoutSplaying will return to the
  3506. // caller one-by-one the elements of of a table. The return value is a
  3507. // pointer to the user defined structure associated with the element.
  3508. // The input parameter RestartKey indicates if the enumeration should
  3509. // start from the beginning or should return the next element. If the
  3510. // are no more new elements to return the return value is NULL. As an
  3511. // example of its use, to enumerate all of the elements in a table the
  3512. // user would write:
  3513. //
  3514. // RestartKey = NULL;
  3515. // for (ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey);
  3516. // ptr != NULL;
  3517. // ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey)) {
  3518. // :
  3519. // }
  3520. //
  3521. // If RestartKey is NULL, the package will start from the least entry in the
  3522. // table, otherwise it will start from the last entry returned.
  3523. //
  3524. //
  3525. // Note that unlike RtlEnumerateGenericTable, this routine will NOT perturb
  3526. // the splay order of the tree.
  3527. //
  3528. NTSYSAPI
  3529. PVOID
  3530. NTAPI
  3531. RtlEnumerateGenericTableWithoutSplaying (
  3532. PRTL_GENERIC_TABLE Table,
  3533. PVOID *RestartKey
  3534. );
  3535. //
  3536. // The function GetElementGenericTable will return the i'th element
  3537. // inserted in the generic table. I = 0 implies the first element,
  3538. // I = (RtlNumberGenericTableElements(Table)-1) will return the last element
  3539. // inserted into the generic table. The type of I is ULONG. Values
  3540. // of I > than (NumberGenericTableElements(Table)-1) will return NULL. If
  3541. // an arbitrary element is deleted from the generic table it will cause
  3542. // all elements inserted after the deleted element to "move up".
  3543. NTSYSAPI
  3544. PVOID
  3545. NTAPI
  3546. RtlGetElementGenericTable(
  3547. PRTL_GENERIC_TABLE Table,
  3548. ULONG I
  3549. );
  3550. //
  3551. // The function NumberGenericTableElements returns a ULONG value
  3552. // which is the number of generic table elements currently inserted
  3553. // in the generic table.
  3554. NTSYSAPI
  3555. ULONG
  3556. NTAPI
  3557. RtlNumberGenericTableElements(
  3558. PRTL_GENERIC_TABLE Table
  3559. );
  3560. //
  3561. // The function IsGenericTableEmpty will return to the caller TRUE if
  3562. // the input table is empty (i.e., does not contain any elements) and
  3563. // FALSE otherwise.
  3564. //
  3565. NTSYSAPI
  3566. BOOLEAN
  3567. NTAPI
  3568. RtlIsGenericTableEmpty (
  3569. PRTL_GENERIC_TABLE Table
  3570. );
  3571. #endif // RTL_USE_AVL_TABLES
  3572. typedef NTSTATUS
  3573. (NTAPI * PRTL_HEAP_COMMIT_ROUTINE)(
  3574. IN PVOID Base,
  3575. IN OUT PVOID *CommitAddress,
  3576. IN OUT PSIZE_T CommitSize
  3577. );
  3578. typedef struct _RTL_HEAP_PARAMETERS {
  3579. ULONG Length;
  3580. SIZE_T SegmentReserve;
  3581. SIZE_T SegmentCommit;
  3582. SIZE_T DeCommitFreeBlockThreshold;
  3583. SIZE_T DeCommitTotalFreeThreshold;
  3584. SIZE_T MaximumAllocationSize;
  3585. SIZE_T VirtualMemoryThreshold;
  3586. SIZE_T InitialCommit;
  3587. SIZE_T InitialReserve;
  3588. PRTL_HEAP_COMMIT_ROUTINE CommitRoutine;
  3589. SIZE_T Reserved[ 2 ];
  3590. } RTL_HEAP_PARAMETERS, *PRTL_HEAP_PARAMETERS;
  3591. NTSYSAPI
  3592. PVOID
  3593. NTAPI
  3594. RtlCreateHeap(
  3595. IN ULONG Flags,
  3596. IN PVOID HeapBase OPTIONAL,
  3597. IN SIZE_T ReserveSize OPTIONAL,
  3598. IN SIZE_T CommitSize OPTIONAL,
  3599. IN PVOID Lock OPTIONAL,
  3600. IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL
  3601. );
  3602. #define HEAP_NO_SERIALIZE 0x00000001 // winnt
  3603. #define HEAP_GROWABLE 0x00000002 // winnt
  3604. #define HEAP_GENERATE_EXCEPTIONS 0x00000004 // winnt
  3605. #define HEAP_ZERO_MEMORY 0x00000008 // winnt
  3606. #define HEAP_REALLOC_IN_PLACE_ONLY 0x00000010 // winnt
  3607. #define HEAP_TAIL_CHECKING_ENABLED 0x00000020 // winnt
  3608. #define HEAP_FREE_CHECKING_ENABLED 0x00000040 // winnt
  3609. #define HEAP_DISABLE_COALESCE_ON_FREE 0x00000080 // winnt
  3610. #define HEAP_CREATE_ALIGN_16 0x00010000 // winnt Create heap with 16 byte alignment (obsolete)
  3611. #define HEAP_CREATE_ENABLE_TRACING 0x00020000 // winnt Create heap call tracing enabled (obsolete)
  3612. #define HEAP_SETTABLE_USER_VALUE 0x00000100
  3613. #define HEAP_SETTABLE_USER_FLAG1 0x00000200
  3614. #define HEAP_SETTABLE_USER_FLAG2 0x00000400
  3615. #define HEAP_SETTABLE_USER_FLAG3 0x00000800
  3616. #define HEAP_SETTABLE_USER_FLAGS 0x00000E00
  3617. #define HEAP_CLASS_0 0x00000000 // process heap
  3618. #define HEAP_CLASS_1 0x00001000 // private heap
  3619. #define HEAP_CLASS_2 0x00002000 // Kernel Heap
  3620. #define HEAP_CLASS_3 0x00003000 // GDI heap
  3621. #define HEAP_CLASS_4 0x00004000 // User heap
  3622. #define HEAP_CLASS_5 0x00005000 // Console heap
  3623. #define HEAP_CLASS_6 0x00006000 // User Desktop heap
  3624. #define HEAP_CLASS_7 0x00007000 // Csrss Shared heap
  3625. #define HEAP_CLASS_8 0x00008000 // Csr Port heap
  3626. #define HEAP_CLASS_MASK 0x0000F000
  3627. #define HEAP_MAXIMUM_TAG 0x0FFF // winnt
  3628. #define HEAP_GLOBAL_TAG 0x0800
  3629. #define HEAP_PSEUDO_TAG_FLAG 0x8000 // winnt
  3630. #define HEAP_TAG_SHIFT 18 // winnt
  3631. #define HEAP_MAKE_TAG_FLAGS( b, o ) ((ULONG)((b) + ((o) << 18))) // winnt
  3632. #define HEAP_TAG_MASK (HEAP_MAXIMUM_TAG << HEAP_TAG_SHIFT)
  3633. #define HEAP_CREATE_VALID_MASK (HEAP_NO_SERIALIZE | \
  3634. HEAP_GROWABLE | \
  3635. HEAP_GENERATE_EXCEPTIONS | \
  3636. HEAP_ZERO_MEMORY | \
  3637. HEAP_REALLOC_IN_PLACE_ONLY | \
  3638. HEAP_TAIL_CHECKING_ENABLED | \
  3639. HEAP_FREE_CHECKING_ENABLED | \
  3640. HEAP_DISABLE_COALESCE_ON_FREE | \
  3641. HEAP_CLASS_MASK | \
  3642. HEAP_CREATE_ALIGN_16 | \
  3643. HEAP_CREATE_ENABLE_TRACING)
  3644. NTSYSAPI
  3645. PVOID
  3646. NTAPI
  3647. RtlDestroyHeap(
  3648. IN PVOID HeapHandle
  3649. );
  3650. NTSYSAPI
  3651. PVOID
  3652. NTAPI
  3653. RtlAllocateHeap(
  3654. IN PVOID HeapHandle,
  3655. IN ULONG Flags,
  3656. IN SIZE_T Size
  3657. );
  3658. NTSYSAPI
  3659. BOOLEAN
  3660. NTAPI
  3661. RtlFreeHeap(
  3662. IN PVOID HeapHandle,
  3663. IN ULONG Flags,
  3664. IN PVOID BaseAddress
  3665. );
  3666. #if defined (_MSC_VER) && ( _MSC_VER >= 900 )
  3667. PVOID
  3668. _ReturnAddress (
  3669. VOID
  3670. );
  3671. #pragma intrinsic(_ReturnAddress)
  3672. #endif
  3673. #if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
  3674. #define RtlGetCallersAddress(CallersAddress, CallersCaller) \
  3675. *CallersAddress = (PVOID)_ReturnAddress(); \
  3676. *CallersCaller = NULL;
  3677. #else
  3678. NTSYSAPI
  3679. VOID
  3680. NTAPI
  3681. RtlGetCallersAddress(
  3682. OUT PVOID *CallersAddress,
  3683. OUT PVOID *CallersCaller
  3684. );
  3685. #endif
  3686. NTSYSAPI
  3687. ULONG
  3688. NTAPI
  3689. RtlWalkFrameChain (
  3690. OUT PVOID *Callers,
  3691. IN ULONG Count,
  3692. IN ULONG Flags
  3693. );
  3694. typedef NTSTATUS (NTAPI * PRTL_QUERY_REGISTRY_ROUTINE)(
  3695. IN PWSTR ValueName,
  3696. IN ULONG ValueType,
  3697. IN PVOID ValueData,
  3698. IN ULONG ValueLength,
  3699. IN PVOID Context,
  3700. IN PVOID EntryContext
  3701. );
  3702. typedef struct _RTL_QUERY_REGISTRY_TABLE {
  3703. PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
  3704. ULONG Flags;
  3705. PWSTR Name;
  3706. PVOID EntryContext;
  3707. ULONG DefaultType;
  3708. PVOID DefaultData;
  3709. ULONG DefaultLength;
  3710. } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
  3711. //
  3712. // The following flags specify how the Name field of a RTL_QUERY_REGISTRY_TABLE
  3713. // entry is interpreted. A NULL name indicates the end of the table.
  3714. //
  3715. #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001 // Name is a subkey and remainder of
  3716. // table or until next subkey are value
  3717. // names for that subkey to look at.
  3718. #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002 // Reset current key to original key for
  3719. // this and all following table entries.
  3720. #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004 // Fail if no match found for this table
  3721. // entry.
  3722. #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008 // Used to mark a table entry that has no
  3723. // value name, just wants a call out, not
  3724. // an enumeration of all values.
  3725. #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010 // Used to suppress the expansion of
  3726. // REG_MULTI_SZ into multiple callouts or
  3727. // to prevent the expansion of environment
  3728. // variable values in REG_EXPAND_SZ
  3729. #define RTL_QUERY_REGISTRY_DIRECT 0x00000020 // QueryRoutine field ignored. EntryContext
  3730. // field points to location to store value.
  3731. // For null terminated strings, EntryContext
  3732. // points to UNICODE_STRING structure that
  3733. // that describes maximum size of buffer.
  3734. // If .Buffer field is NULL then a buffer is
  3735. // allocated.
  3736. //
  3737. #define RTL_QUERY_REGISTRY_DELETE 0x00000040 // Used to delete value keys after they
  3738. // are queried.
  3739. NTSYSAPI
  3740. NTSTATUS
  3741. NTAPI
  3742. RtlQueryRegistryValues(
  3743. IN ULONG RelativeTo,
  3744. IN PCWSTR Path,
  3745. IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
  3746. IN PVOID Context,
  3747. IN PVOID Environment OPTIONAL
  3748. );
  3749. NTSYSAPI
  3750. NTSTATUS
  3751. NTAPI
  3752. RtlWriteRegistryValue(
  3753. IN ULONG RelativeTo,
  3754. IN PCWSTR Path,
  3755. IN PCWSTR ValueName,
  3756. IN ULONG ValueType,
  3757. IN PVOID ValueData,
  3758. IN ULONG ValueLength
  3759. );
  3760. NTSYSAPI
  3761. NTSTATUS
  3762. NTAPI
  3763. RtlDeleteRegistryValue(
  3764. IN ULONG RelativeTo,
  3765. IN PCWSTR Path,
  3766. IN PCWSTR ValueName
  3767. );
  3768. // end_wdm
  3769. NTSYSAPI
  3770. NTSTATUS
  3771. NTAPI
  3772. RtlCreateRegistryKey(
  3773. IN ULONG RelativeTo,
  3774. IN PWSTR Path
  3775. );
  3776. NTSYSAPI
  3777. NTSTATUS
  3778. NTAPI
  3779. RtlCheckRegistryKey(
  3780. IN ULONG RelativeTo,
  3781. IN PWSTR Path
  3782. );
  3783. // begin_wdm
  3784. //
  3785. // The following values for the RelativeTo parameter determine what the
  3786. // Path parameter to RtlQueryRegistryValues is relative to.
  3787. //
  3788. #define RTL_REGISTRY_ABSOLUTE 0 // Path is a full path
  3789. #define RTL_REGISTRY_SERVICES 1 // \Registry\Machine\System\CurrentControlSet\Services
  3790. #define RTL_REGISTRY_CONTROL 2 // \Registry\Machine\System\CurrentControlSet\Control
  3791. #define RTL_REGISTRY_WINDOWS_NT 3 // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
  3792. #define RTL_REGISTRY_DEVICEMAP 4 // \Registry\Machine\Hardware\DeviceMap
  3793. #define RTL_REGISTRY_USER 5 // \Registry\User\CurrentUser
  3794. #define RTL_REGISTRY_MAXIMUM 6
  3795. #define RTL_REGISTRY_HANDLE 0x40000000 // Low order bits are registry handle
  3796. #define RTL_REGISTRY_OPTIONAL 0x80000000 // Indicates the key node is optional
  3797. NTSYSAPI
  3798. ULONG
  3799. NTAPI
  3800. RtlRandom (
  3801. PULONG Seed
  3802. );
  3803. NTSYSAPI
  3804. ULONG
  3805. NTAPI
  3806. RtlRandomEx (
  3807. PULONG Seed
  3808. );
  3809. NTSYSAPI
  3810. NTSTATUS
  3811. NTAPI
  3812. RtlCharToInteger (
  3813. PCSZ String,
  3814. ULONG Base,
  3815. PULONG Value
  3816. );
  3817. NTSYSAPI
  3818. NTSTATUS
  3819. NTAPI
  3820. RtlIntegerToUnicodeString (
  3821. ULONG Value,
  3822. ULONG Base,
  3823. PUNICODE_STRING String
  3824. );
  3825. NTSYSAPI
  3826. NTSTATUS
  3827. NTAPI
  3828. RtlInt64ToUnicodeString (
  3829. IN ULONGLONG Value,
  3830. IN ULONG Base OPTIONAL,
  3831. IN OUT PUNICODE_STRING String
  3832. );
  3833. #ifdef _WIN64
  3834. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlInt64ToUnicodeString(Value, Base, String)
  3835. #else
  3836. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlIntegerToUnicodeString(Value, Base, String)
  3837. #endif
  3838. NTSYSAPI
  3839. NTSTATUS
  3840. NTAPI
  3841. RtlUnicodeStringToInteger (
  3842. PCUNICODE_STRING String,
  3843. ULONG Base,
  3844. PULONG Value
  3845. );
  3846. //
  3847. // String manipulation routines
  3848. //
  3849. #ifdef _NTSYSTEM_
  3850. #define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
  3851. #define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
  3852. #else
  3853. #define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
  3854. #define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  3855. #endif // _NTSYSTEM_
  3856. extern BOOLEAN NLS_MB_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  3857. extern BOOLEAN NLS_MB_OEM_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  3858. NTSYSAPI
  3859. VOID
  3860. NTAPI
  3861. RtlInitString(
  3862. PSTRING DestinationString,
  3863. PCSZ SourceString
  3864. );
  3865. NTSYSAPI
  3866. VOID
  3867. NTAPI
  3868. RtlInitAnsiString(
  3869. PANSI_STRING DestinationString,
  3870. PCSZ SourceString
  3871. );
  3872. NTSYSAPI
  3873. VOID
  3874. NTAPI
  3875. RtlInitUnicodeString(
  3876. PUNICODE_STRING DestinationString,
  3877. PCWSTR SourceString
  3878. );
  3879. #define RtlInitEmptyUnicodeString(_ucStr,_buf,_bufSize) \
  3880. ((_ucStr)->Buffer = (_buf), \
  3881. (_ucStr)->Length = 0, \
  3882. (_ucStr)->MaximumLength = (USHORT)(_bufSize))
  3883. // end_ntddk end_wdm
  3884. NTSYSAPI
  3885. NTSTATUS
  3886. NTAPI
  3887. RtlInitUnicodeStringEx(
  3888. PUNICODE_STRING DestinationString,
  3889. PCWSTR SourceString
  3890. );
  3891. NTSYSAPI
  3892. BOOLEAN
  3893. NTAPI
  3894. RtlCreateUnicodeString(
  3895. OUT PUNICODE_STRING DestinationString,
  3896. IN PCWSTR SourceString
  3897. );
  3898. NTSYSAPI
  3899. VOID
  3900. NTAPI
  3901. RtlCopyString(
  3902. PSTRING DestinationString,
  3903. const STRING * SourceString
  3904. );
  3905. NTSYSAPI
  3906. CHAR
  3907. NTAPI
  3908. RtlUpperChar (
  3909. CHAR Character
  3910. );
  3911. NTSYSAPI
  3912. LONG
  3913. NTAPI
  3914. RtlCompareString(
  3915. const STRING * String1,
  3916. const STRING * String2,
  3917. BOOLEAN CaseInSensitive
  3918. );
  3919. NTSYSAPI
  3920. BOOLEAN
  3921. NTAPI
  3922. RtlEqualString(
  3923. const STRING * String1,
  3924. const STRING * String2,
  3925. BOOLEAN CaseInSensitive
  3926. );
  3927. NTSYSAPI
  3928. VOID
  3929. NTAPI
  3930. RtlUpperString(
  3931. PSTRING DestinationString,
  3932. const STRING * SourceString
  3933. );
  3934. NTSYSAPI
  3935. NTSTATUS
  3936. NTAPI
  3937. RtlAppendStringToString (
  3938. PSTRING Destination,
  3939. const STRING * Source
  3940. );
  3941. // begin_ntddk begin_wdm
  3942. //
  3943. // NLS String functions
  3944. //
  3945. NTSYSAPI
  3946. NTSTATUS
  3947. NTAPI
  3948. RtlAnsiStringToUnicodeString(
  3949. PUNICODE_STRING DestinationString,
  3950. PCANSI_STRING SourceString,
  3951. BOOLEAN AllocateDestinationString
  3952. );
  3953. NTSYSAPI
  3954. NTSTATUS
  3955. NTAPI
  3956. RtlUnicodeStringToAnsiString(
  3957. PANSI_STRING DestinationString,
  3958. PCUNICODE_STRING SourceString,
  3959. BOOLEAN AllocateDestinationString
  3960. );
  3961. NTSYSAPI
  3962. NTSTATUS
  3963. NTAPI
  3964. RtlOemStringToUnicodeString(
  3965. PUNICODE_STRING DestinationString,
  3966. PCOEM_STRING SourceString,
  3967. BOOLEAN AllocateDestinationString
  3968. );
  3969. NTSYSAPI
  3970. NTSTATUS
  3971. NTAPI
  3972. RtlUnicodeStringToOemString(
  3973. POEM_STRING DestinationString,
  3974. PCUNICODE_STRING SourceString,
  3975. BOOLEAN AllocateDestinationString
  3976. );
  3977. NTSYSAPI
  3978. NTSTATUS
  3979. NTAPI
  3980. RtlUpcaseUnicodeStringToOemString(
  3981. POEM_STRING DestinationString,
  3982. PCUNICODE_STRING SourceString,
  3983. BOOLEAN AllocateDestinationString
  3984. );
  3985. NTSYSAPI
  3986. NTSTATUS
  3987. NTAPI
  3988. RtlOemStringToCountedUnicodeString(
  3989. PUNICODE_STRING DestinationString,
  3990. PCOEM_STRING SourceString,
  3991. BOOLEAN AllocateDestinationString
  3992. );
  3993. NTSYSAPI
  3994. NTSTATUS
  3995. NTAPI
  3996. RtlUnicodeStringToCountedOemString(
  3997. POEM_STRING DestinationString,
  3998. PCUNICODE_STRING SourceString,
  3999. BOOLEAN AllocateDestinationString
  4000. );
  4001. NTSYSAPI
  4002. NTSTATUS
  4003. NTAPI
  4004. RtlUpcaseUnicodeStringToCountedOemString(
  4005. POEM_STRING DestinationString,
  4006. PCUNICODE_STRING SourceString,
  4007. BOOLEAN AllocateDestinationString
  4008. );
  4009. // begin_ntddk begin_wdm begin_ntndis
  4010. NTSYSAPI
  4011. LONG
  4012. NTAPI
  4013. RtlCompareUnicodeString(
  4014. PCUNICODE_STRING String1,
  4015. PCUNICODE_STRING String2,
  4016. BOOLEAN CaseInSensitive
  4017. );
  4018. NTSYSAPI
  4019. BOOLEAN
  4020. NTAPI
  4021. RtlEqualUnicodeString(
  4022. const UNICODE_STRING *String1,
  4023. const UNICODE_STRING *String2,
  4024. BOOLEAN CaseInSensitive
  4025. );
  4026. #define HASH_STRING_ALGORITHM_DEFAULT (0)
  4027. #define HASH_STRING_ALGORITHM_X65599 (1)
  4028. #define HASH_STRING_ALGORITHM_INVALID (0xffffffff)
  4029. NTSYSAPI
  4030. NTSTATUS
  4031. NTAPI
  4032. RtlHashUnicodeString(
  4033. IN const UNICODE_STRING *String,
  4034. IN BOOLEAN CaseInSensitive,
  4035. IN ULONG HashAlgorithm,
  4036. OUT PULONG HashValue
  4037. );
  4038. // end_ntddk end_wdm end_ntndis
  4039. NTSYSAPI
  4040. NTSTATUS
  4041. NTAPI
  4042. RtlValidateUnicodeString(
  4043. IN ULONG Flags,
  4044. IN const UNICODE_STRING *String
  4045. );
  4046. #define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE (0x00000001)
  4047. #define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING (0x00000002)
  4048. NTSYSAPI
  4049. NTSTATUS
  4050. NTAPI
  4051. RtlDuplicateUnicodeString(
  4052. IN ULONG Flags,
  4053. IN const UNICODE_STRING *StringIn,
  4054. OUT UNICODE_STRING *StringOut
  4055. );
  4056. // begin_ntddk begin_ntndis
  4057. NTSYSAPI
  4058. BOOLEAN
  4059. NTAPI
  4060. RtlPrefixUnicodeString(
  4061. IN PUNICODE_STRING String1,
  4062. IN PUNICODE_STRING String2,
  4063. IN BOOLEAN CaseInSensitive
  4064. );
  4065. NTSYSAPI
  4066. NTSTATUS
  4067. NTAPI
  4068. RtlUpcaseUnicodeString(
  4069. PUNICODE_STRING DestinationString,
  4070. PCUNICODE_STRING SourceString,
  4071. BOOLEAN AllocateDestinationString
  4072. );
  4073. NTSTATUS
  4074. RtlDowncaseUnicodeString(
  4075. OUT PUNICODE_STRING DestinationString,
  4076. IN PCUNICODE_STRING SourceString,
  4077. IN BOOLEAN AllocateDestinationString
  4078. );
  4079. NTSYSAPI
  4080. VOID
  4081. NTAPI
  4082. RtlCopyUnicodeString(
  4083. PUNICODE_STRING DestinationString,
  4084. PCUNICODE_STRING SourceString
  4085. );
  4086. NTSYSAPI
  4087. NTSTATUS
  4088. NTAPI
  4089. RtlAppendUnicodeStringToString (
  4090. PUNICODE_STRING Destination,
  4091. PCUNICODE_STRING Source
  4092. );
  4093. NTSYSAPI
  4094. NTSTATUS
  4095. NTAPI
  4096. RtlAppendUnicodeToString (
  4097. PUNICODE_STRING Destination,
  4098. PCWSTR Source
  4099. );
  4100. // end_ntndis end_wdm
  4101. NTSYSAPI
  4102. WCHAR
  4103. NTAPI
  4104. RtlUpcaseUnicodeChar(
  4105. WCHAR SourceCharacter
  4106. );
  4107. NTSYSAPI
  4108. WCHAR
  4109. NTAPI
  4110. RtlDowncaseUnicodeChar(
  4111. WCHAR SourceCharacter
  4112. );
  4113. // begin_wdm
  4114. NTSYSAPI
  4115. VOID
  4116. NTAPI
  4117. RtlFreeUnicodeString(
  4118. PUNICODE_STRING UnicodeString
  4119. );
  4120. NTSYSAPI
  4121. VOID
  4122. NTAPI
  4123. RtlFreeAnsiString(
  4124. PANSI_STRING AnsiString
  4125. );
  4126. // end_ntddk end_wdm end_nthal
  4127. NTSYSAPI
  4128. VOID
  4129. NTAPI
  4130. RtlFreeOemString(
  4131. POEM_STRING OemString
  4132. );
  4133. // begin_wdm
  4134. NTSYSAPI
  4135. ULONG
  4136. NTAPI
  4137. RtlxUnicodeStringToAnsiSize(
  4138. PCUNICODE_STRING UnicodeString
  4139. );
  4140. //
  4141. // NTSYSAPI
  4142. // ULONG
  4143. // NTAPI
  4144. // RtlUnicodeStringToAnsiSize(
  4145. // PUNICODE_STRING UnicodeString
  4146. // );
  4147. //
  4148. #define RtlUnicodeStringToAnsiSize(STRING) ( \
  4149. NLS_MB_CODE_PAGE_TAG ? \
  4150. RtlxUnicodeStringToAnsiSize(STRING) : \
  4151. ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
  4152. )
  4153. // end_wdm
  4154. NTSYSAPI
  4155. ULONG
  4156. NTAPI
  4157. RtlxUnicodeStringToOemSize(
  4158. PCUNICODE_STRING UnicodeString
  4159. );
  4160. //
  4161. // NTSYSAPI
  4162. // ULONG
  4163. // NTAPI
  4164. // RtlUnicodeStringToOemSize(
  4165. // PUNICODE_STRING UnicodeString
  4166. // );
  4167. //
  4168. #define RtlUnicodeStringToOemSize(STRING) ( \
  4169. NLS_MB_OEM_CODE_PAGE_TAG ? \
  4170. RtlxUnicodeStringToOemSize(STRING) : \
  4171. ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
  4172. )
  4173. NTSYSAPI
  4174. ULONG
  4175. NTAPI
  4176. RtlxAnsiStringToUnicodeSize(
  4177. PCANSI_STRING AnsiString
  4178. );
  4179. //
  4180. // NTSYSAPI
  4181. // ULONG
  4182. // NTAPI
  4183. // RtlAnsiStringToUnicodeSize(
  4184. // PANSI_STRING AnsiString
  4185. // );
  4186. //
  4187. #define RtlAnsiStringToUnicodeSize(STRING) ( \
  4188. NLS_MB_CODE_PAGE_TAG ? \
  4189. RtlxAnsiStringToUnicodeSize(STRING) : \
  4190. ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
  4191. )
  4192. // end_ntddk end_wdm
  4193. NTSYSAPI
  4194. ULONG
  4195. NTAPI
  4196. RtlxOemStringToUnicodeSize(
  4197. PCOEM_STRING OemString
  4198. );
  4199. //
  4200. // NTSYSAPI
  4201. // ULONG
  4202. // NTAPI
  4203. // RtlOemStringToUnicodeSize(
  4204. // POEM_STRING OemString
  4205. // );
  4206. //
  4207. #define RtlOemStringToUnicodeSize(STRING) ( \
  4208. NLS_MB_OEM_CODE_PAGE_TAG ? \
  4209. RtlxOemStringToUnicodeSize(STRING) : \
  4210. ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
  4211. )
  4212. //
  4213. // ULONG
  4214. // RtlOemStringToCountedUnicodeSize(
  4215. // POEM_STRING OemString
  4216. // );
  4217. //
  4218. #define RtlOemStringToCountedUnicodeSize(STRING) ( \
  4219. (ULONG)(RtlOemStringToUnicodeSize(STRING) - sizeof(UNICODE_NULL)) \
  4220. )
  4221. NTSYSAPI
  4222. NTSTATUS
  4223. NTAPI
  4224. RtlMultiByteToUnicodeN(
  4225. PWSTR UnicodeString,
  4226. ULONG MaxBytesInUnicodeString,
  4227. PULONG BytesInUnicodeString,
  4228. PCSTR MultiByteString,
  4229. ULONG BytesInMultiByteString
  4230. );
  4231. NTSYSAPI
  4232. NTSTATUS
  4233. NTAPI
  4234. RtlMultiByteToUnicodeSize(
  4235. PULONG BytesInUnicodeString,
  4236. PCSTR MultiByteString,
  4237. ULONG BytesInMultiByteString
  4238. );
  4239. NTSYSAPI
  4240. NTSTATUS
  4241. NTAPI
  4242. RtlUnicodeToMultiByteSize(
  4243. PULONG BytesInMultiByteString,
  4244. IN PWSTR UnicodeString,
  4245. ULONG BytesInUnicodeString
  4246. );
  4247. NTSYSAPI
  4248. NTSTATUS
  4249. NTAPI
  4250. RtlUnicodeToMultiByteN(
  4251. PCHAR MultiByteString,
  4252. ULONG MaxBytesInMultiByteString,
  4253. PULONG BytesInMultiByteString,
  4254. PWSTR UnicodeString,
  4255. ULONG BytesInUnicodeString
  4256. );
  4257. NTSYSAPI
  4258. NTSTATUS
  4259. NTAPI
  4260. RtlUpcaseUnicodeToMultiByteN(
  4261. PCHAR MultiByteString,
  4262. ULONG MaxBytesInMultiByteString,
  4263. PULONG BytesInMultiByteString,
  4264. PWSTR UnicodeString,
  4265. ULONG BytesInUnicodeString
  4266. );
  4267. NTSYSAPI
  4268. NTSTATUS
  4269. NTAPI
  4270. RtlOemToUnicodeN(
  4271. PWSTR UnicodeString,
  4272. ULONG MaxBytesInUnicodeString,
  4273. PULONG BytesInUnicodeString,
  4274. IN PCHAR OemString,
  4275. ULONG BytesInOemString
  4276. );
  4277. NTSYSAPI
  4278. NTSTATUS
  4279. NTAPI
  4280. RtlUnicodeToOemN(
  4281. PCHAR OemString,
  4282. ULONG MaxBytesInOemString,
  4283. PULONG BytesInOemString,
  4284. PWSTR UnicodeString,
  4285. ULONG BytesInUnicodeString
  4286. );
  4287. NTSYSAPI
  4288. NTSTATUS
  4289. NTAPI
  4290. RtlUpcaseUnicodeToOemN(
  4291. PCHAR OemString,
  4292. ULONG MaxBytesInOemString,
  4293. PULONG BytesInOemString,
  4294. PWSTR UnicodeString,
  4295. ULONG BytesInUnicodeString
  4296. );
  4297. typedef
  4298. PVOID
  4299. (NTAPI *PRTL_ALLOCATE_STRING_ROUTINE) (
  4300. SIZE_T NumberOfBytes
  4301. );
  4302. typedef
  4303. VOID
  4304. (NTAPI *PRTL_FREE_STRING_ROUTINE) (
  4305. PVOID Buffer
  4306. );
  4307. extern const PRTL_ALLOCATE_STRING_ROUTINE RtlAllocateStringRoutine;
  4308. extern const PRTL_FREE_STRING_ROUTINE RtlFreeStringRoutine;
  4309. //
  4310. // Defines and Routines for handling GUID's.
  4311. //
  4312. // begin_ntddk begin_wdm begin_nthal
  4313. // begin_ntminiport
  4314. #include <guiddef.h>
  4315. // end_ntminiport
  4316. #ifndef DEFINE_GUIDEX
  4317. #define DEFINE_GUIDEX(name) EXTERN_C const CDECL GUID name
  4318. #endif // !defined(DEFINE_GUIDEX)
  4319. #ifndef STATICGUIDOF
  4320. #define STATICGUIDOF(guid) STATIC_##guid
  4321. #endif // !defined(STATICGUIDOF)
  4322. #ifndef __IID_ALIGNED__
  4323. #define __IID_ALIGNED__
  4324. #ifdef __cplusplus
  4325. inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
  4326. {
  4327. return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
  4328. }
  4329. #else // !__cplusplus
  4330. #define IsEqualGUIDAligned(guid1, guid2) \
  4331. ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
  4332. #endif // !__cplusplus
  4333. #endif // !__IID_ALIGNED__
  4334. NTSYSAPI
  4335. NTSTATUS
  4336. NTAPI
  4337. RtlStringFromGUID(
  4338. IN REFGUID Guid,
  4339. OUT PUNICODE_STRING GuidString
  4340. );
  4341. NTSYSAPI
  4342. NTSTATUS
  4343. NTAPI
  4344. RtlGUIDFromString(
  4345. IN PUNICODE_STRING GuidString,
  4346. OUT GUID* Guid
  4347. );
  4348. // end_ntddk end_wdm end_nthal
  4349. //
  4350. // Routine for generating 8.3 names from long names.
  4351. //
  4352. //
  4353. // The context structure is used when generating 8.3 names. The caller must
  4354. // always zero out the structure before starting a new generation sequence
  4355. //
  4356. typedef struct _GENERATE_NAME_CONTEXT {
  4357. //
  4358. // The structure is divided into two strings. The Name, and extension.
  4359. // Each part contains the value that was last inserted in the name.
  4360. // The length values are in terms of wchars and not bytes. We also
  4361. // store the last index value used in the generation collision algorithm.
  4362. //
  4363. USHORT Checksum;
  4364. BOOLEAN ChecksumInserted;
  4365. UCHAR NameLength; // not including extension
  4366. WCHAR NameBuffer[8]; // e.g., "ntoskrnl"
  4367. ULONG ExtensionLength; // including dot
  4368. WCHAR ExtensionBuffer[4]; // e.g., ".exe"
  4369. ULONG LastIndexValue;
  4370. } GENERATE_NAME_CONTEXT;
  4371. typedef GENERATE_NAME_CONTEXT *PGENERATE_NAME_CONTEXT;
  4372. NTSYSAPI
  4373. VOID
  4374. NTAPI
  4375. RtlGenerate8dot3Name (
  4376. IN PUNICODE_STRING Name,
  4377. IN BOOLEAN AllowExtendedCharacters,
  4378. IN OUT PGENERATE_NAME_CONTEXT Context,
  4379. OUT PUNICODE_STRING Name8dot3
  4380. );
  4381. NTSYSAPI
  4382. BOOLEAN
  4383. NTAPI
  4384. RtlIsNameLegalDOS8Dot3 (
  4385. IN PUNICODE_STRING Name,
  4386. IN OUT POEM_STRING OemName OPTIONAL,
  4387. IN OUT PBOOLEAN NameContainsSpaces OPTIONAL
  4388. );
  4389. BOOLEAN
  4390. RtlIsValidOemCharacter (
  4391. IN PWCHAR Char
  4392. );
  4393. //
  4394. // Prefix package types and procedures.
  4395. //
  4396. // Note that the following two record structures should really be opaque
  4397. // to the user of this package. The only information about the two
  4398. // structures available for the user should be the size and alignment
  4399. // of the structures.
  4400. //
  4401. typedef struct _PREFIX_TABLE_ENTRY {
  4402. CSHORT NodeTypeCode;
  4403. CSHORT NameLength;
  4404. struct _PREFIX_TABLE_ENTRY *NextPrefixTree;
  4405. RTL_SPLAY_LINKS Links;
  4406. PSTRING Prefix;
  4407. } PREFIX_TABLE_ENTRY;
  4408. typedef PREFIX_TABLE_ENTRY *PPREFIX_TABLE_ENTRY;
  4409. typedef struct _PREFIX_TABLE {
  4410. CSHORT NodeTypeCode;
  4411. CSHORT NameLength;
  4412. PPREFIX_TABLE_ENTRY NextPrefixTree;
  4413. } PREFIX_TABLE;
  4414. typedef PREFIX_TABLE *PPREFIX_TABLE;
  4415. //
  4416. // The procedure prototypes for the prefix package
  4417. //
  4418. NTSYSAPI
  4419. VOID
  4420. NTAPI
  4421. PfxInitialize (
  4422. PPREFIX_TABLE PrefixTable
  4423. );
  4424. NTSYSAPI
  4425. BOOLEAN
  4426. NTAPI
  4427. PfxInsertPrefix (
  4428. PPREFIX_TABLE PrefixTable,
  4429. PSTRING Prefix,
  4430. PPREFIX_TABLE_ENTRY PrefixTableEntry
  4431. );
  4432. NTSYSAPI
  4433. VOID
  4434. NTAPI
  4435. PfxRemovePrefix (
  4436. PPREFIX_TABLE PrefixTable,
  4437. PPREFIX_TABLE_ENTRY PrefixTableEntry
  4438. );
  4439. NTSYSAPI
  4440. PPREFIX_TABLE_ENTRY
  4441. NTAPI
  4442. PfxFindPrefix (
  4443. PPREFIX_TABLE PrefixTable,
  4444. PSTRING FullName
  4445. );
  4446. //
  4447. // The following definitions are for the unicode version of the prefix
  4448. // package.
  4449. //
  4450. typedef struct _UNICODE_PREFIX_TABLE_ENTRY {
  4451. CSHORT NodeTypeCode;
  4452. CSHORT NameLength;
  4453. struct _UNICODE_PREFIX_TABLE_ENTRY *NextPrefixTree;
  4454. struct _UNICODE_PREFIX_TABLE_ENTRY *CaseMatch;
  4455. RTL_SPLAY_LINKS Links;
  4456. PUNICODE_STRING Prefix;
  4457. } UNICODE_PREFIX_TABLE_ENTRY;
  4458. typedef UNICODE_PREFIX_TABLE_ENTRY *PUNICODE_PREFIX_TABLE_ENTRY;
  4459. typedef struct _UNICODE_PREFIX_TABLE {
  4460. CSHORT NodeTypeCode;
  4461. CSHORT NameLength;
  4462. PUNICODE_PREFIX_TABLE_ENTRY NextPrefixTree;
  4463. PUNICODE_PREFIX_TABLE_ENTRY LastNextEntry;
  4464. } UNICODE_PREFIX_TABLE;
  4465. typedef UNICODE_PREFIX_TABLE *PUNICODE_PREFIX_TABLE;
  4466. NTSYSAPI
  4467. VOID
  4468. NTAPI
  4469. RtlInitializeUnicodePrefix (
  4470. PUNICODE_PREFIX_TABLE PrefixTable
  4471. );
  4472. NTSYSAPI
  4473. BOOLEAN
  4474. NTAPI
  4475. RtlInsertUnicodePrefix (
  4476. PUNICODE_PREFIX_TABLE PrefixTable,
  4477. PUNICODE_STRING Prefix,
  4478. PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry
  4479. );
  4480. NTSYSAPI
  4481. VOID
  4482. NTAPI
  4483. RtlRemoveUnicodePrefix (
  4484. PUNICODE_PREFIX_TABLE PrefixTable,
  4485. PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry
  4486. );
  4487. NTSYSAPI
  4488. PUNICODE_PREFIX_TABLE_ENTRY
  4489. NTAPI
  4490. RtlFindUnicodePrefix (
  4491. PUNICODE_PREFIX_TABLE PrefixTable,
  4492. PUNICODE_STRING FullName,
  4493. ULONG CaseInsensitiveIndex
  4494. );
  4495. NTSYSAPI
  4496. PUNICODE_PREFIX_TABLE_ENTRY
  4497. NTAPI
  4498. RtlNextUnicodePrefix (
  4499. PUNICODE_PREFIX_TABLE PrefixTable,
  4500. BOOLEAN Restart
  4501. );
  4502. //
  4503. //
  4504. // Compression package types and procedures.
  4505. //
  4506. #define COMPRESSION_FORMAT_NONE (0x0000) // winnt
  4507. #define COMPRESSION_FORMAT_DEFAULT (0x0001) // winnt
  4508. #define COMPRESSION_FORMAT_LZNT1 (0x0002) // winnt
  4509. #define COMPRESSION_ENGINE_STANDARD (0x0000) // winnt
  4510. #define COMPRESSION_ENGINE_MAXIMUM (0x0100) // winnt
  4511. #define COMPRESSION_ENGINE_HIBER (0x0200) // winnt
  4512. //
  4513. // Compressed Data Information structure. This structure is
  4514. // used to describe the state of a compressed data buffer,
  4515. // whose uncompressed size is known. All compressed chunks
  4516. // described by this structure must be compressed with the
  4517. // same format. On compressed reads, this entire structure
  4518. // is an output, and on compressed writes the entire structure
  4519. // is an input.
  4520. //
  4521. typedef struct _COMPRESSED_DATA_INFO {
  4522. //
  4523. // Code for the compression format (and engine) as
  4524. // defined in ntrtl.h. Note that COMPRESSION_FORMAT_NONE
  4525. // and COMPRESSION_FORMAT_DEFAULT are invalid if
  4526. // any of the described chunks are compressed.
  4527. //
  4528. USHORT CompressionFormatAndEngine;
  4529. //
  4530. // Since chunks and compression units are expected to be
  4531. // powers of 2 in size, we express then log2. So, for
  4532. // example (1 << ChunkShift) == ChunkSizeInBytes. The
  4533. // ClusterShift indicates how much space must be saved
  4534. // to successfully compress a compression unit - each
  4535. // successfully compressed compression unit must occupy
  4536. // at least one cluster less in bytes than an uncompressed
  4537. // compression unit.
  4538. //
  4539. UCHAR CompressionUnitShift;
  4540. UCHAR ChunkShift;
  4541. UCHAR ClusterShift;
  4542. UCHAR Reserved;
  4543. //
  4544. // This is the number of entries in the CompressedChunkSizes
  4545. // array.
  4546. //
  4547. USHORT NumberOfChunks;
  4548. //
  4549. // This is an array of the sizes of all chunks resident
  4550. // in the compressed data buffer. There must be one entry
  4551. // in this array for each chunk possible in the uncompressed
  4552. // buffer size. A size of FSRTL_CHUNK_SIZE indicates the
  4553. // corresponding chunk is uncompressed and occupies exactly
  4554. // that size. A size of 0 indicates that the corresponding
  4555. // chunk contains nothing but binary 0's, and occupies no
  4556. // space in the compressed data. All other sizes must be
  4557. // less than FSRTL_CHUNK_SIZE, and indicate the exact size
  4558. // of the compressed data in bytes.
  4559. //
  4560. ULONG CompressedChunkSizes[ANYSIZE_ARRAY];
  4561. } COMPRESSED_DATA_INFO;
  4562. typedef COMPRESSED_DATA_INFO *PCOMPRESSED_DATA_INFO;
  4563. NTSYSAPI
  4564. NTSTATUS
  4565. NTAPI
  4566. RtlGetCompressionWorkSpaceSize (
  4567. IN USHORT CompressionFormatAndEngine,
  4568. OUT PULONG CompressBufferWorkSpaceSize,
  4569. OUT PULONG CompressFragmentWorkSpaceSize
  4570. );
  4571. NTSYSAPI
  4572. NTSTATUS
  4573. NTAPI
  4574. RtlCompressBuffer (
  4575. IN USHORT CompressionFormatAndEngine,
  4576. IN PUCHAR UncompressedBuffer,
  4577. IN ULONG UncompressedBufferSize,
  4578. OUT PUCHAR CompressedBuffer,
  4579. IN ULONG CompressedBufferSize,
  4580. IN ULONG UncompressedChunkSize,
  4581. OUT PULONG FinalCompressedSize,
  4582. IN PVOID WorkSpace
  4583. );
  4584. NTSYSAPI
  4585. NTSTATUS
  4586. NTAPI
  4587. RtlDecompressBuffer (
  4588. IN USHORT CompressionFormat,
  4589. OUT PUCHAR UncompressedBuffer,
  4590. IN ULONG UncompressedBufferSize,
  4591. IN PUCHAR CompressedBuffer,
  4592. IN ULONG CompressedBufferSize,
  4593. OUT PULONG FinalUncompressedSize
  4594. );
  4595. NTSYSAPI
  4596. NTSTATUS
  4597. NTAPI
  4598. RtlDecompressFragment (
  4599. IN USHORT CompressionFormat,
  4600. OUT PUCHAR UncompressedFragment,
  4601. IN ULONG UncompressedFragmentSize,
  4602. IN PUCHAR CompressedBuffer,
  4603. IN ULONG CompressedBufferSize,
  4604. IN ULONG FragmentOffset,
  4605. OUT PULONG FinalUncompressedSize,
  4606. IN PVOID WorkSpace
  4607. );
  4608. NTSYSAPI
  4609. NTSTATUS
  4610. NTAPI
  4611. RtlDescribeChunk (
  4612. IN USHORT CompressionFormat,
  4613. IN OUT PUCHAR *CompressedBuffer,
  4614. IN PUCHAR EndOfCompressedBufferPlus1,
  4615. OUT PUCHAR *ChunkBuffer,
  4616. OUT PULONG ChunkSize
  4617. );
  4618. NTSYSAPI
  4619. NTSTATUS
  4620. NTAPI
  4621. RtlReserveChunk (
  4622. IN USHORT CompressionFormat,
  4623. IN OUT PUCHAR *CompressedBuffer,
  4624. IN PUCHAR EndOfCompressedBufferPlus1,
  4625. OUT PUCHAR *ChunkBuffer,
  4626. IN ULONG ChunkSize
  4627. );
  4628. NTSYSAPI
  4629. NTSTATUS
  4630. NTAPI
  4631. RtlDecompressChunks (
  4632. OUT PUCHAR UncompressedBuffer,
  4633. IN ULONG UncompressedBufferSize,
  4634. IN PUCHAR CompressedBuffer,
  4635. IN ULONG CompressedBufferSize,
  4636. IN PUCHAR CompressedTail,
  4637. IN ULONG CompressedTailSize,
  4638. IN PCOMPRESSED_DATA_INFO CompressedDataInfo
  4639. );
  4640. NTSYSAPI
  4641. NTSTATUS
  4642. NTAPI
  4643. RtlCompressChunks (
  4644. IN PUCHAR UncompressedBuffer,
  4645. IN ULONG UncompressedBufferSize,
  4646. OUT PUCHAR CompressedBuffer,
  4647. IN ULONG CompressedBufferSize,
  4648. IN OUT PCOMPRESSED_DATA_INFO CompressedDataInfo,
  4649. IN ULONG CompressedDataInfoLength,
  4650. IN PVOID WorkSpace
  4651. );
  4652. //
  4653. // Fast primitives to compare, move, and zero memory
  4654. //
  4655. // begin_winnt begin_ntndis
  4656. NTSYSAPI
  4657. SIZE_T
  4658. NTAPI
  4659. RtlCompareMemory (
  4660. const VOID *Source1,
  4661. const VOID *Source2,
  4662. SIZE_T Length
  4663. );
  4664. #if defined(_M_AMD64) || defined(_M_IA64)
  4665. #define RtlEqualMemory(Source1, Source2, Length) \
  4666. ((Length) == RtlCompareMemory(Source1, Source2, Length))
  4667. NTSYSAPI
  4668. VOID
  4669. NTAPI
  4670. RtlCopyMemory (
  4671. VOID UNALIGNED *Destination,
  4672. CONST VOID UNALIGNED *Source,
  4673. SIZE_T Length
  4674. );
  4675. #if !defined(_M_AMD64)
  4676. NTSYSAPI
  4677. VOID
  4678. NTAPI
  4679. RtlCopyMemory32 (
  4680. VOID UNALIGNED *Destination,
  4681. CONST VOID UNALIGNED *Source,
  4682. ULONG Length
  4683. );
  4684. #endif
  4685. NTSYSAPI
  4686. VOID
  4687. NTAPI
  4688. RtlMoveMemory (
  4689. VOID UNALIGNED *Destination,
  4690. CONST VOID UNALIGNED *Source,
  4691. SIZE_T Length
  4692. );
  4693. NTSYSAPI
  4694. VOID
  4695. NTAPI
  4696. RtlFillMemory (
  4697. VOID UNALIGNED *Destination,
  4698. SIZE_T Length,
  4699. UCHAR Fill
  4700. );
  4701. NTSYSAPI
  4702. VOID
  4703. NTAPI
  4704. RtlZeroMemory (
  4705. VOID UNALIGNED *Destination,
  4706. SIZE_T Length
  4707. );
  4708. #else
  4709. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  4710. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  4711. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  4712. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  4713. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  4714. #endif
  4715. #if !defined(MIDL_PASS)
  4716. FORCEINLINE
  4717. PVOID
  4718. RtlSecureZeroMemory(
  4719. IN PVOID ptr,
  4720. IN SIZE_T cnt
  4721. )
  4722. {
  4723. volatile char *vptr = (volatile char *)ptr;
  4724. while (cnt) {
  4725. *vptr = 0;
  4726. vptr++;
  4727. cnt--;
  4728. }
  4729. return ptr;
  4730. }
  4731. #endif
  4732. // end_ntndis end_winnt
  4733. #define RtlCopyBytes RtlCopyMemory
  4734. #define RtlZeroBytes RtlZeroMemory
  4735. #define RtlFillBytes RtlFillMemory
  4736. #if defined(_M_AMD64)
  4737. NTSYSAPI
  4738. VOID
  4739. NTAPI
  4740. RtlCopyMemoryNonTemporal (
  4741. VOID UNALIGNED *Destination,
  4742. CONST VOID UNALIGNED *Source,
  4743. SIZE_T Length
  4744. );
  4745. #else
  4746. #define RtlCopyMemoryNonTemporal RtlCopyMemory
  4747. #endif
  4748. NTSYSAPI
  4749. VOID
  4750. FASTCALL
  4751. RtlPrefetchMemoryNonTemporal(
  4752. IN PVOID Source,
  4753. IN SIZE_T Length
  4754. );
  4755. // end_ntddk end_wdm end_nthal
  4756. NTSYSAPI
  4757. SIZE_T
  4758. NTAPI
  4759. RtlCompareMemoryUlong (
  4760. PVOID Source,
  4761. SIZE_T Length,
  4762. ULONG Pattern
  4763. );
  4764. NTSYSAPI
  4765. VOID
  4766. NTAPI
  4767. RtlFillMemoryUlong (
  4768. PVOID Destination,
  4769. SIZE_T Length,
  4770. ULONG Pattern
  4771. );
  4772. NTSYSAPI
  4773. VOID
  4774. NTAPI
  4775. RtlFillMemoryUlonglong (
  4776. PVOID Destination,
  4777. SIZE_T Length,
  4778. ULONGLONG Pattern
  4779. );
  4780. //
  4781. // Define kernel debugger print prototypes and macros.
  4782. //
  4783. // N.B. The following function cannot be directly imported because there are
  4784. // a few places in the source tree where this function is redefined.
  4785. //
  4786. VOID
  4787. NTAPI
  4788. DbgBreakPoint(
  4789. VOID
  4790. );
  4791. // end_wdm
  4792. NTSYSAPI
  4793. VOID
  4794. NTAPI
  4795. DbgBreakPointWithStatus(
  4796. IN ULONG Status
  4797. );
  4798. // begin_wdm
  4799. #define DBG_STATUS_CONTROL_C 1
  4800. #define DBG_STATUS_SYSRQ 2
  4801. #define DBG_STATUS_BUGCHECK_FIRST 3
  4802. #define DBG_STATUS_BUGCHECK_SECOND 4
  4803. #define DBG_STATUS_FATAL 5
  4804. #define DBG_STATUS_DEBUG_CONTROL 6
  4805. #define DBG_STATUS_WORKER 7
  4806. #if DBG
  4807. #define KdPrint(_x_) DbgPrint _x_
  4808. // end_wdm
  4809. #define KdPrintEx(_x_) DbgPrintEx _x_
  4810. #define vKdPrintEx(_x_) vDbgPrintEx _x_
  4811. #define vKdPrintExWithPrefix(_x_) vDbgPrintExWithPrefix _x_
  4812. // begin_wdm
  4813. #define KdBreakPoint() DbgBreakPoint()
  4814. // end_wdm
  4815. #define KdBreakPointWithStatus(s) DbgBreakPointWithStatus(s)
  4816. // begin_wdm
  4817. #else
  4818. #define KdPrint(_x_)
  4819. // end_wdm
  4820. #define KdPrintEx(_x_)
  4821. #define vKdPrintEx(_x_)
  4822. #define vKdPrintExWithPrefix(_x_)
  4823. // begin_wdm
  4824. #define KdBreakPoint()
  4825. // end_wdm
  4826. #define KdBreakPointWithStatus(s)
  4827. // begin_wdm
  4828. #endif
  4829. #ifndef _DBGNT_
  4830. ULONG
  4831. __cdecl
  4832. DbgPrint(
  4833. PCH Format,
  4834. ...
  4835. );
  4836. // end_wdm
  4837. ULONG
  4838. __cdecl
  4839. DbgPrintEx(
  4840. IN ULONG ComponentId,
  4841. IN ULONG Level,
  4842. IN PCH Format,
  4843. ...
  4844. );
  4845. #ifdef _VA_LIST_DEFINED
  4846. ULONG
  4847. vDbgPrintEx(
  4848. IN ULONG ComponentId,
  4849. IN ULONG Level,
  4850. IN PCH Format,
  4851. va_list arglist
  4852. );
  4853. ULONG
  4854. vDbgPrintExWithPrefix(
  4855. IN PCH Prefix,
  4856. IN ULONG ComponentId,
  4857. IN ULONG Level,
  4858. IN PCH Format,
  4859. va_list arglist
  4860. );
  4861. #endif
  4862. ULONG
  4863. __cdecl
  4864. DbgPrintReturnControlC(
  4865. PCH Format,
  4866. ...
  4867. );
  4868. NTSYSAPI
  4869. NTSTATUS
  4870. DbgQueryDebugFilterState(
  4871. IN ULONG ComponentId,
  4872. IN ULONG Level
  4873. );
  4874. NTSYSAPI
  4875. NTSTATUS
  4876. DbgSetDebugFilterState(
  4877. IN ULONG ComponentId,
  4878. IN ULONG Level,
  4879. IN BOOLEAN State
  4880. );
  4881. // begin_wdm
  4882. #endif // _DBGNT_
  4883. //
  4884. // Large integer arithmetic routines.
  4885. //
  4886. //
  4887. // Large integer add - 64-bits + 64-bits -> 64-bits
  4888. //
  4889. #if !defined(MIDL_PASS)
  4890. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4891. __inline
  4892. LARGE_INTEGER
  4893. NTAPI
  4894. RtlLargeIntegerAdd (
  4895. LARGE_INTEGER Addend1,
  4896. LARGE_INTEGER Addend2
  4897. )
  4898. {
  4899. LARGE_INTEGER Sum;
  4900. Sum.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
  4901. return Sum;
  4902. }
  4903. //
  4904. // Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  4905. //
  4906. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4907. __inline
  4908. LARGE_INTEGER
  4909. NTAPI
  4910. RtlEnlargedIntegerMultiply (
  4911. LONG Multiplicand,
  4912. LONG Multiplier
  4913. )
  4914. {
  4915. LARGE_INTEGER Product;
  4916. Product.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  4917. return Product;
  4918. }
  4919. //
  4920. // Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  4921. //
  4922. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4923. __inline
  4924. LARGE_INTEGER
  4925. NTAPI
  4926. RtlEnlargedUnsignedMultiply (
  4927. ULONG Multiplicand,
  4928. ULONG Multiplier
  4929. )
  4930. {
  4931. LARGE_INTEGER Product;
  4932. Product.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  4933. return Product;
  4934. }
  4935. //
  4936. // Enlarged integer divide - 64-bits / 32-bits > 32-bits
  4937. //
  4938. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4939. __inline
  4940. ULONG
  4941. NTAPI
  4942. RtlEnlargedUnsignedDivide (
  4943. IN ULARGE_INTEGER Dividend,
  4944. IN ULONG Divisor,
  4945. IN PULONG Remainder OPTIONAL
  4946. )
  4947. {
  4948. ULONG Quotient;
  4949. Quotient = (ULONG)(Dividend.QuadPart / Divisor);
  4950. if (ARGUMENT_PRESENT(Remainder)) {
  4951. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  4952. }
  4953. return Quotient;
  4954. }
  4955. //
  4956. // Large integer negation - -(64-bits)
  4957. //
  4958. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4959. __inline
  4960. LARGE_INTEGER
  4961. NTAPI
  4962. RtlLargeIntegerNegate (
  4963. LARGE_INTEGER Subtrahend
  4964. )
  4965. {
  4966. LARGE_INTEGER Difference;
  4967. Difference.QuadPart = -Subtrahend.QuadPart;
  4968. return Difference;
  4969. }
  4970. //
  4971. // Large integer subtract - 64-bits - 64-bits -> 64-bits.
  4972. //
  4973. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4974. __inline
  4975. LARGE_INTEGER
  4976. NTAPI
  4977. RtlLargeIntegerSubtract (
  4978. LARGE_INTEGER Minuend,
  4979. LARGE_INTEGER Subtrahend
  4980. )
  4981. {
  4982. LARGE_INTEGER Difference;
  4983. Difference.QuadPart = Minuend.QuadPart - Subtrahend.QuadPart;
  4984. return Difference;
  4985. }
  4986. //
  4987. // Extended large integer magic divide - 64-bits / 32-bits -> 64-bits
  4988. //
  4989. #if defined(_AMD64_)
  4990. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4991. __inline
  4992. LARGE_INTEGER
  4993. NTAPI
  4994. RtlExtendedMagicDivide (
  4995. LARGE_INTEGER Dividend,
  4996. LARGE_INTEGER MagicDivisor,
  4997. CCHAR ShiftCount
  4998. )
  4999. {
  5000. LARGE_INTEGER Quotient;
  5001. Quotient.QuadPart = UnsignedMultiplyHigh((ULONG64)Dividend.QuadPart,
  5002. (ULONG64)MagicDivisor.QuadPart);
  5003. Quotient.QuadPart = (ULONG64)Quotient.QuadPart >> ShiftCount;
  5004. return Quotient;
  5005. }
  5006. #endif // defined(_AMD64_)
  5007. #if defined(_X86_) || defined(_IA64_)
  5008. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5009. NTSYSAPI
  5010. LARGE_INTEGER
  5011. NTAPI
  5012. RtlExtendedMagicDivide (
  5013. LARGE_INTEGER Dividend,
  5014. LARGE_INTEGER MagicDivisor,
  5015. CCHAR ShiftCount
  5016. );
  5017. #endif // defined(_X86_) || defined(_IA64_)
  5018. #if defined(_AMD64_) || defined(_IA64_)
  5019. //
  5020. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  5021. //
  5022. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5023. __inline
  5024. LARGE_INTEGER
  5025. NTAPI
  5026. RtlExtendedLargeIntegerDivide (
  5027. LARGE_INTEGER Dividend,
  5028. ULONG Divisor,
  5029. PULONG Remainder OPTIONAL
  5030. )
  5031. {
  5032. LARGE_INTEGER Quotient;
  5033. Quotient.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
  5034. if (ARGUMENT_PRESENT(Remainder)) {
  5035. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  5036. }
  5037. return Quotient;
  5038. }
  5039. // end_wdm
  5040. //
  5041. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  5042. //
  5043. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5044. __inline
  5045. LARGE_INTEGER
  5046. NTAPI
  5047. RtlLargeIntegerDivide (
  5048. LARGE_INTEGER Dividend,
  5049. LARGE_INTEGER Divisor,
  5050. PLARGE_INTEGER Remainder OPTIONAL
  5051. )
  5052. {
  5053. LARGE_INTEGER Quotient;
  5054. Quotient.QuadPart = Dividend.QuadPart / Divisor.QuadPart;
  5055. if (ARGUMENT_PRESENT(Remainder)) {
  5056. Remainder->QuadPart = Dividend.QuadPart % Divisor.QuadPart;
  5057. }
  5058. return Quotient;
  5059. }
  5060. // begin_wdm
  5061. //
  5062. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  5063. //
  5064. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5065. __inline
  5066. LARGE_INTEGER
  5067. NTAPI
  5068. RtlExtendedIntegerMultiply (
  5069. LARGE_INTEGER Multiplicand,
  5070. LONG Multiplier
  5071. )
  5072. {
  5073. LARGE_INTEGER Product;
  5074. Product.QuadPart = Multiplicand.QuadPart * Multiplier;
  5075. return Product;
  5076. }
  5077. #else
  5078. //
  5079. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  5080. //
  5081. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5082. NTSYSAPI
  5083. LARGE_INTEGER
  5084. NTAPI
  5085. RtlExtendedLargeIntegerDivide (
  5086. LARGE_INTEGER Dividend,
  5087. ULONG Divisor,
  5088. PULONG Remainder
  5089. );
  5090. // end_wdm
  5091. //
  5092. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  5093. //
  5094. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5095. NTSYSAPI
  5096. LARGE_INTEGER
  5097. NTAPI
  5098. RtlLargeIntegerDivide (
  5099. LARGE_INTEGER Dividend,
  5100. LARGE_INTEGER Divisor,
  5101. PLARGE_INTEGER Remainder
  5102. );
  5103. // begin_wdm
  5104. //
  5105. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  5106. //
  5107. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5108. NTSYSAPI
  5109. LARGE_INTEGER
  5110. NTAPI
  5111. RtlExtendedIntegerMultiply (
  5112. LARGE_INTEGER Multiplicand,
  5113. LONG Multiplier
  5114. );
  5115. #endif // defined(_AMD64_) || defined(_IA64_)
  5116. //
  5117. // Large integer and - 64-bite & 64-bits -> 64-bits.
  5118. //
  5119. #if PRAGMA_DEPRECATED_DDK
  5120. #pragma deprecated(RtlLargeIntegerAnd) // Use native __int64 math
  5121. #endif
  5122. #define RtlLargeIntegerAnd(Result, Source, Mask) \
  5123. Result.QuadPart = Source.QuadPart & Mask.QuadPart
  5124. //
  5125. // Convert signed integer to large integer.
  5126. //
  5127. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5128. __inline
  5129. LARGE_INTEGER
  5130. NTAPI
  5131. RtlConvertLongToLargeInteger (
  5132. LONG SignedInteger
  5133. )
  5134. {
  5135. LARGE_INTEGER Result;
  5136. Result.QuadPart = SignedInteger;
  5137. return Result;
  5138. }
  5139. //
  5140. // Convert unsigned integer to large integer.
  5141. //
  5142. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5143. __inline
  5144. LARGE_INTEGER
  5145. NTAPI
  5146. RtlConvertUlongToLargeInteger (
  5147. ULONG UnsignedInteger
  5148. )
  5149. {
  5150. LARGE_INTEGER Result;
  5151. Result.QuadPart = UnsignedInteger;
  5152. return Result;
  5153. }
  5154. //
  5155. // Large integer shift routines.
  5156. //
  5157. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5158. __inline
  5159. LARGE_INTEGER
  5160. NTAPI
  5161. RtlLargeIntegerShiftLeft (
  5162. LARGE_INTEGER LargeInteger,
  5163. CCHAR ShiftCount
  5164. )
  5165. {
  5166. LARGE_INTEGER Result;
  5167. Result.QuadPart = LargeInteger.QuadPart << ShiftCount;
  5168. return Result;
  5169. }
  5170. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5171. __inline
  5172. LARGE_INTEGER
  5173. NTAPI
  5174. RtlLargeIntegerShiftRight (
  5175. LARGE_INTEGER LargeInteger,
  5176. CCHAR ShiftCount
  5177. )
  5178. {
  5179. LARGE_INTEGER Result;
  5180. Result.QuadPart = (ULONG64)LargeInteger.QuadPart >> ShiftCount;
  5181. return Result;
  5182. }
  5183. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5184. __inline
  5185. LARGE_INTEGER
  5186. NTAPI
  5187. RtlLargeIntegerArithmeticShift (
  5188. LARGE_INTEGER LargeInteger,
  5189. CCHAR ShiftCount
  5190. )
  5191. {
  5192. LARGE_INTEGER Result;
  5193. Result.QuadPart = LargeInteger.QuadPart >> ShiftCount;
  5194. return Result;
  5195. }
  5196. //
  5197. // Large integer comparison routines.
  5198. //
  5199. #if PRAGMA_DEPRECATED_DDK
  5200. #pragma deprecated(RtlLargeIntegerGreaterThan) // Use native __int64 math
  5201. #pragma deprecated(RtlLargeIntegerGreaterThanOrEqualTo) // Use native __int64 math
  5202. #pragma deprecated(RtlLargeIntegerEqualTo) // Use native __int64 math
  5203. #pragma deprecated(RtlLargeIntegerNotEqualTo) // Use native __int64 math
  5204. #pragma deprecated(RtlLargeIntegerLessThan) // Use native __int64 math
  5205. #pragma deprecated(RtlLargeIntegerLessThanOrEqualTo) // Use native __int64 math
  5206. #pragma deprecated(RtlLargeIntegerGreaterThanZero) // Use native __int64 math
  5207. #pragma deprecated(RtlLargeIntegerGreaterOrEqualToZero) // Use native __int64 math
  5208. #pragma deprecated(RtlLargeIntegerEqualToZero) // Use native __int64 math
  5209. #pragma deprecated(RtlLargeIntegerNotEqualToZero) // Use native __int64 math
  5210. #pragma deprecated(RtlLargeIntegerLessThanZero) // Use native __int64 math
  5211. #pragma deprecated(RtlLargeIntegerLessOrEqualToZero) // Use native __int64 math
  5212. #endif
  5213. #define RtlLargeIntegerGreaterThan(X,Y) ( \
  5214. (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
  5215. ((X).HighPart > (Y).HighPart) \
  5216. )
  5217. #define RtlLargeIntegerGreaterThanOrEqualTo(X,Y) ( \
  5218. (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
  5219. ((X).HighPart > (Y).HighPart) \
  5220. )
  5221. #define RtlLargeIntegerEqualTo(X,Y) ( \
  5222. !(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  5223. )
  5224. #define RtlLargeIntegerNotEqualTo(X,Y) ( \
  5225. (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  5226. )
  5227. #define RtlLargeIntegerLessThan(X,Y) ( \
  5228. (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
  5229. ((X).HighPart < (Y).HighPart) \
  5230. )
  5231. #define RtlLargeIntegerLessThanOrEqualTo(X,Y) ( \
  5232. (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
  5233. ((X).HighPart < (Y).HighPart) \
  5234. )
  5235. #define RtlLargeIntegerGreaterThanZero(X) ( \
  5236. (((X).HighPart == 0) && ((X).LowPart > 0)) || \
  5237. ((X).HighPart > 0 ) \
  5238. )
  5239. #define RtlLargeIntegerGreaterOrEqualToZero(X) ( \
  5240. (X).HighPart >= 0 \
  5241. )
  5242. #define RtlLargeIntegerEqualToZero(X) ( \
  5243. !((X).LowPart | (X).HighPart) \
  5244. )
  5245. #define RtlLargeIntegerNotEqualToZero(X) ( \
  5246. ((X).LowPart | (X).HighPart) \
  5247. )
  5248. #define RtlLargeIntegerLessThanZero(X) ( \
  5249. ((X).HighPart < 0) \
  5250. )
  5251. #define RtlLargeIntegerLessOrEqualToZero(X) ( \
  5252. ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) \
  5253. )
  5254. #endif // !defined(MIDL_PASS)
  5255. //
  5256. // Time conversion routines
  5257. //
  5258. typedef struct _TIME_FIELDS {
  5259. CSHORT Year; // range [1601...]
  5260. CSHORT Month; // range [1..12]
  5261. CSHORT Day; // range [1..31]
  5262. CSHORT Hour; // range [0..23]
  5263. CSHORT Minute; // range [0..59]
  5264. CSHORT Second; // range [0..59]
  5265. CSHORT Milliseconds;// range [0..999]
  5266. CSHORT Weekday; // range [0..6] == [Sunday..Saturday]
  5267. } TIME_FIELDS;
  5268. typedef TIME_FIELDS *PTIME_FIELDS;
  5269. NTSYSAPI
  5270. VOID
  5271. NTAPI
  5272. RtlTimeToTimeFields (
  5273. PLARGE_INTEGER Time,
  5274. PTIME_FIELDS TimeFields
  5275. );
  5276. //
  5277. // A time field record (Weekday ignored) -> 64 bit Time value
  5278. //
  5279. NTSYSAPI
  5280. BOOLEAN
  5281. NTAPI
  5282. RtlTimeFieldsToTime (
  5283. PTIME_FIELDS TimeFields,
  5284. PLARGE_INTEGER Time
  5285. );
  5286. // end_ntddk end_wdm
  5287. //
  5288. // A 64 bit Time value -> Seconds since the start of 1980
  5289. //
  5290. NTSYSAPI
  5291. BOOLEAN
  5292. NTAPI
  5293. RtlTimeToSecondsSince1980 (
  5294. PLARGE_INTEGER Time,
  5295. PULONG ElapsedSeconds
  5296. );
  5297. //
  5298. // Seconds since the start of 1980 -> 64 bit Time value
  5299. //
  5300. NTSYSAPI
  5301. VOID
  5302. NTAPI
  5303. RtlSecondsSince1980ToTime (
  5304. ULONG ElapsedSeconds,
  5305. PLARGE_INTEGER Time
  5306. );
  5307. //
  5308. // A 64 bit Time value -> Seconds since the start of 1970
  5309. //
  5310. NTSYSAPI
  5311. BOOLEAN
  5312. NTAPI
  5313. RtlTimeToSecondsSince1970 (
  5314. PLARGE_INTEGER Time,
  5315. PULONG ElapsedSeconds
  5316. );
  5317. //
  5318. // Seconds since the start of 1970 -> 64 bit Time value
  5319. //
  5320. NTSYSAPI
  5321. VOID
  5322. NTAPI
  5323. RtlSecondsSince1970ToTime (
  5324. ULONG ElapsedSeconds,
  5325. PLARGE_INTEGER Time
  5326. );
  5327. //
  5328. // The following macros store and retrieve USHORTS and ULONGS from potentially
  5329. // unaligned addresses, avoiding alignment faults. they should probably be
  5330. // rewritten in assembler
  5331. //
  5332. #define SHORT_SIZE (sizeof(USHORT))
  5333. #define SHORT_MASK (SHORT_SIZE - 1)
  5334. #define LONG_SIZE (sizeof(LONG))
  5335. #define LONGLONG_SIZE (sizeof(LONGLONG))
  5336. #define LONG_MASK (LONG_SIZE - 1)
  5337. #define LONGLONG_MASK (LONGLONG_SIZE - 1)
  5338. #define LOWBYTE_MASK 0x00FF
  5339. #define FIRSTBYTE(VALUE) ((VALUE) & LOWBYTE_MASK)
  5340. #define SECONDBYTE(VALUE) (((VALUE) >> 8) & LOWBYTE_MASK)
  5341. #define THIRDBYTE(VALUE) (((VALUE) >> 16) & LOWBYTE_MASK)
  5342. #define FOURTHBYTE(VALUE) (((VALUE) >> 24) & LOWBYTE_MASK)
  5343. //
  5344. // if MIPS Big Endian, order of bytes is reversed.
  5345. //
  5346. #define SHORT_LEAST_SIGNIFICANT_BIT 0
  5347. #define SHORT_MOST_SIGNIFICANT_BIT 1
  5348. #define LONG_LEAST_SIGNIFICANT_BIT 0
  5349. #define LONG_3RD_MOST_SIGNIFICANT_BIT 1
  5350. #define LONG_2ND_MOST_SIGNIFICANT_BIT 2
  5351. #define LONG_MOST_SIGNIFICANT_BIT 3
  5352. //++
  5353. //
  5354. // VOID
  5355. // RtlStoreUshort (
  5356. // PUSHORT ADDRESS
  5357. // USHORT VALUE
  5358. // )
  5359. //
  5360. // Routine Description:
  5361. //
  5362. // This macro stores a USHORT value in at a particular address, avoiding
  5363. // alignment faults.
  5364. //
  5365. // Arguments:
  5366. //
  5367. // ADDRESS - where to store USHORT value
  5368. // VALUE - USHORT to store
  5369. //
  5370. // Return Value:
  5371. //
  5372. // none.
  5373. //
  5374. //--
  5375. #define RtlStoreUshort(ADDRESS,VALUE) \
  5376. if ((ULONG_PTR)(ADDRESS) & SHORT_MASK) { \
  5377. ((PUCHAR) (ADDRESS))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(VALUE)); \
  5378. ((PUCHAR) (ADDRESS))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  5379. } \
  5380. else { \
  5381. *((PUSHORT) (ADDRESS)) = (USHORT) VALUE; \
  5382. }
  5383. //++
  5384. //
  5385. // VOID
  5386. // RtlStoreUlong (
  5387. // PULONG ADDRESS
  5388. // ULONG VALUE
  5389. // )
  5390. //
  5391. // Routine Description:
  5392. //
  5393. // This macro stores a ULONG value in at a particular address, avoiding
  5394. // alignment faults.
  5395. //
  5396. // Arguments:
  5397. //
  5398. // ADDRESS - where to store ULONG value
  5399. // VALUE - ULONG to store
  5400. //
  5401. // Return Value:
  5402. //
  5403. // none.
  5404. //
  5405. // Note:
  5406. // Depending on the machine, we might want to call storeushort in the
  5407. // unaligned case.
  5408. //
  5409. //--
  5410. #define RtlStoreUlong(ADDRESS,VALUE) \
  5411. if ((ULONG_PTR)(ADDRESS) & LONG_MASK) { \
  5412. ((PUCHAR) (ADDRESS))[LONG_LEAST_SIGNIFICANT_BIT ] = (UCHAR)(FIRSTBYTE(VALUE)); \
  5413. ((PUCHAR) (ADDRESS))[LONG_3RD_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  5414. ((PUCHAR) (ADDRESS))[LONG_2ND_MOST_SIGNIFICANT_BIT ] = (UCHAR)(THIRDBYTE(VALUE)); \
  5415. ((PUCHAR) (ADDRESS))[LONG_MOST_SIGNIFICANT_BIT ] = (UCHAR)(FOURTHBYTE(VALUE)); \
  5416. } \
  5417. else { \
  5418. *((PULONG) (ADDRESS)) = (ULONG) (VALUE); \
  5419. }
  5420. //++
  5421. //
  5422. // VOID
  5423. // RtlStoreUlonglong (
  5424. // PULONGLONG ADDRESS
  5425. // ULONG VALUE
  5426. // )
  5427. //
  5428. // Routine Description:
  5429. //
  5430. // This macro stores a ULONGLONG value in at a particular address, avoiding
  5431. // alignment faults.
  5432. //
  5433. // Arguments:
  5434. //
  5435. // ADDRESS - where to store ULONGLONG value
  5436. // VALUE - ULONGLONG to store
  5437. //
  5438. // Return Value:
  5439. //
  5440. // none.
  5441. //
  5442. //--
  5443. #define RtlStoreUlonglong(ADDRESS,VALUE) \
  5444. if ((ULONG_PTR)(ADDRESS) & LONGLONG_MASK) { \
  5445. RtlStoreUlong((ULONG_PTR)(ADDRESS), \
  5446. (ULONGLONG)(VALUE) & 0xFFFFFFFF); \
  5447. RtlStoreUlong((ULONG_PTR)(ADDRESS)+sizeof(ULONG), \
  5448. (ULONGLONG)(VALUE) >> 32); \
  5449. } else { \
  5450. *((PULONGLONG)(ADDRESS)) = (ULONGLONG)(VALUE); \
  5451. }
  5452. //++
  5453. //
  5454. // VOID
  5455. // RtlStoreUlongPtr (
  5456. // PULONG_PTR ADDRESS
  5457. // ULONG_PTR VALUE
  5458. // )
  5459. //
  5460. // Routine Description:
  5461. //
  5462. // This macro stores a ULONG_PTR value in at a particular address, avoiding
  5463. // alignment faults.
  5464. //
  5465. // Arguments:
  5466. //
  5467. // ADDRESS - where to store ULONG_PTR value
  5468. // VALUE - ULONG_PTR to store
  5469. //
  5470. // Return Value:
  5471. //
  5472. // none.
  5473. //
  5474. //--
  5475. #ifdef _WIN64
  5476. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  5477. RtlStoreUlonglong(ADDRESS,VALUE)
  5478. #else
  5479. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  5480. RtlStoreUlong(ADDRESS,VALUE)
  5481. #endif
  5482. //++
  5483. //
  5484. // VOID
  5485. // RtlRetrieveUshort (
  5486. // PUSHORT DESTINATION_ADDRESS
  5487. // PUSHORT SOURCE_ADDRESS
  5488. // )
  5489. //
  5490. // Routine Description:
  5491. //
  5492. // This macro retrieves a USHORT value from the SOURCE address, avoiding
  5493. // alignment faults. The DESTINATION address is assumed to be aligned.
  5494. //
  5495. // Arguments:
  5496. //
  5497. // DESTINATION_ADDRESS - where to store USHORT value
  5498. // SOURCE_ADDRESS - where to retrieve USHORT value from
  5499. //
  5500. // Return Value:
  5501. //
  5502. // none.
  5503. //
  5504. //--
  5505. #define RtlRetrieveUshort(DEST_ADDRESS,SRC_ADDRESS) \
  5506. if ((ULONG_PTR)SRC_ADDRESS & SHORT_MASK) { \
  5507. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  5508. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  5509. } \
  5510. else { \
  5511. *((PUSHORT) DEST_ADDRESS) = *((PUSHORT) SRC_ADDRESS); \
  5512. } \
  5513. //++
  5514. //
  5515. // VOID
  5516. // RtlRetrieveUlong (
  5517. // PULONG DESTINATION_ADDRESS
  5518. // PULONG SOURCE_ADDRESS
  5519. // )
  5520. //
  5521. // Routine Description:
  5522. //
  5523. // This macro retrieves a ULONG value from the SOURCE address, avoiding
  5524. // alignment faults. The DESTINATION address is assumed to be aligned.
  5525. //
  5526. // Arguments:
  5527. //
  5528. // DESTINATION_ADDRESS - where to store ULONG value
  5529. // SOURCE_ADDRESS - where to retrieve ULONG value from
  5530. //
  5531. // Return Value:
  5532. //
  5533. // none.
  5534. //
  5535. // Note:
  5536. // Depending on the machine, we might want to call retrieveushort in the
  5537. // unaligned case.
  5538. //
  5539. //--
  5540. #define RtlRetrieveUlong(DEST_ADDRESS,SRC_ADDRESS) \
  5541. if ((ULONG_PTR)SRC_ADDRESS & LONG_MASK) { \
  5542. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  5543. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  5544. ((PUCHAR) DEST_ADDRESS)[2] = ((PUCHAR) SRC_ADDRESS)[2]; \
  5545. ((PUCHAR) DEST_ADDRESS)[3] = ((PUCHAR) SRC_ADDRESS)[3]; \
  5546. } \
  5547. else { \
  5548. *((PULONG) DEST_ADDRESS) = *((PULONG) SRC_ADDRESS); \
  5549. }
  5550. // end_ntddk end_wdm
  5551. //++
  5552. //
  5553. // PCHAR
  5554. // RtlOffsetToPointer (
  5555. // PVOID Base,
  5556. // ULONG Offset
  5557. // )
  5558. //
  5559. // Routine Description:
  5560. //
  5561. // This macro generates a pointer which points to the byte that is 'Offset'
  5562. // bytes beyond 'Base'. This is useful for referencing fields within
  5563. // self-relative data structures.
  5564. //
  5565. // Arguments:
  5566. //
  5567. // Base - The address of the base of the structure.
  5568. //
  5569. // Offset - An unsigned integer offset of the byte whose address is to
  5570. // be generated.
  5571. //
  5572. // Return Value:
  5573. //
  5574. // A PCHAR pointer to the byte that is 'Offset' bytes beyond 'Base'.
  5575. //
  5576. //
  5577. //--
  5578. #define RtlOffsetToPointer(B,O) ((PCHAR)( ((PCHAR)(B)) + ((ULONG_PTR)(O)) ))
  5579. //++
  5580. //
  5581. // ULONG
  5582. // RtlPointerToOffset (
  5583. // PVOID Base,
  5584. // PVOID Pointer
  5585. // )
  5586. //
  5587. // Routine Description:
  5588. //
  5589. // This macro calculates the offset from Base to Pointer. This is useful
  5590. // for producing self-relative offsets for structures.
  5591. //
  5592. // Arguments:
  5593. //
  5594. // Base - The address of the base of the structure.
  5595. //
  5596. // Pointer - A pointer to a field, presumably within the structure
  5597. // pointed to by Base. This value must be larger than that specified
  5598. // for Base.
  5599. //
  5600. // Return Value:
  5601. //
  5602. // A ULONG offset from Base to Pointer.
  5603. //
  5604. //
  5605. //--
  5606. #define RtlPointerToOffset(B,P) ((ULONG)( ((PCHAR)(P)) - ((PCHAR)(B)) ))
  5607. //
  5608. // BitMap routines. The following structure, routines, and macros are
  5609. // for manipulating bitmaps. The user is responsible for allocating a bitmap
  5610. // structure (which is really a header) and a buffer (which must be longword
  5611. // aligned and multiple longwords in size).
  5612. //
  5613. typedef struct _RTL_BITMAP {
  5614. ULONG SizeOfBitMap; // Number of bits in bit map
  5615. PULONG Buffer; // Pointer to the bit map itself
  5616. } RTL_BITMAP;
  5617. typedef RTL_BITMAP *PRTL_BITMAP;
  5618. //
  5619. // The following routine initializes a new bitmap. It does not alter the
  5620. // data currently in the bitmap. This routine must be called before
  5621. // any other bitmap routine/macro.
  5622. //
  5623. NTSYSAPI
  5624. VOID
  5625. NTAPI
  5626. RtlInitializeBitMap (
  5627. PRTL_BITMAP BitMapHeader,
  5628. PULONG BitMapBuffer,
  5629. ULONG SizeOfBitMap
  5630. );
  5631. //
  5632. // The following three routines clear, set, and test the state of a
  5633. // single bit in a bitmap.
  5634. //
  5635. NTSYSAPI
  5636. VOID
  5637. NTAPI
  5638. RtlClearBit (
  5639. PRTL_BITMAP BitMapHeader,
  5640. ULONG BitNumber
  5641. );
  5642. NTSYSAPI
  5643. VOID
  5644. NTAPI
  5645. RtlSetBit (
  5646. PRTL_BITMAP BitMapHeader,
  5647. ULONG BitNumber
  5648. );
  5649. NTSYSAPI
  5650. BOOLEAN
  5651. NTAPI
  5652. RtlTestBit (
  5653. PRTL_BITMAP BitMapHeader,
  5654. ULONG BitNumber
  5655. );
  5656. //
  5657. // The following two routines either clear or set all of the bits
  5658. // in a bitmap.
  5659. //
  5660. NTSYSAPI
  5661. VOID
  5662. NTAPI
  5663. RtlClearAllBits (
  5664. PRTL_BITMAP BitMapHeader
  5665. );
  5666. NTSYSAPI
  5667. VOID
  5668. NTAPI
  5669. RtlSetAllBits (
  5670. PRTL_BITMAP BitMapHeader
  5671. );
  5672. //
  5673. // The following two routines locate a contiguous region of either
  5674. // clear or set bits within the bitmap. The region will be at least
  5675. // as large as the number specified, and the search of the bitmap will
  5676. // begin at the specified hint index (which is a bit index within the
  5677. // bitmap, zero based). The return value is the bit index of the located
  5678. // region (zero based) or -1 (i.e., 0xffffffff) if such a region cannot
  5679. // be located
  5680. //
  5681. NTSYSAPI
  5682. ULONG
  5683. NTAPI
  5684. RtlFindClearBits (
  5685. PRTL_BITMAP BitMapHeader,
  5686. ULONG NumberToFind,
  5687. ULONG HintIndex
  5688. );
  5689. NTSYSAPI
  5690. ULONG
  5691. NTAPI
  5692. RtlFindSetBits (
  5693. PRTL_BITMAP BitMapHeader,
  5694. ULONG NumberToFind,
  5695. ULONG HintIndex
  5696. );
  5697. //
  5698. // The following two routines locate a contiguous region of either
  5699. // clear or set bits within the bitmap and either set or clear the bits
  5700. // within the located region. The region will be as large as the number
  5701. // specified, and the search for the region will begin at the specified
  5702. // hint index (which is a bit index within the bitmap, zero based). The
  5703. // return value is the bit index of the located region (zero based) or
  5704. // -1 (i.e., 0xffffffff) if such a region cannot be located. If a region
  5705. // cannot be located then the setting/clearing of the bitmap is not performed.
  5706. //
  5707. NTSYSAPI
  5708. ULONG
  5709. NTAPI
  5710. RtlFindClearBitsAndSet (
  5711. PRTL_BITMAP BitMapHeader,
  5712. ULONG NumberToFind,
  5713. ULONG HintIndex
  5714. );
  5715. NTSYSAPI
  5716. ULONG
  5717. NTAPI
  5718. RtlFindSetBitsAndClear (
  5719. PRTL_BITMAP BitMapHeader,
  5720. ULONG NumberToFind,
  5721. ULONG HintIndex
  5722. );
  5723. //
  5724. // The following two routines clear or set bits within a specified region
  5725. // of the bitmap. The starting index is zero based.
  5726. //
  5727. NTSYSAPI
  5728. VOID
  5729. NTAPI
  5730. RtlClearBits (
  5731. PRTL_BITMAP BitMapHeader,
  5732. ULONG StartingIndex,
  5733. ULONG NumberToClear
  5734. );
  5735. NTSYSAPI
  5736. VOID
  5737. NTAPI
  5738. RtlSetBits (
  5739. PRTL_BITMAP BitMapHeader,
  5740. ULONG StartingIndex,
  5741. ULONG NumberToSet
  5742. );
  5743. //
  5744. // The following routine locates a set of contiguous regions of clear
  5745. // bits within the bitmap. The caller specifies whether to return the
  5746. // longest runs or just the first found lcoated. The following structure is
  5747. // used to denote a contiguous run of bits. The two routines return an array
  5748. // of this structure, one for each run located.
  5749. //
  5750. typedef struct _RTL_BITMAP_RUN {
  5751. ULONG StartingIndex;
  5752. ULONG NumberOfBits;
  5753. } RTL_BITMAP_RUN;
  5754. typedef RTL_BITMAP_RUN *PRTL_BITMAP_RUN;
  5755. NTSYSAPI
  5756. ULONG
  5757. NTAPI
  5758. RtlFindClearRuns (
  5759. PRTL_BITMAP BitMapHeader,
  5760. PRTL_BITMAP_RUN RunArray,
  5761. ULONG SizeOfRunArray,
  5762. BOOLEAN LocateLongestRuns
  5763. );
  5764. //
  5765. // The following routine locates the longest contiguous region of
  5766. // clear bits within the bitmap. The returned starting index value
  5767. // denotes the first contiguous region located satisfying our requirements
  5768. // The return value is the length (in bits) of the longest region found.
  5769. //
  5770. NTSYSAPI
  5771. ULONG
  5772. NTAPI
  5773. RtlFindLongestRunClear (
  5774. PRTL_BITMAP BitMapHeader,
  5775. PULONG StartingIndex
  5776. );
  5777. //
  5778. // The following routine locates the first contiguous region of
  5779. // clear bits within the bitmap. The returned starting index value
  5780. // denotes the first contiguous region located satisfying our requirements
  5781. // The return value is the length (in bits) of the region found.
  5782. //
  5783. NTSYSAPI
  5784. ULONG
  5785. NTAPI
  5786. RtlFindFirstRunClear (
  5787. PRTL_BITMAP BitMapHeader,
  5788. PULONG StartingIndex
  5789. );
  5790. //
  5791. // The following macro returns the value of the bit stored within the
  5792. // bitmap at the specified location. If the bit is set a value of 1 is
  5793. // returned otherwise a value of 0 is returned.
  5794. //
  5795. // ULONG
  5796. // RtlCheckBit (
  5797. // PRTL_BITMAP BitMapHeader,
  5798. // ULONG BitPosition
  5799. // );
  5800. //
  5801. //
  5802. // To implement CheckBit the macro retrieves the longword containing the
  5803. // bit in question, shifts the longword to get the bit in question into the
  5804. // low order bit position and masks out all other bits.
  5805. //
  5806. #define RtlCheckBit(BMH,BP) ((((BMH)->Buffer[(BP) / 32]) >> ((BP) % 32)) & 0x1)
  5807. //
  5808. // The following two procedures return to the caller the total number of
  5809. // clear or set bits within the specified bitmap.
  5810. //
  5811. NTSYSAPI
  5812. ULONG
  5813. NTAPI
  5814. RtlNumberOfClearBits (
  5815. PRTL_BITMAP BitMapHeader
  5816. );
  5817. NTSYSAPI
  5818. ULONG
  5819. NTAPI
  5820. RtlNumberOfSetBits (
  5821. PRTL_BITMAP BitMapHeader
  5822. );
  5823. //
  5824. // The following two procedures return to the caller a boolean value
  5825. // indicating if the specified range of bits are all clear or set.
  5826. //
  5827. NTSYSAPI
  5828. BOOLEAN
  5829. NTAPI
  5830. RtlAreBitsClear (
  5831. PRTL_BITMAP BitMapHeader,
  5832. ULONG StartingIndex,
  5833. ULONG Length
  5834. );
  5835. NTSYSAPI
  5836. BOOLEAN
  5837. NTAPI
  5838. RtlAreBitsSet (
  5839. PRTL_BITMAP BitMapHeader,
  5840. ULONG StartingIndex,
  5841. ULONG Length
  5842. );
  5843. NTSYSAPI
  5844. ULONG
  5845. NTAPI
  5846. RtlFindNextForwardRunClear (
  5847. IN PRTL_BITMAP BitMapHeader,
  5848. IN ULONG FromIndex,
  5849. IN PULONG StartingRunIndex
  5850. );
  5851. NTSYSAPI
  5852. ULONG
  5853. NTAPI
  5854. RtlFindLastBackwardRunClear (
  5855. IN PRTL_BITMAP BitMapHeader,
  5856. IN ULONG FromIndex,
  5857. IN PULONG StartingRunIndex
  5858. );
  5859. //
  5860. // The following two procedures return to the caller a value indicating
  5861. // the position within a ULONGLONG of the most or least significant non-zero
  5862. // bit. A value of zero results in a return value of -1.
  5863. //
  5864. NTSYSAPI
  5865. CCHAR
  5866. NTAPI
  5867. RtlFindLeastSignificantBit (
  5868. IN ULONGLONG Set
  5869. );
  5870. NTSYSAPI
  5871. CCHAR
  5872. NTAPI
  5873. RtlFindMostSignificantBit (
  5874. IN ULONGLONG Set
  5875. );
  5876. //
  5877. // Security ID RTL routine definitions
  5878. //
  5879. NTSYSAPI
  5880. BOOLEAN
  5881. NTAPI
  5882. RtlValidSid (
  5883. PSID Sid
  5884. );
  5885. NTSYSAPI
  5886. BOOLEAN
  5887. NTAPI
  5888. RtlEqualSid (
  5889. PSID Sid1,
  5890. PSID Sid2
  5891. );
  5892. NTSYSAPI
  5893. BOOLEAN
  5894. NTAPI
  5895. RtlEqualPrefixSid (
  5896. PSID Sid1,
  5897. PSID Sid2
  5898. );
  5899. NTSYSAPI
  5900. ULONG
  5901. NTAPI
  5902. RtlLengthRequiredSid (
  5903. ULONG SubAuthorityCount
  5904. );
  5905. NTSYSAPI
  5906. PVOID
  5907. NTAPI
  5908. RtlFreeSid(
  5909. IN PSID Sid
  5910. );
  5911. NTSYSAPI
  5912. NTSTATUS
  5913. NTAPI
  5914. RtlAllocateAndInitializeSid(
  5915. IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
  5916. IN UCHAR SubAuthorityCount,
  5917. IN ULONG SubAuthority0,
  5918. IN ULONG SubAuthority1,
  5919. IN ULONG SubAuthority2,
  5920. IN ULONG SubAuthority3,
  5921. IN ULONG SubAuthority4,
  5922. IN ULONG SubAuthority5,
  5923. IN ULONG SubAuthority6,
  5924. IN ULONG SubAuthority7,
  5925. OUT PSID *Sid
  5926. );
  5927. NTSYSAPI // ntifs
  5928. NTSTATUS // ntifs
  5929. NTAPI // ntifs
  5930. RtlInitializeSid ( // ntifs
  5931. PSID Sid, // ntifs
  5932. PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, // ntifs
  5933. UCHAR SubAuthorityCount // ntifs
  5934. ); // ntifs
  5935. NTSYSAPI
  5936. PSID_IDENTIFIER_AUTHORITY
  5937. NTAPI
  5938. RtlIdentifierAuthoritySid (
  5939. PSID Sid
  5940. );
  5941. NTSYSAPI // ntifs
  5942. PULONG // ntifs
  5943. NTAPI // ntifs
  5944. RtlSubAuthoritySid ( // ntifs
  5945. PSID Sid, // ntifs
  5946. ULONG SubAuthority // ntifs
  5947. ); // ntifs
  5948. NTSYSAPI
  5949. PUCHAR
  5950. NTAPI
  5951. RtlSubAuthorityCountSid (
  5952. PSID Sid
  5953. );
  5954. // begin_ntifs
  5955. NTSYSAPI
  5956. ULONG
  5957. NTAPI
  5958. RtlLengthSid (
  5959. PSID Sid
  5960. );
  5961. NTSYSAPI
  5962. NTSTATUS
  5963. NTAPI
  5964. RtlCopySid (
  5965. ULONG DestinationSidLength,
  5966. PSID DestinationSid,
  5967. PSID SourceSid
  5968. );
  5969. //
  5970. // BOOLEAN
  5971. // RtlEqualLuid(
  5972. // PLUID L1,
  5973. // PLUID L2
  5974. // );
  5975. #define RtlEqualLuid(L1, L2) (((L1)->LowPart == (L2)->LowPart) && \
  5976. ((L1)->HighPart == (L2)->HighPart))
  5977. //
  5978. // BOOLEAN
  5979. // RtlIsZeroLuid(
  5980. // PLUID L1
  5981. // );
  5982. //
  5983. #define RtlIsZeroLuid(L1) ((BOOLEAN) (((L1)->LowPart | (L1)->HighPart) == 0))
  5984. #if !defined(MIDL_PASS)
  5985. FORCEINLINE LUID
  5986. NTAPI
  5987. RtlConvertLongToLuid(
  5988. LONG Long
  5989. )
  5990. {
  5991. LUID TempLuid;
  5992. LARGE_INTEGER TempLi;
  5993. TempLi.QuadPart = Long;
  5994. TempLuid.LowPart = TempLi.LowPart;
  5995. TempLuid.HighPart = TempLi.HighPart;
  5996. return(TempLuid);
  5997. }
  5998. FORCEINLINE
  5999. LUID
  6000. NTAPI
  6001. RtlConvertUlongToLuid(
  6002. ULONG Ulong
  6003. )
  6004. {
  6005. LUID TempLuid;
  6006. TempLuid.LowPart = Ulong;
  6007. TempLuid.HighPart = 0;
  6008. return(TempLuid);
  6009. }
  6010. #endif
  6011. // end_ntddk
  6012. NTSYSAPI
  6013. VOID
  6014. NTAPI
  6015. RtlCopyLuid (
  6016. PLUID DestinationLuid,
  6017. PLUID SourceLuid
  6018. );
  6019. NTSYSAPI
  6020. VOID
  6021. NTAPI
  6022. RtlMapGenericMask(
  6023. PACCESS_MASK AccessMask,
  6024. PGENERIC_MAPPING GenericMapping
  6025. );
  6026. NTSYSAPI
  6027. NTSTATUS
  6028. NTAPI
  6029. RtlCreateAcl (
  6030. PACL Acl,
  6031. ULONG AclLength,
  6032. ULONG AclRevision
  6033. );
  6034. NTSYSAPI
  6035. NTSTATUS
  6036. NTAPI
  6037. RtlGetAce (
  6038. PACL Acl,
  6039. ULONG AceIndex,
  6040. PVOID *Ace
  6041. );
  6042. NTSYSAPI
  6043. NTSTATUS
  6044. NTAPI
  6045. RtlAddAccessAllowedAce (
  6046. PACL Acl,
  6047. ULONG AceRevision,
  6048. ACCESS_MASK AccessMask,
  6049. PSID Sid
  6050. );
  6051. //
  6052. // SecurityDescriptor RTL routine definitions
  6053. //
  6054. NTSYSAPI
  6055. NTSTATUS
  6056. NTAPI
  6057. RtlCreateSecurityDescriptor (
  6058. PSECURITY_DESCRIPTOR SecurityDescriptor,
  6059. ULONG Revision
  6060. );
  6061. // end_wdm end_ntddk
  6062. NTSYSAPI
  6063. NTSTATUS
  6064. NTAPI
  6065. RtlCreateSecurityDescriptorRelative (
  6066. PISECURITY_DESCRIPTOR_RELATIVE SecurityDescriptor,
  6067. ULONG Revision
  6068. );
  6069. // begin_wdm begin_ntddk
  6070. NTSYSAPI
  6071. BOOLEAN
  6072. NTAPI
  6073. RtlValidSecurityDescriptor (
  6074. PSECURITY_DESCRIPTOR SecurityDescriptor
  6075. );
  6076. NTSYSAPI
  6077. ULONG
  6078. NTAPI
  6079. RtlLengthSecurityDescriptor (
  6080. PSECURITY_DESCRIPTOR SecurityDescriptor
  6081. );
  6082. NTSYSAPI
  6083. BOOLEAN
  6084. NTAPI
  6085. RtlValidRelativeSecurityDescriptor (
  6086. IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
  6087. IN ULONG SecurityDescriptorLength,
  6088. IN SECURITY_INFORMATION RequiredInformation
  6089. );
  6090. NTSYSAPI
  6091. NTSTATUS
  6092. NTAPI
  6093. RtlSetDaclSecurityDescriptor (
  6094. PSECURITY_DESCRIPTOR SecurityDescriptor,
  6095. BOOLEAN DaclPresent,
  6096. PACL Dacl,
  6097. BOOLEAN DaclDefaulted
  6098. );
  6099. // end_wdm end_ntddk
  6100. NTSYSAPI
  6101. NTSTATUS
  6102. NTAPI
  6103. RtlGetDaclSecurityDescriptor (
  6104. PSECURITY_DESCRIPTOR SecurityDescriptor,
  6105. PBOOLEAN DaclPresent,
  6106. PACL *Dacl,
  6107. PBOOLEAN DaclDefaulted
  6108. );
  6109. NTSYSAPI
  6110. NTSTATUS
  6111. NTAPI
  6112. RtlSetOwnerSecurityDescriptor (
  6113. PSECURITY_DESCRIPTOR SecurityDescriptor,
  6114. PSID Owner,
  6115. BOOLEAN OwnerDefaulted
  6116. );
  6117. NTSYSAPI
  6118. NTSTATUS
  6119. NTAPI
  6120. RtlGetOwnerSecurityDescriptor (
  6121. PSECURITY_DESCRIPTOR SecurityDescriptor,
  6122. PSID *Owner,
  6123. PBOOLEAN OwnerDefaulted
  6124. );
  6125. NTSYSAPI
  6126. ULONG
  6127. NTAPI
  6128. RtlNtStatusToDosError (
  6129. NTSTATUS Status
  6130. );
  6131. NTSYSAPI
  6132. ULONG
  6133. NTAPI
  6134. RtlNtStatusToDosErrorNoTeb (
  6135. NTSTATUS Status
  6136. );
  6137. NTSYSAPI
  6138. NTSTATUS
  6139. NTAPI
  6140. RtlCustomCPToUnicodeN(
  6141. IN PCPTABLEINFO CustomCP,
  6142. OUT PWCH UnicodeString,
  6143. IN ULONG MaxBytesInUnicodeString,
  6144. OUT PULONG BytesInUnicodeString OPTIONAL,
  6145. IN PCH CustomCPString,
  6146. IN ULONG BytesInCustomCPString
  6147. );
  6148. NTSYSAPI
  6149. NTSTATUS
  6150. NTAPI
  6151. RtlUnicodeToCustomCPN(
  6152. IN PCPTABLEINFO CustomCP,
  6153. OUT PCH CustomCPString,
  6154. IN ULONG MaxBytesInCustomCPString,
  6155. OUT PULONG BytesInCustomCPString OPTIONAL,
  6156. IN PWCH UnicodeString,
  6157. IN ULONG BytesInUnicodeString
  6158. );
  6159. NTSYSAPI
  6160. NTSTATUS
  6161. NTAPI
  6162. RtlUpcaseUnicodeToCustomCPN(
  6163. IN PCPTABLEINFO CustomCP,
  6164. OUT PCH CustomCPString,
  6165. IN ULONG MaxBytesInCustomCPString,
  6166. OUT PULONG BytesInCustomCPString OPTIONAL,
  6167. IN PWCH UnicodeString,
  6168. IN ULONG BytesInUnicodeString
  6169. );
  6170. NTSYSAPI
  6171. VOID
  6172. NTAPI
  6173. RtlInitCodePageTable(
  6174. IN PUSHORT TableBase,
  6175. OUT PCPTABLEINFO CodePageTable
  6176. );
  6177. //
  6178. // Routine for converting from a volume device object to a DOS name.
  6179. //
  6180. NTSYSAPI
  6181. NTSTATUS
  6182. NTAPI
  6183. RtlVolumeDeviceToDosName(
  6184. IN PVOID VolumeDeviceObject,
  6185. OUT PUNICODE_STRING DosName
  6186. );
  6187. //
  6188. // Routine for verifying or creating the "System Volume Information"
  6189. // folder on NTFS volumes.
  6190. //
  6191. NTSYSAPI
  6192. NTSTATUS
  6193. NTAPI
  6194. RtlCreateSystemVolumeInformationFolder(
  6195. IN PUNICODE_STRING VolumeRootPath
  6196. );
  6197. #define RTL_SYSTEM_VOLUME_INFORMATION_FOLDER L"System Volume Information"
  6198. typedef struct _OSVERSIONINFOA {
  6199. ULONG dwOSVersionInfoSize;
  6200. ULONG dwMajorVersion;
  6201. ULONG dwMinorVersion;
  6202. ULONG dwBuildNumber;
  6203. ULONG dwPlatformId;
  6204. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6205. } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
  6206. typedef struct _OSVERSIONINFOW {
  6207. ULONG dwOSVersionInfoSize;
  6208. ULONG dwMajorVersion;
  6209. ULONG dwMinorVersion;
  6210. ULONG dwBuildNumber;
  6211. ULONG dwPlatformId;
  6212. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6213. } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;
  6214. #ifdef UNICODE
  6215. typedef OSVERSIONINFOW OSVERSIONINFO;
  6216. typedef POSVERSIONINFOW POSVERSIONINFO;
  6217. typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
  6218. #else
  6219. typedef OSVERSIONINFOA OSVERSIONINFO;
  6220. typedef POSVERSIONINFOA POSVERSIONINFO;
  6221. typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
  6222. #endif // UNICODE
  6223. typedef struct _OSVERSIONINFOEXA {
  6224. ULONG dwOSVersionInfoSize;
  6225. ULONG dwMajorVersion;
  6226. ULONG dwMinorVersion;
  6227. ULONG dwBuildNumber;
  6228. ULONG dwPlatformId;
  6229. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6230. USHORT wServicePackMajor;
  6231. USHORT wServicePackMinor;
  6232. USHORT wSuiteMask;
  6233. UCHAR wProductType;
  6234. UCHAR wReserved;
  6235. } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
  6236. typedef struct _OSVERSIONINFOEXW {
  6237. ULONG dwOSVersionInfoSize;
  6238. ULONG dwMajorVersion;
  6239. ULONG dwMinorVersion;
  6240. ULONG dwBuildNumber;
  6241. ULONG dwPlatformId;
  6242. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6243. USHORT wServicePackMajor;
  6244. USHORT wServicePackMinor;
  6245. USHORT wSuiteMask;
  6246. UCHAR wProductType;
  6247. UCHAR wReserved;
  6248. } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW, RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
  6249. #ifdef UNICODE
  6250. typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
  6251. typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
  6252. typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
  6253. #else
  6254. typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
  6255. typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
  6256. typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
  6257. #endif // UNICODE
  6258. //
  6259. // RtlVerifyVersionInfo() conditions
  6260. //
  6261. #define VER_EQUAL 1
  6262. #define VER_GREATER 2
  6263. #define VER_GREATER_EQUAL 3
  6264. #define VER_LESS 4
  6265. #define VER_LESS_EQUAL 5
  6266. #define VER_AND 6
  6267. #define VER_OR 7
  6268. #define VER_CONDITION_MASK 7
  6269. #define VER_NUM_BITS_PER_CONDITION_MASK 3
  6270. //
  6271. // RtlVerifyVersionInfo() type mask bits
  6272. //
  6273. #define VER_MINORVERSION 0x0000001
  6274. #define VER_MAJORVERSION 0x0000002
  6275. #define VER_BUILDNUMBER 0x0000004
  6276. #define VER_PLATFORMID 0x0000008
  6277. #define VER_SERVICEPACKMINOR 0x0000010
  6278. #define VER_SERVICEPACKMAJOR 0x0000020
  6279. #define VER_SUITENAME 0x0000040
  6280. #define VER_PRODUCT_TYPE 0x0000080
  6281. //
  6282. // RtlVerifyVersionInfo() os product type values
  6283. //
  6284. #define VER_NT_WORKSTATION 0x0000001
  6285. #define VER_NT_DOMAIN_CONTROLLER 0x0000002
  6286. #define VER_NT_SERVER 0x0000003
  6287. //
  6288. // dwPlatformId defines:
  6289. //
  6290. #define VER_PLATFORM_WIN32s 0
  6291. #define VER_PLATFORM_WIN32_WINDOWS 1
  6292. #define VER_PLATFORM_WIN32_NT 2
  6293. //
  6294. //
  6295. // VerifyVersionInfo() macro to set the condition mask
  6296. //
  6297. // For documentation sakes here's the old version of the macro that got
  6298. // changed to call an API
  6299. // #define VER_SET_CONDITION(_m_,_t_,_c_) _m_=(_m_|(_c_<<(1<<_t_)))
  6300. //
  6301. #define VER_SET_CONDITION(_m_,_t_,_c_) \
  6302. ((_m_)=VerSetConditionMask((_m_),(_t_),(_c_)))
  6303. ULONGLONG
  6304. NTAPI
  6305. VerSetConditionMask(
  6306. IN ULONGLONG ConditionMask,
  6307. IN ULONG TypeMask,
  6308. IN UCHAR Condition
  6309. );
  6310. //
  6311. // end_winnt
  6312. //
  6313. NTSYSAPI
  6314. NTSTATUS
  6315. RtlGetVersion(
  6316. OUT PRTL_OSVERSIONINFOW lpVersionInformation
  6317. );
  6318. NTSYSAPI
  6319. NTSTATUS
  6320. RtlVerifyVersionInfo(
  6321. IN PRTL_OSVERSIONINFOEXW VersionInfo,
  6322. IN ULONG TypeMask,
  6323. IN ULONGLONG ConditionMask
  6324. );
  6325. //
  6326. //
  6327. // Interlocked bit manipulation interfaces
  6328. //
  6329. NTSYSAPI
  6330. ULONG
  6331. FASTCALL
  6332. RtlInterlockedSetBits (
  6333. IN OUT PULONG Flags,
  6334. IN ULONG Flag
  6335. );
  6336. NTSYSAPI
  6337. ULONG
  6338. FASTCALL
  6339. RtlInterlockedClearBits (
  6340. IN OUT PULONG Flags,
  6341. IN ULONG Flag
  6342. );
  6343. NTSYSAPI
  6344. ULONG
  6345. FASTCALL
  6346. RtlInterlockedSetClearBits (
  6347. IN OUT PULONG Flags,
  6348. IN ULONG sFlag,
  6349. IN ULONG cFlag
  6350. );
  6351. //
  6352. // These are for when the compiler has fixes in for these intrinsics
  6353. //
  6354. #if (_MSC_FULL_VER > 13009037) || !defined (_M_IX86)
  6355. #define RtlInterlockedSetBits(Flags, Flag) \
  6356. InterlockedOr ((PLONG) (Flags), Flag)
  6357. #define RtlInterlockedAndBits(Flags, Flag) \
  6358. InterlockedAnd ((PLONG) (Flags), Flag)
  6359. #define RtlInterlockedClearBits(Flags, Flag) \
  6360. RtlInterlockedAndBits (Flags, ~(Flag))
  6361. #define RtlInterlockedXorBits(Flags, Flag) \
  6362. InterlockedXor (Flags, Flag)
  6363. #define RtlInterlockedSetBitsDiscardReturn(Flags, Flag) \
  6364. (VOID) RtlInterlockedSetBits (Flags, Flag)
  6365. #define RtlInterlockedAndBitsDiscardReturn(Flags, Flag) \
  6366. (VOID) RtlInterlockedAndBits (Flags, Flag)
  6367. #define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
  6368. RtlInterlockedAndBitsDiscardReturn (Flags, ~(Flag))
  6369. #else
  6370. #if defined (_X86_) && !defined(MIDL_PASS)
  6371. FORCEINLINE
  6372. VOID
  6373. RtlInterlockedSetBitsDiscardReturn(
  6374. IN OUT PULONG Flags,
  6375. IN ULONG Flag
  6376. )
  6377. {
  6378. __asm {
  6379. mov ecx, Flags
  6380. mov eax, Flag
  6381. #if defined (NT_UP)
  6382. or [ecx], eax
  6383. #else
  6384. lock or [ecx], eax
  6385. #endif
  6386. }
  6387. }
  6388. FORCEINLINE
  6389. VOID
  6390. RtlInterlockedAndBitsDiscardReturn(
  6391. IN OUT PULONG Flags,
  6392. IN ULONG Flag
  6393. )
  6394. {
  6395. __asm {
  6396. mov ecx, Flags
  6397. mov eax, Flag
  6398. #if defined (NT_UP)
  6399. and [ecx], eax
  6400. #else
  6401. lock and [ecx], eax
  6402. #endif
  6403. }
  6404. }
  6405. #define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
  6406. (VOID) RtlInterlockedAndBitsDiscardReturn ((Flags), ~(Flag))
  6407. #else
  6408. #define RtlInterlockedSetBitsDiscardReturn(Flags, Flag) \
  6409. (VOID) RtlInterlockedSetBits ((Flags), (Flag))
  6410. #define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
  6411. (VOID) RtlInterlockedClearBits ((Flags), (Flag))
  6412. #endif /* #if defined(_X86_) && !defined(MIDL_PASS) */
  6413. #endif
  6414. //
  6415. // Component name filter id enumeration and levels.
  6416. //
  6417. #define DPFLTR_ERROR_LEVEL 0
  6418. #define DPFLTR_WARNING_LEVEL 1
  6419. #define DPFLTR_TRACE_LEVEL 2
  6420. #define DPFLTR_INFO_LEVEL 3
  6421. #define DPFLTR_MASK 0x80000000
  6422. typedef enum _DPFLTR_TYPE {
  6423. DPFLTR_SYSTEM_ID = 0,
  6424. DPFLTR_SMSS_ID = 1,
  6425. DPFLTR_SETUP_ID = 2,
  6426. DPFLTR_NTFS_ID = 3,
  6427. DPFLTR_FSTUB_ID = 4,
  6428. DPFLTR_CRASHDUMP_ID = 5,
  6429. DPFLTR_CDAUDIO_ID = 6,
  6430. DPFLTR_CDROM_ID = 7,
  6431. DPFLTR_CLASSPNP_ID = 8,
  6432. DPFLTR_DISK_ID = 9,
  6433. DPFLTR_REDBOOK_ID = 10,
  6434. DPFLTR_STORPROP_ID = 11,
  6435. DPFLTR_SCSIPORT_ID = 12,
  6436. DPFLTR_SCSIMINIPORT_ID = 13,
  6437. DPFLTR_CONFIG_ID = 14,
  6438. DPFLTR_I8042PRT_ID = 15,
  6439. DPFLTR_SERMOUSE_ID = 16,
  6440. DPFLTR_LSERMOUS_ID = 17,
  6441. DPFLTR_KBDHID_ID = 18,
  6442. DPFLTR_MOUHID_ID = 19,
  6443. DPFLTR_KBDCLASS_ID = 20,
  6444. DPFLTR_MOUCLASS_ID = 21,
  6445. DPFLTR_TWOTRACK_ID = 22,
  6446. DPFLTR_WMILIB_ID = 23,
  6447. DPFLTR_ACPI_ID = 24,
  6448. DPFLTR_AMLI_ID = 25,
  6449. DPFLTR_HALIA64_ID = 26,
  6450. DPFLTR_VIDEO_ID = 27,
  6451. DPFLTR_SVCHOST_ID = 28,
  6452. DPFLTR_VIDEOPRT_ID = 29,
  6453. DPFLTR_TCPIP_ID = 30,
  6454. DPFLTR_DMSYNTH_ID = 31,
  6455. DPFLTR_NTOSPNP_ID = 32,
  6456. DPFLTR_FASTFAT_ID = 33,
  6457. DPFLTR_SAMSS_ID = 34,
  6458. DPFLTR_PNPMGR_ID = 35,
  6459. DPFLTR_NETAPI_ID = 36,
  6460. DPFLTR_SCSERVER_ID = 37,
  6461. DPFLTR_SCCLIENT_ID = 38,
  6462. DPFLTR_SERIAL_ID = 39,
  6463. DPFLTR_SERENUM_ID = 40,
  6464. DPFLTR_UHCD_ID = 41,
  6465. DPFLTR_BOOTOK_ID = 42,
  6466. DPFLTR_BOOTVRFY_ID = 43,
  6467. DPFLTR_RPCPROXY_ID = 44,
  6468. DPFLTR_AUTOCHK_ID = 45,
  6469. DPFLTR_DCOMSS_ID = 46,
  6470. DPFLTR_UNIMODEM_ID = 47,
  6471. DPFLTR_SIS_ID = 48,
  6472. DPFLTR_FLTMGR_ID = 49,
  6473. DPFLTR_WMICORE_ID = 50,
  6474. DPFLTR_BURNENG_ID = 51,
  6475. DPFLTR_IMAPI_ID = 52,
  6476. DPFLTR_SXS_ID = 53,
  6477. DPFLTR_FUSION_ID = 54,
  6478. DPFLTR_IDLETASK_ID = 55,
  6479. DPFLTR_SOFTPCI_ID = 56,
  6480. DPFLTR_TAPE_ID = 57,
  6481. DPFLTR_MCHGR_ID = 58,
  6482. DPFLTR_IDEP_ID = 59,
  6483. DPFLTR_PCIIDE_ID = 60,
  6484. DPFLTR_FLOPPY_ID = 61,
  6485. DPFLTR_FDC_ID = 62,
  6486. DPFLTR_TERMSRV_ID = 63,
  6487. DPFLTR_W32TIME_ID = 64,
  6488. DPFLTR_PREFETCHER_ID = 65,
  6489. DPFLTR_RSFILTER_ID = 66,
  6490. DPFLTR_FCPORT_ID = 67,
  6491. DPFLTR_PCI_ID = 68,
  6492. DPFLTR_DMIO_ID = 69,
  6493. DPFLTR_DMCONFIG_ID = 70,
  6494. DPFLTR_DMADMIN_ID = 71,
  6495. DPFLTR_WSOCKTRANSPORT_ID = 72,
  6496. DPFLTR_VSS_ID = 73,
  6497. DPFLTR_PNPMEM_ID = 74,
  6498. DPFLTR_PROCESSOR_ID = 75,
  6499. DPFLTR_DMSERVER_ID = 76,
  6500. DPFLTR_SR_ID = 77,
  6501. DPFLTR_INFINIBAND_ID = 78,
  6502. DPFLTR_IHVDRIVER_ID = 79,
  6503. DPFLTR_IHVVIDEO_ID = 80,
  6504. DPFLTR_IHVAUDIO_ID = 81,
  6505. DPFLTR_IHVNETWORK_ID = 82,
  6506. DPFLTR_IHVSTREAMING_ID = 83,
  6507. DPFLTR_IHVBUS_ID = 84,
  6508. DPFLTR_HPS_ID = 85,
  6509. DPFLTR_RTLTHREADPOOL_ID = 86,
  6510. DPFLTR_LDR_ID = 87,
  6511. DPFLTR_TCPIP6_ID = 88,
  6512. DPFLTR_ISAPNP_ID = 89,
  6513. DPFLTR_SHPC_ID = 90,
  6514. DPFLTR_STORPORT_ID = 91,
  6515. DPFLTR_STORMINIPORT_ID = 92,
  6516. DPFLTR_PRINTSPOOLER_ID = 93,
  6517. DPFLTR_ENDOFTABLE_ID
  6518. } DPFLTR_TYPE;
  6519. #ifndef _PO_DDK_
  6520. #define _PO_DDK_
  6521. // begin_winnt
  6522. typedef enum _SYSTEM_POWER_STATE {
  6523. PowerSystemUnspecified = 0,
  6524. PowerSystemWorking = 1,
  6525. PowerSystemSleeping1 = 2,
  6526. PowerSystemSleeping2 = 3,
  6527. PowerSystemSleeping3 = 4,
  6528. PowerSystemHibernate = 5,
  6529. PowerSystemShutdown = 6,
  6530. PowerSystemMaximum = 7
  6531. } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
  6532. #define POWER_SYSTEM_MAXIMUM 7
  6533. typedef enum {
  6534. PowerActionNone = 0,
  6535. PowerActionReserved,
  6536. PowerActionSleep,
  6537. PowerActionHibernate,
  6538. PowerActionShutdown,
  6539. PowerActionShutdownReset,
  6540. PowerActionShutdownOff,
  6541. PowerActionWarmEject
  6542. } POWER_ACTION, *PPOWER_ACTION;
  6543. typedef enum _DEVICE_POWER_STATE {
  6544. PowerDeviceUnspecified = 0,
  6545. PowerDeviceD0,
  6546. PowerDeviceD1,
  6547. PowerDeviceD2,
  6548. PowerDeviceD3,
  6549. PowerDeviceMaximum
  6550. } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
  6551. // end_winnt
  6552. typedef union _POWER_STATE {
  6553. SYSTEM_POWER_STATE SystemState;
  6554. DEVICE_POWER_STATE DeviceState;
  6555. } POWER_STATE, *PPOWER_STATE;
  6556. typedef enum _POWER_STATE_TYPE {
  6557. SystemPowerState = 0,
  6558. DevicePowerState
  6559. } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
  6560. //
  6561. // Generic power related IOCTLs
  6562. //
  6563. #define IOCTL_QUERY_DEVICE_POWER_STATE \
  6564. CTL_CODE(FILE_DEVICE_BATTERY, 0x0, METHOD_BUFFERED, FILE_READ_ACCESS)
  6565. #define IOCTL_SET_DEVICE_WAKE \
  6566. CTL_CODE(FILE_DEVICE_BATTERY, 0x1, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  6567. #define IOCTL_CANCEL_DEVICE_WAKE \
  6568. CTL_CODE(FILE_DEVICE_BATTERY, 0x2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  6569. //
  6570. // Defines for W32 interfaces
  6571. //
  6572. // begin_winnt
  6573. #define ES_SYSTEM_REQUIRED ((ULONG)0x00000001)
  6574. #define ES_DISPLAY_REQUIRED ((ULONG)0x00000002)
  6575. #define ES_USER_PRESENT ((ULONG)0x00000004)
  6576. #define ES_CONTINUOUS ((ULONG)0x80000000)
  6577. typedef ULONG EXECUTION_STATE;
  6578. typedef enum {
  6579. LT_DONT_CARE,
  6580. LT_LOWEST_LATENCY
  6581. } LATENCY_TIME;
  6582. #endif // !_PO_DDK_
  6583. //
  6584. // Define the various device type values. Note that values used by Microsoft
  6585. // Corporation are in the range 0-32767, and 32768-65535 are reserved for use
  6586. // by customers.
  6587. //
  6588. #define DEVICE_TYPE ULONG
  6589. #define FILE_DEVICE_BEEP 0x00000001
  6590. #define FILE_DEVICE_CD_ROM 0x00000002
  6591. #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
  6592. #define FILE_DEVICE_CONTROLLER 0x00000004
  6593. #define FILE_DEVICE_DATALINK 0x00000005
  6594. #define FILE_DEVICE_DFS 0x00000006
  6595. #define FILE_DEVICE_DISK 0x00000007
  6596. #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
  6597. #define FILE_DEVICE_FILE_SYSTEM 0x00000009
  6598. #define FILE_DEVICE_INPORT_PORT 0x0000000a
  6599. #define FILE_DEVICE_KEYBOARD 0x0000000b
  6600. #define FILE_DEVICE_MAILSLOT 0x0000000c
  6601. #define FILE_DEVICE_MIDI_IN 0x0000000d
  6602. #define FILE_DEVICE_MIDI_OUT 0x0000000e
  6603. #define FILE_DEVICE_MOUSE 0x0000000f
  6604. #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
  6605. #define FILE_DEVICE_NAMED_PIPE 0x00000011
  6606. #define FILE_DEVICE_NETWORK 0x00000012
  6607. #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
  6608. #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
  6609. #define FILE_DEVICE_NULL 0x00000015
  6610. #define FILE_DEVICE_PARALLEL_PORT 0x00000016
  6611. #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
  6612. #define FILE_DEVICE_PRINTER 0x00000018
  6613. #define FILE_DEVICE_SCANNER 0x00000019
  6614. #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
  6615. #define FILE_DEVICE_SERIAL_PORT 0x0000001b
  6616. #define FILE_DEVICE_SCREEN 0x0000001c
  6617. #define FILE_DEVICE_SOUND 0x0000001d
  6618. #define FILE_DEVICE_STREAMS 0x0000001e
  6619. #define FILE_DEVICE_TAPE 0x0000001f
  6620. #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
  6621. #define FILE_DEVICE_TRANSPORT 0x00000021
  6622. #define FILE_DEVICE_UNKNOWN 0x00000022
  6623. #define FILE_DEVICE_VIDEO 0x00000023
  6624. #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
  6625. #define FILE_DEVICE_WAVE_IN 0x00000025
  6626. #define FILE_DEVICE_WAVE_OUT 0x00000026
  6627. #define FILE_DEVICE_8042_PORT 0x00000027
  6628. #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
  6629. #define FILE_DEVICE_BATTERY 0x00000029
  6630. #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
  6631. #define FILE_DEVICE_MODEM 0x0000002b
  6632. #define FILE_DEVICE_VDM 0x0000002c
  6633. #define FILE_DEVICE_MASS_STORAGE 0x0000002d
  6634. #define FILE_DEVICE_SMB 0x0000002e
  6635. #define FILE_DEVICE_KS 0x0000002f
  6636. #define FILE_DEVICE_CHANGER 0x00000030
  6637. #define FILE_DEVICE_SMARTCARD 0x00000031
  6638. #define FILE_DEVICE_ACPI 0x00000032
  6639. #define FILE_DEVICE_DVD 0x00000033
  6640. #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
  6641. #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
  6642. #define FILE_DEVICE_DFS_VOLUME 0x00000036
  6643. #define FILE_DEVICE_SERENUM 0x00000037
  6644. #define FILE_DEVICE_TERMSRV 0x00000038
  6645. #define FILE_DEVICE_KSEC 0x00000039
  6646. #define FILE_DEVICE_FIPS 0x0000003A
  6647. //
  6648. // Macro definition for defining IOCTL and FSCTL function control codes. Note
  6649. // that function codes 0-2047 are reserved for Microsoft Corporation, and
  6650. // 2048-4095 are reserved for customers.
  6651. //
  6652. #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
  6653. ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  6654. )
  6655. //
  6656. // Macro to extract device type out of the device io control code
  6657. //
  6658. #define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0xffff0000)) >> 16)
  6659. //
  6660. // Define the method codes for how buffers are passed for I/O and FS controls
  6661. //
  6662. #define METHOD_BUFFERED 0
  6663. #define METHOD_IN_DIRECT 1
  6664. #define METHOD_OUT_DIRECT 2
  6665. #define METHOD_NEITHER 3
  6666. //
  6667. // Define the access check value for any access
  6668. //
  6669. //
  6670. // The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
  6671. // ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
  6672. // constants *MUST* always be in sync.
  6673. //
  6674. //
  6675. // FILE_SPECIAL_ACCESS is checked by the NT I/O system the same as FILE_ANY_ACCESS.
  6676. // The file systems, however, may add additional access checks for I/O and FS controls
  6677. // that use this value.
  6678. //
  6679. #define FILE_ANY_ACCESS 0
  6680. #define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
  6681. #define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
  6682. #define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
  6683. #define PROCESS_DUP_HANDLE (0x0040) // winnt
  6684. #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  6685. 0xFFF)
  6686. // begin_nthal
  6687. #if defined(_WIN64)
  6688. #define MAXIMUM_PROCESSORS 64
  6689. #else
  6690. #define MAXIMUM_PROCESSORS 32
  6691. #endif
  6692. // end_nthal
  6693. // end_winnt
  6694. //
  6695. // Thread Specific Access Rights
  6696. //
  6697. #define THREAD_TERMINATE (0x0001) // winnt
  6698. #define THREAD_SET_INFORMATION (0x0020) // winnt
  6699. #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  6700. 0x3FF)
  6701. //
  6702. // ClientId
  6703. //
  6704. typedef struct _CLIENT_ID {
  6705. HANDLE UniqueProcess;
  6706. HANDLE UniqueThread;
  6707. } CLIENT_ID;
  6708. typedef CLIENT_ID *PCLIENT_ID;
  6709. //
  6710. // Thread Environment Block (and portable part of Thread Information Block)
  6711. //
  6712. //
  6713. // NT_TIB - Thread Information Block - Portable part.
  6714. //
  6715. // This is the subsystem portable part of the Thread Information Block.
  6716. // It appears as the first part of the TEB for all threads which have
  6717. // a user mode component.
  6718. //
  6719. //
  6720. // begin_winnt
  6721. typedef struct _NT_TIB {
  6722. struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
  6723. PVOID StackBase;
  6724. PVOID StackLimit;
  6725. PVOID SubSystemTib;
  6726. union {
  6727. PVOID FiberData;
  6728. ULONG Version;
  6729. };
  6730. PVOID ArbitraryUserPointer;
  6731. struct _NT_TIB *Self;
  6732. } NT_TIB;
  6733. typedef NT_TIB *PNT_TIB;
  6734. //
  6735. // 32 and 64 bit specific version for wow64 and the debugger
  6736. //
  6737. typedef struct _NT_TIB32 {
  6738. ULONG ExceptionList;
  6739. ULONG StackBase;
  6740. ULONG StackLimit;
  6741. ULONG SubSystemTib;
  6742. union {
  6743. ULONG FiberData;
  6744. ULONG Version;
  6745. };
  6746. ULONG ArbitraryUserPointer;
  6747. ULONG Self;
  6748. } NT_TIB32, *PNT_TIB32;
  6749. typedef struct _NT_TIB64 {
  6750. ULONG64 ExceptionList;
  6751. ULONG64 StackBase;
  6752. ULONG64 StackLimit;
  6753. ULONG64 SubSystemTib;
  6754. union {
  6755. ULONG64 FiberData;
  6756. ULONG Version;
  6757. };
  6758. ULONG64 ArbitraryUserPointer;
  6759. ULONG64 Self;
  6760. } NT_TIB64, *PNT_TIB64;
  6761. //
  6762. // Process Information Classes
  6763. //
  6764. typedef enum _PROCESSINFOCLASS {
  6765. ProcessBasicInformation,
  6766. ProcessQuotaLimits,
  6767. ProcessIoCounters,
  6768. ProcessVmCounters,
  6769. ProcessTimes,
  6770. ProcessBasePriority,
  6771. ProcessRaisePriority,
  6772. ProcessDebugPort,
  6773. ProcessExceptionPort,
  6774. ProcessAccessToken,
  6775. ProcessLdtInformation,
  6776. ProcessLdtSize,
  6777. ProcessDefaultHardErrorMode,
  6778. ProcessIoPortHandlers, // Note: this is kernel mode only
  6779. ProcessPooledUsageAndLimits,
  6780. ProcessWorkingSetWatch,
  6781. ProcessUserModeIOPL,
  6782. ProcessEnableAlignmentFaultFixup,
  6783. ProcessPriorityClass,
  6784. ProcessWx86Information,
  6785. ProcessHandleCount,
  6786. ProcessAffinityMask,
  6787. ProcessPriorityBoost,
  6788. ProcessDeviceMap,
  6789. ProcessSessionInformation,
  6790. ProcessForegroundInformation,
  6791. ProcessWow64Information,
  6792. ProcessImageFileName,
  6793. ProcessLUIDDeviceMapsEnabled,
  6794. ProcessBreakOnTermination,
  6795. ProcessDebugObjectHandle,
  6796. ProcessDebugFlags,
  6797. ProcessHandleTracing,
  6798. MaxProcessInfoClass // MaxProcessInfoClass should always be the last enum
  6799. } PROCESSINFOCLASS;
  6800. //
  6801. // Thread Information Classes
  6802. //
  6803. typedef enum _THREADINFOCLASS {
  6804. ThreadBasicInformation,
  6805. ThreadTimes,
  6806. ThreadPriority,
  6807. ThreadBasePriority,
  6808. ThreadAffinityMask,
  6809. ThreadImpersonationToken,
  6810. ThreadDescriptorTableEntry,
  6811. ThreadEnableAlignmentFaultFixup,
  6812. ThreadEventPair_Reusable,
  6813. ThreadQuerySetWin32StartAddress,
  6814. ThreadZeroTlsCell,
  6815. ThreadPerformanceCount,
  6816. ThreadAmILastThread,
  6817. ThreadIdealProcessor,
  6818. ThreadPriorityBoost,
  6819. ThreadSetTlsArrayAddress,
  6820. ThreadIsIoPending,
  6821. ThreadHideFromDebugger,
  6822. ThreadBreakOnTermination,
  6823. MaxThreadInfoClass
  6824. } THREADINFOCLASS;
  6825. //
  6826. // Process Information Structures
  6827. //
  6828. //
  6829. // PageFaultHistory Information
  6830. // NtQueryInformationProcess using ProcessWorkingSetWatch
  6831. //
  6832. typedef struct _PROCESS_WS_WATCH_INFORMATION {
  6833. PVOID FaultingPc;
  6834. PVOID FaultingVa;
  6835. } PROCESS_WS_WATCH_INFORMATION, *PPROCESS_WS_WATCH_INFORMATION;
  6836. //
  6837. // Basic Process Information
  6838. // NtQueryInformationProcess using ProcessBasicInfo
  6839. //
  6840. typedef struct _PROCESS_BASIC_INFORMATION {
  6841. NTSTATUS ExitStatus;
  6842. PPEB PebBaseAddress;
  6843. ULONG_PTR AffinityMask;
  6844. KPRIORITY BasePriority;
  6845. ULONG_PTR UniqueProcessId;
  6846. ULONG_PTR InheritedFromUniqueProcessId;
  6847. } PROCESS_BASIC_INFORMATION;
  6848. typedef PROCESS_BASIC_INFORMATION *PPROCESS_BASIC_INFORMATION;
  6849. //
  6850. // Process Device Map information
  6851. // NtQueryInformationProcess using ProcessDeviceMap
  6852. // NtSetInformationProcess using ProcessDeviceMap
  6853. //
  6854. typedef struct _PROCESS_DEVICEMAP_INFORMATION {
  6855. union {
  6856. struct {
  6857. HANDLE DirectoryHandle;
  6858. } Set;
  6859. struct {
  6860. ULONG DriveMap;
  6861. UCHAR DriveType[ 32 ];
  6862. } Query;
  6863. };
  6864. } PROCESS_DEVICEMAP_INFORMATION, *PPROCESS_DEVICEMAP_INFORMATION;
  6865. typedef struct _PROCESS_DEVICEMAP_INFORMATION_EX {
  6866. union {
  6867. struct {
  6868. HANDLE DirectoryHandle;
  6869. } Set;
  6870. struct {
  6871. ULONG DriveMap;
  6872. UCHAR DriveType[ 32 ];
  6873. } Query;
  6874. };
  6875. ULONG Flags; // specifies that the query type
  6876. } PROCESS_DEVICEMAP_INFORMATION_EX, *PPROCESS_DEVICEMAP_INFORMATION_EX;
  6877. //
  6878. // PROCESS_DEVICEMAP_INFORMATION_EX flags
  6879. //
  6880. #define PROCESS_LUID_DOSDEVICES_ONLY 0x00000001
  6881. //
  6882. // Multi-User Session specific Process Information
  6883. // NtQueryInformationProcess using ProcessSessionInformation
  6884. //
  6885. typedef struct _PROCESS_SESSION_INFORMATION {
  6886. ULONG SessionId;
  6887. } PROCESS_SESSION_INFORMATION, *PPROCESS_SESSION_INFORMATION;
  6888. typedef struct _PROCESS_HANDLE_TRACING_ENABLE {
  6889. ULONG Flags;
  6890. } PROCESS_HANDLE_TRACING_ENABLE, *PPROCESS_HANDLE_TRACING_ENABLE;
  6891. #define PROCESS_HANDLE_TRACING_MAX_STACKS 16
  6892. typedef struct _PROCESS_HANDLE_TRACING_ENTRY {
  6893. HANDLE Handle;
  6894. CLIENT_ID ClientId;
  6895. ULONG Type;
  6896. PVOID Stacks[PROCESS_HANDLE_TRACING_MAX_STACKS];
  6897. } PROCESS_HANDLE_TRACING_ENTRY, *PPROCESS_HANDLE_TRACING_ENTRY;
  6898. typedef struct _PROCESS_HANDLE_TRACING_QUERY {
  6899. HANDLE Handle;
  6900. ULONG TotalTraces;
  6901. PROCESS_HANDLE_TRACING_ENTRY HandleTrace[1];
  6902. } PROCESS_HANDLE_TRACING_QUERY, *PPROCESS_HANDLE_TRACING_QUERY;
  6903. //
  6904. // Process Quotas
  6905. // NtQueryInformationProcess using ProcessQuotaLimits
  6906. // NtQueryInformationProcess using ProcessPooledQuotaLimits
  6907. // NtSetInformationProcess using ProcessQuotaLimits
  6908. //
  6909. // begin_winnt
  6910. typedef struct _QUOTA_LIMITS {
  6911. SIZE_T PagedPoolLimit;
  6912. SIZE_T NonPagedPoolLimit;
  6913. SIZE_T MinimumWorkingSetSize;
  6914. SIZE_T MaximumWorkingSetSize;
  6915. SIZE_T PagefileLimit;
  6916. LARGE_INTEGER TimeLimit;
  6917. } QUOTA_LIMITS;
  6918. typedef QUOTA_LIMITS *PQUOTA_LIMITS;
  6919. // end_winnt
  6920. //
  6921. // Process I/O Counters
  6922. // NtQueryInformationProcess using ProcessIoCounters
  6923. //
  6924. // begin_winnt
  6925. typedef struct _IO_COUNTERS {
  6926. ULONGLONG ReadOperationCount;
  6927. ULONGLONG WriteOperationCount;
  6928. ULONGLONG OtherOperationCount;
  6929. ULONGLONG ReadTransferCount;
  6930. ULONGLONG WriteTransferCount;
  6931. ULONGLONG OtherTransferCount;
  6932. } IO_COUNTERS;
  6933. typedef IO_COUNTERS *PIO_COUNTERS;
  6934. // end_winnt
  6935. //
  6936. // Process Virtual Memory Counters
  6937. // NtQueryInformationProcess using ProcessVmCounters
  6938. //
  6939. typedef struct _VM_COUNTERS {
  6940. SIZE_T PeakVirtualSize;
  6941. SIZE_T VirtualSize;
  6942. ULONG PageFaultCount;
  6943. SIZE_T PeakWorkingSetSize;
  6944. SIZE_T WorkingSetSize;
  6945. SIZE_T QuotaPeakPagedPoolUsage;
  6946. SIZE_T QuotaPagedPoolUsage;
  6947. SIZE_T QuotaPeakNonPagedPoolUsage;
  6948. SIZE_T QuotaNonPagedPoolUsage;
  6949. SIZE_T PagefileUsage;
  6950. SIZE_T PeakPagefileUsage;
  6951. } VM_COUNTERS;
  6952. typedef VM_COUNTERS *PVM_COUNTERS;
  6953. typedef struct _VM_COUNTERS_EX {
  6954. SIZE_T PeakVirtualSize;
  6955. SIZE_T VirtualSize;
  6956. ULONG PageFaultCount;
  6957. SIZE_T PeakWorkingSetSize;
  6958. SIZE_T WorkingSetSize;
  6959. SIZE_T QuotaPeakPagedPoolUsage;
  6960. SIZE_T QuotaPagedPoolUsage;
  6961. SIZE_T QuotaPeakNonPagedPoolUsage;
  6962. SIZE_T QuotaNonPagedPoolUsage;
  6963. SIZE_T PagefileUsage;
  6964. SIZE_T PeakPagefileUsage;
  6965. SIZE_T PrivateUsage;
  6966. } VM_COUNTERS_EX;
  6967. typedef VM_COUNTERS_EX *PVM_COUNTERS_EX;
  6968. //
  6969. // Process Pooled Quota Usage and Limits
  6970. // NtQueryInformationProcess using ProcessPooledUsageAndLimits
  6971. //
  6972. typedef struct _POOLED_USAGE_AND_LIMITS {
  6973. SIZE_T PeakPagedPoolUsage;
  6974. SIZE_T PagedPoolUsage;
  6975. SIZE_T PagedPoolLimit;
  6976. SIZE_T PeakNonPagedPoolUsage;
  6977. SIZE_T NonPagedPoolUsage;
  6978. SIZE_T NonPagedPoolLimit;
  6979. SIZE_T PeakPagefileUsage;
  6980. SIZE_T PagefileUsage;
  6981. SIZE_T PagefileLimit;
  6982. } POOLED_USAGE_AND_LIMITS;
  6983. typedef POOLED_USAGE_AND_LIMITS *PPOOLED_USAGE_AND_LIMITS;
  6984. //
  6985. // Process Security Context Information
  6986. // NtSetInformationProcess using ProcessAccessToken
  6987. // PROCESS_SET_ACCESS_TOKEN access to the process is needed
  6988. // to use this info level.
  6989. //
  6990. typedef struct _PROCESS_ACCESS_TOKEN {
  6991. //
  6992. // Handle to Primary token to assign to the process.
  6993. // TOKEN_ASSIGN_PRIMARY access to this token is needed.
  6994. //
  6995. HANDLE Token;
  6996. //
  6997. // Handle to the initial thread of the process.
  6998. // A process's access token can only be changed if the process has
  6999. // no threads or one thread. If the process has no threads, this
  7000. // field must be set to NULL. Otherwise, it must contain a handle
  7001. // open to the process's only thread. THREAD_QUERY_INFORMATION access
  7002. // is needed via this handle.
  7003. HANDLE Thread;
  7004. } PROCESS_ACCESS_TOKEN, *PPROCESS_ACCESS_TOKEN;
  7005. //
  7006. // Process/Thread System and User Time
  7007. // NtQueryInformationProcess using ProcessTimes
  7008. // NtQueryInformationThread using ThreadTimes
  7009. //
  7010. typedef struct _KERNEL_USER_TIMES {
  7011. LARGE_INTEGER CreateTime;
  7012. LARGE_INTEGER ExitTime;
  7013. LARGE_INTEGER KernelTime;
  7014. LARGE_INTEGER UserTime;
  7015. } KERNEL_USER_TIMES;
  7016. typedef KERNEL_USER_TIMES *PKERNEL_USER_TIMES;
  7017. NTSYSCALLAPI
  7018. NTSTATUS
  7019. NTAPI
  7020. NtOpenProcess (
  7021. OUT PHANDLE ProcessHandle,
  7022. IN ACCESS_MASK DesiredAccess,
  7023. IN POBJECT_ATTRIBUTES ObjectAttributes,
  7024. IN PCLIENT_ID ClientId OPTIONAL
  7025. );
  7026. #define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
  7027. NTSYSCALLAPI
  7028. NTSTATUS
  7029. NTAPI
  7030. NtQueryInformationProcess(
  7031. IN HANDLE ProcessHandle,
  7032. IN PROCESSINFOCLASS ProcessInformationClass,
  7033. OUT PVOID ProcessInformation,
  7034. IN ULONG ProcessInformationLength,
  7035. OUT PULONG ReturnLength OPTIONAL
  7036. );
  7037. #define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
  7038. NTSYSCALLAPI
  7039. NTSTATUS
  7040. NTAPI
  7041. NtSetInformationThread(
  7042. IN HANDLE ThreadHandle,
  7043. IN THREADINFOCLASS ThreadInformationClass,
  7044. IN PVOID ThreadInformation,
  7045. IN ULONG ThreadInformationLength
  7046. );
  7047. //
  7048. // Security operation mode of the system is held in a control
  7049. // longword.
  7050. //
  7051. typedef ULONG LSA_OPERATIONAL_MODE, *PLSA_OPERATIONAL_MODE;
  7052. //
  7053. // Used by a logon process to indicate what type of logon is being
  7054. // requested.
  7055. //
  7056. typedef enum _SECURITY_LOGON_TYPE {
  7057. Interactive = 2, // Interactively logged on (locally or remotely)
  7058. Network, // Accessing system via network
  7059. Batch, // Started via a batch queue
  7060. Service, // Service started by service controller
  7061. Proxy, // Proxy logon
  7062. Unlock, // Unlock workstation
  7063. NetworkCleartext, // Network logon with cleartext credentials
  7064. NewCredentials, // Clone caller, new default credentials
  7065. RemoteInteractive, // Remote, yet interactive. Terminal server
  7066. CachedInteractive // Try cached credentials without hitting the net.
  7067. } SECURITY_LOGON_TYPE, *PSECURITY_LOGON_TYPE;
  7068. typedef UNICODE_STRING LSA_UNICODE_STRING, *PLSA_UNICODE_STRING;
  7069. typedef STRING LSA_STRING, *PLSA_STRING;
  7070. typedef OBJECT_ATTRIBUTES LSA_OBJECT_ATTRIBUTES, *PLSA_OBJECT_ATTRIBUTES;
  7071. NTSTATUS
  7072. NTAPI
  7073. LsaRegisterLogonProcess (
  7074. IN PLSA_STRING LogonProcessName,
  7075. OUT PHANDLE LsaHandle,
  7076. OUT PLSA_OPERATIONAL_MODE SecurityMode
  7077. );
  7078. NTSTATUS
  7079. NTAPI
  7080. LsaLogonUser (
  7081. IN HANDLE LsaHandle,
  7082. IN PLSA_STRING OriginName,
  7083. IN SECURITY_LOGON_TYPE LogonType,
  7084. IN ULONG AuthenticationPackage,
  7085. IN PVOID AuthenticationInformation,
  7086. IN ULONG AuthenticationInformationLength,
  7087. IN PTOKEN_GROUPS LocalGroups OPTIONAL,
  7088. IN PTOKEN_SOURCE SourceContext,
  7089. OUT PVOID *ProfileBuffer,
  7090. OUT PULONG ProfileBufferLength,
  7091. OUT PLUID LogonId,
  7092. OUT PHANDLE Token,
  7093. OUT PQUOTA_LIMITS Quotas,
  7094. OUT PNTSTATUS SubStatus
  7095. );
  7096. NTSTATUS
  7097. NTAPI
  7098. LsaFreeReturnBuffer (
  7099. IN PVOID Buffer
  7100. );
  7101. #ifndef _NTLSA_IFS_
  7102. #define _NTLSA_IFS_
  7103. #endif
  7104. /////////////////////////////////////////////////////////////////////////
  7105. // //
  7106. // Name of the MSV1_0 authentication package //
  7107. // //
  7108. /////////////////////////////////////////////////////////////////////////
  7109. #define MSV1_0_PACKAGE_NAME "MICROSOFT_AUTHENTICATION_PACKAGE_V1_0"
  7110. #define MSV1_0_PACKAGE_NAMEW L"MICROSOFT_AUTHENTICATION_PACKAGE_V1_0"
  7111. #define MSV1_0_PACKAGE_NAMEW_LENGTH sizeof(MSV1_0_PACKAGE_NAMEW) - sizeof(WCHAR)
  7112. //
  7113. // Location of MSV authentication package data
  7114. //
  7115. #define MSV1_0_SUBAUTHENTICATION_KEY "SYSTEM\\CurrentControlSet\\Control\\Lsa\\MSV1_0"
  7116. #define MSV1_0_SUBAUTHENTICATION_VALUE "Auth"
  7117. /////////////////////////////////////////////////////////////////////////
  7118. // //
  7119. // Widely used MSV1_0 data types //
  7120. // //
  7121. /////////////////////////////////////////////////////////////////////////
  7122. ///////////////////////////////////////////////////////////////////////////////
  7123. // //
  7124. // LOGON Related Data Structures
  7125. //
  7126. // //
  7127. ///////////////////////////////////////////////////////////////////////////////
  7128. //
  7129. // When a LsaLogonUser() call is dispatched to the MsV1_0 authentication
  7130. // package, the beginning of the AuthenticationInformation buffer is
  7131. // cast to a MSV1_0_LOGON_SUBMIT_TYPE to determine the type of logon
  7132. // being requested. Similarly, upon return, the type of profile buffer
  7133. // can be determined by typecasting it to a MSV_1_0_PROFILE_BUFFER_TYPE.
  7134. //
  7135. //
  7136. // MSV1.0 LsaLogonUser() submission message types.
  7137. //
  7138. typedef enum _MSV1_0_LOGON_SUBMIT_TYPE {
  7139. MsV1_0InteractiveLogon = 2,
  7140. MsV1_0Lm20Logon,
  7141. MsV1_0NetworkLogon,
  7142. MsV1_0SubAuthLogon,
  7143. MsV1_0WorkstationUnlockLogon = 7
  7144. } MSV1_0_LOGON_SUBMIT_TYPE, *PMSV1_0_LOGON_SUBMIT_TYPE;
  7145. //
  7146. // MSV1.0 LsaLogonUser() profile buffer types.
  7147. //
  7148. typedef enum _MSV1_0_PROFILE_BUFFER_TYPE {
  7149. MsV1_0InteractiveProfile = 2,
  7150. MsV1_0Lm20LogonProfile,
  7151. MsV1_0SmartCardProfile
  7152. } MSV1_0_PROFILE_BUFFER_TYPE, *PMSV1_0_PROFILE_BUFFER_TYPE;
  7153. //
  7154. // MsV1_0InteractiveLogon
  7155. //
  7156. // The AuthenticationInformation buffer of an LsaLogonUser() call to
  7157. // perform an interactive logon contains the following data structure:
  7158. //
  7159. typedef struct _MSV1_0_INTERACTIVE_LOGON {
  7160. MSV1_0_LOGON_SUBMIT_TYPE MessageType;
  7161. UNICODE_STRING LogonDomainName;
  7162. UNICODE_STRING UserName;
  7163. UNICODE_STRING Password;
  7164. } MSV1_0_INTERACTIVE_LOGON, *PMSV1_0_INTERACTIVE_LOGON;
  7165. //
  7166. // Where:
  7167. //
  7168. // MessageType - Contains the type of logon being requested. This
  7169. // field must be set to MsV1_0InteractiveLogon.
  7170. //
  7171. // UserName - Is a string representing the user's account name. The
  7172. // name may be up to 255 characters long. The name is treated case
  7173. // insensitive.
  7174. //
  7175. // Password - Is a string containing the user's cleartext password.
  7176. // The password may be up to 255 characters long and contain any
  7177. // UNICODE value.
  7178. //
  7179. //
  7180. //
  7181. // The ProfileBuffer returned upon a successful logon of this type
  7182. // contains the following data structure:
  7183. //
  7184. typedef struct _MSV1_0_INTERACTIVE_PROFILE {
  7185. MSV1_0_PROFILE_BUFFER_TYPE MessageType;
  7186. USHORT LogonCount;
  7187. USHORT BadPasswordCount;
  7188. LARGE_INTEGER LogonTime;
  7189. LARGE_INTEGER LogoffTime;
  7190. LARGE_INTEGER KickOffTime;
  7191. LARGE_INTEGER PasswordLastSet;
  7192. LARGE_INTEGER PasswordCanChange;
  7193. LARGE_INTEGER PasswordMustChange;
  7194. UNICODE_STRING LogonScript;
  7195. UNICODE_STRING HomeDirectory;
  7196. UNICODE_STRING FullName;
  7197. UNICODE_STRING ProfilePath;
  7198. UNICODE_STRING HomeDirectoryDrive;
  7199. UNICODE_STRING LogonServer;
  7200. ULONG UserFlags;
  7201. } MSV1_0_INTERACTIVE_PROFILE, *PMSV1_0_INTERACTIVE_PROFILE;
  7202. //
  7203. // where:
  7204. //
  7205. // MessageType - Identifies the type of profile data being returned.
  7206. // Contains the type of logon being requested. This field must
  7207. // be set to MsV1_0InteractiveProfile.
  7208. //
  7209. // LogonCount - Number of times the user is currently logged on.
  7210. //
  7211. // BadPasswordCount - Number of times a bad password was applied to
  7212. // the account since last successful logon.
  7213. //
  7214. // LogonTime - Time when user last logged on. This is an absolute
  7215. // format NT standard time value.
  7216. //
  7217. // LogoffTime - Time when user should log off. This is an absolute
  7218. // format NT standard time value.
  7219. //
  7220. // KickOffTime - Time when system should force user logoff. This is
  7221. // an absolute format NT standard time value.
  7222. //
  7223. // PasswordLastChanged - Time and date the password was last
  7224. // changed. This is an absolute format NT standard time
  7225. // value.
  7226. //
  7227. // PasswordCanChange - Time and date when the user can change the
  7228. // password. This is an absolute format NT time value. To
  7229. // prevent a password from ever changing, set this field to a
  7230. // date very far into the future.
  7231. //
  7232. // PasswordMustChange - Time and date when the user must change the
  7233. // password. If the user can never change the password, this
  7234. // field is undefined. This is an absolute format NT time
  7235. // value.
  7236. //
  7237. // LogonScript - The (relative) path to the account's logon
  7238. // script.
  7239. //
  7240. // HomeDirectory - The home directory for the user.
  7241. //
  7242. //
  7243. // MsV1_0Lm20Logon and MsV1_0NetworkLogon
  7244. //
  7245. // The AuthenticationInformation buffer of an LsaLogonUser() call to
  7246. // perform an network logon contains the following data structure:
  7247. //
  7248. // MsV1_0NetworkLogon logon differs from MsV1_0Lm20Logon in that the
  7249. // ParameterControl field exists.
  7250. //
  7251. #define MSV1_0_CHALLENGE_LENGTH 8
  7252. #define MSV1_0_USER_SESSION_KEY_LENGTH 16
  7253. #define MSV1_0_LANMAN_SESSION_KEY_LENGTH 8
  7254. //
  7255. // Values for ParameterControl.
  7256. //
  7257. #define MSV1_0_CLEARTEXT_PASSWORD_ALLOWED 0x02
  7258. #define MSV1_0_UPDATE_LOGON_STATISTICS 0x04
  7259. #define MSV1_0_RETURN_USER_PARAMETERS 0x08
  7260. #define MSV1_0_DONT_TRY_GUEST_ACCOUNT 0x10
  7261. #define MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT 0x20
  7262. #define MSV1_0_RETURN_PASSWORD_EXPIRY 0x40
  7263. // this next flag says that CaseInsensitiveChallengeResponse
  7264. // (aka LmResponse) contains a client challenge in the first 8 bytes
  7265. #define MSV1_0_USE_CLIENT_CHALLENGE 0x80
  7266. #define MSV1_0_TRY_GUEST_ACCOUNT_ONLY 0x100
  7267. #define MSV1_0_RETURN_PROFILE_PATH 0x200
  7268. #define MSV1_0_TRY_SPECIFIED_DOMAIN_ONLY 0x400
  7269. #define MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT 0x800
  7270. #define MSV1_0_DISABLE_PERSONAL_FALLBACK 0x00001000
  7271. #define MSV1_0_ALLOW_FORCE_GUEST 0x00002000
  7272. #define MSV1_0_SUBAUTHENTICATION_DLL_EX 0x00100000
  7273. //
  7274. // The high order byte is a value indicating the SubAuthentication DLL.
  7275. // Zero indicates no SubAuthentication DLL.
  7276. //
  7277. #define MSV1_0_SUBAUTHENTICATION_DLL 0xFF000000
  7278. #define MSV1_0_SUBAUTHENTICATION_DLL_SHIFT 24
  7279. #define MSV1_0_MNS_LOGON 0x01000000
  7280. //
  7281. // This is the list of subauthentication dlls used in MS
  7282. //
  7283. #define MSV1_0_SUBAUTHENTICATION_DLL_RAS 2
  7284. #define MSV1_0_SUBAUTHENTICATION_DLL_IIS 132
  7285. typedef struct _MSV1_0_LM20_LOGON {
  7286. MSV1_0_LOGON_SUBMIT_TYPE MessageType;
  7287. UNICODE_STRING LogonDomainName;
  7288. UNICODE_STRING UserName;
  7289. UNICODE_STRING Workstation;
  7290. UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  7291. STRING CaseSensitiveChallengeResponse;
  7292. STRING CaseInsensitiveChallengeResponse;
  7293. ULONG ParameterControl;
  7294. } MSV1_0_LM20_LOGON, * PMSV1_0_LM20_LOGON;
  7295. //
  7296. // NT 5.0 SubAuth dlls can use this struct
  7297. //
  7298. typedef struct _MSV1_0_SUBAUTH_LOGON{
  7299. MSV1_0_LOGON_SUBMIT_TYPE MessageType;
  7300. UNICODE_STRING LogonDomainName;
  7301. UNICODE_STRING UserName;
  7302. UNICODE_STRING Workstation;
  7303. UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  7304. STRING AuthenticationInfo1;
  7305. STRING AuthenticationInfo2;
  7306. ULONG ParameterControl;
  7307. ULONG SubAuthPackageId;
  7308. } MSV1_0_SUBAUTH_LOGON, * PMSV1_0_SUBAUTH_LOGON;
  7309. //
  7310. // Values for UserFlags.
  7311. //
  7312. #define LOGON_GUEST 0x01
  7313. #define LOGON_NOENCRYPTION 0x02
  7314. #define LOGON_CACHED_ACCOUNT 0x04
  7315. #define LOGON_USED_LM_PASSWORD 0x08
  7316. #define LOGON_EXTRA_SIDS 0x20
  7317. #define LOGON_SUBAUTH_SESSION_KEY 0x40
  7318. #define LOGON_SERVER_TRUST_ACCOUNT 0x80
  7319. #define LOGON_NTLMV2_ENABLED 0x100 // says DC understands NTLMv2
  7320. #define LOGON_RESOURCE_GROUPS 0x200
  7321. #define LOGON_PROFILE_PATH_RETURNED 0x400
  7322. //
  7323. // The high order byte is reserved for return by SubAuthentication DLLs.
  7324. //
  7325. #define MSV1_0_SUBAUTHENTICATION_FLAGS 0xFF000000
  7326. // Values returned by the MSV1_0_MNS_LOGON SubAuthentication DLL
  7327. #define LOGON_GRACE_LOGON 0x01000000
  7328. typedef struct _MSV1_0_LM20_LOGON_PROFILE {
  7329. MSV1_0_PROFILE_BUFFER_TYPE MessageType;
  7330. LARGE_INTEGER KickOffTime;
  7331. LARGE_INTEGER LogoffTime;
  7332. ULONG UserFlags;
  7333. UCHAR UserSessionKey[MSV1_0_USER_SESSION_KEY_LENGTH];
  7334. UNICODE_STRING LogonDomainName;
  7335. UCHAR LanmanSessionKey[MSV1_0_LANMAN_SESSION_KEY_LENGTH];
  7336. UNICODE_STRING LogonServer;
  7337. UNICODE_STRING UserParameters;
  7338. } MSV1_0_LM20_LOGON_PROFILE, * PMSV1_0_LM20_LOGON_PROFILE;
  7339. //
  7340. // Supplemental credentials structure used for passing credentials into
  7341. // MSV1_0 from other packages
  7342. //
  7343. #define MSV1_0_OWF_PASSWORD_LENGTH 16
  7344. #define MSV1_0_CRED_LM_PRESENT 0x1
  7345. #define MSV1_0_CRED_NT_PRESENT 0x2
  7346. #define MSV1_0_CRED_VERSION 0
  7347. typedef struct _MSV1_0_SUPPLEMENTAL_CREDENTIAL {
  7348. ULONG Version;
  7349. ULONG Flags;
  7350. UCHAR LmPassword[MSV1_0_OWF_PASSWORD_LENGTH];
  7351. UCHAR NtPassword[MSV1_0_OWF_PASSWORD_LENGTH];
  7352. } MSV1_0_SUPPLEMENTAL_CREDENTIAL, *PMSV1_0_SUPPLEMENTAL_CREDENTIAL;
  7353. //
  7354. // NTLM3 definitions.
  7355. //
  7356. #define MSV1_0_NTLM3_RESPONSE_LENGTH 16
  7357. #define MSV1_0_NTLM3_OWF_LENGTH 16
  7358. //
  7359. // this is the longest amount of time we'll allow challenge response
  7360. // pairs to be used. Note that this also has to allow for worst case clock skew
  7361. //
  7362. #define MSV1_0_MAX_NTLM3_LIFE 129600 // 36 hours (in seconds)
  7363. #define MSV1_0_MAX_AVL_SIZE 64000
  7364. //
  7365. // MsvAvFlags bit values
  7366. //
  7367. #define MSV1_0_AV_FLAG_FORCE_GUEST 0x00000001
  7368. // this is an MSV1_0 private data structure, defining the layout of an NTLM3 response, as sent by a
  7369. // client in the NtChallengeResponse field of the NETLOGON_NETWORK_INFO structure. If can be differentiated
  7370. // from an old style NT response by its length. This is crude, but it needs to pass through servers and
  7371. // the servers' DCs that do not understand NTLM3 but that are willing to pass longer responses.
  7372. typedef struct _MSV1_0_NTLM3_RESPONSE {
  7373. UCHAR Response[MSV1_0_NTLM3_RESPONSE_LENGTH]; // hash of OWF of password with all the following fields
  7374. UCHAR RespType; // id number of response; current is 1
  7375. UCHAR HiRespType; // highest id number understood by client
  7376. USHORT Flags; // reserved; must be sent as zero at this version
  7377. ULONG MsgWord; // 32 bit message from client to server (for use by auth protocol)
  7378. ULONGLONG TimeStamp; // time stamp when client generated response -- NT system time, quad part
  7379. UCHAR ChallengeFromClient[MSV1_0_CHALLENGE_LENGTH];
  7380. ULONG AvPairsOff; // offset to start of AvPairs (to allow future expansion)
  7381. UCHAR Buffer[1]; // start of buffer with AV pairs (or future stuff -- so use the offset)
  7382. } MSV1_0_NTLM3_RESPONSE, *PMSV1_0_NTLM3_RESPONSE;
  7383. #define MSV1_0_NTLM3_INPUT_LENGTH (sizeof(MSV1_0_NTLM3_RESPONSE) - MSV1_0_NTLM3_RESPONSE_LENGTH)
  7384. typedef enum {
  7385. MsvAvEOL, // end of list
  7386. MsvAvNbComputerName, // server's computer name -- NetBIOS
  7387. MsvAvNbDomainName, // server's domain name -- NetBIOS
  7388. MsvAvDnsComputerName, // server's computer name -- DNS
  7389. MsvAvDnsDomainName, // server's domain name -- DNS
  7390. MsvAvDnsTreeName, // server's tree name -- DNS
  7391. MsvAvFlags // server's extended flags -- DWORD mask
  7392. } MSV1_0_AVID;
  7393. typedef struct _MSV1_0_AV_PAIR {
  7394. USHORT AvId;
  7395. USHORT AvLen;
  7396. // Data is treated as byte array following structure
  7397. } MSV1_0_AV_PAIR, *PMSV1_0_AV_PAIR;
  7398. ///////////////////////////////////////////////////////////////////////////////
  7399. // //
  7400. // CALL PACKAGE Related Data Structures //
  7401. // //
  7402. ///////////////////////////////////////////////////////////////////////////////
  7403. //
  7404. // MSV1.0 LsaCallAuthenticationPackage() submission and response
  7405. // message types.
  7406. //
  7407. typedef enum _MSV1_0_PROTOCOL_MESSAGE_TYPE {
  7408. MsV1_0Lm20ChallengeRequest = 0, // Both submission and response
  7409. MsV1_0Lm20GetChallengeResponse, // Both submission and response
  7410. MsV1_0EnumerateUsers, // Both submission and response
  7411. MsV1_0GetUserInfo, // Both submission and response
  7412. MsV1_0ReLogonUsers, // Submission only
  7413. MsV1_0ChangePassword, // Both submission and response
  7414. MsV1_0ChangeCachedPassword, // Both submission and response
  7415. MsV1_0GenericPassthrough, // Both submission and response
  7416. MsV1_0CacheLogon, // Submission only, no response
  7417. MsV1_0SubAuth, // Both submission and response
  7418. MsV1_0DeriveCredential, // Both submission and response
  7419. MsV1_0CacheLookup, // Both submission and response
  7420. MsV1_0SetProcessOption, // Submission only, no response
  7421. } MSV1_0_PROTOCOL_MESSAGE_TYPE, *PMSV1_0_PROTOCOL_MESSAGE_TYPE;
  7422. // end_ntsecapi
  7423. //
  7424. // MsV1_0Lm20ChallengeRequest submit buffer and response
  7425. //
  7426. typedef struct _MSV1_0_LM20_CHALLENGE_REQUEST {
  7427. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7428. } MSV1_0_LM20_CHALLENGE_REQUEST, *PMSV1_0_LM20_CHALLENGE_REQUEST;
  7429. typedef struct _MSV1_0_LM20_CHALLENGE_RESPONSE {
  7430. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7431. UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  7432. } MSV1_0_LM20_CHALLENGE_RESPONSE, *PMSV1_0_LM20_CHALLENGE_RESPONSE;
  7433. //
  7434. // MsV1_0Lm20GetChallengeResponse submit buffer and response
  7435. //
  7436. #define USE_PRIMARY_PASSWORD 0x01
  7437. #define RETURN_PRIMARY_USERNAME 0x02
  7438. #define RETURN_PRIMARY_LOGON_DOMAINNAME 0x04
  7439. #define RETURN_NON_NT_USER_SESSION_KEY 0x08
  7440. #define GENERATE_CLIENT_CHALLENGE 0x10
  7441. #define GCR_NTLM3_PARMS 0x20
  7442. #define GCR_TARGET_INFO 0x40 // ServerName field contains target info AV pairs
  7443. #define RETURN_RESERVED_PARAMETER 0x80 // was 0x10
  7444. #define GCR_ALLOW_NTLM 0x100
  7445. #define GCR_MACHINE_CREDENTIAL 0x400
  7446. //
  7447. // version 1 of the GETCHALLENRESP structure, which was used by RAS and others.
  7448. // compiled before the additional fields added to GETCHALLENRESP_REQUEST.
  7449. // here to allow sizing operations for backwards compatibility.
  7450. //
  7451. typedef struct _MSV1_0_GETCHALLENRESP_REQUEST_V1 {
  7452. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7453. ULONG ParameterControl;
  7454. LUID LogonId;
  7455. UNICODE_STRING Password;
  7456. UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  7457. } MSV1_0_GETCHALLENRESP_REQUEST_V1, *PMSV1_0_GETCHALLENRESP_REQUEST_V1;
  7458. typedef struct _MSV1_0_GETCHALLENRESP_REQUEST {
  7459. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7460. ULONG ParameterControl;
  7461. LUID LogonId;
  7462. UNICODE_STRING Password;
  7463. UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  7464. //
  7465. // the following 3 fields are only present if GCR_NTLM3_PARMS is set in ParameterControl
  7466. //
  7467. UNICODE_STRING UserName;
  7468. UNICODE_STRING LogonDomainName;
  7469. UNICODE_STRING ServerName; // server domain or target info AV pairs
  7470. } MSV1_0_GETCHALLENRESP_REQUEST, *PMSV1_0_GETCHALLENRESP_REQUEST;
  7471. typedef struct _MSV1_0_GETCHALLENRESP_RESPONSE {
  7472. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7473. STRING CaseSensitiveChallengeResponse;
  7474. STRING CaseInsensitiveChallengeResponse;
  7475. UNICODE_STRING UserName;
  7476. UNICODE_STRING LogonDomainName;
  7477. UCHAR UserSessionKey[MSV1_0_USER_SESSION_KEY_LENGTH];
  7478. UCHAR LanmanSessionKey[MSV1_0_LANMAN_SESSION_KEY_LENGTH];
  7479. } MSV1_0_GETCHALLENRESP_RESPONSE, *PMSV1_0_GETCHALLENRESP_RESPONSE;
  7480. //
  7481. // MsV1_0EnumerateUsers submit buffer and response
  7482. //
  7483. typedef struct _MSV1_0_ENUMUSERS_REQUEST {
  7484. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7485. } MSV1_0_ENUMUSERS_REQUEST, *PMSV1_0_ENUMUSERS_REQUEST;
  7486. typedef struct _MSV1_0_ENUMUSERS_RESPONSE {
  7487. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7488. ULONG NumberOfLoggedOnUsers;
  7489. PLUID LogonIds;
  7490. PULONG EnumHandles;
  7491. } MSV1_0_ENUMUSERS_RESPONSE, *PMSV1_0_ENUMUSERS_RESPONSE;
  7492. //
  7493. // MsV1_0GetUserInfo submit buffer and response
  7494. //
  7495. typedef struct _MSV1_0_GETUSERINFO_REQUEST {
  7496. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7497. LUID LogonId;
  7498. } MSV1_0_GETUSERINFO_REQUEST, *PMSV1_0_GETUSERINFO_REQUEST;
  7499. typedef struct _MSV1_0_GETUSERINFO_RESPONSE {
  7500. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7501. PSID UserSid;
  7502. UNICODE_STRING UserName;
  7503. UNICODE_STRING LogonDomainName;
  7504. UNICODE_STRING LogonServer;
  7505. SECURITY_LOGON_TYPE LogonType;
  7506. } MSV1_0_GETUSERINFO_RESPONSE, *PMSV1_0_GETUSERINFO_RESPONSE;
  7507. // begin_winnt
  7508. //
  7509. // Define access rights to files and directories
  7510. //
  7511. //
  7512. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  7513. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  7514. // constants *MUST* always be in sync.
  7515. // The values are redefined in devioctl.h because they must be available to
  7516. // both DOS and NT.
  7517. //
  7518. #define FILE_READ_DATA ( 0x0001 ) // file & pipe
  7519. #define FILE_LIST_DIRECTORY ( 0x0001 ) // directory
  7520. #define FILE_WRITE_DATA ( 0x0002 ) // file & pipe
  7521. #define FILE_ADD_FILE ( 0x0002 ) // directory
  7522. #define FILE_APPEND_DATA ( 0x0004 ) // file
  7523. #define FILE_ADD_SUBDIRECTORY ( 0x0004 ) // directory
  7524. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 ) // named pipe
  7525. #define FILE_READ_EA ( 0x0008 ) // file & directory
  7526. #define FILE_WRITE_EA ( 0x0010 ) // file & directory
  7527. #define FILE_EXECUTE ( 0x0020 ) // file
  7528. #define FILE_TRAVERSE ( 0x0020 ) // directory
  7529. #define FILE_DELETE_CHILD ( 0x0040 ) // directory
  7530. #define FILE_READ_ATTRIBUTES ( 0x0080 ) // all
  7531. #define FILE_WRITE_ATTRIBUTES ( 0x0100 ) // all
  7532. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  7533. #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\
  7534. FILE_READ_DATA |\
  7535. FILE_READ_ATTRIBUTES |\
  7536. FILE_READ_EA |\
  7537. SYNCHRONIZE)
  7538. #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE |\
  7539. FILE_WRITE_DATA |\
  7540. FILE_WRITE_ATTRIBUTES |\
  7541. FILE_WRITE_EA |\
  7542. FILE_APPEND_DATA |\
  7543. SYNCHRONIZE)
  7544. #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE |\
  7545. FILE_READ_ATTRIBUTES |\
  7546. FILE_EXECUTE |\
  7547. SYNCHRONIZE)
  7548. // end_winnt
  7549. //
  7550. // Define share access rights to files and directories
  7551. //
  7552. #define FILE_SHARE_READ 0x00000001 // winnt
  7553. #define FILE_SHARE_WRITE 0x00000002 // winnt
  7554. #define FILE_SHARE_DELETE 0x00000004 // winnt
  7555. #define FILE_SHARE_VALID_FLAGS 0x00000007
  7556. //
  7557. // Define the file attributes values
  7558. //
  7559. // Note: 0x00000008 is reserved for use for the old DOS VOLID (volume ID)
  7560. // and is therefore not considered valid in NT.
  7561. //
  7562. // Note: 0x00000010 is reserved for use for the old DOS SUBDIRECTORY flag
  7563. // and is therefore not considered valid in NT. This flag has
  7564. // been disassociated with file attributes since the other flags are
  7565. // protected with READ_ and WRITE_ATTRIBUTES access to the file.
  7566. //
  7567. // Note: Note also that the order of these flags is set to allow both the
  7568. // FAT and the Pinball File Systems to directly set the attributes
  7569. // flags in attributes words without having to pick each flag out
  7570. // individually. The order of these flags should not be changed!
  7571. //
  7572. #define FILE_ATTRIBUTE_READONLY 0x00000001 // winnt
  7573. #define FILE_ATTRIBUTE_HIDDEN 0x00000002 // winnt
  7574. #define FILE_ATTRIBUTE_SYSTEM 0x00000004 // winnt
  7575. //OLD DOS VOLID 0x00000008
  7576. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010 // winnt
  7577. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020 // winnt
  7578. #define FILE_ATTRIBUTE_DEVICE 0x00000040 // winnt
  7579. #define FILE_ATTRIBUTE_NORMAL 0x00000080 // winnt
  7580. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100 // winnt
  7581. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 // winnt
  7582. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 // winnt
  7583. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800 // winnt
  7584. #define FILE_ATTRIBUTE_OFFLINE 0x00001000 // winnt
  7585. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 // winnt
  7586. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 // winnt
  7587. #define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
  7588. #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x000031a7
  7589. //
  7590. // Define the create disposition values
  7591. //
  7592. #define FILE_SUPERSEDE 0x00000000
  7593. #define FILE_OPEN 0x00000001
  7594. #define FILE_CREATE 0x00000002
  7595. #define FILE_OPEN_IF 0x00000003
  7596. #define FILE_OVERWRITE 0x00000004
  7597. #define FILE_OVERWRITE_IF 0x00000005
  7598. #define FILE_MAXIMUM_DISPOSITION 0x00000005
  7599. //
  7600. // Define the create/open option flags
  7601. //
  7602. #define FILE_DIRECTORY_FILE 0x00000001
  7603. #define FILE_WRITE_THROUGH 0x00000002
  7604. #define FILE_SEQUENTIAL_ONLY 0x00000004
  7605. #define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
  7606. #define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
  7607. #define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
  7608. #define FILE_NON_DIRECTORY_FILE 0x00000040
  7609. #define FILE_CREATE_TREE_CONNECTION 0x00000080
  7610. #define FILE_COMPLETE_IF_OPLOCKED 0x00000100
  7611. #define FILE_NO_EA_KNOWLEDGE 0x00000200
  7612. #define FILE_OPEN_FOR_RECOVERY 0x00000400
  7613. #define FILE_RANDOM_ACCESS 0x00000800
  7614. #define FILE_DELETE_ON_CLOSE 0x00001000
  7615. #define FILE_OPEN_BY_FILE_ID 0x00002000
  7616. #define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
  7617. #define FILE_NO_COMPRESSION 0x00008000
  7618. #define FILE_RESERVE_OPFILTER 0x00100000
  7619. #define FILE_OPEN_REPARSE_POINT 0x00200000
  7620. #define FILE_OPEN_NO_RECALL 0x00400000
  7621. #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
  7622. #define FILE_COPY_STRUCTURED_STORAGE 0x00000041
  7623. #define FILE_STRUCTURED_STORAGE 0x00000441
  7624. #define FILE_VALID_OPTION_FLAGS 0x00ffffff
  7625. #define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
  7626. #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
  7627. #define FILE_VALID_SET_FLAGS 0x00000036
  7628. //
  7629. // Define the I/O status information return values for NtCreateFile/NtOpenFile
  7630. //
  7631. #define FILE_SUPERSEDED 0x00000000
  7632. #define FILE_OPENED 0x00000001
  7633. #define FILE_CREATED 0x00000002
  7634. #define FILE_OVERWRITTEN 0x00000003
  7635. #define FILE_EXISTS 0x00000004
  7636. #define FILE_DOES_NOT_EXIST 0x00000005
  7637. // end_ntddk end_wdm end_nthal
  7638. //
  7639. // Define the I/O status information return values for requests for oplocks
  7640. // via NtFsControlFile
  7641. //
  7642. #define FILE_OPLOCK_BROKEN_TO_LEVEL_2 0x00000007
  7643. #define FILE_OPLOCK_BROKEN_TO_NONE 0x00000008
  7644. //
  7645. // Define the I/O status information return values for NtCreateFile/NtOpenFile
  7646. // when the sharing access fails but a batch oplock break is in progress
  7647. //
  7648. #define FILE_OPBATCH_BREAK_UNDERWAY 0x00000009
  7649. //
  7650. // Define the filter flags for NtNotifyChangeDirectoryFile
  7651. //
  7652. #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001 // winnt
  7653. #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002 // winnt
  7654. #define FILE_NOTIFY_CHANGE_NAME 0x00000003
  7655. #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004 // winnt
  7656. #define FILE_NOTIFY_CHANGE_SIZE 0x00000008 // winnt
  7657. #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010 // winnt
  7658. #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020 // winnt
  7659. #define FILE_NOTIFY_CHANGE_CREATION 0x00000040 // winnt
  7660. #define FILE_NOTIFY_CHANGE_EA 0x00000080
  7661. #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100 // winnt
  7662. #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
  7663. #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
  7664. #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
  7665. #define FILE_NOTIFY_VALID_MASK 0x00000fff
  7666. //
  7667. // Define the file action type codes for NtNotifyChangeDirectoryFile
  7668. //
  7669. #define FILE_ACTION_ADDED 0x00000001 // winnt
  7670. #define FILE_ACTION_REMOVED 0x00000002 // winnt
  7671. #define FILE_ACTION_MODIFIED 0x00000003 // winnt
  7672. #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004 // winnt
  7673. #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005 // winnt
  7674. #define FILE_ACTION_ADDED_STREAM 0x00000006
  7675. #define FILE_ACTION_REMOVED_STREAM 0x00000007
  7676. #define FILE_ACTION_MODIFIED_STREAM 0x00000008
  7677. #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
  7678. #define FILE_ACTION_ID_NOT_TUNNELLED 0x0000000A
  7679. #define FILE_ACTION_TUNNELLED_ID_COLLISION 0x0000000B
  7680. //
  7681. // Define the NamedPipeType flags for NtCreateNamedPipeFile
  7682. //
  7683. #define FILE_PIPE_BYTE_STREAM_TYPE 0x00000000
  7684. #define FILE_PIPE_MESSAGE_TYPE 0x00000001
  7685. //
  7686. // Define the CompletionMode flags for NtCreateNamedPipeFile
  7687. //
  7688. #define FILE_PIPE_QUEUE_OPERATION 0x00000000
  7689. #define FILE_PIPE_COMPLETE_OPERATION 0x00000001
  7690. //
  7691. // Define the ReadMode flags for NtCreateNamedPipeFile
  7692. //
  7693. #define FILE_PIPE_BYTE_STREAM_MODE 0x00000000
  7694. #define FILE_PIPE_MESSAGE_MODE 0x00000001
  7695. //
  7696. // Define the NamedPipeConfiguration flags for NtQueryInformation
  7697. //
  7698. #define FILE_PIPE_INBOUND 0x00000000
  7699. #define FILE_PIPE_OUTBOUND 0x00000001
  7700. #define FILE_PIPE_FULL_DUPLEX 0x00000002
  7701. //
  7702. // Define the NamedPipeState flags for NtQueryInformation
  7703. //
  7704. #define FILE_PIPE_DISCONNECTED_STATE 0x00000001
  7705. #define FILE_PIPE_LISTENING_STATE 0x00000002
  7706. #define FILE_PIPE_CONNECTED_STATE 0x00000003
  7707. #define FILE_PIPE_CLOSING_STATE 0x00000004
  7708. //
  7709. // Define the NamedPipeEnd flags for NtQueryInformation
  7710. //
  7711. #define FILE_PIPE_CLIENT_END 0x00000000
  7712. #define FILE_PIPE_SERVER_END 0x00000001
  7713. //
  7714. // Define special ByteOffset parameters for read and write operations
  7715. //
  7716. #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
  7717. #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
  7718. //
  7719. // Define alignment requirement values
  7720. //
  7721. #define FILE_BYTE_ALIGNMENT 0x00000000
  7722. #define FILE_WORD_ALIGNMENT 0x00000001
  7723. #define FILE_LONG_ALIGNMENT 0x00000003
  7724. #define FILE_QUAD_ALIGNMENT 0x00000007
  7725. #define FILE_OCTA_ALIGNMENT 0x0000000f
  7726. #define FILE_32_BYTE_ALIGNMENT 0x0000001f
  7727. #define FILE_64_BYTE_ALIGNMENT 0x0000003f
  7728. #define FILE_128_BYTE_ALIGNMENT 0x0000007f
  7729. #define FILE_256_BYTE_ALIGNMENT 0x000000ff
  7730. #define FILE_512_BYTE_ALIGNMENT 0x000001ff
  7731. //
  7732. // Define the maximum length of a filename string
  7733. //
  7734. #define MAXIMUM_FILENAME_LENGTH 256
  7735. // end_ntddk end_wdm end_nthal
  7736. //
  7737. // Define the file system attributes flags
  7738. //
  7739. #define FILE_CASE_SENSITIVE_SEARCH 0x00000001 // winnt
  7740. #define FILE_CASE_PRESERVED_NAMES 0x00000002 // winnt
  7741. #define FILE_UNICODE_ON_DISK 0x00000004 // winnt
  7742. #define FILE_PERSISTENT_ACLS 0x00000008 // winnt
  7743. #define FILE_FILE_COMPRESSION 0x00000010 // winnt
  7744. #define FILE_VOLUME_QUOTAS 0x00000020 // winnt
  7745. #define FILE_SUPPORTS_SPARSE_FILES 0x00000040 // winnt
  7746. #define FILE_SUPPORTS_REPARSE_POINTS 0x00000080 // winnt
  7747. #define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100 // winnt
  7748. #define FILE_VOLUME_IS_COMPRESSED 0x00008000 // winnt
  7749. #define FILE_SUPPORTS_OBJECT_IDS 0x00010000 // winnt
  7750. #define FILE_SUPPORTS_ENCRYPTION 0x00020000 // winnt
  7751. #define FILE_NAMED_STREAMS 0x00040000 // winnt
  7752. #define FILE_READ_ONLY_VOLUME 0x00080000 // winnt
  7753. //
  7754. // Define the flags for NtSet(Query)EaFile service structure entries
  7755. //
  7756. #define FILE_NEED_EA 0x00000080
  7757. //
  7758. // Define EA type values
  7759. //
  7760. #define FILE_EA_TYPE_BINARY 0xfffe
  7761. #define FILE_EA_TYPE_ASCII 0xfffd
  7762. #define FILE_EA_TYPE_BITMAP 0xfffb
  7763. #define FILE_EA_TYPE_METAFILE 0xfffa
  7764. #define FILE_EA_TYPE_ICON 0xfff9
  7765. #define FILE_EA_TYPE_EA 0xffee
  7766. #define FILE_EA_TYPE_MVMT 0xffdf
  7767. #define FILE_EA_TYPE_MVST 0xffde
  7768. #define FILE_EA_TYPE_ASN1 0xffdd
  7769. #define FILE_EA_TYPE_FAMILY_IDS 0xff01
  7770. // begin_ntddk begin_wdm begin_nthal
  7771. //
  7772. // Define the various device characteristics flags
  7773. //
  7774. #define FILE_REMOVABLE_MEDIA 0x00000001
  7775. #define FILE_READ_ONLY_DEVICE 0x00000002
  7776. #define FILE_FLOPPY_DISKETTE 0x00000004
  7777. #define FILE_WRITE_ONCE_MEDIA 0x00000008
  7778. #define FILE_REMOTE_DEVICE 0x00000010
  7779. #define FILE_DEVICE_IS_MOUNTED 0x00000020
  7780. #define FILE_VIRTUAL_VOLUME 0x00000040
  7781. #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
  7782. #define FILE_DEVICE_SECURE_OPEN 0x00000100
  7783. #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
  7784. // end_wdm
  7785. //
  7786. // The FILE_EXPECT flags will only exist for WinXP. After that they will be
  7787. // ignored and an IRP will be sent in their place.
  7788. //
  7789. #define FILE_CHARACTERISTICS_EXPECT_ORDERLY_REMOVAL 0x00000200
  7790. #define FILE_CHARACTERISTICS_EXPECT_SURPRISE_REMOVAL 0x00000300
  7791. #define FILE_CHARACTERISTICS_REMOVAL_POLICY_MASK 0x00000300
  7792. //
  7793. // flags specified here will be propagated up and down a device stack
  7794. // after FDO and all filter devices are added, but before the device
  7795. // stack is started
  7796. //
  7797. #define FILE_CHARACTERISTICS_PROPAGATED ( FILE_REMOVABLE_MEDIA | \
  7798. FILE_READ_ONLY_DEVICE | \
  7799. FILE_FLOPPY_DISKETTE | \
  7800. FILE_WRITE_ONCE_MEDIA | \
  7801. FILE_DEVICE_SECURE_OPEN )
  7802. // end_ntddk end_nthal
  7803. // begin_ntddk begin_wdm begin_nthal
  7804. //
  7805. // Define the base asynchronous I/O argument types
  7806. //
  7807. typedef struct _IO_STATUS_BLOCK {
  7808. union {
  7809. NTSTATUS Status;
  7810. PVOID Pointer;
  7811. };
  7812. ULONG_PTR Information;
  7813. } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
  7814. #if defined(_WIN64)
  7815. typedef struct _IO_STATUS_BLOCK32 {
  7816. NTSTATUS Status;
  7817. ULONG Information;
  7818. } IO_STATUS_BLOCK32, *PIO_STATUS_BLOCK32;
  7819. #endif
  7820. //
  7821. // Define an Asynchronous Procedure Call from I/O viewpoint
  7822. //
  7823. typedef
  7824. VOID
  7825. (NTAPI *PIO_APC_ROUTINE) (
  7826. IN PVOID ApcContext,
  7827. IN PIO_STATUS_BLOCK IoStatusBlock,
  7828. IN ULONG Reserved
  7829. );
  7830. #define PIO_APC_ROUTINE_DEFINED
  7831. // end_ntddk end_wdm end_nthal
  7832. // begin_winnt
  7833. //
  7834. // Define the file notification information structure
  7835. //
  7836. typedef struct _FILE_NOTIFY_INFORMATION {
  7837. ULONG NextEntryOffset;
  7838. ULONG Action;
  7839. ULONG FileNameLength;
  7840. WCHAR FileName[1];
  7841. } FILE_NOTIFY_INFORMATION, *PFILE_NOTIFY_INFORMATION;
  7842. // end_winnt
  7843. // begin_ntddk begin_wdm begin_nthal
  7844. //
  7845. // Define the file information class values
  7846. //
  7847. // WARNING: The order of the following values are assumed by the I/O system.
  7848. // Any changes made here should be reflected there as well.
  7849. //
  7850. typedef enum _FILE_INFORMATION_CLASS {
  7851. // end_wdm
  7852. FileDirectoryInformation = 1,
  7853. FileFullDirectoryInformation, // 2
  7854. FileBothDirectoryInformation, // 3
  7855. FileBasicInformation, // 4 wdm
  7856. FileStandardInformation, // 5 wdm
  7857. FileInternalInformation, // 6
  7858. FileEaInformation, // 7
  7859. FileAccessInformation, // 8
  7860. FileNameInformation, // 9
  7861. FileRenameInformation, // 10
  7862. FileLinkInformation, // 11
  7863. FileNamesInformation, // 12
  7864. FileDispositionInformation, // 13
  7865. FilePositionInformation, // 14 wdm
  7866. FileFullEaInformation, // 15
  7867. FileModeInformation, // 16
  7868. FileAlignmentInformation, // 17
  7869. FileAllInformation, // 18
  7870. FileAllocationInformation, // 19
  7871. FileEndOfFileInformation, // 20 wdm
  7872. FileAlternateNameInformation, // 21
  7873. FileStreamInformation, // 22
  7874. FilePipeInformation, // 23
  7875. FilePipeLocalInformation, // 24
  7876. FilePipeRemoteInformation, // 25
  7877. FileMailslotQueryInformation, // 26
  7878. FileMailslotSetInformation, // 27
  7879. FileCompressionInformation, // 28
  7880. FileObjectIdInformation, // 29
  7881. FileCompletionInformation, // 30
  7882. FileMoveClusterInformation, // 31
  7883. FileQuotaInformation, // 32
  7884. FileReparsePointInformation, // 33
  7885. FileNetworkOpenInformation, // 34
  7886. FileAttributeTagInformation, // 35
  7887. FileTrackingInformation, // 36
  7888. FileIdBothDirectoryInformation, // 37
  7889. FileIdFullDirectoryInformation, // 38
  7890. FileValidDataLengthInformation, // 39
  7891. FileShortNameInformation, // 40
  7892. FileMaximumInformation
  7893. // begin_wdm
  7894. } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
  7895. //
  7896. // Define the various structures which are returned on query operations
  7897. //
  7898. // end_ntddk end_wdm end_nthal
  7899. //
  7900. // NtQueryDirectoryFile return types:
  7901. //
  7902. // FILE_DIRECTORY_INFORMATION
  7903. // FILE_FULL_DIR_INFORMATION
  7904. // FILE_ID_FULL_DIR_INFORMATION
  7905. // FILE_BOTH_DIR_INFORMATION
  7906. // FILE_ID_BOTH_DIR_INFORMATION
  7907. // FILE_NAMES_INFORMATION
  7908. // FILE_OBJECTID_INFORMATION
  7909. //
  7910. typedef struct _FILE_DIRECTORY_INFORMATION {
  7911. ULONG NextEntryOffset;
  7912. ULONG FileIndex;
  7913. LARGE_INTEGER CreationTime;
  7914. LARGE_INTEGER LastAccessTime;
  7915. LARGE_INTEGER LastWriteTime;
  7916. LARGE_INTEGER ChangeTime;
  7917. LARGE_INTEGER EndOfFile;
  7918. LARGE_INTEGER AllocationSize;
  7919. ULONG FileAttributes;
  7920. ULONG FileNameLength;
  7921. WCHAR FileName[1];
  7922. } FILE_DIRECTORY_INFORMATION, *PFILE_DIRECTORY_INFORMATION;
  7923. typedef struct _FILE_FULL_DIR_INFORMATION {
  7924. ULONG NextEntryOffset;
  7925. ULONG FileIndex;
  7926. LARGE_INTEGER CreationTime;
  7927. LARGE_INTEGER LastAccessTime;
  7928. LARGE_INTEGER LastWriteTime;
  7929. LARGE_INTEGER ChangeTime;
  7930. LARGE_INTEGER EndOfFile;
  7931. LARGE_INTEGER AllocationSize;
  7932. ULONG FileAttributes;
  7933. ULONG FileNameLength;
  7934. ULONG EaSize;
  7935. WCHAR FileName[1];
  7936. } FILE_FULL_DIR_INFORMATION, *PFILE_FULL_DIR_INFORMATION;
  7937. typedef struct _FILE_ID_FULL_DIR_INFORMATION {
  7938. ULONG NextEntryOffset;
  7939. ULONG FileIndex;
  7940. LARGE_INTEGER CreationTime;
  7941. LARGE_INTEGER LastAccessTime;
  7942. LARGE_INTEGER LastWriteTime;
  7943. LARGE_INTEGER ChangeTime;
  7944. LARGE_INTEGER EndOfFile;
  7945. LARGE_INTEGER AllocationSize;
  7946. ULONG FileAttributes;
  7947. ULONG FileNameLength;
  7948. ULONG EaSize;
  7949. LARGE_INTEGER FileId;
  7950. WCHAR FileName[1];
  7951. } FILE_ID_FULL_DIR_INFORMATION, *PFILE_ID_FULL_DIR_INFORMATION;
  7952. typedef struct _FILE_BOTH_DIR_INFORMATION {
  7953. ULONG NextEntryOffset;
  7954. ULONG FileIndex;
  7955. LARGE_INTEGER CreationTime;
  7956. LARGE_INTEGER LastAccessTime;
  7957. LARGE_INTEGER LastWriteTime;
  7958. LARGE_INTEGER ChangeTime;
  7959. LARGE_INTEGER EndOfFile;
  7960. LARGE_INTEGER AllocationSize;
  7961. ULONG FileAttributes;
  7962. ULONG FileNameLength;
  7963. ULONG EaSize;
  7964. CCHAR ShortNameLength;
  7965. WCHAR ShortName[12];
  7966. WCHAR FileName[1];
  7967. } FILE_BOTH_DIR_INFORMATION, *PFILE_BOTH_DIR_INFORMATION;
  7968. typedef struct _FILE_ID_BOTH_DIR_INFORMATION {
  7969. ULONG NextEntryOffset;
  7970. ULONG FileIndex;
  7971. LARGE_INTEGER CreationTime;
  7972. LARGE_INTEGER LastAccessTime;
  7973. LARGE_INTEGER LastWriteTime;
  7974. LARGE_INTEGER ChangeTime;
  7975. LARGE_INTEGER EndOfFile;
  7976. LARGE_INTEGER AllocationSize;
  7977. ULONG FileAttributes;
  7978. ULONG FileNameLength;
  7979. ULONG EaSize;
  7980. CCHAR ShortNameLength;
  7981. WCHAR ShortName[12];
  7982. LARGE_INTEGER FileId;
  7983. WCHAR FileName[1];
  7984. } FILE_ID_BOTH_DIR_INFORMATION, *PFILE_ID_BOTH_DIR_INFORMATION;
  7985. typedef struct _FILE_NAMES_INFORMATION {
  7986. ULONG NextEntryOffset;
  7987. ULONG FileIndex;
  7988. ULONG FileNameLength;
  7989. WCHAR FileName[1];
  7990. } FILE_NAMES_INFORMATION, *PFILE_NAMES_INFORMATION;
  7991. typedef struct _FILE_OBJECTID_INFORMATION {
  7992. LONGLONG FileReference;
  7993. UCHAR ObjectId[16];
  7994. union {
  7995. struct {
  7996. UCHAR BirthVolumeId[16];
  7997. UCHAR BirthObjectId[16];
  7998. UCHAR DomainId[16];
  7999. } ;
  8000. UCHAR ExtendedInfo[48];
  8001. };
  8002. } FILE_OBJECTID_INFORMATION, *PFILE_OBJECTID_INFORMATION;
  8003. //
  8004. // The following constants provide addition meta characters to fully
  8005. // support the more obscure aspects of DOS wild card processing.
  8006. //
  8007. #define ANSI_DOS_STAR ('<')
  8008. #define ANSI_DOS_QM ('>')
  8009. #define ANSI_DOS_DOT ('"')
  8010. #define DOS_STAR (L'<')
  8011. #define DOS_QM (L'>')
  8012. #define DOS_DOT (L'"')
  8013. //
  8014. // NtQuery(Set)InformationFile return types:
  8015. //
  8016. // FILE_BASIC_INFORMATION
  8017. // FILE_STANDARD_INFORMATION
  8018. // FILE_INTERNAL_INFORMATION
  8019. // FILE_EA_INFORMATION
  8020. // FILE_ACCESS_INFORMATION
  8021. // FILE_POSITION_INFORMATION
  8022. // FILE_MODE_INFORMATION
  8023. // FILE_ALIGNMENT_INFORMATION
  8024. // FILE_NAME_INFORMATION
  8025. // FILE_ALL_INFORMATION
  8026. //
  8027. // FILE_NETWORK_OPEN_INFORMATION
  8028. //
  8029. // FILE_ALLOCATION_INFORMATION
  8030. // FILE_COMPRESSION_INFORMATION
  8031. // FILE_DISPOSITION_INFORMATION
  8032. // FILE_END_OF_FILE_INFORMATION
  8033. // FILE_LINK_INFORMATION
  8034. // FILE_MOVE_CLUSTER_INFORMATION
  8035. // FILE_RENAME_INFORMATION
  8036. // FILE_SHORT_NAME_INFORMATION
  8037. // FILE_STREAM_INFORMATION
  8038. // FILE_COMPLETION_INFORMATION
  8039. //
  8040. // FILE_PIPE_INFORMATION
  8041. // FILE_PIPE_LOCAL_INFORMATION
  8042. // FILE_PIPE_REMOTE_INFORMATION
  8043. //
  8044. // FILE_MAILSLOT_QUERY_INFORMATION
  8045. // FILE_MAILSLOT_SET_INFORMATION
  8046. // FILE_REPARSE_POINT_INFORMATION
  8047. //
  8048. typedef struct _FILE_BASIC_INFORMATION { // ntddk wdm nthal
  8049. LARGE_INTEGER CreationTime; // ntddk wdm nthal
  8050. LARGE_INTEGER LastAccessTime; // ntddk wdm nthal
  8051. LARGE_INTEGER LastWriteTime; // ntddk wdm nthal
  8052. LARGE_INTEGER ChangeTime; // ntddk wdm nthal
  8053. ULONG FileAttributes; // ntddk wdm nthal
  8054. } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION; // ntddk wdm nthal
  8055. // ntddk wdm nthal
  8056. typedef struct _FILE_STANDARD_INFORMATION { // ntddk wdm nthal
  8057. LARGE_INTEGER AllocationSize; // ntddk wdm nthal
  8058. LARGE_INTEGER EndOfFile; // ntddk wdm nthal
  8059. ULONG NumberOfLinks; // ntddk wdm nthal
  8060. BOOLEAN DeletePending; // ntddk wdm nthal
  8061. BOOLEAN Directory; // ntddk wdm nthal
  8062. } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION; // ntddk wdm nthal
  8063. // ntddk wdm nthal
  8064. typedef struct _FILE_INTERNAL_INFORMATION {
  8065. LARGE_INTEGER IndexNumber;
  8066. } FILE_INTERNAL_INFORMATION, *PFILE_INTERNAL_INFORMATION;
  8067. typedef struct _FILE_EA_INFORMATION {
  8068. ULONG EaSize;
  8069. } FILE_EA_INFORMATION, *PFILE_EA_INFORMATION;
  8070. typedef struct _FILE_ACCESS_INFORMATION {
  8071. ACCESS_MASK AccessFlags;
  8072. } FILE_ACCESS_INFORMATION, *PFILE_ACCESS_INFORMATION;
  8073. typedef struct _FILE_POSITION_INFORMATION { // ntddk wdm nthal
  8074. LARGE_INTEGER CurrentByteOffset; // ntddk wdm nthal
  8075. } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION; // ntddk wdm nthal
  8076. // ntddk wdm nthal
  8077. typedef struct _FILE_MODE_INFORMATION {
  8078. ULONG Mode;
  8079. } FILE_MODE_INFORMATION, *PFILE_MODE_INFORMATION;
  8080. typedef struct _FILE_ALIGNMENT_INFORMATION { // ntddk nthal
  8081. ULONG AlignmentRequirement; // ntddk nthal
  8082. } FILE_ALIGNMENT_INFORMATION, *PFILE_ALIGNMENT_INFORMATION; // ntddk nthal
  8083. // ntddk nthal
  8084. typedef struct _FILE_NAME_INFORMATION { // ntddk
  8085. ULONG FileNameLength; // ntddk
  8086. WCHAR FileName[1]; // ntddk
  8087. } FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION; // ntddk
  8088. // ntddk
  8089. typedef struct _FILE_ALL_INFORMATION {
  8090. FILE_BASIC_INFORMATION BasicInformation;
  8091. FILE_STANDARD_INFORMATION StandardInformation;
  8092. FILE_INTERNAL_INFORMATION InternalInformation;
  8093. FILE_EA_INFORMATION EaInformation;
  8094. FILE_ACCESS_INFORMATION AccessInformation;
  8095. FILE_POSITION_INFORMATION PositionInformation;
  8096. FILE_MODE_INFORMATION ModeInformation;
  8097. FILE_ALIGNMENT_INFORMATION AlignmentInformation;
  8098. FILE_NAME_INFORMATION NameInformation;
  8099. } FILE_ALL_INFORMATION, *PFILE_ALL_INFORMATION;
  8100. typedef struct _FILE_NETWORK_OPEN_INFORMATION { // ntddk wdm nthal
  8101. LARGE_INTEGER CreationTime; // ntddk wdm nthal
  8102. LARGE_INTEGER LastAccessTime; // ntddk wdm nthal
  8103. LARGE_INTEGER LastWriteTime; // ntddk wdm nthal
  8104. LARGE_INTEGER ChangeTime; // ntddk wdm nthal
  8105. LARGE_INTEGER AllocationSize; // ntddk wdm nthal
  8106. LARGE_INTEGER EndOfFile; // ntddk wdm nthal
  8107. ULONG FileAttributes; // ntddk wdm nthal
  8108. } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION; // ntddk wdm nthal
  8109. // ntddk wdm nthal
  8110. typedef struct _FILE_ATTRIBUTE_TAG_INFORMATION { // ntddk nthal
  8111. ULONG FileAttributes; // ntddk nthal
  8112. ULONG ReparseTag; // ntddk nthal
  8113. } FILE_ATTRIBUTE_TAG_INFORMATION, *PFILE_ATTRIBUTE_TAG_INFORMATION; // ntddk nthal
  8114. // ntddk nthal
  8115. typedef struct _FILE_ALLOCATION_INFORMATION {
  8116. LARGE_INTEGER AllocationSize;
  8117. } FILE_ALLOCATION_INFORMATION, *PFILE_ALLOCATION_INFORMATION;
  8118. typedef struct _FILE_COMPRESSION_INFORMATION {
  8119. LARGE_INTEGER CompressedFileSize;
  8120. USHORT CompressionFormat;
  8121. UCHAR CompressionUnitShift;
  8122. UCHAR ChunkShift;
  8123. UCHAR ClusterShift;
  8124. UCHAR Reserved[3];
  8125. } FILE_COMPRESSION_INFORMATION, *PFILE_COMPRESSION_INFORMATION;
  8126. typedef struct _FILE_DISPOSITION_INFORMATION { // ntddk nthal
  8127. BOOLEAN DeleteFile; // ntddk nthal
  8128. } FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION; // ntddk nthal
  8129. // ntddk nthal
  8130. typedef struct _FILE_END_OF_FILE_INFORMATION { // ntddk nthal
  8131. LARGE_INTEGER EndOfFile; // ntddk nthal
  8132. } FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION; // ntddk nthal
  8133. // ntddk nthal
  8134. typedef struct _FILE_VALID_DATA_LENGTH_INFORMATION { // ntddk nthal
  8135. LARGE_INTEGER ValidDataLength; // ntddk nthal
  8136. } FILE_VALID_DATA_LENGTH_INFORMATION, *PFILE_VALID_DATA_LENGTH_INFORMATION; // ntddk nthal
  8137. #ifdef _MAC
  8138. #pragma warning( disable : 4121)
  8139. #endif
  8140. typedef struct _FILE_LINK_INFORMATION {
  8141. BOOLEAN ReplaceIfExists;
  8142. HANDLE RootDirectory;
  8143. ULONG FileNameLength;
  8144. WCHAR FileName[1];
  8145. } FILE_LINK_INFORMATION, *PFILE_LINK_INFORMATION;
  8146. #ifdef _MAC
  8147. #pragma warning( default : 4121 )
  8148. #endif
  8149. typedef struct _FILE_MOVE_CLUSTER_INFORMATION {
  8150. ULONG ClusterCount;
  8151. HANDLE RootDirectory;
  8152. ULONG FileNameLength;
  8153. WCHAR FileName[1];
  8154. } FILE_MOVE_CLUSTER_INFORMATION, *PFILE_MOVE_CLUSTER_INFORMATION;
  8155. #ifdef _MAC
  8156. #pragma warning( disable : 4121)
  8157. #endif
  8158. typedef struct _FILE_RENAME_INFORMATION {
  8159. BOOLEAN ReplaceIfExists;
  8160. HANDLE RootDirectory;
  8161. ULONG FileNameLength;
  8162. WCHAR FileName[1];
  8163. } FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION;
  8164. #ifdef _MAC
  8165. #pragma warning( default : 4121 )
  8166. #endif
  8167. typedef struct _FILE_STREAM_INFORMATION {
  8168. ULONG NextEntryOffset;
  8169. ULONG StreamNameLength;
  8170. LARGE_INTEGER StreamSize;
  8171. LARGE_INTEGER StreamAllocationSize;
  8172. WCHAR StreamName[1];
  8173. } FILE_STREAM_INFORMATION, *PFILE_STREAM_INFORMATION;
  8174. typedef struct _FILE_TRACKING_INFORMATION {
  8175. HANDLE DestinationFile;
  8176. ULONG ObjectInformationLength;
  8177. CHAR ObjectInformation[1];
  8178. } FILE_TRACKING_INFORMATION, *PFILE_TRACKING_INFORMATION;
  8179. typedef struct _FILE_COMPLETION_INFORMATION {
  8180. HANDLE Port;
  8181. PVOID Key;
  8182. } FILE_COMPLETION_INFORMATION, *PFILE_COMPLETION_INFORMATION;
  8183. typedef struct _FILE_PIPE_INFORMATION {
  8184. ULONG ReadMode;
  8185. ULONG CompletionMode;
  8186. } FILE_PIPE_INFORMATION, *PFILE_PIPE_INFORMATION;
  8187. typedef struct _FILE_PIPE_LOCAL_INFORMATION {
  8188. ULONG NamedPipeType;
  8189. ULONG NamedPipeConfiguration;
  8190. ULONG MaximumInstances;
  8191. ULONG CurrentInstances;
  8192. ULONG InboundQuota;
  8193. ULONG ReadDataAvailable;
  8194. ULONG OutboundQuota;
  8195. ULONG WriteQuotaAvailable;
  8196. ULONG NamedPipeState;
  8197. ULONG NamedPipeEnd;
  8198. } FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION;
  8199. typedef struct _FILE_PIPE_REMOTE_INFORMATION {
  8200. LARGE_INTEGER CollectDataTime;
  8201. ULONG MaximumCollectionCount;
  8202. } FILE_PIPE_REMOTE_INFORMATION, *PFILE_PIPE_REMOTE_INFORMATION;
  8203. typedef struct _FILE_MAILSLOT_QUERY_INFORMATION {
  8204. ULONG MaximumMessageSize;
  8205. ULONG MailslotQuota;
  8206. ULONG NextMessageSize;
  8207. ULONG MessagesAvailable;
  8208. LARGE_INTEGER ReadTimeout;
  8209. } FILE_MAILSLOT_QUERY_INFORMATION, *PFILE_MAILSLOT_QUERY_INFORMATION;
  8210. typedef struct _FILE_MAILSLOT_SET_INFORMATION {
  8211. PLARGE_INTEGER ReadTimeout;
  8212. } FILE_MAILSLOT_SET_INFORMATION, *PFILE_MAILSLOT_SET_INFORMATION;
  8213. typedef struct _FILE_REPARSE_POINT_INFORMATION {
  8214. LONGLONG FileReference;
  8215. ULONG Tag;
  8216. } FILE_REPARSE_POINT_INFORMATION, *PFILE_REPARSE_POINT_INFORMATION;
  8217. //
  8218. // NtQuery(Set)EaFile
  8219. //
  8220. // The offset for the start of EaValue is EaName[EaNameLength + 1]
  8221. //
  8222. // begin_ntddk begin_wdm
  8223. typedef struct _FILE_FULL_EA_INFORMATION {
  8224. ULONG NextEntryOffset;
  8225. UCHAR Flags;
  8226. UCHAR EaNameLength;
  8227. USHORT EaValueLength;
  8228. CHAR EaName[1];
  8229. } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
  8230. // end_ntddk end_wdm
  8231. typedef struct _FILE_GET_EA_INFORMATION {
  8232. ULONG NextEntryOffset;
  8233. UCHAR EaNameLength;
  8234. CHAR EaName[1];
  8235. } FILE_GET_EA_INFORMATION, *PFILE_GET_EA_INFORMATION;
  8236. //
  8237. // NtQuery(Set)QuotaInformationFile
  8238. //
  8239. typedef struct _FILE_GET_QUOTA_INFORMATION {
  8240. ULONG NextEntryOffset;
  8241. ULONG SidLength;
  8242. SID Sid;
  8243. } FILE_GET_QUOTA_INFORMATION, *PFILE_GET_QUOTA_INFORMATION;
  8244. typedef struct _FILE_QUOTA_INFORMATION {
  8245. ULONG NextEntryOffset;
  8246. ULONG SidLength;
  8247. LARGE_INTEGER ChangeTime;
  8248. LARGE_INTEGER QuotaUsed;
  8249. LARGE_INTEGER QuotaThreshold;
  8250. LARGE_INTEGER QuotaLimit;
  8251. SID Sid;
  8252. } FILE_QUOTA_INFORMATION, *PFILE_QUOTA_INFORMATION;
  8253. // begin_ntddk begin_wdm begin_nthal
  8254. //
  8255. // Define the file system information class values
  8256. //
  8257. // WARNING: The order of the following values are assumed by the I/O system.
  8258. // Any changes made here should be reflected there as well.
  8259. typedef enum _FSINFOCLASS {
  8260. FileFsVolumeInformation = 1,
  8261. FileFsLabelInformation, // 2
  8262. FileFsSizeInformation, // 3
  8263. FileFsDeviceInformation, // 4
  8264. FileFsAttributeInformation, // 5
  8265. FileFsControlInformation, // 6
  8266. FileFsFullSizeInformation, // 7
  8267. FileFsObjectIdInformation, // 8
  8268. FileFsDriverPathInformation, // 9
  8269. FileFsMaximumInformation
  8270. } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
  8271. // end_ntddk end_wdm end_nthal
  8272. //
  8273. // NtQuery[Set]VolumeInformationFile types:
  8274. //
  8275. // FILE_FS_LABEL_INFORMATION
  8276. // FILE_FS_VOLUME_INFORMATION
  8277. // FILE_FS_SIZE_INFORMATION
  8278. // FILE_FS_DEVICE_INFORMATION
  8279. // FILE_FS_ATTRIBUTE_INFORMATION
  8280. // FILE_FS_CONTROL_INFORMATION
  8281. // FILE_FS_OBJECTID_INFORMATION
  8282. //
  8283. typedef struct _FILE_FS_LABEL_INFORMATION {
  8284. ULONG VolumeLabelLength;
  8285. WCHAR VolumeLabel[1];
  8286. } FILE_FS_LABEL_INFORMATION, *PFILE_FS_LABEL_INFORMATION;
  8287. typedef struct _FILE_FS_VOLUME_INFORMATION {
  8288. LARGE_INTEGER VolumeCreationTime;
  8289. ULONG VolumeSerialNumber;
  8290. ULONG VolumeLabelLength;
  8291. BOOLEAN SupportsObjects;
  8292. WCHAR VolumeLabel[1];
  8293. } FILE_FS_VOLUME_INFORMATION, *PFILE_FS_VOLUME_INFORMATION;
  8294. typedef struct _FILE_FS_SIZE_INFORMATION {
  8295. LARGE_INTEGER TotalAllocationUnits;
  8296. LARGE_INTEGER AvailableAllocationUnits;
  8297. ULONG SectorsPerAllocationUnit;
  8298. ULONG BytesPerSector;
  8299. } FILE_FS_SIZE_INFORMATION, *PFILE_FS_SIZE_INFORMATION;
  8300. typedef struct _FILE_FS_FULL_SIZE_INFORMATION {
  8301. LARGE_INTEGER TotalAllocationUnits;
  8302. LARGE_INTEGER CallerAvailableAllocationUnits;
  8303. LARGE_INTEGER ActualAvailableAllocationUnits;
  8304. ULONG SectorsPerAllocationUnit;
  8305. ULONG BytesPerSector;
  8306. } FILE_FS_FULL_SIZE_INFORMATION, *PFILE_FS_FULL_SIZE_INFORMATION;
  8307. typedef struct _FILE_FS_OBJECTID_INFORMATION {
  8308. UCHAR ObjectId[16];
  8309. UCHAR ExtendedInfo[48];
  8310. } FILE_FS_OBJECTID_INFORMATION, *PFILE_FS_OBJECTID_INFORMATION;
  8311. typedef struct _FILE_FS_DEVICE_INFORMATION { // ntddk wdm nthal
  8312. DEVICE_TYPE DeviceType; // ntddk wdm nthal
  8313. ULONG Characteristics; // ntddk wdm nthal
  8314. } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION; // ntddk wdm nthal
  8315. // ntddk wdm nthal
  8316. typedef struct _FILE_FS_ATTRIBUTE_INFORMATION {
  8317. ULONG FileSystemAttributes;
  8318. LONG MaximumComponentNameLength;
  8319. ULONG FileSystemNameLength;
  8320. WCHAR FileSystemName[1];
  8321. } FILE_FS_ATTRIBUTE_INFORMATION, *PFILE_FS_ATTRIBUTE_INFORMATION;
  8322. typedef struct _FILE_FS_DRIVER_PATH_INFORMATION {
  8323. BOOLEAN DriverInPath;
  8324. ULONG DriverNameLength;
  8325. WCHAR DriverName[1];
  8326. } FILE_FS_DRIVER_PATH_INFORMATION, *PFILE_FS_DRIVER_PATH_INFORMATION;
  8327. //
  8328. // File system control flags
  8329. //
  8330. #define FILE_VC_QUOTA_NONE 0x00000000
  8331. #define FILE_VC_QUOTA_TRACK 0x00000001
  8332. #define FILE_VC_QUOTA_ENFORCE 0x00000002
  8333. #define FILE_VC_QUOTA_MASK 0x00000003
  8334. #define FILE_VC_CONTENT_INDEX_DISABLED 0x00000008
  8335. #define FILE_VC_LOG_QUOTA_THRESHOLD 0x00000010
  8336. #define FILE_VC_LOG_QUOTA_LIMIT 0x00000020
  8337. #define FILE_VC_LOG_VOLUME_THRESHOLD 0x00000040
  8338. #define FILE_VC_LOG_VOLUME_LIMIT 0x00000080
  8339. #define FILE_VC_QUOTAS_INCOMPLETE 0x00000100
  8340. #define FILE_VC_QUOTAS_REBUILDING 0x00000200
  8341. #define FILE_VC_VALID_MASK 0x000003ff
  8342. typedef struct _FILE_FS_CONTROL_INFORMATION {
  8343. LARGE_INTEGER FreeSpaceStartFiltering;
  8344. LARGE_INTEGER FreeSpaceThreshold;
  8345. LARGE_INTEGER FreeSpaceStopFiltering;
  8346. LARGE_INTEGER DefaultQuotaThreshold;
  8347. LARGE_INTEGER DefaultQuotaLimit;
  8348. ULONG FileSystemControlFlags;
  8349. } FILE_FS_CONTROL_INFORMATION, *PFILE_FS_CONTROL_INFORMATION;
  8350. // begin_winnt begin_ntddk begin_nthal
  8351. //
  8352. // Define segement buffer structure for scatter/gather read/write.
  8353. //
  8354. typedef union _FILE_SEGMENT_ELEMENT {
  8355. PVOID64 Buffer;
  8356. ULONGLONG Alignment;
  8357. }FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
  8358. NTSYSCALLAPI
  8359. NTSTATUS
  8360. NTAPI
  8361. NtCreateFile(
  8362. OUT PHANDLE FileHandle,
  8363. IN ACCESS_MASK DesiredAccess,
  8364. IN POBJECT_ATTRIBUTES ObjectAttributes,
  8365. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8366. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  8367. IN ULONG FileAttributes,
  8368. IN ULONG ShareAccess,
  8369. IN ULONG CreateDisposition,
  8370. IN ULONG CreateOptions,
  8371. IN PVOID EaBuffer OPTIONAL,
  8372. IN ULONG EaLength
  8373. );
  8374. NTSYSCALLAPI
  8375. NTSTATUS
  8376. NTAPI
  8377. NtDeviceIoControlFile(
  8378. IN HANDLE FileHandle,
  8379. IN HANDLE Event OPTIONAL,
  8380. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8381. IN PVOID ApcContext OPTIONAL,
  8382. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8383. IN ULONG IoControlCode,
  8384. IN PVOID InputBuffer OPTIONAL,
  8385. IN ULONG InputBufferLength,
  8386. OUT PVOID OutputBuffer OPTIONAL,
  8387. IN ULONG OutputBufferLength
  8388. );
  8389. NTSYSCALLAPI
  8390. NTSTATUS
  8391. NTAPI
  8392. NtFsControlFile(
  8393. IN HANDLE FileHandle,
  8394. IN HANDLE Event OPTIONAL,
  8395. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8396. IN PVOID ApcContext OPTIONAL,
  8397. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8398. IN ULONG FsControlCode,
  8399. IN PVOID InputBuffer OPTIONAL,
  8400. IN ULONG InputBufferLength,
  8401. OUT PVOID OutputBuffer OPTIONAL,
  8402. IN ULONG OutputBufferLength
  8403. );
  8404. NTSYSCALLAPI
  8405. NTSTATUS
  8406. NTAPI
  8407. NtLockFile(
  8408. IN HANDLE FileHandle,
  8409. IN HANDLE Event OPTIONAL,
  8410. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8411. IN PVOID ApcContext OPTIONAL,
  8412. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8413. IN PLARGE_INTEGER ByteOffset,
  8414. IN PLARGE_INTEGER Length,
  8415. IN ULONG Key,
  8416. IN BOOLEAN FailImmediately,
  8417. IN BOOLEAN ExclusiveLock
  8418. );
  8419. NTSYSCALLAPI
  8420. NTSTATUS
  8421. NTAPI
  8422. NtOpenFile(
  8423. OUT PHANDLE FileHandle,
  8424. IN ACCESS_MASK DesiredAccess,
  8425. IN POBJECT_ATTRIBUTES ObjectAttributes,
  8426. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8427. IN ULONG ShareAccess,
  8428. IN ULONG OpenOptions
  8429. );
  8430. NTSYSCALLAPI
  8431. NTSTATUS
  8432. NTAPI
  8433. NtQueryDirectoryFile(
  8434. IN HANDLE FileHandle,
  8435. IN HANDLE Event OPTIONAL,
  8436. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8437. IN PVOID ApcContext OPTIONAL,
  8438. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8439. OUT PVOID FileInformation,
  8440. IN ULONG Length,
  8441. IN FILE_INFORMATION_CLASS FileInformationClass,
  8442. IN BOOLEAN ReturnSingleEntry,
  8443. IN PUNICODE_STRING FileName OPTIONAL,
  8444. IN BOOLEAN RestartScan
  8445. );
  8446. NTSYSCALLAPI
  8447. NTSTATUS
  8448. NTAPI
  8449. NtQueryInformationFile(
  8450. IN HANDLE FileHandle,
  8451. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8452. OUT PVOID FileInformation,
  8453. IN ULONG Length,
  8454. IN FILE_INFORMATION_CLASS FileInformationClass
  8455. );
  8456. NTSYSCALLAPI
  8457. NTSTATUS
  8458. NTAPI
  8459. NtQueryQuotaInformationFile(
  8460. IN HANDLE FileHandle,
  8461. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8462. OUT PVOID Buffer,
  8463. IN ULONG Length,
  8464. IN BOOLEAN ReturnSingleEntry,
  8465. IN PVOID SidList OPTIONAL,
  8466. IN ULONG SidListLength,
  8467. IN PSID StartSid OPTIONAL,
  8468. IN BOOLEAN RestartScan
  8469. );
  8470. NTSYSCALLAPI
  8471. NTSTATUS
  8472. NTAPI
  8473. NtQueryVolumeInformationFile(
  8474. IN HANDLE FileHandle,
  8475. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8476. OUT PVOID FsInformation,
  8477. IN ULONG Length,
  8478. IN FS_INFORMATION_CLASS FsInformationClass
  8479. );
  8480. NTSYSCALLAPI
  8481. NTSTATUS
  8482. NTAPI
  8483. NtReadFile(
  8484. IN HANDLE FileHandle,
  8485. IN HANDLE Event OPTIONAL,
  8486. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8487. IN PVOID ApcContext OPTIONAL,
  8488. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8489. OUT PVOID Buffer,
  8490. IN ULONG Length,
  8491. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  8492. IN PULONG Key OPTIONAL
  8493. );
  8494. NTSYSCALLAPI
  8495. NTSTATUS
  8496. NTAPI
  8497. NtSetInformationFile(
  8498. IN HANDLE FileHandle,
  8499. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8500. IN PVOID FileInformation,
  8501. IN ULONG Length,
  8502. IN FILE_INFORMATION_CLASS FileInformationClass
  8503. );
  8504. NTSYSCALLAPI
  8505. NTSTATUS
  8506. NTAPI
  8507. NtSetQuotaInformationFile(
  8508. IN HANDLE FileHandle,
  8509. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8510. IN PVOID Buffer,
  8511. IN ULONG Length
  8512. );
  8513. NTSYSCALLAPI
  8514. NTSTATUS
  8515. NTAPI
  8516. NtSetVolumeInformationFile(
  8517. IN HANDLE FileHandle,
  8518. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8519. IN PVOID FsInformation,
  8520. IN ULONG Length,
  8521. IN FS_INFORMATION_CLASS FsInformationClass
  8522. );
  8523. NTSYSCALLAPI
  8524. NTSTATUS
  8525. NTAPI
  8526. NtWriteFile(
  8527. IN HANDLE FileHandle,
  8528. IN HANDLE Event OPTIONAL,
  8529. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8530. IN PVOID ApcContext OPTIONAL,
  8531. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8532. IN PVOID Buffer,
  8533. IN ULONG Length,
  8534. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  8535. IN PULONG Key OPTIONAL
  8536. );
  8537. //
  8538. // Macro definition for defining IOCTL and FSCTL function control codes. Note
  8539. // that function codes 0-2047 are reserved for Microsoft Corporation, and
  8540. // 2048-4095 are reserved for customers.
  8541. //
  8542. // These macros are defined in devioctl.h which contains the portable IO
  8543. // definitions (for use by both DOS and NT)
  8544. //
  8545. //
  8546. // The IoGetFunctionCodeFromCtlCode( ControlCode ) Macro is defined in io.h
  8547. // This macro is used to extract the function code from an IOCTL (or FSCTL).
  8548. // The macro can only be used in kernel mode code.
  8549. //
  8550. //
  8551. // General File System control codes - Note that these values are valid
  8552. // regardless of the actual file system type
  8553. //
  8554. //
  8555. // IMPORTANT: These values have been arranged in order of increasing
  8556. // control codes. Do NOT breaks this!! Add all new codes
  8557. // at end of list regardless of functionality type.
  8558. //
  8559. // Note: FSCTL_QUERY_RETRIEVAL_POINTER and FSCTL_MARK_AS_SYSTEM_HIVE only
  8560. // work from Kernel mode on local paging files or the system hives.
  8561. //
  8562. // begin_winioctl
  8563. #ifndef _FILESYSTEMFSCTL_
  8564. #define _FILESYSTEMFSCTL_
  8565. //
  8566. // The following is a list of the native file system fsctls followed by
  8567. // additional network file system fsctls. Some values have been
  8568. // decommissioned.
  8569. //
  8570. #define FSCTL_REQUEST_OPLOCK_LEVEL_1 CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 0, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8571. #define FSCTL_REQUEST_OPLOCK_LEVEL_2 CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 1, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8572. #define FSCTL_REQUEST_BATCH_OPLOCK CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8573. #define FSCTL_OPLOCK_BREAK_ACKNOWLEDGE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 3, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8574. #define FSCTL_OPBATCH_ACK_CLOSE_PENDING CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 4, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8575. #define FSCTL_OPLOCK_BREAK_NOTIFY CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 5, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8576. #define FSCTL_LOCK_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 6, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8577. #define FSCTL_UNLOCK_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 7, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8578. #define FSCTL_DISMOUNT_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 8, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8579. // decommissioned fsctl value 9
  8580. #define FSCTL_IS_VOLUME_MOUNTED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 10, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8581. #define FSCTL_IS_PATHNAME_VALID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 11, METHOD_BUFFERED, FILE_ANY_ACCESS) // PATHNAME_BUFFER,
  8582. #define FSCTL_MARK_VOLUME_DIRTY CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 12, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8583. // decommissioned fsctl value 13
  8584. #define FSCTL_QUERY_RETRIEVAL_POINTERS CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 14, METHOD_NEITHER, FILE_ANY_ACCESS)
  8585. #define FSCTL_GET_COMPRESSION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8586. #define FSCTL_SET_COMPRESSION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 16, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
  8587. // decommissioned fsctl value 17
  8588. // decommissioned fsctl value 18
  8589. #define FSCTL_MARK_AS_SYSTEM_HIVE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 19, METHOD_NEITHER, FILE_ANY_ACCESS)
  8590. #define FSCTL_OPLOCK_BREAK_ACK_NO_2 CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 20, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8591. #define FSCTL_INVALIDATE_VOLUMES CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 21, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8592. #define FSCTL_QUERY_FAT_BPB CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 22, METHOD_BUFFERED, FILE_ANY_ACCESS) // FSCTL_QUERY_FAT_BPB_BUFFER
  8593. #define FSCTL_REQUEST_FILTER_OPLOCK CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 23, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8594. #define FSCTL_FILESYSTEM_GET_STATISTICS CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 24, METHOD_BUFFERED, FILE_ANY_ACCESS) // FILESYSTEM_STATISTICS
  8595. #if(_WIN32_WINNT >= 0x0400)
  8596. #define FSCTL_GET_NTFS_VOLUME_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 25, METHOD_BUFFERED, FILE_ANY_ACCESS) // NTFS_VOLUME_DATA_BUFFER
  8597. #define FSCTL_GET_NTFS_FILE_RECORD CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 26, METHOD_BUFFERED, FILE_ANY_ACCESS) // NTFS_FILE_RECORD_INPUT_BUFFER, NTFS_FILE_RECORD_OUTPUT_BUFFER
  8598. #define FSCTL_GET_VOLUME_BITMAP CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 27, METHOD_NEITHER, FILE_ANY_ACCESS) // STARTING_LCN_INPUT_BUFFER, VOLUME_BITMAP_BUFFER
  8599. #define FSCTL_GET_RETRIEVAL_POINTERS CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 28, METHOD_NEITHER, FILE_ANY_ACCESS) // STARTING_VCN_INPUT_BUFFER, RETRIEVAL_POINTERS_BUFFER
  8600. #define FSCTL_MOVE_FILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 29, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // MOVE_FILE_DATA,
  8601. #define FSCTL_IS_VOLUME_DIRTY CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 30, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8602. // decomissioned fsctl value 31
  8603. #define FSCTL_ALLOW_EXTENDED_DASD_IO CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 32, METHOD_NEITHER, FILE_ANY_ACCESS)
  8604. #endif /* _WIN32_WINNT >= 0x0400 */
  8605. #if(_WIN32_WINNT >= 0x0500)
  8606. // decommissioned fsctl value 33
  8607. // decommissioned fsctl value 34
  8608. #define FSCTL_FIND_FILES_BY_SID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 35, METHOD_NEITHER, FILE_ANY_ACCESS)
  8609. // decommissioned fsctl value 36
  8610. // decommissioned fsctl value 37
  8611. #define FSCTL_SET_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 38, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // FILE_OBJECTID_BUFFER
  8612. #define FSCTL_GET_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 39, METHOD_BUFFERED, FILE_ANY_ACCESS) // FILE_OBJECTID_BUFFER
  8613. #define FSCTL_DELETE_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 40, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
  8614. #define FSCTL_SET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // REPARSE_DATA_BUFFER,
  8615. #define FSCTL_GET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_ANY_ACCESS) // REPARSE_DATA_BUFFER
  8616. #define FSCTL_DELETE_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 43, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // REPARSE_DATA_BUFFER,
  8617. #define FSCTL_ENUM_USN_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 44, METHOD_NEITHER, FILE_ANY_ACCESS) // MFT_ENUM_DATA,
  8618. #define FSCTL_SECURITY_ID_CHECK CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 45, METHOD_NEITHER, FILE_READ_DATA) // BULK_SECURITY_TEST_DATA,
  8619. #define FSCTL_READ_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 46, METHOD_NEITHER, FILE_ANY_ACCESS) // READ_USN_JOURNAL_DATA, USN
  8620. #define FSCTL_SET_OBJECT_ID_EXTENDED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 47, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
  8621. #define FSCTL_CREATE_OR_GET_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 48, METHOD_BUFFERED, FILE_ANY_ACCESS) // FILE_OBJECTID_BUFFER
  8622. #define FSCTL_SET_SPARSE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
  8623. #define FSCTL_SET_ZERO_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 50, METHOD_BUFFERED, FILE_WRITE_DATA) // FILE_ZERO_DATA_INFORMATION,
  8624. #define FSCTL_QUERY_ALLOCATED_RANGES CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 51, METHOD_NEITHER, FILE_READ_DATA) // FILE_ALLOCATED_RANGE_BUFFER, FILE_ALLOCATED_RANGE_BUFFER
  8625. // decommissioned fsctl value 52
  8626. #define FSCTL_SET_ENCRYPTION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 53, METHOD_NEITHER, FILE_ANY_ACCESS) // ENCRYPTION_BUFFER, DECRYPTION_STATUS_BUFFER
  8627. #define FSCTL_ENCRYPTION_FSCTL_IO CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 54, METHOD_NEITHER, FILE_ANY_ACCESS)
  8628. #define FSCTL_WRITE_RAW_ENCRYPTED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 55, METHOD_NEITHER, FILE_SPECIAL_ACCESS) // ENCRYPTED_DATA_INFO,
  8629. #define FSCTL_READ_RAW_ENCRYPTED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 56, METHOD_NEITHER, FILE_SPECIAL_ACCESS) // REQUEST_RAW_ENCRYPTED_DATA, ENCRYPTED_DATA_INFO
  8630. #define FSCTL_CREATE_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 57, METHOD_NEITHER, FILE_ANY_ACCESS) // CREATE_USN_JOURNAL_DATA,
  8631. #define FSCTL_READ_FILE_USN_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 58, METHOD_NEITHER, FILE_ANY_ACCESS) // Read the Usn Record for a file
  8632. #define FSCTL_WRITE_USN_CLOSE_RECORD CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 59, METHOD_NEITHER, FILE_ANY_ACCESS) // Generate Close Usn Record
  8633. #define FSCTL_EXTEND_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 60, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8634. #define FSCTL_QUERY_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 61, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8635. #define FSCTL_DELETE_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 62, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8636. #define FSCTL_MARK_HANDLE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 63, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8637. #define FSCTL_SIS_COPYFILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 64, METHOD_BUFFERED, FILE_ANY_ACCESS)
  8638. #define FSCTL_SIS_LINK_FILES CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 65, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
  8639. #define FSCTL_HSM_MSG CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 66, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
  8640. // decommissioned fsctl value 67
  8641. #define FSCTL_HSM_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 68, METHOD_NEITHER, FILE_READ_DATA | FILE_WRITE_DATA)
  8642. #define FSCTL_RECALL_FILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 69, METHOD_NEITHER, FILE_ANY_ACCESS)
  8643. // decommissioned fsctl value 70
  8644. #define FSCTL_READ_FROM_PLEX CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 71, METHOD_OUT_DIRECT, FILE_READ_DATA)
  8645. #define FSCTL_FILE_PREFETCH CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 72, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // FILE_PREFETCH
  8646. #endif /* _WIN32_WINNT >= 0x0500 */
  8647. //
  8648. // The following long list of structs are associated with the preceeding
  8649. // file system fsctls.
  8650. //
  8651. //
  8652. // Structure for FSCTL_IS_PATHNAME_VALID
  8653. //
  8654. typedef struct _PATHNAME_BUFFER {
  8655. ULONG PathNameLength;
  8656. WCHAR Name[1];
  8657. } PATHNAME_BUFFER, *PPATHNAME_BUFFER;
  8658. //
  8659. // Structure for FSCTL_QUERY_BPB_INFO
  8660. //
  8661. typedef struct _FSCTL_QUERY_FAT_BPB_BUFFER {
  8662. UCHAR First0x24BytesOfBootSector[0x24];
  8663. } FSCTL_QUERY_FAT_BPB_BUFFER, *PFSCTL_QUERY_FAT_BPB_BUFFER;
  8664. #if(_WIN32_WINNT >= 0x0400)
  8665. //
  8666. // Structures for FSCTL_GET_NTFS_VOLUME_DATA.
  8667. // The user must pass the basic buffer below. Ntfs
  8668. // will return as many fields as available in the extended
  8669. // buffer which follows immediately after the VOLUME_DATA_BUFFER.
  8670. //
  8671. typedef struct {
  8672. LARGE_INTEGER VolumeSerialNumber;
  8673. LARGE_INTEGER NumberSectors;
  8674. LARGE_INTEGER TotalClusters;
  8675. LARGE_INTEGER FreeClusters;
  8676. LARGE_INTEGER TotalReserved;
  8677. ULONG BytesPerSector;
  8678. ULONG BytesPerCluster;
  8679. ULONG BytesPerFileRecordSegment;
  8680. ULONG ClustersPerFileRecordSegment;
  8681. LARGE_INTEGER MftValidDataLength;
  8682. LARGE_INTEGER MftStartLcn;
  8683. LARGE_INTEGER Mft2StartLcn;
  8684. LARGE_INTEGER MftZoneStart;
  8685. LARGE_INTEGER MftZoneEnd;
  8686. } NTFS_VOLUME_DATA_BUFFER, *PNTFS_VOLUME_DATA_BUFFER;
  8687. typedef struct {
  8688. ULONG ByteCount;
  8689. USHORT MajorVersion;
  8690. USHORT MinorVersion;
  8691. } NTFS_EXTENDED_VOLUME_DATA, *PNTFS_EXTENDED_VOLUME_DATA;
  8692. #endif /* _WIN32_WINNT >= 0x0400 */
  8693. #if(_WIN32_WINNT >= 0x0400)
  8694. //
  8695. // Structure for FSCTL_GET_VOLUME_BITMAP
  8696. //
  8697. typedef struct {
  8698. LARGE_INTEGER StartingLcn;
  8699. } STARTING_LCN_INPUT_BUFFER, *PSTARTING_LCN_INPUT_BUFFER;
  8700. typedef struct {
  8701. LARGE_INTEGER StartingLcn;
  8702. LARGE_INTEGER BitmapSize;
  8703. UCHAR Buffer[1];
  8704. } VOLUME_BITMAP_BUFFER, *PVOLUME_BITMAP_BUFFER;
  8705. #endif /* _WIN32_WINNT >= 0x0400 */
  8706. #if(_WIN32_WINNT >= 0x0400)
  8707. //
  8708. // Structure for FSCTL_GET_RETRIEVAL_POINTERS
  8709. //
  8710. typedef struct {
  8711. LARGE_INTEGER StartingVcn;
  8712. } STARTING_VCN_INPUT_BUFFER, *PSTARTING_VCN_INPUT_BUFFER;
  8713. typedef struct RETRIEVAL_POINTERS_BUFFER {
  8714. ULONG ExtentCount;
  8715. LARGE_INTEGER StartingVcn;
  8716. struct {
  8717. LARGE_INTEGER NextVcn;
  8718. LARGE_INTEGER Lcn;
  8719. } Extents[1];
  8720. } RETRIEVAL_POINTERS_BUFFER, *PRETRIEVAL_POINTERS_BUFFER;
  8721. #endif /* _WIN32_WINNT >= 0x0400 */
  8722. #if(_WIN32_WINNT >= 0x0400)
  8723. //
  8724. // Structures for FSCTL_GET_NTFS_FILE_RECORD
  8725. //
  8726. typedef struct {
  8727. LARGE_INTEGER FileReferenceNumber;
  8728. } NTFS_FILE_RECORD_INPUT_BUFFER, *PNTFS_FILE_RECORD_INPUT_BUFFER;
  8729. typedef struct {
  8730. LARGE_INTEGER FileReferenceNumber;
  8731. ULONG FileRecordLength;
  8732. UCHAR FileRecordBuffer[1];
  8733. } NTFS_FILE_RECORD_OUTPUT_BUFFER, *PNTFS_FILE_RECORD_OUTPUT_BUFFER;
  8734. #endif /* _WIN32_WINNT >= 0x0400 */
  8735. #if(_WIN32_WINNT >= 0x0400)
  8736. //
  8737. // Structure for FSCTL_MOVE_FILE
  8738. //
  8739. typedef struct {
  8740. HANDLE FileHandle;
  8741. LARGE_INTEGER StartingVcn;
  8742. LARGE_INTEGER StartingLcn;
  8743. ULONG ClusterCount;
  8744. } MOVE_FILE_DATA, *PMOVE_FILE_DATA;
  8745. #if defined(_WIN64)
  8746. //
  8747. // 32/64 Bit thunking support structure
  8748. //
  8749. typedef struct _MOVE_FILE_DATA32 {
  8750. UINT32 FileHandle;
  8751. LARGE_INTEGER StartingVcn;
  8752. LARGE_INTEGER StartingLcn;
  8753. ULONG ClusterCount;
  8754. } MOVE_FILE_DATA32, *PMOVE_FILE_DATA32;
  8755. #endif
  8756. #endif /* _WIN32_WINNT >= 0x0400 */
  8757. #if(_WIN32_WINNT >= 0x0500)
  8758. //
  8759. // Structure for FSCTL_FIND_FILES_BY_SID
  8760. //
  8761. typedef struct {
  8762. ULONG Restart;
  8763. SID Sid;
  8764. } FIND_BY_SID_DATA, *PFIND_BY_SID_DATA;
  8765. #endif /* _WIN32_WINNT >= 0x0500 */
  8766. #if(_WIN32_WINNT >= 0x0500)
  8767. //
  8768. // The following structures apply to Usn operations.
  8769. //
  8770. //
  8771. // Structure for FSCTL_ENUM_USN_DATA
  8772. //
  8773. typedef struct {
  8774. ULONGLONG StartFileReferenceNumber;
  8775. USN LowUsn;
  8776. USN HighUsn;
  8777. } MFT_ENUM_DATA, *PMFT_ENUM_DATA;
  8778. //
  8779. // Structure for FSCTL_CREATE_USN_JOURNAL
  8780. //
  8781. typedef struct {
  8782. ULONGLONG MaximumSize;
  8783. ULONGLONG AllocationDelta;
  8784. } CREATE_USN_JOURNAL_DATA, *PCREATE_USN_JOURNAL_DATA;
  8785. //
  8786. // Structure for FSCTL_READ_USN_JOURNAL
  8787. //
  8788. typedef struct {
  8789. USN StartUsn;
  8790. ULONG ReasonMask;
  8791. ULONG ReturnOnlyOnClose;
  8792. ULONGLONG Timeout;
  8793. ULONGLONG BytesToWaitFor;
  8794. ULONGLONG UsnJournalID;
  8795. } READ_USN_JOURNAL_DATA, *PREAD_USN_JOURNAL_DATA;
  8796. //
  8797. // The initial Major.Minor version of the Usn record will be 2.0.
  8798. // In general, the MinorVersion may be changed if fields are added
  8799. // to this structure in such a way that the previous version of the
  8800. // software can still correctly the fields it knows about. The
  8801. // MajorVersion should only be changed if the previous version of
  8802. // any software using this structure would incorrectly handle new
  8803. // records due to structure changes.
  8804. //
  8805. // The first update to this will force the structure to version 2.0.
  8806. // This will add the extended information about the source as
  8807. // well as indicate the file name offset within the structure.
  8808. //
  8809. // The following structure is returned with these fsctls.
  8810. //
  8811. // FSCTL_READ_USN_JOURNAL
  8812. // FSCTL_READ_FILE_USN_DATA
  8813. // FSCTL_ENUM_USN_DATA
  8814. //
  8815. typedef struct {
  8816. ULONG RecordLength;
  8817. USHORT MajorVersion;
  8818. USHORT MinorVersion;
  8819. ULONGLONG FileReferenceNumber;
  8820. ULONGLONG ParentFileReferenceNumber;
  8821. USN Usn;
  8822. LARGE_INTEGER TimeStamp;
  8823. ULONG Reason;
  8824. ULONG SourceInfo;
  8825. ULONG SecurityId;
  8826. ULONG FileAttributes;
  8827. USHORT FileNameLength;
  8828. USHORT FileNameOffset;
  8829. WCHAR FileName[1];
  8830. } USN_RECORD, *PUSN_RECORD;
  8831. #define USN_PAGE_SIZE (0x1000)
  8832. #define USN_REASON_DATA_OVERWRITE (0x00000001)
  8833. #define USN_REASON_DATA_EXTEND (0x00000002)
  8834. #define USN_REASON_DATA_TRUNCATION (0x00000004)
  8835. #define USN_REASON_NAMED_DATA_OVERWRITE (0x00000010)
  8836. #define USN_REASON_NAMED_DATA_EXTEND (0x00000020)
  8837. #define USN_REASON_NAMED_DATA_TRUNCATION (0x00000040)
  8838. #define USN_REASON_FILE_CREATE (0x00000100)
  8839. #define USN_REASON_FILE_DELETE (0x00000200)
  8840. #define USN_REASON_EA_CHANGE (0x00000400)
  8841. #define USN_REASON_SECURITY_CHANGE (0x00000800)
  8842. #define USN_REASON_RENAME_OLD_NAME (0x00001000)
  8843. #define USN_REASON_RENAME_NEW_NAME (0x00002000)
  8844. #define USN_REASON_INDEXABLE_CHANGE (0x00004000)
  8845. #define USN_REASON_BASIC_INFO_CHANGE (0x00008000)
  8846. #define USN_REASON_HARD_LINK_CHANGE (0x00010000)
  8847. #define USN_REASON_COMPRESSION_CHANGE (0x00020000)
  8848. #define USN_REASON_ENCRYPTION_CHANGE (0x00040000)
  8849. #define USN_REASON_OBJECT_ID_CHANGE (0x00080000)
  8850. #define USN_REASON_REPARSE_POINT_CHANGE (0x00100000)
  8851. #define USN_REASON_STREAM_CHANGE (0x00200000)
  8852. #define USN_REASON_CLOSE (0x80000000)
  8853. //
  8854. // Structure for FSCTL_QUERY_USN_JOUNAL
  8855. //
  8856. typedef struct {
  8857. ULONGLONG UsnJournalID;
  8858. USN FirstUsn;
  8859. USN NextUsn;
  8860. USN LowestValidUsn;
  8861. USN MaxUsn;
  8862. ULONGLONG MaximumSize;
  8863. ULONGLONG AllocationDelta;
  8864. } USN_JOURNAL_DATA, *PUSN_JOURNAL_DATA;
  8865. //
  8866. // Structure for FSCTL_DELETE_USN_JOURNAL
  8867. //
  8868. typedef struct {
  8869. ULONGLONG UsnJournalID;
  8870. ULONG DeleteFlags;
  8871. } DELETE_USN_JOURNAL_DATA, *PDELETE_USN_JOURNAL_DATA;
  8872. #define USN_DELETE_FLAG_DELETE (0x00000001)
  8873. #define USN_DELETE_FLAG_NOTIFY (0x00000002)
  8874. #define USN_DELETE_VALID_FLAGS (0x00000003)
  8875. //
  8876. // Structure for FSCTL_MARK_HANDLE
  8877. //
  8878. typedef struct {
  8879. ULONG UsnSourceInfo;
  8880. HANDLE VolumeHandle;
  8881. ULONG HandleInfo;
  8882. } MARK_HANDLE_INFO, *PMARK_HANDLE_INFO;
  8883. #if defined(_WIN64)
  8884. //
  8885. // 32/64 Bit thunking support structure
  8886. //
  8887. typedef struct {
  8888. ULONG UsnSourceInfo;
  8889. UINT32 VolumeHandle;
  8890. ULONG HandleInfo;
  8891. } MARK_HANDLE_INFO32, *PMARK_HANDLE_INFO32;
  8892. #endif
  8893. //
  8894. // Flags for the additional source information above.
  8895. //
  8896. // USN_SOURCE_DATA_MANAGEMENT - Service is not modifying the external view
  8897. // of any part of the file. Typical case is HSM moving data to
  8898. // and from external storage.
  8899. //
  8900. // USN_SOURCE_AUXILIARY_DATA - Service is not modifying the external view
  8901. // of the file with regard to the application that created this file.
  8902. // Can be used to add private data streams to a file.
  8903. //
  8904. // USN_SOURCE_REPLICATION_MANAGEMENT - Service is modifying a file to match
  8905. // the contents of the same file which exists in another member of the
  8906. // replica set.
  8907. //
  8908. #define USN_SOURCE_DATA_MANAGEMENT (0x00000001)
  8909. #define USN_SOURCE_AUXILIARY_DATA (0x00000002)
  8910. #define USN_SOURCE_REPLICATION_MANAGEMENT (0x00000004)
  8911. //
  8912. // Flags for the HandleInfo field above
  8913. //
  8914. // MARK_HANDLE_PROTECT_CLUSTERS - disallow any defragmenting (FSCTL_MOVE_FILE) until the
  8915. // the handle is closed
  8916. //
  8917. #define MARK_HANDLE_PROTECT_CLUSTERS (0x00000001)
  8918. #endif /* _WIN32_WINNT >= 0x0500 */
  8919. #if(_WIN32_WINNT >= 0x0500)
  8920. //
  8921. // Structure for FSCTL_SECURITY_ID_CHECK
  8922. //
  8923. typedef struct {
  8924. ACCESS_MASK DesiredAccess;
  8925. ULONG SecurityIds[1];
  8926. } BULK_SECURITY_TEST_DATA, *PBULK_SECURITY_TEST_DATA;
  8927. #endif /* _WIN32_WINNT >= 0x0500 */
  8928. #if(_WIN32_WINNT >= 0x0500)
  8929. //
  8930. // Output flags for the FSCTL_IS_VOLUME_DIRTY
  8931. //
  8932. #define VOLUME_IS_DIRTY (0x00000001)
  8933. #define VOLUME_UPGRADE_SCHEDULED (0x00000002)
  8934. #endif /* _WIN32_WINNT >= 0x0500 */
  8935. //
  8936. // Structures for FSCTL_FILE_PREFETCH
  8937. //
  8938. typedef struct _FILE_PREFETCH {
  8939. ULONG Type;
  8940. ULONG Count;
  8941. ULONGLONG Prefetch[1];
  8942. } FILE_PREFETCH, *PFILE_PREFETCH;
  8943. #define FILE_PREFETCH_TYPE_FOR_CREATE 0x1
  8944. // Structures for FSCTL_FILESYSTEM_GET_STATISTICS
  8945. //
  8946. // Filesystem performance counters
  8947. //
  8948. typedef struct _FILESYSTEM_STATISTICS {
  8949. USHORT FileSystemType;
  8950. USHORT Version; // currently version 1
  8951. ULONG SizeOfCompleteStructure; // must by a mutiple of 64 bytes
  8952. ULONG UserFileReads;
  8953. ULONG UserFileReadBytes;
  8954. ULONG UserDiskReads;
  8955. ULONG UserFileWrites;
  8956. ULONG UserFileWriteBytes;
  8957. ULONG UserDiskWrites;
  8958. ULONG MetaDataReads;
  8959. ULONG MetaDataReadBytes;
  8960. ULONG MetaDataDiskReads;
  8961. ULONG MetaDataWrites;
  8962. ULONG MetaDataWriteBytes;
  8963. ULONG MetaDataDiskWrites;
  8964. //
  8965. // The file system's private structure is appended here.
  8966. //
  8967. } FILESYSTEM_STATISTICS, *PFILESYSTEM_STATISTICS;
  8968. // values for FS_STATISTICS.FileSystemType
  8969. #define FILESYSTEM_STATISTICS_TYPE_NTFS 1
  8970. #define FILESYSTEM_STATISTICS_TYPE_FAT 2
  8971. //
  8972. // File System Specific Statistics Data
  8973. //
  8974. typedef struct _FAT_STATISTICS {
  8975. ULONG CreateHits;
  8976. ULONG SuccessfulCreates;
  8977. ULONG FailedCreates;
  8978. ULONG NonCachedReads;
  8979. ULONG NonCachedReadBytes;
  8980. ULONG NonCachedWrites;
  8981. ULONG NonCachedWriteBytes;
  8982. ULONG NonCachedDiskReads;
  8983. ULONG NonCachedDiskWrites;
  8984. } FAT_STATISTICS, *PFAT_STATISTICS;
  8985. typedef struct _NTFS_STATISTICS {
  8986. ULONG LogFileFullExceptions;
  8987. ULONG OtherExceptions;
  8988. //
  8989. // Other meta data io's
  8990. //
  8991. ULONG MftReads;
  8992. ULONG MftReadBytes;
  8993. ULONG MftWrites;
  8994. ULONG MftWriteBytes;
  8995. struct {
  8996. USHORT Write;
  8997. USHORT Create;
  8998. USHORT SetInfo;
  8999. USHORT Flush;
  9000. } MftWritesUserLevel;
  9001. USHORT MftWritesFlushForLogFileFull;
  9002. USHORT MftWritesLazyWriter;
  9003. USHORT MftWritesUserRequest;
  9004. ULONG Mft2Writes;
  9005. ULONG Mft2WriteBytes;
  9006. struct {
  9007. USHORT Write;
  9008. USHORT Create;
  9009. USHORT SetInfo;
  9010. USHORT Flush;
  9011. } Mft2WritesUserLevel;
  9012. USHORT Mft2WritesFlushForLogFileFull;
  9013. USHORT Mft2WritesLazyWriter;
  9014. USHORT Mft2WritesUserRequest;
  9015. ULONG RootIndexReads;
  9016. ULONG RootIndexReadBytes;
  9017. ULONG RootIndexWrites;
  9018. ULONG RootIndexWriteBytes;
  9019. ULONG BitmapReads;
  9020. ULONG BitmapReadBytes;
  9021. ULONG BitmapWrites;
  9022. ULONG BitmapWriteBytes;
  9023. USHORT BitmapWritesFlushForLogFileFull;
  9024. USHORT BitmapWritesLazyWriter;
  9025. USHORT BitmapWritesUserRequest;
  9026. struct {
  9027. USHORT Write;
  9028. USHORT Create;
  9029. USHORT SetInfo;
  9030. } BitmapWritesUserLevel;
  9031. ULONG MftBitmapReads;
  9032. ULONG MftBitmapReadBytes;
  9033. ULONG MftBitmapWrites;
  9034. ULONG MftBitmapWriteBytes;
  9035. USHORT MftBitmapWritesFlushForLogFileFull;
  9036. USHORT MftBitmapWritesLazyWriter;
  9037. USHORT MftBitmapWritesUserRequest;
  9038. struct {
  9039. USHORT Write;
  9040. USHORT Create;
  9041. USHORT SetInfo;
  9042. USHORT Flush;
  9043. } MftBitmapWritesUserLevel;
  9044. ULONG UserIndexReads;
  9045. ULONG UserIndexReadBytes;
  9046. ULONG UserIndexWrites;
  9047. ULONG UserIndexWriteBytes;
  9048. //
  9049. // Additions for NT 5.0
  9050. //
  9051. ULONG LogFileReads;
  9052. ULONG LogFileReadBytes;
  9053. ULONG LogFileWrites;
  9054. ULONG LogFileWriteBytes;
  9055. struct {
  9056. ULONG Calls; // number of individual calls to allocate clusters
  9057. ULONG Clusters; // number of clusters allocated
  9058. ULONG Hints; // number of times a hint was specified
  9059. ULONG RunsReturned; // number of runs used to satisify all the requests
  9060. ULONG HintsHonored; // number of times the hint was useful
  9061. ULONG HintsClusters; // number of clusters allocated via the hint
  9062. ULONG Cache; // number of times the cache was useful other than the hint
  9063. ULONG CacheClusters; // number of clusters allocated via the cache other than the hint
  9064. ULONG CacheMiss; // number of times the cache wasn't useful
  9065. ULONG CacheMissClusters; // number of clusters allocated without the cache
  9066. } Allocate;
  9067. } NTFS_STATISTICS, *PNTFS_STATISTICS;
  9068. #if(_WIN32_WINNT >= 0x0500)
  9069. //
  9070. // Structure for FSCTL_SET_OBJECT_ID, FSCTL_GET_OBJECT_ID, and FSCTL_CREATE_OR_GET_OBJECT_ID
  9071. //
  9072. #if _MSC_VER >= 1200
  9073. #pragma warning(push)
  9074. #endif
  9075. #pragma warning(disable:4201) // unnamed struct
  9076. typedef struct _FILE_OBJECTID_BUFFER {
  9077. //
  9078. // This is the portion of the object id that is indexed.
  9079. //
  9080. UCHAR ObjectId[16];
  9081. //
  9082. // This portion of the object id is not indexed, it's just
  9083. // some metadata for the user's benefit.
  9084. //
  9085. union {
  9086. struct {
  9087. UCHAR BirthVolumeId[16];
  9088. UCHAR BirthObjectId[16];
  9089. UCHAR DomainId[16];
  9090. } ;
  9091. UCHAR ExtendedInfo[48];
  9092. };
  9093. } FILE_OBJECTID_BUFFER, *PFILE_OBJECTID_BUFFER;
  9094. #if _MSC_VER >= 1200
  9095. #pragma warning(pop)
  9096. #else
  9097. #pragma warning( default : 4201 )
  9098. #endif
  9099. #endif /* _WIN32_WINNT >= 0x0500 */
  9100. #if(_WIN32_WINNT >= 0x0500)
  9101. //
  9102. // Structure for FSCTL_SET_SPARSE
  9103. //
  9104. typedef struct _FILE_SET_SPARSE_BUFFER {
  9105. BOOLEAN SetSparse;
  9106. } FILE_SET_SPARSE_BUFFER, *PFILE_SET_SPARSE_BUFFER;
  9107. #endif /* _WIN32_WINNT >= 0x0500 */
  9108. #if(_WIN32_WINNT >= 0x0500)
  9109. //
  9110. // Structure for FSCTL_SET_ZERO_DATA
  9111. //
  9112. typedef struct _FILE_ZERO_DATA_INFORMATION {
  9113. LARGE_INTEGER FileOffset;
  9114. LARGE_INTEGER BeyondFinalZero;
  9115. } FILE_ZERO_DATA_INFORMATION, *PFILE_ZERO_DATA_INFORMATION;
  9116. #endif /* _WIN32_WINNT >= 0x0500 */
  9117. #if(_WIN32_WINNT >= 0x0500)
  9118. //
  9119. // Structure for FSCTL_QUERY_ALLOCATED_RANGES
  9120. //
  9121. //
  9122. // Querying the allocated ranges requires an output buffer to store the
  9123. // allocated ranges and an input buffer to specify the range to query.
  9124. // The input buffer contains a single entry, the output buffer is an
  9125. // array of the following structure.
  9126. //
  9127. typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
  9128. LARGE_INTEGER FileOffset;
  9129. LARGE_INTEGER Length;
  9130. } FILE_ALLOCATED_RANGE_BUFFER, *PFILE_ALLOCATED_RANGE_BUFFER;
  9131. #endif /* _WIN32_WINNT >= 0x0500 */
  9132. #if(_WIN32_WINNT >= 0x0500)
  9133. //
  9134. // Structures for FSCTL_SET_ENCRYPTION, FSCTL_WRITE_RAW_ENCRYPTED, and FSCTL_READ_RAW_ENCRYPTED
  9135. //
  9136. //
  9137. // The input buffer to set encryption indicates whether we are to encrypt/decrypt a file
  9138. // or an individual stream.
  9139. //
  9140. typedef struct _ENCRYPTION_BUFFER {
  9141. ULONG EncryptionOperation;
  9142. UCHAR Private[1];
  9143. } ENCRYPTION_BUFFER, *PENCRYPTION_BUFFER;
  9144. #define FILE_SET_ENCRYPTION 0x00000001
  9145. #define FILE_CLEAR_ENCRYPTION 0x00000002
  9146. #define STREAM_SET_ENCRYPTION 0x00000003
  9147. #define STREAM_CLEAR_ENCRYPTION 0x00000004
  9148. #define MAXIMUM_ENCRYPTION_VALUE 0x00000004
  9149. //
  9150. // The optional output buffer to set encryption indicates that the last encrypted
  9151. // stream in a file has been marked as decrypted.
  9152. //
  9153. typedef struct _DECRYPTION_STATUS_BUFFER {
  9154. BOOLEAN NoEncryptedStreams;
  9155. } DECRYPTION_STATUS_BUFFER, *PDECRYPTION_STATUS_BUFFER;
  9156. #define ENCRYPTION_FORMAT_DEFAULT (0x01)
  9157. #define COMPRESSION_FORMAT_SPARSE (0x4000)
  9158. //
  9159. // Request Encrypted Data structure. This is used to indicate
  9160. // the range of the file to read. It also describes the
  9161. // output buffer used to return the data.
  9162. //
  9163. typedef struct _REQUEST_RAW_ENCRYPTED_DATA {
  9164. //
  9165. // Requested file offset and requested length to read.
  9166. // The fsctl will round the starting offset down
  9167. // to a file system boundary. It will also
  9168. // round the length up to a file system boundary.
  9169. //
  9170. LONGLONG FileOffset;
  9171. ULONG Length;
  9172. } REQUEST_RAW_ENCRYPTED_DATA, *PREQUEST_RAW_ENCRYPTED_DATA;
  9173. //
  9174. // Encrypted Data Information structure. This structure
  9175. // is used to return raw encrypted data from a file in
  9176. // order to perform off-line recovery. The data will be
  9177. // encrypted or encrypted and compressed. The off-line
  9178. // service will need to use the encryption and compression
  9179. // format information to recover the file data. In the
  9180. // event that the data is both encrypted and compressed then
  9181. // the decryption must occur before decompression. All
  9182. // the data units below must be encrypted and compressed
  9183. // with the same format.
  9184. //
  9185. // The data will be returned in units. The data unit size
  9186. // will be fixed per request. If the data is compressed
  9187. // then the data unit size will be the compression unit size.
  9188. //
  9189. // This structure is at the beginning of the buffer used to
  9190. // return the encrypted data. The actual raw bytes from
  9191. // the file will follow this buffer. The offset of the
  9192. // raw bytes from the beginning of this structure is
  9193. // specified in the REQUEST_RAW_ENCRYPTED_DATA structure
  9194. // described above.
  9195. //
  9196. typedef struct _ENCRYPTED_DATA_INFO {
  9197. //
  9198. // This is the file offset for the first entry in the
  9199. // data block array. The file system will round
  9200. // the requested start offset down to a boundary
  9201. // that is consistent with the format of the file.
  9202. //
  9203. ULONGLONG StartingFileOffset;
  9204. //
  9205. // Data offset in output buffer. The output buffer
  9206. // begins with an ENCRYPTED_DATA_INFO structure.
  9207. // The file system will then store the raw bytes from
  9208. // disk beginning at the following offset within the
  9209. // output buffer.
  9210. //
  9211. ULONG OutputBufferOffset;
  9212. //
  9213. // The number of bytes being returned that are within
  9214. // the size of the file. If this value is less than
  9215. // (NumberOfDataBlocks << DataUnitShift), it means the
  9216. // end of the file occurs within this transfer. Any
  9217. // data beyond file size is invalid and was never
  9218. // passed to the encryption driver.
  9219. //
  9220. ULONG BytesWithinFileSize;
  9221. //
  9222. // The number of bytes being returned that are below
  9223. // valid data length. If this value is less than
  9224. // (NumberOfDataBlocks << DataUnitShift), it means the
  9225. // end of the valid data occurs within this transfer.
  9226. // After decrypting the data from this transfer, any
  9227. // byte(s) beyond valid data length must be zeroed.
  9228. //
  9229. ULONG BytesWithinValidDataLength;
  9230. //
  9231. // Code for the compression format as defined in
  9232. // ntrtl.h. Note that COMPRESSION_FORMAT_NONE
  9233. // and COMPRESSION_FORMAT_DEFAULT are invalid if
  9234. // any of the described chunks are compressed.
  9235. //
  9236. USHORT CompressionFormat;
  9237. //
  9238. // The DataUnit is the granularity used to access the
  9239. // disk. It will be the same as the compression unit
  9240. // size for a compressed file. For an uncompressed
  9241. // file, it will be some cluster-aligned power of 2 that
  9242. // the file system deems convenient. A caller should
  9243. // not expect that successive calls will have the
  9244. // same data unit shift value as the previous call.
  9245. //
  9246. // Since chunks and compression units are expected to be
  9247. // powers of 2 in size, we express them log2. So, for
  9248. // example (1 << ChunkShift) == ChunkSizeInBytes. The
  9249. // ClusterShift indicates how much space must be saved
  9250. // to successfully compress a compression unit - each
  9251. // successfully compressed data unit must occupy
  9252. // at least one cluster less in bytes than an uncompressed
  9253. // data block unit.
  9254. //
  9255. UCHAR DataUnitShift;
  9256. UCHAR ChunkShift;
  9257. UCHAR ClusterShift;
  9258. //
  9259. // The format for the encryption.
  9260. //
  9261. UCHAR EncryptionFormat;
  9262. //
  9263. // This is the number of entries in the data block size
  9264. // array.
  9265. //
  9266. USHORT NumberOfDataBlocks;
  9267. //
  9268. // This is an array of sizes in the data block array. There
  9269. // must be one entry in this array for each data block
  9270. // read from disk. The size has a different meaning
  9271. // depending on whether the file is compressed.
  9272. //
  9273. // A size of zero always indicates that the final data consists entirely
  9274. // of zeroes. There is no decryption or decompression to
  9275. // perform.
  9276. //
  9277. // If the file is compressed then the data block size indicates
  9278. // whether this block is compressed. A size equal to
  9279. // the block size indicates that the corresponding block did
  9280. // not compress. Any other non-zero size indicates the
  9281. // size of the compressed data which needs to be
  9282. // decrypted/decompressed.
  9283. //
  9284. // If the file is not compressed then the data block size
  9285. // indicates the amount of data within the block that
  9286. // needs to be decrypted. Any other non-zero size indicates
  9287. // that the remaining bytes in the data unit within the file
  9288. // consists of zeros. An example of this is when the
  9289. // the read spans the valid data length of the file. There
  9290. // is no data to decrypt past the valid data length.
  9291. //
  9292. ULONG DataBlockSize[ANYSIZE_ARRAY];
  9293. } ENCRYPTED_DATA_INFO;
  9294. typedef ENCRYPTED_DATA_INFO *PENCRYPTED_DATA_INFO;
  9295. #endif /* _WIN32_WINNT >= 0x0500 */
  9296. #if(_WIN32_WINNT >= 0x0500)
  9297. //
  9298. // FSCTL_READ_FROM_PLEX support
  9299. // Request Plex Read Data structure. This is used to indicate
  9300. // the range of the file to read. It also describes
  9301. // which plex to perform the read from.
  9302. //
  9303. typedef struct _PLEX_READ_DATA_REQUEST {
  9304. //
  9305. // Requested offset and length to read.
  9306. // The offset can be the virtual offset (vbo) in to a file,
  9307. // or a volume. In the case of a file offset,
  9308. // the fsd will round the starting offset down
  9309. // to a file system boundary. It will also
  9310. // round the length up to a file system boundary and
  9311. // enforce any other applicable limits.
  9312. //
  9313. LARGE_INTEGER ByteOffset;
  9314. ULONG ByteLength;
  9315. ULONG PlexNumber;
  9316. } PLEX_READ_DATA_REQUEST, *PPLEX_READ_DATA_REQUEST;
  9317. #endif /* _WIN32_WINNT >= 0x0500 */
  9318. #if(_WIN32_WINNT >= 0x0500)
  9319. //
  9320. // FSCTL_SIS_COPYFILE support
  9321. // Source and destination file names are passed in the FileNameBuffer.
  9322. // Both strings are null terminated, with the source name starting at
  9323. // the beginning of FileNameBuffer, and the destination name immediately
  9324. // following. Length fields include terminating nulls.
  9325. //
  9326. typedef struct _SI_COPYFILE {
  9327. ULONG SourceFileNameLength;
  9328. ULONG DestinationFileNameLength;
  9329. ULONG Flags;
  9330. WCHAR FileNameBuffer[1];
  9331. } SI_COPYFILE, *PSI_COPYFILE;
  9332. #define COPYFILE_SIS_LINK 0x0001 // Copy only if source is SIS
  9333. #define COPYFILE_SIS_REPLACE 0x0002 // Replace destination if it exists, otherwise don't.
  9334. #define COPYFILE_SIS_FLAGS 0x0003
  9335. #endif /* _WIN32_WINNT >= 0x0500 */
  9336. #endif // _FILESYSTEMFSCTL_
  9337. // end_winioctl
  9338. //
  9339. // Structures for FSCTL_SET_REPARSE_POINT, FSCTL_GET_REPARSE_POINT, and FSCTL_DELETE_REPARSE_POINT
  9340. //
  9341. //
  9342. // The reparse structure is used by layered drivers to store data in a
  9343. // reparse point. The constraints on reparse tags are defined below.
  9344. // This version of the reparse data buffer is only for Microsoft tags.
  9345. //
  9346. #if _MSC_VER >= 1200
  9347. #pragma warning(push)
  9348. #endif
  9349. #pragma warning(disable:4201) // unnamed struct
  9350. typedef struct _REPARSE_DATA_BUFFER {
  9351. ULONG ReparseTag;
  9352. USHORT ReparseDataLength;
  9353. USHORT Reserved;
  9354. union {
  9355. struct {
  9356. USHORT SubstituteNameOffset;
  9357. USHORT SubstituteNameLength;
  9358. USHORT PrintNameOffset;
  9359. USHORT PrintNameLength;
  9360. WCHAR PathBuffer[1];
  9361. } SymbolicLinkReparseBuffer;
  9362. struct {
  9363. USHORT SubstituteNameOffset;
  9364. USHORT SubstituteNameLength;
  9365. USHORT PrintNameOffset;
  9366. USHORT PrintNameLength;
  9367. WCHAR PathBuffer[1];
  9368. } MountPointReparseBuffer;
  9369. struct {
  9370. UCHAR DataBuffer[1];
  9371. } GenericReparseBuffer;
  9372. };
  9373. } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
  9374. #if _MSC_VER >= 1200
  9375. #pragma warning(pop)
  9376. #else
  9377. #pragma warning( default : 4201 )
  9378. #endif
  9379. #define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer)
  9380. // begin_winnt
  9381. //
  9382. // The reparse GUID structure is used by all 3rd party layered drivers to
  9383. // store data in a reparse point. For non-Microsoft tags, The GUID field
  9384. // cannot be GUID_NULL.
  9385. // The constraints on reparse tags are defined below.
  9386. // Microsoft tags can also be used with this format of the reparse point buffer.
  9387. //
  9388. typedef struct _REPARSE_GUID_DATA_BUFFER {
  9389. ULONG ReparseTag;
  9390. USHORT ReparseDataLength;
  9391. USHORT Reserved;
  9392. GUID ReparseGuid;
  9393. struct {
  9394. UCHAR DataBuffer[1];
  9395. } GenericReparseBuffer;
  9396. } REPARSE_GUID_DATA_BUFFER, *PREPARSE_GUID_DATA_BUFFER;
  9397. #define REPARSE_GUID_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer)
  9398. //
  9399. // Maximum allowed size of the reparse data.
  9400. //
  9401. #define MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 )
  9402. //
  9403. // Predefined reparse tags.
  9404. // These tags need to avoid conflicting with IO_REMOUNT defined in ntos\inc\io.h
  9405. //
  9406. #define IO_REPARSE_TAG_RESERVED_ZERO (0)
  9407. #define IO_REPARSE_TAG_RESERVED_ONE (1)
  9408. //
  9409. // The value of the following constant needs to satisfy the following conditions:
  9410. // (1) Be at least as large as the largest of the reserved tags.
  9411. // (2) Be strictly smaller than all the tags in use.
  9412. //
  9413. #define IO_REPARSE_TAG_RESERVED_RANGE IO_REPARSE_TAG_RESERVED_ONE
  9414. //
  9415. // The reparse tags are a ULONG. The 32 bits are laid out as follows:
  9416. //
  9417. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  9418. // 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
  9419. // +-+-+-+-+-----------------------+-------------------------------+
  9420. // |M|R|N|R| Reserved bits | Reparse Tag Value |
  9421. // +-+-+-+-+-----------------------+-------------------------------+
  9422. //
  9423. // M is the Microsoft bit. When set to 1, it denotes a tag owned by Microsoft.
  9424. // All ISVs must use a tag with a 0 in this position.
  9425. // Note: If a Microsoft tag is used by non-Microsoft software, the
  9426. // behavior is not defined.
  9427. //
  9428. // R is reserved. Must be zero for non-Microsoft tags.
  9429. //
  9430. // N is name surrogate. When set to 1, the file represents another named
  9431. // entity in the system.
  9432. //
  9433. // The M and N bits are OR-able.
  9434. // The following macros check for the M and N bit values:
  9435. //
  9436. //
  9437. // Macro to determine whether a reparse point tag corresponds to a tag
  9438. // owned by Microsoft.
  9439. //
  9440. #define IsReparseTagMicrosoft(_tag) ( \
  9441. ((_tag) & 0x80000000) \
  9442. )
  9443. //
  9444. // Macro to determine whether a reparse point tag is a name surrogate
  9445. //
  9446. #define IsReparseTagNameSurrogate(_tag) ( \
  9447. ((_tag) & 0x20000000) \
  9448. )
  9449. // end_winnt
  9450. //
  9451. // The following constant represents the bits that are valid to use in
  9452. // reparse tags.
  9453. //
  9454. #define IO_REPARSE_TAG_VALID_VALUES (0xF000FFFF)
  9455. //
  9456. // Macro to determine whether a reparse tag is a valid tag.
  9457. //
  9458. #define IsReparseTagValid(_tag) ( \
  9459. !((_tag) & ~IO_REPARSE_TAG_VALID_VALUES) && \
  9460. ((_tag) > IO_REPARSE_TAG_RESERVED_RANGE) \
  9461. )
  9462. //
  9463. // Microsoft tags for reparse points.
  9464. //
  9465. #define IO_REPARSE_TAG_SYMBOLIC_LINK IO_REPARSE_TAG_RESERVED_ZERO
  9466. #define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L) // winnt ntifs
  9467. #define IO_REPARSE_TAG_HSM (0xC0000004L) // winnt ntifs
  9468. #define IO_REPARSE_TAG_SIS (0x80000007L) // winnt ntifs
  9469. //
  9470. // The reparse tags 0x80000008 thru 0x8000000A are reserved for Microsoft
  9471. // internal use (may be published in the future)
  9472. //
  9473. #define IO_REPARSE_TAG_FILTER_MANAGER (0x8000000BL) // winnt ntifs
  9474. //
  9475. // Non-Microsoft tags for reparse points
  9476. //
  9477. //
  9478. // Congruent May 2000. Used by IFSTEST
  9479. //
  9480. #define IO_REPARSE_TAG_IFSTEST_CONGRUENT (0x00000009L)
  9481. //
  9482. // The following three FSCTLs are placed in this file to facilitate sharing
  9483. // between the redirector and the IO subsystem
  9484. //
  9485. // This FSCTL is used to garner the link tracking information for a file.
  9486. // The data structures used for retreving the information are
  9487. // LINK_TRACKING_INFORMATION defined further down in this file.
  9488. //
  9489. #define FSCTL_LMR_GET_LINK_TRACKING_INFORMATION CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM,58,METHOD_BUFFERED,FILE_ANY_ACCESS)
  9490. //
  9491. // This FSCTL is used to update the link tracking information on a server for
  9492. // an intra machine/ inter volume move on that server
  9493. //
  9494. #define FSCTL_LMR_SET_LINK_TRACKING_INFORMATION CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM,59,METHOD_BUFFERED,FILE_ANY_ACCESS)
  9495. //
  9496. // The following IOCTL is used in link tracking implementation. It determines if the
  9497. // two file objects passed in are on the same server. This IOCTL is available in
  9498. // kernel mode only since it accepts FILE_OBJECT as parameters
  9499. //
  9500. #define IOCTL_LMR_ARE_FILE_OBJECTS_ON_SAME_SERVER CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM,60,METHOD_BUFFERED,FILE_ANY_ACCESS)
  9501. //
  9502. // Named Pipe file control code and structure declarations
  9503. //
  9504. //
  9505. // External named pipe file control operations
  9506. //
  9507. #define FSCTL_PIPE_ASSIGN_EVENT CTL_CODE(FILE_DEVICE_NAMED_PIPE, 0, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9508. #define FSCTL_PIPE_DISCONNECT CTL_CODE(FILE_DEVICE_NAMED_PIPE, 1, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9509. #define FSCTL_PIPE_LISTEN CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9510. #define FSCTL_PIPE_PEEK CTL_CODE(FILE_DEVICE_NAMED_PIPE, 3, METHOD_BUFFERED, FILE_READ_DATA)
  9511. #define FSCTL_PIPE_QUERY_EVENT CTL_CODE(FILE_DEVICE_NAMED_PIPE, 4, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9512. #define FSCTL_PIPE_TRANSCEIVE CTL_CODE(FILE_DEVICE_NAMED_PIPE, 5, METHOD_NEITHER, FILE_READ_DATA | FILE_WRITE_DATA)
  9513. #define FSCTL_PIPE_WAIT CTL_CODE(FILE_DEVICE_NAMED_PIPE, 6, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9514. #define FSCTL_PIPE_IMPERSONATE CTL_CODE(FILE_DEVICE_NAMED_PIPE, 7, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9515. #define FSCTL_PIPE_SET_CLIENT_PROCESS CTL_CODE(FILE_DEVICE_NAMED_PIPE, 8, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9516. #define FSCTL_PIPE_QUERY_CLIENT_PROCESS CTL_CODE(FILE_DEVICE_NAMED_PIPE, 9, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9517. //
  9518. // Internal named pipe file control operations
  9519. //
  9520. #define FSCTL_PIPE_INTERNAL_READ CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2045, METHOD_BUFFERED, FILE_READ_DATA)
  9521. #define FSCTL_PIPE_INTERNAL_WRITE CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2046, METHOD_BUFFERED, FILE_WRITE_DATA)
  9522. #define FSCTL_PIPE_INTERNAL_TRANSCEIVE CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2047, METHOD_NEITHER, FILE_READ_DATA | FILE_WRITE_DATA)
  9523. #define FSCTL_PIPE_INTERNAL_READ_OVFLOW CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2048, METHOD_BUFFERED, FILE_READ_DATA)
  9524. //
  9525. // Define entry types for query event information
  9526. //
  9527. #define FILE_PIPE_READ_DATA 0x00000000
  9528. #define FILE_PIPE_WRITE_SPACE 0x00000001
  9529. //
  9530. // Named pipe file system control structure declarations
  9531. //
  9532. // Control structure for FSCTL_PIPE_ASSIGN_EVENT
  9533. typedef struct _FILE_PIPE_ASSIGN_EVENT_BUFFER {
  9534. HANDLE EventHandle;
  9535. ULONG KeyValue;
  9536. } FILE_PIPE_ASSIGN_EVENT_BUFFER, *PFILE_PIPE_ASSIGN_EVENT_BUFFER;
  9537. // Control structure for FSCTL_PIPE_PEEK
  9538. typedef struct _FILE_PIPE_PEEK_BUFFER {
  9539. ULONG NamedPipeState;
  9540. ULONG ReadDataAvailable;
  9541. ULONG NumberOfMessages;
  9542. ULONG MessageLength;
  9543. CHAR Data[1];
  9544. } FILE_PIPE_PEEK_BUFFER, *PFILE_PIPE_PEEK_BUFFER;
  9545. // Control structure for FSCTL_PIPE_QUERY_EVENT
  9546. typedef struct _FILE_PIPE_EVENT_BUFFER {
  9547. ULONG NamedPipeState;
  9548. ULONG EntryType;
  9549. ULONG ByteCount;
  9550. ULONG KeyValue;
  9551. ULONG NumberRequests;
  9552. } FILE_PIPE_EVENT_BUFFER, *PFILE_PIPE_EVENT_BUFFER;
  9553. // Control structure for FSCTL_PIPE_WAIT
  9554. typedef struct _FILE_PIPE_WAIT_FOR_BUFFER {
  9555. LARGE_INTEGER Timeout;
  9556. ULONG NameLength;
  9557. BOOLEAN TimeoutSpecified;
  9558. WCHAR Name[1];
  9559. } FILE_PIPE_WAIT_FOR_BUFFER, *PFILE_PIPE_WAIT_FOR_BUFFER;
  9560. // Control structure for FSCTL_PIPE_SET_CLIENT_PROCESS and FSCTL_PIPE_QUERY_CLIENT_PROCESS
  9561. typedef struct _FILE_PIPE_CLIENT_PROCESS_BUFFER {
  9562. #if !defined(BUILD_WOW6432)
  9563. PVOID ClientSession;
  9564. PVOID ClientProcess;
  9565. #else
  9566. ULONGLONG ClientSession;
  9567. ULONGLONG ClientProcess;
  9568. #endif
  9569. } FILE_PIPE_CLIENT_PROCESS_BUFFER, *PFILE_PIPE_CLIENT_PROCESS_BUFFER;
  9570. // This is an extension to the client process info buffer containing the client
  9571. // computer name
  9572. #define FILE_PIPE_COMPUTER_NAME_LENGTH 15
  9573. typedef struct _FILE_PIPE_CLIENT_PROCESS_BUFFER_EX {
  9574. #if !defined(BUILD_WOW6432)
  9575. PVOID ClientSession;
  9576. PVOID ClientProcess;
  9577. #else
  9578. ULONGLONG ClientSession;
  9579. ULONGLONG ClientProcess;
  9580. #endif
  9581. USHORT ClientComputerNameLength; // in bytes
  9582. WCHAR ClientComputerBuffer[FILE_PIPE_COMPUTER_NAME_LENGTH+1]; // terminated
  9583. } FILE_PIPE_CLIENT_PROCESS_BUFFER_EX, *PFILE_PIPE_CLIENT_PROCESS_BUFFER_EX;
  9584. #define FSCTL_MAILSLOT_PEEK CTL_CODE(FILE_DEVICE_MAILSLOT, 0, METHOD_NEITHER, FILE_READ_DATA)
  9585. //
  9586. // Control structure for FSCTL_LMR_GET_LINK_TRACKING_INFORMATION
  9587. //
  9588. //
  9589. // For links on DFS volumes the volume id and machine id are returned for
  9590. // link tracking
  9591. //
  9592. typedef enum _LINK_TRACKING_INFORMATION_TYPE {
  9593. NtfsLinkTrackingInformation,
  9594. DfsLinkTrackingInformation
  9595. } LINK_TRACKING_INFORMATION_TYPE, *PLINK_TRACKING_INFORMATION_TYPE;
  9596. typedef struct _LINK_TRACKING_INFORMATION {
  9597. LINK_TRACKING_INFORMATION_TYPE Type;
  9598. UCHAR VolumeId[16];
  9599. } LINK_TRACKING_INFORMATION, *PLINK_TRACKING_INFORMATION;
  9600. //
  9601. // Control structure for FSCTL_LMR_SET_LINK_TRACKING_INFORMATION
  9602. //
  9603. typedef struct _REMOTE_LINK_TRACKING_INFORMATION_ {
  9604. PVOID TargetFileObject;
  9605. ULONG TargetLinkTrackingInformationLength;
  9606. UCHAR TargetLinkTrackingInformationBuffer[1];
  9607. } REMOTE_LINK_TRACKING_INFORMATION,
  9608. *PREMOTE_LINK_TRACKING_INFORMATION;
  9609. //
  9610. // Define the I/O bus interface types.
  9611. //
  9612. typedef enum _INTERFACE_TYPE {
  9613. InterfaceTypeUndefined = -1,
  9614. Internal,
  9615. Isa,
  9616. Eisa,
  9617. MicroChannel,
  9618. TurboChannel,
  9619. PCIBus,
  9620. VMEBus,
  9621. NuBus,
  9622. PCMCIABus,
  9623. CBus,
  9624. MPIBus,
  9625. MPSABus,
  9626. ProcessorInternal,
  9627. InternalPowerBus,
  9628. PNPISABus,
  9629. PNPBus,
  9630. MaximumInterfaceType
  9631. }INTERFACE_TYPE, *PINTERFACE_TYPE;
  9632. //
  9633. // Define the DMA transfer widths.
  9634. //
  9635. typedef enum _DMA_WIDTH {
  9636. Width8Bits,
  9637. Width16Bits,
  9638. Width32Bits,
  9639. MaximumDmaWidth
  9640. }DMA_WIDTH, *PDMA_WIDTH;
  9641. //
  9642. // Define DMA transfer speeds.
  9643. //
  9644. typedef enum _DMA_SPEED {
  9645. Compatible,
  9646. TypeA,
  9647. TypeB,
  9648. TypeC,
  9649. TypeF,
  9650. MaximumDmaSpeed
  9651. }DMA_SPEED, *PDMA_SPEED;
  9652. //
  9653. // Define Interface reference/dereference routines for
  9654. // Interfaces exported by IRP_MN_QUERY_INTERFACE
  9655. //
  9656. typedef VOID (*PINTERFACE_REFERENCE)(PVOID Context);
  9657. typedef VOID (*PINTERFACE_DEREFERENCE)(PVOID Context);
  9658. // end_wdm
  9659. //
  9660. // Define types of bus information.
  9661. //
  9662. typedef enum _BUS_DATA_TYPE {
  9663. ConfigurationSpaceUndefined = -1,
  9664. Cmos,
  9665. EisaConfiguration,
  9666. Pos,
  9667. CbusConfiguration,
  9668. PCIConfiguration,
  9669. VMEConfiguration,
  9670. NuBusConfiguration,
  9671. PCMCIAConfiguration,
  9672. MPIConfiguration,
  9673. MPSAConfiguration,
  9674. PNPISAConfiguration,
  9675. SgiInternalConfiguration,
  9676. MaximumBusDataType
  9677. } BUS_DATA_TYPE, *PBUS_DATA_TYPE;
  9678. #if defined(USE_LPC6432)
  9679. #define LPC_CLIENT_ID CLIENT_ID64
  9680. #define LPC_SIZE_T ULONGLONG
  9681. #define LPC_PVOID ULONGLONG
  9682. #define LPC_HANDLE ULONGLONG
  9683. #else
  9684. #define LPC_CLIENT_ID CLIENT_ID
  9685. #define LPC_SIZE_T SIZE_T
  9686. #define LPC_PVOID PVOID
  9687. #define LPC_HANDLE HANDLE
  9688. #endif
  9689. typedef struct _PORT_MESSAGE {
  9690. union {
  9691. struct {
  9692. CSHORT DataLength;
  9693. CSHORT TotalLength;
  9694. } s1;
  9695. ULONG Length;
  9696. } u1;
  9697. union {
  9698. struct {
  9699. CSHORT Type;
  9700. CSHORT DataInfoOffset;
  9701. } s2;
  9702. ULONG ZeroInit;
  9703. } u2;
  9704. union {
  9705. LPC_CLIENT_ID ClientId;
  9706. double DoNotUseThisField; // Force quadword alignment
  9707. };
  9708. ULONG MessageId;
  9709. union {
  9710. LPC_SIZE_T ClientViewSize; // Only valid on LPC_CONNECTION_REQUEST message
  9711. ULONG CallbackId; // Only valid on LPC_REQUEST message
  9712. };
  9713. // UCHAR Data[];
  9714. } PORT_MESSAGE, *PPORT_MESSAGE;
  9715. //
  9716. // The following bit may be placed in the Type field of a message
  9717. // prior calling NtRequestPort or NtRequestWaitReplyPort. If the
  9718. // previous mode is KernelMode, the bit it left as is and passed
  9719. // to the receiver of the message. Otherwise the bit is clear.
  9720. //
  9721. #define LPC_KERNELMODE_MESSAGE (CSHORT)0x8000
  9722. typedef struct _PORT_VIEW {
  9723. ULONG Length;
  9724. LPC_HANDLE SectionHandle;
  9725. ULONG SectionOffset;
  9726. LPC_SIZE_T ViewSize;
  9727. LPC_PVOID ViewBase;
  9728. LPC_PVOID ViewRemoteBase;
  9729. } PORT_VIEW, *PPORT_VIEW;
  9730. typedef struct _REMOTE_PORT_VIEW {
  9731. ULONG Length;
  9732. LPC_SIZE_T ViewSize;
  9733. LPC_PVOID ViewBase;
  9734. } REMOTE_PORT_VIEW, *PREMOTE_PORT_VIEW;
  9735. NTSYSCALLAPI
  9736. NTSTATUS
  9737. NTAPI
  9738. NtConnectPort(
  9739. OUT PHANDLE PortHandle,
  9740. IN PUNICODE_STRING PortName,
  9741. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
  9742. IN OUT PPORT_VIEW ClientView OPTIONAL,
  9743. IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL,
  9744. OUT PULONG MaxMessageLength OPTIONAL,
  9745. IN OUT PVOID ConnectionInformation OPTIONAL,
  9746. IN OUT PULONG ConnectionInformationLength OPTIONAL
  9747. );
  9748. NTSYSCALLAPI
  9749. NTSTATUS
  9750. NTAPI
  9751. NtSecureConnectPort(
  9752. OUT PHANDLE PortHandle,
  9753. IN PUNICODE_STRING PortName,
  9754. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
  9755. IN OUT PPORT_VIEW ClientView OPTIONAL,
  9756. IN PSID RequiredServerSid,
  9757. IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL,
  9758. OUT PULONG MaxMessageLength OPTIONAL,
  9759. IN OUT PVOID ConnectionInformation OPTIONAL,
  9760. IN OUT PULONG ConnectionInformationLength OPTIONAL
  9761. );
  9762. NTSYSCALLAPI
  9763. NTSTATUS
  9764. NTAPI
  9765. NtRequestWaitReplyPort(
  9766. IN HANDLE PortHandle,
  9767. IN PPORT_MESSAGE RequestMessage,
  9768. OUT PPORT_MESSAGE ReplyMessage
  9769. );
  9770. NTSYSCALLAPI
  9771. NTSTATUS
  9772. NTAPI
  9773. NtSetSecurityObject(
  9774. IN HANDLE Handle,
  9775. IN SECURITY_INFORMATION SecurityInformation,
  9776. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  9777. );
  9778. NTSYSCALLAPI
  9779. NTSTATUS
  9780. NTAPI
  9781. NtQuerySecurityObject(
  9782. IN HANDLE Handle,
  9783. IN SECURITY_INFORMATION SecurityInformation,
  9784. OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  9785. IN ULONG Length,
  9786. OUT PULONG LengthNeeded
  9787. );
  9788. NTSYSCALLAPI
  9789. NTSTATUS
  9790. NTAPI
  9791. NtClose(
  9792. IN HANDLE Handle
  9793. );
  9794. #define SEC_COMMIT 0x8000000
  9795. NTSYSCALLAPI
  9796. NTSTATUS
  9797. NTAPI
  9798. NtCreateSection (
  9799. OUT PHANDLE SectionHandle,
  9800. IN ACCESS_MASK DesiredAccess,
  9801. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  9802. IN PLARGE_INTEGER MaximumSize OPTIONAL,
  9803. IN ULONG SectionPageProtection,
  9804. IN ULONG AllocationAttributes,
  9805. IN HANDLE FileHandle OPTIONAL
  9806. );
  9807. NTSYSCALLAPI
  9808. NTSTATUS
  9809. NTAPI
  9810. NtAllocateVirtualMemory(
  9811. IN HANDLE ProcessHandle,
  9812. IN OUT PVOID *BaseAddress,
  9813. IN ULONG_PTR ZeroBits,
  9814. IN OUT PSIZE_T RegionSize,
  9815. IN ULONG AllocationType,
  9816. IN ULONG Protect
  9817. );
  9818. NTSYSCALLAPI
  9819. NTSTATUS
  9820. NTAPI
  9821. NtFreeVirtualMemory(
  9822. IN HANDLE ProcessHandle,
  9823. IN OUT PVOID *BaseAddress,
  9824. IN OUT PSIZE_T RegionSize,
  9825. IN ULONG FreeType
  9826. );
  9827. //
  9828. // Priority increment definitions. The comment for each definition gives
  9829. // the names of the system services that use the definition when satisfying
  9830. // a wait.
  9831. //
  9832. //
  9833. // Priority increment used when satisfying a wait on an executive event
  9834. // (NtPulseEvent and NtSetEvent)
  9835. //
  9836. #define EVENT_INCREMENT 1
  9837. //
  9838. // Priority increment when no I/O has been done. This is used by device
  9839. // and file system drivers when completing an IRP (IoCompleteRequest).
  9840. //
  9841. #define IO_NO_INCREMENT 0
  9842. //
  9843. // Priority increment for completing CD-ROM I/O. This is used by CD-ROM device
  9844. // and file system drivers when completing an IRP (IoCompleteRequest)
  9845. //
  9846. #define IO_CD_ROM_INCREMENT 1
  9847. //
  9848. // Priority increment for completing disk I/O. This is used by disk device
  9849. // and file system drivers when completing an IRP (IoCompleteRequest)
  9850. //
  9851. #define IO_DISK_INCREMENT 1
  9852. //
  9853. // Priority increment for completing mailslot I/O. This is used by the mail-
  9854. // slot file system driver when completing an IRP (IoCompleteRequest).
  9855. //
  9856. #define IO_MAILSLOT_INCREMENT 2
  9857. //
  9858. // Priority increment for completing named pipe I/O. This is used by the
  9859. // named pipe file system driver when completing an IRP (IoCompleteRequest).
  9860. //
  9861. #define IO_NAMED_PIPE_INCREMENT 2
  9862. //
  9863. // Priority increment for completing network I/O. This is used by network
  9864. // device and network file system drivers when completing an IRP
  9865. // (IoCompleteRequest).
  9866. //
  9867. #define IO_NETWORK_INCREMENT 2
  9868. //
  9869. // Priority increment used when satisfying a wait on an executive semaphore
  9870. // (NtReleaseSemaphore)
  9871. //
  9872. #define SEMAPHORE_INCREMENT 1
  9873. #if defined(_X86_)
  9874. //
  9875. // Types to use to contain PFNs and their counts.
  9876. //
  9877. typedef ULONG PFN_COUNT;
  9878. typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
  9879. typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
  9880. //
  9881. // Define maximum size of flush multiple TB request.
  9882. //
  9883. #define FLUSH_MULTIPLE_MAXIMUM 16
  9884. //
  9885. // Indicate that the i386 compiler supports the pragma textout construct.
  9886. //
  9887. #define ALLOC_PRAGMA 1
  9888. //
  9889. // Indicate that the i386 compiler supports the DATA_SEG("INIT") and
  9890. // DATA_SEG("PAGE") pragmas
  9891. //
  9892. #define ALLOC_DATA_PRAGMA 1
  9893. #define NORMAL_DISPATCH_LENGTH 106
  9894. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  9895. //
  9896. // Interrupt Request Level definitions
  9897. //
  9898. #define PASSIVE_LEVEL 0 // Passive release level
  9899. #define LOW_LEVEL 0 // Lowest interrupt level
  9900. #define APC_LEVEL 1 // APC interrupt level
  9901. #define DISPATCH_LEVEL 2 // Dispatcher level
  9902. #define PROFILE_LEVEL 27 // timer used for profiling.
  9903. #define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
  9904. #define CLOCK2_LEVEL 28 // Interval clock 2 level
  9905. #define IPI_LEVEL 29 // Interprocessor interrupt level
  9906. #define POWER_LEVEL 30 // Power failure level
  9907. #define HIGH_LEVEL 31 // Highest interrupt level
  9908. #if defined(NT_UP)
  9909. #define SYNCH_LEVEL DISPATCH_LEVEL // synchronization level - UP system
  9910. #else
  9911. #define SYNCH_LEVEL (IPI_LEVEL-1) // synchronization level - MP system
  9912. #endif
  9913. //
  9914. // I/O space read and write macros.
  9915. //
  9916. // These have to be actual functions on the 386, because we need
  9917. // to use assembler, but cannot return a value if we inline it.
  9918. //
  9919. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  9920. // (Use x86 move instructions, with LOCK prefix to force correct behavior
  9921. // w.r.t. caches and write buffers.)
  9922. //
  9923. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  9924. // (Use x86 in/out instructions.)
  9925. //
  9926. NTKERNELAPI
  9927. UCHAR
  9928. NTAPI
  9929. READ_REGISTER_UCHAR(
  9930. PUCHAR Register
  9931. );
  9932. NTKERNELAPI
  9933. USHORT
  9934. NTAPI
  9935. READ_REGISTER_USHORT(
  9936. PUSHORT Register
  9937. );
  9938. NTKERNELAPI
  9939. ULONG
  9940. NTAPI
  9941. READ_REGISTER_ULONG(
  9942. PULONG Register
  9943. );
  9944. NTKERNELAPI
  9945. VOID
  9946. NTAPI
  9947. READ_REGISTER_BUFFER_UCHAR(
  9948. PUCHAR Register,
  9949. PUCHAR Buffer,
  9950. ULONG Count
  9951. );
  9952. NTKERNELAPI
  9953. VOID
  9954. NTAPI
  9955. READ_REGISTER_BUFFER_USHORT(
  9956. PUSHORT Register,
  9957. PUSHORT Buffer,
  9958. ULONG Count
  9959. );
  9960. NTKERNELAPI
  9961. VOID
  9962. NTAPI
  9963. READ_REGISTER_BUFFER_ULONG(
  9964. PULONG Register,
  9965. PULONG Buffer,
  9966. ULONG Count
  9967. );
  9968. NTKERNELAPI
  9969. VOID
  9970. NTAPI
  9971. WRITE_REGISTER_UCHAR(
  9972. PUCHAR Register,
  9973. UCHAR Value
  9974. );
  9975. NTKERNELAPI
  9976. VOID
  9977. NTAPI
  9978. WRITE_REGISTER_USHORT(
  9979. PUSHORT Register,
  9980. USHORT Value
  9981. );
  9982. NTKERNELAPI
  9983. VOID
  9984. NTAPI
  9985. WRITE_REGISTER_ULONG(
  9986. PULONG Register,
  9987. ULONG Value
  9988. );
  9989. NTKERNELAPI
  9990. VOID
  9991. NTAPI
  9992. WRITE_REGISTER_BUFFER_UCHAR(
  9993. PUCHAR Register,
  9994. PUCHAR Buffer,
  9995. ULONG Count
  9996. );
  9997. NTKERNELAPI
  9998. VOID
  9999. NTAPI
  10000. WRITE_REGISTER_BUFFER_USHORT(
  10001. PUSHORT Register,
  10002. PUSHORT Buffer,
  10003. ULONG Count
  10004. );
  10005. NTKERNELAPI
  10006. VOID
  10007. NTAPI
  10008. WRITE_REGISTER_BUFFER_ULONG(
  10009. PULONG Register,
  10010. PULONG Buffer,
  10011. ULONG Count
  10012. );
  10013. NTHALAPI
  10014. UCHAR
  10015. NTAPI
  10016. READ_PORT_UCHAR(
  10017. PUCHAR Port
  10018. );
  10019. NTHALAPI
  10020. USHORT
  10021. NTAPI
  10022. READ_PORT_USHORT(
  10023. PUSHORT Port
  10024. );
  10025. NTHALAPI
  10026. ULONG
  10027. NTAPI
  10028. READ_PORT_ULONG(
  10029. PULONG Port
  10030. );
  10031. NTHALAPI
  10032. VOID
  10033. NTAPI
  10034. READ_PORT_BUFFER_UCHAR(
  10035. PUCHAR Port,
  10036. PUCHAR Buffer,
  10037. ULONG Count
  10038. );
  10039. NTHALAPI
  10040. VOID
  10041. NTAPI
  10042. READ_PORT_BUFFER_USHORT(
  10043. PUSHORT Port,
  10044. PUSHORT Buffer,
  10045. ULONG Count
  10046. );
  10047. NTHALAPI
  10048. VOID
  10049. NTAPI
  10050. READ_PORT_BUFFER_ULONG(
  10051. PULONG Port,
  10052. PULONG Buffer,
  10053. ULONG Count
  10054. );
  10055. NTHALAPI
  10056. VOID
  10057. NTAPI
  10058. WRITE_PORT_UCHAR(
  10059. PUCHAR Port,
  10060. UCHAR Value
  10061. );
  10062. NTHALAPI
  10063. VOID
  10064. NTAPI
  10065. WRITE_PORT_USHORT(
  10066. PUSHORT Port,
  10067. USHORT Value
  10068. );
  10069. NTHALAPI
  10070. VOID
  10071. NTAPI
  10072. WRITE_PORT_ULONG(
  10073. PULONG Port,
  10074. ULONG Value
  10075. );
  10076. NTHALAPI
  10077. VOID
  10078. NTAPI
  10079. WRITE_PORT_BUFFER_UCHAR(
  10080. PUCHAR Port,
  10081. PUCHAR Buffer,
  10082. ULONG Count
  10083. );
  10084. NTHALAPI
  10085. VOID
  10086. NTAPI
  10087. WRITE_PORT_BUFFER_USHORT(
  10088. PUSHORT Port,
  10089. PUSHORT Buffer,
  10090. ULONG Count
  10091. );
  10092. NTHALAPI
  10093. VOID
  10094. NTAPI
  10095. WRITE_PORT_BUFFER_ULONG(
  10096. PULONG Port,
  10097. PULONG Buffer,
  10098. ULONG Count
  10099. );
  10100. // end_ntndis
  10101. //
  10102. // Get data cache fill size.
  10103. //
  10104. #if PRAGMA_DEPRECATED_DDK
  10105. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  10106. #endif
  10107. #define KeGetDcacheFillSize() 1L
  10108. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  10109. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  10110. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  10111. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  10112. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  10113. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  10114. // begin_wdm
  10115. #define KeQueryTickCount(CurrentCount ) { \
  10116. volatile PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  10117. while (TRUE) { \
  10118. (CurrentCount)->HighPart = _TickCount->High1Time; \
  10119. (CurrentCount)->LowPart = _TickCount->LowPart; \
  10120. if ((CurrentCount)->HighPart == _TickCount->High2Time) break; \
  10121. _asm { rep nop } \
  10122. } \
  10123. }
  10124. // end_wdm
  10125. #else
  10126. VOID
  10127. NTAPI
  10128. KeQueryTickCount (
  10129. OUT PLARGE_INTEGER CurrentCount
  10130. );
  10131. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  10132. //
  10133. // Processor Control Region Structure Definition
  10134. //
  10135. #define PCR_MINOR_VERSION 1
  10136. #define PCR_MAJOR_VERSION 1
  10137. typedef struct _KPCR {
  10138. //
  10139. // Start of the architecturally defined section of the PCR. This section
  10140. // may be directly addressed by vendor/platform specific HAL code and will
  10141. // not change from version to version of NT.
  10142. //
  10143. NT_TIB NtTib;
  10144. struct _KPCR *SelfPcr; // flat address of this PCR
  10145. struct _KPRCB *Prcb; // pointer to Prcb
  10146. KIRQL Irql;
  10147. ULONG IRR;
  10148. ULONG IrrActive;
  10149. ULONG IDR;
  10150. PVOID KdVersionBlock;
  10151. struct _KIDTENTRY *IDT;
  10152. struct _KGDTENTRY *GDT;
  10153. struct _KTSS *TSS;
  10154. USHORT MajorVersion;
  10155. USHORT MinorVersion;
  10156. KAFFINITY SetMember;
  10157. ULONG StallScaleFactor;
  10158. UCHAR DebugActive;
  10159. UCHAR Number;
  10160. } KPCR, *PKPCR;
  10161. //
  10162. // The non-volatile 387 state
  10163. //
  10164. typedef struct _KFLOATING_SAVE {
  10165. ULONG ControlWord;
  10166. ULONG StatusWord;
  10167. ULONG ErrorOffset;
  10168. ULONG ErrorSelector;
  10169. ULONG DataOffset; // Not used in wdm
  10170. ULONG DataSelector;
  10171. ULONG Cr0NpxState;
  10172. ULONG Spare1; // Not used in wdm
  10173. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  10174. //
  10175. // i386 Specific portions of mm component
  10176. //
  10177. //
  10178. // Define the page size for the Intel 386 as 4096 (0x1000).
  10179. //
  10180. #define PAGE_SIZE 0x1000
  10181. //
  10182. // Define the number of trailing zeroes in a page aligned virtual address.
  10183. // This is used as the shift count when shifting virtual addresses to
  10184. // virtual page numbers.
  10185. //
  10186. #define PAGE_SHIFT 12L
  10187. // end_ntndis end_wdm
  10188. //
  10189. // Define the number of bits to shift to right justify the Page Directory Index
  10190. // field of a PTE.
  10191. //
  10192. #define PDI_SHIFT_X86 22
  10193. #define PDI_SHIFT_X86PAE 21
  10194. #if !defined (_X86PAE_)
  10195. #define PDI_SHIFT PDI_SHIFT_X86
  10196. #else
  10197. #define PDI_SHIFT PDI_SHIFT_X86PAE
  10198. #define PPI_SHIFT 30
  10199. #endif
  10200. //
  10201. // Define the number of bits to shift to right justify the Page Table Index
  10202. // field of a PTE.
  10203. //
  10204. #define PTI_SHIFT 12
  10205. //
  10206. // Define the highest user address and user probe address.
  10207. //
  10208. extern PVOID *MmHighestUserAddress;
  10209. extern PVOID *MmSystemRangeStart;
  10210. extern ULONG *MmUserProbeAddress;
  10211. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  10212. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  10213. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  10214. //
  10215. // The lowest user address reserves the low 64k.
  10216. //
  10217. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  10218. //
  10219. // The lowest address for system space.
  10220. //
  10221. #if !defined (_X86PAE_)
  10222. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  10223. #else
  10224. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
  10225. #endif
  10226. // begin_wdm
  10227. #define MmGetProcedureAddress(Address) (Address)
  10228. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  10229. #define KIP0PCRADDRESS 0xffdff000
  10230. #define KI_USER_SHARED_DATA 0xffdf0000
  10231. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  10232. //
  10233. // Result type definition for i386. (Machine specific enumerate type
  10234. // which is return type for portable exinterlockedincrement/decrement
  10235. // procedures.) In general, you should use the enumerated type defined
  10236. // in ex.h instead of directly referencing these constants.
  10237. //
  10238. // Flags loaded into AH by LAHF instruction
  10239. #define EFLAG_SIGN 0x8000
  10240. #define EFLAG_ZERO 0x4000
  10241. #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
  10242. #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  10243. #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
  10244. #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  10245. //
  10246. // Convert various portable ExInterlock APIs into their architectural
  10247. // equivalents.
  10248. //
  10249. #if PRAGMA_DEPRECATED_DDK
  10250. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  10251. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  10252. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  10253. #endif
  10254. #define ExInterlockedIncrementLong(Addend,Lock) \
  10255. Exfi386InterlockedIncrementLong(Addend)
  10256. #define ExInterlockedDecrementLong(Addend,Lock) \
  10257. Exfi386InterlockedDecrementLong(Addend)
  10258. #define ExInterlockedExchangeUlong(Target,Value,Lock) \
  10259. Exfi386InterlockedExchangeUlong(Target,Value)
  10260. // begin_wdm
  10261. #define ExInterlockedAddUlong ExfInterlockedAddUlong
  10262. #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
  10263. #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
  10264. #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
  10265. #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
  10266. #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
  10267. // end_wdm
  10268. //
  10269. // Prototypes for architectural specific versions of Exi386 Api
  10270. //
  10271. //
  10272. // Interlocked result type is portable, but its values are machine specific.
  10273. // Constants for value are in i386.h, mips.h, etc.
  10274. //
  10275. typedef enum _INTERLOCKED_RESULT {
  10276. ResultNegative = RESULT_NEGATIVE,
  10277. ResultZero = RESULT_ZERO,
  10278. ResultPositive = RESULT_POSITIVE
  10279. } INTERLOCKED_RESULT;
  10280. NTKERNELAPI
  10281. INTERLOCKED_RESULT
  10282. FASTCALL
  10283. Exfi386InterlockedIncrementLong (
  10284. IN PLONG Addend
  10285. );
  10286. NTKERNELAPI
  10287. INTERLOCKED_RESULT
  10288. FASTCALL
  10289. Exfi386InterlockedDecrementLong (
  10290. IN PLONG Addend
  10291. );
  10292. NTKERNELAPI
  10293. ULONG
  10294. FASTCALL
  10295. Exfi386InterlockedExchangeUlong (
  10296. IN PULONG Target,
  10297. IN ULONG Value
  10298. );
  10299. #if !defined(_WINBASE_) && !defined(NONTOSPINTERLOCK)
  10300. #if !defined(MIDL_PASS) // wdm
  10301. #if defined(NO_INTERLOCKED_INTRINSICS) || defined(_CROSS_PLATFORM_)
  10302. // begin_wdm
  10303. NTKERNELAPI
  10304. LONG
  10305. FASTCALL
  10306. InterlockedIncrement(
  10307. IN LONG volatile *Addend
  10308. );
  10309. NTKERNELAPI
  10310. LONG
  10311. FASTCALL
  10312. InterlockedDecrement(
  10313. IN LONG volatile *Addend
  10314. );
  10315. NTKERNELAPI
  10316. LONG
  10317. FASTCALL
  10318. InterlockedExchange(
  10319. IN OUT LONG volatile *Target,
  10320. IN LONG Value
  10321. );
  10322. #define InterlockedExchangePointer(Target, Value) \
  10323. (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value))
  10324. LONG
  10325. FASTCALL
  10326. InterlockedExchangeAdd(
  10327. IN OUT LONG volatile *Addend,
  10328. IN LONG Increment
  10329. );
  10330. NTKERNELAPI
  10331. LONG
  10332. FASTCALL
  10333. InterlockedCompareExchange(
  10334. IN OUT LONG volatile *Destination,
  10335. IN LONG ExChange,
  10336. IN LONG Comperand
  10337. );
  10338. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  10339. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  10340. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  10341. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  10342. NTKERNELAPI
  10343. LONGLONG
  10344. FASTCALL
  10345. ExfInterlockedCompareExchange64(
  10346. IN OUT LONGLONG volatile *Destination,
  10347. IN PLONGLONG ExChange,
  10348. IN PLONGLONG Comperand
  10349. );
  10350. // end_wdm
  10351. #else // NO_INTERLOCKED_INCREMENTS || _CROSS_PLATFORM_
  10352. #define InterlockedExchangePointer(Target, Value) \
  10353. (PVOID)InterlockedExchange((PLONG)Target, (LONG)Value)
  10354. #if (_MSC_FULL_VER > 13009037)
  10355. LONG
  10356. __cdecl
  10357. _InterlockedExchange(
  10358. IN OUT LONG volatile *Target,
  10359. IN LONG Value
  10360. );
  10361. #pragma intrinsic (_InterlockedExchange)
  10362. #define InterlockedExchange _InterlockedExchange
  10363. #else
  10364. FORCEINLINE
  10365. LONG
  10366. FASTCALL
  10367. InterlockedExchange(
  10368. IN OUT LONG volatile *Target,
  10369. IN LONG Value
  10370. )
  10371. {
  10372. __asm {
  10373. mov eax, Value
  10374. mov ecx, Target
  10375. xchg [ecx], eax
  10376. }
  10377. }
  10378. #endif
  10379. #if (_MSC_FULL_VER > 13009037)
  10380. LONG
  10381. __cdecl
  10382. _InterlockedIncrement(
  10383. IN LONG volatile *Addend
  10384. );
  10385. #pragma intrinsic (_InterlockedIncrement)
  10386. #define InterlockedIncrement _InterlockedIncrement
  10387. #else
  10388. #define InterlockedIncrement(Addend) (InterlockedExchangeAdd (Addend, 1)+1)
  10389. #endif
  10390. #if (_MSC_FULL_VER > 13009037)
  10391. LONG
  10392. __cdecl
  10393. _InterlockedDecrement(
  10394. IN LONG volatile *Addend
  10395. );
  10396. #pragma intrinsic (_InterlockedDecrement)
  10397. #define InterlockedDecrement _InterlockedDecrement
  10398. #else
  10399. #define InterlockedDecrement(Addend) (InterlockedExchangeAdd (Addend, -1)-1)
  10400. #endif
  10401. #if (_MSC_FULL_VER > 13009037)
  10402. LONG
  10403. __cdecl
  10404. _InterlockedExchangeAdd(
  10405. IN OUT LONG volatile *Addend,
  10406. IN LONG Increment
  10407. );
  10408. #pragma intrinsic (_InterlockedExchangeAdd)
  10409. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  10410. #else
  10411. // begin_wdm
  10412. FORCEINLINE
  10413. LONG
  10414. FASTCALL
  10415. InterlockedExchangeAdd(
  10416. IN OUT LONG volatile *Addend,
  10417. IN LONG Increment
  10418. )
  10419. {
  10420. __asm {
  10421. mov eax, Increment
  10422. mov ecx, Addend
  10423. lock xadd [ecx], eax
  10424. }
  10425. }
  10426. // end_wdm
  10427. #endif
  10428. #if (_MSC_FULL_VER > 13009037)
  10429. LONG
  10430. __cdecl
  10431. _InterlockedCompareExchange (
  10432. IN OUT LONG volatile *Destination,
  10433. IN LONG ExChange,
  10434. IN LONG Comperand
  10435. );
  10436. #pragma intrinsic (_InterlockedCompareExchange)
  10437. #define InterlockedCompareExchange (LONG)_InterlockedCompareExchange
  10438. #else
  10439. FORCEINLINE
  10440. LONG
  10441. FASTCALL
  10442. InterlockedCompareExchange(
  10443. IN OUT LONG volatile *Destination,
  10444. IN LONG Exchange,
  10445. IN LONG Comperand
  10446. )
  10447. {
  10448. __asm {
  10449. mov eax, Comperand
  10450. mov ecx, Destination
  10451. mov edx, Exchange
  10452. lock cmpxchg [ecx], edx
  10453. }
  10454. }
  10455. #endif
  10456. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  10457. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  10458. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  10459. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  10460. NTKERNELAPI
  10461. LONGLONG
  10462. FASTCALL
  10463. ExfInterlockedCompareExchange64(
  10464. IN OUT LONGLONG volatile *Destination,
  10465. IN PLONGLONG ExChange,
  10466. IN PLONGLONG Comperand
  10467. );
  10468. #endif // INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  10469. // begin_wdm
  10470. #endif // MIDL_PASS
  10471. #endif // __WINBASE__ && !NONTOSPINTERLOCK
  10472. //
  10473. // Turn these instrinsics off until the compiler can handle them
  10474. //
  10475. #if (_MSC_FULL_VER > 13009037)
  10476. LONG
  10477. _InterlockedOr (
  10478. IN OUT PLONG Target,
  10479. IN LONG Set
  10480. );
  10481. #pragma intrinsic (_InterlockedOr)
  10482. #define InterlockedOr _InterlockedOr
  10483. LONG
  10484. _InterlockedAnd (
  10485. IN OUT LONG volatile *Target,
  10486. IN LONG Set
  10487. );
  10488. #pragma intrinsic (_InterlockedAnd)
  10489. #define InterlockedAnd _InterlockedAnd
  10490. LONG
  10491. _InterlockedXor (
  10492. IN OUT LONG volatile Target,
  10493. IN LONG Set
  10494. );
  10495. #pragma intrinsic (_InterlockedXor)
  10496. #define InterlockedXor _InterlockedXor
  10497. #else // compiler version
  10498. FORCEINLINE
  10499. LONG
  10500. InterlockedAnd (
  10501. IN OUT LONG volatile *Target,
  10502. LONG Set
  10503. )
  10504. {
  10505. LONG i;
  10506. LONG j;
  10507. j = *Target;
  10508. do {
  10509. i = j;
  10510. j = InterlockedCompareExchange(Target,
  10511. i & Set,
  10512. i);
  10513. } while (i != j);
  10514. return j;
  10515. }
  10516. FORCEINLINE
  10517. LONG
  10518. InterlockedOr (
  10519. IN OUT LONG volatile *Target,
  10520. IN LONG Set
  10521. )
  10522. {
  10523. LONG i;
  10524. LONG j;
  10525. j = *Target;
  10526. do {
  10527. i = j;
  10528. j = InterlockedCompareExchange(Target,
  10529. i | Set,
  10530. i);
  10531. } while (i != j);
  10532. return j;
  10533. }
  10534. #endif // compiler version
  10535. #if !defined(MIDL_PASS) && defined(_M_IX86)
  10536. //
  10537. // i386 function definitions
  10538. //
  10539. #pragma warning(disable:4035) // re-enable below
  10540. // end_wdm
  10541. #if NT_UP
  10542. #define _PCR ds:[KIP0PCRADDRESS]
  10543. #else
  10544. #define _PCR fs:[0]
  10545. #endif
  10546. //
  10547. // Get current IRQL.
  10548. //
  10549. // On x86 this function resides in the HAL
  10550. //
  10551. NTHALAPI
  10552. KIRQL
  10553. NTAPI
  10554. KeGetCurrentIrql();
  10555. // end_wdm
  10556. //
  10557. // Get the current processor number
  10558. //
  10559. FORCEINLINE
  10560. ULONG
  10561. NTAPI
  10562. KeGetCurrentProcessorNumber(VOID)
  10563. {
  10564. __asm { movzx eax, _PCR KPCR.Number }
  10565. }
  10566. #pragma warning(default:4035)
  10567. // begin_wdm
  10568. #endif // !defined(MIDL_PASS) && defined(_M_IX86)
  10569. NTKERNELAPI
  10570. NTSTATUS
  10571. NTAPI
  10572. KeSaveFloatingPointState (
  10573. OUT PKFLOATING_SAVE FloatSave
  10574. );
  10575. NTKERNELAPI
  10576. NTSTATUS
  10577. NTAPI
  10578. KeRestoreFloatingPointState (
  10579. IN PKFLOATING_SAVE FloatSave
  10580. );
  10581. #endif // defined(_X86_)
  10582. // Use the following for kernel mode runtime checks of X86 system architecture
  10583. #ifdef _X86_
  10584. #ifdef IsNEC_98
  10585. #undef IsNEC_98
  10586. #endif
  10587. #ifdef IsNotNEC_98
  10588. #undef IsNotNEC_98
  10589. #endif
  10590. #ifdef SetNEC_98
  10591. #undef SetNEC_98
  10592. #endif
  10593. #ifdef SetNotNEC_98
  10594. #undef SetNotNEC_98
  10595. #endif
  10596. #define IsNEC_98 (SharedUserData->AlternativeArchitecture == NEC98x86)
  10597. #define IsNotNEC_98 (SharedUserData->AlternativeArchitecture != NEC98x86)
  10598. #define SetNEC_98 SharedUserData->AlternativeArchitecture = NEC98x86
  10599. #define SetNotNEC_98 SharedUserData->AlternativeArchitecture = StandardDesign
  10600. #endif
  10601. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  10602. //
  10603. // Define intrinsic function to do in's and out's.
  10604. //
  10605. #ifdef __cplusplus
  10606. extern "C" {
  10607. #endif
  10608. UCHAR
  10609. __inbyte (
  10610. IN USHORT Port
  10611. );
  10612. USHORT
  10613. __inword (
  10614. IN USHORT Port
  10615. );
  10616. ULONG
  10617. __indword (
  10618. IN USHORT Port
  10619. );
  10620. VOID
  10621. __outbyte (
  10622. IN USHORT Port,
  10623. IN UCHAR Data
  10624. );
  10625. VOID
  10626. __outword (
  10627. IN USHORT Port,
  10628. IN USHORT Data
  10629. );
  10630. VOID
  10631. __outdword (
  10632. IN USHORT Port,
  10633. IN ULONG Data
  10634. );
  10635. VOID
  10636. __inbytestring (
  10637. IN USHORT Port,
  10638. IN PUCHAR Buffer,
  10639. IN ULONG Count
  10640. );
  10641. VOID
  10642. __inwordstring (
  10643. IN USHORT Port,
  10644. IN PUSHORT Buffer,
  10645. IN ULONG Count
  10646. );
  10647. VOID
  10648. __indwordstring (
  10649. IN USHORT Port,
  10650. IN PULONG Buffer,
  10651. IN ULONG Count
  10652. );
  10653. VOID
  10654. __outbytestring (
  10655. IN USHORT Port,
  10656. IN PUCHAR Buffer,
  10657. IN ULONG Count
  10658. );
  10659. VOID
  10660. __outwordstring (
  10661. IN USHORT Port,
  10662. IN PUSHORT Buffer,
  10663. IN ULONG Count
  10664. );
  10665. VOID
  10666. __outdwordstring (
  10667. IN USHORT Port,
  10668. IN PULONG Buffer,
  10669. IN ULONG Count
  10670. );
  10671. #ifdef __cplusplus
  10672. }
  10673. #endif
  10674. #pragma intrinsic(__inbyte)
  10675. #pragma intrinsic(__inword)
  10676. #pragma intrinsic(__indword)
  10677. #pragma intrinsic(__outbyte)
  10678. #pragma intrinsic(__outword)
  10679. #pragma intrinsic(__outdword)
  10680. #pragma intrinsic(__inbytestring)
  10681. #pragma intrinsic(__inwordstring)
  10682. #pragma intrinsic(__indwordstring)
  10683. #pragma intrinsic(__outbytestring)
  10684. #pragma intrinsic(__outwordstring)
  10685. #pragma intrinsic(__outdwordstring)
  10686. //
  10687. // Interlocked intrinsic functions.
  10688. //
  10689. #define InterlockedAnd _InterlockedAnd
  10690. #define InterlockedOr _InterlockedOr
  10691. #define InterlockedXor _InterlockedXor
  10692. #define InterlockedIncrement _InterlockedIncrement
  10693. #define InterlockedDecrement _InterlockedDecrement
  10694. #define InterlockedAdd _InterlockedAdd
  10695. #define InterlockedExchange _InterlockedExchange
  10696. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  10697. #define InterlockedCompareExchange _InterlockedCompareExchange
  10698. #define InterlockedAnd64 _InterlockedAnd64
  10699. #define InterlockedOr64 _InterlockedOr64
  10700. #define InterlockedXor64 _InterlockedXor64
  10701. #define InterlockedIncrement64 _InterlockedIncrement64
  10702. #define InterlockedDecrement64 _InterlockedDecrement64
  10703. #define InterlockedAdd64 _InterlockedAdd64
  10704. #define InterlockedExchange64 _InterlockedExchange64
  10705. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  10706. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  10707. #define InterlockedExchangePointer _InterlockedExchangePointer
  10708. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  10709. #ifdef __cplusplus
  10710. extern "C" {
  10711. #endif
  10712. LONG
  10713. InterlockedAnd (
  10714. IN OUT LONG volatile *Destination,
  10715. IN LONG Value
  10716. );
  10717. LONG
  10718. InterlockedOr (
  10719. IN OUT LONG volatile *Destination,
  10720. IN LONG Value
  10721. );
  10722. LONG
  10723. InterlockedXor (
  10724. IN OUT LONG volatile *Destination,
  10725. IN LONG Value
  10726. );
  10727. LONG64
  10728. InterlockedAnd64 (
  10729. IN OUT LONG64 volatile *Destination,
  10730. IN LONG64 Value
  10731. );
  10732. LONG64
  10733. InterlockedOr64 (
  10734. IN OUT LONG64 volatile *Destination,
  10735. IN LONG64 Value
  10736. );
  10737. LONG64
  10738. InterlockedXor64 (
  10739. IN OUT LONG64 volatile *Destination,
  10740. IN LONG64 Value
  10741. );
  10742. LONG
  10743. InterlockedIncrement(
  10744. IN OUT LONG volatile *Addend
  10745. );
  10746. LONG
  10747. InterlockedDecrement(
  10748. IN OUT LONG volatile *Addend
  10749. );
  10750. LONG
  10751. InterlockedExchange(
  10752. IN OUT LONG volatile *Target,
  10753. IN LONG Value
  10754. );
  10755. LONG
  10756. InterlockedExchangeAdd(
  10757. IN OUT LONG volatile *Addend,
  10758. IN LONG Value
  10759. );
  10760. #if !defined(_X86AMD64_)
  10761. __forceinline
  10762. LONG
  10763. InterlockedAdd(
  10764. IN OUT LONG volatile *Addend,
  10765. IN LONG Value
  10766. )
  10767. {
  10768. return InterlockedExchangeAdd(Addend, Value) + Value;
  10769. }
  10770. #endif
  10771. LONG
  10772. InterlockedCompareExchange (
  10773. IN OUT LONG volatile *Destination,
  10774. IN LONG ExChange,
  10775. IN LONG Comperand
  10776. );
  10777. LONG64
  10778. InterlockedIncrement64(
  10779. IN OUT LONG64 volatile *Addend
  10780. );
  10781. LONG64
  10782. InterlockedDecrement64(
  10783. IN OUT LONG64 volatile *Addend
  10784. );
  10785. LONG64
  10786. InterlockedExchange64(
  10787. IN OUT LONG64 volatile *Target,
  10788. IN LONG64 Value
  10789. );
  10790. LONG64
  10791. InterlockedExchangeAdd64(
  10792. IN OUT LONG64 volatile *Addend,
  10793. IN LONG64 Value
  10794. );
  10795. #if !defined(_X86AMD64_)
  10796. __forceinline
  10797. LONG64
  10798. InterlockedAdd64(
  10799. IN OUT LONG64 volatile *Addend,
  10800. IN LONG64 Value
  10801. )
  10802. {
  10803. return InterlockedExchangeAdd64(Addend, Value) + Value;
  10804. }
  10805. #endif
  10806. LONG64
  10807. InterlockedCompareExchange64 (
  10808. IN OUT LONG64 volatile *Destination,
  10809. IN LONG64 ExChange,
  10810. IN LONG64 Comperand
  10811. );
  10812. PVOID
  10813. InterlockedCompareExchangePointer (
  10814. IN OUT PVOID volatile *Destination,
  10815. IN PVOID Exchange,
  10816. IN PVOID Comperand
  10817. );
  10818. PVOID
  10819. InterlockedExchangePointer(
  10820. IN OUT PVOID volatile *Target,
  10821. IN PVOID Value
  10822. );
  10823. #pragma intrinsic(_InterlockedAnd)
  10824. #pragma intrinsic(_InterlockedOr)
  10825. #pragma intrinsic(_InterlockedXor)
  10826. #pragma intrinsic(_InterlockedIncrement)
  10827. #pragma intrinsic(_InterlockedDecrement)
  10828. #pragma intrinsic(_InterlockedExchange)
  10829. #pragma intrinsic(_InterlockedExchangeAdd)
  10830. #pragma intrinsic(_InterlockedCompareExchange)
  10831. #pragma intrinsic(_InterlockedAnd64)
  10832. #pragma intrinsic(_InterlockedOr64)
  10833. #pragma intrinsic(_InterlockedXor64)
  10834. #pragma intrinsic(_InterlockedIncrement64)
  10835. #pragma intrinsic(_InterlockedDecrement64)
  10836. #pragma intrinsic(_InterlockedExchange64)
  10837. #pragma intrinsic(_InterlockedExchangeAdd64)
  10838. #pragma intrinsic(_InterlockedCompareExchange64)
  10839. #pragma intrinsic(_InterlockedExchangePointer)
  10840. #pragma intrinsic(_InterlockedCompareExchangePointer)
  10841. #ifdef __cplusplus
  10842. }
  10843. #endif
  10844. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  10845. #if defined(_AMD64_)
  10846. //
  10847. // Types to use to contain PFNs and their counts.
  10848. //
  10849. typedef ULONG PFN_COUNT;
  10850. typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
  10851. typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
  10852. //
  10853. // Define maximum size of flush multiple TB request.
  10854. //
  10855. #define FLUSH_MULTIPLE_MAXIMUM 16
  10856. //
  10857. // Indicate that the AMD64 compiler supports the allocate pragmas.
  10858. //
  10859. #define ALLOC_PRAGMA 1
  10860. #define ALLOC_DATA_PRAGMA 1
  10861. #define NORMAL_DISPATCH_LENGTH 106
  10862. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  10863. //
  10864. // Interrupt Request Level definitions
  10865. //
  10866. #define PASSIVE_LEVEL 0 // Passive release level
  10867. #define LOW_LEVEL 0 // Lowest interrupt level
  10868. #define APC_LEVEL 1 // APC interrupt level
  10869. #define DISPATCH_LEVEL 2 // Dispatcher level
  10870. #define CLOCK_LEVEL 13 // Interval clock level
  10871. #define IPI_LEVEL 14 // Interprocessor interrupt level
  10872. #define POWER_LEVEL 14 // Power failure level
  10873. #define PROFILE_LEVEL 15 // timer used for profiling.
  10874. #define HIGH_LEVEL 15 // Highest interrupt level
  10875. #if defined(NT_UP)
  10876. #define SYNCH_LEVEL DISPATCH_LEVEL // synchronization level
  10877. #else
  10878. #define SYNCH_LEVEL (IPI_LEVEL - 1) // synchronization level
  10879. #endif
  10880. #define IRQL_VECTOR_OFFSET 2 // offset from IRQL to vector / 16
  10881. //
  10882. // I/O space read and write macros.
  10883. //
  10884. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  10885. // (Use move instructions, with LOCK prefix to force correct behavior
  10886. // w.r.t. caches and write buffers.)
  10887. //
  10888. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  10889. // (Use in/out instructions.)
  10890. //
  10891. __forceinline
  10892. UCHAR
  10893. READ_REGISTER_UCHAR (
  10894. volatile UCHAR *Register
  10895. )
  10896. {
  10897. return *Register;
  10898. }
  10899. __forceinline
  10900. USHORT
  10901. READ_REGISTER_USHORT (
  10902. volatile USHORT *Register
  10903. )
  10904. {
  10905. return *Register;
  10906. }
  10907. __forceinline
  10908. ULONG
  10909. READ_REGISTER_ULONG (
  10910. volatile ULONG *Register
  10911. )
  10912. {
  10913. return *Register;
  10914. }
  10915. __forceinline
  10916. VOID
  10917. READ_REGISTER_BUFFER_UCHAR (
  10918. PUCHAR Register,
  10919. PUCHAR Buffer,
  10920. ULONG Count
  10921. )
  10922. {
  10923. __movsb(Register, Buffer, Count);
  10924. return;
  10925. }
  10926. __forceinline
  10927. VOID
  10928. READ_REGISTER_BUFFER_USHORT (
  10929. PUSHORT Register,
  10930. PUSHORT Buffer,
  10931. ULONG Count
  10932. )
  10933. {
  10934. __movsw(Register, Buffer, Count);
  10935. return;
  10936. }
  10937. __forceinline
  10938. VOID
  10939. READ_REGISTER_BUFFER_ULONG (
  10940. PULONG Register,
  10941. PULONG Buffer,
  10942. ULONG Count
  10943. )
  10944. {
  10945. __movsd(Register, Buffer, Count);
  10946. return;
  10947. }
  10948. __forceinline
  10949. VOID
  10950. WRITE_REGISTER_UCHAR (
  10951. PUCHAR Register,
  10952. UCHAR Value
  10953. )
  10954. {
  10955. LONG Synch;
  10956. *Register = Value;
  10957. InterlockedOr(&Synch, 1);
  10958. return;
  10959. }
  10960. __forceinline
  10961. VOID
  10962. WRITE_REGISTER_USHORT (
  10963. PUSHORT Register,
  10964. USHORT Value
  10965. )
  10966. {
  10967. LONG Synch;
  10968. *Register = Value;
  10969. InterlockedOr(&Synch, 1);
  10970. return;
  10971. }
  10972. __forceinline
  10973. VOID
  10974. WRITE_REGISTER_ULONG (
  10975. PULONG Register,
  10976. ULONG Value
  10977. )
  10978. {
  10979. LONG Synch;
  10980. *Register = Value;
  10981. InterlockedOr(&Synch, 1);
  10982. return;
  10983. }
  10984. __forceinline
  10985. VOID
  10986. WRITE_REGISTER_BUFFER_UCHAR (
  10987. PUCHAR Register,
  10988. PUCHAR Buffer,
  10989. ULONG Count
  10990. )
  10991. {
  10992. LONG Synch;
  10993. __movsb(Register, Buffer, Count);
  10994. InterlockedOr(&Synch, 1);
  10995. return;
  10996. }
  10997. __forceinline
  10998. VOID
  10999. WRITE_REGISTER_BUFFER_USHORT (
  11000. PUSHORT Register,
  11001. PUSHORT Buffer,
  11002. ULONG Count
  11003. )
  11004. {
  11005. LONG Synch;
  11006. __movsw(Register, Buffer, Count);
  11007. InterlockedOr(&Synch, 1);
  11008. return;
  11009. }
  11010. __forceinline
  11011. VOID
  11012. WRITE_REGISTER_BUFFER_ULONG (
  11013. PULONG Register,
  11014. PULONG Buffer,
  11015. ULONG Count
  11016. )
  11017. {
  11018. LONG Synch;
  11019. __movsd(Register, Buffer, Count);
  11020. InterlockedOr(&Synch, 1);
  11021. return;
  11022. }
  11023. __forceinline
  11024. UCHAR
  11025. READ_PORT_UCHAR (
  11026. PUCHAR Port
  11027. )
  11028. {
  11029. return __inbyte((USHORT)((ULONG64)Port));
  11030. }
  11031. __forceinline
  11032. USHORT
  11033. READ_PORT_USHORT (
  11034. PUSHORT Port
  11035. )
  11036. {
  11037. return __inword((USHORT)((ULONG64)Port));
  11038. }
  11039. __forceinline
  11040. ULONG
  11041. READ_PORT_ULONG (
  11042. PULONG Port
  11043. )
  11044. {
  11045. return __indword((USHORT)((ULONG64)Port));
  11046. }
  11047. __forceinline
  11048. VOID
  11049. READ_PORT_BUFFER_UCHAR (
  11050. PUCHAR Port,
  11051. PUCHAR Buffer,
  11052. ULONG Count
  11053. )
  11054. {
  11055. __inbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  11056. return;
  11057. }
  11058. __forceinline
  11059. VOID
  11060. READ_PORT_BUFFER_USHORT (
  11061. PUSHORT Port,
  11062. PUSHORT Buffer,
  11063. ULONG Count
  11064. )
  11065. {
  11066. __inwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  11067. return;
  11068. }
  11069. __forceinline
  11070. VOID
  11071. READ_PORT_BUFFER_ULONG (
  11072. PULONG Port,
  11073. PULONG Buffer,
  11074. ULONG Count
  11075. )
  11076. {
  11077. __indwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  11078. return;
  11079. }
  11080. __forceinline
  11081. VOID
  11082. WRITE_PORT_UCHAR (
  11083. PUCHAR Port,
  11084. UCHAR Value
  11085. )
  11086. {
  11087. __outbyte((USHORT)((ULONG64)Port), Value);
  11088. return;
  11089. }
  11090. __forceinline
  11091. VOID
  11092. WRITE_PORT_USHORT (
  11093. PUSHORT Port,
  11094. USHORT Value
  11095. )
  11096. {
  11097. __outword((USHORT)((ULONG64)Port), Value);
  11098. return;
  11099. }
  11100. __forceinline
  11101. VOID
  11102. WRITE_PORT_ULONG (
  11103. PULONG Port,
  11104. ULONG Value
  11105. )
  11106. {
  11107. __outdword((USHORT)((ULONG64)Port), Value);
  11108. return;
  11109. }
  11110. __forceinline
  11111. VOID
  11112. WRITE_PORT_BUFFER_UCHAR (
  11113. PUCHAR Port,
  11114. PUCHAR Buffer,
  11115. ULONG Count
  11116. )
  11117. {
  11118. __outbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  11119. return;
  11120. }
  11121. __forceinline
  11122. VOID
  11123. WRITE_PORT_BUFFER_USHORT (
  11124. PUSHORT Port,
  11125. PUSHORT Buffer,
  11126. ULONG Count
  11127. )
  11128. {
  11129. __outwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  11130. return;
  11131. }
  11132. __forceinline
  11133. VOID
  11134. WRITE_PORT_BUFFER_ULONG (
  11135. PULONG Port,
  11136. PULONG Buffer,
  11137. ULONG Count
  11138. )
  11139. {
  11140. __outdwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  11141. return;
  11142. }
  11143. // end_ntndis
  11144. //
  11145. // Get data cache fill size.
  11146. //
  11147. #if PRAGMA_DEPRECATED_DDK
  11148. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  11149. #endif
  11150. #define KeGetDcacheFillSize() 1L
  11151. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  11152. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  11153. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  11154. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  11155. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  11156. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  11157. // begin_wdm
  11158. #define KeQueryTickCount(CurrentCount ) \
  11159. *(PULONG64)(CurrentCount) = **((volatile ULONG64 **)(&KeTickCount));
  11160. // end_wdm
  11161. #else
  11162. VOID
  11163. KeQueryTickCount (
  11164. OUT PLARGE_INTEGER CurrentCount
  11165. );
  11166. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  11167. //
  11168. // Processor Control Region Structure Definition
  11169. //
  11170. #define PCR_MINOR_VERSION 1
  11171. #define PCR_MAJOR_VERSION 1
  11172. typedef struct _KPCR {
  11173. //
  11174. // Start of the architecturally defined section of the PCR. This section
  11175. // may be directly addressed by vendor/platform specific HAL code and will
  11176. // not change from version to version of NT.
  11177. //
  11178. NT_TIB NtTib;
  11179. struct _KPRCB *CurrentPrcb;
  11180. ULONG64 SavedRcx;
  11181. ULONG64 SavedR11;
  11182. KIRQL Irql;
  11183. UCHAR SecondLevelCacheAssociativity;
  11184. UCHAR Number;
  11185. UCHAR Fill0;
  11186. ULONG Irr;
  11187. ULONG IrrActive;
  11188. ULONG Idr;
  11189. USHORT MajorVersion;
  11190. USHORT MinorVersion;
  11191. ULONG StallScaleFactor;
  11192. union _KIDTENTRY64 *IdtBase;
  11193. union _KGDTENTRY64 *GdtBase;
  11194. struct _KTSS64 *TssBase;
  11195. } KPCR, *PKPCR;
  11196. //
  11197. // The nonvolatile floating state
  11198. //
  11199. typedef struct _KFLOATING_SAVE {
  11200. ULONG MxCsr;
  11201. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  11202. //
  11203. // AMD64 Specific portions of mm component.
  11204. //
  11205. // Define the page size for the AMD64 as 4096 (0x1000).
  11206. //
  11207. #define PAGE_SIZE 0x1000
  11208. //
  11209. // Define the number of trailing zeroes in a page aligned virtual address.
  11210. // This is used as the shift count when shifting virtual addresses to
  11211. // virtual page numbers.
  11212. //
  11213. #define PAGE_SHIFT 12L
  11214. // end_ntndis end_wdm
  11215. #define PXE_BASE 0xFFFFF6FB7DBED000UI64
  11216. #define PXE_SELFMAP 0xFFFFF6FB7DBEDF68UI64
  11217. #define PPE_BASE 0xFFFFF6FB7DA00000UI64
  11218. #define PDE_BASE 0xFFFFF6FB40000000UI64
  11219. #define PTE_BASE 0xFFFFF68000000000UI64
  11220. #define PXE_TOP 0xFFFFF6FB7DBEDFFFUI64
  11221. #define PPE_TOP 0xFFFFF6FB7DBFFFFFUI64
  11222. #define PDE_TOP 0xFFFFF6FB7FFFFFFFUI64
  11223. #define PTE_TOP 0xFFFFF6FFFFFFFFFFUI64
  11224. #define PDE_KTBASE_AMD64 PPE_BASE
  11225. #define PTI_SHIFT 12
  11226. #define PDI_SHIFT 21
  11227. #define PPI_SHIFT 30
  11228. #define PXI_SHIFT 39
  11229. #define PTE_PER_PAGE 512
  11230. #define PDE_PER_PAGE 512
  11231. #define PPE_PER_PAGE 512
  11232. #define PXE_PER_PAGE 512
  11233. #define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
  11234. #define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
  11235. #define PPI_MASK (PPE_PER_PAGE - 1)
  11236. #define PXI_MASK (PXE_PER_PAGE - 1)
  11237. //
  11238. // Define the highest user address and user probe address.
  11239. //
  11240. extern PVOID *MmHighestUserAddress;
  11241. extern PVOID *MmSystemRangeStart;
  11242. extern ULONG64 *MmUserProbeAddress;
  11243. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  11244. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  11245. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  11246. //
  11247. // The lowest user address reserves the low 64k.
  11248. //
  11249. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  11250. //
  11251. // The lowest address for system space.
  11252. //
  11253. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000
  11254. // begin_wdm
  11255. #define MmGetProcedureAddress(Address) (Address)
  11256. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  11257. #define KI_USER_SHARED_DATA 0xFFFFF78000000000UI64
  11258. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  11259. //
  11260. // Intrinsic functions
  11261. //
  11262. // begin_wdm
  11263. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  11264. // end_wdm
  11265. //
  11266. // The following routines are provided for backward compatibility with old
  11267. // code. They are no longer the preferred way to accomplish these functions.
  11268. //
  11269. #if PRAGMA_DEPRECATED_DDK
  11270. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  11271. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  11272. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  11273. #endif
  11274. #define RESULT_ZERO 0
  11275. #define RESULT_NEGATIVE 1
  11276. #define RESULT_POSITIVE 2
  11277. typedef enum _INTERLOCKED_RESULT {
  11278. ResultNegative = RESULT_NEGATIVE,
  11279. ResultZero = RESULT_ZERO,
  11280. ResultPositive = RESULT_POSITIVE
  11281. } INTERLOCKED_RESULT;
  11282. #define ExInterlockedDecrementLong(Addend, Lock) \
  11283. _ExInterlockedDecrementLong(Addend)
  11284. __forceinline
  11285. LONG
  11286. _ExInterlockedDecrementLong (
  11287. IN OUT PLONG Addend
  11288. )
  11289. {
  11290. LONG Result;
  11291. Result = InterlockedDecrement(Addend);
  11292. if (Result < 0) {
  11293. return ResultNegative;
  11294. } else if (Result > 0) {
  11295. return ResultPositive;
  11296. } else {
  11297. return ResultZero;
  11298. }
  11299. }
  11300. #define ExInterlockedIncrementLong(Addend, Lock) \
  11301. _ExInterlockedIncrementLong(Addend)
  11302. __forceinline
  11303. LONG
  11304. _ExInterlockedIncrementLong (
  11305. IN OUT PLONG Addend
  11306. )
  11307. {
  11308. LONG Result;
  11309. Result = InterlockedIncrement(Addend);
  11310. if (Result < 0) {
  11311. return ResultNegative;
  11312. } else if (Result > 0) {
  11313. return ResultPositive;
  11314. } else {
  11315. return ResultZero;
  11316. }
  11317. }
  11318. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  11319. _ExInterlockedExchangeUlong(Target, Value)
  11320. __forceinline
  11321. _ExInterlockedExchangeUlong (
  11322. IN OUT PULONG Target,
  11323. IN ULONG Value
  11324. )
  11325. {
  11326. return (ULONG)InterlockedExchange((PLONG)Target, (LONG)Value);
  11327. }
  11328. // begin_wdm
  11329. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  11330. #if !defined(MIDL_PASS) && defined(_M_AMD64)
  11331. //
  11332. // AMD646 function prototype definitions
  11333. //
  11334. // end_wdm
  11335. //
  11336. // Get the current processor number
  11337. //
  11338. __forceinline
  11339. ULONG
  11340. KeGetCurrentProcessorNumber (
  11341. VOID
  11342. )
  11343. {
  11344. return (ULONG)__readgsbyte(FIELD_OFFSET(KPCR, Number));
  11345. }
  11346. // begin_wdm
  11347. #endif // !defined(MIDL_PASS) && defined(_M_AMD64)
  11348. NTKERNELAPI
  11349. NTSTATUS
  11350. KeSaveFloatingPointState (
  11351. OUT PKFLOATING_SAVE SaveArea
  11352. );
  11353. NTKERNELAPI
  11354. NTSTATUS
  11355. KeRestoreFloatingPointState (
  11356. IN PKFLOATING_SAVE SaveArea
  11357. );
  11358. #endif // defined(_AMD64_)
  11359. #if defined(_AMD64_)
  11360. NTKERNELAPI
  11361. KIRQL
  11362. KeGetCurrentIrql (
  11363. VOID
  11364. );
  11365. NTKERNELAPI
  11366. VOID
  11367. KeLowerIrql (
  11368. IN KIRQL NewIrql
  11369. );
  11370. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  11371. NTKERNELAPI
  11372. KIRQL
  11373. KfRaiseIrql (
  11374. IN KIRQL NewIrql
  11375. );
  11376. // end_wdm
  11377. NTKERNELAPI
  11378. KIRQL
  11379. KeRaiseIrqlToDpcLevel (
  11380. VOID
  11381. );
  11382. NTKERNELAPI
  11383. KIRQL
  11384. KeRaiseIrqlToSynchLevel (
  11385. VOID
  11386. );
  11387. // begin_wdm
  11388. #endif // defined(_AMD64_)
  11389. #if defined(_IA64_)
  11390. //
  11391. // Types to use to contain PFNs and their counts.
  11392. //
  11393. typedef ULONG PFN_COUNT;
  11394. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  11395. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  11396. //
  11397. // Define maximum size of flush multiple TB request.
  11398. //
  11399. #define FLUSH_MULTIPLE_MAXIMUM 100
  11400. //
  11401. // Indicate that the IA64 compiler supports the pragma textout construct.
  11402. //
  11403. #define ALLOC_PRAGMA 1
  11404. //
  11405. // Define intrinsic calls and their prototypes
  11406. //
  11407. #include "ia64reg.h"
  11408. #ifdef __cplusplus
  11409. extern "C" {
  11410. #endif
  11411. unsigned __int64 __getReg (int);
  11412. void __setReg (int, unsigned __int64);
  11413. void __isrlz (void);
  11414. void __dsrlz (void);
  11415. void __fwb (void);
  11416. void __mf (void);
  11417. void __mfa (void);
  11418. void __synci (void);
  11419. __int64 __thash (__int64);
  11420. __int64 __ttag (__int64);
  11421. void __ptcl (__int64, __int64);
  11422. void __ptcg (__int64, __int64);
  11423. void __ptcga (__int64, __int64);
  11424. void __ptri (__int64, __int64);
  11425. void __ptrd (__int64, __int64);
  11426. void __invalat (void);
  11427. void __break (int);
  11428. void __fc (__int64);
  11429. void __sum (int);
  11430. void __rsm (int);
  11431. void _ReleaseSpinLock( unsigned __int64 *);
  11432. #ifdef _M_IA64
  11433. #pragma intrinsic (__getReg)
  11434. #pragma intrinsic (__setReg)
  11435. #pragma intrinsic (__isrlz)
  11436. #pragma intrinsic (__dsrlz)
  11437. #pragma intrinsic (__fwb)
  11438. #pragma intrinsic (__mf)
  11439. #pragma intrinsic (__mfa)
  11440. #pragma intrinsic (__synci)
  11441. #pragma intrinsic (__thash)
  11442. #pragma intrinsic (__ttag)
  11443. #pragma intrinsic (__ptcl)
  11444. #pragma intrinsic (__ptcg)
  11445. #pragma intrinsic (__ptcga)
  11446. #pragma intrinsic (__ptri)
  11447. #pragma intrinsic (__ptrd)
  11448. #pragma intrinsic (__invalat)
  11449. #pragma intrinsic (__break)
  11450. #pragma intrinsic (__fc)
  11451. #pragma intrinsic (__sum)
  11452. #pragma intrinsic (__rsm)
  11453. #pragma intrinsic (_ReleaseSpinLock)
  11454. #endif // _M_IA64
  11455. #ifdef __cplusplus
  11456. }
  11457. #endif
  11458. // end_wdm end_ntndis
  11459. //
  11460. // Define macro to generate import names.
  11461. //
  11462. #define IMPORT_NAME(name) __imp_##name
  11463. // begin_wdm
  11464. //
  11465. // Define length of interrupt vector table.
  11466. //
  11467. #define MAXIMUM_VECTOR 256
  11468. // end_wdm
  11469. //
  11470. // IA64 specific interlocked operation result values.
  11471. //
  11472. #define RESULT_ZERO 0
  11473. #define RESULT_NEGATIVE 1
  11474. #define RESULT_POSITIVE 2
  11475. //
  11476. // Interlocked result type is portable, but its values are machine specific.
  11477. // Constants for values are in i386.h, mips.h, etc.
  11478. //
  11479. typedef enum _INTERLOCKED_RESULT {
  11480. ResultNegative = RESULT_NEGATIVE,
  11481. ResultZero = RESULT_ZERO,
  11482. ResultPositive = RESULT_POSITIVE
  11483. } INTERLOCKED_RESULT;
  11484. //
  11485. // Convert portable interlock interfaces to architecture specific interfaces.
  11486. //
  11487. #if PRAGMA_DEPRECATED_DDK
  11488. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  11489. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  11490. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  11491. #endif
  11492. #define ExInterlockedIncrementLong(Addend, Lock) \
  11493. ExIa64InterlockedIncrementLong(Addend)
  11494. #define ExInterlockedDecrementLong(Addend, Lock) \
  11495. ExIa64InterlockedDecrementLong(Addend)
  11496. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  11497. ExIa64InterlockedExchangeUlong(Target, Value)
  11498. NTKERNELAPI
  11499. INTERLOCKED_RESULT
  11500. ExIa64InterlockedIncrementLong (
  11501. IN PLONG Addend
  11502. );
  11503. NTKERNELAPI
  11504. INTERLOCKED_RESULT
  11505. ExIa64InterlockedDecrementLong (
  11506. IN PLONG Addend
  11507. );
  11508. NTKERNELAPI
  11509. ULONG
  11510. ExIa64InterlockedExchangeUlong (
  11511. IN PULONG Target,
  11512. IN ULONG Value
  11513. );
  11514. // begin_wdm
  11515. //
  11516. // IA64 Interrupt Definitions.
  11517. //
  11518. // Define length of interrupt object dispatch code in longwords.
  11519. //
  11520. #define DISPATCH_LENGTH 2*2 // Length of dispatch code template in 32-bit words
  11521. //
  11522. // Begin of a block of definitions that must be synchronized with kxia64.h.
  11523. //
  11524. //
  11525. // Define Interrupt Request Levels.
  11526. //
  11527. #define PASSIVE_LEVEL 0 // Passive release level
  11528. #define LOW_LEVEL 0 // Lowest interrupt level
  11529. #define APC_LEVEL 1 // APC interrupt level
  11530. #define DISPATCH_LEVEL 2 // Dispatcher level
  11531. #define CMC_LEVEL 3 // Correctable machine check level
  11532. #define DEVICE_LEVEL_BASE 4 // 4 - 11 - Device IRQLs
  11533. #define PC_LEVEL 12 // Performance Counter IRQL
  11534. #define IPI_LEVEL 14 // IPI IRQL
  11535. #define CLOCK_LEVEL 13 // Clock Timer IRQL
  11536. #define POWER_LEVEL 15 // Power failure level
  11537. #define PROFILE_LEVEL 15 // Profiling level
  11538. #define HIGH_LEVEL 15 // Highest interrupt level
  11539. #if defined(NT_UP)
  11540. #define SYNCH_LEVEL DISPATCH_LEVEL // Synchronization level - UP
  11541. #else
  11542. #define SYNCH_LEVEL (IPI_LEVEL-1) // Synchronization level - MP
  11543. #endif
  11544. //
  11545. // The current IRQL is maintained in the TPR.mic field. The
  11546. // shift count is the number of bits to shift right to extract the
  11547. // IRQL from the TPR. See the GET/SET_IRQL macros.
  11548. //
  11549. #define TPR_MIC 4
  11550. #define TPR_IRQL_SHIFT TPR_MIC
  11551. // To go from vector number <-> IRQL we just do a shift
  11552. #define VECTOR_IRQL_SHIFT TPR_IRQL_SHIFT
  11553. //
  11554. // Interrupt Vector Definitions
  11555. //
  11556. #define APC_VECTOR APC_LEVEL << VECTOR_IRQL_SHIFT
  11557. #define DISPATCH_VECTOR DISPATCH_LEVEL << VECTOR_IRQL_SHIFT
  11558. //
  11559. // End of a block of definitions that must be synchronized with kxia64.h.
  11560. //
  11561. //
  11562. // Define profile intervals.
  11563. //
  11564. #define DEFAULT_PROFILE_COUNT 0x40000000 // ~= 20 seconds @50mhz
  11565. #define DEFAULT_PROFILE_INTERVAL (10 * 500) // 500 microseconds
  11566. #define MAXIMUM_PROFILE_INTERVAL (10 * 1000 * 1000) // 1 second
  11567. #define MINIMUM_PROFILE_INTERVAL (10 * 40) // 40 microseconds
  11568. #if defined(_M_IA64) && !defined(RC_INVOKED)
  11569. #define InterlockedAdd _InterlockedAdd
  11570. #define InterlockedIncrement _InterlockedIncrement
  11571. #define InterlockedDecrement _InterlockedDecrement
  11572. #define InterlockedExchange _InterlockedExchange
  11573. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  11574. #define InterlockedAdd64 _InterlockedAdd64
  11575. #define InterlockedIncrement64 _InterlockedIncrement64
  11576. #define InterlockedDecrement64 _InterlockedDecrement64
  11577. #define InterlockedExchange64 _InterlockedExchange64
  11578. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  11579. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  11580. #define InterlockedCompareExchange _InterlockedCompareExchange
  11581. #define InterlockedExchangePointer _InterlockedExchangePointer
  11582. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  11583. #ifdef __cplusplus
  11584. extern "C" {
  11585. #endif
  11586. LONG
  11587. __cdecl
  11588. InterlockedAdd (
  11589. LONG volatile *Addend,
  11590. LONG Value
  11591. );
  11592. LONGLONG
  11593. __cdecl
  11594. InterlockedAdd64 (
  11595. LONGLONG volatile *Addend,
  11596. LONGLONG Value
  11597. );
  11598. LONG
  11599. __cdecl
  11600. InterlockedIncrement(
  11601. IN OUT LONG volatile *Addend
  11602. );
  11603. LONG
  11604. __cdecl
  11605. InterlockedDecrement(
  11606. IN OUT LONG volatile *Addend
  11607. );
  11608. LONG
  11609. __cdecl
  11610. InterlockedExchange(
  11611. IN OUT LONG volatile *Target,
  11612. IN LONG Value
  11613. );
  11614. LONG
  11615. __cdecl
  11616. InterlockedExchangeAdd(
  11617. IN OUT LONG volatile *Addend,
  11618. IN LONG Value
  11619. );
  11620. LONG
  11621. __cdecl
  11622. InterlockedCompareExchange (
  11623. IN OUT LONG volatile *Destination,
  11624. IN LONG ExChange,
  11625. IN LONG Comperand
  11626. );
  11627. LONGLONG
  11628. __cdecl
  11629. InterlockedIncrement64(
  11630. IN OUT LONGLONG volatile *Addend
  11631. );
  11632. LONGLONG
  11633. __cdecl
  11634. InterlockedDecrement64(
  11635. IN OUT LONGLONG volatile *Addend
  11636. );
  11637. LONGLONG
  11638. __cdecl
  11639. InterlockedExchange64(
  11640. IN OUT LONGLONG volatile *Target,
  11641. IN LONGLONG Value
  11642. );
  11643. LONGLONG
  11644. __cdecl
  11645. InterlockedExchangeAdd64(
  11646. IN OUT LONGLONG volatile *Addend,
  11647. IN LONGLONG Value
  11648. );
  11649. LONGLONG
  11650. __cdecl
  11651. InterlockedCompareExchange64 (
  11652. IN OUT LONGLONG volatile *Destination,
  11653. IN LONGLONG ExChange,
  11654. IN LONGLONG Comperand
  11655. );
  11656. PVOID
  11657. __cdecl
  11658. InterlockedCompareExchangePointer (
  11659. IN OUT PVOID volatile *Destination,
  11660. IN PVOID Exchange,
  11661. IN PVOID Comperand
  11662. );
  11663. PVOID
  11664. __cdecl
  11665. InterlockedExchangePointer(
  11666. IN OUT PVOID volatile *Target,
  11667. IN PVOID Value
  11668. );
  11669. #pragma intrinsic(_InterlockedAdd)
  11670. #pragma intrinsic(_InterlockedIncrement)
  11671. #pragma intrinsic(_InterlockedDecrement)
  11672. #pragma intrinsic(_InterlockedExchange)
  11673. #pragma intrinsic(_InterlockedCompareExchange)
  11674. #pragma intrinsic(_InterlockedExchangeAdd)
  11675. #pragma intrinsic(_InterlockedAdd64)
  11676. #pragma intrinsic(_InterlockedIncrement64)
  11677. #pragma intrinsic(_InterlockedDecrement64)
  11678. #pragma intrinsic(_InterlockedExchange64)
  11679. #pragma intrinsic(_InterlockedCompareExchange64)
  11680. #pragma intrinsic(_InterlockedExchangeAdd64)
  11681. #pragma intrinsic(_InterlockedExchangePointer)
  11682. #pragma intrinsic(_InterlockedCompareExchangePointer)
  11683. #ifdef __cplusplus
  11684. }
  11685. #endif
  11686. #endif // defined(_M_IA64) && !defined(RC_INVOKED)
  11687. __inline
  11688. LONG
  11689. InterlockedAnd (
  11690. IN OUT LONG volatile *Target,
  11691. LONG Set
  11692. )
  11693. {
  11694. LONG i;
  11695. LONG j;
  11696. j = *Target;
  11697. do {
  11698. i = j;
  11699. j = InterlockedCompareExchange(Target,
  11700. i & Set,
  11701. i);
  11702. } while (i != j);
  11703. return j;
  11704. }
  11705. __inline
  11706. LONG
  11707. InterlockedOr (
  11708. IN OUT LONG volatile *Target,
  11709. IN LONG Set
  11710. )
  11711. {
  11712. LONG i;
  11713. LONG j;
  11714. j = *Target;
  11715. do {
  11716. i = j;
  11717. j = InterlockedCompareExchange(Target,
  11718. i | Set,
  11719. i);
  11720. } while (i != j);
  11721. return j;
  11722. }
  11723. #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
  11724. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  11725. //
  11726. // Prototype for get current IRQL. **** TBD (read TPR)
  11727. //
  11728. NTKERNELAPI
  11729. KIRQL
  11730. KeGetCurrentIrql();
  11731. // end_wdm
  11732. //
  11733. // Get address of current processor block.
  11734. //
  11735. #define KeGetCurrentPrcb() PCR->Prcb
  11736. //
  11737. // Get address of processor control region.
  11738. //
  11739. #define KeGetPcr() PCR
  11740. //
  11741. // Get address of current kernel thread object.
  11742. //
  11743. #if defined(_M_IA64)
  11744. #define KeGetCurrentThread() PCR->CurrentThread
  11745. #endif
  11746. //
  11747. // Get current processor number.
  11748. //
  11749. #define KeGetCurrentProcessorNumber() PCR->Number
  11750. //
  11751. // Get data cache fill size.
  11752. //
  11753. #if PRAGMA_DEPRECATED_DDK
  11754. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  11755. #endif
  11756. #define KeGetDcacheFillSize() PCR->DcacheFillSize
  11757. #define KeSaveFloatingPointState(a) STATUS_SUCCESS
  11758. #define KeRestoreFloatingPointState(a) STATUS_SUCCESS
  11759. //
  11760. // Define the page size
  11761. //
  11762. #define PAGE_SIZE 0x2000
  11763. //
  11764. // Define the number of trailing zeroes in a page aligned virtual address.
  11765. // This is used as the shift count when shifting virtual addresses to
  11766. // virtual page numbers.
  11767. //
  11768. #define PAGE_SHIFT 13L
  11769. //
  11770. // Cache and write buffer flush functions.
  11771. //
  11772. NTKERNELAPI
  11773. VOID
  11774. KeFlushIoBuffers (
  11775. IN PMDL Mdl,
  11776. IN BOOLEAN ReadOperation,
  11777. IN BOOLEAN DmaOperation
  11778. );
  11779. //
  11780. // Kernel breakin breakpoint
  11781. //
  11782. VOID
  11783. KeBreakinBreakpoint (
  11784. VOID
  11785. );
  11786. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  11787. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  11788. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  11789. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  11790. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  11791. // begin_wdm
  11792. #define KeQueryTickCount(CurrentCount ) \
  11793. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  11794. // end_wdm
  11795. #else
  11796. NTKERNELAPI
  11797. VOID
  11798. KeQueryTickCount (
  11799. OUT PLARGE_INTEGER CurrentCount
  11800. );
  11801. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  11802. //
  11803. // I/O space read and write macros.
  11804. //
  11805. NTHALAPI
  11806. UCHAR
  11807. READ_PORT_UCHAR (
  11808. PUCHAR RegisterAddress
  11809. );
  11810. NTHALAPI
  11811. USHORT
  11812. READ_PORT_USHORT (
  11813. PUSHORT RegisterAddress
  11814. );
  11815. NTHALAPI
  11816. ULONG
  11817. READ_PORT_ULONG (
  11818. PULONG RegisterAddress
  11819. );
  11820. NTHALAPI
  11821. VOID
  11822. READ_PORT_BUFFER_UCHAR (
  11823. PUCHAR portAddress,
  11824. PUCHAR readBuffer,
  11825. ULONG readCount
  11826. );
  11827. NTHALAPI
  11828. VOID
  11829. READ_PORT_BUFFER_USHORT (
  11830. PUSHORT portAddress,
  11831. PUSHORT readBuffer,
  11832. ULONG readCount
  11833. );
  11834. NTHALAPI
  11835. VOID
  11836. READ_PORT_BUFFER_ULONG (
  11837. PULONG portAddress,
  11838. PULONG readBuffer,
  11839. ULONG readCount
  11840. );
  11841. NTHALAPI
  11842. VOID
  11843. WRITE_PORT_UCHAR (
  11844. PUCHAR portAddress,
  11845. UCHAR Data
  11846. );
  11847. NTHALAPI
  11848. VOID
  11849. WRITE_PORT_USHORT (
  11850. PUSHORT portAddress,
  11851. USHORT Data
  11852. );
  11853. NTHALAPI
  11854. VOID
  11855. WRITE_PORT_ULONG (
  11856. PULONG portAddress,
  11857. ULONG Data
  11858. );
  11859. NTHALAPI
  11860. VOID
  11861. WRITE_PORT_BUFFER_UCHAR (
  11862. PUCHAR portAddress,
  11863. PUCHAR writeBuffer,
  11864. ULONG writeCount
  11865. );
  11866. NTHALAPI
  11867. VOID
  11868. WRITE_PORT_BUFFER_USHORT (
  11869. PUSHORT portAddress,
  11870. PUSHORT writeBuffer,
  11871. ULONG writeCount
  11872. );
  11873. NTHALAPI
  11874. VOID
  11875. WRITE_PORT_BUFFER_ULONG (
  11876. PULONG portAddress,
  11877. PULONG writeBuffer,
  11878. ULONG writeCount
  11879. );
  11880. #define READ_REGISTER_UCHAR(x) \
  11881. (__mf(), *(volatile UCHAR * const)(x))
  11882. #define READ_REGISTER_USHORT(x) \
  11883. (__mf(), *(volatile USHORT * const)(x))
  11884. #define READ_REGISTER_ULONG(x) \
  11885. (__mf(), *(volatile ULONG * const)(x))
  11886. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  11887. PUCHAR registerBuffer = x; \
  11888. PUCHAR readBuffer = y; \
  11889. ULONG readCount; \
  11890. __mf(); \
  11891. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  11892. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  11893. } \
  11894. }
  11895. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  11896. PUSHORT registerBuffer = x; \
  11897. PUSHORT readBuffer = y; \
  11898. ULONG readCount; \
  11899. __mf(); \
  11900. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  11901. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  11902. } \
  11903. }
  11904. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  11905. PULONG registerBuffer = x; \
  11906. PULONG readBuffer = y; \
  11907. ULONG readCount; \
  11908. __mf(); \
  11909. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  11910. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  11911. } \
  11912. }
  11913. #define WRITE_REGISTER_UCHAR(x, y) { \
  11914. *(volatile UCHAR * const)(x) = y; \
  11915. KeFlushWriteBuffer(); \
  11916. }
  11917. #define WRITE_REGISTER_USHORT(x, y) { \
  11918. *(volatile USHORT * const)(x) = y; \
  11919. KeFlushWriteBuffer(); \
  11920. }
  11921. #define WRITE_REGISTER_ULONG(x, y) { \
  11922. *(volatile ULONG * const)(x) = y; \
  11923. KeFlushWriteBuffer(); \
  11924. }
  11925. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  11926. PUCHAR registerBuffer = x; \
  11927. PUCHAR writeBuffer = y; \
  11928. ULONG writeCount; \
  11929. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  11930. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  11931. } \
  11932. KeFlushWriteBuffer(); \
  11933. }
  11934. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  11935. PUSHORT registerBuffer = x; \
  11936. PUSHORT writeBuffer = y; \
  11937. ULONG writeCount; \
  11938. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  11939. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  11940. } \
  11941. KeFlushWriteBuffer(); \
  11942. }
  11943. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  11944. PULONG registerBuffer = x; \
  11945. PULONG writeBuffer = y; \
  11946. ULONG writeCount; \
  11947. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  11948. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  11949. } \
  11950. KeFlushWriteBuffer(); \
  11951. }
  11952. //
  11953. // Non-volatile floating point state
  11954. //
  11955. typedef struct _KFLOATING_SAVE {
  11956. ULONG Reserved;
  11957. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  11958. //
  11959. // Processor Control Block (PRCB)
  11960. //
  11961. #define PRCB_MINOR_VERSION 1
  11962. #define PRCB_MAJOR_VERSION 1
  11963. #define PRCB_BUILD_DEBUG 0x0001
  11964. #define PRCB_BUILD_UNIPROCESSOR 0x0002
  11965. struct _RESTART_BLOCK;
  11966. typedef struct _KPRCB {
  11967. //
  11968. // Major and minor version numbers of the PCR.
  11969. //
  11970. USHORT MinorVersion;
  11971. USHORT MajorVersion;
  11972. //
  11973. // Start of the architecturally defined section of the PRCB. This section
  11974. // may be directly addressed by vendor/platform specific HAL code and will
  11975. // not change from version to version of NT.
  11976. //
  11977. //
  11978. struct _KTHREAD *CurrentThread;
  11979. struct _KTHREAD *RESTRICTED_POINTER NextThread;
  11980. struct _KTHREAD *IdleThread;
  11981. CCHAR Number;
  11982. CCHAR WakeIdle;
  11983. USHORT BuildType;
  11984. KAFFINITY SetMember;
  11985. struct _RESTART_BLOCK *RestartBlock;
  11986. ULONG_PTR PcrPage;
  11987. ULONG Spare0[4];
  11988. //
  11989. // Processor Idendification Registers.
  11990. //
  11991. ULONG ProcessorModel;
  11992. ULONG ProcessorRevision;
  11993. ULONG ProcessorFamily;
  11994. ULONG ProcessorArchRev;
  11995. ULONGLONG ProcessorSerialNumber;
  11996. ULONGLONG ProcessorFeatureBits;
  11997. UCHAR ProcessorVendorString[16];
  11998. //
  11999. // Space reserved for the system.
  12000. //
  12001. ULONGLONG SystemReserved[8];
  12002. //
  12003. // Space reserved for the HAL.
  12004. //
  12005. ULONGLONG HalReserved[16];
  12006. //
  12007. // End of the architecturally defined section of the PRCB.
  12008. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  12009. // begin_ntndis
  12010. //
  12011. // OS_MCA, OS_INIT HandOff State definitions
  12012. //
  12013. // Note: The following definitions *must* match the definiions of the
  12014. // corresponding SAL Revision Hand-Off structures.
  12015. //
  12016. typedef struct _SAL_HANDOFF_STATE {
  12017. ULONGLONG PalProcEntryPoint;
  12018. ULONGLONG SalProcEntryPoint;
  12019. ULONGLONG SalGlobalPointer;
  12020. LONGLONG RendezVousResult;
  12021. ULONGLONG SalReturnAddress;
  12022. ULONGLONG MinStateSavePtr;
  12023. } SAL_HANDOFF_STATE, *PSAL_HANDOFF_STATE;
  12024. typedef struct _OS_HANDOFF_STATE {
  12025. ULONGLONG Result;
  12026. ULONGLONG SalGlobalPointer;
  12027. ULONGLONG MinStateSavePtr;
  12028. ULONGLONG SalReturnAddress;
  12029. ULONGLONG NewContextFlag;
  12030. } OS_HANDOFF_STATE, *POS_HANDOFF_STATE;
  12031. //
  12032. // per processor OS_MCA and OS_INIT resource structure
  12033. //
  12034. #define SER_EVENT_STACK_FRAME_ENTRIES 8
  12035. typedef struct _SAL_EVENT_RESOURCES {
  12036. SAL_HANDOFF_STATE SalToOsHandOff;
  12037. OS_HANDOFF_STATE OsToSalHandOff;
  12038. PVOID StateDump;
  12039. ULONGLONG StateDumpPhysical;
  12040. PVOID BackStore;
  12041. ULONGLONG BackStoreLimit;
  12042. PVOID Stack;
  12043. ULONGLONG StackLimit;
  12044. PULONGLONG PTOM;
  12045. ULONGLONG StackFrame[SER_EVENT_STACK_FRAME_ENTRIES];
  12046. PVOID EventPool;
  12047. ULONG EventPoolSize;
  12048. } SAL_EVENT_RESOURCES, *PSAL_EVENT_RESOURCES;
  12049. //
  12050. // PAL Mini-save area, used by MCA and INIT
  12051. //
  12052. typedef struct _PAL_MINI_SAVE_AREA {
  12053. ULONGLONG IntNats; // Nat bits for r1-r31
  12054. // r1-r31 in bits 1 thru 31.
  12055. ULONGLONG IntGp; // r1, volatile
  12056. ULONGLONG IntT0; // r2-r3, volatile
  12057. ULONGLONG IntT1; //
  12058. ULONGLONG IntS0; // r4-r7, preserved
  12059. ULONGLONG IntS1;
  12060. ULONGLONG IntS2;
  12061. ULONGLONG IntS3;
  12062. ULONGLONG IntV0; // r8, volatile
  12063. ULONGLONG IntT2; // r9-r11, volatile
  12064. ULONGLONG IntT3;
  12065. ULONGLONG IntT4;
  12066. ULONGLONG IntSp; // stack pointer (r12), special
  12067. ULONGLONG IntTeb; // teb (r13), special
  12068. ULONGLONG IntT5; // r14-r31, volatile
  12069. ULONGLONG IntT6;
  12070. ULONGLONG B0R16; // Bank 0 registers 16-31
  12071. ULONGLONG B0R17;
  12072. ULONGLONG B0R18;
  12073. ULONGLONG B0R19;
  12074. ULONGLONG B0R20;
  12075. ULONGLONG B0R21;
  12076. ULONGLONG B0R22;
  12077. ULONGLONG B0R23;
  12078. ULONGLONG B0R24;
  12079. ULONGLONG B0R25;
  12080. ULONGLONG B0R26;
  12081. ULONGLONG B0R27;
  12082. ULONGLONG B0R28;
  12083. ULONGLONG B0R29;
  12084. ULONGLONG B0R30;
  12085. ULONGLONG B0R31;
  12086. ULONGLONG IntT7; // Bank 1 registers 16-31
  12087. ULONGLONG IntT8;
  12088. ULONGLONG IntT9;
  12089. ULONGLONG IntT10;
  12090. ULONGLONG IntT11;
  12091. ULONGLONG IntT12;
  12092. ULONGLONG IntT13;
  12093. ULONGLONG IntT14;
  12094. ULONGLONG IntT15;
  12095. ULONGLONG IntT16;
  12096. ULONGLONG IntT17;
  12097. ULONGLONG IntT18;
  12098. ULONGLONG IntT19;
  12099. ULONGLONG IntT20;
  12100. ULONGLONG IntT21;
  12101. ULONGLONG IntT22;
  12102. ULONGLONG Preds; // predicates, preserved
  12103. ULONGLONG BrRp; // return pointer, b0, preserved
  12104. ULONGLONG RsRSC; // RSE configuration, volatile
  12105. ULONGLONG StIIP; // Interruption IP
  12106. ULONGLONG StIPSR; // Interruption Processor Status
  12107. ULONGLONG StIFS; // Interruption Function State
  12108. ULONGLONG XIP; // Event IP
  12109. ULONGLONG XPSR; // Event Processor Status
  12110. ULONGLONG XFS; // Event Function State
  12111. } PAL_MINI_SAVE_AREA, *PPAL_MINI_SAVE_AREA;
  12112. //
  12113. // Define Processor Control Region Structure.
  12114. //
  12115. #define PCR_MINOR_VERSION 1
  12116. #define PCR_MAJOR_VERSION 1
  12117. typedef struct _KPCR {
  12118. //
  12119. // Major and minor version numbers of the PCR.
  12120. //
  12121. ULONG MinorVersion;
  12122. ULONG MajorVersion;
  12123. //
  12124. // Start of the architecturally defined section of the PCR. This section
  12125. // may be directly addressed by vendor/platform specific HAL code and will
  12126. // not change from version to version of NT.
  12127. //
  12128. //
  12129. // First and second level cache parameters.
  12130. //
  12131. ULONG FirstLevelDcacheSize;
  12132. ULONG FirstLevelDcacheFillSize;
  12133. ULONG FirstLevelIcacheSize;
  12134. ULONG FirstLevelIcacheFillSize;
  12135. ULONG SecondLevelDcacheSize;
  12136. ULONG SecondLevelDcacheFillSize;
  12137. ULONG SecondLevelIcacheSize;
  12138. ULONG SecondLevelIcacheFillSize;
  12139. //
  12140. // Data cache alignment and fill size used for cache flushing and alignment.
  12141. // These fields are set to the larger of the first and second level data
  12142. // cache fill sizes.
  12143. //
  12144. ULONG DcacheAlignment;
  12145. ULONG DcacheFillSize;
  12146. //
  12147. // Instruction cache alignment and fill size used for cache flushing and
  12148. // alignment. These fields are set to the larger of the first and second
  12149. // level data cache fill sizes.
  12150. //
  12151. ULONG IcacheAlignment;
  12152. ULONG IcacheFillSize;
  12153. //
  12154. // Processor identification from PrId register.
  12155. //
  12156. ULONG ProcessorId;
  12157. //
  12158. // Profiling data.
  12159. //
  12160. ULONG ProfileInterval;
  12161. ULONG ProfileCount;
  12162. //
  12163. // Stall execution count and scale factor.
  12164. //
  12165. ULONG StallExecutionCount;
  12166. ULONG StallScaleFactor;
  12167. ULONG InterruptionCount;
  12168. //
  12169. // Space reserved for the system.
  12170. //
  12171. ULONGLONG SystemReserved[6];
  12172. //
  12173. // Space reserved for the HAL
  12174. //
  12175. ULONGLONG HalReserved[64];
  12176. //
  12177. // IRQL mapping tables.
  12178. //
  12179. UCHAR IrqlMask[64];
  12180. UCHAR IrqlTable[64];
  12181. //
  12182. // External Interrupt vectors.
  12183. //
  12184. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  12185. //
  12186. // Reserved interrupt vector mask.
  12187. //
  12188. ULONG ReservedVectors;
  12189. //
  12190. // Processor affinity mask.
  12191. //
  12192. KAFFINITY SetMember;
  12193. //
  12194. // Complement of the processor affinity mask.
  12195. //
  12196. KAFFINITY NotMember;
  12197. //
  12198. // Pointer to processor control block.
  12199. //
  12200. struct _KPRCB *Prcb;
  12201. //
  12202. // Shadow copy of Prcb->CurrentThread for fast access
  12203. //
  12204. struct _KTHREAD *CurrentThread;
  12205. //
  12206. // Processor number.
  12207. //
  12208. CCHAR Number; // Processor Number
  12209. UCHAR DebugActive; // debug register active in user flag
  12210. UCHAR KernelDebugActive; // debug register active in kernel flag
  12211. UCHAR CurrentIrql; // Current IRQL
  12212. union {
  12213. USHORT SoftwareInterruptPending; // Software Interrupt Pending Flag
  12214. struct {
  12215. UCHAR ApcInterrupt; // 0x01 if APC int pending
  12216. UCHAR DispatchInterrupt; // 0x01 if dispatch int pending
  12217. };
  12218. };
  12219. //
  12220. // Address of per processor SAPIC EOI Table
  12221. //
  12222. PVOID EOITable;
  12223. //
  12224. // IA-64 Machine Check Events trackers
  12225. //
  12226. UCHAR InOsMca;
  12227. UCHAR InOsInit;
  12228. UCHAR InOsCmc;
  12229. UCHAR InOsCpe;
  12230. ULONG InOsULONG_Spare; // Spare ULONG
  12231. PSAL_EVENT_RESOURCES OsMcaResourcePtr;
  12232. PSAL_EVENT_RESOURCES OsInitResourcePtr;
  12233. //
  12234. // End of the architecturally defined section of the PCR. This section
  12235. // may be directly addressed by vendor/platform specific HAL code and will
  12236. // not change from version to version of NT.
  12237. //
  12238. } KPCR, *PKPCR;
  12239. //
  12240. // The highest user address reserves 64K bytes for a guard page. This
  12241. // the probing of address from kernel mode to only have to check the
  12242. // starting address for structures of 64k bytes or less.
  12243. //
  12244. extern NTKERNELAPI PVOID MmHighestUserAddress;
  12245. extern NTKERNELAPI PVOID MmSystemRangeStart;
  12246. extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
  12247. #define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
  12248. #define MM_USER_PROBE_ADDRESS MmUserProbeAddress
  12249. #define MM_SYSTEM_RANGE_START MmSystemRangeStart
  12250. //
  12251. // The lowest user address reserves the low 64k.
  12252. //
  12253. #define MM_LOWEST_USER_ADDRESS (PVOID)((ULONG_PTR)(UADDRESS_BASE+0x00010000))
  12254. // begin_wdm
  12255. #define MmGetProcedureAddress(Address) (Address)
  12256. #define MmLockPagableCodeSection(PLabelAddress) \
  12257. MmLockPagableDataSection((PVOID)(*((PULONGLONG)PLabelAddress)))
  12258. #define VRN_MASK 0xE000000000000000UI64 // Virtual Region Number mask
  12259. //
  12260. // The lowest address for system space.
  12261. //
  12262. #define MM_LOWEST_SYSTEM_ADDRESS ((PVOID)((ULONG_PTR)(KADDRESS_BASE + 0xC0C00000)))
  12263. #endif // defined(_IA64_)
  12264. //
  12265. // Define configuration routine types.
  12266. //
  12267. // Configuration information.
  12268. //
  12269. typedef enum _CONFIGURATION_TYPE {
  12270. ArcSystem,
  12271. CentralProcessor,
  12272. FloatingPointProcessor,
  12273. PrimaryIcache,
  12274. PrimaryDcache,
  12275. SecondaryIcache,
  12276. SecondaryDcache,
  12277. SecondaryCache,
  12278. EisaAdapter,
  12279. TcAdapter,
  12280. ScsiAdapter,
  12281. DtiAdapter,
  12282. MultiFunctionAdapter,
  12283. DiskController,
  12284. TapeController,
  12285. CdromController,
  12286. WormController,
  12287. SerialController,
  12288. NetworkController,
  12289. DisplayController,
  12290. ParallelController,
  12291. PointerController,
  12292. KeyboardController,
  12293. AudioController,
  12294. OtherController,
  12295. DiskPeripheral,
  12296. FloppyDiskPeripheral,
  12297. TapePeripheral,
  12298. ModemPeripheral,
  12299. MonitorPeripheral,
  12300. PrinterPeripheral,
  12301. PointerPeripheral,
  12302. KeyboardPeripheral,
  12303. TerminalPeripheral,
  12304. OtherPeripheral,
  12305. LinePeripheral,
  12306. NetworkPeripheral,
  12307. SystemMemory,
  12308. DockingInformation,
  12309. RealModeIrqRoutingTable,
  12310. RealModePCIEnumeration,
  12311. MaximumType
  12312. } CONFIGURATION_TYPE, *PCONFIGURATION_TYPE;
  12313. #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
  12314. //
  12315. // Object Manager Object Type Specific Access Rights.
  12316. //
  12317. #define OBJECT_TYPE_CREATE (0x0001)
  12318. #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  12319. //
  12320. // Object Manager Directory Specific Access Rights.
  12321. //
  12322. #define DIRECTORY_QUERY (0x0001)
  12323. #define DIRECTORY_TRAVERSE (0x0002)
  12324. #define DIRECTORY_CREATE_OBJECT (0x0004)
  12325. #define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
  12326. #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
  12327. //
  12328. // Object Manager Symbolic Link Specific Access Rights.
  12329. //
  12330. #define SYMBOLIC_LINK_QUERY (0x0001)
  12331. #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  12332. typedef struct _OBJECT_NAME_INFORMATION {
  12333. UNICODE_STRING Name;
  12334. } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
  12335. #define DUPLICATE_CLOSE_SOURCE 0x00000001 // winnt
  12336. #define DUPLICATE_SAME_ACCESS 0x00000002 // winnt
  12337. #define DUPLICATE_SAME_ATTRIBUTES 0x00000004
  12338. // begin_winnt
  12339. //
  12340. // Predefined Value Types.
  12341. //
  12342. #define REG_NONE ( 0 ) // No value type
  12343. #define REG_SZ ( 1 ) // Unicode nul terminated string
  12344. #define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string
  12345. // (with environment variable references)
  12346. #define REG_BINARY ( 3 ) // Free form binary
  12347. #define REG_DWORD ( 4 ) // 32-bit number
  12348. #define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD)
  12349. #define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
  12350. #define REG_LINK ( 6 ) // Symbolic Link (unicode)
  12351. #define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings
  12352. #define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
  12353. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
  12354. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  12355. #define REG_QWORD ( 11 ) // 64-bit number
  12356. #define REG_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as REG_QWORD)
  12357. //
  12358. // Service Types (Bit Mask)
  12359. //
  12360. #define SERVICE_KERNEL_DRIVER 0x00000001
  12361. #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
  12362. #define SERVICE_ADAPTER 0x00000004
  12363. #define SERVICE_RECOGNIZER_DRIVER 0x00000008
  12364. #define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | \
  12365. SERVICE_FILE_SYSTEM_DRIVER | \
  12366. SERVICE_RECOGNIZER_DRIVER)
  12367. #define SERVICE_WIN32_OWN_PROCESS 0x00000010
  12368. #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
  12369. #define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | \
  12370. SERVICE_WIN32_SHARE_PROCESS)
  12371. #define SERVICE_INTERACTIVE_PROCESS 0x00000100
  12372. #define SERVICE_TYPE_ALL (SERVICE_WIN32 | \
  12373. SERVICE_ADAPTER | \
  12374. SERVICE_DRIVER | \
  12375. SERVICE_INTERACTIVE_PROCESS)
  12376. //
  12377. // Start Type
  12378. //
  12379. #define SERVICE_BOOT_START 0x00000000
  12380. #define SERVICE_SYSTEM_START 0x00000001
  12381. #define SERVICE_AUTO_START 0x00000002
  12382. #define SERVICE_DEMAND_START 0x00000003
  12383. #define SERVICE_DISABLED 0x00000004
  12384. //
  12385. // Error control type
  12386. //
  12387. #define SERVICE_ERROR_IGNORE 0x00000000
  12388. #define SERVICE_ERROR_NORMAL 0x00000001
  12389. #define SERVICE_ERROR_SEVERE 0x00000002
  12390. #define SERVICE_ERROR_CRITICAL 0x00000003
  12391. //
  12392. //
  12393. // Define the registry driver node enumerations
  12394. //
  12395. typedef enum _CM_SERVICE_NODE_TYPE {
  12396. DriverType = SERVICE_KERNEL_DRIVER,
  12397. FileSystemType = SERVICE_FILE_SYSTEM_DRIVER,
  12398. Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS,
  12399. Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  12400. AdapterType = SERVICE_ADAPTER,
  12401. RecognizerType = SERVICE_RECOGNIZER_DRIVER
  12402. } SERVICE_NODE_TYPE;
  12403. typedef enum _CM_SERVICE_LOAD_TYPE {
  12404. BootLoad = SERVICE_BOOT_START,
  12405. SystemLoad = SERVICE_SYSTEM_START,
  12406. AutoLoad = SERVICE_AUTO_START,
  12407. DemandLoad = SERVICE_DEMAND_START,
  12408. DisableLoad = SERVICE_DISABLED
  12409. } SERVICE_LOAD_TYPE;
  12410. typedef enum _CM_ERROR_CONTROL_TYPE {
  12411. IgnoreError = SERVICE_ERROR_IGNORE,
  12412. NormalError = SERVICE_ERROR_NORMAL,
  12413. SevereError = SERVICE_ERROR_SEVERE,
  12414. CriticalError = SERVICE_ERROR_CRITICAL
  12415. } SERVICE_ERROR_TYPE;
  12416. // end_winnt
  12417. //
  12418. // Resource List definitions
  12419. //
  12420. // begin_ntminiport begin_ntndis
  12421. //
  12422. // Defines the Type in the RESOURCE_DESCRIPTOR
  12423. //
  12424. // NOTE: For all CM_RESOURCE_TYPE values, there must be a
  12425. // corresponding ResType value in the 32-bit ConfigMgr headerfile
  12426. // (cfgmgr32.h). Values in the range [0x6,0x80) use the same values
  12427. // as their ConfigMgr counterparts. CM_RESOURCE_TYPE values with
  12428. // the high bit set (i.e., in the range [0x80,0xFF]), are
  12429. // non-arbitrated resources. These correspond to the same values
  12430. // in cfgmgr32.h that have their high bit set (however, since
  12431. // cfgmgr32.h uses 16 bits for ResType values, these values are in
  12432. // the range [0x8000,0x807F). Note that ConfigMgr ResType values
  12433. // cannot be in the range [0x8080,0xFFFF), because they would not
  12434. // be able to map into CM_RESOURCE_TYPE values. (0xFFFF itself is
  12435. // a special value, because it maps to CmResourceTypeDeviceSpecific.)
  12436. //
  12437. typedef int CM_RESOURCE_TYPE;
  12438. // CmResourceTypeNull is reserved
  12439. #define CmResourceTypeNull 0 // ResType_All or ResType_None (0x0000)
  12440. #define CmResourceTypePort 1 // ResType_IO (0x0002)
  12441. #define CmResourceTypeInterrupt 2 // ResType_IRQ (0x0004)
  12442. #define CmResourceTypeMemory 3 // ResType_Mem (0x0001)
  12443. #define CmResourceTypeDma 4 // ResType_DMA (0x0003)
  12444. #define CmResourceTypeDeviceSpecific 5 // ResType_ClassSpecific (0xFFFF)
  12445. #define CmResourceTypeBusNumber 6 // ResType_BusNumber (0x0006)
  12446. // end_wdm
  12447. #define CmResourceTypeMaximum 7
  12448. // begin_wdm
  12449. #define CmResourceTypeNonArbitrated 128 // Not arbitrated if 0x80 bit set
  12450. #define CmResourceTypeConfigData 128 // ResType_Reserved (0x8000)
  12451. #define CmResourceTypeDevicePrivate 129 // ResType_DevicePrivate (0x8001)
  12452. #define CmResourceTypePcCardConfig 130 // ResType_PcCardConfig (0x8002)
  12453. #define CmResourceTypeMfCardConfig 131 // ResType_MfCardConfig (0x8003)
  12454. //
  12455. // Defines the ShareDisposition in the RESOURCE_DESCRIPTOR
  12456. //
  12457. typedef enum _CM_SHARE_DISPOSITION {
  12458. CmResourceShareUndetermined = 0, // Reserved
  12459. CmResourceShareDeviceExclusive,
  12460. CmResourceShareDriverExclusive,
  12461. CmResourceShareShared
  12462. } CM_SHARE_DISPOSITION;
  12463. //
  12464. // Define the bit masks for Flags when type is CmResourceTypeInterrupt
  12465. //
  12466. #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
  12467. #define CM_RESOURCE_INTERRUPT_LATCHED 1
  12468. //
  12469. // Define the bit masks for Flags when type is CmResourceTypeMemory
  12470. //
  12471. #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
  12472. #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
  12473. #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
  12474. #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
  12475. #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
  12476. #define CM_RESOURCE_MEMORY_24 0x0010
  12477. #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
  12478. //
  12479. // Define the bit masks for Flags when type is CmResourceTypePort
  12480. //
  12481. #define CM_RESOURCE_PORT_MEMORY 0x0000
  12482. #define CM_RESOURCE_PORT_IO 0x0001
  12483. #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
  12484. #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
  12485. #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
  12486. #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
  12487. #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
  12488. #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
  12489. //
  12490. // Define the bit masks for Flags when type is CmResourceTypeDma
  12491. //
  12492. #define CM_RESOURCE_DMA_8 0x0000
  12493. #define CM_RESOURCE_DMA_16 0x0001
  12494. #define CM_RESOURCE_DMA_32 0x0002
  12495. #define CM_RESOURCE_DMA_8_AND_16 0x0004
  12496. #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
  12497. #define CM_RESOURCE_DMA_TYPE_A 0x0010
  12498. #define CM_RESOURCE_DMA_TYPE_B 0x0020
  12499. #define CM_RESOURCE_DMA_TYPE_F 0x0040
  12500. // end_ntminiport end_ntndis
  12501. //
  12502. // This structure defines one type of resource used by a driver.
  12503. //
  12504. // There can only be *1* DeviceSpecificData block. It must be located at
  12505. // the end of all resource descriptors in a full descriptor block.
  12506. //
  12507. //
  12508. // Make sure alignment is made properly by compiler; otherwise move
  12509. // flags back to the top of the structure (common to all members of the
  12510. // union).
  12511. //
  12512. // begin_ntndis
  12513. #include "pshpack4.h"
  12514. typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
  12515. UCHAR Type;
  12516. UCHAR ShareDisposition;
  12517. USHORT Flags;
  12518. union {
  12519. //
  12520. // Range of resources, inclusive. These are physical, bus relative.
  12521. // It is known that Port and Memory below have the exact same layout
  12522. // as Generic.
  12523. //
  12524. struct {
  12525. PHYSICAL_ADDRESS Start;
  12526. ULONG Length;
  12527. } Generic;
  12528. //
  12529. // end_wdm
  12530. // Range of port numbers, inclusive. These are physical, bus
  12531. // relative. The value should be the same as the one passed to
  12532. // HalTranslateBusAddress().
  12533. // begin_wdm
  12534. //
  12535. struct {
  12536. PHYSICAL_ADDRESS Start;
  12537. ULONG Length;
  12538. } Port;
  12539. //
  12540. // end_wdm
  12541. // IRQL and vector. Should be same values as were passed to
  12542. // HalGetInterruptVector().
  12543. // begin_wdm
  12544. //
  12545. struct {
  12546. ULONG Level;
  12547. ULONG Vector;
  12548. KAFFINITY Affinity;
  12549. } Interrupt;
  12550. //
  12551. // Range of memory addresses, inclusive. These are physical, bus
  12552. // relative. The value should be the same as the one passed to
  12553. // HalTranslateBusAddress().
  12554. //
  12555. struct {
  12556. PHYSICAL_ADDRESS Start; // 64 bit physical addresses.
  12557. ULONG Length;
  12558. } Memory;
  12559. //
  12560. // Physical DMA channel.
  12561. //
  12562. struct {
  12563. ULONG Channel;
  12564. ULONG Port;
  12565. ULONG Reserved1;
  12566. } Dma;
  12567. //
  12568. // Device driver private data, usually used to help it figure
  12569. // what the resource assignments decisions that were made.
  12570. //
  12571. struct {
  12572. ULONG Data[3];
  12573. } DevicePrivate;
  12574. //
  12575. // Bus Number information.
  12576. //
  12577. struct {
  12578. ULONG Start;
  12579. ULONG Length;
  12580. ULONG Reserved;
  12581. } BusNumber;
  12582. //
  12583. // Device Specific information defined by the driver.
  12584. // The DataSize field indicates the size of the data in bytes. The
  12585. // data is located immediately after the DeviceSpecificData field in
  12586. // the structure.
  12587. //
  12588. struct {
  12589. ULONG DataSize;
  12590. ULONG Reserved1;
  12591. ULONG Reserved2;
  12592. } DeviceSpecificData;
  12593. } u;
  12594. } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
  12595. #include "poppack.h"
  12596. //
  12597. // A Partial Resource List is what can be found in the ARC firmware
  12598. // or will be generated by ntdetect.com.
  12599. // The configuration manager will transform this structure into a Full
  12600. // resource descriptor when it is about to store it in the regsitry.
  12601. //
  12602. // Note: There must a be a convention to the order of fields of same type,
  12603. // (defined on a device by device basis) so that the fields can make sense
  12604. // to a driver (i.e. when multiple memory ranges are necessary).
  12605. //
  12606. typedef struct _CM_PARTIAL_RESOURCE_LIST {
  12607. USHORT Version;
  12608. USHORT Revision;
  12609. ULONG Count;
  12610. CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
  12611. } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
  12612. //
  12613. // A Full Resource Descriptor is what can be found in the registry.
  12614. // This is what will be returned to a driver when it queries the registry
  12615. // to get device information; it will be stored under a key in the hardware
  12616. // description tree.
  12617. //
  12618. // end_wdm
  12619. // Note: The BusNumber and Type are redundant information, but we will keep
  12620. // it since it allows the driver _not_ to append it when it is creating
  12621. // a resource list which could possibly span multiple buses.
  12622. //
  12623. // begin_wdm
  12624. // Note: There must a be a convention to the order of fields of same type,
  12625. // (defined on a device by device basis) so that the fields can make sense
  12626. // to a driver (i.e. when multiple memory ranges are necessary).
  12627. //
  12628. typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
  12629. INTERFACE_TYPE InterfaceType; // unused for WDM
  12630. ULONG BusNumber; // unused for WDM
  12631. CM_PARTIAL_RESOURCE_LIST PartialResourceList;
  12632. } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
  12633. //
  12634. // The Resource list is what will be stored by the drivers into the
  12635. // resource map via the IO API.
  12636. //
  12637. typedef struct _CM_RESOURCE_LIST {
  12638. ULONG Count;
  12639. CM_FULL_RESOURCE_DESCRIPTOR List[1];
  12640. } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
  12641. // end_ntndis
  12642. //
  12643. // Define the structures used to interpret configuration data of
  12644. // \\Registry\machine\hardware\description tree.
  12645. // Basically, these structures are used to interpret component
  12646. // sepcific data.
  12647. //
  12648. //
  12649. // Define DEVICE_FLAGS
  12650. //
  12651. typedef struct _DEVICE_FLAGS {
  12652. ULONG Failed : 1;
  12653. ULONG ReadOnly : 1;
  12654. ULONG Removable : 1;
  12655. ULONG ConsoleIn : 1;
  12656. ULONG ConsoleOut : 1;
  12657. ULONG Input : 1;
  12658. ULONG Output : 1;
  12659. } DEVICE_FLAGS, *PDEVICE_FLAGS;
  12660. //
  12661. // Define Component Information structure
  12662. //
  12663. typedef struct _CM_COMPONENT_INFORMATION {
  12664. DEVICE_FLAGS Flags;
  12665. ULONG Version;
  12666. ULONG Key;
  12667. KAFFINITY AffinityMask;
  12668. } CM_COMPONENT_INFORMATION, *PCM_COMPONENT_INFORMATION;
  12669. //
  12670. // The following structures are used to interpret x86
  12671. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  12672. // (Most of the structures are defined by BIOS. They are
  12673. // not aligned on word (or dword) boundary.
  12674. //
  12675. //
  12676. // Define the Rom Block structure
  12677. //
  12678. typedef struct _CM_ROM_BLOCK {
  12679. ULONG Address;
  12680. ULONG Size;
  12681. } CM_ROM_BLOCK, *PCM_ROM_BLOCK;
  12682. // begin_ntminiport begin_ntndis
  12683. #include "pshpack1.h"
  12684. // end_ntminiport end_ntndis
  12685. //
  12686. // Define INT13 driver parameter block
  12687. //
  12688. typedef struct _CM_INT13_DRIVE_PARAMETER {
  12689. USHORT DriveSelect;
  12690. ULONG MaxCylinders;
  12691. USHORT SectorsPerTrack;
  12692. USHORT MaxHeads;
  12693. USHORT NumberDrives;
  12694. } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
  12695. // begin_ntminiport begin_ntndis
  12696. //
  12697. // Define Mca POS data block for slot
  12698. //
  12699. typedef struct _CM_MCA_POS_DATA {
  12700. USHORT AdapterId;
  12701. UCHAR PosData1;
  12702. UCHAR PosData2;
  12703. UCHAR PosData3;
  12704. UCHAR PosData4;
  12705. } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
  12706. //
  12707. // Memory configuration of eisa data block structure
  12708. //
  12709. typedef struct _EISA_MEMORY_TYPE {
  12710. UCHAR ReadWrite: 1;
  12711. UCHAR Cached : 1;
  12712. UCHAR Reserved0 :1;
  12713. UCHAR Type:2;
  12714. UCHAR Shared:1;
  12715. UCHAR Reserved1 :1;
  12716. UCHAR MoreEntries : 1;
  12717. } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
  12718. typedef struct _EISA_MEMORY_CONFIGURATION {
  12719. EISA_MEMORY_TYPE ConfigurationByte;
  12720. UCHAR DataSize;
  12721. USHORT AddressLowWord;
  12722. UCHAR AddressHighByte;
  12723. USHORT MemorySize;
  12724. } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
  12725. //
  12726. // Interrupt configurationn of eisa data block structure
  12727. //
  12728. typedef struct _EISA_IRQ_DESCRIPTOR {
  12729. UCHAR Interrupt : 4;
  12730. UCHAR Reserved :1;
  12731. UCHAR LevelTriggered :1;
  12732. UCHAR Shared : 1;
  12733. UCHAR MoreEntries : 1;
  12734. } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
  12735. typedef struct _EISA_IRQ_CONFIGURATION {
  12736. EISA_IRQ_DESCRIPTOR ConfigurationByte;
  12737. UCHAR Reserved;
  12738. } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
  12739. //
  12740. // DMA description of eisa data block structure
  12741. //
  12742. typedef struct _DMA_CONFIGURATION_BYTE0 {
  12743. UCHAR Channel : 3;
  12744. UCHAR Reserved : 3;
  12745. UCHAR Shared :1;
  12746. UCHAR MoreEntries :1;
  12747. } DMA_CONFIGURATION_BYTE0;
  12748. typedef struct _DMA_CONFIGURATION_BYTE1 {
  12749. UCHAR Reserved0 : 2;
  12750. UCHAR TransferSize : 2;
  12751. UCHAR Timing : 2;
  12752. UCHAR Reserved1 : 2;
  12753. } DMA_CONFIGURATION_BYTE1;
  12754. typedef struct _EISA_DMA_CONFIGURATION {
  12755. DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
  12756. DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
  12757. } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
  12758. //
  12759. // Port description of eisa data block structure
  12760. //
  12761. typedef struct _EISA_PORT_DESCRIPTOR {
  12762. UCHAR NumberPorts : 5;
  12763. UCHAR Reserved :1;
  12764. UCHAR Shared :1;
  12765. UCHAR MoreEntries : 1;
  12766. } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
  12767. typedef struct _EISA_PORT_CONFIGURATION {
  12768. EISA_PORT_DESCRIPTOR Configuration;
  12769. USHORT PortAddress;
  12770. } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
  12771. //
  12772. // Eisa slot information definition
  12773. // N.B. This structure is different from the one defined
  12774. // in ARC eisa addendum.
  12775. //
  12776. typedef struct _CM_EISA_SLOT_INFORMATION {
  12777. UCHAR ReturnCode;
  12778. UCHAR ReturnFlags;
  12779. UCHAR MajorRevision;
  12780. UCHAR MinorRevision;
  12781. USHORT Checksum;
  12782. UCHAR NumberFunctions;
  12783. UCHAR FunctionInformation;
  12784. ULONG CompressedId;
  12785. } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
  12786. //
  12787. // Eisa function information definition
  12788. //
  12789. typedef struct _CM_EISA_FUNCTION_INFORMATION {
  12790. ULONG CompressedId;
  12791. UCHAR IdSlotFlags1;
  12792. UCHAR IdSlotFlags2;
  12793. UCHAR MinorRevision;
  12794. UCHAR MajorRevision;
  12795. UCHAR Selections[26];
  12796. UCHAR FunctionFlags;
  12797. UCHAR TypeString[80];
  12798. EISA_MEMORY_CONFIGURATION EisaMemory[9];
  12799. EISA_IRQ_CONFIGURATION EisaIrq[7];
  12800. EISA_DMA_CONFIGURATION EisaDma[4];
  12801. EISA_PORT_CONFIGURATION EisaPort[20];
  12802. UCHAR InitializationData[60];
  12803. } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
  12804. //
  12805. // The following defines the way pnp bios information is stored in
  12806. // the registry \\HKEY_LOCAL_MACHINE\HARDWARE\Description\System\MultifunctionAdapter\x
  12807. // key, where x is an integer number indicating adapter instance. The
  12808. // "Identifier" of the key must equal to "PNP BIOS" and the
  12809. // "ConfigurationData" is organized as follow:
  12810. //
  12811. // CM_PNP_BIOS_INSTALLATION_CHECK +
  12812. // CM_PNP_BIOS_DEVICE_NODE for device 1 +
  12813. // CM_PNP_BIOS_DEVICE_NODE for device 2 +
  12814. // ...
  12815. // CM_PNP_BIOS_DEVICE_NODE for device n
  12816. //
  12817. //
  12818. // Pnp BIOS device node structure
  12819. //
  12820. typedef struct _CM_PNP_BIOS_DEVICE_NODE {
  12821. USHORT Size;
  12822. UCHAR Node;
  12823. ULONG ProductId;
  12824. UCHAR DeviceType[3];
  12825. USHORT DeviceAttributes;
  12826. // followed by AllocatedResourceBlock, PossibleResourceBlock
  12827. // and CompatibleDeviceId
  12828. } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
  12829. //
  12830. // Pnp BIOS Installation check
  12831. //
  12832. typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK {
  12833. UCHAR Signature[4]; // $PnP (ascii)
  12834. UCHAR Revision;
  12835. UCHAR Length;
  12836. USHORT ControlField;
  12837. UCHAR Checksum;
  12838. ULONG EventFlagAddress; // Physical address
  12839. USHORT RealModeEntryOffset;
  12840. USHORT RealModeEntrySegment;
  12841. USHORT ProtectedModeEntryOffset;
  12842. ULONG ProtectedModeCodeBaseAddress;
  12843. ULONG OemDeviceId;
  12844. USHORT RealModeDataBaseAddress;
  12845. ULONG ProtectedModeDataBaseAddress;
  12846. } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
  12847. #include "poppack.h"
  12848. //
  12849. // Masks for EISA function information
  12850. //
  12851. #define EISA_FUNCTION_ENABLED 0x80
  12852. #define EISA_FREE_FORM_DATA 0x40
  12853. #define EISA_HAS_PORT_INIT_ENTRY 0x20
  12854. #define EISA_HAS_PORT_RANGE 0x10
  12855. #define EISA_HAS_DMA_ENTRY 0x08
  12856. #define EISA_HAS_IRQ_ENTRY 0x04
  12857. #define EISA_HAS_MEMORY_ENTRY 0x02
  12858. #define EISA_HAS_TYPE_ENTRY 0x01
  12859. #define EISA_HAS_INFORMATION EISA_HAS_PORT_RANGE + \
  12860. EISA_HAS_DMA_ENTRY + \
  12861. EISA_HAS_IRQ_ENTRY + \
  12862. EISA_HAS_MEMORY_ENTRY + \
  12863. EISA_HAS_TYPE_ENTRY
  12864. //
  12865. // Masks for EISA memory configuration
  12866. //
  12867. #define EISA_MORE_ENTRIES 0x80
  12868. #define EISA_SYSTEM_MEMORY 0x00
  12869. #define EISA_MEMORY_TYPE_RAM 0x01
  12870. //
  12871. // Returned error code for EISA bios call
  12872. //
  12873. #define EISA_INVALID_SLOT 0x80
  12874. #define EISA_INVALID_FUNCTION 0x81
  12875. #define EISA_INVALID_CONFIGURATION 0x82
  12876. #define EISA_EMPTY_SLOT 0x83
  12877. #define EISA_INVALID_BIOS_CALL 0x86
  12878. // end_ntminiport end_ntndis
  12879. //
  12880. // The following structures are used to interpret mips
  12881. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  12882. //
  12883. //
  12884. // Device data records for adapters.
  12885. //
  12886. //
  12887. // The device data record for the Emulex SCSI controller.
  12888. //
  12889. typedef struct _CM_SCSI_DEVICE_DATA {
  12890. USHORT Version;
  12891. USHORT Revision;
  12892. UCHAR HostIdentifier;
  12893. } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
  12894. //
  12895. // Device data records for controllers.
  12896. //
  12897. //
  12898. // The device data record for the Video controller.
  12899. //
  12900. typedef struct _CM_VIDEO_DEVICE_DATA {
  12901. USHORT Version;
  12902. USHORT Revision;
  12903. ULONG VideoClock;
  12904. } CM_VIDEO_DEVICE_DATA, *PCM_VIDEO_DEVICE_DATA;
  12905. //
  12906. // The device data record for the SONIC network controller.
  12907. //
  12908. typedef struct _CM_SONIC_DEVICE_DATA {
  12909. USHORT Version;
  12910. USHORT Revision;
  12911. USHORT DataConfigurationRegister;
  12912. UCHAR EthernetAddress[8];
  12913. } CM_SONIC_DEVICE_DATA, *PCM_SONIC_DEVICE_DATA;
  12914. //
  12915. // The device data record for the serial controller.
  12916. //
  12917. typedef struct _CM_SERIAL_DEVICE_DATA {
  12918. USHORT Version;
  12919. USHORT Revision;
  12920. ULONG BaudClock;
  12921. } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
  12922. //
  12923. // Device data records for peripherals.
  12924. //
  12925. //
  12926. // The device data record for the Monitor peripheral.
  12927. //
  12928. typedef struct _CM_MONITOR_DEVICE_DATA {
  12929. USHORT Version;
  12930. USHORT Revision;
  12931. USHORT HorizontalScreenSize;
  12932. USHORT VerticalScreenSize;
  12933. USHORT HorizontalResolution;
  12934. USHORT VerticalResolution;
  12935. USHORT HorizontalDisplayTimeLow;
  12936. USHORT HorizontalDisplayTime;
  12937. USHORT HorizontalDisplayTimeHigh;
  12938. USHORT HorizontalBackPorchLow;
  12939. USHORT HorizontalBackPorch;
  12940. USHORT HorizontalBackPorchHigh;
  12941. USHORT HorizontalFrontPorchLow;
  12942. USHORT HorizontalFrontPorch;
  12943. USHORT HorizontalFrontPorchHigh;
  12944. USHORT HorizontalSyncLow;
  12945. USHORT HorizontalSync;
  12946. USHORT HorizontalSyncHigh;
  12947. USHORT VerticalBackPorchLow;
  12948. USHORT VerticalBackPorch;
  12949. USHORT VerticalBackPorchHigh;
  12950. USHORT VerticalFrontPorchLow;
  12951. USHORT VerticalFrontPorch;
  12952. USHORT VerticalFrontPorchHigh;
  12953. USHORT VerticalSyncLow;
  12954. USHORT VerticalSync;
  12955. USHORT VerticalSyncHigh;
  12956. } CM_MONITOR_DEVICE_DATA, *PCM_MONITOR_DEVICE_DATA;
  12957. //
  12958. // The device data record for the Floppy peripheral.
  12959. //
  12960. typedef struct _CM_FLOPPY_DEVICE_DATA {
  12961. USHORT Version;
  12962. USHORT Revision;
  12963. CHAR Size[8];
  12964. ULONG MaxDensity;
  12965. ULONG MountDensity;
  12966. //
  12967. // New data fields for version >= 2.0
  12968. //
  12969. UCHAR StepRateHeadUnloadTime;
  12970. UCHAR HeadLoadTime;
  12971. UCHAR MotorOffTime;
  12972. UCHAR SectorLengthCode;
  12973. UCHAR SectorPerTrack;
  12974. UCHAR ReadWriteGapLength;
  12975. UCHAR DataTransferLength;
  12976. UCHAR FormatGapLength;
  12977. UCHAR FormatFillCharacter;
  12978. UCHAR HeadSettleTime;
  12979. UCHAR MotorSettleTime;
  12980. UCHAR MaximumTrackValue;
  12981. UCHAR DataTransferRate;
  12982. } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
  12983. //
  12984. // The device data record for the Keyboard peripheral.
  12985. // The KeyboardFlags is defined (by x86 BIOS INT 16h, function 02) as:
  12986. // bit 7 : Insert on
  12987. // bit 6 : Caps Lock on
  12988. // bit 5 : Num Lock on
  12989. // bit 4 : Scroll Lock on
  12990. // bit 3 : Alt Key is down
  12991. // bit 2 : Ctrl Key is down
  12992. // bit 1 : Left shift key is down
  12993. // bit 0 : Right shift key is down
  12994. //
  12995. typedef struct _CM_KEYBOARD_DEVICE_DATA {
  12996. USHORT Version;
  12997. USHORT Revision;
  12998. UCHAR Type;
  12999. UCHAR Subtype;
  13000. USHORT KeyboardFlags;
  13001. } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
  13002. //
  13003. // Declaration of the structure for disk geometries
  13004. //
  13005. typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA {
  13006. ULONG BytesPerSector;
  13007. ULONG NumberOfCylinders;
  13008. ULONG SectorsPerTrack;
  13009. ULONG NumberOfHeads;
  13010. } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
  13011. // end_wdm
  13012. //
  13013. // Declaration of the structure for the PcCard ISA IRQ map
  13014. //
  13015. typedef struct _CM_PCCARD_DEVICE_DATA {
  13016. UCHAR Flags;
  13017. UCHAR ErrorCode;
  13018. USHORT Reserved;
  13019. ULONG BusData;
  13020. ULONG DeviceId;
  13021. ULONG LegacyBaseAddress;
  13022. UCHAR IRQMap[16];
  13023. } CM_PCCARD_DEVICE_DATA, *PCM_PCCARD_DEVICE_DATA;
  13024. // Definitions for Flags
  13025. #define PCCARD_MAP_ERROR 0x01
  13026. #define PCCARD_DEVICE_PCI 0x10
  13027. #define PCCARD_SCAN_DISABLED 0x01
  13028. #define PCCARD_MAP_ZERO 0x02
  13029. #define PCCARD_NO_TIMER 0x03
  13030. #define PCCARD_NO_PIC 0x04
  13031. #define PCCARD_NO_LEGACY_BASE 0x05
  13032. #define PCCARD_DUP_LEGACY_BASE 0x06
  13033. #define PCCARD_NO_CONTROLLERS 0x07
  13034. // begin_wdm
  13035. // begin_ntminiport
  13036. //
  13037. // Defines Resource Options
  13038. //
  13039. #define IO_RESOURCE_PREFERRED 0x01
  13040. #define IO_RESOURCE_DEFAULT 0x02
  13041. #define IO_RESOURCE_ALTERNATIVE 0x08
  13042. //
  13043. // This structure defines one type of resource requested by the driver
  13044. //
  13045. typedef struct _IO_RESOURCE_DESCRIPTOR {
  13046. UCHAR Option;
  13047. UCHAR Type; // use CM_RESOURCE_TYPE
  13048. UCHAR ShareDisposition; // use CM_SHARE_DISPOSITION
  13049. UCHAR Spare1;
  13050. USHORT Flags; // use CM resource flag defines
  13051. USHORT Spare2; // align
  13052. union {
  13053. struct {
  13054. ULONG Length;
  13055. ULONG Alignment;
  13056. PHYSICAL_ADDRESS MinimumAddress;
  13057. PHYSICAL_ADDRESS MaximumAddress;
  13058. } Port;
  13059. struct {
  13060. ULONG Length;
  13061. ULONG Alignment;
  13062. PHYSICAL_ADDRESS MinimumAddress;
  13063. PHYSICAL_ADDRESS MaximumAddress;
  13064. } Memory;
  13065. struct {
  13066. ULONG MinimumVector;
  13067. ULONG MaximumVector;
  13068. } Interrupt;
  13069. struct {
  13070. ULONG MinimumChannel;
  13071. ULONG MaximumChannel;
  13072. } Dma;
  13073. struct {
  13074. ULONG Length;
  13075. ULONG Alignment;
  13076. PHYSICAL_ADDRESS MinimumAddress;
  13077. PHYSICAL_ADDRESS MaximumAddress;
  13078. } Generic;
  13079. struct {
  13080. ULONG Data[3];
  13081. } DevicePrivate;
  13082. //
  13083. // Bus Number information.
  13084. //
  13085. struct {
  13086. ULONG Length;
  13087. ULONG MinBusNumber;
  13088. ULONG MaxBusNumber;
  13089. ULONG Reserved;
  13090. } BusNumber;
  13091. struct {
  13092. ULONG Priority; // use LCPRI_Xxx values in cfg.h
  13093. ULONG Reserved1;
  13094. ULONG Reserved2;
  13095. } ConfigData;
  13096. } u;
  13097. } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
  13098. // end_ntminiport
  13099. typedef struct _IO_RESOURCE_LIST {
  13100. USHORT Version;
  13101. USHORT Revision;
  13102. ULONG Count;
  13103. IO_RESOURCE_DESCRIPTOR Descriptors[1];
  13104. } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
  13105. typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
  13106. ULONG ListSize;
  13107. INTERFACE_TYPE InterfaceType; // unused for WDM
  13108. ULONG BusNumber; // unused for WDM
  13109. ULONG SlotNumber;
  13110. ULONG Reserved[3];
  13111. ULONG AlternativeLists;
  13112. IO_RESOURCE_LIST List[1];
  13113. } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
  13114. //
  13115. // Registry Specific Access Rights.
  13116. //
  13117. #define KEY_QUERY_VALUE (0x0001)
  13118. #define KEY_SET_VALUE (0x0002)
  13119. #define KEY_CREATE_SUB_KEY (0x0004)
  13120. #define KEY_ENUMERATE_SUB_KEYS (0x0008)
  13121. #define KEY_NOTIFY (0x0010)
  13122. #define KEY_CREATE_LINK (0x0020)
  13123. #define KEY_WOW64_32KEY (0x0200)
  13124. #define KEY_WOW64_64KEY (0x0100)
  13125. #define KEY_WOW64_RES (0x0300)
  13126. #define KEY_READ ((STANDARD_RIGHTS_READ |\
  13127. KEY_QUERY_VALUE |\
  13128. KEY_ENUMERATE_SUB_KEYS |\
  13129. KEY_NOTIFY) \
  13130. & \
  13131. (~SYNCHRONIZE))
  13132. #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
  13133. KEY_SET_VALUE |\
  13134. KEY_CREATE_SUB_KEY) \
  13135. & \
  13136. (~SYNCHRONIZE))
  13137. #define KEY_EXECUTE ((KEY_READ) \
  13138. & \
  13139. (~SYNCHRONIZE))
  13140. #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
  13141. KEY_QUERY_VALUE |\
  13142. KEY_SET_VALUE |\
  13143. KEY_CREATE_SUB_KEY |\
  13144. KEY_ENUMERATE_SUB_KEYS |\
  13145. KEY_NOTIFY |\
  13146. KEY_CREATE_LINK) \
  13147. & \
  13148. (~SYNCHRONIZE))
  13149. //
  13150. // Open/Create Options
  13151. //
  13152. #define REG_OPTION_RESERVED (0x00000000L) // Parameter is reserved
  13153. #define REG_OPTION_NON_VOLATILE (0x00000000L) // Key is preserved
  13154. // when system is rebooted
  13155. #define REG_OPTION_VOLATILE (0x00000001L) // Key is not preserved
  13156. // when system is rebooted
  13157. #define REG_OPTION_CREATE_LINK (0x00000002L) // Created key is a
  13158. // symbolic link
  13159. #define REG_OPTION_BACKUP_RESTORE (0x00000004L) // open for backup or restore
  13160. // special access rules
  13161. // privilege required
  13162. #define REG_OPTION_OPEN_LINK (0x00000008L) // Open symbolic link
  13163. #define REG_LEGAL_OPTION \
  13164. (REG_OPTION_RESERVED |\
  13165. REG_OPTION_NON_VOLATILE |\
  13166. REG_OPTION_VOLATILE |\
  13167. REG_OPTION_CREATE_LINK |\
  13168. REG_OPTION_BACKUP_RESTORE |\
  13169. REG_OPTION_OPEN_LINK)
  13170. //
  13171. // Key creation/open disposition
  13172. //
  13173. #define REG_CREATED_NEW_KEY (0x00000001L) // New Registry Key created
  13174. #define REG_OPENED_EXISTING_KEY (0x00000002L) // Existing Key opened
  13175. //
  13176. // hive format to be used by Reg(Nt)SaveKeyEx
  13177. //
  13178. #define REG_STANDARD_FORMAT 1
  13179. #define REG_LATEST_FORMAT 2
  13180. #define REG_NO_COMPRESSION 4
  13181. //
  13182. // Key restore flags
  13183. //
  13184. #define REG_WHOLE_HIVE_VOLATILE (0x00000001L) // Restore whole hive volatile
  13185. #define REG_REFRESH_HIVE (0x00000002L) // Unwind changes to last flush
  13186. #define REG_NO_LAZY_FLUSH (0x00000004L) // Never lazy flush this hive
  13187. #define REG_FORCE_RESTORE (0x00000008L) // Force the restore process even when we have open handles on subkeys
  13188. //
  13189. // Key query structures
  13190. //
  13191. typedef struct _KEY_BASIC_INFORMATION {
  13192. LARGE_INTEGER LastWriteTime;
  13193. ULONG TitleIndex;
  13194. ULONG NameLength;
  13195. WCHAR Name[1]; // Variable length string
  13196. } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
  13197. typedef struct _KEY_NODE_INFORMATION {
  13198. LARGE_INTEGER LastWriteTime;
  13199. ULONG TitleIndex;
  13200. ULONG ClassOffset;
  13201. ULONG ClassLength;
  13202. ULONG NameLength;
  13203. WCHAR Name[1]; // Variable length string
  13204. // Class[1]; // Variable length string not declared
  13205. } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
  13206. typedef struct _KEY_FULL_INFORMATION {
  13207. LARGE_INTEGER LastWriteTime;
  13208. ULONG TitleIndex;
  13209. ULONG ClassOffset;
  13210. ULONG ClassLength;
  13211. ULONG SubKeys;
  13212. ULONG MaxNameLen;
  13213. ULONG MaxClassLen;
  13214. ULONG Values;
  13215. ULONG MaxValueNameLen;
  13216. ULONG MaxValueDataLen;
  13217. WCHAR Class[1]; // Variable length
  13218. } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
  13219. // end_wdm
  13220. typedef struct _KEY_NAME_INFORMATION {
  13221. ULONG NameLength;
  13222. WCHAR Name[1]; // Variable length string
  13223. } KEY_NAME_INFORMATION, *PKEY_NAME_INFORMATION;
  13224. typedef struct _KEY_CACHED_INFORMATION {
  13225. LARGE_INTEGER LastWriteTime;
  13226. ULONG TitleIndex;
  13227. ULONG SubKeys;
  13228. ULONG MaxNameLen;
  13229. ULONG Values;
  13230. ULONG MaxValueNameLen;
  13231. ULONG MaxValueDataLen;
  13232. ULONG NameLength;
  13233. WCHAR Name[1]; // Variable length string
  13234. } KEY_CACHED_INFORMATION, *PKEY_CACHED_INFORMATION;
  13235. typedef struct _KEY_FLAGS_INFORMATION {
  13236. ULONG UserFlags;
  13237. } KEY_FLAGS_INFORMATION, *PKEY_FLAGS_INFORMATION;
  13238. // begin_wdm
  13239. typedef enum _KEY_INFORMATION_CLASS {
  13240. KeyBasicInformation,
  13241. KeyNodeInformation,
  13242. KeyFullInformation
  13243. // end_wdm
  13244. ,
  13245. KeyNameInformation,
  13246. KeyCachedInformation,
  13247. KeyFlagsInformation
  13248. // begin_wdm
  13249. } KEY_INFORMATION_CLASS;
  13250. typedef struct _KEY_WRITE_TIME_INFORMATION {
  13251. LARGE_INTEGER LastWriteTime;
  13252. } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
  13253. typedef struct _KEY_USER_FLAGS_INFORMATION {
  13254. ULONG UserFlags;
  13255. } KEY_USER_FLAGS_INFORMATION, *PKEY_USER_FLAGS_INFORMATION;
  13256. typedef enum _KEY_SET_INFORMATION_CLASS {
  13257. KeyWriteTimeInformation,
  13258. KeyUserFlagsInformation
  13259. } KEY_SET_INFORMATION_CLASS;
  13260. //
  13261. // Value entry query structures
  13262. //
  13263. typedef struct _KEY_VALUE_BASIC_INFORMATION {
  13264. ULONG TitleIndex;
  13265. ULONG Type;
  13266. ULONG NameLength;
  13267. WCHAR Name[1]; // Variable size
  13268. } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
  13269. typedef struct _KEY_VALUE_FULL_INFORMATION {
  13270. ULONG TitleIndex;
  13271. ULONG Type;
  13272. ULONG DataOffset;
  13273. ULONG DataLength;
  13274. ULONG NameLength;
  13275. WCHAR Name[1]; // Variable size
  13276. // Data[1]; // Variable size data not declared
  13277. } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
  13278. typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
  13279. ULONG TitleIndex;
  13280. ULONG Type;
  13281. ULONG DataLength;
  13282. UCHAR Data[1]; // Variable size
  13283. } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
  13284. typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
  13285. ULONG Type;
  13286. ULONG DataLength;
  13287. UCHAR Data[1]; // Variable size
  13288. } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
  13289. typedef struct _KEY_VALUE_ENTRY {
  13290. PUNICODE_STRING ValueName;
  13291. ULONG DataLength;
  13292. ULONG DataOffset;
  13293. ULONG Type;
  13294. } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
  13295. typedef enum _KEY_VALUE_INFORMATION_CLASS {
  13296. KeyValueBasicInformation,
  13297. KeyValueFullInformation,
  13298. KeyValuePartialInformation,
  13299. KeyValueFullInformationAlign64,
  13300. KeyValuePartialInformationAlign64
  13301. } KEY_VALUE_INFORMATION_CLASS;
  13302. //
  13303. // Section Information Structures.
  13304. //
  13305. typedef enum _SECTION_INHERIT {
  13306. ViewShare = 1,
  13307. ViewUnmap = 2
  13308. } SECTION_INHERIT;
  13309. //
  13310. // Section Access Rights.
  13311. //
  13312. // begin_winnt
  13313. #define SECTION_QUERY 0x0001
  13314. #define SECTION_MAP_WRITE 0x0002
  13315. #define SECTION_MAP_READ 0x0004
  13316. #define SECTION_MAP_EXECUTE 0x0008
  13317. #define SECTION_EXTEND_SIZE 0x0010
  13318. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  13319. SECTION_MAP_WRITE | \
  13320. SECTION_MAP_READ | \
  13321. SECTION_MAP_EXECUTE | \
  13322. SECTION_EXTEND_SIZE)
  13323. // end_winnt
  13324. #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
  13325. #define PAGE_NOACCESS 0x01 // winnt
  13326. #define PAGE_READONLY 0x02 // winnt
  13327. #define PAGE_READWRITE 0x04 // winnt
  13328. #define PAGE_WRITECOPY 0x08 // winnt
  13329. #define PAGE_EXECUTE 0x10 // winnt
  13330. #define PAGE_EXECUTE_READ 0x20 // winnt
  13331. #define PAGE_EXECUTE_READWRITE 0x40 // winnt
  13332. #define PAGE_EXECUTE_WRITECOPY 0x80 // winnt
  13333. #define PAGE_GUARD 0x100 // winnt
  13334. #define PAGE_NOCACHE 0x200 // winnt
  13335. #define PAGE_WRITECOMBINE 0x400 // winnt
  13336. #define MEM_COMMIT 0x1000
  13337. #define MEM_RESERVE 0x2000
  13338. #define MEM_DECOMMIT 0x4000
  13339. #define MEM_RELEASE 0x8000
  13340. #define MEM_FREE 0x10000
  13341. #define MEM_PRIVATE 0x20000
  13342. #define MEM_MAPPED 0x40000
  13343. #define MEM_RESET 0x80000
  13344. #define MEM_TOP_DOWN 0x100000
  13345. #define MEM_LARGE_PAGES 0x20000000
  13346. #define MEM_4MB_PAGES 0x80000000
  13347. #define SEC_RESERVE 0x4000000
  13348. //
  13349. // Exception flag definitions.
  13350. //
  13351. // begin_winnt
  13352. #define EXCEPTION_NONCONTINUABLE 0x1 // Noncontinuable exception
  13353. // end_winnt
  13354. //
  13355. // Define maximum number of exception parameters.
  13356. //
  13357. // begin_winnt
  13358. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  13359. //
  13360. // Exception record definition.
  13361. //
  13362. typedef struct _EXCEPTION_RECORD {
  13363. NTSTATUS ExceptionCode;
  13364. ULONG ExceptionFlags;
  13365. struct _EXCEPTION_RECORD *ExceptionRecord;
  13366. PVOID ExceptionAddress;
  13367. ULONG NumberParameters;
  13368. ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  13369. } EXCEPTION_RECORD;
  13370. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  13371. typedef struct _EXCEPTION_RECORD32 {
  13372. NTSTATUS ExceptionCode;
  13373. ULONG ExceptionFlags;
  13374. ULONG ExceptionRecord;
  13375. ULONG ExceptionAddress;
  13376. ULONG NumberParameters;
  13377. ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  13378. } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
  13379. typedef struct _EXCEPTION_RECORD64 {
  13380. NTSTATUS ExceptionCode;
  13381. ULONG ExceptionFlags;
  13382. ULONG64 ExceptionRecord;
  13383. ULONG64 ExceptionAddress;
  13384. ULONG NumberParameters;
  13385. ULONG __unusedAlignment;
  13386. ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  13387. } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
  13388. //
  13389. // Typedef for pointer returned by exception_info()
  13390. //
  13391. typedef struct _EXCEPTION_POINTERS {
  13392. PEXCEPTION_RECORD ExceptionRecord;
  13393. PCONTEXT ContextRecord;
  13394. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  13395. // end_winnt
  13396. #ifdef _WIN64
  13397. #define PORT_MAXIMUM_MESSAGE_LENGTH 512
  13398. #else
  13399. #define PORT_MAXIMUM_MESSAGE_LENGTH 256
  13400. #endif
  13401. //
  13402. // Define I/O Driver error log packet structure. This structure is filled in
  13403. // by the driver.
  13404. //
  13405. typedef struct _IO_ERROR_LOG_PACKET {
  13406. UCHAR MajorFunctionCode;
  13407. UCHAR RetryCount;
  13408. USHORT DumpDataSize;
  13409. USHORT NumberOfStrings;
  13410. USHORT StringOffset;
  13411. USHORT EventCategory;
  13412. NTSTATUS ErrorCode;
  13413. ULONG UniqueErrorValue;
  13414. NTSTATUS FinalStatus;
  13415. ULONG SequenceNumber;
  13416. ULONG IoControlCode;
  13417. LARGE_INTEGER DeviceOffset;
  13418. ULONG DumpData[1];
  13419. }IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
  13420. //
  13421. // Define the I/O error log message. This message is sent by the error log
  13422. // thread over the lpc port.
  13423. //
  13424. typedef struct _IO_ERROR_LOG_MESSAGE {
  13425. USHORT Type;
  13426. USHORT Size;
  13427. USHORT DriverNameLength;
  13428. LARGE_INTEGER TimeStamp;
  13429. ULONG DriverNameOffset;
  13430. IO_ERROR_LOG_PACKET EntryData;
  13431. }IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
  13432. //
  13433. // Define the maximum message size that will be sent over the LPC to the
  13434. // application reading the error log entries.
  13435. //
  13436. //
  13437. // Regardless of LPC size restrictions, ERROR_LOG_MAXIMUM_SIZE must remain
  13438. // a value that can fit in a UCHAR.
  13439. //
  13440. #define ERROR_LOG_LIMIT_SIZE (256-16)
  13441. //
  13442. // This limit, exclusive of IO_ERROR_LOG_MESSAGE_HEADER_LENGTH, also applies
  13443. // to IO_ERROR_LOG_MESSAGE_LENGTH
  13444. //
  13445. #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
  13446. sizeof(IO_ERROR_LOG_PACKET) + \
  13447. (sizeof(WCHAR) * 40))
  13448. #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
  13449. (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  13450. //
  13451. // IO_ERROR_LOG_MESSAGE_LENGTH is
  13452. // min(PORT_MAXIMUM_MESSAGE_LENGTH, ERROR_LOG_MESSAGE_LIMIT_SIZE)
  13453. //
  13454. #define IO_ERROR_LOG_MESSAGE_LENGTH \
  13455. ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
  13456. ERROR_LOG_MESSAGE_LIMIT_SIZE : \
  13457. PORT_MAXIMUM_MESSAGE_LENGTH)
  13458. //
  13459. // Define the maximum packet size a driver can allocate.
  13460. //
  13461. #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
  13462. IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  13463. //
  13464. // Event Specific Access Rights.
  13465. //
  13466. #define EVENT_QUERY_STATE 0x0001
  13467. #define EVENT_MODIFY_STATE 0x0002 // winnt
  13468. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) // winnt
  13469. //
  13470. // Semaphore Specific Access Rights.
  13471. //
  13472. #define SEMAPHORE_QUERY_STATE 0x0001
  13473. #define SEMAPHORE_MODIFY_STATE 0x0002 // winnt
  13474. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) // winnt
  13475. //
  13476. // Driver Verifier Definitions
  13477. //
  13478. typedef ULONG_PTR (*PDRIVER_VERIFIER_THUNK_ROUTINE) (
  13479. IN PVOID Context
  13480. );
  13481. //
  13482. // This structure is passed in by drivers that want to thunk callers of
  13483. // their exports.
  13484. //
  13485. typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
  13486. PDRIVER_VERIFIER_THUNK_ROUTINE PristineRoutine;
  13487. PDRIVER_VERIFIER_THUNK_ROUTINE NewRoutine;
  13488. } DRIVER_VERIFIER_THUNK_PAIRS, *PDRIVER_VERIFIER_THUNK_PAIRS;
  13489. //
  13490. // Driver Verifier flags.
  13491. //
  13492. #define DRIVER_VERIFIER_SPECIAL_POOLING 0x0001
  13493. #define DRIVER_VERIFIER_FORCE_IRQL_CHECKING 0x0002
  13494. #define DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES 0x0004
  13495. #define DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS 0x0008
  13496. #define DRIVER_VERIFIER_IO_CHECKING 0x0010
  13497. //
  13498. // Defined processor features
  13499. //
  13500. #define PF_FLOATING_POINT_PRECISION_ERRATA 0 // winnt
  13501. #define PF_FLOATING_POINT_EMULATED 1 // winnt
  13502. #define PF_COMPARE_EXCHANGE_DOUBLE 2 // winnt
  13503. #define PF_MMX_INSTRUCTIONS_AVAILABLE 3 // winnt
  13504. #define PF_PPC_MOVEMEM_64BIT_OK 4 // winnt
  13505. #define PF_ALPHA_BYTE_INSTRUCTIONS 5 // winnt
  13506. #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6 // winnt
  13507. #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7 // winnt
  13508. #define PF_RDTSC_INSTRUCTION_AVAILABLE 8 // winnt
  13509. #define PF_PAE_ENABLED 9 // winnt
  13510. #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10 // winnt
  13511. typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE {
  13512. StandardDesign, // None == 0 == standard design
  13513. NEC98x86, // NEC PC98xx series on X86
  13514. EndAlternatives // past end of known alternatives
  13515. } ALTERNATIVE_ARCHITECTURE_TYPE;
  13516. // correctly define these run-time definitions for non X86 machines
  13517. #ifndef _X86_
  13518. #ifndef IsNEC_98
  13519. #define IsNEC_98 (FALSE)
  13520. #endif
  13521. #ifndef IsNotNEC_98
  13522. #define IsNotNEC_98 (TRUE)
  13523. #endif
  13524. #ifndef SetNEC_98
  13525. #define SetNEC_98
  13526. #endif
  13527. #ifndef SetNotNEC_98
  13528. #define SetNotNEC_98
  13529. #endif
  13530. #endif
  13531. #define PROCESSOR_FEATURE_MAX 64
  13532. // end_wdm
  13533. #if defined(REMOTE_BOOT)
  13534. //
  13535. // Defined system flags.
  13536. //
  13537. /* the following two lines should be tagged with "winnt" when REMOTE_BOOT is on. */
  13538. #define SYSTEM_FLAG_REMOTE_BOOT_CLIENT 0x00000001
  13539. #define SYSTEM_FLAG_DISKLESS_CLIENT 0x00000002
  13540. #endif // defined(REMOTE_BOOT)
  13541. //
  13542. // Define data shared between kernel and user mode.
  13543. //
  13544. // N.B. User mode has read only access to this data
  13545. //
  13546. #ifdef _MAC
  13547. #pragma warning( disable : 4121)
  13548. #endif
  13549. //
  13550. // Note: When adding a new field that's processor-architecture-specific (for example, bound with #if i386),
  13551. // then place this field to be the last element in the KUSER_SHARED_DATA so that offsets into common
  13552. // fields are the same for Wow6432 and Win64.
  13553. //
  13554. typedef struct _KUSER_SHARED_DATA {
  13555. //
  13556. // Current low 32-bit of tick count and tick count multiplier.
  13557. //
  13558. // N.B. The tick count is updated each time the clock ticks.
  13559. //
  13560. volatile ULONG TickCountLow;
  13561. ULONG TickCountMultiplier;
  13562. //
  13563. // Current 64-bit interrupt time in 100ns units.
  13564. //
  13565. volatile KSYSTEM_TIME InterruptTime;
  13566. //
  13567. // Current 64-bit system time in 100ns units.
  13568. //
  13569. volatile KSYSTEM_TIME SystemTime;
  13570. //
  13571. // Current 64-bit time zone bias.
  13572. //
  13573. volatile KSYSTEM_TIME TimeZoneBias;
  13574. //
  13575. // Support image magic number range for the host system.
  13576. //
  13577. // N.B. This is an inclusive range.
  13578. //
  13579. USHORT ImageNumberLow;
  13580. USHORT ImageNumberHigh;
  13581. //
  13582. // Copy of system root in Unicode
  13583. //
  13584. WCHAR NtSystemRoot[ 260 ];
  13585. //
  13586. // Maximum stack trace depth if tracing enabled.
  13587. //
  13588. ULONG MaxStackTraceDepth;
  13589. //
  13590. // Crypto Exponent
  13591. //
  13592. ULONG CryptoExponent;
  13593. //
  13594. // TimeZoneId
  13595. //
  13596. ULONG TimeZoneId;
  13597. ULONG Reserved2[ 8 ];
  13598. //
  13599. // product type
  13600. //
  13601. NT_PRODUCT_TYPE NtProductType;
  13602. BOOLEAN ProductTypeIsValid;
  13603. //
  13604. // NT Version. Note that each process sees a version from its PEB, but
  13605. // if the process is running with an altered view of the system version,
  13606. // the following two fields are used to correctly identify the version
  13607. //
  13608. ULONG NtMajorVersion;
  13609. ULONG NtMinorVersion;
  13610. //
  13611. // Processor Feature Bits
  13612. //
  13613. BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
  13614. //
  13615. // Reserved fields - do not use
  13616. //
  13617. ULONG Reserved1;
  13618. ULONG Reserved3;
  13619. //
  13620. // Time slippage while in debugger
  13621. //
  13622. volatile ULONG TimeSlip;
  13623. //
  13624. // Alternative system architecture. Example: NEC PC98xx on x86
  13625. //
  13626. ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
  13627. //
  13628. // If the system is an evaluation unit, the following field contains the
  13629. // date and time that the evaluation unit expires. A value of 0 indicates
  13630. // that there is no expiration. A non-zero value is the UTC absolute time
  13631. // that the system expires.
  13632. //
  13633. LARGE_INTEGER SystemExpirationDate;
  13634. //
  13635. // Suite Support
  13636. //
  13637. ULONG SuiteMask;
  13638. //
  13639. // TRUE if a kernel debugger is connected/enabled
  13640. //
  13641. BOOLEAN KdDebuggerEnabled;
  13642. //
  13643. // Current console session Id. Always zero on non-TS systems
  13644. //
  13645. volatile ULONG ActiveConsoleId;
  13646. //
  13647. // Force-dismounts cause handles to become invalid. Rather than
  13648. // always probe handles, we maintain a serial number of
  13649. // dismounts that clients can use to see if they need to probe
  13650. // handles.
  13651. //
  13652. volatile ULONG DismountCount;
  13653. //
  13654. // This field indicates the status of the 64-bit COM+ package on the system.
  13655. // It indicates whether the Itermediate Language (IL) COM+ images need to
  13656. // use the 64-bit COM+ runtime or the 32-bit COM+ runtime.
  13657. //
  13658. ULONG ComPlusPackage;
  13659. //
  13660. // Time in tick count for system-wide last user input across all
  13661. // terminal sessions. For MP performance, it is not updated all
  13662. // the time (e.g. once a minute per session). It is used for idle
  13663. // detection.
  13664. //
  13665. ULONG LastSystemRITEventTickCount;
  13666. //
  13667. // Number of physical pages in the system. This can dynamically
  13668. // change as physical memory can be added or removed from a running
  13669. // system.
  13670. //
  13671. ULONG NumberOfPhysicalPages;
  13672. //
  13673. // True if the system was booted in safe boot mode.
  13674. //
  13675. BOOLEAN SafeBootMode;
  13676. //
  13677. // The following field is used for Heap and CritSec Tracing
  13678. // The last bit is set for Critical Sec Collision tracing and
  13679. // second Last bit is for Heap Tracing
  13680. // Also the first 16 bits are used as counter.
  13681. //
  13682. ULONG TraceLogging;
  13683. #if defined(i386)
  13684. //
  13685. // Depending on the processor, the code for fast system call
  13686. // will differ, the following buffer is filled with the appropriate
  13687. // code sequence and user mode code will branch through it.
  13688. //
  13689. // (32 bytes, using ULONGLONG for alignment).
  13690. //
  13691. ULONGLONG Fill0; // alignment
  13692. ULONGLONG SystemCall[4];
  13693. #endif
  13694. } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
  13695. #ifdef _MAC
  13696. #pragma warning( default : 4121 )
  13697. #endif
  13698. //
  13699. #if defined(_X86_)
  13700. #define PAUSE_PROCESSOR _asm { rep nop }
  13701. #else
  13702. #define PAUSE_PROCESSOR
  13703. #endif
  13704. //
  13705. // Interrupt modes.
  13706. //
  13707. typedef enum _KINTERRUPT_MODE {
  13708. LevelSensitive,
  13709. Latched
  13710. } KINTERRUPT_MODE;
  13711. //
  13712. // Wait reasons
  13713. //
  13714. typedef enum _KWAIT_REASON {
  13715. Executive,
  13716. FreePage,
  13717. PageIn,
  13718. PoolAllocation,
  13719. DelayExecution,
  13720. Suspended,
  13721. UserRequest,
  13722. WrExecutive,
  13723. WrFreePage,
  13724. WrPageIn,
  13725. WrPoolAllocation,
  13726. WrDelayExecution,
  13727. WrSuspended,
  13728. WrUserRequest,
  13729. WrEventPair,
  13730. WrQueue,
  13731. WrLpcReceive,
  13732. WrLpcReply,
  13733. WrVirtualMemory,
  13734. WrPageOut,
  13735. WrRendezvous,
  13736. Spare2,
  13737. Spare3,
  13738. Spare4,
  13739. Spare5,
  13740. Spare6,
  13741. WrKernel,
  13742. MaximumWaitReason
  13743. } KWAIT_REASON;
  13744. // end_ntddk end_wdm end_nthal
  13745. //
  13746. // Miscellaneous type definitions
  13747. //
  13748. // APC state
  13749. //
  13750. typedef struct _KAPC_STATE {
  13751. LIST_ENTRY ApcListHead[MaximumMode];
  13752. struct _KPROCESS *Process;
  13753. BOOLEAN KernelApcInProgress;
  13754. BOOLEAN KernelApcPending;
  13755. BOOLEAN UserApcPending;
  13756. } KAPC_STATE, *PKAPC_STATE, *RESTRICTED_POINTER PRKAPC_STATE;
  13757. typedef struct _KWAIT_BLOCK {
  13758. LIST_ENTRY WaitListEntry;
  13759. struct _KTHREAD *RESTRICTED_POINTER Thread;
  13760. PVOID Object;
  13761. struct _KWAIT_BLOCK *RESTRICTED_POINTER NextWaitBlock;
  13762. USHORT WaitKey;
  13763. USHORT WaitType;
  13764. } KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
  13765. //
  13766. // Thread start function
  13767. //
  13768. typedef
  13769. VOID
  13770. (*PKSTART_ROUTINE) (
  13771. IN PVOID StartContext
  13772. );
  13773. //
  13774. // Kernel object structure definitions
  13775. //
  13776. //
  13777. // Device Queue object and entry
  13778. //
  13779. typedef struct _KDEVICE_QUEUE {
  13780. CSHORT Type;
  13781. CSHORT Size;
  13782. LIST_ENTRY DeviceListHead;
  13783. KSPIN_LOCK Lock;
  13784. BOOLEAN Busy;
  13785. } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
  13786. typedef struct _KDEVICE_QUEUE_ENTRY {
  13787. LIST_ENTRY DeviceListEntry;
  13788. ULONG SortKey;
  13789. BOOLEAN Inserted;
  13790. } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY, *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
  13791. //
  13792. // Define the interrupt service function type and the empty struct
  13793. // type.
  13794. //
  13795. typedef
  13796. BOOLEAN
  13797. (*PKSERVICE_ROUTINE) (
  13798. IN struct _KINTERRUPT *Interrupt,
  13799. IN PVOID ServiceContext
  13800. );
  13801. //
  13802. // Mutant object
  13803. //
  13804. typedef struct _KMUTANT {
  13805. DISPATCHER_HEADER Header;
  13806. LIST_ENTRY MutantListEntry;
  13807. struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
  13808. BOOLEAN Abandoned;
  13809. UCHAR ApcDisable;
  13810. } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
  13811. // end_ntddk end_wdm end_ntosp
  13812. //
  13813. // Queue object
  13814. //
  13815. // begin_ntosp
  13816. typedef struct _KQUEUE {
  13817. DISPATCHER_HEADER Header;
  13818. LIST_ENTRY EntryListHead;
  13819. ULONG CurrentCount;
  13820. ULONG MaximumCount;
  13821. LIST_ENTRY ThreadListHead;
  13822. } KQUEUE, *PKQUEUE, *RESTRICTED_POINTER PRKQUEUE;
  13823. // end_ntosp
  13824. // begin_ntddk begin_wdm begin_ntosp
  13825. //
  13826. //
  13827. // Semaphore object
  13828. //
  13829. typedef struct _KSEMAPHORE {
  13830. DISPATCHER_HEADER Header;
  13831. LONG Limit;
  13832. } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
  13833. //
  13834. // DPC object
  13835. //
  13836. NTKERNELAPI
  13837. VOID
  13838. KeInitializeDpc (
  13839. IN PRKDPC Dpc,
  13840. IN PKDEFERRED_ROUTINE DeferredRoutine,
  13841. IN PVOID DeferredContext
  13842. );
  13843. NTKERNELAPI
  13844. BOOLEAN
  13845. KeInsertQueueDpc (
  13846. IN PRKDPC Dpc,
  13847. IN PVOID SystemArgument1,
  13848. IN PVOID SystemArgument2
  13849. );
  13850. NTKERNELAPI
  13851. BOOLEAN
  13852. KeRemoveQueueDpc (
  13853. IN PRKDPC Dpc
  13854. );
  13855. // end_wdm
  13856. NTKERNELAPI
  13857. VOID
  13858. KeSetImportanceDpc (
  13859. IN PRKDPC Dpc,
  13860. IN KDPC_IMPORTANCE Importance
  13861. );
  13862. NTKERNELAPI
  13863. VOID
  13864. KeSetTargetProcessorDpc (
  13865. IN PRKDPC Dpc,
  13866. IN CCHAR Number
  13867. );
  13868. // begin_wdm
  13869. NTKERNELAPI
  13870. VOID
  13871. KeFlushQueuedDpcs (
  13872. VOID
  13873. );
  13874. //
  13875. // Device queue object
  13876. //
  13877. NTKERNELAPI
  13878. VOID
  13879. KeInitializeDeviceQueue (
  13880. IN PKDEVICE_QUEUE DeviceQueue
  13881. );
  13882. NTKERNELAPI
  13883. BOOLEAN
  13884. KeInsertDeviceQueue (
  13885. IN PKDEVICE_QUEUE DeviceQueue,
  13886. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  13887. );
  13888. NTKERNELAPI
  13889. BOOLEAN
  13890. KeInsertByKeyDeviceQueue (
  13891. IN PKDEVICE_QUEUE DeviceQueue,
  13892. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
  13893. IN ULONG SortKey
  13894. );
  13895. NTKERNELAPI
  13896. PKDEVICE_QUEUE_ENTRY
  13897. KeRemoveDeviceQueue (
  13898. IN PKDEVICE_QUEUE DeviceQueue
  13899. );
  13900. NTKERNELAPI
  13901. PKDEVICE_QUEUE_ENTRY
  13902. KeRemoveByKeyDeviceQueue (
  13903. IN PKDEVICE_QUEUE DeviceQueue,
  13904. IN ULONG SortKey
  13905. );
  13906. NTKERNELAPI
  13907. PKDEVICE_QUEUE_ENTRY
  13908. KeRemoveByKeyDeviceQueueIfBusy (
  13909. IN PKDEVICE_QUEUE DeviceQueue,
  13910. IN ULONG SortKey
  13911. );
  13912. NTKERNELAPI
  13913. BOOLEAN
  13914. KeRemoveEntryDeviceQueue (
  13915. IN PKDEVICE_QUEUE DeviceQueue,
  13916. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  13917. );
  13918. //
  13919. // Kernel dispatcher object functions
  13920. //
  13921. // Event Object
  13922. //
  13923. NTKERNELAPI
  13924. VOID
  13925. KeInitializeEvent (
  13926. IN PRKEVENT Event,
  13927. IN EVENT_TYPE Type,
  13928. IN BOOLEAN State
  13929. );
  13930. NTKERNELAPI
  13931. VOID
  13932. KeClearEvent (
  13933. IN PRKEVENT Event
  13934. );
  13935. NTKERNELAPI
  13936. LONG
  13937. KePulseEvent (
  13938. IN PRKEVENT Event,
  13939. IN KPRIORITY Increment,
  13940. IN BOOLEAN Wait
  13941. );
  13942. NTKERNELAPI
  13943. LONG
  13944. KeReadStateEvent (
  13945. IN PRKEVENT Event
  13946. );
  13947. NTKERNELAPI
  13948. LONG
  13949. KeResetEvent (
  13950. IN PRKEVENT Event
  13951. );
  13952. NTKERNELAPI
  13953. LONG
  13954. KeSetEvent (
  13955. IN PRKEVENT Event,
  13956. IN KPRIORITY Increment,
  13957. IN BOOLEAN Wait
  13958. );
  13959. NTKERNELAPI
  13960. VOID
  13961. KeInitializeMutant (
  13962. IN PRKMUTANT Mutant,
  13963. IN BOOLEAN InitialOwner
  13964. );
  13965. LONG
  13966. KeReadStateMutant (
  13967. IN PRKMUTANT Mutant
  13968. );
  13969. NTKERNELAPI
  13970. LONG
  13971. KeReleaseMutant (
  13972. IN PRKMUTANT Mutant,
  13973. IN KPRIORITY Increment,
  13974. IN BOOLEAN Abandoned,
  13975. IN BOOLEAN Wait
  13976. );
  13977. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  13978. //
  13979. // Mutex object
  13980. //
  13981. NTKERNELAPI
  13982. VOID
  13983. KeInitializeMutex (
  13984. IN PRKMUTEX Mutex,
  13985. IN ULONG Level
  13986. );
  13987. NTKERNELAPI
  13988. LONG
  13989. KeReadStateMutex (
  13990. IN PRKMUTEX Mutex
  13991. );
  13992. NTKERNELAPI
  13993. LONG
  13994. KeReleaseMutex (
  13995. IN PRKMUTEX Mutex,
  13996. IN BOOLEAN Wait
  13997. );
  13998. // end_ntddk end_wdm
  13999. //
  14000. // Queue Object.
  14001. //
  14002. NTKERNELAPI
  14003. VOID
  14004. KeInitializeQueue (
  14005. IN PRKQUEUE Queue,
  14006. IN ULONG Count OPTIONAL
  14007. );
  14008. NTKERNELAPI
  14009. LONG
  14010. KeReadStateQueue (
  14011. IN PRKQUEUE Queue
  14012. );
  14013. NTKERNELAPI
  14014. LONG
  14015. KeInsertQueue (
  14016. IN PRKQUEUE Queue,
  14017. IN PLIST_ENTRY Entry
  14018. );
  14019. NTKERNELAPI
  14020. LONG
  14021. KeInsertHeadQueue (
  14022. IN PRKQUEUE Queue,
  14023. IN PLIST_ENTRY Entry
  14024. );
  14025. NTKERNELAPI
  14026. PLIST_ENTRY
  14027. KeRemoveQueue (
  14028. IN PRKQUEUE Queue,
  14029. IN KPROCESSOR_MODE WaitMode,
  14030. IN PLARGE_INTEGER Timeout OPTIONAL
  14031. );
  14032. PLIST_ENTRY
  14033. KeRundownQueue (
  14034. IN PRKQUEUE Queue
  14035. );
  14036. // begin_ntddk begin_wdm
  14037. //
  14038. // Semaphore object
  14039. //
  14040. NTKERNELAPI
  14041. VOID
  14042. KeInitializeSemaphore (
  14043. IN PRKSEMAPHORE Semaphore,
  14044. IN LONG Count,
  14045. IN LONG Limit
  14046. );
  14047. NTKERNELAPI
  14048. LONG
  14049. KeReadStateSemaphore (
  14050. IN PRKSEMAPHORE Semaphore
  14051. );
  14052. NTKERNELAPI
  14053. LONG
  14054. KeReleaseSemaphore (
  14055. IN PRKSEMAPHORE Semaphore,
  14056. IN KPRIORITY Increment,
  14057. IN LONG Adjustment,
  14058. IN BOOLEAN Wait
  14059. );
  14060. NTKERNELAPI
  14061. VOID
  14062. KeAttachProcess (
  14063. IN PRKPROCESS Process
  14064. );
  14065. NTKERNELAPI
  14066. VOID
  14067. KeDetachProcess (
  14068. VOID
  14069. );
  14070. NTKERNELAPI
  14071. VOID
  14072. KeStackAttachProcess (
  14073. IN PRKPROCESS PROCESS,
  14074. OUT PRKAPC_STATE ApcState
  14075. );
  14076. NTKERNELAPI
  14077. VOID
  14078. KeUnstackDetachProcess (
  14079. IN PRKAPC_STATE ApcState
  14080. );
  14081. NTKERNELAPI
  14082. NTSTATUS
  14083. KeDelayExecutionThread (
  14084. IN KPROCESSOR_MODE WaitMode,
  14085. IN BOOLEAN Alertable,
  14086. IN PLARGE_INTEGER Interval
  14087. );
  14088. NTKERNELAPI
  14089. KPRIORITY
  14090. KeQueryPriorityThread (
  14091. IN PKTHREAD Thread
  14092. );
  14093. NTKERNELAPI
  14094. ULONG
  14095. KeQueryRuntimeThread (
  14096. IN PKTHREAD Thread,
  14097. OUT PULONG UserTime
  14098. );
  14099. NTKERNELAPI
  14100. LONG
  14101. KeSetBasePriorityThread (
  14102. IN PKTHREAD Thread,
  14103. IN LONG Increment
  14104. );
  14105. NTKERNELAPI
  14106. CCHAR
  14107. KeSetIdealProcessorThread (
  14108. IN PKTHREAD Thread,
  14109. IN CCHAR Processor
  14110. );
  14111. // begin_ntosp
  14112. NTKERNELAPI
  14113. BOOLEAN
  14114. KeSetKernelStackSwapEnable (
  14115. IN BOOLEAN Enable
  14116. );
  14117. NTKERNELAPI
  14118. KPRIORITY
  14119. KeSetPriorityThread (
  14120. IN PKTHREAD Thread,
  14121. IN KPRIORITY Priority
  14122. );
  14123. #if ((defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) ||defined(_NTHAL_)) && !defined(_NTSYSTEM_DRIVER_) || defined(_NTOSP_))
  14124. // begin_wdm
  14125. NTKERNELAPI
  14126. VOID
  14127. KeEnterCriticalRegion (
  14128. VOID
  14129. );
  14130. NTKERNELAPI
  14131. VOID
  14132. KeLeaveCriticalRegion (
  14133. VOID
  14134. );
  14135. NTKERNELAPI
  14136. BOOLEAN
  14137. KeAreApcsDisabled(
  14138. VOID
  14139. );
  14140. // end_wdm
  14141. #else
  14142. //++
  14143. //
  14144. // VOID
  14145. // KeEnterCriticalRegion (
  14146. // VOID
  14147. // )
  14148. //
  14149. //
  14150. // Routine Description:
  14151. //
  14152. // This function disables kernel APC's.
  14153. //
  14154. // N.B. The following code does not require any interlocks. There are
  14155. // two cases of interest: 1) On an MP system, the thread cannot
  14156. // be running on two processors as once, and 2) if the thread is
  14157. // is interrupted to deliver a kernel mode APC which also calls
  14158. // this routine, the values read and stored will stack and unstack
  14159. // properly.
  14160. //
  14161. // Arguments:
  14162. //
  14163. // None.
  14164. //
  14165. // Return Value:
  14166. //
  14167. // None.
  14168. //--
  14169. #define KeEnterCriticalRegion() KeGetCurrentThread()->KernelApcDisable -= 1
  14170. //++
  14171. //
  14172. // VOID
  14173. // KeEnterCriticalRegionThread (
  14174. // PKTHREAD CurrentThread
  14175. // )
  14176. //
  14177. //
  14178. // Routine Description:
  14179. //
  14180. // This function disables kernel APC's for the current thread only.
  14181. //
  14182. // N.B. The following code does not require any interlocks. There are
  14183. // two cases of interest: 1) On an MP system, the thread cannot
  14184. // be running on two processors as once, and 2) if the thread is
  14185. // is interrupted to deliver a kernel mode APC which also calls
  14186. // this routine, the values read and stored will stack and unstack
  14187. // properly.
  14188. //
  14189. // Arguments:
  14190. //
  14191. // CurrentThread - Current thread thats executing. This must be the
  14192. // current thread.
  14193. //
  14194. // Return Value:
  14195. //
  14196. // None.
  14197. //--
  14198. #define KeEnterCriticalRegionThread(CurrentThread) { \
  14199. ASSERT (CurrentThread == KeGetCurrentThread ()); \
  14200. (CurrentThread)->KernelApcDisable -= 1; \
  14201. }
  14202. //++
  14203. //
  14204. // VOID
  14205. // KeLeaveCriticalRegion (
  14206. // VOID
  14207. // )
  14208. //
  14209. //
  14210. // Routine Description:
  14211. //
  14212. // This function enables kernel APC's.
  14213. //
  14214. // N.B. The following code does not require any interlocks. There are
  14215. // two cases of interest: 1) On an MP system, the thread cannot
  14216. // be running on two processors as once, and 2) if the thread is
  14217. // is interrupted to deliver a kernel mode APC which also calls
  14218. // this routine, the values read and stored will stack and unstack
  14219. // properly.
  14220. //
  14221. // Arguments:
  14222. //
  14223. // None.
  14224. //
  14225. // Return Value:
  14226. //
  14227. // None.
  14228. //--
  14229. #define KeLeaveCriticalRegion() KiLeaveCriticalRegion()
  14230. //++
  14231. //
  14232. // VOID
  14233. // KeLeaveCriticalRegionThread (
  14234. // PKTHREAD CurrentThread
  14235. // )
  14236. //
  14237. //
  14238. // Routine Description:
  14239. //
  14240. // This function enables kernel APC's for the current thread.
  14241. //
  14242. // N.B. The following code does not require any interlocks. There are
  14243. // two cases of interest: 1) On an MP system, the thread cannot
  14244. // be running on two processors as once, and 2) if the thread is
  14245. // is interrupted to deliver a kernel mode APC which also calls
  14246. // this routine, the values read and stored will stack and unstack
  14247. // properly.
  14248. //
  14249. // Arguments:
  14250. //
  14251. // CurrentThread - Current thread thats executing. This must be the
  14252. // current thread.
  14253. //
  14254. // Return Value:
  14255. //
  14256. // None.
  14257. //--
  14258. #define KeLeaveCriticalRegionThread(CurrentThread) { \
  14259. ASSERT (CurrentThread == KeGetCurrentThread ()); \
  14260. KiLeaveCriticalRegionThread(CurrentThread); \
  14261. }
  14262. #define KeAreApcsDisabled() (KeGetCurrentThread()->KernelApcDisable != 0);
  14263. //++
  14264. //
  14265. // KPROCESSOR_MODE
  14266. // KeGetPReviousMode (
  14267. // VOID
  14268. // )
  14269. //
  14270. //
  14271. // Routine Description:
  14272. //
  14273. // This function gets the threads previous mode from the trap frame
  14274. //
  14275. //
  14276. // Arguments:
  14277. //
  14278. // None.
  14279. //
  14280. // Return Value:
  14281. //
  14282. // KPROCESSOR_MODE - Previous mode for this thread
  14283. //--
  14284. #define KeGetPreviousMode() (KeGetCurrentThread()->PreviousMode)
  14285. //++
  14286. //
  14287. // KPROCESSOR_MODE
  14288. // KeGetPReviousModeByThread (
  14289. // PKTHREAD xxCurrentThread
  14290. // )
  14291. //
  14292. //
  14293. // Routine Description:
  14294. //
  14295. // This function gets the threads previous mode from the trap frame.
  14296. //
  14297. //
  14298. // Arguments:
  14299. //
  14300. // xxCurrentThread - Current thread. This can not be a cross thread reference
  14301. //
  14302. // Return Value:
  14303. //
  14304. // KPROCESSOR_MODE - Previous mode for this thread
  14305. //--
  14306. #define KeGetPreviousModeByThread(xxCurrentThread) (ASSERT (xxCurrentThread == KeGetCurrentThread ()),\
  14307. (xxCurrentThread)->PreviousMode)
  14308. #endif
  14309. // begin_wdm
  14310. //
  14311. // Timer object
  14312. //
  14313. NTKERNELAPI
  14314. VOID
  14315. KeInitializeTimer (
  14316. IN PKTIMER Timer
  14317. );
  14318. NTKERNELAPI
  14319. VOID
  14320. KeInitializeTimerEx (
  14321. IN PKTIMER Timer,
  14322. IN TIMER_TYPE Type
  14323. );
  14324. NTKERNELAPI
  14325. BOOLEAN
  14326. KeCancelTimer (
  14327. IN PKTIMER
  14328. );
  14329. NTKERNELAPI
  14330. BOOLEAN
  14331. KeReadStateTimer (
  14332. PKTIMER Timer
  14333. );
  14334. NTKERNELAPI
  14335. BOOLEAN
  14336. KeSetTimer (
  14337. IN PKTIMER Timer,
  14338. IN LARGE_INTEGER DueTime,
  14339. IN PKDPC Dpc OPTIONAL
  14340. );
  14341. NTKERNELAPI
  14342. BOOLEAN
  14343. KeSetTimerEx (
  14344. IN PKTIMER Timer,
  14345. IN LARGE_INTEGER DueTime,
  14346. IN LONG Period OPTIONAL,
  14347. IN PKDPC Dpc OPTIONAL
  14348. );
  14349. #define KeWaitForMutexObject KeWaitForSingleObject
  14350. NTKERNELAPI
  14351. NTSTATUS
  14352. KeWaitForMultipleObjects (
  14353. IN ULONG Count,
  14354. IN PVOID Object[],
  14355. IN WAIT_TYPE WaitType,
  14356. IN KWAIT_REASON WaitReason,
  14357. IN KPROCESSOR_MODE WaitMode,
  14358. IN BOOLEAN Alertable,
  14359. IN PLARGE_INTEGER Timeout OPTIONAL,
  14360. IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
  14361. );
  14362. NTKERNELAPI
  14363. NTSTATUS
  14364. KeWaitForSingleObject (
  14365. IN PVOID Object,
  14366. IN KWAIT_REASON WaitReason,
  14367. IN KPROCESSOR_MODE WaitMode,
  14368. IN BOOLEAN Alertable,
  14369. IN PLARGE_INTEGER Timeout OPTIONAL
  14370. );
  14371. //
  14372. // On X86 the following routines are defined in the HAL and imported by
  14373. // all other modules.
  14374. //
  14375. #if defined(_X86_) && !defined(_NTHAL_)
  14376. #define _DECL_HAL_KE_IMPORT __declspec(dllimport)
  14377. #else
  14378. #define _DECL_HAL_KE_IMPORT
  14379. #endif
  14380. _DECL_HAL_KE_IMPORT
  14381. KIRQL
  14382. FASTCALL
  14383. KeAcquireQueuedSpinLock (
  14384. IN KSPIN_LOCK_QUEUE_NUMBER Number
  14385. );
  14386. _DECL_HAL_KE_IMPORT
  14387. VOID
  14388. FASTCALL
  14389. KeReleaseQueuedSpinLock (
  14390. IN KSPIN_LOCK_QUEUE_NUMBER Number,
  14391. IN KIRQL OldIrql
  14392. );
  14393. _DECL_HAL_KE_IMPORT
  14394. LOGICAL
  14395. FASTCALL
  14396. KeTryToAcquireQueuedSpinLock(
  14397. IN KSPIN_LOCK_QUEUE_NUMBER Number,
  14398. IN PKIRQL OldIrql
  14399. );
  14400. //
  14401. // spin lock functions
  14402. //
  14403. NTKERNELAPI
  14404. VOID
  14405. NTAPI
  14406. KeInitializeSpinLock (
  14407. IN PKSPIN_LOCK SpinLock
  14408. );
  14409. #if defined(_X86_)
  14410. NTKERNELAPI
  14411. VOID
  14412. FASTCALL
  14413. KefAcquireSpinLockAtDpcLevel (
  14414. IN PKSPIN_LOCK SpinLock
  14415. );
  14416. NTKERNELAPI
  14417. VOID
  14418. FASTCALL
  14419. KefReleaseSpinLockFromDpcLevel (
  14420. IN PKSPIN_LOCK SpinLock
  14421. );
  14422. #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
  14423. #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
  14424. _DECL_HAL_KE_IMPORT
  14425. KIRQL
  14426. FASTCALL
  14427. KfAcquireSpinLock (
  14428. IN PKSPIN_LOCK SpinLock
  14429. );
  14430. _DECL_HAL_KE_IMPORT
  14431. VOID
  14432. FASTCALL
  14433. KfReleaseSpinLock (
  14434. IN PKSPIN_LOCK SpinLock,
  14435. IN KIRQL NewIrql
  14436. );
  14437. // end_wdm
  14438. _DECL_HAL_KE_IMPORT
  14439. KIRQL
  14440. FASTCALL
  14441. KeAcquireSpinLockRaiseToSynch (
  14442. IN PKSPIN_LOCK SpinLock
  14443. );
  14444. // begin_wdm
  14445. #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
  14446. #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
  14447. #else
  14448. NTKERNELAPI
  14449. KIRQL
  14450. FASTCALL
  14451. KeAcquireSpinLockRaiseToSynch (
  14452. IN PKSPIN_LOCK SpinLock
  14453. );
  14454. NTKERNELAPI
  14455. VOID
  14456. KeAcquireSpinLockAtDpcLevel (
  14457. IN PKSPIN_LOCK SpinLock
  14458. );
  14459. NTKERNELAPI
  14460. VOID
  14461. KeReleaseSpinLockFromDpcLevel (
  14462. IN PKSPIN_LOCK SpinLock
  14463. );
  14464. NTKERNELAPI
  14465. KIRQL
  14466. KeAcquireSpinLockRaiseToDpc (
  14467. IN PKSPIN_LOCK SpinLock
  14468. );
  14469. #define KeAcquireSpinLock(SpinLock, OldIrql) \
  14470. *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
  14471. NTKERNELAPI
  14472. VOID
  14473. KeReleaseSpinLock (
  14474. IN PKSPIN_LOCK SpinLock,
  14475. IN KIRQL NewIrql
  14476. );
  14477. #endif
  14478. NTKERNELAPI
  14479. BOOLEAN
  14480. FASTCALL
  14481. KeTryToAcquireSpinLockAtDpcLevel (
  14482. IN PKSPIN_LOCK SpinLock
  14483. );
  14484. #if defined(_X86_)
  14485. _DECL_HAL_KE_IMPORT
  14486. VOID
  14487. FASTCALL
  14488. KfLowerIrql (
  14489. IN KIRQL NewIrql
  14490. );
  14491. _DECL_HAL_KE_IMPORT
  14492. KIRQL
  14493. FASTCALL
  14494. KfRaiseIrql (
  14495. IN KIRQL NewIrql
  14496. );
  14497. // end_wdm
  14498. _DECL_HAL_KE_IMPORT
  14499. KIRQL
  14500. KeRaiseIrqlToDpcLevel(
  14501. VOID
  14502. );
  14503. _DECL_HAL_KE_IMPORT
  14504. KIRQL
  14505. KeRaiseIrqlToSynchLevel(
  14506. VOID
  14507. );
  14508. // begin_wdm
  14509. #define KeLowerIrql(a) KfLowerIrql(a)
  14510. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  14511. // end_wdm
  14512. // begin_wdm
  14513. #elif defined(_ALPHA_)
  14514. #define KeLowerIrql(a) __swpirql(a)
  14515. #define KeRaiseIrql(a,b) *(b) = __swpirql(a)
  14516. // end_wdm
  14517. extern ULONG KiSynchIrql;
  14518. #define KfRaiseIrql(a) __swpirql(a)
  14519. #define KeRaiseIrqlToDpcLevel() __swpirql(DISPATCH_LEVEL)
  14520. #define KeRaiseIrqlToSynchLevel() __swpirql((UCHAR)KiSynchIrql)
  14521. // begin_wdm
  14522. #elif defined(_IA64_)
  14523. VOID
  14524. KeLowerIrql (
  14525. IN KIRQL NewIrql
  14526. );
  14527. VOID
  14528. KeRaiseIrql (
  14529. IN KIRQL NewIrql,
  14530. OUT PKIRQL OldIrql
  14531. );
  14532. // end_wdm
  14533. KIRQL
  14534. KfRaiseIrql (
  14535. IN KIRQL NewIrql
  14536. );
  14537. KIRQL
  14538. KeRaiseIrqlToDpcLevel (
  14539. VOID
  14540. );
  14541. KIRQL
  14542. KeRaiseIrqlToSynchLevel (
  14543. VOID
  14544. );
  14545. // begin_wdm
  14546. #elif defined(_AMD64_)
  14547. //
  14548. // These function are defined in amd64.h for the AMD64 platform.
  14549. //
  14550. #else
  14551. #error "no target architecture"
  14552. #endif
  14553. //
  14554. // Queued spin lock functions for "in stack" lock handles.
  14555. //
  14556. // The following three functions RAISE and LOWER IRQL when a queued
  14557. // in stack spin lock is acquired or released using these routines.
  14558. //
  14559. _DECL_HAL_KE_IMPORT
  14560. VOID
  14561. FASTCALL
  14562. KeAcquireInStackQueuedSpinLock (
  14563. IN PKSPIN_LOCK SpinLock,
  14564. IN PKLOCK_QUEUE_HANDLE LockHandle
  14565. );
  14566. _DECL_HAL_KE_IMPORT
  14567. VOID
  14568. FASTCALL
  14569. KeReleaseInStackQueuedSpinLock (
  14570. IN PKLOCK_QUEUE_HANDLE LockHandle
  14571. );
  14572. //
  14573. // The following two functions do NOT raise or lower IRQL when a queued
  14574. // in stack spin lock is acquired or released using these functions.
  14575. //
  14576. NTKERNELAPI
  14577. VOID
  14578. FASTCALL
  14579. KeAcquireInStackQueuedSpinLockAtDpcLevel (
  14580. IN PKSPIN_LOCK SpinLock,
  14581. IN PKLOCK_QUEUE_HANDLE LockHandle
  14582. );
  14583. NTKERNELAPI
  14584. VOID
  14585. FASTCALL
  14586. KeReleaseInStackQueuedSpinLockFromDpcLevel (
  14587. IN PKLOCK_QUEUE_HANDLE LockHandle
  14588. );
  14589. //
  14590. // Miscellaneous kernel functions
  14591. //
  14592. typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
  14593. BufferEmpty,
  14594. BufferInserted,
  14595. BufferStarted,
  14596. BufferFinished,
  14597. BufferIncomplete
  14598. } KBUGCHECK_BUFFER_DUMP_STATE;
  14599. typedef
  14600. VOID
  14601. (*PKBUGCHECK_CALLBACK_ROUTINE) (
  14602. IN PVOID Buffer,
  14603. IN ULONG Length
  14604. );
  14605. typedef struct _KBUGCHECK_CALLBACK_RECORD {
  14606. LIST_ENTRY Entry;
  14607. PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
  14608. PVOID Buffer;
  14609. ULONG Length;
  14610. PUCHAR Component;
  14611. ULONG_PTR Checksum;
  14612. UCHAR State;
  14613. } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
  14614. #define KeInitializeCallbackRecord(CallbackRecord) \
  14615. (CallbackRecord)->State = BufferEmpty
  14616. NTKERNELAPI
  14617. BOOLEAN
  14618. KeDeregisterBugCheckCallback (
  14619. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord
  14620. );
  14621. NTKERNELAPI
  14622. BOOLEAN
  14623. KeRegisterBugCheckCallback (
  14624. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
  14625. IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
  14626. IN PVOID Buffer,
  14627. IN ULONG Length,
  14628. IN PUCHAR Component
  14629. );
  14630. typedef enum _KBUGCHECK_CALLBACK_REASON {
  14631. KbCallbackInvalid,
  14632. KbCallbackReserved1,
  14633. KbCallbackSecondaryDumpData,
  14634. KbCallbackDumpIo,
  14635. } KBUGCHECK_CALLBACK_REASON;
  14636. typedef
  14637. VOID
  14638. (*PKBUGCHECK_REASON_CALLBACK_ROUTINE) (
  14639. IN KBUGCHECK_CALLBACK_REASON Reason,
  14640. IN struct _KBUGCHECK_REASON_CALLBACK_RECORD* Record,
  14641. IN OUT PVOID ReasonSpecificData,
  14642. IN ULONG ReasonSpecificDataLength
  14643. );
  14644. typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
  14645. LIST_ENTRY Entry;
  14646. PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
  14647. PUCHAR Component;
  14648. ULONG_PTR Checksum;
  14649. KBUGCHECK_CALLBACK_REASON Reason;
  14650. UCHAR State;
  14651. } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
  14652. typedef struct _KBUGCHECK_SECONDARY_DUMP_DATA {
  14653. IN PVOID InBuffer;
  14654. IN ULONG InBufferLength;
  14655. IN ULONG MaximumAllowed;
  14656. OUT GUID Guid;
  14657. OUT PVOID OutBuffer;
  14658. OUT ULONG OutBufferLength;
  14659. } KBUGCHECK_SECONDARY_DUMP_DATA, *PKBUGCHECK_SECONDARY_DUMP_DATA;
  14660. typedef enum _KBUGCHECK_DUMP_IO_TYPE
  14661. {
  14662. KbDumpIoInvalid,
  14663. KbDumpIoHeader,
  14664. KbDumpIoBody,
  14665. KbDumpIoSecondaryData,
  14666. KbDumpIoComplete
  14667. } KBUGCHECK_DUMP_IO_TYPE;
  14668. typedef struct _KBUGCHECK_DUMP_IO {
  14669. IN ULONG64 Offset;
  14670. IN PVOID Buffer;
  14671. IN ULONG BufferLength;
  14672. IN KBUGCHECK_DUMP_IO_TYPE Type;
  14673. } KBUGCHECK_DUMP_IO, *PKBUGCHECK_DUMP_IO;
  14674. NTKERNELAPI
  14675. BOOLEAN
  14676. KeDeregisterBugCheckReasonCallback (
  14677. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
  14678. );
  14679. NTKERNELAPI
  14680. BOOLEAN
  14681. KeRegisterBugCheckReasonCallback (
  14682. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord,
  14683. IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine,
  14684. IN KBUGCHECK_CALLBACK_REASON Reason,
  14685. IN PUCHAR Component
  14686. );
  14687. // end_wdm
  14688. NTKERNELAPI
  14689. DECLSPEC_NORETURN
  14690. VOID
  14691. NTAPI
  14692. KeBugCheck (
  14693. IN ULONG BugCheckCode
  14694. );
  14695. NTKERNELAPI
  14696. DECLSPEC_NORETURN
  14697. VOID
  14698. KeBugCheckEx(
  14699. IN ULONG BugCheckCode,
  14700. IN ULONG_PTR BugCheckParameter1,
  14701. IN ULONG_PTR BugCheckParameter2,
  14702. IN ULONG_PTR BugCheckParameter3,
  14703. IN ULONG_PTR BugCheckParameter4
  14704. );
  14705. NTKERNELAPI
  14706. ULONGLONG
  14707. KeQueryInterruptTime (
  14708. VOID
  14709. );
  14710. NTKERNELAPI
  14711. VOID
  14712. KeQuerySystemTime (
  14713. OUT PLARGE_INTEGER CurrentTime
  14714. );
  14715. NTKERNELAPI
  14716. ULONG
  14717. KeQueryTimeIncrement (
  14718. VOID
  14719. );
  14720. NTKERNELAPI
  14721. ULONG
  14722. KeGetRecommendedSharedDataAlignment (
  14723. VOID
  14724. );
  14725. // end_wdm
  14726. NTKERNELAPI
  14727. KAFFINITY
  14728. KeQueryActiveProcessors (
  14729. VOID
  14730. );
  14731. //
  14732. // Time update notify routine.
  14733. //
  14734. typedef
  14735. VOID
  14736. (FASTCALL *PTIME_UPDATE_NOTIFY_ROUTINE)(
  14737. IN HANDLE ThreadId,
  14738. IN KPROCESSOR_MODE Mode
  14739. );
  14740. NTKERNELAPI
  14741. VOID
  14742. FASTCALL
  14743. KeSetTimeUpdateNotifyRoutine(
  14744. IN PTIME_UPDATE_NOTIFY_ROUTINE NotifyRoutine
  14745. );
  14746. #if defined(_AMD64_) || defined(_ALPHA_) || defined(_IA64_)
  14747. extern volatile LARGE_INTEGER KeTickCount;
  14748. #else
  14749. extern volatile KSYSTEM_TIME KeTickCount;
  14750. #endif
  14751. typedef enum _MEMORY_CACHING_TYPE_ORIG {
  14752. MmFrameBufferCached = 2
  14753. } MEMORY_CACHING_TYPE_ORIG;
  14754. typedef enum _MEMORY_CACHING_TYPE {
  14755. MmNonCached = FALSE,
  14756. MmCached = TRUE,
  14757. MmWriteCombined = MmFrameBufferCached,
  14758. MmHardwareCoherentCached,
  14759. MmNonCachedUnordered, // IA64
  14760. MmUSWCCached,
  14761. MmMaximumCacheType
  14762. } MEMORY_CACHING_TYPE;
  14763. //
  14764. // Pool Allocation routines (in pool.c)
  14765. //
  14766. typedef enum _POOL_TYPE {
  14767. NonPagedPool,
  14768. PagedPool,
  14769. NonPagedPoolMustSucceed,
  14770. DontUseThisType,
  14771. NonPagedPoolCacheAligned,
  14772. PagedPoolCacheAligned,
  14773. NonPagedPoolCacheAlignedMustS,
  14774. MaxPoolType
  14775. // end_wdm
  14776. ,
  14777. //
  14778. // Note these per session types are carefully chosen so that the appropriate
  14779. // masking still applies as well as MaxPoolType above.
  14780. //
  14781. NonPagedPoolSession = 32,
  14782. PagedPoolSession = NonPagedPoolSession + 1,
  14783. NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
  14784. DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
  14785. NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
  14786. PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
  14787. NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1,
  14788. // begin_wdm
  14789. } POOL_TYPE;
  14790. #define POOL_COLD_ALLOCATION 256 // Note this cannot encode into the header.
  14791. #define POOL_RAISE_IF_ALLOCATION_FAILURE 16
  14792. NTKERNELAPI
  14793. PVOID
  14794. ExAllocatePool(
  14795. IN POOL_TYPE PoolType,
  14796. IN SIZE_T NumberOfBytes
  14797. );
  14798. NTKERNELAPI
  14799. PVOID
  14800. ExAllocatePoolWithQuota(
  14801. IN POOL_TYPE PoolType,
  14802. IN SIZE_T NumberOfBytes
  14803. );
  14804. NTKERNELAPI
  14805. PVOID
  14806. NTAPI
  14807. ExAllocatePoolWithTag(
  14808. IN POOL_TYPE PoolType,
  14809. IN SIZE_T NumberOfBytes,
  14810. IN ULONG Tag
  14811. );
  14812. //
  14813. // _EX_POOL_PRIORITY_ provides a method for the system to handle requests
  14814. // intelligently in low resource conditions.
  14815. //
  14816. // LowPoolPriority should be used when it is acceptable to the driver for the
  14817. // mapping request to fail if the system is low on resources. An example of
  14818. // this could be for a non-critical network connection where the driver can
  14819. // handle the failure case when system resources are close to being depleted.
  14820. //
  14821. // NormalPoolPriority should be used when it is acceptable to the driver for the
  14822. // mapping request to fail if the system is very low on resources. An example
  14823. // of this could be for a non-critical local filesystem request.
  14824. //
  14825. // HighPoolPriority should be used when it is unacceptable to the driver for the
  14826. // mapping request to fail unless the system is completely out of resources.
  14827. // An example of this would be the paging file path in a driver.
  14828. //
  14829. // SpecialPool can be specified to bound the allocation at a page end (or
  14830. // beginning). This should only be done on systems being debugged as the
  14831. // memory cost is expensive.
  14832. //
  14833. // N.B. These values are very carefully chosen so that the pool allocation
  14834. // code can quickly crack the priority request.
  14835. //
  14836. typedef enum _EX_POOL_PRIORITY {
  14837. LowPoolPriority,
  14838. LowPoolPrioritySpecialPoolOverrun = 8,
  14839. LowPoolPrioritySpecialPoolUnderrun = 9,
  14840. NormalPoolPriority = 16,
  14841. NormalPoolPrioritySpecialPoolOverrun = 24,
  14842. NormalPoolPrioritySpecialPoolUnderrun = 25,
  14843. HighPoolPriority = 32,
  14844. HighPoolPrioritySpecialPoolOverrun = 40,
  14845. HighPoolPrioritySpecialPoolUnderrun = 41
  14846. } EX_POOL_PRIORITY;
  14847. NTKERNELAPI
  14848. PVOID
  14849. NTAPI
  14850. ExAllocatePoolWithTagPriority(
  14851. IN POOL_TYPE PoolType,
  14852. IN SIZE_T NumberOfBytes,
  14853. IN ULONG Tag,
  14854. IN EX_POOL_PRIORITY Priority
  14855. );
  14856. #ifndef POOL_TAGGING
  14857. #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
  14858. #endif //POOL_TAGGING
  14859. NTKERNELAPI
  14860. PVOID
  14861. ExAllocatePoolWithQuotaTag(
  14862. IN POOL_TYPE PoolType,
  14863. IN SIZE_T NumberOfBytes,
  14864. IN ULONG Tag
  14865. );
  14866. #ifndef POOL_TAGGING
  14867. #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
  14868. #endif //POOL_TAGGING
  14869. NTKERNELAPI
  14870. VOID
  14871. NTAPI
  14872. ExFreePool(
  14873. IN PVOID P
  14874. );
  14875. // end_wdm
  14876. #if defined(POOL_TAGGING)
  14877. #define ExFreePool(a) ExFreePoolWithTag(a,0)
  14878. #endif
  14879. //
  14880. // If high order bit in Pool tag is set, then must use ExFreePoolWithTag to free
  14881. //
  14882. #define PROTECTED_POOL 0x80000000
  14883. // begin_wdm
  14884. NTKERNELAPI
  14885. VOID
  14886. ExFreePoolWithTag(
  14887. IN PVOID P,
  14888. IN ULONG Tag
  14889. );
  14890. NTKERNELAPI
  14891. SIZE_T
  14892. ExQueryPoolBlockSize (
  14893. IN PVOID PoolBlock,
  14894. OUT PBOOLEAN QuotaCharged
  14895. );
  14896. //
  14897. // Routines to support fast mutexes.
  14898. //
  14899. typedef struct _FAST_MUTEX {
  14900. LONG Count;
  14901. PKTHREAD Owner;
  14902. ULONG Contention;
  14903. KEVENT Event;
  14904. ULONG OldIrql;
  14905. } FAST_MUTEX, *PFAST_MUTEX;
  14906. #define ExInitializeFastMutex(_FastMutex) \
  14907. (_FastMutex)->Count = 1; \
  14908. (_FastMutex)->Owner = NULL; \
  14909. (_FastMutex)->Contention = 0; \
  14910. KeInitializeEvent(&(_FastMutex)->Event, \
  14911. SynchronizationEvent, \
  14912. FALSE);
  14913. NTKERNELAPI
  14914. VOID
  14915. FASTCALL
  14916. ExAcquireFastMutexUnsafe (
  14917. IN PFAST_MUTEX FastMutex
  14918. );
  14919. NTKERNELAPI
  14920. VOID
  14921. FASTCALL
  14922. ExReleaseFastMutexUnsafe (
  14923. IN PFAST_MUTEX FastMutex
  14924. );
  14925. #if defined(_ALPHA_) || defined(_IA64_) || defined(_AMD64_)
  14926. NTKERNELAPI
  14927. VOID
  14928. FASTCALL
  14929. ExAcquireFastMutex (
  14930. IN PFAST_MUTEX FastMutex
  14931. );
  14932. NTKERNELAPI
  14933. VOID
  14934. FASTCALL
  14935. ExReleaseFastMutex (
  14936. IN PFAST_MUTEX FastMutex
  14937. );
  14938. NTKERNELAPI
  14939. BOOLEAN
  14940. FASTCALL
  14941. ExTryToAcquireFastMutex (
  14942. IN PFAST_MUTEX FastMutex
  14943. );
  14944. #elif defined(_X86_)
  14945. NTHALAPI
  14946. VOID
  14947. FASTCALL
  14948. ExAcquireFastMutex (
  14949. IN PFAST_MUTEX FastMutex
  14950. );
  14951. NTHALAPI
  14952. VOID
  14953. FASTCALL
  14954. ExReleaseFastMutex (
  14955. IN PFAST_MUTEX FastMutex
  14956. );
  14957. NTHALAPI
  14958. BOOLEAN
  14959. FASTCALL
  14960. ExTryToAcquireFastMutex (
  14961. IN PFAST_MUTEX FastMutex
  14962. );
  14963. #else
  14964. #error "Target architecture not defined"
  14965. #endif
  14966. //
  14967. NTKERNELAPI
  14968. VOID
  14969. FASTCALL
  14970. ExInterlockedAddLargeStatistic (
  14971. IN PLARGE_INTEGER Addend,
  14972. IN ULONG Increment
  14973. );
  14974. // end_ntndis
  14975. NTKERNELAPI
  14976. LARGE_INTEGER
  14977. ExInterlockedAddLargeInteger (
  14978. IN PLARGE_INTEGER Addend,
  14979. IN LARGE_INTEGER Increment,
  14980. IN PKSPIN_LOCK Lock
  14981. );
  14982. NTKERNELAPI
  14983. ULONG
  14984. FASTCALL
  14985. ExInterlockedAddUlong (
  14986. IN PULONG Addend,
  14987. IN ULONG Increment,
  14988. IN PKSPIN_LOCK Lock
  14989. );
  14990. #if defined(_AMD64_) || defined(_AXP64_) || defined(_IA64_)
  14991. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  14992. InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
  14993. #elif defined(_ALPHA_)
  14994. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  14995. ExpInterlockedCompareExchange64(Destination, Exchange, Comperand)
  14996. #else
  14997. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  14998. ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
  14999. #endif
  15000. NTKERNELAPI
  15001. PLIST_ENTRY
  15002. FASTCALL
  15003. ExInterlockedInsertHeadList (
  15004. IN PLIST_ENTRY ListHead,
  15005. IN PLIST_ENTRY ListEntry,
  15006. IN PKSPIN_LOCK Lock
  15007. );
  15008. NTKERNELAPI
  15009. PLIST_ENTRY
  15010. FASTCALL
  15011. ExInterlockedInsertTailList (
  15012. IN PLIST_ENTRY ListHead,
  15013. IN PLIST_ENTRY ListEntry,
  15014. IN PKSPIN_LOCK Lock
  15015. );
  15016. NTKERNELAPI
  15017. PLIST_ENTRY
  15018. FASTCALL
  15019. ExInterlockedRemoveHeadList (
  15020. IN PLIST_ENTRY ListHead,
  15021. IN PKSPIN_LOCK Lock
  15022. );
  15023. NTKERNELAPI
  15024. PSINGLE_LIST_ENTRY
  15025. FASTCALL
  15026. ExInterlockedPopEntryList (
  15027. IN PSINGLE_LIST_ENTRY ListHead,
  15028. IN PKSPIN_LOCK Lock
  15029. );
  15030. NTKERNELAPI
  15031. PSINGLE_LIST_ENTRY
  15032. FASTCALL
  15033. ExInterlockedPushEntryList (
  15034. IN PSINGLE_LIST_ENTRY ListHead,
  15035. IN PSINGLE_LIST_ENTRY ListEntry,
  15036. IN PKSPIN_LOCK Lock
  15037. );
  15038. //
  15039. // Define interlocked sequenced listhead functions.
  15040. //
  15041. // A sequenced interlocked list is a singly linked list with a header that
  15042. // contains the current depth and a sequence number. Each time an entry is
  15043. // inserted or removed from the list the depth is updated and the sequence
  15044. // number is incremented. This enables AMD64, IA64, and Pentium and later
  15045. // machines to insert and remove from the list without the use of spinlocks.
  15046. //
  15047. #if !defined(_WINBASE_)
  15048. /*++
  15049. Routine Description:
  15050. This function initializes a sequenced singly linked listhead.
  15051. Arguments:
  15052. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  15053. Return Value:
  15054. None.
  15055. --*/
  15056. #if defined(_WIN64) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  15057. NTKERNELAPI
  15058. VOID
  15059. InitializeSListHead (
  15060. IN PSLIST_HEADER SListHead
  15061. );
  15062. #else
  15063. __inline
  15064. VOID
  15065. InitializeSListHead (
  15066. IN PSLIST_HEADER SListHead
  15067. )
  15068. {
  15069. #ifdef _WIN64
  15070. //
  15071. // Slist headers must be 16 byte aligned.
  15072. //
  15073. if ((ULONG_PTR) SListHead & 0x0f) {
  15074. DbgPrint( "InitializeSListHead unaligned Slist header. Address = %p, Caller = %p\n", SListHead, _ReturnAddress());
  15075. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  15076. }
  15077. #endif
  15078. SListHead->Alignment = 0;
  15079. //
  15080. // For IA-64 we save the region number of the elements of the list in a
  15081. // separate field. This imposes the requirement that all elements stored
  15082. // in the list are from the same region.
  15083. #if defined(_IA64_)
  15084. SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
  15085. #elif defined(_AMD64_)
  15086. SListHead->Region = 0;
  15087. #endif
  15088. return;
  15089. }
  15090. #endif
  15091. #endif // !defined(_WINBASE_)
  15092. #define ExInitializeSListHead InitializeSListHead
  15093. PSLIST_ENTRY
  15094. FirstEntrySList (
  15095. IN const SLIST_HEADER *SListHead
  15096. );
  15097. /*++
  15098. Routine Description:
  15099. This function queries the current number of entries contained in a
  15100. sequenced single linked list.
  15101. Arguments:
  15102. SListHead - Supplies a pointer to the sequenced listhead which is
  15103. be queried.
  15104. Return Value:
  15105. The current number of entries in the sequenced singly linked list is
  15106. returned as the function value.
  15107. --*/
  15108. #if defined(_WIN64)
  15109. #if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  15110. NTKERNELAPI
  15111. USHORT
  15112. ExQueryDepthSList (
  15113. IN PSLIST_HEADER SListHead
  15114. );
  15115. #else
  15116. __inline
  15117. USHORT
  15118. ExQueryDepthSList (
  15119. IN PSLIST_HEADER SListHead
  15120. )
  15121. {
  15122. return (USHORT)(SListHead->Alignment & 0xffff);
  15123. }
  15124. #endif
  15125. #else
  15126. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  15127. #endif
  15128. #if defined(_WIN64)
  15129. #define ExInterlockedPopEntrySList(Head, Lock) \
  15130. ExpInterlockedPopEntrySList(Head)
  15131. #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
  15132. ExpInterlockedPushEntrySList(Head, Entry)
  15133. #define ExInterlockedFlushSList(Head) \
  15134. ExpInterlockedFlushSList(Head)
  15135. #if !defined(_WINBASE_)
  15136. #define InterlockedPopEntrySList(Head) \
  15137. ExpInterlockedPopEntrySList(Head)
  15138. #define InterlockedPushEntrySList(Head, Entry) \
  15139. ExpInterlockedPushEntrySList(Head, Entry)
  15140. #define InterlockedFlushSList(Head) \
  15141. ExpInterlockedFlushSList(Head)
  15142. #define QueryDepthSList(Head) \
  15143. ExQueryDepthSList(Head)
  15144. #endif // !defined(_WINBASE_)
  15145. NTKERNELAPI
  15146. PSLIST_ENTRY
  15147. ExpInterlockedPopEntrySList (
  15148. IN PSLIST_HEADER ListHead
  15149. );
  15150. NTKERNELAPI
  15151. PSLIST_ENTRY
  15152. ExpInterlockedPushEntrySList (
  15153. IN PSLIST_HEADER ListHead,
  15154. IN PSLIST_ENTRY ListEntry
  15155. );
  15156. NTKERNELAPI
  15157. PSLIST_ENTRY
  15158. ExpInterlockedFlushSList (
  15159. IN PSLIST_HEADER ListHead
  15160. );
  15161. #else
  15162. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  15163. NTKERNELAPI
  15164. PSLIST_ENTRY
  15165. FASTCALL
  15166. ExInterlockedPopEntrySList (
  15167. IN PSLIST_HEADER ListHead,
  15168. IN PKSPIN_LOCK Lock
  15169. );
  15170. NTKERNELAPI
  15171. PSLIST_ENTRY
  15172. FASTCALL
  15173. ExInterlockedPushEntrySList (
  15174. IN PSLIST_HEADER ListHead,
  15175. IN PSLIST_ENTRY ListEntry,
  15176. IN PKSPIN_LOCK Lock
  15177. );
  15178. #else
  15179. #define ExInterlockedPopEntrySList(ListHead, Lock) \
  15180. InterlockedPopEntrySList(ListHead)
  15181. #define ExInterlockedPushEntrySList(ListHead, ListEntry, Lock) \
  15182. InterlockedPushEntrySList(ListHead, ListEntry)
  15183. #endif
  15184. NTKERNELAPI
  15185. PSLIST_ENTRY
  15186. FASTCALL
  15187. ExInterlockedFlushSList (
  15188. IN PSLIST_HEADER ListHead
  15189. );
  15190. #if !defined(_WINBASE_)
  15191. NTKERNELAPI
  15192. PSLIST_ENTRY
  15193. FASTCALL
  15194. InterlockedPopEntrySList (
  15195. IN PSLIST_HEADER ListHead
  15196. );
  15197. NTKERNELAPI
  15198. PSLIST_ENTRY
  15199. FASTCALL
  15200. InterlockedPushEntrySList (
  15201. IN PSLIST_HEADER ListHead,
  15202. IN PSLIST_ENTRY ListEntry
  15203. );
  15204. #define InterlockedFlushSList(Head) \
  15205. ExInterlockedFlushSList(Head)
  15206. #define QueryDepthSList(Head) \
  15207. ExQueryDepthSList(Head)
  15208. #endif // !defined(_WINBASE_)
  15209. #endif // defined(_WIN64)
  15210. // end_ntddk end_wdm end_ntosp
  15211. PSLIST_ENTRY
  15212. FASTCALL
  15213. InterlockedPushListSList (
  15214. IN PSLIST_HEADER ListHead,
  15215. IN PSLIST_ENTRY List,
  15216. IN PSLIST_ENTRY ListEnd,
  15217. IN ULONG Count
  15218. );
  15219. //
  15220. // Define interlocked lookaside list structure and allocation functions.
  15221. //
  15222. VOID
  15223. ExAdjustLookasideDepth (
  15224. VOID
  15225. );
  15226. // begin_ntddk begin_wdm begin_ntosp
  15227. typedef
  15228. PVOID
  15229. (*PALLOCATE_FUNCTION) (
  15230. IN POOL_TYPE PoolType,
  15231. IN SIZE_T NumberOfBytes,
  15232. IN ULONG Tag
  15233. );
  15234. typedef
  15235. VOID
  15236. (*PFREE_FUNCTION) (
  15237. IN PVOID Buffer
  15238. );
  15239. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  15240. typedef struct _GENERAL_LOOKASIDE {
  15241. #else
  15242. typedef struct DECLSPEC_CACHEALIGN _GENERAL_LOOKASIDE {
  15243. #endif
  15244. SLIST_HEADER ListHead;
  15245. USHORT Depth;
  15246. USHORT MaximumDepth;
  15247. ULONG TotalAllocates;
  15248. union {
  15249. ULONG AllocateMisses;
  15250. ULONG AllocateHits;
  15251. };
  15252. ULONG TotalFrees;
  15253. union {
  15254. ULONG FreeMisses;
  15255. ULONG FreeHits;
  15256. };
  15257. POOL_TYPE Type;
  15258. ULONG Tag;
  15259. ULONG Size;
  15260. PALLOCATE_FUNCTION Allocate;
  15261. PFREE_FUNCTION Free;
  15262. LIST_ENTRY ListEntry;
  15263. ULONG LastTotalAllocates;
  15264. union {
  15265. ULONG LastAllocateMisses;
  15266. ULONG LastAllocateHits;
  15267. };
  15268. ULONG Future[2];
  15269. } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
  15270. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  15271. typedef struct _NPAGED_LOOKASIDE_LIST {
  15272. #else
  15273. typedef struct DECLSPEC_CACHEALIGN _NPAGED_LOOKASIDE_LIST {
  15274. #endif
  15275. GENERAL_LOOKASIDE L;
  15276. #if !defined(_AMD64_) && !defined(_IA64_)
  15277. KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
  15278. #endif
  15279. } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
  15280. NTKERNELAPI
  15281. VOID
  15282. ExInitializeNPagedLookasideList (
  15283. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  15284. IN PALLOCATE_FUNCTION Allocate,
  15285. IN PFREE_FUNCTION Free,
  15286. IN ULONG Flags,
  15287. IN SIZE_T Size,
  15288. IN ULONG Tag,
  15289. IN USHORT Depth
  15290. );
  15291. NTKERNELAPI
  15292. VOID
  15293. ExDeleteNPagedLookasideList (
  15294. IN PNPAGED_LOOKASIDE_LIST Lookaside
  15295. );
  15296. __inline
  15297. PVOID
  15298. ExAllocateFromNPagedLookasideList(
  15299. IN PNPAGED_LOOKASIDE_LIST Lookaside
  15300. )
  15301. /*++
  15302. Routine Description:
  15303. This function removes (pops) the first entry from the specified
  15304. nonpaged lookaside list.
  15305. Arguments:
  15306. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  15307. Return Value:
  15308. If an entry is removed from the specified lookaside list, then the
  15309. address of the entry is returned as the function value. Otherwise,
  15310. NULL is returned.
  15311. --*/
  15312. {
  15313. PVOID Entry;
  15314. Lookaside->L.TotalAllocates += 1;
  15315. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  15316. Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
  15317. &Lookaside->Lock__ObsoleteButDoNotDelete);
  15318. #else
  15319. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  15320. #endif
  15321. if (Entry == NULL) {
  15322. Lookaside->L.AllocateMisses += 1;
  15323. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  15324. Lookaside->L.Size,
  15325. Lookaside->L.Tag);
  15326. }
  15327. return Entry;
  15328. }
  15329. __inline
  15330. VOID
  15331. ExFreeToNPagedLookasideList(
  15332. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  15333. IN PVOID Entry
  15334. )
  15335. /*++
  15336. Routine Description:
  15337. This function inserts (pushes) the specified entry into the specified
  15338. nonpaged lookaside list.
  15339. Arguments:
  15340. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  15341. Entry - Supples a pointer to the entry that is inserted in the
  15342. lookaside list.
  15343. Return Value:
  15344. None.
  15345. --*/
  15346. {
  15347. Lookaside->L.TotalFrees += 1;
  15348. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  15349. Lookaside->L.FreeMisses += 1;
  15350. (Lookaside->L.Free)(Entry);
  15351. } else {
  15352. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  15353. ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
  15354. (PSLIST_ENTRY)Entry,
  15355. &Lookaside->Lock__ObsoleteButDoNotDelete);
  15356. #else
  15357. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  15358. (PSLIST_ENTRY)Entry);
  15359. #endif
  15360. }
  15361. return;
  15362. }
  15363. // end_ntndis
  15364. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  15365. typedef struct _PAGED_LOOKASIDE_LIST {
  15366. #else
  15367. typedef struct DECLSPEC_CACHEALIGN _PAGED_LOOKASIDE_LIST {
  15368. #endif
  15369. GENERAL_LOOKASIDE L;
  15370. #if !defined(_AMD64_) && !defined(_IA64_)
  15371. FAST_MUTEX Lock__ObsoleteButDoNotDelete;
  15372. #endif
  15373. } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
  15374. NTKERNELAPI
  15375. VOID
  15376. ExInitializePagedLookasideList (
  15377. IN PPAGED_LOOKASIDE_LIST Lookaside,
  15378. IN PALLOCATE_FUNCTION Allocate,
  15379. IN PFREE_FUNCTION Free,
  15380. IN ULONG Flags,
  15381. IN SIZE_T Size,
  15382. IN ULONG Tag,
  15383. IN USHORT Depth
  15384. );
  15385. NTKERNELAPI
  15386. VOID
  15387. ExDeletePagedLookasideList (
  15388. IN PPAGED_LOOKASIDE_LIST Lookaside
  15389. );
  15390. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  15391. NTKERNELAPI
  15392. PVOID
  15393. ExAllocateFromPagedLookasideList(
  15394. IN PPAGED_LOOKASIDE_LIST Lookaside
  15395. );
  15396. #else
  15397. __inline
  15398. PVOID
  15399. ExAllocateFromPagedLookasideList(
  15400. IN PPAGED_LOOKASIDE_LIST Lookaside
  15401. )
  15402. /*++
  15403. Routine Description:
  15404. This function removes (pops) the first entry from the specified
  15405. paged lookaside list.
  15406. Arguments:
  15407. Lookaside - Supplies a pointer to a paged lookaside list structure.
  15408. Return Value:
  15409. If an entry is removed from the specified lookaside list, then the
  15410. address of the entry is returned as the function value. Otherwise,
  15411. NULL is returned.
  15412. --*/
  15413. {
  15414. PVOID Entry;
  15415. Lookaside->L.TotalAllocates += 1;
  15416. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  15417. if (Entry == NULL) {
  15418. Lookaside->L.AllocateMisses += 1;
  15419. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  15420. Lookaside->L.Size,
  15421. Lookaside->L.Tag);
  15422. }
  15423. return Entry;
  15424. }
  15425. #endif
  15426. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  15427. NTKERNELAPI
  15428. VOID
  15429. ExFreeToPagedLookasideList(
  15430. IN PPAGED_LOOKASIDE_LIST Lookaside,
  15431. IN PVOID Entry
  15432. );
  15433. #else
  15434. __inline
  15435. VOID
  15436. ExFreeToPagedLookasideList(
  15437. IN PPAGED_LOOKASIDE_LIST Lookaside,
  15438. IN PVOID Entry
  15439. )
  15440. /*++
  15441. Routine Description:
  15442. This function inserts (pushes) the specified entry into the specified
  15443. paged lookaside list.
  15444. Arguments:
  15445. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  15446. Entry - Supples a pointer to the entry that is inserted in the
  15447. lookaside list.
  15448. Return Value:
  15449. None.
  15450. --*/
  15451. {
  15452. Lookaside->L.TotalFrees += 1;
  15453. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  15454. Lookaside->L.FreeMisses += 1;
  15455. (Lookaside->L.Free)(Entry);
  15456. } else {
  15457. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  15458. (PSLIST_ENTRY)Entry);
  15459. }
  15460. return;
  15461. }
  15462. #endif
  15463. NTKERNELAPI
  15464. VOID
  15465. NTAPI
  15466. ProbeForRead(
  15467. IN CONST VOID *Address,
  15468. IN SIZE_T Length,
  15469. IN ULONG Alignment
  15470. );
  15471. //
  15472. // Common probe for write functions.
  15473. //
  15474. NTKERNELAPI
  15475. VOID
  15476. NTAPI
  15477. ProbeForWrite (
  15478. IN PVOID Address,
  15479. IN SIZE_T Length,
  15480. IN ULONG Alignment
  15481. );
  15482. //
  15483. // Worker Thread
  15484. //
  15485. typedef enum _WORK_QUEUE_TYPE {
  15486. CriticalWorkQueue,
  15487. DelayedWorkQueue,
  15488. HyperCriticalWorkQueue,
  15489. MaximumWorkQueue
  15490. } WORK_QUEUE_TYPE;
  15491. typedef
  15492. VOID
  15493. (*PWORKER_THREAD_ROUTINE)(
  15494. IN PVOID Parameter
  15495. );
  15496. typedef struct _WORK_QUEUE_ITEM {
  15497. LIST_ENTRY List;
  15498. PWORKER_THREAD_ROUTINE WorkerRoutine;
  15499. PVOID Parameter;
  15500. } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
  15501. #if PRAGMA_DEPRECATED_DDK
  15502. #pragma deprecated(ExInitializeWorkItem) // Use IoAllocateWorkItem
  15503. #endif
  15504. #define ExInitializeWorkItem(Item, Routine, Context) \
  15505. (Item)->WorkerRoutine = (Routine); \
  15506. (Item)->Parameter = (Context); \
  15507. (Item)->List.Flink = NULL;
  15508. DECLSPEC_DEPRECATED_DDK // Use IoQueueWorkItem
  15509. NTKERNELAPI
  15510. VOID
  15511. ExQueueWorkItem(
  15512. IN PWORK_QUEUE_ITEM WorkItem,
  15513. IN WORK_QUEUE_TYPE QueueType
  15514. );
  15515. NTKERNELAPI
  15516. BOOLEAN
  15517. ExIsProcessorFeaturePresent(
  15518. ULONG ProcessorFeature
  15519. );
  15520. //
  15521. // Zone Allocation
  15522. //
  15523. typedef struct _ZONE_SEGMENT_HEADER {
  15524. SINGLE_LIST_ENTRY SegmentList;
  15525. PVOID Reserved;
  15526. } ZONE_SEGMENT_HEADER, *PZONE_SEGMENT_HEADER;
  15527. typedef struct _ZONE_HEADER {
  15528. SINGLE_LIST_ENTRY FreeList;
  15529. SINGLE_LIST_ENTRY SegmentList;
  15530. ULONG BlockSize;
  15531. ULONG TotalSegmentSize;
  15532. } ZONE_HEADER, *PZONE_HEADER;
  15533. DECLSPEC_DEPRECATED_DDK
  15534. NTKERNELAPI
  15535. NTSTATUS
  15536. ExInitializeZone(
  15537. IN PZONE_HEADER Zone,
  15538. IN ULONG BlockSize,
  15539. IN PVOID InitialSegment,
  15540. IN ULONG InitialSegmentSize
  15541. );
  15542. DECLSPEC_DEPRECATED_DDK
  15543. NTKERNELAPI
  15544. NTSTATUS
  15545. ExExtendZone(
  15546. IN PZONE_HEADER Zone,
  15547. IN PVOID Segment,
  15548. IN ULONG SegmentSize
  15549. );
  15550. DECLSPEC_DEPRECATED_DDK
  15551. NTKERNELAPI
  15552. NTSTATUS
  15553. ExInterlockedExtendZone(
  15554. IN PZONE_HEADER Zone,
  15555. IN PVOID Segment,
  15556. IN ULONG SegmentSize,
  15557. IN PKSPIN_LOCK Lock
  15558. );
  15559. //++
  15560. //
  15561. // PVOID
  15562. // ExAllocateFromZone(
  15563. // IN PZONE_HEADER Zone
  15564. // )
  15565. //
  15566. // Routine Description:
  15567. //
  15568. // This routine removes an entry from the zone and returns a pointer to it.
  15569. //
  15570. // Arguments:
  15571. //
  15572. // Zone - Pointer to the zone header controlling the storage from which the
  15573. // entry is to be allocated.
  15574. //
  15575. // Return Value:
  15576. //
  15577. // The function value is a pointer to the storage allocated from the zone.
  15578. //
  15579. //--
  15580. #if PRAGMA_DEPRECATED_DDK
  15581. #pragma deprecated(ExAllocateFromZone)
  15582. #endif
  15583. #define ExAllocateFromZone(Zone) \
  15584. (PVOID)((Zone)->FreeList.Next); \
  15585. if ( (Zone)->FreeList.Next ) (Zone)->FreeList.Next = (Zone)->FreeList.Next->Next
  15586. //++
  15587. //
  15588. // PVOID
  15589. // ExFreeToZone(
  15590. // IN PZONE_HEADER Zone,
  15591. // IN PVOID Block
  15592. // )
  15593. //
  15594. // Routine Description:
  15595. //
  15596. // This routine places the specified block of storage back onto the free
  15597. // list in the specified zone.
  15598. //
  15599. // Arguments:
  15600. //
  15601. // Zone - Pointer to the zone header controlling the storage to which the
  15602. // entry is to be inserted.
  15603. //
  15604. // Block - Pointer to the block of storage to be freed back to the zone.
  15605. //
  15606. // Return Value:
  15607. //
  15608. // Pointer to previous block of storage that was at the head of the free
  15609. // list. NULL implies the zone went from no available free blocks to
  15610. // at least one free block.
  15611. //
  15612. //--
  15613. #if PRAGMA_DEPRECATED_DDK
  15614. #pragma deprecated(ExFreeToZone)
  15615. #endif
  15616. #define ExFreeToZone(Zone,Block) \
  15617. ( ((PSINGLE_LIST_ENTRY)(Block))->Next = (Zone)->FreeList.Next, \
  15618. (Zone)->FreeList.Next = ((PSINGLE_LIST_ENTRY)(Block)), \
  15619. ((PSINGLE_LIST_ENTRY)(Block))->Next \
  15620. )
  15621. //++
  15622. //
  15623. // BOOLEAN
  15624. // ExIsFullZone(
  15625. // IN PZONE_HEADER Zone
  15626. // )
  15627. //
  15628. // Routine Description:
  15629. //
  15630. // This routine determines if the specified zone is full or not. A zone
  15631. // is considered full if the free list is empty.
  15632. //
  15633. // Arguments:
  15634. //
  15635. // Zone - Pointer to the zone header to be tested.
  15636. //
  15637. // Return Value:
  15638. //
  15639. // TRUE if the zone is full and FALSE otherwise.
  15640. //
  15641. //--
  15642. #if PRAGMA_DEPRECATED_DDK
  15643. #pragma deprecated(ExIsFullZone)
  15644. #endif
  15645. #define ExIsFullZone(Zone) \
  15646. ( (Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY)NULL )
  15647. //++
  15648. //
  15649. // PVOID
  15650. // ExInterlockedAllocateFromZone(
  15651. // IN PZONE_HEADER Zone,
  15652. // IN PKSPIN_LOCK Lock
  15653. // )
  15654. //
  15655. // Routine Description:
  15656. //
  15657. // This routine removes an entry from the zone and returns a pointer to it.
  15658. // The removal is performed with the specified lock owned for the sequence
  15659. // to make it MP-safe.
  15660. //
  15661. // Arguments:
  15662. //
  15663. // Zone - Pointer to the zone header controlling the storage from which the
  15664. // entry is to be allocated.
  15665. //
  15666. // Lock - Pointer to the spin lock which should be obtained before removing
  15667. // the entry from the allocation list. The lock is released before
  15668. // returning to the caller.
  15669. //
  15670. // Return Value:
  15671. //
  15672. // The function value is a pointer to the storage allocated from the zone.
  15673. //
  15674. //--
  15675. #if PRAGMA_DEPRECATED_DDK
  15676. #pragma deprecated(ExInterlockedAllocateFromZone)
  15677. #endif
  15678. #define ExInterlockedAllocateFromZone(Zone,Lock) \
  15679. (PVOID) ExInterlockedPopEntryList( &(Zone)->FreeList, Lock )
  15680. //++
  15681. //
  15682. // PVOID
  15683. // ExInterlockedFreeToZone(
  15684. // IN PZONE_HEADER Zone,
  15685. // IN PVOID Block,
  15686. // IN PKSPIN_LOCK Lock
  15687. // )
  15688. //
  15689. // Routine Description:
  15690. //
  15691. // This routine places the specified block of storage back onto the free
  15692. // list in the specified zone. The insertion is performed with the lock
  15693. // owned for the sequence to make it MP-safe.
  15694. //
  15695. // Arguments:
  15696. //
  15697. // Zone - Pointer to the zone header controlling the storage to which the
  15698. // entry is to be inserted.
  15699. //
  15700. // Block - Pointer to the block of storage to be freed back to the zone.
  15701. //
  15702. // Lock - Pointer to the spin lock which should be obtained before inserting
  15703. // the entry onto the free list. The lock is released before returning
  15704. // to the caller.
  15705. //
  15706. // Return Value:
  15707. //
  15708. // Pointer to previous block of storage that was at the head of the free
  15709. // list. NULL implies the zone went from no available free blocks to
  15710. // at least one free block.
  15711. //
  15712. //--
  15713. #if PRAGMA_DEPRECATED_DDK
  15714. #pragma deprecated(ExInterlockedFreeToZone)
  15715. #endif
  15716. #define ExInterlockedFreeToZone(Zone,Block,Lock) \
  15717. ExInterlockedPushEntryList( &(Zone)->FreeList, ((PSINGLE_LIST_ENTRY) (Block)), Lock )
  15718. //++
  15719. //
  15720. // BOOLEAN
  15721. // ExIsObjectInFirstZoneSegment(
  15722. // IN PZONE_HEADER Zone,
  15723. // IN PVOID Object
  15724. // )
  15725. //
  15726. // Routine Description:
  15727. //
  15728. // This routine determines if the specified pointer lives in the zone.
  15729. //
  15730. // Arguments:
  15731. //
  15732. // Zone - Pointer to the zone header controlling the storage to which the
  15733. // object may belong.
  15734. //
  15735. // Object - Pointer to the object in question.
  15736. //
  15737. // Return Value:
  15738. //
  15739. // TRUE if the Object came from the first segment of zone.
  15740. //
  15741. //--
  15742. #if PRAGMA_DEPRECATED_DDK
  15743. #pragma deprecated(ExIsObjectInFirstZoneSegment)
  15744. #endif
  15745. #define ExIsObjectInFirstZoneSegment(Zone,Object) ((BOOLEAN) \
  15746. (((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
  15747. ((PUCHAR)(Object) < (PUCHAR)(Zone)->SegmentList.Next + \
  15748. (Zone)->TotalSegmentSize)) \
  15749. )
  15750. //
  15751. // Define executive resource data structures.
  15752. //
  15753. typedef ULONG_PTR ERESOURCE_THREAD;
  15754. typedef ERESOURCE_THREAD *PERESOURCE_THREAD;
  15755. typedef struct _OWNER_ENTRY {
  15756. ERESOURCE_THREAD OwnerThread;
  15757. union {
  15758. LONG OwnerCount;
  15759. ULONG TableSize;
  15760. };
  15761. } OWNER_ENTRY, *POWNER_ENTRY;
  15762. typedef struct _ERESOURCE {
  15763. LIST_ENTRY SystemResourcesList;
  15764. POWNER_ENTRY OwnerTable;
  15765. SHORT ActiveCount;
  15766. USHORT Flag;
  15767. PKSEMAPHORE SharedWaiters;
  15768. PKEVENT ExclusiveWaiters;
  15769. OWNER_ENTRY OwnerThreads[2];
  15770. ULONG ContentionCount;
  15771. USHORT NumberOfSharedWaiters;
  15772. USHORT NumberOfExclusiveWaiters;
  15773. union {
  15774. PVOID Address;
  15775. ULONG_PTR CreatorBackTraceIndex;
  15776. };
  15777. KSPIN_LOCK SpinLock;
  15778. } ERESOURCE, *PERESOURCE;
  15779. //
  15780. // Values for ERESOURCE.Flag
  15781. //
  15782. #define ResourceNeverExclusive 0x10
  15783. #define ResourceReleaseByOtherThread 0x20
  15784. #define ResourceOwnedExclusive 0x80
  15785. #define RESOURCE_HASH_TABLE_SIZE 64
  15786. typedef struct _RESOURCE_HASH_ENTRY {
  15787. LIST_ENTRY ListEntry;
  15788. PVOID Address;
  15789. ULONG ContentionCount;
  15790. ULONG Number;
  15791. } RESOURCE_HASH_ENTRY, *PRESOURCE_HASH_ENTRY;
  15792. typedef struct _RESOURCE_PERFORMANCE_DATA {
  15793. ULONG ActiveResourceCount;
  15794. ULONG TotalResourceCount;
  15795. ULONG ExclusiveAcquire;
  15796. ULONG SharedFirstLevel;
  15797. ULONG SharedSecondLevel;
  15798. ULONG StarveFirstLevel;
  15799. ULONG StarveSecondLevel;
  15800. ULONG WaitForExclusive;
  15801. ULONG OwnerTableExpands;
  15802. ULONG MaximumTableExpand;
  15803. LIST_ENTRY HashTable[RESOURCE_HASH_TABLE_SIZE];
  15804. } RESOURCE_PERFORMANCE_DATA, *PRESOURCE_PERFORMANCE_DATA;
  15805. //
  15806. // Define executive resource function prototypes.
  15807. //
  15808. NTKERNELAPI
  15809. NTSTATUS
  15810. ExInitializeResourceLite(
  15811. IN PERESOURCE Resource
  15812. );
  15813. NTKERNELAPI
  15814. NTSTATUS
  15815. ExReinitializeResourceLite(
  15816. IN PERESOURCE Resource
  15817. );
  15818. NTKERNELAPI
  15819. BOOLEAN
  15820. ExAcquireResourceSharedLite(
  15821. IN PERESOURCE Resource,
  15822. IN BOOLEAN Wait
  15823. );
  15824. NTKERNELAPI
  15825. BOOLEAN
  15826. ExAcquireResourceExclusiveLite(
  15827. IN PERESOURCE Resource,
  15828. IN BOOLEAN Wait
  15829. );
  15830. NTKERNELAPI
  15831. BOOLEAN
  15832. ExAcquireSharedStarveExclusive(
  15833. IN PERESOURCE Resource,
  15834. IN BOOLEAN Wait
  15835. );
  15836. NTKERNELAPI
  15837. BOOLEAN
  15838. ExAcquireSharedWaitForExclusive(
  15839. IN PERESOURCE Resource,
  15840. IN BOOLEAN Wait
  15841. );
  15842. NTKERNELAPI
  15843. BOOLEAN
  15844. ExTryToAcquireResourceExclusiveLite(
  15845. IN PERESOURCE Resource
  15846. );
  15847. //
  15848. // VOID
  15849. // ExReleaseResource(
  15850. // IN PERESOURCE Resource
  15851. // );
  15852. //
  15853. #if PRAGMA_DEPRECATED_DDK
  15854. #pragma deprecated(ExReleaseResource) // Use ExReleaseResourceLite
  15855. #endif
  15856. #define ExReleaseResource(R) (ExReleaseResourceLite(R))
  15857. NTKERNELAPI
  15858. VOID
  15859. FASTCALL
  15860. ExReleaseResourceLite(
  15861. IN PERESOURCE Resource
  15862. );
  15863. NTKERNELAPI
  15864. VOID
  15865. ExReleaseResourceForThreadLite(
  15866. IN PERESOURCE Resource,
  15867. IN ERESOURCE_THREAD ResourceThreadId
  15868. );
  15869. NTKERNELAPI
  15870. VOID
  15871. ExSetResourceOwnerPointer(
  15872. IN PERESOURCE Resource,
  15873. IN PVOID OwnerPointer
  15874. );
  15875. NTKERNELAPI
  15876. VOID
  15877. ExConvertExclusiveToSharedLite(
  15878. IN PERESOURCE Resource
  15879. );
  15880. NTKERNELAPI
  15881. NTSTATUS
  15882. ExDeleteResourceLite (
  15883. IN PERESOURCE Resource
  15884. );
  15885. NTKERNELAPI
  15886. ULONG
  15887. ExGetExclusiveWaiterCount (
  15888. IN PERESOURCE Resource
  15889. );
  15890. NTKERNELAPI
  15891. ULONG
  15892. ExGetSharedWaiterCount (
  15893. IN PERESOURCE Resource
  15894. );
  15895. // end_ntddk end_wdm end_ntosp
  15896. NTKERNELAPI
  15897. VOID
  15898. ExDisableResourceBoostLite (
  15899. IN PERESOURCE Resource
  15900. );
  15901. // begin_ntddk begin_wdm begin_ntosp
  15902. //
  15903. // ERESOURCE_THREAD
  15904. // ExGetCurrentResourceThread(
  15905. // );
  15906. //
  15907. #define ExGetCurrentResourceThread() ((ULONG_PTR)PsGetCurrentThread())
  15908. NTKERNELAPI
  15909. BOOLEAN
  15910. ExIsResourceAcquiredExclusiveLite (
  15911. IN PERESOURCE Resource
  15912. );
  15913. NTKERNELAPI
  15914. ULONG
  15915. ExIsResourceAcquiredSharedLite (
  15916. IN PERESOURCE Resource
  15917. );
  15918. //
  15919. // An acquired resource is always owned shared, as shared ownership is a subset
  15920. // of exclusive ownership.
  15921. //
  15922. #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
  15923. // end_wdm
  15924. //
  15925. // ntddk.h stole the entrypoints we wanted so fix them up here.
  15926. //
  15927. #if PRAGMA_DEPRECATED_DDK
  15928. #pragma deprecated(ExInitializeResource) // use ExInitializeResourceLite
  15929. #pragma deprecated(ExAcquireResourceShared) // use ExAcquireResourceSharedLite
  15930. #pragma deprecated(ExAcquireResourceExclusive) // use ExAcquireResourceExclusiveLite
  15931. #pragma deprecated(ExReleaseResourceForThread) // use ExReleaseResourceForThreadLite
  15932. #pragma deprecated(ExConvertExclusiveToShared) // use ExConvertExclusiveToSharedLite
  15933. #pragma deprecated(ExDeleteResource) // use ExDeleteResourceLite
  15934. #pragma deprecated(ExIsResourceAcquiredExclusive) // use ExIsResourceAcquiredExclusiveLite
  15935. #pragma deprecated(ExIsResourceAcquiredShared) // use ExIsResourceAcquiredSharedLite
  15936. #pragma deprecated(ExIsResourceAcquired) // use ExIsResourceAcquiredSharedLite
  15937. #endif
  15938. #define ExInitializeResource ExInitializeResourceLite
  15939. #define ExAcquireResourceShared ExAcquireResourceSharedLite
  15940. #define ExAcquireResourceExclusive ExAcquireResourceExclusiveLite
  15941. #define ExReleaseResourceForThread ExReleaseResourceForThreadLite
  15942. #define ExConvertExclusiveToShared ExConvertExclusiveToSharedLite
  15943. #define ExDeleteResource ExDeleteResourceLite
  15944. #define ExIsResourceAcquiredExclusive ExIsResourceAcquiredExclusiveLite
  15945. #define ExIsResourceAcquiredShared ExIsResourceAcquiredSharedLite
  15946. #define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
  15947. // end_ntddk end_ntosp
  15948. #define ExDisableResourceBoost ExDisableResourceBoostLite
  15949. //
  15950. // Get previous mode
  15951. //
  15952. NTKERNELAPI
  15953. KPROCESSOR_MODE
  15954. ExGetPreviousMode(
  15955. VOID
  15956. );
  15957. //
  15958. // Raise status from kernel mode.
  15959. //
  15960. NTKERNELAPI
  15961. VOID
  15962. NTAPI
  15963. ExRaiseStatus (
  15964. IN NTSTATUS Status
  15965. );
  15966. // end_wdm
  15967. NTKERNELAPI
  15968. VOID
  15969. ExRaiseDatatypeMisalignment (
  15970. VOID
  15971. );
  15972. NTKERNELAPI
  15973. VOID
  15974. ExRaiseAccessViolation (
  15975. VOID
  15976. );
  15977. //
  15978. // Set timer resolution.
  15979. //
  15980. NTKERNELAPI
  15981. ULONG
  15982. ExSetTimerResolution (
  15983. IN ULONG DesiredTime,
  15984. IN BOOLEAN SetResolution
  15985. );
  15986. //
  15987. // Subtract time zone bias from system time to get local time.
  15988. //
  15989. NTKERNELAPI
  15990. VOID
  15991. ExSystemTimeToLocalTime (
  15992. IN PLARGE_INTEGER SystemTime,
  15993. OUT PLARGE_INTEGER LocalTime
  15994. );
  15995. //
  15996. // Add time zone bias to local time to get system time.
  15997. //
  15998. NTKERNELAPI
  15999. VOID
  16000. ExLocalTimeToSystemTime (
  16001. IN PLARGE_INTEGER LocalTime,
  16002. OUT PLARGE_INTEGER SystemTime
  16003. );
  16004. //
  16005. // Define the type for Callback function.
  16006. //
  16007. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  16008. typedef VOID (*PCALLBACK_FUNCTION ) (
  16009. IN PVOID CallbackContext,
  16010. IN PVOID Argument1,
  16011. IN PVOID Argument2
  16012. );
  16013. NTKERNELAPI
  16014. NTSTATUS
  16015. ExCreateCallback (
  16016. OUT PCALLBACK_OBJECT *CallbackObject,
  16017. IN POBJECT_ATTRIBUTES ObjectAttributes,
  16018. IN BOOLEAN Create,
  16019. IN BOOLEAN AllowMultipleCallbacks
  16020. );
  16021. NTKERNELAPI
  16022. PVOID
  16023. ExRegisterCallback (
  16024. IN PCALLBACK_OBJECT CallbackObject,
  16025. IN PCALLBACK_FUNCTION CallbackFunction,
  16026. IN PVOID CallbackContext
  16027. );
  16028. NTKERNELAPI
  16029. VOID
  16030. ExUnregisterCallback (
  16031. IN PVOID CallbackRegistration
  16032. );
  16033. NTKERNELAPI
  16034. VOID
  16035. ExNotifyCallback (
  16036. IN PVOID CallbackObject,
  16037. IN PVOID Argument1,
  16038. IN PVOID Argument2
  16039. );
  16040. //
  16041. // UUID Generation
  16042. //
  16043. typedef GUID UUID;
  16044. NTKERNELAPI
  16045. NTSTATUS
  16046. ExUuidCreate(
  16047. OUT UUID *Uuid
  16048. );
  16049. //
  16050. // suite support
  16051. //
  16052. NTKERNELAPI
  16053. BOOLEAN
  16054. ExVerifySuite(
  16055. SUITE_TYPE SuiteType
  16056. );
  16057. //
  16058. // Security operation codes
  16059. //
  16060. typedef enum _SECURITY_OPERATION_CODE {
  16061. SetSecurityDescriptor,
  16062. QuerySecurityDescriptor,
  16063. DeleteSecurityDescriptor,
  16064. AssignSecurityDescriptor
  16065. } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
  16066. //
  16067. // Token Flags
  16068. //
  16069. // Flags that may be defined in the TokenFlags field of the token object,
  16070. // or in an ACCESS_STATE structure
  16071. //
  16072. #define TOKEN_HAS_TRAVERSE_PRIVILEGE 0x01
  16073. #define TOKEN_HAS_BACKUP_PRIVILEGE 0x02
  16074. #define TOKEN_HAS_RESTORE_PRIVILEGE 0x04
  16075. #define TOKEN_HAS_ADMIN_GROUP 0x08
  16076. #define TOKEN_IS_RESTRICTED 0x10
  16077. #define TOKEN_SESSION_NOT_REFERENCED 0x20
  16078. #define TOKEN_SANDBOX_INERT 0x40
  16079. //
  16080. // Data structure used to capture subject security context
  16081. // for access validations and auditing.
  16082. //
  16083. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  16084. // BY ALL EXCEPT THE SECURITY ROUTINES.
  16085. //
  16086. typedef struct _SECURITY_SUBJECT_CONTEXT {
  16087. PACCESS_TOKEN ClientToken;
  16088. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  16089. PACCESS_TOKEN PrimaryToken;
  16090. PVOID ProcessAuditId;
  16091. } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
  16092. ///////////////////////////////////////////////////////////////////////////////
  16093. // //
  16094. // ACCESS_STATE and related structures //
  16095. // //
  16096. ///////////////////////////////////////////////////////////////////////////////
  16097. //
  16098. // Initial Privilege Set - Room for three privileges, which should
  16099. // be enough for most applications. This structure exists so that
  16100. // it can be imbedded in an ACCESS_STATE structure. Use PRIVILEGE_SET
  16101. // for all other references to Privilege sets.
  16102. //
  16103. #define INITIAL_PRIVILEGE_COUNT 3
  16104. typedef struct _INITIAL_PRIVILEGE_SET {
  16105. ULONG PrivilegeCount;
  16106. ULONG Control;
  16107. LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
  16108. } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
  16109. //
  16110. // Combine the information that describes the state
  16111. // of an access-in-progress into a single structure
  16112. //
  16113. typedef struct _ACCESS_STATE {
  16114. LUID OperationID;
  16115. BOOLEAN SecurityEvaluated;
  16116. BOOLEAN GenerateAudit;
  16117. BOOLEAN GenerateOnClose;
  16118. BOOLEAN PrivilegesAllocated;
  16119. ULONG Flags;
  16120. ACCESS_MASK RemainingDesiredAccess;
  16121. ACCESS_MASK PreviouslyGrantedAccess;
  16122. ACCESS_MASK OriginalDesiredAccess;
  16123. SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
  16124. PSECURITY_DESCRIPTOR SecurityDescriptor;
  16125. PVOID AuxData;
  16126. union {
  16127. INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
  16128. PRIVILEGE_SET PrivilegeSet;
  16129. } Privileges;
  16130. BOOLEAN AuditPrivileges;
  16131. UNICODE_STRING ObjectName;
  16132. UNICODE_STRING ObjectTypeName;
  16133. } ACCESS_STATE, *PACCESS_STATE;
  16134. typedef struct _SE_EXPORTS {
  16135. //
  16136. // Privilege values
  16137. //
  16138. LUID SeCreateTokenPrivilege;
  16139. LUID SeAssignPrimaryTokenPrivilege;
  16140. LUID SeLockMemoryPrivilege;
  16141. LUID SeIncreaseQuotaPrivilege;
  16142. LUID SeUnsolicitedInputPrivilege;
  16143. LUID SeTcbPrivilege;
  16144. LUID SeSecurityPrivilege;
  16145. LUID SeTakeOwnershipPrivilege;
  16146. LUID SeLoadDriverPrivilege;
  16147. LUID SeCreatePagefilePrivilege;
  16148. LUID SeIncreaseBasePriorityPrivilege;
  16149. LUID SeSystemProfilePrivilege;
  16150. LUID SeSystemtimePrivilege;
  16151. LUID SeProfileSingleProcessPrivilege;
  16152. LUID SeCreatePermanentPrivilege;
  16153. LUID SeBackupPrivilege;
  16154. LUID SeRestorePrivilege;
  16155. LUID SeShutdownPrivilege;
  16156. LUID SeDebugPrivilege;
  16157. LUID SeAuditPrivilege;
  16158. LUID SeSystemEnvironmentPrivilege;
  16159. LUID SeChangeNotifyPrivilege;
  16160. LUID SeRemoteShutdownPrivilege;
  16161. //
  16162. // Universally defined Sids
  16163. //
  16164. PSID SeNullSid;
  16165. PSID SeWorldSid;
  16166. PSID SeLocalSid;
  16167. PSID SeCreatorOwnerSid;
  16168. PSID SeCreatorGroupSid;
  16169. //
  16170. // Nt defined Sids
  16171. //
  16172. PSID SeNtAuthoritySid;
  16173. PSID SeDialupSid;
  16174. PSID SeNetworkSid;
  16175. PSID SeBatchSid;
  16176. PSID SeInteractiveSid;
  16177. PSID SeLocalSystemSid;
  16178. PSID SeAliasAdminsSid;
  16179. PSID SeAliasUsersSid;
  16180. PSID SeAliasGuestsSid;
  16181. PSID SeAliasPowerUsersSid;
  16182. PSID SeAliasAccountOpsSid;
  16183. PSID SeAliasSystemOpsSid;
  16184. PSID SeAliasPrintOpsSid;
  16185. PSID SeAliasBackupOpsSid;
  16186. //
  16187. // New Sids defined for NT5
  16188. //
  16189. PSID SeAuthenticatedUsersSid;
  16190. PSID SeRestrictedSid;
  16191. PSID SeAnonymousLogonSid;
  16192. //
  16193. // New Privileges defined for NT5
  16194. //
  16195. LUID SeUndockPrivilege;
  16196. LUID SeSyncAgentPrivilege;
  16197. LUID SeEnableDelegationPrivilege;
  16198. //
  16199. // New Sids defined for post-Windows 2000
  16200. PSID SeLocalServiceSid;
  16201. PSID SeNetworkServiceSid;
  16202. //
  16203. // New Privileges defined for post-Windows 2000
  16204. //
  16205. LUID SeManageVolumePrivilege;
  16206. } SE_EXPORTS, *PSE_EXPORTS;
  16207. ///////////////////////////////////////////////////////////////////////////////
  16208. // //
  16209. // Logon session notification callback routines //
  16210. // //
  16211. ///////////////////////////////////////////////////////////////////////////////
  16212. //
  16213. // These callback routines are used to notify file systems that have
  16214. // registered of logon sessions being terminated, so they can cleanup state
  16215. // associated with this logon session
  16216. //
  16217. typedef NTSTATUS
  16218. (*PSE_LOGON_SESSION_TERMINATED_ROUTINE)(
  16219. IN PLUID LogonId);
  16220. //++
  16221. //
  16222. // ULONG
  16223. // SeLengthSid(
  16224. // IN PSID Sid
  16225. // );
  16226. //
  16227. // Routine Description:
  16228. //
  16229. // This routine computes the length of a SID.
  16230. //
  16231. // Arguments:
  16232. //
  16233. // Sid - Points to the SID whose length is to be returned.
  16234. //
  16235. // Return Value:
  16236. //
  16237. // The length, in bytes of the SID.
  16238. //
  16239. //--
  16240. #define SeLengthSid( Sid ) \
  16241. (8 + (4 * ((SID *)Sid)->SubAuthorityCount))
  16242. //
  16243. //VOID
  16244. //SeDeleteClientSecurity(
  16245. // IN PSECURITY_CLIENT_CONTEXT ClientContext
  16246. // )
  16247. //
  16248. ///*++
  16249. //
  16250. //Routine Description:
  16251. //
  16252. // This service deletes a client security context block,
  16253. // performing whatever cleanup might be necessary to do so. In
  16254. // particular, reference to any client token is removed.
  16255. //
  16256. //Arguments:
  16257. //
  16258. // ClientContext - Points to the client security context block to be
  16259. // deleted.
  16260. //
  16261. //
  16262. //Return Value:
  16263. //
  16264. //
  16265. //
  16266. //--*/
  16267. //--
  16268. // begin_ntosp
  16269. #define SeDeleteClientSecurity(C) { \
  16270. if (SeTokenType((C)->ClientToken) == TokenPrimary) { \
  16271. PsDereferencePrimaryToken( (C)->ClientToken ); \
  16272. } else { \
  16273. PsDereferenceImpersonationToken( (C)->ClientToken ); \
  16274. } \
  16275. }
  16276. //++
  16277. //
  16278. // PACCESS_TOKEN
  16279. // SeQuerySubjectContextToken(
  16280. // IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  16281. // );
  16282. //
  16283. // Routine Description:
  16284. //
  16285. // This routine returns the effective token from the subject context,
  16286. // either the client token, if present, or the process token.
  16287. //
  16288. // Arguments:
  16289. //
  16290. // SubjectContext - Context to query
  16291. //
  16292. // Return Value:
  16293. //
  16294. // This routine returns the PACCESS_TOKEN for the effective token.
  16295. // The pointer may be passed to SeQueryInformationToken. This routine
  16296. // does not affect the lock status of the token, i.e. the token is not
  16297. // locked. If the SubjectContext has been locked, the token remains locked,
  16298. // if not, the token remains unlocked.
  16299. //
  16300. //--
  16301. #define SeQuerySubjectContextToken( SubjectContext ) \
  16302. ( ARGUMENT_PRESENT( ((PSECURITY_SUBJECT_CONTEXT) SubjectContext)->ClientToken) ? \
  16303. ((PSECURITY_SUBJECT_CONTEXT) SubjectContext)->ClientToken : \
  16304. ((PSECURITY_SUBJECT_CONTEXT) SubjectContext)->PrimaryToken )
  16305. NTKERNELAPI
  16306. VOID
  16307. SeCaptureSubjectContext (
  16308. OUT PSECURITY_SUBJECT_CONTEXT SubjectContext
  16309. );
  16310. NTKERNELAPI
  16311. VOID
  16312. SeLockSubjectContext(
  16313. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  16314. );
  16315. NTKERNELAPI
  16316. VOID
  16317. SeUnlockSubjectContext(
  16318. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  16319. );
  16320. NTKERNELAPI
  16321. VOID
  16322. SeReleaseSubjectContext (
  16323. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  16324. );
  16325. NTKERNELAPI
  16326. NTSTATUS
  16327. SeAssignSecurity (
  16328. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  16329. IN PSECURITY_DESCRIPTOR ExplicitDescriptor,
  16330. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  16331. IN BOOLEAN IsDirectoryObject,
  16332. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  16333. IN PGENERIC_MAPPING GenericMapping,
  16334. IN POOL_TYPE PoolType
  16335. );
  16336. NTKERNELAPI
  16337. NTSTATUS
  16338. SeAssignSecurityEx (
  16339. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  16340. IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL,
  16341. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  16342. IN GUID *ObjectType OPTIONAL,
  16343. IN BOOLEAN IsDirectoryObject,
  16344. IN ULONG AutoInheritFlags,
  16345. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  16346. IN PGENERIC_MAPPING GenericMapping,
  16347. IN POOL_TYPE PoolType
  16348. );
  16349. NTKERNELAPI
  16350. NTSTATUS
  16351. SeDeassignSecurity (
  16352. IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
  16353. );
  16354. NTKERNELAPI
  16355. BOOLEAN
  16356. SeAccessCheck (
  16357. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  16358. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  16359. IN BOOLEAN SubjectContextLocked,
  16360. IN ACCESS_MASK DesiredAccess,
  16361. IN ACCESS_MASK PreviouslyGrantedAccess,
  16362. OUT PPRIVILEGE_SET *Privileges OPTIONAL,
  16363. IN PGENERIC_MAPPING GenericMapping,
  16364. IN KPROCESSOR_MODE AccessMode,
  16365. OUT PACCESS_MASK GrantedAccess,
  16366. OUT PNTSTATUS AccessStatus
  16367. );
  16368. #ifdef SE_NTFS_WORLD_CACHE
  16369. VOID
  16370. SeGetWorldRights (
  16371. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  16372. IN PGENERIC_MAPPING GenericMapping,
  16373. OUT PACCESS_MASK GrantedAccess
  16374. );
  16375. #endif
  16376. NTKERNELAPI
  16377. BOOLEAN
  16378. SePrivilegeCheck(
  16379. IN OUT PPRIVILEGE_SET RequiredPrivileges,
  16380. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  16381. IN KPROCESSOR_MODE AccessMode
  16382. );
  16383. NTKERNELAPI
  16384. VOID
  16385. SeFreePrivileges(
  16386. IN PPRIVILEGE_SET Privileges
  16387. );
  16388. NTKERNELAPI
  16389. VOID
  16390. SeOpenObjectAuditAlarm (
  16391. IN PUNICODE_STRING ObjectTypeName,
  16392. IN PVOID Object OPTIONAL,
  16393. IN PUNICODE_STRING AbsoluteObjectName OPTIONAL,
  16394. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  16395. IN PACCESS_STATE AccessState,
  16396. IN BOOLEAN ObjectCreated,
  16397. IN BOOLEAN AccessGranted,
  16398. IN KPROCESSOR_MODE AccessMode,
  16399. OUT PBOOLEAN GenerateOnClose
  16400. );
  16401. NTKERNELAPI
  16402. VOID
  16403. SeOpenObjectForDeleteAuditAlarm (
  16404. IN PUNICODE_STRING ObjectTypeName,
  16405. IN PVOID Object OPTIONAL,
  16406. IN PUNICODE_STRING AbsoluteObjectName OPTIONAL,
  16407. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  16408. IN PACCESS_STATE AccessState,
  16409. IN BOOLEAN ObjectCreated,
  16410. IN BOOLEAN AccessGranted,
  16411. IN KPROCESSOR_MODE AccessMode,
  16412. OUT PBOOLEAN GenerateOnClose
  16413. );
  16414. VOID
  16415. SeDeleteObjectAuditAlarm(
  16416. IN PVOID Object,
  16417. IN HANDLE Handle
  16418. );
  16419. NTKERNELAPI
  16420. BOOLEAN
  16421. SeValidSecurityDescriptor(
  16422. IN ULONG Length,
  16423. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  16424. );
  16425. NTKERNELAPI
  16426. TOKEN_TYPE
  16427. SeTokenType(
  16428. IN PACCESS_TOKEN Token
  16429. );
  16430. NTKERNELAPI
  16431. BOOLEAN
  16432. SeTokenIsAdmin(
  16433. IN PACCESS_TOKEN Token
  16434. );
  16435. NTKERNELAPI
  16436. BOOLEAN
  16437. SeTokenIsRestricted(
  16438. IN PACCESS_TOKEN Token
  16439. );
  16440. NTSTATUS
  16441. SeFilterToken (
  16442. IN PACCESS_TOKEN ExistingToken,
  16443. IN ULONG Flags,
  16444. IN PTOKEN_GROUPS SidsToDisable OPTIONAL,
  16445. IN PTOKEN_PRIVILEGES PrivilegesToDelete OPTIONAL,
  16446. IN PTOKEN_GROUPS RestrictedSids OPTIONAL,
  16447. OUT PACCESS_TOKEN * FilteredToken
  16448. );
  16449. // begin_ntosp
  16450. NTKERNELAPI
  16451. NTSTATUS
  16452. SeQueryAuthenticationIdToken(
  16453. IN PACCESS_TOKEN Token,
  16454. OUT PLUID AuthenticationId
  16455. );
  16456. // end_ntosp
  16457. NTKERNELAPI
  16458. NTSTATUS
  16459. SeQuerySessionIdToken(
  16460. IN PACCESS_TOKEN,
  16461. IN PULONG pSessionId
  16462. );
  16463. NTKERNELAPI
  16464. NTSTATUS
  16465. SeSetSessionIdToken(
  16466. IN PACCESS_TOKEN,
  16467. IN ULONG SessionId
  16468. );
  16469. // begin_ntosp
  16470. NTKERNELAPI
  16471. NTSTATUS
  16472. SeCreateClientSecurity (
  16473. IN PETHREAD ClientThread,
  16474. IN PSECURITY_QUALITY_OF_SERVICE ClientSecurityQos,
  16475. IN BOOLEAN RemoteSession,
  16476. OUT PSECURITY_CLIENT_CONTEXT ClientContext
  16477. );
  16478. // end_ntosp
  16479. NTKERNELAPI
  16480. VOID
  16481. SeImpersonateClient(
  16482. IN PSECURITY_CLIENT_CONTEXT ClientContext,
  16483. IN PETHREAD ServerThread OPTIONAL
  16484. );
  16485. // begin_ntosp
  16486. NTKERNELAPI
  16487. NTSTATUS
  16488. SeImpersonateClientEx(
  16489. IN PSECURITY_CLIENT_CONTEXT ClientContext,
  16490. IN PETHREAD ServerThread OPTIONAL
  16491. );
  16492. // end_ntosp
  16493. NTKERNELAPI
  16494. NTSTATUS
  16495. SeCreateClientSecurityFromSubjectContext (
  16496. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  16497. IN PSECURITY_QUALITY_OF_SERVICE ClientSecurityQos,
  16498. IN BOOLEAN ServerIsRemote,
  16499. OUT PSECURITY_CLIENT_CONTEXT ClientContext
  16500. );
  16501. NTKERNELAPI
  16502. NTSTATUS
  16503. SeQuerySecurityDescriptorInfo (
  16504. IN PSECURITY_INFORMATION SecurityInformation,
  16505. OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  16506. IN OUT PULONG Length,
  16507. IN PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor
  16508. );
  16509. NTKERNELAPI
  16510. NTSTATUS
  16511. SeSetSecurityDescriptorInfo (
  16512. IN PVOID Object OPTIONAL,
  16513. IN PSECURITY_INFORMATION SecurityInformation,
  16514. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  16515. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  16516. IN POOL_TYPE PoolType,
  16517. IN PGENERIC_MAPPING GenericMapping
  16518. );
  16519. NTKERNELAPI
  16520. NTSTATUS
  16521. SeSetSecurityDescriptorInfoEx (
  16522. IN PVOID Object OPTIONAL,
  16523. IN PSECURITY_INFORMATION SecurityInformation,
  16524. IN PSECURITY_DESCRIPTOR ModificationDescriptor,
  16525. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  16526. IN ULONG AutoInheritFlags,
  16527. IN POOL_TYPE PoolType,
  16528. IN PGENERIC_MAPPING GenericMapping
  16529. );
  16530. NTKERNELAPI
  16531. NTSTATUS
  16532. SeAppendPrivileges(
  16533. PACCESS_STATE AccessState,
  16534. PPRIVILEGE_SET Privileges
  16535. );
  16536. NTKERNELAPI
  16537. BOOLEAN
  16538. SeSinglePrivilegeCheck(
  16539. LUID PrivilegeValue,
  16540. KPROCESSOR_MODE PreviousMode
  16541. );
  16542. NTKERNELAPI
  16543. BOOLEAN
  16544. SeAuditingFileEvents(
  16545. IN BOOLEAN AccessGranted,
  16546. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  16547. );
  16548. BOOLEAN
  16549. SeAuditingHardLinkEvents(
  16550. IN BOOLEAN AccessGranted,
  16551. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  16552. );
  16553. NTKERNELAPI
  16554. BOOLEAN
  16555. SeAuditingFileOrGlobalEvents(
  16556. IN BOOLEAN AccessGranted,
  16557. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  16558. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext
  16559. );
  16560. VOID
  16561. SeAuditHardLinkCreation(
  16562. IN PUNICODE_STRING FileName,
  16563. IN PUNICODE_STRING LinkName,
  16564. IN BOOLEAN bSuccess
  16565. );
  16566. VOID
  16567. SeSetAccessStateGenericMapping (
  16568. PACCESS_STATE AccessState,
  16569. PGENERIC_MAPPING GenericMapping
  16570. );
  16571. NTKERNELAPI
  16572. NTSTATUS
  16573. SeRegisterLogonSessionTerminatedRoutine(
  16574. IN PSE_LOGON_SESSION_TERMINATED_ROUTINE CallbackRoutine
  16575. );
  16576. NTKERNELAPI
  16577. NTSTATUS
  16578. SeUnregisterLogonSessionTerminatedRoutine(
  16579. IN PSE_LOGON_SESSION_TERMINATED_ROUTINE CallbackRoutine
  16580. );
  16581. NTKERNELAPI
  16582. NTSTATUS
  16583. SeMarkLogonSessionForTerminationNotification(
  16584. IN PLUID LogonId
  16585. );
  16586. // begin_ntosp
  16587. NTKERNELAPI
  16588. NTSTATUS
  16589. SeQueryInformationToken (
  16590. IN PACCESS_TOKEN Token,
  16591. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  16592. OUT PVOID *TokenInformation
  16593. );
  16594. //
  16595. // Grants access to SeExports structure
  16596. //
  16597. extern NTKERNELAPI PSE_EXPORTS SeExports;
  16598. //
  16599. // System Thread and Process Creation and Termination
  16600. //
  16601. NTKERNELAPI
  16602. NTSTATUS
  16603. PsCreateSystemThread(
  16604. OUT PHANDLE ThreadHandle,
  16605. IN ULONG DesiredAccess,
  16606. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  16607. IN HANDLE ProcessHandle OPTIONAL,
  16608. OUT PCLIENT_ID ClientId OPTIONAL,
  16609. IN PKSTART_ROUTINE StartRoutine,
  16610. IN PVOID StartContext
  16611. );
  16612. NTKERNELAPI
  16613. NTSTATUS
  16614. PsTerminateSystemThread(
  16615. IN NTSTATUS ExitStatus
  16616. );
  16617. typedef
  16618. VOID
  16619. (*PCREATE_PROCESS_NOTIFY_ROUTINE)(
  16620. IN HANDLE ParentId,
  16621. IN HANDLE ProcessId,
  16622. IN BOOLEAN Create
  16623. );
  16624. NTSTATUS
  16625. PsSetCreateProcessNotifyRoutine(
  16626. IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
  16627. IN BOOLEAN Remove
  16628. );
  16629. typedef
  16630. VOID
  16631. (*PCREATE_THREAD_NOTIFY_ROUTINE)(
  16632. IN HANDLE ProcessId,
  16633. IN HANDLE ThreadId,
  16634. IN BOOLEAN Create
  16635. );
  16636. NTSTATUS
  16637. PsSetCreateThreadNotifyRoutine(
  16638. IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
  16639. );
  16640. NTSTATUS
  16641. PsRemoveCreateThreadNotifyRoutine (
  16642. IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
  16643. );
  16644. //
  16645. // Structures for Load Image Notify
  16646. //
  16647. typedef struct _IMAGE_INFO {
  16648. union {
  16649. ULONG Properties;
  16650. struct {
  16651. ULONG ImageAddressingMode : 8; // code addressing mode
  16652. ULONG SystemModeImage : 1; // system mode image
  16653. ULONG ImageMappedToAllPids : 1; // image mapped into all processes
  16654. ULONG Reserved : 22;
  16655. };
  16656. };
  16657. PVOID ImageBase;
  16658. ULONG ImageSelector;
  16659. SIZE_T ImageSize;
  16660. ULONG ImageSectionNumber;
  16661. } IMAGE_INFO, *PIMAGE_INFO;
  16662. #define IMAGE_ADDRESSING_MODE_32BIT 3
  16663. typedef
  16664. VOID
  16665. (*PLOAD_IMAGE_NOTIFY_ROUTINE)(
  16666. IN PUNICODE_STRING FullImageName,
  16667. IN HANDLE ProcessId, // pid into which image is being mapped
  16668. IN PIMAGE_INFO ImageInfo
  16669. );
  16670. NTSTATUS
  16671. PsSetLoadImageNotifyRoutine(
  16672. IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
  16673. );
  16674. NTSTATUS
  16675. PsRemoveLoadImageNotifyRoutine(
  16676. IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
  16677. );
  16678. // end_ntddk
  16679. //
  16680. // Security Support
  16681. //
  16682. NTSTATUS
  16683. PsAssignImpersonationToken(
  16684. IN PETHREAD Thread,
  16685. IN HANDLE Token
  16686. );
  16687. // begin_ntosp
  16688. NTKERNELAPI
  16689. PACCESS_TOKEN
  16690. PsReferencePrimaryToken(
  16691. IN PEPROCESS Process
  16692. );
  16693. VOID
  16694. PsDereferencePrimaryToken(
  16695. IN PACCESS_TOKEN PrimaryToken
  16696. );
  16697. VOID
  16698. PsDereferenceImpersonationToken(
  16699. IN PACCESS_TOKEN ImpersonationToken
  16700. );
  16701. NTKERNELAPI
  16702. PACCESS_TOKEN
  16703. PsReferenceImpersonationToken(
  16704. IN PETHREAD Thread,
  16705. OUT PBOOLEAN CopyOnOpen,
  16706. OUT PBOOLEAN EffectiveOnly,
  16707. OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  16708. );
  16709. LARGE_INTEGER
  16710. PsGetProcessExitTime(
  16711. VOID
  16712. );
  16713. BOOLEAN
  16714. PsIsThreadTerminating(
  16715. IN PETHREAD Thread
  16716. );
  16717. // begin_ntosp
  16718. NTSTATUS
  16719. PsImpersonateClient(
  16720. IN PETHREAD Thread,
  16721. IN PACCESS_TOKEN Token,
  16722. IN BOOLEAN CopyOnOpen,
  16723. IN BOOLEAN EffectiveOnly,
  16724. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  16725. );
  16726. // end_ntosp
  16727. BOOLEAN
  16728. PsDisableImpersonation(
  16729. IN PETHREAD Thread,
  16730. IN PSE_IMPERSONATION_STATE ImpersonationState
  16731. );
  16732. VOID
  16733. PsRestoreImpersonation(
  16734. IN PETHREAD Thread,
  16735. IN PSE_IMPERSONATION_STATE ImpersonationState
  16736. );
  16737. //
  16738. // Quota Operations
  16739. //
  16740. VOID
  16741. PsChargePoolQuota(
  16742. IN PEPROCESS Process,
  16743. IN POOL_TYPE PoolType,
  16744. IN ULONG_PTR Amount
  16745. );
  16746. NTSTATUS
  16747. PsChargeProcessPoolQuota(
  16748. IN PEPROCESS Process,
  16749. IN POOL_TYPE PoolType,
  16750. IN ULONG_PTR Amount
  16751. );
  16752. VOID
  16753. PsReturnPoolQuota(
  16754. IN PEPROCESS Process,
  16755. IN POOL_TYPE PoolType,
  16756. IN ULONG_PTR Amount
  16757. );
  16758. HANDLE
  16759. PsGetCurrentProcessId( VOID );
  16760. HANDLE
  16761. PsGetCurrentThreadId( VOID );
  16762. // end_ntosp
  16763. BOOLEAN
  16764. PsGetVersion(
  16765. PULONG MajorVersion OPTIONAL,
  16766. PULONG MinorVersion OPTIONAL,
  16767. PULONG BuildNumber OPTIONAL,
  16768. PUNICODE_STRING CSDVersion OPTIONAL
  16769. );
  16770. NTKERNELAPI
  16771. BOOLEAN
  16772. PsIsSystemThread(
  16773. PETHREAD Thread
  16774. );
  16775. //
  16776. // Define I/O system data structure type codes. Each major data structure in
  16777. // the I/O system has a type code The type field in each structure is at the
  16778. // same offset. The following values can be used to determine which type of
  16779. // data structure a pointer refers to.
  16780. //
  16781. #define IO_TYPE_ADAPTER 0x00000001
  16782. #define IO_TYPE_CONTROLLER 0x00000002
  16783. #define IO_TYPE_DEVICE 0x00000003
  16784. #define IO_TYPE_DRIVER 0x00000004
  16785. #define IO_TYPE_FILE 0x00000005
  16786. #define IO_TYPE_IRP 0x00000006
  16787. #define IO_TYPE_MASTER_ADAPTER 0x00000007
  16788. #define IO_TYPE_OPEN_PACKET 0x00000008
  16789. #define IO_TYPE_TIMER 0x00000009
  16790. #define IO_TYPE_VPB 0x0000000a
  16791. #define IO_TYPE_ERROR_LOG 0x0000000b
  16792. #define IO_TYPE_ERROR_MESSAGE 0x0000000c
  16793. #define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
  16794. //
  16795. // Define the major function codes for IRPs.
  16796. //
  16797. #define IRP_MJ_CREATE 0x00
  16798. #define IRP_MJ_CREATE_NAMED_PIPE 0x01
  16799. #define IRP_MJ_CLOSE 0x02
  16800. #define IRP_MJ_READ 0x03
  16801. #define IRP_MJ_WRITE 0x04
  16802. #define IRP_MJ_QUERY_INFORMATION 0x05
  16803. #define IRP_MJ_SET_INFORMATION 0x06
  16804. #define IRP_MJ_QUERY_EA 0x07
  16805. #define IRP_MJ_SET_EA 0x08
  16806. #define IRP_MJ_FLUSH_BUFFERS 0x09
  16807. #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  16808. #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  16809. #define IRP_MJ_DIRECTORY_CONTROL 0x0c
  16810. #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  16811. #define IRP_MJ_DEVICE_CONTROL 0x0e
  16812. #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  16813. #define IRP_MJ_SHUTDOWN 0x10
  16814. #define IRP_MJ_LOCK_CONTROL 0x11
  16815. #define IRP_MJ_CLEANUP 0x12
  16816. #define IRP_MJ_CREATE_MAILSLOT 0x13
  16817. #define IRP_MJ_QUERY_SECURITY 0x14
  16818. #define IRP_MJ_SET_SECURITY 0x15
  16819. #define IRP_MJ_POWER 0x16
  16820. #define IRP_MJ_SYSTEM_CONTROL 0x17
  16821. #define IRP_MJ_DEVICE_CHANGE 0x18
  16822. #define IRP_MJ_QUERY_QUOTA 0x19
  16823. #define IRP_MJ_SET_QUOTA 0x1a
  16824. #define IRP_MJ_PNP 0x1b
  16825. #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
  16826. #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  16827. //
  16828. // Make the Scsi major code the same as internal device control.
  16829. //
  16830. #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
  16831. //
  16832. // Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
  16833. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  16834. // reserved to customers of Microsoft.
  16835. //
  16836. // end_wdm end_ntndis
  16837. //
  16838. // Directory control minor function codes
  16839. //
  16840. #define IRP_MN_QUERY_DIRECTORY 0x01
  16841. #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
  16842. //
  16843. // File system control minor function codes. Note that "user request" is
  16844. // assumed to be zero by both the I/O system and file systems. Do not change
  16845. // this value.
  16846. //
  16847. #define IRP_MN_USER_FS_REQUEST 0x00
  16848. #define IRP_MN_MOUNT_VOLUME 0x01
  16849. #define IRP_MN_VERIFY_VOLUME 0x02
  16850. #define IRP_MN_LOAD_FILE_SYSTEM 0x03
  16851. #define IRP_MN_TRACK_LINK 0x04 // To be obsoleted soon
  16852. #define IRP_MN_KERNEL_CALL 0x04
  16853. //
  16854. // Lock control minor function codes
  16855. //
  16856. #define IRP_MN_LOCK 0x01
  16857. #define IRP_MN_UNLOCK_SINGLE 0x02
  16858. #define IRP_MN_UNLOCK_ALL 0x03
  16859. #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
  16860. //
  16861. // Read and Write minor function codes for file systems supporting Lan Manager
  16862. // software. All of these subfunction codes are invalid if the file has been
  16863. // opened with FO_NO_INTERMEDIATE_BUFFERING. They are also invalid in combi-
  16864. // nation with synchronous calls (Irp Flag or file open option).
  16865. //
  16866. // Note that "normal" is assumed to be zero by both the I/O system and file
  16867. // systems. Do not change this value.
  16868. //
  16869. #define IRP_MN_NORMAL 0x00
  16870. #define IRP_MN_DPC 0x01
  16871. #define IRP_MN_MDL 0x02
  16872. #define IRP_MN_COMPLETE 0x04
  16873. #define IRP_MN_COMPRESSED 0x08
  16874. #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
  16875. #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
  16876. #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
  16877. // begin_wdm
  16878. //
  16879. // Device Control Request minor function codes for SCSI support. Note that
  16880. // user requests are assumed to be zero.
  16881. //
  16882. #define IRP_MN_SCSI_CLASS 0x01
  16883. //
  16884. // PNP minor function codes.
  16885. //
  16886. #define IRP_MN_START_DEVICE 0x00
  16887. #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
  16888. #define IRP_MN_REMOVE_DEVICE 0x02
  16889. #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  16890. #define IRP_MN_STOP_DEVICE 0x04
  16891. #define IRP_MN_QUERY_STOP_DEVICE 0x05
  16892. #define IRP_MN_CANCEL_STOP_DEVICE 0x06
  16893. #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  16894. #define IRP_MN_QUERY_INTERFACE 0x08
  16895. #define IRP_MN_QUERY_CAPABILITIES 0x09
  16896. #define IRP_MN_QUERY_RESOURCES 0x0A
  16897. #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  16898. #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
  16899. #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
  16900. #define IRP_MN_READ_CONFIG 0x0F
  16901. #define IRP_MN_WRITE_CONFIG 0x10
  16902. #define IRP_MN_EJECT 0x11
  16903. #define IRP_MN_SET_LOCK 0x12
  16904. #define IRP_MN_QUERY_ID 0x13
  16905. #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
  16906. #define IRP_MN_QUERY_BUS_INFORMATION 0x15
  16907. #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
  16908. #define IRP_MN_SURPRISE_REMOVAL 0x17
  16909. // end_wdm
  16910. #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
  16911. // begin_wdm
  16912. //
  16913. // POWER minor function codes
  16914. //
  16915. #define IRP_MN_WAIT_WAKE 0x00
  16916. #define IRP_MN_POWER_SEQUENCE 0x01
  16917. #define IRP_MN_SET_POWER 0x02
  16918. #define IRP_MN_QUERY_POWER 0x03
  16919. // begin_ntminiport
  16920. //
  16921. // WMI minor function codes under IRP_MJ_SYSTEM_CONTROL
  16922. //
  16923. #define IRP_MN_QUERY_ALL_DATA 0x00
  16924. #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
  16925. #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
  16926. #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
  16927. #define IRP_MN_ENABLE_EVENTS 0x04
  16928. #define IRP_MN_DISABLE_EVENTS 0x05
  16929. #define IRP_MN_ENABLE_COLLECTION 0x06
  16930. #define IRP_MN_DISABLE_COLLECTION 0x07
  16931. #define IRP_MN_REGINFO 0x08
  16932. #define IRP_MN_EXECUTE_METHOD 0x09
  16933. // Minor code 0x0a is reserved
  16934. #define IRP_MN_REGINFO_EX 0x0b
  16935. // end_ntminiport
  16936. //
  16937. // Define option flags for IoCreateFile. Note that these values must be
  16938. // exactly the same as the SL_... flags for a create function. Note also
  16939. // that there are flags that may be passed to IoCreateFile that are not
  16940. // placed in the stack location for the create IRP. These flags start in
  16941. // the next byte.
  16942. //
  16943. #define IO_FORCE_ACCESS_CHECK 0x0001
  16944. // end_ntddk end_wdm end_nthal end_ntosp
  16945. #define IO_OPEN_PAGING_FILE 0x0002
  16946. #define IO_OPEN_TARGET_DIRECTORY 0x0004
  16947. //
  16948. // Flags not passed to driver
  16949. //
  16950. // begin_ntddk begin_wdm begin_ntosp
  16951. #define IO_NO_PARAMETER_CHECKING 0x0100
  16952. //
  16953. // Define Information fields for whether or not a REPARSE or a REMOUNT has
  16954. // occurred in the file system.
  16955. //
  16956. #define IO_REPARSE 0x0
  16957. #define IO_REMOUNT 0x1
  16958. // end_ntddk end_wdm
  16959. #define IO_CHECK_CREATE_PARAMETERS 0x0200
  16960. #define IO_ATTACH_DEVICE 0x0400
  16961. // end_ntosp
  16962. // begin_ntifs begin_ntosp
  16963. //
  16964. // This flag is only meaning full to IoCreateFileSpecifyDeviceObjectHint.
  16965. // FileHandles created using IoCreateFileSpecifyDeviceObjectHint with this
  16966. // flag set will bypass ShareAccess checks on this file.
  16967. //
  16968. #define IO_IGNORE_SHARE_ACCESS_CHECK 0x0800 // Ignores share access checks on opens.
  16969. //
  16970. // Define the objects that can be created by IoCreateFile.
  16971. //
  16972. typedef enum _CREATE_FILE_TYPE {
  16973. CreateFileTypeNone,
  16974. CreateFileTypeNamedPipe,
  16975. CreateFileTypeMailslot
  16976. } CREATE_FILE_TYPE;
  16977. //
  16978. // Define the structures used by the I/O system
  16979. //
  16980. //
  16981. // Define empty typedefs for the _IRP, _DEVICE_OBJECT, and _DRIVER_OBJECT
  16982. // structures so they may be referenced by function types before they are
  16983. // actually defined.
  16984. //
  16985. struct _DEVICE_DESCRIPTION;
  16986. struct _DEVICE_OBJECT;
  16987. struct _DMA_ADAPTER;
  16988. struct _DRIVER_OBJECT;
  16989. struct _DRIVE_LAYOUT_INFORMATION;
  16990. struct _DISK_PARTITION;
  16991. struct _FILE_OBJECT;
  16992. struct _IRP;
  16993. struct _SCSI_REQUEST_BLOCK;
  16994. struct _SCATTER_GATHER_LIST;
  16995. //
  16996. // Define the I/O version of a DPC routine.
  16997. //
  16998. typedef
  16999. VOID
  17000. (*PIO_DPC_ROUTINE) (
  17001. IN PKDPC Dpc,
  17002. IN struct _DEVICE_OBJECT *DeviceObject,
  17003. IN struct _IRP *Irp,
  17004. IN PVOID Context
  17005. );
  17006. //
  17007. // Define driver timer routine type.
  17008. //
  17009. typedef
  17010. VOID
  17011. (*PIO_TIMER_ROUTINE) (
  17012. IN struct _DEVICE_OBJECT *DeviceObject,
  17013. IN PVOID Context
  17014. );
  17015. //
  17016. // Define driver initialization routine type.
  17017. //
  17018. typedef
  17019. NTSTATUS
  17020. (*PDRIVER_INITIALIZE) (
  17021. IN struct _DRIVER_OBJECT *DriverObject,
  17022. IN PUNICODE_STRING RegistryPath
  17023. );
  17024. // end_wdm
  17025. //
  17026. // Define driver reinitialization routine type.
  17027. //
  17028. typedef
  17029. VOID
  17030. (*PDRIVER_REINITIALIZE) (
  17031. IN struct _DRIVER_OBJECT *DriverObject,
  17032. IN PVOID Context,
  17033. IN ULONG Count
  17034. );
  17035. // begin_wdm begin_ntndis
  17036. //
  17037. // Define driver cancel routine type.
  17038. //
  17039. typedef
  17040. VOID
  17041. (*PDRIVER_CANCEL) (
  17042. IN struct _DEVICE_OBJECT *DeviceObject,
  17043. IN struct _IRP *Irp
  17044. );
  17045. //
  17046. // Define driver dispatch routine type.
  17047. //
  17048. typedef
  17049. NTSTATUS
  17050. (*PDRIVER_DISPATCH) (
  17051. IN struct _DEVICE_OBJECT *DeviceObject,
  17052. IN struct _IRP *Irp
  17053. );
  17054. //
  17055. // Define driver start I/O routine type.
  17056. //
  17057. typedef
  17058. VOID
  17059. (*PDRIVER_STARTIO) (
  17060. IN struct _DEVICE_OBJECT *DeviceObject,
  17061. IN struct _IRP *Irp
  17062. );
  17063. //
  17064. // Define driver unload routine type.
  17065. //
  17066. typedef
  17067. VOID
  17068. (*PDRIVER_UNLOAD) (
  17069. IN struct _DRIVER_OBJECT *DriverObject
  17070. );
  17071. //
  17072. // Define driver AddDevice routine type.
  17073. //
  17074. typedef
  17075. NTSTATUS
  17076. (*PDRIVER_ADD_DEVICE) (
  17077. IN struct _DRIVER_OBJECT *DriverObject,
  17078. IN struct _DEVICE_OBJECT *PhysicalDeviceObject
  17079. );
  17080. // end_ntddk end_wdm end_nthal end_ntndis end_ntosp
  17081. //
  17082. // Define driver FS notification change routine type.
  17083. //
  17084. typedef
  17085. VOID
  17086. (*PDRIVER_FS_NOTIFICATION) (
  17087. IN struct _DEVICE_OBJECT *DeviceObject,
  17088. IN BOOLEAN FsActive
  17089. );
  17090. // begin_ntddk begin_wdm begin_ntosp
  17091. //
  17092. // Define fast I/O procedure prototypes.
  17093. //
  17094. // Fast I/O read and write procedures.
  17095. //
  17096. typedef
  17097. BOOLEAN
  17098. (*PFAST_IO_CHECK_IF_POSSIBLE) (
  17099. IN struct _FILE_OBJECT *FileObject,
  17100. IN PLARGE_INTEGER FileOffset,
  17101. IN ULONG Length,
  17102. IN BOOLEAN Wait,
  17103. IN ULONG LockKey,
  17104. IN BOOLEAN CheckForReadOperation,
  17105. OUT PIO_STATUS_BLOCK IoStatus,
  17106. IN struct _DEVICE_OBJECT *DeviceObject
  17107. );
  17108. typedef
  17109. BOOLEAN
  17110. (*PFAST_IO_READ) (
  17111. IN struct _FILE_OBJECT *FileObject,
  17112. IN PLARGE_INTEGER FileOffset,
  17113. IN ULONG Length,
  17114. IN BOOLEAN Wait,
  17115. IN ULONG LockKey,
  17116. OUT PVOID Buffer,
  17117. OUT PIO_STATUS_BLOCK IoStatus,
  17118. IN struct _DEVICE_OBJECT *DeviceObject
  17119. );
  17120. typedef
  17121. BOOLEAN
  17122. (*PFAST_IO_WRITE) (
  17123. IN struct _FILE_OBJECT *FileObject,
  17124. IN PLARGE_INTEGER FileOffset,
  17125. IN ULONG Length,
  17126. IN BOOLEAN Wait,
  17127. IN ULONG LockKey,
  17128. IN PVOID Buffer,
  17129. OUT PIO_STATUS_BLOCK IoStatus,
  17130. IN struct _DEVICE_OBJECT *DeviceObject
  17131. );
  17132. //
  17133. // Fast I/O query basic and standard information procedures.
  17134. //
  17135. typedef
  17136. BOOLEAN
  17137. (*PFAST_IO_QUERY_BASIC_INFO) (
  17138. IN struct _FILE_OBJECT *FileObject,
  17139. IN BOOLEAN Wait,
  17140. OUT PFILE_BASIC_INFORMATION Buffer,
  17141. OUT PIO_STATUS_BLOCK IoStatus,
  17142. IN struct _DEVICE_OBJECT *DeviceObject
  17143. );
  17144. typedef
  17145. BOOLEAN
  17146. (*PFAST_IO_QUERY_STANDARD_INFO) (
  17147. IN struct _FILE_OBJECT *FileObject,
  17148. IN BOOLEAN Wait,
  17149. OUT PFILE_STANDARD_INFORMATION Buffer,
  17150. OUT PIO_STATUS_BLOCK IoStatus,
  17151. IN struct _DEVICE_OBJECT *DeviceObject
  17152. );
  17153. //
  17154. // Fast I/O lock and unlock procedures.
  17155. //
  17156. typedef
  17157. BOOLEAN
  17158. (*PFAST_IO_LOCK) (
  17159. IN struct _FILE_OBJECT *FileObject,
  17160. IN PLARGE_INTEGER FileOffset,
  17161. IN PLARGE_INTEGER Length,
  17162. PEPROCESS ProcessId,
  17163. ULONG Key,
  17164. BOOLEAN FailImmediately,
  17165. BOOLEAN ExclusiveLock,
  17166. OUT PIO_STATUS_BLOCK IoStatus,
  17167. IN struct _DEVICE_OBJECT *DeviceObject
  17168. );
  17169. typedef
  17170. BOOLEAN
  17171. (*PFAST_IO_UNLOCK_SINGLE) (
  17172. IN struct _FILE_OBJECT *FileObject,
  17173. IN PLARGE_INTEGER FileOffset,
  17174. IN PLARGE_INTEGER Length,
  17175. PEPROCESS ProcessId,
  17176. ULONG Key,
  17177. OUT PIO_STATUS_BLOCK IoStatus,
  17178. IN struct _DEVICE_OBJECT *DeviceObject
  17179. );
  17180. typedef
  17181. BOOLEAN
  17182. (*PFAST_IO_UNLOCK_ALL) (
  17183. IN struct _FILE_OBJECT *FileObject,
  17184. PEPROCESS ProcessId,
  17185. OUT PIO_STATUS_BLOCK IoStatus,
  17186. IN struct _DEVICE_OBJECT *DeviceObject
  17187. );
  17188. typedef
  17189. BOOLEAN
  17190. (*PFAST_IO_UNLOCK_ALL_BY_KEY) (
  17191. IN struct _FILE_OBJECT *FileObject,
  17192. PVOID ProcessId,
  17193. ULONG Key,
  17194. OUT PIO_STATUS_BLOCK IoStatus,
  17195. IN struct _DEVICE_OBJECT *DeviceObject
  17196. );
  17197. //
  17198. // Fast I/O device control procedure.
  17199. //
  17200. typedef
  17201. BOOLEAN
  17202. (*PFAST_IO_DEVICE_CONTROL) (
  17203. IN struct _FILE_OBJECT *FileObject,
  17204. IN BOOLEAN Wait,
  17205. IN PVOID InputBuffer OPTIONAL,
  17206. IN ULONG InputBufferLength,
  17207. OUT PVOID OutputBuffer OPTIONAL,
  17208. IN ULONG OutputBufferLength,
  17209. IN ULONG IoControlCode,
  17210. OUT PIO_STATUS_BLOCK IoStatus,
  17211. IN struct _DEVICE_OBJECT *DeviceObject
  17212. );
  17213. //
  17214. // Define callbacks for NtCreateSection to synchronize correctly with
  17215. // the file system. It pre-acquires the resources that will be needed
  17216. // when calling to query and set file/allocation size in the file system.
  17217. //
  17218. typedef
  17219. VOID
  17220. (*PFAST_IO_ACQUIRE_FILE) (
  17221. IN struct _FILE_OBJECT *FileObject
  17222. );
  17223. typedef
  17224. VOID
  17225. (*PFAST_IO_RELEASE_FILE) (
  17226. IN struct _FILE_OBJECT *FileObject
  17227. );
  17228. //
  17229. // Define callback for drivers that have device objects attached to lower-
  17230. // level drivers' device objects. This callback is made when the lower-level
  17231. // driver is deleting its device object.
  17232. //
  17233. typedef
  17234. VOID
  17235. (*PFAST_IO_DETACH_DEVICE) (
  17236. IN struct _DEVICE_OBJECT *SourceDevice,
  17237. IN struct _DEVICE_OBJECT *TargetDevice
  17238. );
  17239. //
  17240. // This structure is used by the server to quickly get the information needed
  17241. // to service a server open call. It is takes what would be two fast io calls
  17242. // one for basic information and the other for standard information and makes
  17243. // it into one call.
  17244. //
  17245. typedef
  17246. BOOLEAN
  17247. (*PFAST_IO_QUERY_NETWORK_OPEN_INFO) (
  17248. IN struct _FILE_OBJECT *FileObject,
  17249. IN BOOLEAN Wait,
  17250. OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
  17251. OUT struct _IO_STATUS_BLOCK *IoStatus,
  17252. IN struct _DEVICE_OBJECT *DeviceObject
  17253. );
  17254. //
  17255. // Define Mdl-based routines for the server to call
  17256. //
  17257. typedef
  17258. BOOLEAN
  17259. (*PFAST_IO_MDL_READ) (
  17260. IN struct _FILE_OBJECT *FileObject,
  17261. IN PLARGE_INTEGER FileOffset,
  17262. IN ULONG Length,
  17263. IN ULONG LockKey,
  17264. OUT PMDL *MdlChain,
  17265. OUT PIO_STATUS_BLOCK IoStatus,
  17266. IN struct _DEVICE_OBJECT *DeviceObject
  17267. );
  17268. typedef
  17269. BOOLEAN
  17270. (*PFAST_IO_MDL_READ_COMPLETE) (
  17271. IN struct _FILE_OBJECT *FileObject,
  17272. IN PMDL MdlChain,
  17273. IN struct _DEVICE_OBJECT *DeviceObject
  17274. );
  17275. typedef
  17276. BOOLEAN
  17277. (*PFAST_IO_PREPARE_MDL_WRITE) (
  17278. IN struct _FILE_OBJECT *FileObject,
  17279. IN PLARGE_INTEGER FileOffset,
  17280. IN ULONG Length,
  17281. IN ULONG LockKey,
  17282. OUT PMDL *MdlChain,
  17283. OUT PIO_STATUS_BLOCK IoStatus,
  17284. IN struct _DEVICE_OBJECT *DeviceObject
  17285. );
  17286. typedef
  17287. BOOLEAN
  17288. (*PFAST_IO_MDL_WRITE_COMPLETE) (
  17289. IN struct _FILE_OBJECT *FileObject,
  17290. IN PLARGE_INTEGER FileOffset,
  17291. IN PMDL MdlChain,
  17292. IN struct _DEVICE_OBJECT *DeviceObject
  17293. );
  17294. //
  17295. // If this routine is present, it will be called by FsRtl
  17296. // to acquire the file for the mapped page writer.
  17297. //
  17298. typedef
  17299. NTSTATUS
  17300. (*PFAST_IO_ACQUIRE_FOR_MOD_WRITE) (
  17301. IN struct _FILE_OBJECT *FileObject,
  17302. IN PLARGE_INTEGER EndingOffset,
  17303. OUT struct _ERESOURCE **ResourceToRelease,
  17304. IN struct _DEVICE_OBJECT *DeviceObject
  17305. );
  17306. typedef
  17307. NTSTATUS
  17308. (*PFAST_IO_RELEASE_FOR_MOD_WRITE) (
  17309. IN struct _FILE_OBJECT *FileObject,
  17310. IN struct _ERESOURCE *ResourceToRelease,
  17311. IN struct _DEVICE_OBJECT *DeviceObject
  17312. );
  17313. //
  17314. // If this routine is present, it will be called by FsRtl
  17315. // to acquire the file for the mapped page writer.
  17316. //
  17317. typedef
  17318. NTSTATUS
  17319. (*PFAST_IO_ACQUIRE_FOR_CCFLUSH) (
  17320. IN struct _FILE_OBJECT *FileObject,
  17321. IN struct _DEVICE_OBJECT *DeviceObject
  17322. );
  17323. typedef
  17324. NTSTATUS
  17325. (*PFAST_IO_RELEASE_FOR_CCFLUSH) (
  17326. IN struct _FILE_OBJECT *FileObject,
  17327. IN struct _DEVICE_OBJECT *DeviceObject
  17328. );
  17329. typedef
  17330. BOOLEAN
  17331. (*PFAST_IO_READ_COMPRESSED) (
  17332. IN struct _FILE_OBJECT *FileObject,
  17333. IN PLARGE_INTEGER FileOffset,
  17334. IN ULONG Length,
  17335. IN ULONG LockKey,
  17336. OUT PVOID Buffer,
  17337. OUT PMDL *MdlChain,
  17338. OUT PIO_STATUS_BLOCK IoStatus,
  17339. OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  17340. IN ULONG CompressedDataInfoLength,
  17341. IN struct _DEVICE_OBJECT *DeviceObject
  17342. );
  17343. typedef
  17344. BOOLEAN
  17345. (*PFAST_IO_WRITE_COMPRESSED) (
  17346. IN struct _FILE_OBJECT *FileObject,
  17347. IN PLARGE_INTEGER FileOffset,
  17348. IN ULONG Length,
  17349. IN ULONG LockKey,
  17350. IN PVOID Buffer,
  17351. OUT PMDL *MdlChain,
  17352. OUT PIO_STATUS_BLOCK IoStatus,
  17353. IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  17354. IN ULONG CompressedDataInfoLength,
  17355. IN struct _DEVICE_OBJECT *DeviceObject
  17356. );
  17357. typedef
  17358. BOOLEAN
  17359. (*PFAST_IO_MDL_READ_COMPLETE_COMPRESSED) (
  17360. IN struct _FILE_OBJECT *FileObject,
  17361. IN PMDL MdlChain,
  17362. IN struct _DEVICE_OBJECT *DeviceObject
  17363. );
  17364. typedef
  17365. BOOLEAN
  17366. (*PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED) (
  17367. IN struct _FILE_OBJECT *FileObject,
  17368. IN PLARGE_INTEGER FileOffset,
  17369. IN PMDL MdlChain,
  17370. IN struct _DEVICE_OBJECT *DeviceObject
  17371. );
  17372. typedef
  17373. BOOLEAN
  17374. (*PFAST_IO_QUERY_OPEN) (
  17375. IN struct _IRP *Irp,
  17376. OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
  17377. IN struct _DEVICE_OBJECT *DeviceObject
  17378. );
  17379. //
  17380. // Define the structure to describe the Fast I/O dispatch routines. Any
  17381. // additions made to this structure MUST be added monotonically to the end
  17382. // of the structure, and fields CANNOT be removed from the middle.
  17383. //
  17384. typedef struct _FAST_IO_DISPATCH {
  17385. ULONG SizeOfFastIoDispatch;
  17386. PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
  17387. PFAST_IO_READ FastIoRead;
  17388. PFAST_IO_WRITE FastIoWrite;
  17389. PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
  17390. PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
  17391. PFAST_IO_LOCK FastIoLock;
  17392. PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
  17393. PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
  17394. PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
  17395. PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
  17396. PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
  17397. PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
  17398. PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
  17399. PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
  17400. PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
  17401. PFAST_IO_MDL_READ MdlRead;
  17402. PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
  17403. PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
  17404. PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
  17405. PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
  17406. PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
  17407. PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
  17408. PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
  17409. PFAST_IO_QUERY_OPEN FastIoQueryOpen;
  17410. PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
  17411. PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
  17412. PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
  17413. } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
  17414. // end_ntddk end_wdm end_ntosp
  17415. //
  17416. // Valid values for FS_FILTER_PARAMETERS.AcquireForSectionSynchronization.SyncType
  17417. //
  17418. typedef enum _FS_FILTER_SECTION_SYNC_TYPE {
  17419. SyncTypeOther = 0,
  17420. SyncTypeCreateSection
  17421. } FS_FILTER_SECTION_SYNC_TYPE, *PFS_FILTER_SECTION_SYNC_TYPE;
  17422. //
  17423. // Parameters union for the operations that
  17424. // are exposed to the filters through the
  17425. // FsFilterCallbacks registration mechanism.
  17426. //
  17427. typedef union _FS_FILTER_PARAMETERS {
  17428. //
  17429. // AcquireForModifiedPageWriter
  17430. //
  17431. struct {
  17432. PLARGE_INTEGER EndingOffset;
  17433. } AcquireForModifiedPageWriter;
  17434. //
  17435. // ReleaseForModifiedPageWriter
  17436. //
  17437. struct {
  17438. PERESOURCE ResourceToRelease;
  17439. } ReleaseForModifiedPageWriter;
  17440. //
  17441. // AcquireForSectionSynchronization
  17442. //
  17443. struct {
  17444. FS_FILTER_SECTION_SYNC_TYPE SyncType;
  17445. ULONG PageProtection;
  17446. } AcquireForSectionSynchronization;
  17447. //
  17448. // Other
  17449. //
  17450. struct {
  17451. PVOID Argument1;
  17452. PVOID Argument2;
  17453. PVOID Argument3;
  17454. PVOID Argument4;
  17455. PVOID Argument5;
  17456. } Others;
  17457. } FS_FILTER_PARAMETERS, *PFS_FILTER_PARAMETERS;
  17458. //
  17459. // These are the valid values for the Operation field
  17460. // of the FS_FILTER_CALLBACK_DATA structure.
  17461. //
  17462. #define FS_FILTER_ACQUIRE_FOR_SECTION_SYNCHRONIZATION (UCHAR)-1
  17463. #define FS_FILTER_RELEASE_FOR_SECTION_SYNCHRONIZATION (UCHAR)-2
  17464. #define FS_FILTER_ACQUIRE_FOR_MOD_WRITE (UCHAR)-3
  17465. #define FS_FILTER_RELEASE_FOR_MOD_WRITE (UCHAR)-4
  17466. #define FS_FILTER_ACQUIRE_FOR_CC_FLUSH (UCHAR)-5
  17467. #define FS_FILTER_RELEASE_FOR_CC_FLUSH (UCHAR)-6
  17468. typedef struct _FS_FILTER_CALLBACK_DATA {
  17469. ULONG SizeOfFsFilterCallbackData;
  17470. UCHAR Operation;
  17471. UCHAR Reserved;
  17472. struct _DEVICE_OBJECT *DeviceObject;
  17473. struct _FILE_OBJECT *FileObject;
  17474. FS_FILTER_PARAMETERS Parameters;
  17475. } FS_FILTER_CALLBACK_DATA, *PFS_FILTER_CALLBACK_DATA;
  17476. //
  17477. // Prototype for the callbacks received before an operation
  17478. // is passed to the base file system.
  17479. //
  17480. // A filter can fail this operation, but consistant failure
  17481. // will halt system progress.
  17482. //
  17483. typedef
  17484. NTSTATUS
  17485. (*PFS_FILTER_CALLBACK) (
  17486. IN PFS_FILTER_CALLBACK_DATA Data,
  17487. OUT PVOID *CompletionContext
  17488. );
  17489. //
  17490. // Prototype for the completion callback received after an
  17491. // operation is completed.
  17492. //
  17493. typedef
  17494. VOID
  17495. (*PFS_FILTER_COMPLETION_CALLBACK) (
  17496. IN PFS_FILTER_CALLBACK_DATA Data,
  17497. IN NTSTATUS OperationStatus,
  17498. IN PVOID CompletionContext
  17499. );
  17500. //
  17501. // This is the structure that the file system filter fills in to
  17502. // receive notifications for these locking operations.
  17503. //
  17504. // A filter should set the field to NULL for any notification callback
  17505. // it doesn't wish to receive.
  17506. //
  17507. typedef struct _FS_FILTER_CALLBACKS {
  17508. ULONG SizeOfFsFilterCallbacks;
  17509. ULONG Reserved; // For alignment
  17510. PFS_FILTER_CALLBACK PreAcquireForSectionSynchronization;
  17511. PFS_FILTER_COMPLETION_CALLBACK PostAcquireForSectionSynchronization;
  17512. PFS_FILTER_CALLBACK PreReleaseForSectionSynchronization;
  17513. PFS_FILTER_COMPLETION_CALLBACK PostReleaseForSectionSynchronization;
  17514. PFS_FILTER_CALLBACK PreAcquireForCcFlush;
  17515. PFS_FILTER_COMPLETION_CALLBACK PostAcquireForCcFlush;
  17516. PFS_FILTER_CALLBACK PreReleaseForCcFlush;
  17517. PFS_FILTER_COMPLETION_CALLBACK PostReleaseForCcFlush;
  17518. PFS_FILTER_CALLBACK PreAcquireForModifiedPageWriter;
  17519. PFS_FILTER_COMPLETION_CALLBACK PostAcquireForModifiedPageWriter;
  17520. PFS_FILTER_CALLBACK PreReleaseForModifiedPageWriter;
  17521. PFS_FILTER_COMPLETION_CALLBACK PostReleaseForModifiedPageWriter;
  17522. } FS_FILTER_CALLBACKS, *PFS_FILTER_CALLBACKS;
  17523. NTKERNELAPI
  17524. NTSTATUS
  17525. FsRtlRegisterFileSystemFilterCallbacks (
  17526. IN struct _DRIVER_OBJECT *FilterDriverObject,
  17527. IN PFS_FILTER_CALLBACKS Callbacks
  17528. );
  17529. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  17530. //
  17531. // Define the actions that a driver execution routine may request of the
  17532. // adapter/controller allocation routines upon return.
  17533. //
  17534. typedef enum _IO_ALLOCATION_ACTION {
  17535. KeepObject = 1,
  17536. DeallocateObject,
  17537. DeallocateObjectKeepRegisters
  17538. } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
  17539. //
  17540. // Define device driver adapter/controller execution routine.
  17541. //
  17542. typedef
  17543. IO_ALLOCATION_ACTION
  17544. (*PDRIVER_CONTROL) (
  17545. IN struct _DEVICE_OBJECT *DeviceObject,
  17546. IN struct _IRP *Irp,
  17547. IN PVOID MapRegisterBase,
  17548. IN PVOID Context
  17549. );
  17550. //
  17551. // Define the I/O system's security context type for use by file system's
  17552. // when checking access to volumes, files, and directories.
  17553. //
  17554. typedef struct _IO_SECURITY_CONTEXT {
  17555. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  17556. PACCESS_STATE AccessState;
  17557. ACCESS_MASK DesiredAccess;
  17558. ULONG FullCreateOptions;
  17559. } IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
  17560. //
  17561. // Define Volume Parameter Block (VPB) flags.
  17562. //
  17563. #define VPB_MOUNTED 0x00000001
  17564. #define VPB_LOCKED 0x00000002
  17565. #define VPB_PERSISTENT 0x00000004
  17566. #define VPB_REMOVE_PENDING 0x00000008
  17567. #define VPB_RAW_MOUNT 0x00000010
  17568. //
  17569. // Volume Parameter Block (VPB)
  17570. //
  17571. #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR)) // 32 characters
  17572. typedef struct _VPB {
  17573. CSHORT Type;
  17574. CSHORT Size;
  17575. USHORT Flags;
  17576. USHORT VolumeLabelLength; // in bytes
  17577. struct _DEVICE_OBJECT *DeviceObject;
  17578. struct _DEVICE_OBJECT *RealDevice;
  17579. ULONG SerialNumber;
  17580. ULONG ReferenceCount;
  17581. WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
  17582. } VPB, *PVPB;
  17583. #if defined(_WIN64)
  17584. //
  17585. // Use __inline DMA macros (hal.h)
  17586. //
  17587. #ifndef USE_DMA_MACROS
  17588. #define USE_DMA_MACROS
  17589. #endif
  17590. //
  17591. // Only PnP drivers!
  17592. //
  17593. #ifndef NO_LEGACY_DRIVERS
  17594. #define NO_LEGACY_DRIVERS
  17595. #endif
  17596. #endif // _WIN64
  17597. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_) || defined(_NTOSP_))
  17598. // begin_wdm
  17599. //
  17600. // Define object type specific fields of various objects used by the I/O system
  17601. //
  17602. typedef struct _DMA_ADAPTER *PADAPTER_OBJECT;
  17603. // end_wdm
  17604. #else
  17605. //
  17606. // Define object type specific fields of various objects used by the I/O system
  17607. //
  17608. typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT; // ntndis
  17609. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_ || _NTOSP_)
  17610. // begin_wdm
  17611. //
  17612. // Define Wait Context Block (WCB)
  17613. //
  17614. typedef struct _WAIT_CONTEXT_BLOCK {
  17615. KDEVICE_QUEUE_ENTRY WaitQueueEntry;
  17616. PDRIVER_CONTROL DeviceRoutine;
  17617. PVOID DeviceContext;
  17618. ULONG NumberOfMapRegisters;
  17619. PVOID DeviceObject;
  17620. PVOID CurrentIrp;
  17621. PKDPC BufferChainingDpc;
  17622. } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
  17623. // end_wdm
  17624. typedef struct _CONTROLLER_OBJECT {
  17625. CSHORT Type;
  17626. CSHORT Size;
  17627. PVOID ControllerExtension;
  17628. KDEVICE_QUEUE DeviceWaitQueue;
  17629. ULONG Spare1;
  17630. LARGE_INTEGER Spare2;
  17631. } CONTROLLER_OBJECT, *PCONTROLLER_OBJECT;
  17632. // begin_wdm
  17633. //
  17634. // Define Device Object (DO) flags
  17635. //
  17636. #define DO_VERIFY_VOLUME 0x00000002
  17637. #define DO_BUFFERED_IO 0x00000004
  17638. #define DO_EXCLUSIVE 0x00000008
  17639. #define DO_DIRECT_IO 0x00000010
  17640. #define DO_MAP_IO_BUFFER 0x00000020
  17641. #define DO_DEVICE_HAS_NAME 0x00000040
  17642. #define DO_DEVICE_INITIALIZING 0x00000080
  17643. #define DO_SYSTEM_BOOT_PARTITION 0x00000100
  17644. #define DO_LONG_TERM_REQUESTS 0x00000200
  17645. #define DO_NEVER_LAST_DEVICE 0x00000400
  17646. #define DO_SHUTDOWN_REGISTERED 0x00000800
  17647. #define DO_BUS_ENUMERATED_DEVICE 0x00001000
  17648. #define DO_POWER_PAGABLE 0x00002000
  17649. #define DO_POWER_INRUSH 0x00004000
  17650. #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000
  17651. //
  17652. // Device Object structure definition
  17653. //
  17654. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {
  17655. CSHORT Type;
  17656. USHORT Size;
  17657. LONG ReferenceCount;
  17658. struct _DRIVER_OBJECT *DriverObject;
  17659. struct _DEVICE_OBJECT *NextDevice;
  17660. struct _DEVICE_OBJECT *AttachedDevice;
  17661. struct _IRP *CurrentIrp;
  17662. PIO_TIMER Timer;
  17663. ULONG Flags; // See above: DO_...
  17664. ULONG Characteristics; // See ntioapi: FILE_...
  17665. PVPB Vpb;
  17666. PVOID DeviceExtension;
  17667. DEVICE_TYPE DeviceType;
  17668. CCHAR StackSize;
  17669. union {
  17670. LIST_ENTRY ListEntry;
  17671. WAIT_CONTEXT_BLOCK Wcb;
  17672. } Queue;
  17673. ULONG AlignmentRequirement;
  17674. KDEVICE_QUEUE DeviceQueue;
  17675. KDPC Dpc;
  17676. //
  17677. // The following field is for exclusive use by the filesystem to keep
  17678. // track of the number of Fsp threads currently using the device
  17679. //
  17680. ULONG ActiveThreadCount;
  17681. PSECURITY_DESCRIPTOR SecurityDescriptor;
  17682. KEVENT DeviceLock;
  17683. USHORT SectorSize;
  17684. USHORT Spare1;
  17685. struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
  17686. PVOID Reserved;
  17687. } DEVICE_OBJECT;
  17688. typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT; // ntndis
  17689. struct _DEVICE_OBJECT_POWER_EXTENSION;
  17690. typedef struct _DEVOBJ_EXTENSION {
  17691. CSHORT Type;
  17692. USHORT Size;
  17693. //
  17694. // Public part of the DeviceObjectExtension structure
  17695. //
  17696. PDEVICE_OBJECT DeviceObject; // owning device object
  17697. } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
  17698. //
  17699. // Define Driver Object (DRVO) flags
  17700. //
  17701. #define DRVO_UNLOAD_INVOKED 0x00000001
  17702. #define DRVO_LEGACY_DRIVER 0x00000002
  17703. #define DRVO_BUILTIN_DRIVER 0x00000004 // Driver objects for Hal, PnP Mgr
  17704. // end_wdm
  17705. #define DRVO_REINIT_REGISTERED 0x00000008
  17706. #define DRVO_INITIALIZED 0x00000010
  17707. #define DRVO_BOOTREINIT_REGISTERED 0x00000020
  17708. #define DRVO_LEGACY_RESOURCES 0x00000040
  17709. // begin_wdm
  17710. typedef struct _DRIVER_EXTENSION {
  17711. //
  17712. // Back pointer to Driver Object
  17713. //
  17714. struct _DRIVER_OBJECT *DriverObject;
  17715. //
  17716. // The AddDevice entry point is called by the Plug & Play manager
  17717. // to inform the driver when a new device instance arrives that this
  17718. // driver must control.
  17719. //
  17720. PDRIVER_ADD_DEVICE AddDevice;
  17721. //
  17722. // The count field is used to count the number of times the driver has
  17723. // had its registered reinitialization routine invoked.
  17724. //
  17725. ULONG Count;
  17726. //
  17727. // The service name field is used by the pnp manager to determine
  17728. // where the driver related info is stored in the registry.
  17729. //
  17730. UNICODE_STRING ServiceKeyName;
  17731. //
  17732. // Note: any new shared fields get added here.
  17733. //
  17734. } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
  17735. typedef struct _DRIVER_OBJECT {
  17736. CSHORT Type;
  17737. CSHORT Size;
  17738. //
  17739. // The following links all of the devices created by a single driver
  17740. // together on a list, and the Flags word provides an extensible flag
  17741. // location for driver objects.
  17742. //
  17743. PDEVICE_OBJECT DeviceObject;
  17744. ULONG Flags;
  17745. //
  17746. // The following section describes where the driver is loaded. The count
  17747. // field is used to count the number of times the driver has had its
  17748. // registered reinitialization routine invoked.
  17749. //
  17750. PVOID DriverStart;
  17751. ULONG DriverSize;
  17752. PVOID DriverSection;
  17753. PDRIVER_EXTENSION DriverExtension;
  17754. //
  17755. // The driver name field is used by the error log thread
  17756. // determine the name of the driver that an I/O request is/was bound.
  17757. //
  17758. UNICODE_STRING DriverName;
  17759. //
  17760. // The following section is for registry support. Thise is a pointer
  17761. // to the path to the hardware information in the registry
  17762. //
  17763. PUNICODE_STRING HardwareDatabase;
  17764. //
  17765. // The following section contains the optional pointer to an array of
  17766. // alternate entry points to a driver for "fast I/O" support. Fast I/O
  17767. // is performed by invoking the driver routine directly with separate
  17768. // parameters, rather than using the standard IRP call mechanism. Note
  17769. // that these functions may only be used for synchronous I/O, and when
  17770. // the file is cached.
  17771. //
  17772. PFAST_IO_DISPATCH FastIoDispatch;
  17773. //
  17774. // The following section describes the entry points to this particular
  17775. // driver. Note that the major function dispatch table must be the last
  17776. // field in the object so that it remains extensible.
  17777. //
  17778. PDRIVER_INITIALIZE DriverInit;
  17779. PDRIVER_STARTIO DriverStartIo;
  17780. PDRIVER_UNLOAD DriverUnload;
  17781. PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
  17782. } DRIVER_OBJECT;
  17783. typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT; // ntndis
  17784. //
  17785. // The following structure is pointed to by the SectionObject pointer field
  17786. // of a file object, and is allocated by the various NT file systems.
  17787. //
  17788. typedef struct _SECTION_OBJECT_POINTERS {
  17789. PVOID DataSectionObject;
  17790. PVOID SharedCacheMap;
  17791. PVOID ImageSectionObject;
  17792. } SECTION_OBJECT_POINTERS;
  17793. typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
  17794. //
  17795. // Define the format of a completion message.
  17796. //
  17797. typedef struct _IO_COMPLETION_CONTEXT {
  17798. PVOID Port;
  17799. PVOID Key;
  17800. } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
  17801. //
  17802. // Define File Object (FO) flags
  17803. //
  17804. #define FO_FILE_OPEN 0x00000001
  17805. #define FO_SYNCHRONOUS_IO 0x00000002
  17806. #define FO_ALERTABLE_IO 0x00000004
  17807. #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
  17808. #define FO_WRITE_THROUGH 0x00000010
  17809. #define FO_SEQUENTIAL_ONLY 0x00000020
  17810. #define FO_CACHE_SUPPORTED 0x00000040
  17811. #define FO_NAMED_PIPE 0x00000080
  17812. #define FO_STREAM_FILE 0x00000100
  17813. #define FO_MAILSLOT 0x00000200
  17814. #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
  17815. #define FO_DIRECT_DEVICE_OPEN 0x00000800
  17816. #define FO_FILE_MODIFIED 0x00001000
  17817. #define FO_FILE_SIZE_CHANGED 0x00002000
  17818. #define FO_CLEANUP_COMPLETE 0x00004000
  17819. #define FO_TEMPORARY_FILE 0x00008000
  17820. #define FO_DELETE_ON_CLOSE 0x00010000
  17821. #define FO_OPENED_CASE_SENSITIVE 0x00020000
  17822. #define FO_HANDLE_CREATED 0x00040000
  17823. #define FO_FILE_FAST_IO_READ 0x00080000
  17824. #define FO_RANDOM_ACCESS 0x00100000
  17825. #define FO_FILE_OPEN_CANCELLED 0x00200000
  17826. #define FO_VOLUME_OPEN 0x00400000
  17827. #define FO_FILE_OBJECT_HAS_EXTENSION 0x00800000
  17828. #define FO_REMOTE_ORIGIN 0x01000000
  17829. typedef struct _FILE_OBJECT {
  17830. CSHORT Type;
  17831. CSHORT Size;
  17832. PDEVICE_OBJECT DeviceObject;
  17833. PVPB Vpb;
  17834. PVOID FsContext;
  17835. PVOID FsContext2;
  17836. PSECTION_OBJECT_POINTERS SectionObjectPointer;
  17837. PVOID PrivateCacheMap;
  17838. NTSTATUS FinalStatus;
  17839. struct _FILE_OBJECT *RelatedFileObject;
  17840. BOOLEAN LockOperation;
  17841. BOOLEAN DeletePending;
  17842. BOOLEAN ReadAccess;
  17843. BOOLEAN WriteAccess;
  17844. BOOLEAN DeleteAccess;
  17845. BOOLEAN SharedRead;
  17846. BOOLEAN SharedWrite;
  17847. BOOLEAN SharedDelete;
  17848. ULONG Flags;
  17849. UNICODE_STRING FileName;
  17850. LARGE_INTEGER CurrentByteOffset;
  17851. ULONG Waiters;
  17852. ULONG Busy;
  17853. PVOID LastLock;
  17854. KEVENT Lock;
  17855. KEVENT Event;
  17856. PIO_COMPLETION_CONTEXT CompletionContext;
  17857. } FILE_OBJECT;
  17858. typedef struct _FILE_OBJECT *PFILE_OBJECT; // ntndis
  17859. //
  17860. // Define I/O Request Packet (IRP) flags
  17861. //
  17862. #define IRP_NOCACHE 0x00000001
  17863. #define IRP_PAGING_IO 0x00000002
  17864. #define IRP_MOUNT_COMPLETION 0x00000002
  17865. #define IRP_SYNCHRONOUS_API 0x00000004
  17866. #define IRP_ASSOCIATED_IRP 0x00000008
  17867. #define IRP_BUFFERED_IO 0x00000010
  17868. #define IRP_DEALLOCATE_BUFFER 0x00000020
  17869. #define IRP_INPUT_OPERATION 0x00000040
  17870. #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
  17871. #define IRP_CREATE_OPERATION 0x00000080
  17872. #define IRP_READ_OPERATION 0x00000100
  17873. #define IRP_WRITE_OPERATION 0x00000200
  17874. #define IRP_CLOSE_OPERATION 0x00000400
  17875. // end_wdm
  17876. #define IRP_DEFER_IO_COMPLETION 0x00000800
  17877. #define IRP_OB_QUERY_NAME 0x00001000
  17878. #define IRP_HOLD_DEVICE_QUEUE 0x00002000
  17879. #define IRP_RETRY_IO_COMPLETION 0x00004000
  17880. #define IRP_CLASS_CACHE_OPERATION 0x00008000
  17881. #define IRP_SET_USER_EVENT IRP_CLOSE_OPERATION
  17882. // begin_wdm
  17883. //
  17884. // Define I/O request packet (IRP) alternate flags for allocation control.
  17885. //
  17886. #define IRP_QUOTA_CHARGED 0x01
  17887. #define IRP_ALLOCATED_MUST_SUCCEED 0x02
  17888. #define IRP_ALLOCATED_FIXED_SIZE 0x04
  17889. #define IRP_LOOKASIDE_ALLOCATION 0x08
  17890. //
  17891. // I/O Request Packet (IRP) definition
  17892. //
  17893. typedef struct _IRP {
  17894. CSHORT Type;
  17895. USHORT Size;
  17896. //
  17897. // Define the common fields used to control the IRP.
  17898. //
  17899. //
  17900. // Define a pointer to the Memory Descriptor List (MDL) for this I/O
  17901. // request. This field is only used if the I/O is "direct I/O".
  17902. //
  17903. PMDL MdlAddress;
  17904. //
  17905. // Flags word - used to remember various flags.
  17906. //
  17907. ULONG Flags;
  17908. //
  17909. // The following union is used for one of three purposes:
  17910. //
  17911. // 1. This IRP is an associated IRP. The field is a pointer to a master
  17912. // IRP.
  17913. //
  17914. // 2. This is the master IRP. The field is the count of the number of
  17915. // IRPs which must complete (associated IRPs) before the master can
  17916. // complete.
  17917. //
  17918. // 3. This operation is being buffered and the field is the address of
  17919. // the system space buffer.
  17920. //
  17921. union {
  17922. struct _IRP *MasterIrp;
  17923. LONG IrpCount;
  17924. PVOID SystemBuffer;
  17925. } AssociatedIrp;
  17926. //
  17927. // Thread list entry - allows queueing the IRP to the thread pending I/O
  17928. // request packet list.
  17929. //
  17930. LIST_ENTRY ThreadListEntry;
  17931. //
  17932. // I/O status - final status of operation.
  17933. //
  17934. IO_STATUS_BLOCK IoStatus;
  17935. //
  17936. // Requestor mode - mode of the original requestor of this operation.
  17937. //
  17938. KPROCESSOR_MODE RequestorMode;
  17939. //
  17940. // Pending returned - TRUE if pending was initially returned as the
  17941. // status for this packet.
  17942. //
  17943. BOOLEAN PendingReturned;
  17944. //
  17945. // Stack state information.
  17946. //
  17947. CHAR StackCount;
  17948. CHAR CurrentLocation;
  17949. //
  17950. // Cancel - packet has been canceled.
  17951. //
  17952. BOOLEAN Cancel;
  17953. //
  17954. // Cancel Irql - Irql at which the cancel spinlock was acquired.
  17955. //
  17956. KIRQL CancelIrql;
  17957. //
  17958. // ApcEnvironment - Used to save the APC environment at the time that the
  17959. // packet was initialized.
  17960. //
  17961. CCHAR ApcEnvironment;
  17962. //
  17963. // Allocation control flags.
  17964. //
  17965. UCHAR AllocationFlags;
  17966. //
  17967. // User parameters.
  17968. //
  17969. PIO_STATUS_BLOCK UserIosb;
  17970. PKEVENT UserEvent;
  17971. union {
  17972. struct {
  17973. PIO_APC_ROUTINE UserApcRoutine;
  17974. PVOID UserApcContext;
  17975. } AsynchronousParameters;
  17976. LARGE_INTEGER AllocationSize;
  17977. } Overlay;
  17978. //
  17979. // CancelRoutine - Used to contain the address of a cancel routine supplied
  17980. // by a device driver when the IRP is in a cancelable state.
  17981. //
  17982. PDRIVER_CANCEL CancelRoutine;
  17983. //
  17984. // Note that the UserBuffer parameter is outside of the stack so that I/O
  17985. // completion can copy data back into the user's address space without
  17986. // having to know exactly which service was being invoked. The length
  17987. // of the copy is stored in the second half of the I/O status block. If
  17988. // the UserBuffer field is NULL, then no copy is performed.
  17989. //
  17990. PVOID UserBuffer;
  17991. //
  17992. // Kernel structures
  17993. //
  17994. // The following section contains kernel structures which the IRP needs
  17995. // in order to place various work information in kernel controller system
  17996. // queues. Because the size and alignment cannot be controlled, they are
  17997. // placed here at the end so they just hang off and do not affect the
  17998. // alignment of other fields in the IRP.
  17999. //
  18000. union {
  18001. struct {
  18002. union {
  18003. //
  18004. // DeviceQueueEntry - The device queue entry field is used to
  18005. // queue the IRP to the device driver device queue.
  18006. //
  18007. KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
  18008. struct {
  18009. //
  18010. // The following are available to the driver to use in
  18011. // whatever manner is desired, while the driver owns the
  18012. // packet.
  18013. //
  18014. PVOID DriverContext[4];
  18015. } ;
  18016. } ;
  18017. //
  18018. // Thread - pointer to caller's Thread Control Block.
  18019. //
  18020. PETHREAD Thread;
  18021. //
  18022. // Auxiliary buffer - pointer to any auxiliary buffer that is
  18023. // required to pass information to a driver that is not contained
  18024. // in a normal buffer.
  18025. //
  18026. PCHAR AuxiliaryBuffer;
  18027. //
  18028. // The following unnamed structure must be exactly identical
  18029. // to the unnamed structure used in the minipacket header used
  18030. // for completion queue entries.
  18031. //
  18032. struct {
  18033. //
  18034. // List entry - used to queue the packet to completion queue, among
  18035. // others.
  18036. //
  18037. LIST_ENTRY ListEntry;
  18038. union {
  18039. //
  18040. // Current stack location - contains a pointer to the current
  18041. // IO_STACK_LOCATION structure in the IRP stack. This field
  18042. // should never be directly accessed by drivers. They should
  18043. // use the standard functions.
  18044. //
  18045. struct _IO_STACK_LOCATION *CurrentStackLocation;
  18046. //
  18047. // Minipacket type.
  18048. //
  18049. ULONG PacketType;
  18050. };
  18051. };
  18052. //
  18053. // Original file object - pointer to the original file object
  18054. // that was used to open the file. This field is owned by the
  18055. // I/O system and should not be used by any other drivers.
  18056. //
  18057. PFILE_OBJECT OriginalFileObject;
  18058. } Overlay;
  18059. //
  18060. // APC - This APC control block is used for the special kernel APC as
  18061. // well as for the caller's APC, if one was specified in the original
  18062. // argument list. If so, then the APC is reused for the normal APC for
  18063. // whatever mode the caller was in and the "special" routine that is
  18064. // invoked before the APC gets control simply deallocates the IRP.
  18065. //
  18066. KAPC Apc;
  18067. //
  18068. // CompletionKey - This is the key that is used to distinguish
  18069. // individual I/O operations initiated on a single file handle.
  18070. //
  18071. PVOID CompletionKey;
  18072. } Tail;
  18073. } IRP, *PIRP;
  18074. //
  18075. // Define completion routine types for use in stack locations in an IRP
  18076. //
  18077. typedef
  18078. NTSTATUS
  18079. (*PIO_COMPLETION_ROUTINE) (
  18080. IN PDEVICE_OBJECT DeviceObject,
  18081. IN PIRP Irp,
  18082. IN PVOID Context
  18083. );
  18084. //
  18085. // Define stack location control flags
  18086. //
  18087. #define SL_PENDING_RETURNED 0x01
  18088. #define SL_INVOKE_ON_CANCEL 0x20
  18089. #define SL_INVOKE_ON_SUCCESS 0x40
  18090. #define SL_INVOKE_ON_ERROR 0x80
  18091. //
  18092. // Define flags for various functions
  18093. //
  18094. //
  18095. // Create / Create Named Pipe
  18096. //
  18097. // The following flags must exactly match those in the IoCreateFile call's
  18098. // options. The case sensitive flag is added in later, by the parse routine,
  18099. // and is not an actual option to open. Rather, it is part of the object
  18100. // manager's attributes structure.
  18101. //
  18102. #define SL_FORCE_ACCESS_CHECK 0x01
  18103. #define SL_OPEN_PAGING_FILE 0x02
  18104. #define SL_OPEN_TARGET_DIRECTORY 0x04
  18105. #define SL_CASE_SENSITIVE 0x80
  18106. //
  18107. // Read / Write
  18108. //
  18109. #define SL_KEY_SPECIFIED 0x01
  18110. #define SL_OVERRIDE_VERIFY_VOLUME 0x02
  18111. #define SL_WRITE_THROUGH 0x04
  18112. #define SL_FT_SEQUENTIAL_WRITE 0x08
  18113. //
  18114. // Device I/O Control
  18115. //
  18116. //
  18117. // Same SL_OVERRIDE_VERIFY_VOLUME as for read/write above.
  18118. //
  18119. #define SL_READ_ACCESS_GRANTED 0x01
  18120. #define SL_WRITE_ACCESS_GRANTED 0x04 // Gap for SL_OVERRIDE_VERIFY_VOLUME
  18121. //
  18122. // Lock
  18123. //
  18124. #define SL_FAIL_IMMEDIATELY 0x01
  18125. #define SL_EXCLUSIVE_LOCK 0x02
  18126. //
  18127. // QueryDirectory / QueryEa / QueryQuota
  18128. //
  18129. #define SL_RESTART_SCAN 0x01
  18130. #define SL_RETURN_SINGLE_ENTRY 0x02
  18131. #define SL_INDEX_SPECIFIED 0x04
  18132. //
  18133. // NotifyDirectory
  18134. //
  18135. #define SL_WATCH_TREE 0x01
  18136. //
  18137. // FileSystemControl
  18138. //
  18139. // minor: mount/verify volume
  18140. //
  18141. #define SL_ALLOW_RAW_MOUNT 0x01
  18142. //
  18143. // Define PNP/POWER types required by IRP_MJ_PNP/IRP_MJ_POWER.
  18144. //
  18145. typedef enum _DEVICE_RELATION_TYPE {
  18146. BusRelations,
  18147. EjectionRelations,
  18148. PowerRelations,
  18149. RemovalRelations,
  18150. TargetDeviceRelation,
  18151. SingleBusRelations
  18152. } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
  18153. typedef struct _DEVICE_RELATIONS {
  18154. ULONG Count;
  18155. PDEVICE_OBJECT Objects[1]; // variable length
  18156. } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
  18157. typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
  18158. DeviceUsageTypeUndefined,
  18159. DeviceUsageTypePaging,
  18160. DeviceUsageTypeHibernation,
  18161. DeviceUsageTypeDumpFile
  18162. } DEVICE_USAGE_NOTIFICATION_TYPE;
  18163. // begin_ntminiport
  18164. // workaround overloaded definition (rpc generated headers all define INTERFACE
  18165. // to match the class name).
  18166. #undef INTERFACE
  18167. typedef struct _INTERFACE {
  18168. USHORT Size;
  18169. USHORT Version;
  18170. PVOID Context;
  18171. PINTERFACE_REFERENCE InterfaceReference;
  18172. PINTERFACE_DEREFERENCE InterfaceDereference;
  18173. // interface specific entries go here
  18174. } INTERFACE, *PINTERFACE;
  18175. // end_ntminiport
  18176. typedef struct _DEVICE_CAPABILITIES {
  18177. USHORT Size;
  18178. USHORT Version; // the version documented here is version 1
  18179. ULONG DeviceD1:1;
  18180. ULONG DeviceD2:1;
  18181. ULONG LockSupported:1;
  18182. ULONG EjectSupported:1; // Ejectable in S0
  18183. ULONG Removable:1;
  18184. ULONG DockDevice:1;
  18185. ULONG UniqueID:1;
  18186. ULONG SilentInstall:1;
  18187. ULONG RawDeviceOK:1;
  18188. ULONG SurpriseRemovalOK:1;
  18189. ULONG WakeFromD0:1;
  18190. ULONG WakeFromD1:1;
  18191. ULONG WakeFromD2:1;
  18192. ULONG WakeFromD3:1;
  18193. ULONG HardwareDisabled:1;
  18194. ULONG NonDynamic:1;
  18195. ULONG WarmEjectSupported:1;
  18196. ULONG NoDisplayInUI:1;
  18197. ULONG Reserved:14;
  18198. ULONG Address;
  18199. ULONG UINumber;
  18200. DEVICE_POWER_STATE DeviceState[POWER_SYSTEM_MAXIMUM];
  18201. SYSTEM_POWER_STATE SystemWake;
  18202. DEVICE_POWER_STATE DeviceWake;
  18203. ULONG D1Latency;
  18204. ULONG D2Latency;
  18205. ULONG D3Latency;
  18206. } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
  18207. typedef struct _POWER_SEQUENCE {
  18208. ULONG SequenceD1;
  18209. ULONG SequenceD2;
  18210. ULONG SequenceD3;
  18211. } POWER_SEQUENCE, *PPOWER_SEQUENCE;
  18212. typedef enum {
  18213. BusQueryDeviceID = 0, // <Enumerator>\<Enumerator-specific device id>
  18214. BusQueryHardwareIDs = 1, // Hardware ids
  18215. BusQueryCompatibleIDs = 2, // compatible device ids
  18216. BusQueryInstanceID = 3, // persistent id for this instance of the device
  18217. BusQueryDeviceSerialNumber = 4 // serial number for this device
  18218. } BUS_QUERY_ID_TYPE, *PBUS_QUERY_ID_TYPE;
  18219. typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
  18220. #define PNP_DEVICE_DISABLED 0x00000001
  18221. #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
  18222. #define PNP_DEVICE_FAILED 0x00000004
  18223. #define PNP_DEVICE_REMOVED 0x00000008
  18224. #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
  18225. #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
  18226. typedef enum {
  18227. DeviceTextDescription = 0, // DeviceDesc property
  18228. DeviceTextLocationInformation = 1 // DeviceLocation property
  18229. } DEVICE_TEXT_TYPE, *PDEVICE_TEXT_TYPE;
  18230. //
  18231. // Define I/O Request Packet (IRP) stack locations
  18232. //
  18233. #if !defined(_AMD64_) && !defined(_IA64_)
  18234. #include "pshpack4.h"
  18235. #endif
  18236. // begin_ntndis
  18237. #if defined(_WIN64)
  18238. #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
  18239. #else
  18240. #define POINTER_ALIGNMENT
  18241. #endif
  18242. // end_ntndis
  18243. typedef struct _IO_STACK_LOCATION {
  18244. UCHAR MajorFunction;
  18245. UCHAR MinorFunction;
  18246. UCHAR Flags;
  18247. UCHAR Control;
  18248. //
  18249. // The following user parameters are based on the service that is being
  18250. // invoked. Drivers and file systems can determine which set to use based
  18251. // on the above major and minor function codes.
  18252. //
  18253. union {
  18254. //
  18255. // System service parameters for: NtCreateFile
  18256. //
  18257. struct {
  18258. PIO_SECURITY_CONTEXT SecurityContext;
  18259. ULONG Options;
  18260. USHORT POINTER_ALIGNMENT FileAttributes;
  18261. USHORT ShareAccess;
  18262. ULONG POINTER_ALIGNMENT EaLength;
  18263. } Create;
  18264. //
  18265. // System service parameters for: NtReadFile
  18266. //
  18267. struct {
  18268. ULONG Length;
  18269. ULONG POINTER_ALIGNMENT Key;
  18270. LARGE_INTEGER ByteOffset;
  18271. } Read;
  18272. //
  18273. // System service parameters for: NtWriteFile
  18274. //
  18275. struct {
  18276. ULONG Length;
  18277. ULONG POINTER_ALIGNMENT Key;
  18278. LARGE_INTEGER ByteOffset;
  18279. } Write;
  18280. // end_ntddk end_wdm end_nthal
  18281. //
  18282. // System service parameters for: NtQueryDirectoryFile
  18283. //
  18284. struct {
  18285. ULONG Length;
  18286. PSTRING FileName;
  18287. FILE_INFORMATION_CLASS FileInformationClass;
  18288. ULONG POINTER_ALIGNMENT FileIndex;
  18289. } QueryDirectory;
  18290. //
  18291. // System service parameters for: NtNotifyChangeDirectoryFile
  18292. //
  18293. struct {
  18294. ULONG Length;
  18295. ULONG POINTER_ALIGNMENT CompletionFilter;
  18296. } NotifyDirectory;
  18297. // begin_ntddk begin_wdm begin_nthal
  18298. //
  18299. // System service parameters for: NtQueryInformationFile
  18300. //
  18301. struct {
  18302. ULONG Length;
  18303. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  18304. } QueryFile;
  18305. //
  18306. // System service parameters for: NtSetInformationFile
  18307. //
  18308. struct {
  18309. ULONG Length;
  18310. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  18311. PFILE_OBJECT FileObject;
  18312. union {
  18313. struct {
  18314. BOOLEAN ReplaceIfExists;
  18315. BOOLEAN AdvanceOnly;
  18316. };
  18317. ULONG ClusterCount;
  18318. HANDLE DeleteHandle;
  18319. };
  18320. } SetFile;
  18321. // end_ntddk end_wdm end_nthal end_ntosp
  18322. //
  18323. // System service parameters for: NtQueryEaFile
  18324. //
  18325. struct {
  18326. ULONG Length;
  18327. PVOID EaList;
  18328. ULONG EaListLength;
  18329. ULONG POINTER_ALIGNMENT EaIndex;
  18330. } QueryEa;
  18331. //
  18332. // System service parameters for: NtSetEaFile
  18333. //
  18334. struct {
  18335. ULONG Length;
  18336. } SetEa;
  18337. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  18338. //
  18339. // System service parameters for: NtQueryVolumeInformationFile
  18340. //
  18341. struct {
  18342. ULONG Length;
  18343. FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
  18344. } QueryVolume;
  18345. // end_ntddk end_wdm end_nthal end_ntosp
  18346. //
  18347. // System service parameters for: NtSetVolumeInformationFile
  18348. //
  18349. struct {
  18350. ULONG Length;
  18351. FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
  18352. } SetVolume;
  18353. // begin_ntosp
  18354. //
  18355. // System service parameters for: NtFsControlFile
  18356. //
  18357. // Note that the user's output buffer is stored in the UserBuffer field
  18358. // and the user's input buffer is stored in the SystemBuffer field.
  18359. //
  18360. struct {
  18361. ULONG OutputBufferLength;
  18362. ULONG POINTER_ALIGNMENT InputBufferLength;
  18363. ULONG POINTER_ALIGNMENT FsControlCode;
  18364. PVOID Type3InputBuffer;
  18365. } FileSystemControl;
  18366. //
  18367. // System service parameters for: NtLockFile/NtUnlockFile
  18368. //
  18369. struct {
  18370. PLARGE_INTEGER Length;
  18371. ULONG POINTER_ALIGNMENT Key;
  18372. LARGE_INTEGER ByteOffset;
  18373. } LockControl;
  18374. // begin_ntddk begin_wdm begin_nthal
  18375. //
  18376. // System service parameters for: NtFlushBuffersFile
  18377. //
  18378. // No extra user-supplied parameters.
  18379. //
  18380. // end_ntddk end_wdm end_nthal
  18381. // end_ntosp
  18382. //
  18383. // System service parameters for: NtCancelIoFile
  18384. //
  18385. // No extra user-supplied parameters.
  18386. //
  18387. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  18388. //
  18389. // System service parameters for: NtDeviceIoControlFile
  18390. //
  18391. // Note that the user's output buffer is stored in the UserBuffer field
  18392. // and the user's input buffer is stored in the SystemBuffer field.
  18393. //
  18394. struct {
  18395. ULONG OutputBufferLength;
  18396. ULONG POINTER_ALIGNMENT InputBufferLength;
  18397. ULONG POINTER_ALIGNMENT IoControlCode;
  18398. PVOID Type3InputBuffer;
  18399. } DeviceIoControl;
  18400. // end_wdm
  18401. //
  18402. // System service parameters for: NtQuerySecurityObject
  18403. //
  18404. struct {
  18405. SECURITY_INFORMATION SecurityInformation;
  18406. ULONG POINTER_ALIGNMENT Length;
  18407. } QuerySecurity;
  18408. //
  18409. // System service parameters for: NtSetSecurityObject
  18410. //
  18411. struct {
  18412. SECURITY_INFORMATION SecurityInformation;
  18413. PSECURITY_DESCRIPTOR SecurityDescriptor;
  18414. } SetSecurity;
  18415. // begin_wdm
  18416. //
  18417. // Non-system service parameters.
  18418. //
  18419. // Parameters for MountVolume
  18420. //
  18421. struct {
  18422. PVPB Vpb;
  18423. PDEVICE_OBJECT DeviceObject;
  18424. } MountVolume;
  18425. //
  18426. // Parameters for VerifyVolume
  18427. //
  18428. struct {
  18429. PVPB Vpb;
  18430. PDEVICE_OBJECT DeviceObject;
  18431. } VerifyVolume;
  18432. //
  18433. // Parameters for Scsi with internal device contorl.
  18434. //
  18435. struct {
  18436. struct _SCSI_REQUEST_BLOCK *Srb;
  18437. } Scsi;
  18438. // end_ntddk end_wdm end_nthal end_ntosp
  18439. //
  18440. // System service parameters for: NtQueryQuotaInformationFile
  18441. //
  18442. struct {
  18443. ULONG Length;
  18444. PSID StartSid;
  18445. PFILE_GET_QUOTA_INFORMATION SidList;
  18446. ULONG SidListLength;
  18447. } QueryQuota;
  18448. //
  18449. // System service parameters for: NtSetQuotaInformationFile
  18450. //
  18451. struct {
  18452. ULONG Length;
  18453. } SetQuota;
  18454. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  18455. //
  18456. // Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
  18457. //
  18458. struct {
  18459. DEVICE_RELATION_TYPE Type;
  18460. } QueryDeviceRelations;
  18461. //
  18462. // Parameters for IRP_MN_QUERY_INTERFACE
  18463. //
  18464. struct {
  18465. CONST GUID *InterfaceType;
  18466. USHORT Size;
  18467. USHORT Version;
  18468. PINTERFACE Interface;
  18469. PVOID InterfaceSpecificData;
  18470. } QueryInterface;
  18471. //
  18472. // Parameters for Cleanup
  18473. //
  18474. // No extra parameters supplied
  18475. //
  18476. //
  18477. // WMI Irps
  18478. //
  18479. struct {
  18480. ULONG_PTR ProviderId;
  18481. PVOID DataPath;
  18482. ULONG BufferSize;
  18483. PVOID Buffer;
  18484. } WMI;
  18485. //
  18486. // Others - driver-specific
  18487. //
  18488. struct {
  18489. PVOID Argument1;
  18490. PVOID Argument2;
  18491. PVOID Argument3;
  18492. PVOID Argument4;
  18493. } Others;
  18494. } Parameters;
  18495. //
  18496. // Save a pointer to this device driver's device object for this request
  18497. // so it can be passed to the completion routine if needed.
  18498. //
  18499. PDEVICE_OBJECT DeviceObject;
  18500. //
  18501. // The following location contains a pointer to the file object for this
  18502. //
  18503. PFILE_OBJECT FileObject;
  18504. //
  18505. // The following routine is invoked depending on the flags in the above
  18506. // flags field.
  18507. //
  18508. PIO_COMPLETION_ROUTINE CompletionRoutine;
  18509. //
  18510. // The following is used to store the address of the context parameter
  18511. // that should be passed to the CompletionRoutine.
  18512. //
  18513. PVOID Context;
  18514. } IO_STACK_LOCATION, *PIO_STACK_LOCATION;
  18515. #if !defined(_AMD64_) && !defined(_IA64_)
  18516. #include "poppack.h"
  18517. #endif
  18518. //
  18519. // Define the share access structure used by file systems to determine
  18520. // whether or not another accessor may open the file.
  18521. //
  18522. typedef struct _SHARE_ACCESS {
  18523. ULONG OpenCount;
  18524. ULONG Readers;
  18525. ULONG Writers;
  18526. ULONG Deleters;
  18527. ULONG SharedRead;
  18528. ULONG SharedWrite;
  18529. ULONG SharedDelete;
  18530. } SHARE_ACCESS, *PSHARE_ACCESS;
  18531. // end_wdm
  18532. //
  18533. // The following structure is used by drivers that are initializing to
  18534. // determine the number of devices of a particular type that have already
  18535. // been initialized. It is also used to track whether or not the AtDisk
  18536. // address range has already been claimed. Finally, it is used by the
  18537. // NtQuerySystemInformation system service to return device type counts.
  18538. //
  18539. typedef struct _CONFIGURATION_INFORMATION {
  18540. //
  18541. // This field indicates the total number of disks in the system. This
  18542. // number should be used by the driver to determine the name of new
  18543. // disks. This field should be updated by the driver as it finds new
  18544. // disks.
  18545. //
  18546. ULONG DiskCount; // Count of hard disks thus far
  18547. ULONG FloppyCount; // Count of floppy disks thus far
  18548. ULONG CdRomCount; // Count of CD-ROM drives thus far
  18549. ULONG TapeCount; // Count of tape drives thus far
  18550. ULONG ScsiPortCount; // Count of SCSI port adapters thus far
  18551. ULONG SerialCount; // Count of serial devices thus far
  18552. ULONG ParallelCount; // Count of parallel devices thus far
  18553. //
  18554. // These next two fields indicate ownership of one of the two IO address
  18555. // spaces that are used by WD1003-compatable disk controllers.
  18556. //
  18557. BOOLEAN AtDiskPrimaryAddressClaimed; // 0x1F0 - 0x1FF
  18558. BOOLEAN AtDiskSecondaryAddressClaimed; // 0x170 - 0x17F
  18559. //
  18560. // Indicates the structure version, as anything value belong this will have been added.
  18561. // Use the structure size as the version.
  18562. //
  18563. ULONG Version;
  18564. //
  18565. // Indicates the total number of medium changer devices in the system.
  18566. // This field will be updated by the drivers as it determines that
  18567. // new devices have been found and will be supported.
  18568. //
  18569. ULONG MediumChangerCount;
  18570. } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
  18571. // end_ntddk end_nthal end_ntosp
  18572. //
  18573. // The following are global counters used by the I/O system to indicate the
  18574. // amount of I/O being performed in the system. The first three counters
  18575. // are just that, counts of operations that have been requested, while the
  18576. // last three counters track the amount of data transferred for each type
  18577. // of I/O request.
  18578. //
  18579. extern KSPIN_LOCK IoStatisticsLock;
  18580. extern ULONG IoReadOperationCount;
  18581. extern ULONG IoWriteOperationCount;
  18582. extern ULONG IoOtherOperationCount;
  18583. extern LARGE_INTEGER IoReadTransferCount;
  18584. extern LARGE_INTEGER IoWriteTransferCount;
  18585. extern LARGE_INTEGER IoOtherTransferCount;
  18586. //
  18587. // It is difficult for cached file systems to properly charge quota
  18588. // for the storage that they allocate on behalf of user file handles,
  18589. // so the following amount of additional quota is charged against each
  18590. // handle as a "best guess" as to the amount of quota the file system
  18591. // will allocate on behalf of this handle.
  18592. //
  18593. //
  18594. // These numbers are totally arbitrary, and can be changed if it turns out
  18595. // that the file systems actually allocate more (or less) on behalf of
  18596. // their file objects. The non-paged pool charge constant is added to the
  18597. // size of a FILE_OBJECT to get the actual charge amount.
  18598. //
  18599. #define IO_FILE_OBJECT_NON_PAGED_POOL_CHARGE 64
  18600. #define IO_FILE_OBJECT_PAGED_POOL_CHARGE 1024
  18601. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  18602. //
  18603. // Public I/O routine definitions
  18604. //
  18605. NTKERNELAPI
  18606. VOID
  18607. IoAcquireCancelSpinLock(
  18608. OUT PKIRQL Irql
  18609. );
  18610. // end_ntddk end_wdm end_nthal end_ntosp
  18611. NTKERNELAPI
  18612. VOID
  18613. IoAcquireVpbSpinLock(
  18614. OUT PKIRQL Irql
  18615. );
  18616. NTKERNELAPI
  18617. PVOID
  18618. IoAllocateErrorLogEntry(
  18619. IN PVOID IoObject,
  18620. IN UCHAR EntrySize
  18621. );
  18622. NTKERNELAPI
  18623. PIRP
  18624. IoAllocateIrp(
  18625. IN CCHAR StackSize,
  18626. IN BOOLEAN ChargeQuota
  18627. );
  18628. NTKERNELAPI
  18629. PMDL
  18630. IoAllocateMdl(
  18631. IN PVOID VirtualAddress,
  18632. IN ULONG Length,
  18633. IN BOOLEAN SecondaryBuffer,
  18634. IN BOOLEAN ChargeQuota,
  18635. IN OUT PIRP Irp OPTIONAL
  18636. );
  18637. NTKERNELAPI
  18638. NTSTATUS
  18639. IoAttachDevice(
  18640. IN PDEVICE_OBJECT SourceDevice,
  18641. IN PUNICODE_STRING TargetDevice,
  18642. OUT PDEVICE_OBJECT *AttachedDevice
  18643. );
  18644. // end_wdm
  18645. DECLSPEC_DEPRECATED_DDK // Use IoAttachDeviceToDeviceStack
  18646. NTKERNELAPI
  18647. NTSTATUS
  18648. IoAttachDeviceByPointer(
  18649. IN PDEVICE_OBJECT SourceDevice,
  18650. IN PDEVICE_OBJECT TargetDevice
  18651. );
  18652. // begin_wdm
  18653. NTKERNELAPI
  18654. PDEVICE_OBJECT
  18655. IoAttachDeviceToDeviceStack(
  18656. IN PDEVICE_OBJECT SourceDevice,
  18657. IN PDEVICE_OBJECT TargetDevice
  18658. );
  18659. NTKERNELAPI
  18660. PIRP
  18661. IoBuildAsynchronousFsdRequest(
  18662. IN ULONG MajorFunction,
  18663. IN PDEVICE_OBJECT DeviceObject,
  18664. IN OUT PVOID Buffer OPTIONAL,
  18665. IN ULONG Length OPTIONAL,
  18666. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  18667. IN PIO_STATUS_BLOCK IoStatusBlock OPTIONAL
  18668. );
  18669. NTKERNELAPI
  18670. PIRP
  18671. IoBuildDeviceIoControlRequest(
  18672. IN ULONG IoControlCode,
  18673. IN PDEVICE_OBJECT DeviceObject,
  18674. IN PVOID InputBuffer OPTIONAL,
  18675. IN ULONG InputBufferLength,
  18676. OUT PVOID OutputBuffer OPTIONAL,
  18677. IN ULONG OutputBufferLength,
  18678. IN BOOLEAN InternalDeviceIoControl,
  18679. IN PKEVENT Event,
  18680. OUT PIO_STATUS_BLOCK IoStatusBlock
  18681. );
  18682. NTKERNELAPI
  18683. VOID
  18684. IoBuildPartialMdl(
  18685. IN PMDL SourceMdl,
  18686. IN OUT PMDL TargetMdl,
  18687. IN PVOID VirtualAddress,
  18688. IN ULONG Length
  18689. );
  18690. typedef struct _BOOTDISK_INFORMATION {
  18691. LONGLONG BootPartitionOffset;
  18692. LONGLONG SystemPartitionOffset;
  18693. ULONG BootDeviceSignature;
  18694. ULONG SystemDeviceSignature;
  18695. } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
  18696. //
  18697. // This structure should follow the previous structure field for field.
  18698. //
  18699. typedef struct _BOOTDISK_INFORMATION_EX {
  18700. LONGLONG BootPartitionOffset;
  18701. LONGLONG SystemPartitionOffset;
  18702. ULONG BootDeviceSignature;
  18703. ULONG SystemDeviceSignature;
  18704. GUID BootDeviceGuid;
  18705. GUID SystemDeviceGuid;
  18706. BOOLEAN BootDeviceIsGpt;
  18707. BOOLEAN SystemDeviceIsGpt;
  18708. } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
  18709. NTKERNELAPI
  18710. NTSTATUS
  18711. IoGetBootDiskInformation(
  18712. IN OUT PBOOTDISK_INFORMATION BootDiskInformation,
  18713. IN ULONG Size
  18714. );
  18715. NTKERNELAPI
  18716. PIRP
  18717. IoBuildSynchronousFsdRequest(
  18718. IN ULONG MajorFunction,
  18719. IN PDEVICE_OBJECT DeviceObject,
  18720. IN OUT PVOID Buffer OPTIONAL,
  18721. IN ULONG Length OPTIONAL,
  18722. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  18723. IN PKEVENT Event,
  18724. OUT PIO_STATUS_BLOCK IoStatusBlock
  18725. );
  18726. NTKERNELAPI
  18727. NTSTATUS
  18728. FASTCALL
  18729. IofCallDriver(
  18730. IN PDEVICE_OBJECT DeviceObject,
  18731. IN OUT PIRP Irp
  18732. );
  18733. #define IoCallDriver(a,b) \
  18734. IofCallDriver(a,b)
  18735. NTKERNELAPI
  18736. BOOLEAN
  18737. IoCancelIrp(
  18738. IN PIRP Irp
  18739. );
  18740. NTKERNELAPI
  18741. NTSTATUS
  18742. IoCheckDesiredAccess(
  18743. IN OUT PACCESS_MASK DesiredAccess,
  18744. IN ACCESS_MASK GrantedAccess
  18745. );
  18746. NTKERNELAPI
  18747. NTSTATUS
  18748. IoCheckEaBufferValidity(
  18749. IN PFILE_FULL_EA_INFORMATION EaBuffer,
  18750. IN ULONG EaLength,
  18751. OUT PULONG ErrorOffset
  18752. );
  18753. NTKERNELAPI
  18754. NTSTATUS
  18755. IoCheckFunctionAccess(
  18756. IN ACCESS_MASK GrantedAccess,
  18757. IN UCHAR MajorFunction,
  18758. IN UCHAR MinorFunction,
  18759. IN ULONG IoControlCode,
  18760. IN PVOID Arg1 OPTIONAL,
  18761. IN PVOID Arg2 OPTIONAL
  18762. );
  18763. NTKERNELAPI
  18764. NTSTATUS
  18765. IoCheckQuerySetFileInformation(
  18766. IN FILE_INFORMATION_CLASS FileInformationClass,
  18767. IN ULONG Length,
  18768. IN BOOLEAN SetOperation
  18769. );
  18770. NTKERNELAPI
  18771. NTSTATUS
  18772. IoCheckQuerySetVolumeInformation(
  18773. IN FS_INFORMATION_CLASS FsInformationClass,
  18774. IN ULONG Length,
  18775. IN BOOLEAN SetOperation
  18776. );
  18777. NTKERNELAPI
  18778. NTSTATUS
  18779. IoCheckQuotaBufferValidity(
  18780. IN PFILE_QUOTA_INFORMATION QuotaBuffer,
  18781. IN ULONG QuotaLength,
  18782. OUT PULONG ErrorOffset
  18783. );
  18784. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  18785. NTKERNELAPI
  18786. NTSTATUS
  18787. IoCheckShareAccess(
  18788. IN ACCESS_MASK DesiredAccess,
  18789. IN ULONG DesiredShareAccess,
  18790. IN OUT PFILE_OBJECT FileObject,
  18791. IN OUT PSHARE_ACCESS ShareAccess,
  18792. IN BOOLEAN Update
  18793. );
  18794. //
  18795. // This value should be returned from completion routines to continue
  18796. // completing the IRP upwards. Otherwise, STATUS_MORE_PROCESSING_REQUIRED
  18797. // should be returned.
  18798. //
  18799. #define STATUS_CONTINUE_COMPLETION STATUS_SUCCESS
  18800. //
  18801. // Completion routines can also use this enumeration in place of status codes.
  18802. //
  18803. typedef enum _IO_COMPLETION_ROUTINE_RESULT {
  18804. ContinueCompletion = STATUS_CONTINUE_COMPLETION,
  18805. StopCompletion = STATUS_MORE_PROCESSING_REQUIRED
  18806. } IO_COMPLETION_ROUTINE_RESULT, *PIO_COMPLETION_ROUTINE_RESULT;
  18807. NTKERNELAPI
  18808. VOID
  18809. FASTCALL
  18810. IofCompleteRequest(
  18811. IN PIRP Irp,
  18812. IN CCHAR PriorityBoost
  18813. );
  18814. #define IoCompleteRequest(a,b) \
  18815. IofCompleteRequest(a,b)
  18816. NTKERNELAPI
  18817. NTSTATUS
  18818. IoCreateDevice(
  18819. IN PDRIVER_OBJECT DriverObject,
  18820. IN ULONG DeviceExtensionSize,
  18821. IN PUNICODE_STRING DeviceName OPTIONAL,
  18822. IN DEVICE_TYPE DeviceType,
  18823. IN ULONG DeviceCharacteristics,
  18824. IN BOOLEAN Exclusive,
  18825. OUT PDEVICE_OBJECT *DeviceObject
  18826. );
  18827. #define WDM_MAJORVERSION 0x01
  18828. #define WDM_MINORVERSION 0x20
  18829. NTKERNELAPI
  18830. BOOLEAN
  18831. IoIsWdmVersionAvailable(
  18832. IN UCHAR MajorVersion,
  18833. IN UCHAR MinorVersion
  18834. );
  18835. // end_nthal
  18836. NTKERNELAPI
  18837. NTSTATUS
  18838. IoCreateFile(
  18839. OUT PHANDLE FileHandle,
  18840. IN ACCESS_MASK DesiredAccess,
  18841. IN POBJECT_ATTRIBUTES ObjectAttributes,
  18842. OUT PIO_STATUS_BLOCK IoStatusBlock,
  18843. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  18844. IN ULONG FileAttributes,
  18845. IN ULONG ShareAccess,
  18846. IN ULONG Disposition,
  18847. IN ULONG CreateOptions,
  18848. IN PVOID EaBuffer OPTIONAL,
  18849. IN ULONG EaLength,
  18850. IN CREATE_FILE_TYPE CreateFileType,
  18851. IN PVOID ExtraCreateParameters OPTIONAL,
  18852. IN ULONG Options
  18853. );
  18854. // end_ntddk end_wdm end_ntosp
  18855. NTKERNELAPI
  18856. PFILE_OBJECT
  18857. IoCreateStreamFileObject(
  18858. IN PFILE_OBJECT FileObject OPTIONAL,
  18859. IN PDEVICE_OBJECT DeviceObject OPTIONAL
  18860. );
  18861. NTKERNELAPI
  18862. PFILE_OBJECT
  18863. IoCreateStreamFileObjectEx(
  18864. IN PFILE_OBJECT FileObject OPTIONAL,
  18865. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  18866. OUT PHANDLE FileObjectHandle OPTIONAL
  18867. );
  18868. NTKERNELAPI
  18869. PFILE_OBJECT
  18870. IoCreateStreamFileObjectLite(
  18871. IN PFILE_OBJECT FileObject OPTIONAL,
  18872. IN PDEVICE_OBJECT DeviceObject OPTIONAL
  18873. );
  18874. // begin_nthal begin_ntddk begin_wdm begin_ntosp
  18875. NTKERNELAPI
  18876. PKEVENT
  18877. IoCreateNotificationEvent(
  18878. IN PUNICODE_STRING EventName,
  18879. OUT PHANDLE EventHandle
  18880. );
  18881. NTKERNELAPI
  18882. NTSTATUS
  18883. IoCreateSymbolicLink(
  18884. IN PUNICODE_STRING SymbolicLinkName,
  18885. IN PUNICODE_STRING DeviceName
  18886. );
  18887. NTKERNELAPI
  18888. PKEVENT
  18889. IoCreateSynchronizationEvent(
  18890. IN PUNICODE_STRING EventName,
  18891. OUT PHANDLE EventHandle
  18892. );
  18893. NTKERNELAPI
  18894. NTSTATUS
  18895. IoCreateUnprotectedSymbolicLink(
  18896. IN PUNICODE_STRING SymbolicLinkName,
  18897. IN PUNICODE_STRING DeviceName
  18898. );
  18899. // end_wdm
  18900. //++
  18901. //
  18902. // VOID
  18903. // IoDeassignArcName(
  18904. // IN PUNICODE_STRING ArcName
  18905. // )
  18906. //
  18907. // Routine Description:
  18908. //
  18909. // This routine is invoked by drivers to deassign an ARC name that they
  18910. // created to a device. This is generally only called if the driver is
  18911. // deleting the device object, which means that the driver is probably
  18912. // unloading.
  18913. //
  18914. // Arguments:
  18915. //
  18916. // ArcName - Supplies the ARC name to be removed.
  18917. //
  18918. // Return Value:
  18919. //
  18920. // None.
  18921. //
  18922. //--
  18923. #define IoDeassignArcName( ArcName ) ( \
  18924. IoDeleteSymbolicLink( (ArcName) ) )
  18925. NTKERNELAPI
  18926. VOID
  18927. IoDeleteDevice(
  18928. IN PDEVICE_OBJECT DeviceObject
  18929. );
  18930. NTKERNELAPI
  18931. NTSTATUS
  18932. IoDeleteSymbolicLink(
  18933. IN PUNICODE_STRING SymbolicLinkName
  18934. );
  18935. NTKERNELAPI
  18936. VOID
  18937. IoDetachDevice(
  18938. IN OUT PDEVICE_OBJECT TargetDevice
  18939. );
  18940. NTKERNELAPI
  18941. BOOLEAN
  18942. IoFastQueryNetworkAttributes(
  18943. IN POBJECT_ATTRIBUTES ObjectAttributes,
  18944. IN ACCESS_MASK DesiredAccess,
  18945. IN ULONG OpenOptions,
  18946. OUT PIO_STATUS_BLOCK IoStatus,
  18947. OUT PFILE_NETWORK_OPEN_INFORMATION Buffer
  18948. );
  18949. NTKERNELAPI
  18950. VOID
  18951. IoFreeIrp(
  18952. IN PIRP Irp
  18953. );
  18954. NTKERNELAPI
  18955. VOID
  18956. IoFreeMdl(
  18957. IN PMDL Mdl
  18958. );
  18959. NTKERNELAPI
  18960. PDEVICE_OBJECT
  18961. IoGetAttachedDevice(
  18962. IN PDEVICE_OBJECT DeviceObject
  18963. );
  18964. NTKERNELAPI // ntddk wdm nthal
  18965. PDEVICE_OBJECT // ntddk wdm nthal
  18966. IoGetAttachedDeviceReference( // ntddk wdm nthal
  18967. IN PDEVICE_OBJECT DeviceObject // ntddk wdm nthal
  18968. ); // ntddk wdm nthal
  18969. // ntddk wdm nthal
  18970. NTKERNELAPI
  18971. PDEVICE_OBJECT
  18972. IoGetBaseFileSystemDeviceObject(
  18973. IN PFILE_OBJECT FileObject
  18974. );
  18975. NTKERNELAPI // ntddk nthal ntosp
  18976. PCONFIGURATION_INFORMATION // ntddk nthal ntosp
  18977. IoGetConfigurationInformation( VOID ); // ntddk nthal ntosp
  18978. // begin_ntddk begin_wdm begin_nthal
  18979. //++
  18980. //
  18981. // PIO_STACK_LOCATION
  18982. // IoGetCurrentIrpStackLocation(
  18983. // IN PIRP Irp
  18984. // )
  18985. //
  18986. // Routine Description:
  18987. //
  18988. // This routine is invoked to return a pointer to the current stack location
  18989. // in an I/O Request Packet (IRP).
  18990. //
  18991. // Arguments:
  18992. //
  18993. // Irp - Pointer to the I/O Request Packet.
  18994. //
  18995. // Return Value:
  18996. //
  18997. // The function value is a pointer to the current stack location in the
  18998. // packet.
  18999. //
  19000. //--
  19001. #define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
  19002. // end_nthal end_wdm
  19003. NTKERNELAPI
  19004. PDEVICE_OBJECT
  19005. IoGetDeviceToVerify(
  19006. IN PETHREAD Thread
  19007. );
  19008. // begin_wdm
  19009. NTKERNELAPI
  19010. PVOID
  19011. IoGetDriverObjectExtension(
  19012. IN PDRIVER_OBJECT DriverObject,
  19013. IN PVOID ClientIdentificationAddress
  19014. );
  19015. NTKERNELAPI
  19016. PEPROCESS
  19017. IoGetCurrentProcess(
  19018. VOID
  19019. );
  19020. // begin_nthal
  19021. NTKERNELAPI
  19022. NTSTATUS
  19023. IoGetDeviceObjectPointer(
  19024. IN PUNICODE_STRING ObjectName,
  19025. IN ACCESS_MASK DesiredAccess,
  19026. OUT PFILE_OBJECT *FileObject,
  19027. OUT PDEVICE_OBJECT *DeviceObject
  19028. );
  19029. NTKERNELAPI
  19030. struct _DMA_ADAPTER *
  19031. IoGetDmaAdapter(
  19032. IN PDEVICE_OBJECT PhysicalDeviceObject, OPTIONAL // required for PnP drivers
  19033. IN struct _DEVICE_DESCRIPTION *DeviceDescription,
  19034. IN OUT PULONG NumberOfMapRegisters
  19035. );
  19036. NTKERNELAPI
  19037. BOOLEAN
  19038. IoForwardIrpSynchronously(
  19039. IN PDEVICE_OBJECT DeviceObject,
  19040. IN PIRP Irp
  19041. );
  19042. #define IoForwardAndCatchIrp IoForwardIrpSynchronously
  19043. // end_wdm
  19044. NTKERNELAPI
  19045. PGENERIC_MAPPING
  19046. IoGetFileObjectGenericMapping(
  19047. VOID
  19048. );
  19049. // end_nthal
  19050. // begin_wdm
  19051. //++
  19052. //
  19053. // ULONG
  19054. // IoGetFunctionCodeFromCtlCode(
  19055. // IN ULONG ControlCode
  19056. // )
  19057. //
  19058. // Routine Description:
  19059. //
  19060. // This routine extracts the function code from IOCTL and FSCTL function
  19061. // control codes.
  19062. // This routine should only be used by kernel mode code.
  19063. //
  19064. // Arguments:
  19065. //
  19066. // ControlCode - A function control code (IOCTL or FSCTL) from which the
  19067. // function code must be extracted.
  19068. //
  19069. // Return Value:
  19070. //
  19071. // The extracted function code.
  19072. //
  19073. // Note:
  19074. //
  19075. // The CTL_CODE macro, used to create IOCTL and FSCTL function control
  19076. // codes, is defined in ntioapi.h
  19077. //
  19078. //--
  19079. #define IoGetFunctionCodeFromCtlCode( ControlCode ) (\
  19080. ( ControlCode >> 2) & 0x00000FFF )
  19081. // begin_nthal
  19082. NTKERNELAPI
  19083. PVOID
  19084. IoGetInitialStack(
  19085. VOID
  19086. );
  19087. NTKERNELAPI
  19088. VOID
  19089. IoGetStackLimits (
  19090. OUT PULONG_PTR LowLimit,
  19091. OUT PULONG_PTR HighLimit
  19092. );
  19093. //
  19094. // The following function is used to tell the caller how much stack is available
  19095. //
  19096. FORCEINLINE
  19097. ULONG_PTR
  19098. IoGetRemainingStackSize (
  19099. VOID
  19100. )
  19101. {
  19102. ULONG_PTR Top;
  19103. ULONG_PTR Bottom;
  19104. IoGetStackLimits( &Bottom, &Top );
  19105. return((ULONG_PTR)(&Top) - Bottom );
  19106. }
  19107. //++
  19108. //
  19109. // PIO_STACK_LOCATION
  19110. // IoGetNextIrpStackLocation(
  19111. // IN PIRP Irp
  19112. // )
  19113. //
  19114. // Routine Description:
  19115. //
  19116. // This routine is invoked to return a pointer to the next stack location
  19117. // in an I/O Request Packet (IRP).
  19118. //
  19119. // Arguments:
  19120. //
  19121. // Irp - Pointer to the I/O Request Packet.
  19122. //
  19123. // Return Value:
  19124. //
  19125. // The function value is a pointer to the next stack location in the packet.
  19126. //
  19127. //--
  19128. #define IoGetNextIrpStackLocation( Irp ) (\
  19129. (Irp)->Tail.Overlay.CurrentStackLocation - 1 )
  19130. NTKERNELAPI
  19131. PDEVICE_OBJECT
  19132. IoGetRelatedDeviceObject(
  19133. IN PFILE_OBJECT FileObject
  19134. );
  19135. // end_ntddk end_wdm end_nthal
  19136. NTKERNELAPI
  19137. ULONG
  19138. IoGetRequestorProcessId(
  19139. IN PIRP Irp
  19140. );
  19141. NTKERNELAPI
  19142. PEPROCESS
  19143. IoGetRequestorProcess(
  19144. IN PIRP Irp
  19145. );
  19146. // end_ntosp
  19147. NTKERNELAPI
  19148. PIRP
  19149. IoGetTopLevelIrp(
  19150. VOID
  19151. );
  19152. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  19153. //++
  19154. //
  19155. // VOID
  19156. // IoInitializeDpcRequest(
  19157. // IN PDEVICE_OBJECT DeviceObject,
  19158. // IN PIO_DPC_ROUTINE DpcRoutine
  19159. // )
  19160. //
  19161. // Routine Description:
  19162. //
  19163. // This routine is invoked to initialize the DPC in a device object for a
  19164. // device driver during its initialization routine. The DPC is used later
  19165. // when the driver interrupt service routine requests that a DPC routine
  19166. // be queued for later execution.
  19167. //
  19168. // Arguments:
  19169. //
  19170. // DeviceObject - Pointer to the device object that the request is for.
  19171. //
  19172. // DpcRoutine - Address of the driver's DPC routine to be executed when
  19173. // the DPC is dequeued for processing.
  19174. //
  19175. // Return Value:
  19176. //
  19177. // None.
  19178. //
  19179. //--
  19180. #define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\
  19181. KeInitializeDpc( &(DeviceObject)->Dpc, \
  19182. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  19183. (DeviceObject) ) )
  19184. NTKERNELAPI
  19185. VOID
  19186. IoInitializeIrp(
  19187. IN OUT PIRP Irp,
  19188. IN USHORT PacketSize,
  19189. IN CCHAR StackSize
  19190. );
  19191. NTKERNELAPI
  19192. NTSTATUS
  19193. IoInitializeTimer(
  19194. IN PDEVICE_OBJECT DeviceObject,
  19195. IN PIO_TIMER_ROUTINE TimerRoutine,
  19196. IN PVOID Context
  19197. );
  19198. NTKERNELAPI
  19199. VOID
  19200. IoReuseIrp(
  19201. IN OUT PIRP Irp,
  19202. IN NTSTATUS Iostatus
  19203. );
  19204. // end_wdm
  19205. NTKERNELAPI
  19206. VOID
  19207. IoCancelFileOpen(
  19208. IN PDEVICE_OBJECT DeviceObject,
  19209. IN PFILE_OBJECT FileObject
  19210. );
  19211. //++
  19212. //
  19213. // BOOLEAN
  19214. // IoIsErrorUserInduced(
  19215. // IN NTSTATUS Status
  19216. // )
  19217. //
  19218. // Routine Description:
  19219. //
  19220. // This routine is invoked to determine if an error was as a
  19221. // result of user actions. Typically these error are related
  19222. // to removable media and will result in a pop-up.
  19223. //
  19224. // Arguments:
  19225. //
  19226. // Status - The status value to check.
  19227. //
  19228. // Return Value:
  19229. // The function value is TRUE if the user induced the error,
  19230. // otherwise FALSE is returned.
  19231. //
  19232. //--
  19233. #define IoIsErrorUserInduced( Status ) ((BOOLEAN) \
  19234. (((Status) == STATUS_DEVICE_NOT_READY) || \
  19235. ((Status) == STATUS_IO_TIMEOUT) || \
  19236. ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
  19237. ((Status) == STATUS_NO_MEDIA_IN_DEVICE) || \
  19238. ((Status) == STATUS_VERIFY_REQUIRED) || \
  19239. ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
  19240. ((Status) == STATUS_WRONG_VOLUME)))
  19241. // end_ntddk end_wdm end_nthal end_ntosp
  19242. //++
  19243. //
  19244. // BOOLEAN
  19245. // IoIsFileOpenedExclusively(
  19246. // IN PFILE_OBJECT FileObject
  19247. // )
  19248. //
  19249. // Routine Description:
  19250. //
  19251. // This routine is invoked to determine whether the file open represented
  19252. // by the specified file object is opened exclusively.
  19253. //
  19254. // Arguments:
  19255. //
  19256. // FileObject - Pointer to the file object that represents the open instance
  19257. // of the target file to be tested for exclusive access.
  19258. //
  19259. // Return Value:
  19260. //
  19261. // The function value is TRUE if the open instance of the file is exclusive;
  19262. // otherwise FALSE is returned.
  19263. //
  19264. //--
  19265. #define IoIsFileOpenedExclusively( FileObject ) (\
  19266. (BOOLEAN) !((FileObject)->SharedRead || (FileObject)->SharedWrite || (FileObject)->SharedDelete))
  19267. NTKERNELAPI
  19268. BOOLEAN
  19269. IoIsOperationSynchronous(
  19270. IN PIRP Irp
  19271. );
  19272. NTKERNELAPI
  19273. BOOLEAN
  19274. IoIsSystemThread(
  19275. IN PETHREAD Thread
  19276. );
  19277. NTKERNELAPI
  19278. BOOLEAN
  19279. IoIsValidNameGraftingBuffer(
  19280. IN PIRP Irp,
  19281. IN PREPARSE_DATA_BUFFER ReparseBuffer
  19282. );
  19283. // begin_ntddk begin_nthal begin_ntosp
  19284. NTKERNELAPI
  19285. PIRP
  19286. IoMakeAssociatedIrp(
  19287. IN PIRP Irp,
  19288. IN CCHAR StackSize
  19289. );
  19290. // begin_wdm
  19291. //++
  19292. //
  19293. // VOID
  19294. // IoMarkIrpPending(
  19295. // IN OUT PIRP Irp
  19296. // )
  19297. //
  19298. // Routine Description:
  19299. //
  19300. // This routine marks the specified I/O Request Packet (IRP) to indicate
  19301. // that an initial status of STATUS_PENDING was returned to the caller.
  19302. // This is used so that I/O completion can determine whether or not to
  19303. // fully complete the I/O operation requested by the packet.
  19304. //
  19305. // Arguments:
  19306. //
  19307. // Irp - Pointer to the I/O Request Packet to be marked pending.
  19308. //
  19309. // Return Value:
  19310. //
  19311. // None.
  19312. //
  19313. //--
  19314. #define IoMarkIrpPending( Irp ) ( \
  19315. IoGetCurrentIrpStackLocation( (Irp) )->Control |= SL_PENDING_RETURNED )
  19316. NTKERNELAPI
  19317. NTSTATUS
  19318. IoPageRead(
  19319. IN PFILE_OBJECT FileObject,
  19320. IN PMDL MemoryDescriptorList,
  19321. IN PLARGE_INTEGER StartingOffset,
  19322. IN PKEVENT Event,
  19323. OUT PIO_STATUS_BLOCK IoStatusBlock
  19324. );
  19325. NTSTATUS
  19326. IoQueryFileDosDeviceName(
  19327. IN PFILE_OBJECT FileObject,
  19328. OUT POBJECT_NAME_INFORMATION *ObjectNameInformation
  19329. );
  19330. NTKERNELAPI
  19331. NTSTATUS
  19332. IoQueryFileInformation(
  19333. IN PFILE_OBJECT FileObject,
  19334. IN FILE_INFORMATION_CLASS FileInformationClass,
  19335. IN ULONG Length,
  19336. OUT PVOID FileInformation,
  19337. OUT PULONG ReturnedLength
  19338. );
  19339. NTKERNELAPI
  19340. NTSTATUS
  19341. IoQueryVolumeInformation(
  19342. IN PFILE_OBJECT FileObject,
  19343. IN FS_INFORMATION_CLASS FsInformationClass,
  19344. IN ULONG Length,
  19345. OUT PVOID FsInformation,
  19346. OUT PULONG ReturnedLength
  19347. );
  19348. // begin_ntosp
  19349. NTKERNELAPI
  19350. VOID
  19351. IoQueueThreadIrp(
  19352. IN PIRP Irp
  19353. );
  19354. // end_ntosp
  19355. // begin_ntddk begin_nthal begin_ntosp
  19356. NTKERNELAPI
  19357. VOID
  19358. IoRaiseHardError(
  19359. IN PIRP Irp,
  19360. IN PVPB Vpb OPTIONAL,
  19361. IN PDEVICE_OBJECT RealDeviceObject
  19362. );
  19363. NTKERNELAPI
  19364. BOOLEAN
  19365. IoRaiseInformationalHardError(
  19366. IN NTSTATUS ErrorStatus,
  19367. IN PUNICODE_STRING String OPTIONAL,
  19368. IN PKTHREAD Thread OPTIONAL
  19369. );
  19370. NTKERNELAPI
  19371. BOOLEAN
  19372. IoSetThreadHardErrorMode(
  19373. IN BOOLEAN EnableHardErrors
  19374. );
  19375. NTKERNELAPI
  19376. VOID
  19377. IoRegisterBootDriverReinitialization(
  19378. IN PDRIVER_OBJECT DriverObject,
  19379. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  19380. IN PVOID Context
  19381. );
  19382. NTKERNELAPI
  19383. VOID
  19384. IoRegisterDriverReinitialization(
  19385. IN PDRIVER_OBJECT DriverObject,
  19386. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  19387. IN PVOID Context
  19388. );
  19389. // end_ntddk end_nthal end_ntosp
  19390. NTKERNELAPI
  19391. VOID
  19392. IoRegisterFileSystem(
  19393. IN OUT PDEVICE_OBJECT DeviceObject
  19394. );
  19395. NTKERNELAPI
  19396. NTSTATUS
  19397. IoRegisterFsRegistrationChange(
  19398. IN PDRIVER_OBJECT DriverObject,
  19399. IN PDRIVER_FS_NOTIFICATION DriverNotificationRoutine
  19400. );
  19401. // begin_ntddk begin_nthal begin_ntosp
  19402. NTKERNELAPI
  19403. NTSTATUS
  19404. IoRegisterShutdownNotification(
  19405. IN PDEVICE_OBJECT DeviceObject
  19406. );
  19407. NTKERNELAPI
  19408. NTSTATUS
  19409. IoRegisterLastChanceShutdownNotification(
  19410. IN PDEVICE_OBJECT DeviceObject
  19411. );
  19412. // begin_wdm
  19413. NTKERNELAPI
  19414. VOID
  19415. IoReleaseCancelSpinLock(
  19416. IN KIRQL Irql
  19417. );
  19418. // end_ntddk end_nthal end_wdm end_ntosp
  19419. NTKERNELAPI
  19420. VOID
  19421. IoReleaseVpbSpinLock(
  19422. IN KIRQL Irql
  19423. );
  19424. // begin_ntddk begin_nthal begin_ntosp
  19425. NTKERNELAPI
  19426. VOID
  19427. IoRemoveShareAccess(
  19428. IN PFILE_OBJECT FileObject,
  19429. IN OUT PSHARE_ACCESS ShareAccess
  19430. );
  19431. DECLSPEC_DEPRECATED_DDK // Use IoReportResourceForDetection
  19432. NTKERNELAPI
  19433. NTSTATUS
  19434. IoReportResourceUsage(
  19435. IN PUNICODE_STRING DriverClassName OPTIONAL,
  19436. IN PDRIVER_OBJECT DriverObject,
  19437. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  19438. IN ULONG DriverListSize OPTIONAL,
  19439. IN PDEVICE_OBJECT DeviceObject,
  19440. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  19441. IN ULONG DeviceListSize OPTIONAL,
  19442. IN BOOLEAN OverrideConflict,
  19443. OUT PBOOLEAN ConflictDetected
  19444. );
  19445. // begin_wdm
  19446. //++
  19447. //
  19448. // VOID
  19449. // IoRequestDpc(
  19450. // IN PDEVICE_OBJECT DeviceObject,
  19451. // IN PIRP Irp,
  19452. // IN PVOID Context
  19453. // )
  19454. //
  19455. // Routine Description:
  19456. //
  19457. // This routine is invoked by the device driver's interrupt service routine
  19458. // to request that a DPC routine be queued for later execution at a lower
  19459. // IRQL.
  19460. //
  19461. // Arguments:
  19462. //
  19463. // DeviceObject - Device object for which the request is being processed.
  19464. //
  19465. // Irp - Pointer to the current I/O Request Packet (IRP) for the specified
  19466. // device.
  19467. //
  19468. // Context - Provides a general context parameter to be passed to the
  19469. // DPC routine.
  19470. //
  19471. // Return Value:
  19472. //
  19473. // None.
  19474. //
  19475. //--
  19476. #define IoRequestDpc( DeviceObject, Irp, Context ) ( \
  19477. KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )
  19478. //++
  19479. //
  19480. // PDRIVER_CANCEL
  19481. // IoSetCancelRoutine(
  19482. // IN PIRP Irp,
  19483. // IN PDRIVER_CANCEL CancelRoutine
  19484. // )
  19485. //
  19486. // Routine Description:
  19487. //
  19488. // This routine is invoked to set the address of a cancel routine which
  19489. // is to be invoked when an I/O packet has been canceled.
  19490. //
  19491. // Arguments:
  19492. //
  19493. // Irp - Pointer to the I/O Request Packet itself.
  19494. //
  19495. // CancelRoutine - Address of the cancel routine that is to be invoked
  19496. // if the IRP is cancelled.
  19497. //
  19498. // Return Value:
  19499. //
  19500. // Previous value of CancelRoutine field in the IRP.
  19501. //
  19502. //--
  19503. #define IoSetCancelRoutine( Irp, NewCancelRoutine ) ( \
  19504. (PDRIVER_CANCEL) InterlockedExchangePointer( (PVOID *) &(Irp)->CancelRoutine, (PVOID) (NewCancelRoutine) ) )
  19505. //++
  19506. //
  19507. // VOID
  19508. // IoSetCompletionRoutine(
  19509. // IN PIRP Irp,
  19510. // IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  19511. // IN PVOID Context,
  19512. // IN BOOLEAN InvokeOnSuccess,
  19513. // IN BOOLEAN InvokeOnError,
  19514. // IN BOOLEAN InvokeOnCancel
  19515. // )
  19516. //
  19517. // Routine Description:
  19518. //
  19519. // This routine is invoked to set the address of a completion routine which
  19520. // is to be invoked when an I/O packet has been completed by a lower-level
  19521. // driver.
  19522. //
  19523. // Arguments:
  19524. //
  19525. // Irp - Pointer to the I/O Request Packet itself.
  19526. //
  19527. // CompletionRoutine - Address of the completion routine that is to be
  19528. // invoked once the next level driver completes the packet.
  19529. //
  19530. // Context - Specifies a context parameter to be passed to the completion
  19531. // routine.
  19532. //
  19533. // InvokeOnSuccess - Specifies that the completion routine is invoked when the
  19534. // operation is successfully completed.
  19535. //
  19536. // InvokeOnError - Specifies that the completion routine is invoked when the
  19537. // operation completes with an error status.
  19538. //
  19539. // InvokeOnCancel - Specifies that the completion routine is invoked when the
  19540. // operation is being canceled.
  19541. //
  19542. // Return Value:
  19543. //
  19544. // None.
  19545. //
  19546. //--
  19547. #define IoSetCompletionRoutine( Irp, Routine, CompletionContext, Success, Error, Cancel ) { \
  19548. PIO_STACK_LOCATION __irpSp; \
  19549. ASSERT( (Success) | (Error) | (Cancel) ? (Routine) != NULL : TRUE ); \
  19550. __irpSp = IoGetNextIrpStackLocation( (Irp) ); \
  19551. __irpSp->CompletionRoutine = (Routine); \
  19552. __irpSp->Context = (CompletionContext); \
  19553. __irpSp->Control = 0; \
  19554. if ((Success)) { __irpSp->Control = SL_INVOKE_ON_SUCCESS; } \
  19555. if ((Error)) { __irpSp->Control |= SL_INVOKE_ON_ERROR; } \
  19556. if ((Cancel)) { __irpSp->Control |= SL_INVOKE_ON_CANCEL; } }
  19557. NTSTATUS
  19558. IoSetCompletionRoutineEx(
  19559. IN PDEVICE_OBJECT DeviceObject,
  19560. IN PIRP Irp,
  19561. IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  19562. IN PVOID Context,
  19563. IN BOOLEAN InvokeOnSuccess,
  19564. IN BOOLEAN InvokeOnError,
  19565. IN BOOLEAN InvokeOnCancel
  19566. );
  19567. // end_ntddk end_wdm end_nthal end_ntosp
  19568. NTKERNELAPI
  19569. VOID
  19570. IoSetDeviceToVerify(
  19571. IN PETHREAD Thread,
  19572. IN PDEVICE_OBJECT DeviceObject
  19573. );
  19574. // begin_ntddk begin_nthal begin_ntosp
  19575. NTKERNELAPI
  19576. VOID
  19577. IoSetHardErrorOrVerifyDevice(
  19578. IN PIRP Irp,
  19579. IN PDEVICE_OBJECT DeviceObject
  19580. );
  19581. // end_ntddk end_nthal
  19582. NTKERNELAPI
  19583. NTSTATUS
  19584. IoSetInformation(
  19585. IN PFILE_OBJECT FileObject,
  19586. IN FILE_INFORMATION_CLASS FileInformationClass,
  19587. IN ULONG Length,
  19588. IN PVOID FileInformation
  19589. );
  19590. // end_ntosp
  19591. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  19592. //++
  19593. //
  19594. // VOID
  19595. // IoSetNextIrpStackLocation (
  19596. // IN OUT PIRP Irp
  19597. // )
  19598. //
  19599. // Routine Description:
  19600. //
  19601. // This routine is invoked to set the current IRP stack location to
  19602. // the next stack location, i.e. it "pushes" the stack.
  19603. //
  19604. // Arguments:
  19605. //
  19606. // Irp - Pointer to the I/O Request Packet (IRP).
  19607. //
  19608. // Return Value:
  19609. //
  19610. // None.
  19611. //
  19612. //--
  19613. #define IoSetNextIrpStackLocation( Irp ) { \
  19614. (Irp)->CurrentLocation--; \
  19615. (Irp)->Tail.Overlay.CurrentStackLocation--; }
  19616. //++
  19617. //
  19618. // VOID
  19619. // IoCopyCurrentIrpStackLocationToNext(
  19620. // IN PIRP Irp
  19621. // )
  19622. //
  19623. // Routine Description:
  19624. //
  19625. // This routine is invoked to copy the IRP stack arguments and file
  19626. // pointer from the current IrpStackLocation to the next
  19627. // in an I/O Request Packet (IRP).
  19628. //
  19629. // If the caller wants to call IoCallDriver with a completion routine
  19630. // but does not wish to change the arguments otherwise,
  19631. // the caller first calls IoCopyCurrentIrpStackLocationToNext,
  19632. // then IoSetCompletionRoutine, then IoCallDriver.
  19633. //
  19634. // Arguments:
  19635. //
  19636. // Irp - Pointer to the I/O Request Packet.
  19637. //
  19638. // Return Value:
  19639. //
  19640. // None.
  19641. //
  19642. //--
  19643. #define IoCopyCurrentIrpStackLocationToNext( Irp ) { \
  19644. PIO_STACK_LOCATION __irpSp; \
  19645. PIO_STACK_LOCATION __nextIrpSp; \
  19646. __irpSp = IoGetCurrentIrpStackLocation( (Irp) ); \
  19647. __nextIrpSp = IoGetNextIrpStackLocation( (Irp) ); \
  19648. RtlCopyMemory( __nextIrpSp, __irpSp, FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
  19649. __nextIrpSp->Control = 0; }
  19650. //++
  19651. //
  19652. // VOID
  19653. // IoSkipCurrentIrpStackLocation (
  19654. // IN PIRP Irp
  19655. // )
  19656. //
  19657. // Routine Description:
  19658. //
  19659. // This routine is invoked to increment the current stack location of
  19660. // a given IRP.
  19661. //
  19662. // If the caller wishes to call the next driver in a stack, and does not
  19663. // wish to change the arguments, nor does he wish to set a completion
  19664. // routine, then the caller first calls IoSkipCurrentIrpStackLocation
  19665. // and the calls IoCallDriver.
  19666. //
  19667. // Arguments:
  19668. //
  19669. // Irp - Pointer to the I/O Request Packet.
  19670. //
  19671. // Return Value:
  19672. //
  19673. // None
  19674. //
  19675. //--
  19676. #define IoSkipCurrentIrpStackLocation( Irp ) { \
  19677. (Irp)->CurrentLocation++; \
  19678. (Irp)->Tail.Overlay.CurrentStackLocation++; }
  19679. NTKERNELAPI
  19680. VOID
  19681. IoSetShareAccess(
  19682. IN ACCESS_MASK DesiredAccess,
  19683. IN ULONG DesiredShareAccess,
  19684. IN OUT PFILE_OBJECT FileObject,
  19685. OUT PSHARE_ACCESS ShareAccess
  19686. );
  19687. // end_ntddk end_wdm end_nthal end_ntosp
  19688. NTKERNELAPI
  19689. VOID
  19690. IoSetTopLevelIrp(
  19691. IN PIRP Irp
  19692. );
  19693. //++
  19694. //
  19695. // USHORT
  19696. // IoSizeOfIrp(
  19697. // IN CCHAR StackSize
  19698. // )
  19699. //
  19700. // Routine Description:
  19701. //
  19702. // Determines the size of an IRP given the number of stack locations
  19703. // the IRP will have.
  19704. //
  19705. // Arguments:
  19706. //
  19707. // StackSize - Number of stack locations for the IRP.
  19708. //
  19709. // Return Value:
  19710. //
  19711. // Size in bytes of the IRP.
  19712. //
  19713. //--
  19714. #define IoSizeOfIrp( StackSize ) \
  19715. ((USHORT) (sizeof( IRP ) + ((StackSize) * (sizeof( IO_STACK_LOCATION )))))
  19716. NTKERNELAPI
  19717. VOID
  19718. IoStartTimer(
  19719. IN PDEVICE_OBJECT DeviceObject
  19720. );
  19721. NTKERNELAPI
  19722. VOID
  19723. IoStopTimer(
  19724. IN PDEVICE_OBJECT DeviceObject
  19725. );
  19726. // end_ntddk end_wdm end_nthal end_ntosp
  19727. NTKERNELAPI
  19728. NTSTATUS
  19729. IoSynchronousPageWrite(
  19730. IN PFILE_OBJECT FileObject,
  19731. IN PMDL MemoryDescriptorList,
  19732. IN PLARGE_INTEGER StartingOffset,
  19733. IN PKEVENT Event,
  19734. OUT PIO_STATUS_BLOCK IoStatusBlock
  19735. );
  19736. // begin_ntosp
  19737. NTKERNELAPI
  19738. PEPROCESS
  19739. IoThreadToProcess(
  19740. IN PETHREAD Thread
  19741. );
  19742. // end_ntosp
  19743. NTKERNELAPI
  19744. VOID
  19745. IoUnregisterFileSystem(
  19746. IN OUT PDEVICE_OBJECT DeviceObject
  19747. );
  19748. NTKERNELAPI
  19749. VOID
  19750. IoUnregisterFsRegistrationChange(
  19751. IN PDRIVER_OBJECT DriverObject,
  19752. IN PDRIVER_FS_NOTIFICATION DriverNotificationRoutine
  19753. );
  19754. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  19755. NTKERNELAPI
  19756. VOID
  19757. IoUnregisterShutdownNotification(
  19758. IN PDEVICE_OBJECT DeviceObject
  19759. );
  19760. // end_wdm
  19761. NTKERNELAPI
  19762. VOID
  19763. IoUpdateShareAccess(
  19764. IN PFILE_OBJECT FileObject,
  19765. IN OUT PSHARE_ACCESS ShareAccess
  19766. );
  19767. // end_ntddk end_nthal
  19768. NTKERNELAPI
  19769. NTSTATUS
  19770. IoVerifyVolume(
  19771. IN PDEVICE_OBJECT DeviceObject,
  19772. IN BOOLEAN AllowRawMount
  19773. );
  19774. NTKERNELAPI // ntddk wdm nthal
  19775. VOID // ntddk wdm nthal
  19776. IoWriteErrorLogEntry( // ntddk wdm nthal
  19777. IN PVOID ElEntry // ntddk wdm nthal
  19778. ); // ntddk wdm nthal
  19779. typedef struct _IO_WORKITEM *PIO_WORKITEM;
  19780. typedef
  19781. VOID
  19782. (*PIO_WORKITEM_ROUTINE) (
  19783. IN PDEVICE_OBJECT DeviceObject,
  19784. IN PVOID Context
  19785. );
  19786. PIO_WORKITEM
  19787. IoAllocateWorkItem(
  19788. PDEVICE_OBJECT DeviceObject
  19789. );
  19790. VOID
  19791. IoFreeWorkItem(
  19792. PIO_WORKITEM IoWorkItem
  19793. );
  19794. VOID
  19795. IoQueueWorkItem(
  19796. IN PIO_WORKITEM IoWorkItem,
  19797. IN PIO_WORKITEM_ROUTINE WorkerRoutine,
  19798. IN WORK_QUEUE_TYPE QueueType,
  19799. IN PVOID Context
  19800. );
  19801. NTKERNELAPI
  19802. NTSTATUS
  19803. IoWMIRegistrationControl(
  19804. IN PDEVICE_OBJECT DeviceObject,
  19805. IN ULONG Action
  19806. );
  19807. //
  19808. // Action code for IoWMIRegistrationControl api
  19809. //
  19810. #define WMIREG_ACTION_REGISTER 1
  19811. #define WMIREG_ACTION_DEREGISTER 2
  19812. #define WMIREG_ACTION_REREGISTER 3
  19813. #define WMIREG_ACTION_UPDATE_GUIDS 4
  19814. #define WMIREG_ACTION_BLOCK_IRPS 5
  19815. //
  19816. // Code passed in IRP_MN_REGINFO WMI irp
  19817. //
  19818. #define WMIREGISTER 0
  19819. #define WMIUPDATE 1
  19820. NTKERNELAPI
  19821. NTSTATUS
  19822. IoWMIAllocateInstanceIds(
  19823. IN GUID *Guid,
  19824. IN ULONG InstanceCount,
  19825. OUT ULONG *FirstInstanceId
  19826. );
  19827. NTKERNELAPI
  19828. NTSTATUS
  19829. IoWMISuggestInstanceName(
  19830. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  19831. IN PUNICODE_STRING SymbolicLinkName OPTIONAL,
  19832. IN BOOLEAN CombineNames,
  19833. OUT PUNICODE_STRING SuggestedInstanceName
  19834. );
  19835. NTKERNELAPI
  19836. NTSTATUS
  19837. IoWMIWriteEvent(
  19838. IN PVOID WnodeEventItem
  19839. );
  19840. #if defined(_WIN64)
  19841. NTKERNELAPI
  19842. ULONG IoWMIDeviceObjectToProviderId(
  19843. PDEVICE_OBJECT DeviceObject
  19844. );
  19845. #else
  19846. #define IoWMIDeviceObjectToProviderId(DeviceObject) ((ULONG)(DeviceObject))
  19847. #endif
  19848. NTKERNELAPI
  19849. NTSTATUS IoWMIOpenBlock(
  19850. IN GUID *DataBlockGuid,
  19851. IN ULONG DesiredAccess,
  19852. OUT PVOID *DataBlockObject
  19853. );
  19854. NTKERNELAPI
  19855. NTSTATUS IoWMIQueryAllData(
  19856. IN PVOID DataBlockObject,
  19857. IN OUT ULONG *InOutBufferSize,
  19858. OUT /* non paged */ PVOID OutBuffer
  19859. );
  19860. NTKERNELAPI
  19861. NTSTATUS
  19862. IoWMIQueryAllDataMultiple(
  19863. IN PVOID *DataBlockObjectList,
  19864. IN ULONG ObjectCount,
  19865. IN OUT ULONG *InOutBufferSize,
  19866. OUT /* non paged */ PVOID OutBuffer
  19867. );
  19868. NTKERNELAPI
  19869. NTSTATUS
  19870. IoWMIQuerySingleInstance(
  19871. IN PVOID DataBlockObject,
  19872. IN PUNICODE_STRING InstanceName,
  19873. IN OUT ULONG *InOutBufferSize,
  19874. OUT /* non paged */ PVOID OutBuffer
  19875. );
  19876. NTKERNELAPI
  19877. NTSTATUS
  19878. IoWMIQuerySingleInstanceMultiple(
  19879. IN PVOID *DataBlockObjectList,
  19880. IN PUNICODE_STRING InstanceNames,
  19881. IN ULONG ObjectCount,
  19882. IN OUT ULONG *InOutBufferSize,
  19883. OUT /* non paged */ PVOID OutBuffer
  19884. );
  19885. NTKERNELAPI
  19886. NTSTATUS
  19887. IoWMISetSingleInstance(
  19888. IN PVOID DataBlockObject,
  19889. IN PUNICODE_STRING InstanceName,
  19890. IN ULONG Version,
  19891. IN ULONG ValueBufferSize,
  19892. IN PVOID ValueBuffer
  19893. );
  19894. NTKERNELAPI
  19895. NTSTATUS
  19896. IoWMISetSingleItem(
  19897. IN PVOID DataBlockObject,
  19898. IN PUNICODE_STRING InstanceName,
  19899. IN ULONG DataItemId,
  19900. IN ULONG Version,
  19901. IN ULONG ValueBufferSize,
  19902. IN PVOID ValueBuffer
  19903. );
  19904. NTKERNELAPI
  19905. NTSTATUS
  19906. IoWMIExecuteMethod(
  19907. IN PVOID DataBlockObject,
  19908. IN PUNICODE_STRING InstanceName,
  19909. IN ULONG MethodId,
  19910. IN ULONG InBufferSize,
  19911. IN OUT PULONG OutBufferSize,
  19912. IN OUT PUCHAR InOutBuffer
  19913. );
  19914. typedef VOID (*WMI_NOTIFICATION_CALLBACK)(
  19915. PVOID Wnode,
  19916. PVOID Context
  19917. );
  19918. NTKERNELAPI
  19919. NTSTATUS
  19920. IoWMISetNotificationCallback(
  19921. IN PVOID Object,
  19922. IN WMI_NOTIFICATION_CALLBACK Callback,
  19923. IN PVOID Context
  19924. );
  19925. NTKERNELAPI
  19926. NTSTATUS
  19927. IoWMIHandleToInstanceName(
  19928. IN PVOID DataBlockObject,
  19929. IN HANDLE FileHandle,
  19930. OUT PUNICODE_STRING InstanceName
  19931. );
  19932. NTKERNELAPI
  19933. NTSTATUS
  19934. IoWMIDeviceObjectToInstanceName(
  19935. IN PVOID DataBlockObject,
  19936. IN PDEVICE_OBJECT DeviceObject,
  19937. OUT PUNICODE_STRING InstanceName
  19938. );
  19939. #if defined(_WIN64)
  19940. BOOLEAN
  19941. IoIs32bitProcess(
  19942. IN PIRP Irp
  19943. );
  19944. #endif
  19945. NTSTATUS
  19946. IoVolumeDeviceToDosName(
  19947. IN PVOID VolumeDeviceObject,
  19948. OUT PUNICODE_STRING DosName
  19949. );
  19950. NTSTATUS
  19951. IoEnumerateDeviceObjectList(
  19952. IN PDRIVER_OBJECT DriverObject,
  19953. IN PDEVICE_OBJECT *DeviceObjectList,
  19954. IN ULONG DeviceObjectListSize,
  19955. OUT PULONG ActualNumberDeviceObjects
  19956. );
  19957. PDEVICE_OBJECT
  19958. IoGetLowerDeviceObject(
  19959. IN PDEVICE_OBJECT DeviceObject
  19960. );
  19961. PDEVICE_OBJECT
  19962. IoGetDeviceAttachmentBaseRef(
  19963. IN PDEVICE_OBJECT DeviceObject
  19964. );
  19965. NTSTATUS
  19966. IoGetDiskDeviceObject(
  19967. IN PDEVICE_OBJECT FileSystemDeviceObject,
  19968. OUT PDEVICE_OBJECT *DiskDeviceObject
  19969. );
  19970. NTSTATUS
  19971. IoSetSystemPartition(
  19972. PUNICODE_STRING VolumeNameString
  19973. );
  19974. // begin_wdm
  19975. VOID
  19976. IoFreeErrorLogEntry(
  19977. PVOID ElEntry
  19978. );
  19979. // Cancel SAFE API set start
  19980. //
  19981. // The following APIs are to help ease the pain of writing queue packages that
  19982. // handle the cancellation race well. The idea of this set of APIs is to not
  19983. // force a single queue data structure but allow the cancel logic to be hidden
  19984. // from the drivers. A driver implements a queue and as part of its header
  19985. // includes the IO_CSQ structure. In its initialization routine it calls
  19986. // IoInitializeCsq. Then in the dispatch routine when the driver wants to
  19987. // insert an IRP into the queue it calls IoCsqInsertIrp. When the driver wants
  19988. // to remove something from the queue it calls IoCsqRemoveIrp. Note that Insert
  19989. // can fail if the IRP was cancelled in the meantime. Remove can also fail if
  19990. // the IRP was already cancelled.
  19991. //
  19992. // There are typically two modes where drivers queue IRPs. These two modes are
  19993. // covered by the cancel safe queue API set.
  19994. //
  19995. // Mode 1:
  19996. // One is where the driver queues the IRP and at some later
  19997. // point in time dequeues an IRP and issues the IO request.
  19998. // For this mode the driver should use IoCsqInsertIrp and IoCsqRemoveNextIrp.
  19999. // The driver in this case is expected to pass NULL to the irp context
  20000. // parameter in IoInsertIrp.
  20001. //
  20002. // Mode 2:
  20003. // In this the driver queues theIRP, issues the IO request (like issuing a DMA
  20004. // request or writing to a register) and when the IO request completes (either
  20005. // using a DPC or timer) the driver dequeues the IRP and completes it. For this
  20006. // mode the driver should use IoCsqInsertIrp and IoCsqRemoveIrp. In this case
  20007. // the driver should allocate an IRP context and pass it in to IoCsqInsertIrp.
  20008. // The cancel API code creates an association between the IRP and the context
  20009. // and thus ensures that when the time comes to remove the IRP it can ascertain
  20010. // correctly.
  20011. //
  20012. // Note that the cancel API set assumes that the field DriverContext[3] is
  20013. // always available for use and that the driver does not use it.
  20014. //
  20015. //
  20016. // Bookkeeping structure. This should be opaque to drivers.
  20017. // Drivers typically include this as part of their queue headers.
  20018. // Given a CSQ pointer the driver should be able to get its
  20019. // queue header using CONTAINING_RECORD macro
  20020. //
  20021. typedef struct _IO_CSQ IO_CSQ, *PIO_CSQ;
  20022. #define IO_TYPE_CSQ_IRP_CONTEXT 1
  20023. #define IO_TYPE_CSQ 2
  20024. //
  20025. // IRP context structure. This structure is necessary if the driver is using
  20026. // the second mode.
  20027. //
  20028. typedef struct _IO_CSQ_IRP_CONTEXT {
  20029. ULONG Type;
  20030. PIRP Irp;
  20031. PIO_CSQ Csq;
  20032. } IO_CSQ_IRP_CONTEXT, *PIO_CSQ_IRP_CONTEXT;
  20033. //
  20034. // Routines that insert/remove IRP
  20035. //
  20036. typedef VOID
  20037. (*PIO_CSQ_INSERT_IRP)(
  20038. IN struct _IO_CSQ *Csq,
  20039. IN PIRP Irp
  20040. );
  20041. typedef VOID
  20042. (*PIO_CSQ_REMOVE_IRP)(
  20043. IN PIO_CSQ Csq,
  20044. IN PIRP Irp
  20045. );
  20046. //
  20047. // Retrieves next entry after Irp from the queue.
  20048. // Returns NULL if there are no entries in the queue.
  20049. // If Irp is NUL, returns the entry in the head of the queue.
  20050. // This routine does not remove the IRP from the queue.
  20051. //
  20052. typedef PIRP
  20053. (*PIO_CSQ_PEEK_NEXT_IRP)(
  20054. IN PIO_CSQ Csq,
  20055. IN PIRP Irp,
  20056. IN PVOID PeekContext
  20057. );
  20058. //
  20059. // Lock routine that protects the cancel safe queue.
  20060. //
  20061. typedef VOID
  20062. (*PIO_CSQ_ACQUIRE_LOCK)(
  20063. IN PIO_CSQ Csq,
  20064. OUT PKIRQL Irql
  20065. );
  20066. typedef VOID
  20067. (*PIO_CSQ_RELEASE_LOCK)(
  20068. IN PIO_CSQ Csq,
  20069. IN KIRQL Irql
  20070. );
  20071. //
  20072. // Completes the IRP with STATUS_CANCELLED. IRP is guaranteed to be valid
  20073. // In most cases this routine just calls IoCompleteRequest(Irp, STATUS_CANCELLED);
  20074. //
  20075. typedef VOID
  20076. (*PIO_CSQ_COMPLETE_CANCELED_IRP)(
  20077. IN PIO_CSQ Csq,
  20078. IN PIRP Irp
  20079. );
  20080. //
  20081. // Bookkeeping structure. This should be opaque to drivers.
  20082. // Drivers typically include this as part of their queue headers.
  20083. // Given a CSQ pointer the driver should be able to get its
  20084. // queue header using CONTAINING_RECORD macro
  20085. //
  20086. typedef struct _IO_CSQ {
  20087. ULONG Type;
  20088. PIO_CSQ_INSERT_IRP CsqInsertIrp;
  20089. PIO_CSQ_REMOVE_IRP CsqRemoveIrp;
  20090. PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp;
  20091. PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock;
  20092. PIO_CSQ_RELEASE_LOCK CsqReleaseLock;
  20093. PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp;
  20094. PVOID ReservePointer; // Future expansion
  20095. } IO_CSQ, *PIO_CSQ;
  20096. //
  20097. // Initializes the cancel queue structure.
  20098. //
  20099. NTSTATUS
  20100. IoCsqInitialize(
  20101. IN PIO_CSQ Csq,
  20102. IN PIO_CSQ_INSERT_IRP CsqInsertIrp,
  20103. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  20104. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  20105. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  20106. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  20107. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  20108. );
  20109. //
  20110. // The caller calls this routine to insert the IRP and return STATUS_PENDING.
  20111. //
  20112. VOID
  20113. IoCsqInsertIrp(
  20114. IN PIO_CSQ Csq,
  20115. IN PIRP Irp,
  20116. IN PIO_CSQ_IRP_CONTEXT Context
  20117. );
  20118. //
  20119. // Returns an IRP if one can be found. NULL otherwise.
  20120. //
  20121. PIRP
  20122. IoCsqRemoveNextIrp(
  20123. IN PIO_CSQ Csq,
  20124. IN PVOID PeekContext
  20125. );
  20126. //
  20127. // This routine is called from timeout or DPCs.
  20128. // The context is presumably part of the DPC or timer context.
  20129. // If succesfull returns the IRP associated with context.
  20130. //
  20131. PIRP
  20132. IoCsqRemoveIrp(
  20133. IN PIO_CSQ Csq,
  20134. IN PIO_CSQ_IRP_CONTEXT Context
  20135. );
  20136. // Cancel SAFE API set end
  20137. NTSTATUS
  20138. IoCreateFileSpecifyDeviceObjectHint(
  20139. OUT PHANDLE FileHandle,
  20140. IN ACCESS_MASK DesiredAccess,
  20141. IN POBJECT_ATTRIBUTES ObjectAttributes,
  20142. OUT PIO_STATUS_BLOCK IoStatusBlock,
  20143. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  20144. IN ULONG FileAttributes,
  20145. IN ULONG ShareAccess,
  20146. IN ULONG Disposition,
  20147. IN ULONG CreateOptions,
  20148. IN PVOID EaBuffer OPTIONAL,
  20149. IN ULONG EaLength,
  20150. IN CREATE_FILE_TYPE CreateFileType,
  20151. IN PVOID ExtraCreateParameters OPTIONAL,
  20152. IN ULONG Options,
  20153. IN PVOID DeviceObject
  20154. );
  20155. NTSTATUS
  20156. IoAttachDeviceToDeviceStackSafe(
  20157. IN PDEVICE_OBJECT SourceDevice,
  20158. IN PDEVICE_OBJECT TargetDevice,
  20159. OUT PDEVICE_OBJECT *AttachedToDeviceObject
  20160. );
  20161. // end_ntosp
  20162. NTKERNELAPI
  20163. BOOLEAN
  20164. IoIsFileOriginRemote(
  20165. IN PFILE_OBJECT FileObject
  20166. );
  20167. NTKERNELAPI
  20168. NTSTATUS
  20169. IoSetFileOrigin(
  20170. IN PFILE_OBJECT FileObject,
  20171. IN BOOLEAN Remote
  20172. );
  20173. NTSTATUS
  20174. IoValidateDeviceIoControlAccess(
  20175. IN PIRP Irp,
  20176. IN ULONG RequiredAccess
  20177. );
  20178. NTKERNELAPI
  20179. PVOID
  20180. PoRegisterSystemState (
  20181. IN PVOID StateHandle,
  20182. IN EXECUTION_STATE Flags
  20183. );
  20184. NTKERNELAPI
  20185. VOID
  20186. PoUnregisterSystemState (
  20187. IN PVOID StateHandle
  20188. );
  20189. // begin_nthal
  20190. NTKERNELAPI
  20191. POWER_STATE
  20192. PoSetPowerState (
  20193. IN PDEVICE_OBJECT DeviceObject,
  20194. IN POWER_STATE_TYPE Type,
  20195. IN POWER_STATE State
  20196. );
  20197. NTKERNELAPI
  20198. NTSTATUS
  20199. PoCallDriver (
  20200. IN PDEVICE_OBJECT DeviceObject,
  20201. IN OUT PIRP Irp
  20202. );
  20203. NTKERNELAPI
  20204. VOID
  20205. PoStartNextPowerIrp(
  20206. IN PIRP Irp
  20207. );
  20208. NTKERNELAPI
  20209. PULONG
  20210. PoRegisterDeviceForIdleDetection (
  20211. IN PDEVICE_OBJECT DeviceObject,
  20212. IN ULONG ConservationIdleTime,
  20213. IN ULONG PerformanceIdleTime,
  20214. IN DEVICE_POWER_STATE State
  20215. );
  20216. #define PoSetDeviceBusy(IdlePointer) \
  20217. *IdlePointer = 0
  20218. //
  20219. // \Callback\PowerState values
  20220. //
  20221. #define PO_CB_SYSTEM_POWER_POLICY 0
  20222. #define PO_CB_AC_STATUS 1
  20223. #define PO_CB_BUTTON_COLLISION 2
  20224. #define PO_CB_SYSTEM_STATE_LOCK 3
  20225. #define PO_CB_LID_SWITCH_STATE 4
  20226. #define PO_CB_PROCESSOR_POWER_POLICY 5
  20227. // end_ntddk end_wdm end_nthal
  20228. // Used for queuing work items to be performed at shutdown time. Same
  20229. // rules apply as per Ex work queues.
  20230. NTKERNELAPI
  20231. NTSTATUS
  20232. PoQueueShutdownWorkItem(
  20233. IN PWORK_QUEUE_ITEM WorkItem
  20234. );
  20235. #if defined(_ALPHA_) || defined(_IA64_)
  20236. DECLSPEC_DEPRECATED_DDK // Use GetDmaRequirement
  20237. NTHALAPI
  20238. ULONG
  20239. HalGetDmaAlignmentRequirement (
  20240. VOID
  20241. );
  20242. #endif
  20243. #if defined(_M_IX86) || defined(_M_AMD64)
  20244. #define HalGetDmaAlignmentRequirement() 1L
  20245. #endif
  20246. NTHALAPI
  20247. VOID
  20248. KeFlushWriteBuffer (
  20249. VOID
  20250. );
  20251. //
  20252. // Performance counter function.
  20253. //
  20254. NTHALAPI
  20255. LARGE_INTEGER
  20256. KeQueryPerformanceCounter (
  20257. OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL
  20258. );
  20259. // begin_ntndis
  20260. //
  20261. // Stall processor execution function.
  20262. //
  20263. NTHALAPI
  20264. VOID
  20265. KeStallExecutionProcessor (
  20266. IN ULONG MicroSeconds
  20267. );
  20268. //
  20269. // Indicates the system may do I/O to physical addresses above 4 GB.
  20270. //
  20271. extern PBOOLEAN Mm64BitPhysicalAddress;
  20272. //
  20273. // Define maximum disk transfer size to be used by MM and Cache Manager,
  20274. // so that packet-oriented disk drivers can optimize their packet allocation
  20275. // to this size.
  20276. //
  20277. #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
  20278. //++
  20279. //
  20280. // ULONG_PTR
  20281. // ROUND_TO_PAGES (
  20282. // IN ULONG_PTR Size
  20283. // )
  20284. //
  20285. // Routine Description:
  20286. //
  20287. // The ROUND_TO_PAGES macro takes a size in bytes and rounds it up to a
  20288. // multiple of the page size.
  20289. //
  20290. // NOTE: This macro fails for values 0xFFFFFFFF - (PAGE_SIZE - 1).
  20291. //
  20292. // Arguments:
  20293. //
  20294. // Size - Size in bytes to round up to a page multiple.
  20295. //
  20296. // Return Value:
  20297. //
  20298. // Returns the size rounded up to a multiple of the page size.
  20299. //
  20300. //--
  20301. #define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  20302. //++
  20303. //
  20304. // ULONG
  20305. // BYTES_TO_PAGES (
  20306. // IN ULONG Size
  20307. // )
  20308. //
  20309. // Routine Description:
  20310. //
  20311. // The BYTES_TO_PAGES macro takes the size in bytes and calculates the
  20312. // number of pages required to contain the bytes.
  20313. //
  20314. // Arguments:
  20315. //
  20316. // Size - Size in bytes.
  20317. //
  20318. // Return Value:
  20319. //
  20320. // Returns the number of pages required to contain the specified size.
  20321. //
  20322. //--
  20323. #define BYTES_TO_PAGES(Size) ((ULONG)((ULONG_PTR)(Size) >> PAGE_SHIFT) + \
  20324. (((ULONG)(Size) & (PAGE_SIZE - 1)) != 0))
  20325. //++
  20326. //
  20327. // ULONG
  20328. // BYTE_OFFSET (
  20329. // IN PVOID Va
  20330. // )
  20331. //
  20332. // Routine Description:
  20333. //
  20334. // The BYTE_OFFSET macro takes a virtual address and returns the byte offset
  20335. // of that address within the page.
  20336. //
  20337. // Arguments:
  20338. //
  20339. // Va - Virtual address.
  20340. //
  20341. // Return Value:
  20342. //
  20343. // Returns the byte offset portion of the virtual address.
  20344. //
  20345. //--
  20346. #define BYTE_OFFSET(Va) ((ULONG)((LONG_PTR)(Va) & (PAGE_SIZE - 1)))
  20347. //++
  20348. //
  20349. // PVOID
  20350. // PAGE_ALIGN (
  20351. // IN PVOID Va
  20352. // )
  20353. //
  20354. // Routine Description:
  20355. //
  20356. // The PAGE_ALIGN macro takes a virtual address and returns a page-aligned
  20357. // virtual address for that page.
  20358. //
  20359. // Arguments:
  20360. //
  20361. // Va - Virtual address.
  20362. //
  20363. // Return Value:
  20364. //
  20365. // Returns the page aligned virtual address.
  20366. //
  20367. //--
  20368. #define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
  20369. //++
  20370. //
  20371. // ULONG
  20372. // ADDRESS_AND_SIZE_TO_SPAN_PAGES (
  20373. // IN PVOID Va,
  20374. // IN ULONG Size
  20375. // )
  20376. //
  20377. // Routine Description:
  20378. //
  20379. // The ADDRESS_AND_SIZE_TO_SPAN_PAGES macro takes a virtual address and
  20380. // size and returns the number of pages spanned by the size.
  20381. //
  20382. // Arguments:
  20383. //
  20384. // Va - Virtual address.
  20385. //
  20386. // Size - Size in bytes.
  20387. //
  20388. // Return Value:
  20389. //
  20390. // Returns the number of pages spanned by the size.
  20391. //
  20392. //--
  20393. #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) \
  20394. ((ULONG)((((ULONG_PTR)(Va) & (PAGE_SIZE -1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  20395. #if PRAGMA_DEPRECATED_DDK
  20396. #pragma deprecated(COMPUTE_PAGES_SPANNED) // Use ADDRESS_AND_SIZE_TO_SPAN_PAGES
  20397. #endif
  20398. #define COMPUTE_PAGES_SPANNED(Va, Size) ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
  20399. //++
  20400. // PPFN_NUMBER
  20401. // MmGetMdlPfnArray (
  20402. // IN PMDL Mdl
  20403. // )
  20404. //
  20405. // Routine Description:
  20406. //
  20407. // The MmGetMdlPfnArray routine returns the virtual address of the
  20408. // first element of the array of physical page numbers associated with
  20409. // the MDL.
  20410. //
  20411. // Arguments:
  20412. //
  20413. // Mdl - Pointer to an MDL.
  20414. //
  20415. // Return Value:
  20416. //
  20417. // Returns the virtual address of the first element of the array of
  20418. // physical page numbers associated with the MDL.
  20419. //
  20420. //--
  20421. #define MmGetMdlPfnArray(Mdl) ((PPFN_NUMBER)(Mdl + 1))
  20422. //++
  20423. //
  20424. // PVOID
  20425. // MmGetMdlVirtualAddress (
  20426. // IN PMDL Mdl
  20427. // )
  20428. //
  20429. // Routine Description:
  20430. //
  20431. // The MmGetMdlVirtualAddress returns the virtual address of the buffer
  20432. // described by the Mdl.
  20433. //
  20434. // Arguments:
  20435. //
  20436. // Mdl - Pointer to an MDL.
  20437. //
  20438. // Return Value:
  20439. //
  20440. // Returns the virtual address of the buffer described by the Mdl
  20441. //
  20442. //--
  20443. #define MmGetMdlVirtualAddress(Mdl) \
  20444. ((PVOID) ((PCHAR) ((Mdl)->StartVa) + (Mdl)->ByteOffset))
  20445. //++
  20446. //
  20447. // ULONG
  20448. // MmGetMdlByteCount (
  20449. // IN PMDL Mdl
  20450. // )
  20451. //
  20452. // Routine Description:
  20453. //
  20454. // The MmGetMdlByteCount returns the length in bytes of the buffer
  20455. // described by the Mdl.
  20456. //
  20457. // Arguments:
  20458. //
  20459. // Mdl - Pointer to an MDL.
  20460. //
  20461. // Return Value:
  20462. //
  20463. // Returns the byte count of the buffer described by the Mdl
  20464. //
  20465. //--
  20466. #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
  20467. //++
  20468. //
  20469. // ULONG
  20470. // MmGetMdlByteOffset (
  20471. // IN PMDL Mdl
  20472. // )
  20473. //
  20474. // Routine Description:
  20475. //
  20476. // The MmGetMdlByteOffset returns the byte offset within the page
  20477. // of the buffer described by the Mdl.
  20478. //
  20479. // Arguments:
  20480. //
  20481. // Mdl - Pointer to an MDL.
  20482. //
  20483. // Return Value:
  20484. //
  20485. // Returns the byte offset within the page of the buffer described by the Mdl
  20486. //
  20487. //--
  20488. #define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset)
  20489. //++
  20490. //
  20491. // PVOID
  20492. // MmGetMdlStartVa (
  20493. // IN PMDL Mdl
  20494. // )
  20495. //
  20496. // Routine Description:
  20497. //
  20498. // The MmGetMdlBaseVa returns the virtual address of the buffer
  20499. // described by the Mdl rounded down to the nearest page.
  20500. //
  20501. // Arguments:
  20502. //
  20503. // Mdl - Pointer to an MDL.
  20504. //
  20505. // Return Value:
  20506. //
  20507. // Returns the returns the starting virtual address of the MDL.
  20508. //
  20509. //
  20510. //--
  20511. #define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
  20512. typedef enum _MM_SYSTEM_SIZE {
  20513. MmSmallSystem,
  20514. MmMediumSystem,
  20515. MmLargeSystem
  20516. } MM_SYSTEMSIZE;
  20517. NTKERNELAPI
  20518. MM_SYSTEMSIZE
  20519. MmQuerySystemSize(
  20520. VOID
  20521. );
  20522. // end_wdm
  20523. NTKERNELAPI
  20524. BOOLEAN
  20525. MmIsThisAnNtAsSystem(
  20526. VOID
  20527. );
  20528. // begin_wdm
  20529. typedef enum _LOCK_OPERATION {
  20530. IoReadAccess,
  20531. IoWriteAccess,
  20532. IoModifyAccess
  20533. } LOCK_OPERATION;
  20534. NTKERNELAPI
  20535. BOOLEAN
  20536. MmIsRecursiveIoFault(
  20537. VOID
  20538. );
  20539. BOOLEAN
  20540. MmForceSectionClosed (
  20541. IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
  20542. IN BOOLEAN DelayClose
  20543. );
  20544. NTSTATUS
  20545. MmIsVerifierEnabled (
  20546. OUT PULONG VerifierFlags
  20547. );
  20548. NTSTATUS
  20549. MmAddVerifierThunks (
  20550. IN PVOID ThunkBuffer,
  20551. IN ULONG ThunkBufferSize
  20552. );
  20553. typedef enum _MMFLUSH_TYPE {
  20554. MmFlushForDelete,
  20555. MmFlushForWrite
  20556. } MMFLUSH_TYPE;
  20557. BOOLEAN
  20558. MmFlushImageSection (
  20559. IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
  20560. IN MMFLUSH_TYPE FlushType
  20561. );
  20562. BOOLEAN
  20563. MmCanFileBeTruncated (
  20564. IN PSECTION_OBJECT_POINTERS SectionPointer,
  20565. IN PLARGE_INTEGER NewFileSize
  20566. );
  20567. BOOLEAN
  20568. MmSetAddressRangeModified (
  20569. IN PVOID Address,
  20570. IN SIZE_T Length
  20571. );
  20572. NTKERNELAPI
  20573. VOID
  20574. MmProbeAndLockProcessPages (
  20575. IN OUT PMDL MemoryDescriptorList,
  20576. IN PEPROCESS Process,
  20577. IN KPROCESSOR_MODE AccessMode,
  20578. IN LOCK_OPERATION Operation
  20579. );
  20580. // begin_nthal
  20581. //
  20582. // I/O support routines.
  20583. //
  20584. NTKERNELAPI
  20585. VOID
  20586. MmProbeAndLockPages (
  20587. IN OUT PMDL MemoryDescriptorList,
  20588. IN KPROCESSOR_MODE AccessMode,
  20589. IN LOCK_OPERATION Operation
  20590. );
  20591. NTKERNELAPI
  20592. VOID
  20593. MmUnlockPages (
  20594. IN PMDL MemoryDescriptorList
  20595. );
  20596. NTKERNELAPI
  20597. VOID
  20598. MmBuildMdlForNonPagedPool (
  20599. IN OUT PMDL MemoryDescriptorList
  20600. );
  20601. NTKERNELAPI
  20602. PVOID
  20603. MmMapLockedPages (
  20604. IN PMDL MemoryDescriptorList,
  20605. IN KPROCESSOR_MODE AccessMode
  20606. );
  20607. NTKERNELAPI
  20608. PVOID
  20609. MmGetSystemRoutineAddress (
  20610. IN PUNICODE_STRING SystemRoutineName
  20611. );
  20612. NTKERNELAPI
  20613. NTSTATUS
  20614. MmAdvanceMdl (
  20615. IN PMDL Mdl,
  20616. IN ULONG NumberOfBytes
  20617. );
  20618. // end_wdm
  20619. NTKERNELAPI
  20620. NTSTATUS
  20621. MmMapUserAddressesToPage (
  20622. IN PVOID BaseAddress,
  20623. IN SIZE_T NumberOfBytes,
  20624. IN PVOID PageAddress
  20625. );
  20626. // begin_wdm
  20627. NTKERNELAPI
  20628. NTSTATUS
  20629. MmProtectMdlSystemAddress (
  20630. IN PMDL MemoryDescriptorList,
  20631. IN ULONG NewProtect
  20632. );
  20633. //
  20634. // _MM_PAGE_PRIORITY_ provides a method for the system to handle requests
  20635. // intelligently in low resource conditions.
  20636. //
  20637. // LowPagePriority should be used when it is acceptable to the driver for the
  20638. // mapping request to fail if the system is low on resources. An example of
  20639. // this could be for a non-critical network connection where the driver can
  20640. // handle the failure case when system resources are close to being depleted.
  20641. //
  20642. // NormalPagePriority should be used when it is acceptable to the driver for the
  20643. // mapping request to fail if the system is very low on resources. An example
  20644. // of this could be for a non-critical local filesystem request.
  20645. //
  20646. // HighPagePriority should be used when it is unacceptable to the driver for the
  20647. // mapping request to fail unless the system is completely out of resources.
  20648. // An example of this would be the paging file path in a driver.
  20649. //
  20650. // begin_ntndis
  20651. typedef enum _MM_PAGE_PRIORITY {
  20652. LowPagePriority,
  20653. NormalPagePriority = 16,
  20654. HighPagePriority = 32
  20655. } MM_PAGE_PRIORITY;
  20656. // end_ntndis
  20657. //
  20658. // Note: This function is not available in WDM 1.0
  20659. //
  20660. NTKERNELAPI
  20661. PVOID
  20662. MmMapLockedPagesSpecifyCache (
  20663. IN PMDL MemoryDescriptorList,
  20664. IN KPROCESSOR_MODE AccessMode,
  20665. IN MEMORY_CACHING_TYPE CacheType,
  20666. IN PVOID BaseAddress,
  20667. IN ULONG BugCheckOnFailure,
  20668. IN MM_PAGE_PRIORITY Priority
  20669. );
  20670. NTKERNELAPI
  20671. VOID
  20672. MmUnmapLockedPages (
  20673. IN PVOID BaseAddress,
  20674. IN PMDL MemoryDescriptorList
  20675. );
  20676. PVOID
  20677. MmAllocateMappingAddress (
  20678. IN SIZE_T NumberOfBytes,
  20679. IN ULONG PoolTag
  20680. );
  20681. VOID
  20682. MmFreeMappingAddress (
  20683. IN PVOID BaseAddress,
  20684. IN ULONG PoolTag
  20685. );
  20686. PVOID
  20687. MmMapLockedPagesWithReservedMapping (
  20688. IN PVOID MappingAddress,
  20689. IN ULONG PoolTag,
  20690. IN PMDL MemoryDescriptorList,
  20691. IN MEMORY_CACHING_TYPE CacheType
  20692. );
  20693. VOID
  20694. MmUnmapReservedMapping (
  20695. IN PVOID BaseAddress,
  20696. IN ULONG PoolTag,
  20697. IN PMDL MemoryDescriptorList
  20698. );
  20699. // end_wdm
  20700. typedef struct _PHYSICAL_MEMORY_RANGE {
  20701. PHYSICAL_ADDRESS BaseAddress;
  20702. LARGE_INTEGER NumberOfBytes;
  20703. } PHYSICAL_MEMORY_RANGE, *PPHYSICAL_MEMORY_RANGE;
  20704. NTKERNELAPI
  20705. NTSTATUS
  20706. MmAddPhysicalMemory (
  20707. IN PPHYSICAL_ADDRESS StartAddress,
  20708. IN OUT PLARGE_INTEGER NumberOfBytes
  20709. );
  20710. NTKERNELAPI
  20711. NTSTATUS
  20712. MmAddPhysicalMemoryEx (
  20713. IN PPHYSICAL_ADDRESS StartAddress,
  20714. IN OUT PLARGE_INTEGER NumberOfBytes,
  20715. IN ULONG Flags
  20716. );
  20717. NTKERNELAPI
  20718. NTSTATUS
  20719. MmRemovePhysicalMemory (
  20720. IN PPHYSICAL_ADDRESS StartAddress,
  20721. IN OUT PLARGE_INTEGER NumberOfBytes
  20722. );
  20723. NTKERNELAPI
  20724. NTSTATUS
  20725. MmRemovePhysicalMemoryEx (
  20726. IN PPHYSICAL_ADDRESS StartAddress,
  20727. IN OUT PLARGE_INTEGER NumberOfBytes,
  20728. IN ULONG Flags
  20729. );
  20730. NTKERNELAPI
  20731. PPHYSICAL_MEMORY_RANGE
  20732. MmGetPhysicalMemoryRanges (
  20733. VOID
  20734. );
  20735. NTSTATUS
  20736. MmMarkPhysicalMemoryAsGood (
  20737. IN PPHYSICAL_ADDRESS StartAddress,
  20738. IN OUT PLARGE_INTEGER NumberOfBytes
  20739. );
  20740. NTSTATUS
  20741. MmMarkPhysicalMemoryAsBad (
  20742. IN PPHYSICAL_ADDRESS StartAddress,
  20743. IN OUT PLARGE_INTEGER NumberOfBytes
  20744. );
  20745. // begin_wdm
  20746. NTKERNELAPI
  20747. PMDL
  20748. MmAllocatePagesForMdl (
  20749. IN PHYSICAL_ADDRESS LowAddress,
  20750. IN PHYSICAL_ADDRESS HighAddress,
  20751. IN PHYSICAL_ADDRESS SkipBytes,
  20752. IN SIZE_T TotalBytes
  20753. );
  20754. NTKERNELAPI
  20755. VOID
  20756. MmFreePagesFromMdl (
  20757. IN PMDL MemoryDescriptorList
  20758. );
  20759. NTKERNELAPI
  20760. PVOID
  20761. MmMapIoSpace (
  20762. IN PHYSICAL_ADDRESS PhysicalAddress,
  20763. IN SIZE_T NumberOfBytes,
  20764. IN MEMORY_CACHING_TYPE CacheType
  20765. );
  20766. NTKERNELAPI
  20767. VOID
  20768. MmUnmapIoSpace (
  20769. IN PVOID BaseAddress,
  20770. IN SIZE_T NumberOfBytes
  20771. );
  20772. NTKERNELAPI
  20773. PVOID
  20774. MmMapVideoDisplay (
  20775. IN PHYSICAL_ADDRESS PhysicalAddress,
  20776. IN SIZE_T NumberOfBytes,
  20777. IN MEMORY_CACHING_TYPE CacheType
  20778. );
  20779. NTKERNELAPI
  20780. VOID
  20781. MmUnmapVideoDisplay (
  20782. IN PVOID BaseAddress,
  20783. IN SIZE_T NumberOfBytes
  20784. );
  20785. NTKERNELAPI
  20786. PHYSICAL_ADDRESS
  20787. MmGetPhysicalAddress (
  20788. IN PVOID BaseAddress
  20789. );
  20790. NTKERNELAPI
  20791. PVOID
  20792. MmGetVirtualForPhysical (
  20793. IN PHYSICAL_ADDRESS PhysicalAddress
  20794. );
  20795. NTKERNELAPI
  20796. PVOID
  20797. MmAllocateContiguousMemory (
  20798. IN SIZE_T NumberOfBytes,
  20799. IN PHYSICAL_ADDRESS HighestAcceptableAddress
  20800. );
  20801. NTKERNELAPI
  20802. PVOID
  20803. MmAllocateContiguousMemorySpecifyCache (
  20804. IN SIZE_T NumberOfBytes,
  20805. IN PHYSICAL_ADDRESS LowestAcceptableAddress,
  20806. IN PHYSICAL_ADDRESS HighestAcceptableAddress,
  20807. IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
  20808. IN MEMORY_CACHING_TYPE CacheType
  20809. );
  20810. NTKERNELAPI
  20811. VOID
  20812. MmFreeContiguousMemory (
  20813. IN PVOID BaseAddress
  20814. );
  20815. NTKERNELAPI
  20816. VOID
  20817. MmFreeContiguousMemorySpecifyCache (
  20818. IN PVOID BaseAddress,
  20819. IN SIZE_T NumberOfBytes,
  20820. IN MEMORY_CACHING_TYPE CacheType
  20821. );
  20822. NTKERNELAPI
  20823. PVOID
  20824. MmAllocateNonCachedMemory (
  20825. IN SIZE_T NumberOfBytes
  20826. );
  20827. NTKERNELAPI
  20828. VOID
  20829. MmFreeNonCachedMemory (
  20830. IN PVOID BaseAddress,
  20831. IN SIZE_T NumberOfBytes
  20832. );
  20833. NTKERNELAPI
  20834. BOOLEAN
  20835. MmIsAddressValid (
  20836. IN PVOID VirtualAddress
  20837. );
  20838. DECLSPEC_DEPRECATED_DDK
  20839. NTKERNELAPI
  20840. BOOLEAN
  20841. MmIsNonPagedSystemAddressValid (
  20842. IN PVOID VirtualAddress
  20843. );
  20844. // begin_wdm
  20845. NTKERNELAPI
  20846. SIZE_T
  20847. MmSizeOfMdl(
  20848. IN PVOID Base,
  20849. IN SIZE_T Length
  20850. );
  20851. DECLSPEC_DEPRECATED_DDK // Use IoCreateMdl
  20852. NTKERNELAPI
  20853. PMDL
  20854. MmCreateMdl(
  20855. IN PMDL MemoryDescriptorList OPTIONAL,
  20856. IN PVOID Base,
  20857. IN SIZE_T Length
  20858. );
  20859. NTKERNELAPI
  20860. PVOID
  20861. MmLockPagableDataSection(
  20862. IN PVOID AddressWithinSection
  20863. );
  20864. // end_wdm
  20865. NTKERNELAPI
  20866. VOID
  20867. MmLockPagableSectionByHandle (
  20868. IN PVOID ImageSectionHandle
  20869. );
  20870. NTKERNELAPI
  20871. VOID
  20872. MmResetDriverPaging (
  20873. IN PVOID AddressWithinSection
  20874. );
  20875. NTKERNELAPI
  20876. PVOID
  20877. MmPageEntireDriver (
  20878. IN PVOID AddressWithinSection
  20879. );
  20880. NTKERNELAPI
  20881. VOID
  20882. MmUnlockPagableImageSection(
  20883. IN PVOID ImageSectionHandle
  20884. );
  20885. // end_wdm end_ntosp
  20886. // begin_ntosp
  20887. NTKERNELAPI
  20888. HANDLE
  20889. MmSecureVirtualMemory (
  20890. IN PVOID Address,
  20891. IN SIZE_T Size,
  20892. IN ULONG ProbeMode
  20893. );
  20894. NTKERNELAPI
  20895. VOID
  20896. MmUnsecureVirtualMemory (
  20897. IN HANDLE SecureHandle
  20898. );
  20899. // end_ntosp
  20900. NTKERNELAPI
  20901. NTSTATUS
  20902. MmMapViewInSystemSpace (
  20903. IN PVOID Section,
  20904. OUT PVOID *MappedBase,
  20905. IN PSIZE_T ViewSize
  20906. );
  20907. NTKERNELAPI
  20908. NTSTATUS
  20909. MmUnmapViewInSystemSpace (
  20910. IN PVOID MappedBase
  20911. );
  20912. // begin_ntosp
  20913. NTKERNELAPI
  20914. NTSTATUS
  20915. MmMapViewInSessionSpace (
  20916. IN PVOID Section,
  20917. OUT PVOID *MappedBase,
  20918. IN OUT PSIZE_T ViewSize
  20919. );
  20920. NTKERNELAPI
  20921. NTSTATUS
  20922. MmUnmapViewInSessionSpace (
  20923. IN PVOID MappedBase
  20924. );
  20925. // end_ntosp
  20926. // begin_wdm begin_ntosp
  20927. //++
  20928. //
  20929. // VOID
  20930. // MmInitializeMdl (
  20931. // IN PMDL MemoryDescriptorList,
  20932. // IN PVOID BaseVa,
  20933. // IN SIZE_T Length
  20934. // )
  20935. //
  20936. // Routine Description:
  20937. //
  20938. // This routine initializes the header of a Memory Descriptor List (MDL).
  20939. //
  20940. // Arguments:
  20941. //
  20942. // MemoryDescriptorList - Pointer to the MDL to initialize.
  20943. //
  20944. // BaseVa - Base virtual address mapped by the MDL.
  20945. //
  20946. // Length - Length, in bytes, of the buffer mapped by the MDL.
  20947. //
  20948. // Return Value:
  20949. //
  20950. // None.
  20951. //
  20952. //--
  20953. #define MmInitializeMdl(MemoryDescriptorList, BaseVa, Length) { \
  20954. (MemoryDescriptorList)->Next = (PMDL) NULL; \
  20955. (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
  20956. (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa), (Length)))); \
  20957. (MemoryDescriptorList)->MdlFlags = 0; \
  20958. (MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN((BaseVa)); \
  20959. (MemoryDescriptorList)->ByteOffset = BYTE_OFFSET((BaseVa)); \
  20960. (MemoryDescriptorList)->ByteCount = (ULONG)(Length); \
  20961. }
  20962. //++
  20963. //
  20964. // PVOID
  20965. // MmGetSystemAddressForMdlSafe (
  20966. // IN PMDL MDL,
  20967. // IN MM_PAGE_PRIORITY PRIORITY
  20968. // )
  20969. //
  20970. // Routine Description:
  20971. //
  20972. // This routine returns the mapped address of an MDL. If the
  20973. // Mdl is not already mapped or a system address, it is mapped.
  20974. //
  20975. // Arguments:
  20976. //
  20977. // MemoryDescriptorList - Pointer to the MDL to map.
  20978. //
  20979. // Priority - Supplies an indication as to how important it is that this
  20980. // request succeed under low available PTE conditions.
  20981. //
  20982. // Return Value:
  20983. //
  20984. // Returns the base address where the pages are mapped. The base address
  20985. // has the same offset as the virtual address in the MDL.
  20986. //
  20987. // Unlike MmGetSystemAddressForMdl, Safe guarantees that it will always
  20988. // return NULL on failure instead of bugchecking the system.
  20989. //
  20990. // This macro is not usable by WDM 1.0 drivers as 1.0 did not include
  20991. // MmMapLockedPagesSpecifyCache. The solution for WDM 1.0 drivers is to
  20992. // provide synchronization and set/reset the MDL_MAPPING_CAN_FAIL bit.
  20993. //
  20994. //--
  20995. #define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \
  20996. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  20997. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  20998. ((MDL)->MappedSystemVa) : \
  20999. (MmMapLockedPagesSpecifyCache((MDL), \
  21000. KernelMode, \
  21001. MmCached, \
  21002. NULL, \
  21003. FALSE, \
  21004. (PRIORITY))))
  21005. //++
  21006. //
  21007. // PVOID
  21008. // MmGetSystemAddressForMdl (
  21009. // IN PMDL MDL
  21010. // )
  21011. //
  21012. // Routine Description:
  21013. //
  21014. // This routine returns the mapped address of an MDL, if the
  21015. // Mdl is not already mapped or a system address, it is mapped.
  21016. //
  21017. // Arguments:
  21018. //
  21019. // MemoryDescriptorList - Pointer to the MDL to map.
  21020. //
  21021. // Return Value:
  21022. //
  21023. // Returns the base address where the pages are mapped. The base address
  21024. // has the same offset as the virtual address in the MDL.
  21025. //
  21026. //--
  21027. //#define MmGetSystemAddressForMdl(MDL)
  21028. // (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA)) ?
  21029. // ((MDL)->MappedSystemVa) :
  21030. // ((((MDL)->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL)) ?
  21031. // ((PVOID)((ULONG)(MDL)->StartVa | (MDL)->ByteOffset)) :
  21032. // (MmMapLockedPages((MDL),KernelMode)))))
  21033. #if PRAGMA_DEPRECATED_DDK
  21034. #pragma deprecated(MmGetSystemAddressForMdl) // Use MmGetSystemAddressForMdlSafe
  21035. #endif
  21036. #define MmGetSystemAddressForMdl(MDL) \
  21037. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  21038. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  21039. ((MDL)->MappedSystemVa) : \
  21040. (MmMapLockedPages((MDL),KernelMode)))
  21041. //++
  21042. //
  21043. // VOID
  21044. // MmPrepareMdlForReuse (
  21045. // IN PMDL MDL
  21046. // )
  21047. //
  21048. // Routine Description:
  21049. //
  21050. // This routine will take all of the steps necessary to allow an MDL to be
  21051. // re-used.
  21052. //
  21053. // Arguments:
  21054. //
  21055. // MemoryDescriptorList - Pointer to the MDL that will be re-used.
  21056. //
  21057. // Return Value:
  21058. //
  21059. // None.
  21060. //
  21061. //--
  21062. #define MmPrepareMdlForReuse(MDL) \
  21063. if (((MDL)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
  21064. ASSERT(((MDL)->MdlFlags & MDL_PARTIAL) != 0); \
  21065. MmUnmapLockedPages( (MDL)->MappedSystemVa, (MDL) ); \
  21066. } else if (((MDL)->MdlFlags & MDL_PARTIAL) == 0) { \
  21067. ASSERT(((MDL)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
  21068. }
  21069. typedef NTSTATUS (*PMM_DLL_INITIALIZE)(
  21070. IN PUNICODE_STRING RegistryPath
  21071. );
  21072. typedef NTSTATUS (*PMM_DLL_UNLOAD)(
  21073. VOID
  21074. );
  21075. //
  21076. // Prefetch public interface.
  21077. //
  21078. typedef struct _READ_LIST {
  21079. PFILE_OBJECT FileObject;
  21080. ULONG NumberOfEntries;
  21081. LOGICAL IsImage;
  21082. FILE_SEGMENT_ELEMENT List[ANYSIZE_ARRAY];
  21083. } READ_LIST, *PREAD_LIST;
  21084. NTSTATUS
  21085. MmPrefetchPages (
  21086. IN ULONG NumberOfLists,
  21087. IN PREAD_LIST *ReadLists
  21088. );
  21089. //
  21090. // Object Manager types
  21091. //
  21092. typedef struct _OBJECT_HANDLE_INFORMATION {
  21093. ULONG HandleAttributes;
  21094. ACCESS_MASK GrantedAccess;
  21095. } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
  21096. NTKERNELAPI
  21097. NTSTATUS
  21098. ObReferenceObjectByHandle(
  21099. IN HANDLE Handle,
  21100. IN ACCESS_MASK DesiredAccess,
  21101. IN POBJECT_TYPE ObjectType OPTIONAL,
  21102. IN KPROCESSOR_MODE AccessMode,
  21103. OUT PVOID *Object,
  21104. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL
  21105. );
  21106. NTKERNELAPI
  21107. NTSTATUS
  21108. ObOpenObjectByPointer(
  21109. IN PVOID Object,
  21110. IN ULONG HandleAttributes,
  21111. IN PACCESS_STATE PassedAccessState OPTIONAL,
  21112. IN ACCESS_MASK DesiredAccess OPTIONAL,
  21113. IN POBJECT_TYPE ObjectType OPTIONAL,
  21114. IN KPROCESSOR_MODE AccessMode,
  21115. OUT PHANDLE Handle
  21116. );
  21117. NTKERNELAPI
  21118. VOID
  21119. ObMakeTemporaryObject(
  21120. IN PVOID Object
  21121. );
  21122. #define ObDereferenceObject(a) \
  21123. ObfDereferenceObject(a)
  21124. #define ObReferenceObject(Object) ObfReferenceObject(Object)
  21125. NTKERNELAPI
  21126. LONG
  21127. FASTCALL
  21128. ObfReferenceObject(
  21129. IN PVOID Object
  21130. );
  21131. NTKERNELAPI
  21132. NTSTATUS
  21133. ObReferenceObjectByPointer(
  21134. IN PVOID Object,
  21135. IN ACCESS_MASK DesiredAccess,
  21136. IN POBJECT_TYPE ObjectType,
  21137. IN KPROCESSOR_MODE AccessMode
  21138. );
  21139. NTKERNELAPI
  21140. LONG
  21141. FASTCALL
  21142. ObfDereferenceObject(
  21143. IN PVOID Object
  21144. );
  21145. NTKERNELAPI
  21146. NTSTATUS
  21147. ObQueryNameString(
  21148. IN PVOID Object,
  21149. OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
  21150. IN ULONG Length,
  21151. OUT PULONG ReturnLength
  21152. );
  21153. NTSTATUS
  21154. ObGetObjectSecurity(
  21155. IN PVOID Object,
  21156. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
  21157. OUT PBOOLEAN MemoryAllocated
  21158. );
  21159. VOID
  21160. ObReleaseObjectSecurity(
  21161. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  21162. IN BOOLEAN MemoryAllocated
  21163. );
  21164. NTSTATUS
  21165. ObQueryObjectAuditingByHandle(
  21166. IN HANDLE Handle,
  21167. OUT PBOOLEAN GenerateOnClose
  21168. );
  21169. //
  21170. // The following are globally used definitions for an LBN and a VBN
  21171. //
  21172. typedef ULONG LBN;
  21173. typedef LBN *PLBN;
  21174. typedef ULONG VBN;
  21175. typedef VBN *PVBN;
  21176. //
  21177. // Every file system that uses the cache manager must have FsContext
  21178. // of the file object point to a common fcb header structure.
  21179. //
  21180. typedef enum _FAST_IO_POSSIBLE {
  21181. FastIoIsNotPossible = 0,
  21182. FastIoIsPossible,
  21183. FastIoIsQuestionable
  21184. } FAST_IO_POSSIBLE;
  21185. typedef struct _FSRTL_COMMON_FCB_HEADER {
  21186. CSHORT NodeTypeCode;
  21187. CSHORT NodeByteSize;
  21188. //
  21189. // General flags available to FsRtl.
  21190. //
  21191. UCHAR Flags;
  21192. //
  21193. // Indicates if fast I/O is possible or if we should be calling
  21194. // the check for fast I/O routine which is found via the driver
  21195. // object.
  21196. //
  21197. UCHAR IsFastIoPossible; // really type FAST_IO_POSSIBLE
  21198. //
  21199. // Second Flags Field
  21200. //
  21201. UCHAR Flags2;
  21202. //
  21203. // The following reserved field should always be 0
  21204. //
  21205. UCHAR Reserved;
  21206. PERESOURCE Resource;
  21207. PERESOURCE PagingIoResource;
  21208. LARGE_INTEGER AllocationSize;
  21209. LARGE_INTEGER FileSize;
  21210. LARGE_INTEGER ValidDataLength;
  21211. } FSRTL_COMMON_FCB_HEADER;
  21212. typedef FSRTL_COMMON_FCB_HEADER *PFSRTL_COMMON_FCB_HEADER;
  21213. //
  21214. // This Fcb header is used for files which support caching
  21215. // of compressed data, and related new support.
  21216. //
  21217. // We start out by prefixing this structure with the normal
  21218. // FsRtl header from above, which we have to do two different
  21219. // ways for c++ or c.
  21220. //
  21221. #ifdef __cplusplus
  21222. typedef struct _FSRTL_ADVANCED_FCB_HEADER:FSRTL_COMMON_FCB_HEADER {
  21223. #else // __cplusplus
  21224. typedef struct _FSRTL_ADVANCED_FCB_HEADER {
  21225. //
  21226. // Put in the standard FsRtl header fields
  21227. //
  21228. FSRTL_COMMON_FCB_HEADER ;
  21229. #endif // __cplusplus
  21230. //
  21231. // The following two fields are supported only if
  21232. // Flags2 contains FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS
  21233. //
  21234. //
  21235. // This is a pointer to a Fast Mutex which may be used to
  21236. // properly synchronize access to the FsRtl header. The
  21237. // Fast Mutex must be nonpaged.
  21238. //
  21239. PFAST_MUTEX FastMutex;
  21240. //
  21241. // This is a pointer to a list of context structures belonging to
  21242. // filesystem filter drivers that are linked above the filesystem.
  21243. // Each structure is headed by FSRTL_FILTER_CONTEXT.
  21244. //
  21245. LIST_ENTRY FilterContexts;
  21246. } FSRTL_ADVANCED_FCB_HEADER;
  21247. typedef FSRTL_ADVANCED_FCB_HEADER *PFSRTL_ADVANCED_FCB_HEADER;
  21248. //
  21249. // Define FsRtl common header flags
  21250. //
  21251. #define FSRTL_FLAG_FILE_MODIFIED (0x01)
  21252. #define FSRTL_FLAG_FILE_LENGTH_CHANGED (0x02)
  21253. #define FSRTL_FLAG_LIMIT_MODIFIED_PAGES (0x04)
  21254. //
  21255. // Following flags determine how the modified page writer should
  21256. // acquire the file. These flags can't change while either resource
  21257. // is acquired. If neither of these flags is set then the
  21258. // modified/mapped page writer will attempt to acquire the paging io
  21259. // resource shared.
  21260. //
  21261. #define FSRTL_FLAG_ACQUIRE_MAIN_RSRC_EX (0x08)
  21262. #define FSRTL_FLAG_ACQUIRE_MAIN_RSRC_SH (0x10)
  21263. //
  21264. // This flag will be set by the Cache Manager if a view is mapped
  21265. // to a file.
  21266. //
  21267. #define FSRTL_FLAG_USER_MAPPED_FILE (0x20)
  21268. // This flag indicates that the file system is using the
  21269. // FSRTL_ADVANCED_FCB_HEADER structure instead of the FSRTL_COMMON_FCB_HEADER
  21270. // structure.
  21271. //
  21272. #define FSRTL_FLAG_ADVANCED_HEADER (0x40)
  21273. // This flag determines whether there currently is an Eof advance
  21274. // in progress. All such advances must be serialized.
  21275. //
  21276. #define FSRTL_FLAG_EOF_ADVANCE_ACTIVE (0x80)
  21277. //
  21278. // Flag values for Flags2
  21279. //
  21280. // All unused bits are reserved and should NOT be modified.
  21281. //
  21282. //
  21283. // If this flag is set, the Cache Manager will allow modified writing
  21284. // in spite of the value of FsContext2.
  21285. //
  21286. #define FSRTL_FLAG2_DO_MODIFIED_WRITE (0x01)
  21287. //
  21288. // If this flag is set, the additional fields FilterContexts and FastMutex
  21289. // are supported in FSRTL_COMMON_HEADER, and can be used to associate
  21290. // context for filesystem filters with streams.
  21291. //
  21292. #define FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS (0x02)
  21293. //
  21294. // If this flag is set, the cache manager will flush and purge the cache map when
  21295. // a user first maps a file
  21296. //
  21297. #define FSRTL_FLAG2_PURGE_WHEN_MAPPED (0x04)
  21298. //
  21299. // The following constants are used to block top level Irp processing when
  21300. // (in either the fast io or cc case) file system resources have been
  21301. // acquired above the file system, or we are in an Fsp thread.
  21302. //
  21303. #define FSRTL_FSP_TOP_LEVEL_IRP 0x01
  21304. #define FSRTL_CACHE_TOP_LEVEL_IRP 0x02
  21305. #define FSRTL_MOD_WRITE_TOP_LEVEL_IRP 0x03
  21306. #define FSRTL_FAST_IO_TOP_LEVEL_IRP 0x04
  21307. #define FSRTL_MAX_TOP_LEVEL_IRP_FLAG 0x04
  21308. //
  21309. // The following structure is used to synchronize Eof extends.
  21310. //
  21311. typedef struct _EOF_WAIT_BLOCK {
  21312. LIST_ENTRY EofWaitLinks;
  21313. KEVENT Event;
  21314. } EOF_WAIT_BLOCK;
  21315. typedef EOF_WAIT_BLOCK *PEOF_WAIT_BLOCK;
  21316. // begin_ntosp
  21317. //
  21318. // Normal uncompressed Copy and Mdl Apis
  21319. //
  21320. NTKERNELAPI
  21321. BOOLEAN
  21322. FsRtlCopyRead (
  21323. IN PFILE_OBJECT FileObject,
  21324. IN PLARGE_INTEGER FileOffset,
  21325. IN ULONG Length,
  21326. IN BOOLEAN Wait,
  21327. IN ULONG LockKey,
  21328. OUT PVOID Buffer,
  21329. OUT PIO_STATUS_BLOCK IoStatus,
  21330. IN PDEVICE_OBJECT DeviceObject
  21331. );
  21332. NTKERNELAPI
  21333. BOOLEAN
  21334. FsRtlCopyWrite (
  21335. IN PFILE_OBJECT FileObject,
  21336. IN PLARGE_INTEGER FileOffset,
  21337. IN ULONG Length,
  21338. IN BOOLEAN Wait,
  21339. IN ULONG LockKey,
  21340. IN PVOID Buffer,
  21341. OUT PIO_STATUS_BLOCK IoStatus,
  21342. IN PDEVICE_OBJECT DeviceObject
  21343. );
  21344. NTKERNELAPI
  21345. BOOLEAN
  21346. FsRtlMdlReadDev (
  21347. IN PFILE_OBJECT FileObject,
  21348. IN PLARGE_INTEGER FileOffset,
  21349. IN ULONG Length,
  21350. IN ULONG LockKey,
  21351. OUT PMDL *MdlChain,
  21352. OUT PIO_STATUS_BLOCK IoStatus,
  21353. IN PDEVICE_OBJECT DeviceObject
  21354. );
  21355. NTKERNELAPI
  21356. BOOLEAN
  21357. FsRtlMdlReadCompleteDev (
  21358. IN PFILE_OBJECT FileObject,
  21359. IN PMDL MdlChain,
  21360. IN PDEVICE_OBJECT DeviceObject
  21361. );
  21362. NTKERNELAPI
  21363. BOOLEAN
  21364. FsRtlPrepareMdlWriteDev (
  21365. IN PFILE_OBJECT FileObject,
  21366. IN PLARGE_INTEGER FileOffset,
  21367. IN ULONG Length,
  21368. IN ULONG LockKey,
  21369. OUT PMDL *MdlChain,
  21370. OUT PIO_STATUS_BLOCK IoStatus,
  21371. IN PDEVICE_OBJECT DeviceObject
  21372. );
  21373. NTKERNELAPI
  21374. BOOLEAN
  21375. FsRtlMdlWriteCompleteDev (
  21376. IN PFILE_OBJECT FileObject,
  21377. IN PLARGE_INTEGER FileOffset,
  21378. IN PMDL MdlChain,
  21379. IN PDEVICE_OBJECT DeviceObject
  21380. );
  21381. //
  21382. // In Irps, compressed reads and writes are designated by the
  21383. // subfunction IRP_MN_COMPRESSED must be set and the Compressed
  21384. // Data Info buffer must be described by the following structure
  21385. // pointed to by Irp->Tail.Overlay.AuxiliaryBuffer.
  21386. //
  21387. typedef struct _FSRTL_AUXILIARY_BUFFER {
  21388. //
  21389. // Buffer description with length.
  21390. //
  21391. PVOID Buffer;
  21392. ULONG Length;
  21393. //
  21394. // Flags
  21395. //
  21396. ULONG Flags;
  21397. //
  21398. // Pointer to optional Mdl mapping buffer for file system use
  21399. //
  21400. PMDL Mdl;
  21401. } FSRTL_AUXILIARY_BUFFER;
  21402. typedef FSRTL_AUXILIARY_BUFFER *PFSRTL_AUXILIARY_BUFFER;
  21403. //
  21404. // If this flag is set, the auxiliary buffer structure is
  21405. // deallocated on Irp completion. The caller has the
  21406. // option in this case of appending this structure to the
  21407. // structure being described, causing it all to be
  21408. // deallocated at once. If this flag is clear, no deallocate
  21409. // occurs.
  21410. //
  21411. #define FSRTL_AUXILIARY_FLAG_DEALLOCATE 0x00000001
  21412. //
  21413. // The following two routines are called from NtCreateSection to avoid
  21414. // deadlocks with the file systems.
  21415. //
  21416. NTKERNELAPI
  21417. VOID
  21418. FsRtlAcquireFileExclusive (
  21419. IN PFILE_OBJECT FileObject
  21420. );
  21421. NTKERNELAPI
  21422. VOID
  21423. FsRtlReleaseFile (
  21424. IN PFILE_OBJECT FileObject
  21425. );
  21426. //
  21427. // These routines provide a simple interface for the common operations
  21428. // of query/set file size.
  21429. //
  21430. NTSTATUS
  21431. FsRtlGetFileSize(
  21432. IN PFILE_OBJECT FileObject,
  21433. IN OUT PLARGE_INTEGER FileSize
  21434. );
  21435. //
  21436. // Determine if there is a complete device failure on an error.
  21437. //
  21438. NTKERNELAPI
  21439. BOOLEAN
  21440. FsRtlIsTotalDeviceFailure(
  21441. IN NTSTATUS Status
  21442. );
  21443. // end_ntddk
  21444. //
  21445. // Byte range file lock routines, implemented in FileLock.c
  21446. //
  21447. // The file lock info record is used to return enumerated information
  21448. // about a file lock
  21449. //
  21450. typedef struct _FILE_LOCK_INFO {
  21451. //
  21452. // A description of the current locked range, and if the lock
  21453. // is exclusive or shared
  21454. //
  21455. LARGE_INTEGER StartingByte;
  21456. LARGE_INTEGER Length;
  21457. BOOLEAN ExclusiveLock;
  21458. //
  21459. // The following fields describe the owner of the lock.
  21460. //
  21461. ULONG Key;
  21462. PFILE_OBJECT FileObject;
  21463. PVOID ProcessId;
  21464. //
  21465. // The following field is used internally by FsRtl
  21466. //
  21467. LARGE_INTEGER EndingByte;
  21468. } FILE_LOCK_INFO;
  21469. typedef FILE_LOCK_INFO *PFILE_LOCK_INFO;
  21470. //
  21471. // The following two procedure prototypes are used by the caller of the
  21472. // file lock package to supply an alternate routine to call when
  21473. // completing an IRP and when unlocking a byte range. Note that the only
  21474. // utility to us this interface is currently the redirector, all other file
  21475. // system will probably let the IRP complete normally with IoCompleteRequest.
  21476. // The user supplied routine returns any value other than success then the
  21477. // lock package will remove any lock that we just inserted.
  21478. //
  21479. typedef NTSTATUS (*PCOMPLETE_LOCK_IRP_ROUTINE) (
  21480. IN PVOID Context,
  21481. IN PIRP Irp
  21482. );
  21483. typedef VOID (*PUNLOCK_ROUTINE) (
  21484. IN PVOID Context,
  21485. IN PFILE_LOCK_INFO FileLockInfo
  21486. );
  21487. //
  21488. // A FILE_LOCK is an opaque structure but we need to declare the size of
  21489. // it here so that users can allocate space for one.
  21490. //
  21491. typedef struct _FILE_LOCK {
  21492. //
  21493. // The optional procedure to call to complete a request
  21494. //
  21495. PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine;
  21496. //
  21497. // The optional procedure to call when unlocking a byte range
  21498. //
  21499. PUNLOCK_ROUTINE UnlockRoutine;
  21500. //
  21501. // FastIoIsQuestionable is set to true whenever the filesystem require
  21502. // additional checking about whether the fast path can be taken. As an
  21503. // example Ntfs requires checking for disk space before the writes can
  21504. // occur.
  21505. //
  21506. BOOLEAN FastIoIsQuestionable;
  21507. BOOLEAN SpareC[3];
  21508. //
  21509. // FsRtl lock information
  21510. //
  21511. PVOID LockInformation;
  21512. //
  21513. // Contains continuation information for FsRtlGetNextFileLock
  21514. //
  21515. FILE_LOCK_INFO LastReturnedLockInfo;
  21516. PVOID LastReturnedLock;
  21517. } FILE_LOCK;
  21518. typedef FILE_LOCK *PFILE_LOCK;
  21519. PFILE_LOCK
  21520. FsRtlAllocateFileLock (
  21521. IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL,
  21522. IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL
  21523. );
  21524. VOID
  21525. FsRtlFreeFileLock (
  21526. IN PFILE_LOCK FileLock
  21527. );
  21528. NTKERNELAPI
  21529. VOID
  21530. FsRtlInitializeFileLock (
  21531. IN PFILE_LOCK FileLock,
  21532. IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL,
  21533. IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL
  21534. );
  21535. NTKERNELAPI
  21536. VOID
  21537. FsRtlUninitializeFileLock (
  21538. IN PFILE_LOCK FileLock
  21539. );
  21540. NTKERNELAPI
  21541. NTSTATUS
  21542. FsRtlProcessFileLock (
  21543. IN PFILE_LOCK FileLock,
  21544. IN PIRP Irp,
  21545. IN PVOID Context OPTIONAL
  21546. );
  21547. NTKERNELAPI
  21548. BOOLEAN
  21549. FsRtlCheckLockForReadAccess (
  21550. IN PFILE_LOCK FileLock,
  21551. IN PIRP Irp
  21552. );
  21553. NTKERNELAPI
  21554. BOOLEAN
  21555. FsRtlCheckLockForWriteAccess (
  21556. IN PFILE_LOCK FileLock,
  21557. IN PIRP Irp
  21558. );
  21559. NTKERNELAPI
  21560. BOOLEAN
  21561. FsRtlFastCheckLockForRead (
  21562. IN PFILE_LOCK FileLock,
  21563. IN PLARGE_INTEGER StartingByte,
  21564. IN PLARGE_INTEGER Length,
  21565. IN ULONG Key,
  21566. IN PFILE_OBJECT FileObject,
  21567. IN PVOID ProcessId
  21568. );
  21569. NTKERNELAPI
  21570. BOOLEAN
  21571. FsRtlFastCheckLockForWrite (
  21572. IN PFILE_LOCK FileLock,
  21573. IN PLARGE_INTEGER StartingByte,
  21574. IN PLARGE_INTEGER Length,
  21575. IN ULONG Key,
  21576. IN PVOID FileObject,
  21577. IN PVOID ProcessId
  21578. );
  21579. NTKERNELAPI
  21580. PFILE_LOCK_INFO
  21581. FsRtlGetNextFileLock (
  21582. IN PFILE_LOCK FileLock,
  21583. IN BOOLEAN Restart
  21584. );
  21585. NTKERNELAPI
  21586. NTSTATUS
  21587. FsRtlFastUnlockSingle (
  21588. IN PFILE_LOCK FileLock,
  21589. IN PFILE_OBJECT FileObject,
  21590. IN LARGE_INTEGER UNALIGNED *FileOffset,
  21591. IN PLARGE_INTEGER Length,
  21592. IN PEPROCESS ProcessId,
  21593. IN ULONG Key,
  21594. IN PVOID Context OPTIONAL,
  21595. IN BOOLEAN AlreadySynchronized
  21596. );
  21597. NTKERNELAPI
  21598. NTSTATUS
  21599. FsRtlFastUnlockAll (
  21600. IN PFILE_LOCK FileLock,
  21601. IN PFILE_OBJECT FileObject,
  21602. IN PEPROCESS ProcessId,
  21603. IN PVOID Context OPTIONAL
  21604. );
  21605. NTKERNELAPI
  21606. NTSTATUS
  21607. FsRtlFastUnlockAllByKey (
  21608. IN PFILE_LOCK FileLock,
  21609. IN PFILE_OBJECT FileObject,
  21610. IN PEPROCESS ProcessId,
  21611. IN ULONG Key,
  21612. IN PVOID Context OPTIONAL
  21613. );
  21614. NTKERNELAPI
  21615. BOOLEAN
  21616. FsRtlPrivateLock (
  21617. IN PFILE_LOCK FileLock,
  21618. IN PFILE_OBJECT FileObject,
  21619. IN PLARGE_INTEGER FileOffset,
  21620. IN PLARGE_INTEGER Length,
  21621. IN PEPROCESS ProcessId,
  21622. IN ULONG Key,
  21623. IN BOOLEAN FailImmediately,
  21624. IN BOOLEAN ExclusiveLock,
  21625. OUT PIO_STATUS_BLOCK Iosb,
  21626. IN PIRP Irp,
  21627. IN PVOID Context,
  21628. IN BOOLEAN AlreadySynchronized
  21629. );
  21630. //
  21631. // BOOLEAN
  21632. // FsRtlFastLock (
  21633. // IN PFILE_LOCK FileLock,
  21634. // IN PFILE_OBJECT FileObject,
  21635. // IN PLARGE_INTEGER FileOffset,
  21636. // IN PLARGE_INTEGER Length,
  21637. // IN PEPROCESS ProcessId,
  21638. // IN ULONG Key,
  21639. // IN BOOLEAN FailImmediately,
  21640. // IN BOOLEAN ExclusiveLock,
  21641. // OUT PIO_STATUS_BLOCK Iosb,
  21642. // IN PVOID Context OPTIONAL,
  21643. // IN BOOLEAN AlreadySynchronized
  21644. // );
  21645. //
  21646. #define FsRtlFastLock(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11) ( \
  21647. FsRtlPrivateLock( A1, /* FileLock */ \
  21648. A2, /* FileObject */ \
  21649. A3, /* FileOffset */ \
  21650. A4, /* Length */ \
  21651. A5, /* ProcessId */ \
  21652. A6, /* Key */ \
  21653. A7, /* FailImmediately */ \
  21654. A8, /* ExclusiveLock */ \
  21655. A9, /* Iosb */ \
  21656. NULL, /* Irp */ \
  21657. A10, /* Context */ \
  21658. A11 /* AlreadySynchronized */ ) \
  21659. )
  21660. //
  21661. // BOOLEAN
  21662. // FsRtlAreThereCurrentFileLocks (
  21663. // IN PFILE_LOCK FileLock
  21664. // );
  21665. //
  21666. #define FsRtlAreThereCurrentFileLocks(FL) ( \
  21667. ((FL)->FastIoIsQuestionable))
  21668. //
  21669. // Filesystem property tunneling, implemented in tunnel.c
  21670. //
  21671. //
  21672. // Tunnel cache structure
  21673. //
  21674. typedef struct {
  21675. //
  21676. // Mutex for cache manipulation
  21677. //
  21678. FAST_MUTEX Mutex;
  21679. //
  21680. // Splay Tree of tunneled information keyed by
  21681. // DirKey ## Name
  21682. //
  21683. PRTL_SPLAY_LINKS Cache;
  21684. //
  21685. // Timer queue used to age entries out of the main cache
  21686. //
  21687. LIST_ENTRY TimerQueue;
  21688. //
  21689. // Keep track of the number of entries in the cache to prevent
  21690. // excessive use of memory
  21691. //
  21692. USHORT NumEntries;
  21693. } TUNNEL, *PTUNNEL;
  21694. NTKERNELAPI
  21695. VOID
  21696. FsRtlInitializeTunnelCache (
  21697. IN TUNNEL *Cache);
  21698. NTKERNELAPI
  21699. VOID
  21700. FsRtlAddToTunnelCache (
  21701. IN TUNNEL *Cache,
  21702. IN ULONGLONG DirectoryKey,
  21703. IN UNICODE_STRING *ShortName,
  21704. IN UNICODE_STRING *LongName,
  21705. IN BOOLEAN KeyByShortName,
  21706. IN ULONG DataLength,
  21707. IN VOID *Data);
  21708. NTKERNELAPI
  21709. BOOLEAN
  21710. FsRtlFindInTunnelCache (
  21711. IN TUNNEL *Cache,
  21712. IN ULONGLONG DirectoryKey,
  21713. IN UNICODE_STRING *Name,
  21714. OUT UNICODE_STRING *ShortName,
  21715. OUT UNICODE_STRING *LongName,
  21716. IN OUT ULONG *DataLength,
  21717. OUT VOID *Data);
  21718. NTKERNELAPI
  21719. VOID
  21720. FsRtlDeleteKeyFromTunnelCache (
  21721. IN TUNNEL *Cache,
  21722. IN ULONGLONG DirectoryKey);
  21723. NTKERNELAPI
  21724. VOID
  21725. FsRtlDeleteTunnelCache (
  21726. IN TUNNEL *Cache);
  21727. //
  21728. // Dbcs name support routines, implemented in DbcsName.c
  21729. //
  21730. //
  21731. // The following enumerated type is used to denote the result of name
  21732. // comparisons
  21733. //
  21734. typedef enum _FSRTL_COMPARISON_RESULT {
  21735. LessThan = -1,
  21736. EqualTo = 0,
  21737. GreaterThan = 1
  21738. } FSRTL_COMPARISON_RESULT;
  21739. #ifdef NLS_MB_CODE_PAGE_TAG
  21740. #undef NLS_MB_CODE_PAGE_TAG
  21741. #endif // NLS_MB_CODE_PAGE_TAG
  21742. #define LEGAL_ANSI_CHARACTER_ARRAY (*FsRtlLegalAnsiCharacterArray) // ntosp
  21743. #define NLS_MB_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  21744. #define NLS_OEM_LEAD_BYTE_INFO (*NlsOemLeadByteInfo) // ntosp
  21745. extern UCHAR const* const LEGAL_ANSI_CHARACTER_ARRAY;
  21746. extern PUSHORT NLS_OEM_LEAD_BYTE_INFO; // Lead byte info. for ACP
  21747. //
  21748. // These following bit values are set in the FsRtlLegalDbcsCharacterArray
  21749. //
  21750. #define FSRTL_FAT_LEGAL 0x01
  21751. #define FSRTL_HPFS_LEGAL 0x02
  21752. #define FSRTL_NTFS_LEGAL 0x04
  21753. #define FSRTL_WILD_CHARACTER 0x08
  21754. #define FSRTL_OLE_LEGAL 0x10
  21755. #define FSRTL_NTFS_STREAM_LEGAL (FSRTL_NTFS_LEGAL | FSRTL_OLE_LEGAL)
  21756. //
  21757. // The following macro is used to determine if an Ansi character is wild.
  21758. //
  21759. #define FsRtlIsAnsiCharacterWild(C) ( \
  21760. FsRtlTestAnsiCharacter((C), FALSE, FALSE, FSRTL_WILD_CHARACTER) \
  21761. )
  21762. //
  21763. // The following macro is used to determine if an Ansi character is Fat legal.
  21764. //
  21765. #define FsRtlIsAnsiCharacterLegalFat(C,WILD_OK) ( \
  21766. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_FAT_LEGAL) \
  21767. )
  21768. //
  21769. // The following macro is used to determine if an Ansi character is Hpfs legal.
  21770. //
  21771. #define FsRtlIsAnsiCharacterLegalHpfs(C,WILD_OK) ( \
  21772. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_HPFS_LEGAL) \
  21773. )
  21774. //
  21775. // The following macro is used to determine if an Ansi character is Ntfs legal.
  21776. //
  21777. #define FsRtlIsAnsiCharacterLegalNtfs(C,WILD_OK) ( \
  21778. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_NTFS_LEGAL) \
  21779. )
  21780. //
  21781. // The following macro is used to determine if an Ansi character is
  21782. // legal in an Ntfs stream name
  21783. //
  21784. #define FsRtlIsAnsiCharacterLegalNtfsStream(C,WILD_OK) ( \
  21785. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_NTFS_STREAM_LEGAL) \
  21786. )
  21787. //
  21788. // The following macro is used to determine if an Ansi character is legal,
  21789. // according to the caller's specification.
  21790. //
  21791. #define FsRtlIsAnsiCharacterLegal(C,FLAGS) ( \
  21792. FsRtlTestAnsiCharacter((C), TRUE, FALSE, (FLAGS)) \
  21793. )
  21794. //
  21795. // The following macro is used to test attributes of an Ansi character,
  21796. // according to the caller's specified flags.
  21797. //
  21798. #define FsRtlTestAnsiCharacter(C, DEFAULT_RET, WILD_OK, FLAGS) ( \
  21799. ((SCHAR)(C) < 0) ? DEFAULT_RET : \
  21800. FlagOn( LEGAL_ANSI_CHARACTER_ARRAY[(C)], \
  21801. (FLAGS) | \
  21802. ((WILD_OK) ? FSRTL_WILD_CHARACTER : 0) ) \
  21803. )
  21804. //
  21805. // The following two macros use global data defined in ntos\rtl\nlsdata.c
  21806. //
  21807. // BOOLEAN
  21808. // FsRtlIsLeadDbcsCharacter (
  21809. // IN UCHAR DbcsCharacter
  21810. // );
  21811. //
  21812. // /*++
  21813. //
  21814. // Routine Description:
  21815. //
  21816. // This routine takes the first bytes of a Dbcs character and
  21817. // returns whether it is a lead byte in the system code page.
  21818. //
  21819. // Arguments:
  21820. //
  21821. // DbcsCharacter - Supplies the input character being examined
  21822. //
  21823. // Return Value:
  21824. //
  21825. // BOOLEAN - TRUE if the input character is a dbcs lead and
  21826. // FALSE otherwise
  21827. //
  21828. // --*/
  21829. //
  21830. //
  21831. #define FsRtlIsLeadDbcsCharacter(DBCS_CHAR) ( \
  21832. (BOOLEAN)((UCHAR)(DBCS_CHAR) < 0x80 ? FALSE : \
  21833. (NLS_MB_CODE_PAGE_TAG && \
  21834. (NLS_OEM_LEAD_BYTE_INFO[(UCHAR)(DBCS_CHAR)] != 0))) \
  21835. )
  21836. NTKERNELAPI
  21837. VOID
  21838. FsRtlDissectDbcs (
  21839. IN ANSI_STRING InputName,
  21840. OUT PANSI_STRING FirstPart,
  21841. OUT PANSI_STRING RemainingPart
  21842. );
  21843. NTKERNELAPI
  21844. BOOLEAN
  21845. FsRtlDoesDbcsContainWildCards (
  21846. IN PANSI_STRING Name
  21847. );
  21848. NTKERNELAPI
  21849. BOOLEAN
  21850. FsRtlIsDbcsInExpression (
  21851. IN PANSI_STRING Expression,
  21852. IN PANSI_STRING Name
  21853. );
  21854. NTKERNELAPI
  21855. BOOLEAN
  21856. FsRtlIsFatDbcsLegal (
  21857. IN ANSI_STRING DbcsName,
  21858. IN BOOLEAN WildCardsPermissible,
  21859. IN BOOLEAN PathNamePermissible,
  21860. IN BOOLEAN LeadingBackslashPermissible
  21861. );
  21862. // end_ntosp
  21863. NTKERNELAPI
  21864. BOOLEAN
  21865. FsRtlIsHpfsDbcsLegal (
  21866. IN ANSI_STRING DbcsName,
  21867. IN BOOLEAN WildCardsPermissible,
  21868. IN BOOLEAN PathNamePermissible,
  21869. IN BOOLEAN LeadingBackslashPermissible
  21870. );
  21871. //
  21872. // Exception filter routines, implemented in Filter.c
  21873. //
  21874. NTKERNELAPI
  21875. NTSTATUS
  21876. FsRtlNormalizeNtstatus (
  21877. IN NTSTATUS Exception,
  21878. IN NTSTATUS GenericException
  21879. );
  21880. NTKERNELAPI
  21881. BOOLEAN
  21882. FsRtlIsNtstatusExpected (
  21883. IN NTSTATUS Exception
  21884. );
  21885. //
  21886. // The following procedures are used to allocate executive pool and raise
  21887. // insufficient resource status if pool isn't currently available.
  21888. //
  21889. #define FsRtlAllocatePoolWithTag(PoolType, NumberOfBytes, Tag) \
  21890. ExAllocatePoolWithTag((POOL_TYPE)((PoolType) | POOL_RAISE_IF_ALLOCATION_FAILURE), \
  21891. NumberOfBytes, \
  21892. Tag)
  21893. #define FsRtlAllocatePoolWithQuotaTag(PoolType, NumberOfBytes, Tag) \
  21894. ExAllocatePoolWithQuotaTag((POOL_TYPE)((PoolType) | POOL_RAISE_IF_ALLOCATION_FAILURE), \
  21895. NumberOfBytes, \
  21896. Tag)
  21897. //
  21898. // The following function allocates a resource from the FsRtl pool.
  21899. //
  21900. NTKERNELAPI
  21901. PERESOURCE
  21902. FsRtlAllocateResource (
  21903. );
  21904. //
  21905. // Large Integer Mapped Control Blocks routines, implemented in LargeMcb.c
  21906. //
  21907. // Originally this structure was truly opaque and code outside largemcb was
  21908. // never allowed to examine or alter the structures. However, for performance
  21909. // reasons we want to allow ntfs the ability to quickly truncate down the
  21910. // mcb without the overhead of an actual call to largemcb.c. So to do that we
  21911. // need to export the structure. This structure is not exact. The Mapping field
  21912. // is declared here as a pvoid but largemcb.c it is a pointer to mapping pairs.
  21913. //
  21914. typedef struct _LARGE_MCB {
  21915. PFAST_MUTEX FastMutex;
  21916. ULONG MaximumPairCount;
  21917. ULONG PairCount;
  21918. POOL_TYPE PoolType;
  21919. PVOID Mapping;
  21920. } LARGE_MCB;
  21921. typedef LARGE_MCB *PLARGE_MCB;
  21922. NTKERNELAPI
  21923. VOID
  21924. FsRtlInitializeLargeMcb (
  21925. IN PLARGE_MCB Mcb,
  21926. IN POOL_TYPE PoolType
  21927. );
  21928. NTKERNELAPI
  21929. VOID
  21930. FsRtlUninitializeLargeMcb (
  21931. IN PLARGE_MCB Mcb
  21932. );
  21933. NTKERNELAPI
  21934. VOID
  21935. FsRtlResetLargeMcb (
  21936. IN PLARGE_MCB Mcb,
  21937. IN BOOLEAN SelfSynchronized
  21938. );
  21939. NTKERNELAPI
  21940. VOID
  21941. FsRtlTruncateLargeMcb (
  21942. IN PLARGE_MCB Mcb,
  21943. IN LONGLONG Vbn
  21944. );
  21945. NTKERNELAPI
  21946. BOOLEAN
  21947. FsRtlAddLargeMcbEntry (
  21948. IN PLARGE_MCB Mcb,
  21949. IN LONGLONG Vbn,
  21950. IN LONGLONG Lbn,
  21951. IN LONGLONG SectorCount
  21952. );
  21953. NTKERNELAPI
  21954. VOID
  21955. FsRtlRemoveLargeMcbEntry (
  21956. IN PLARGE_MCB Mcb,
  21957. IN LONGLONG Vbn,
  21958. IN LONGLONG SectorCount
  21959. );
  21960. NTKERNELAPI
  21961. BOOLEAN
  21962. FsRtlLookupLargeMcbEntry (
  21963. IN PLARGE_MCB Mcb,
  21964. IN LONGLONG Vbn,
  21965. OUT PLONGLONG Lbn OPTIONAL,
  21966. OUT PLONGLONG SectorCountFromLbn OPTIONAL,
  21967. OUT PLONGLONG StartingLbn OPTIONAL,
  21968. OUT PLONGLONG SectorCountFromStartingLbn OPTIONAL,
  21969. OUT PULONG Index OPTIONAL
  21970. );
  21971. NTKERNELAPI
  21972. BOOLEAN
  21973. FsRtlLookupLastLargeMcbEntry (
  21974. IN PLARGE_MCB Mcb,
  21975. OUT PLONGLONG Vbn,
  21976. OUT PLONGLONG Lbn
  21977. );
  21978. NTKERNELAPI
  21979. BOOLEAN
  21980. FsRtlLookupLastLargeMcbEntryAndIndex (
  21981. IN PLARGE_MCB OpaqueMcb,
  21982. OUT PLONGLONG LargeVbn,
  21983. OUT PLONGLONG LargeLbn,
  21984. OUT PULONG Index
  21985. );
  21986. NTKERNELAPI
  21987. ULONG
  21988. FsRtlNumberOfRunsInLargeMcb (
  21989. IN PLARGE_MCB Mcb
  21990. );
  21991. NTKERNELAPI
  21992. BOOLEAN
  21993. FsRtlGetNextLargeMcbEntry (
  21994. IN PLARGE_MCB Mcb,
  21995. IN ULONG RunIndex,
  21996. OUT PLONGLONG Vbn,
  21997. OUT PLONGLONG Lbn,
  21998. OUT PLONGLONG SectorCount
  21999. );
  22000. NTKERNELAPI
  22001. BOOLEAN
  22002. FsRtlSplitLargeMcb (
  22003. IN PLARGE_MCB Mcb,
  22004. IN LONGLONG Vbn,
  22005. IN LONGLONG Amount
  22006. );
  22007. //
  22008. // Mapped Control Blocks routines, implemented in Mcb.c
  22009. //
  22010. // An MCB is an opaque structure but we need to declare the size of
  22011. // it here so that users can allocate space for one. Consequently the
  22012. // size computation here must be updated by hand if the MCB changes.
  22013. //
  22014. typedef struct _MCB {
  22015. LARGE_MCB DummyFieldThatSizesThisStructureCorrectly;
  22016. } MCB;
  22017. typedef MCB *PMCB;
  22018. NTKERNELAPI
  22019. VOID
  22020. FsRtlInitializeMcb (
  22021. IN PMCB Mcb,
  22022. IN POOL_TYPE PoolType
  22023. );
  22024. NTKERNELAPI
  22025. VOID
  22026. FsRtlUninitializeMcb (
  22027. IN PMCB Mcb
  22028. );
  22029. NTKERNELAPI
  22030. VOID
  22031. FsRtlTruncateMcb (
  22032. IN PMCB Mcb,
  22033. IN VBN Vbn
  22034. );
  22035. NTKERNELAPI
  22036. BOOLEAN
  22037. FsRtlAddMcbEntry (
  22038. IN PMCB Mcb,
  22039. IN VBN Vbn,
  22040. IN LBN Lbn,
  22041. IN ULONG SectorCount
  22042. );
  22043. NTKERNELAPI
  22044. VOID
  22045. FsRtlRemoveMcbEntry (
  22046. IN PMCB Mcb,
  22047. IN VBN Vbn,
  22048. IN ULONG SectorCount
  22049. );
  22050. NTKERNELAPI
  22051. BOOLEAN
  22052. FsRtlLookupMcbEntry (
  22053. IN PMCB Mcb,
  22054. IN VBN Vbn,
  22055. OUT PLBN Lbn,
  22056. OUT PULONG SectorCount OPTIONAL,
  22057. OUT PULONG Index
  22058. );
  22059. NTKERNELAPI
  22060. BOOLEAN
  22061. FsRtlLookupLastMcbEntry (
  22062. IN PMCB Mcb,
  22063. OUT PVBN Vbn,
  22064. OUT PLBN Lbn
  22065. );
  22066. NTKERNELAPI
  22067. ULONG
  22068. FsRtlNumberOfRunsInMcb (
  22069. IN PMCB Mcb
  22070. );
  22071. NTKERNELAPI
  22072. BOOLEAN
  22073. FsRtlGetNextMcbEntry (
  22074. IN PMCB Mcb,
  22075. IN ULONG RunIndex,
  22076. OUT PVBN Vbn,
  22077. OUT PLBN Lbn,
  22078. OUT PULONG SectorCount
  22079. );
  22080. //
  22081. // Fault Tolerance routines, implemented in FaultTol.c
  22082. //
  22083. // The routines in this package implement routines that help file
  22084. // systems interact with the FT device drivers.
  22085. //
  22086. NTKERNELAPI
  22087. NTSTATUS
  22088. FsRtlBalanceReads (
  22089. IN PDEVICE_OBJECT TargetDevice
  22090. );
  22091. //
  22092. // Oplock routines, implemented in Oplock.c
  22093. //
  22094. // An OPLOCK is an opaque structure, we declare it as a PVOID and
  22095. // allocate the actual memory only when needed.
  22096. //
  22097. typedef PVOID OPLOCK, *POPLOCK;
  22098. typedef
  22099. VOID
  22100. (*POPLOCK_WAIT_COMPLETE_ROUTINE) (
  22101. IN PVOID Context,
  22102. IN PIRP Irp
  22103. );
  22104. typedef
  22105. VOID
  22106. (*POPLOCK_FS_PREPOST_IRP) (
  22107. IN PVOID Context,
  22108. IN PIRP Irp
  22109. );
  22110. NTKERNELAPI
  22111. VOID
  22112. FsRtlInitializeOplock (
  22113. IN OUT POPLOCK Oplock
  22114. );
  22115. NTKERNELAPI
  22116. VOID
  22117. FsRtlUninitializeOplock (
  22118. IN OUT POPLOCK Oplock
  22119. );
  22120. NTKERNELAPI
  22121. NTSTATUS
  22122. FsRtlOplockFsctrl (
  22123. IN POPLOCK Oplock,
  22124. IN PIRP Irp,
  22125. IN ULONG OpenCount
  22126. );
  22127. NTKERNELAPI
  22128. NTSTATUS
  22129. FsRtlCheckOplock (
  22130. IN POPLOCK Oplock,
  22131. IN PIRP Irp,
  22132. IN PVOID Context,
  22133. IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL,
  22134. IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL
  22135. );
  22136. NTKERNELAPI
  22137. BOOLEAN
  22138. FsRtlOplockIsFastIoPossible (
  22139. IN POPLOCK Oplock
  22140. );
  22141. NTKERNELAPI
  22142. BOOLEAN
  22143. FsRtlCurrentBatchOplock (
  22144. IN POPLOCK Oplock
  22145. );
  22146. //
  22147. // Volume lock/unlock notification routines, implemented in PnP.c
  22148. //
  22149. // These routines provide PnP volume lock notification support
  22150. // for all filesystems.
  22151. //
  22152. #define FSRTL_VOLUME_DISMOUNT 1
  22153. #define FSRTL_VOLUME_DISMOUNT_FAILED 2
  22154. #define FSRTL_VOLUME_LOCK 3
  22155. #define FSRTL_VOLUME_LOCK_FAILED 4
  22156. #define FSRTL_VOLUME_UNLOCK 5
  22157. #define FSRTL_VOLUME_MOUNT 6
  22158. NTKERNELAPI
  22159. NTSTATUS
  22160. FsRtlNotifyVolumeEvent (
  22161. IN PFILE_OBJECT FileObject,
  22162. IN ULONG EventCode
  22163. );
  22164. //
  22165. // Notify Change routines, implemented in Notify.c
  22166. //
  22167. // These routines provide Notify Change support for all filesystems.
  22168. // Any of the 'Full' notify routines will support returning the
  22169. // change information into the user's buffer.
  22170. //
  22171. typedef PVOID PNOTIFY_SYNC;
  22172. typedef
  22173. BOOLEAN (*PCHECK_FOR_TRAVERSE_ACCESS) (
  22174. IN PVOID NotifyContext,
  22175. IN PVOID TargetContext,
  22176. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  22177. );
  22178. typedef
  22179. BOOLEAN (*PFILTER_REPORT_CHANGE) (
  22180. IN PVOID NotifyContext,
  22181. IN PVOID FilterContext
  22182. );
  22183. NTKERNELAPI
  22184. VOID
  22185. FsRtlNotifyInitializeSync (
  22186. IN PNOTIFY_SYNC *NotifySync
  22187. );
  22188. NTKERNELAPI
  22189. VOID
  22190. FsRtlNotifyUninitializeSync (
  22191. IN PNOTIFY_SYNC *NotifySync
  22192. );
  22193. NTKERNELAPI
  22194. VOID
  22195. FsRtlNotifyFullChangeDirectory (
  22196. IN PNOTIFY_SYNC NotifySync,
  22197. IN PLIST_ENTRY NotifyList,
  22198. IN PVOID FsContext,
  22199. IN PSTRING FullDirectoryName,
  22200. IN BOOLEAN WatchTree,
  22201. IN BOOLEAN IgnoreBuffer,
  22202. IN ULONG CompletionFilter,
  22203. IN PIRP NotifyIrp,
  22204. IN PCHECK_FOR_TRAVERSE_ACCESS TraverseCallback OPTIONAL,
  22205. IN PSECURITY_SUBJECT_CONTEXT SubjectContext OPTIONAL
  22206. );
  22207. NTKERNELAPI
  22208. VOID
  22209. FsRtlNotifyFilterChangeDirectory (
  22210. IN PNOTIFY_SYNC NotifySync,
  22211. IN PLIST_ENTRY NotifyList,
  22212. IN PVOID FsContext,
  22213. IN PSTRING FullDirectoryName,
  22214. IN BOOLEAN WatchTree,
  22215. IN BOOLEAN IgnoreBuffer,
  22216. IN ULONG CompletionFilter,
  22217. IN PIRP NotifyIrp,
  22218. IN PCHECK_FOR_TRAVERSE_ACCESS TraverseCallback OPTIONAL,
  22219. IN PSECURITY_SUBJECT_CONTEXT SubjectContext OPTIONAL,
  22220. IN PFILTER_REPORT_CHANGE FilterCallback OPTIONAL
  22221. );
  22222. NTKERNELAPI
  22223. VOID
  22224. FsRtlNotifyFilterReportChange (
  22225. IN PNOTIFY_SYNC NotifySync,
  22226. IN PLIST_ENTRY NotifyList,
  22227. IN PSTRING FullTargetName,
  22228. IN USHORT TargetNameOffset,
  22229. IN PSTRING StreamName OPTIONAL,
  22230. IN PSTRING NormalizedParentName OPTIONAL,
  22231. IN ULONG FilterMatch,
  22232. IN ULONG Action,
  22233. IN PVOID TargetContext,
  22234. IN PVOID FilterContext
  22235. );
  22236. NTKERNELAPI
  22237. VOID
  22238. FsRtlNotifyFullReportChange (
  22239. IN PNOTIFY_SYNC NotifySync,
  22240. IN PLIST_ENTRY NotifyList,
  22241. IN PSTRING FullTargetName,
  22242. IN USHORT TargetNameOffset,
  22243. IN PSTRING StreamName OPTIONAL,
  22244. IN PSTRING NormalizedParentName OPTIONAL,
  22245. IN ULONG FilterMatch,
  22246. IN ULONG Action,
  22247. IN PVOID TargetContext
  22248. );
  22249. NTKERNELAPI
  22250. VOID
  22251. FsRtlNotifyCleanup (
  22252. IN PNOTIFY_SYNC NotifySync,
  22253. IN PLIST_ENTRY NotifyList,
  22254. IN PVOID FsContext
  22255. );
  22256. //
  22257. // Unicode Name support routines, implemented in Name.c
  22258. //
  22259. // The routines here are used to manipulate unicode names
  22260. //
  22261. //
  22262. // The following macro is used to determine if a character is wild.
  22263. //
  22264. #define FsRtlIsUnicodeCharacterWild(C) ( \
  22265. (((C) >= 0x40) ? FALSE : FlagOn( LEGAL_ANSI_CHARACTER_ARRAY[(C)], \
  22266. FSRTL_WILD_CHARACTER ) ) \
  22267. )
  22268. NTKERNELAPI
  22269. VOID
  22270. FsRtlDissectName (
  22271. IN UNICODE_STRING Path,
  22272. OUT PUNICODE_STRING FirstName,
  22273. OUT PUNICODE_STRING RemainingName
  22274. );
  22275. NTKERNELAPI
  22276. BOOLEAN
  22277. FsRtlDoesNameContainWildCards (
  22278. IN PUNICODE_STRING Name
  22279. );
  22280. NTKERNELAPI
  22281. BOOLEAN
  22282. FsRtlAreNamesEqual (
  22283. PCUNICODE_STRING ConstantNameA,
  22284. PCUNICODE_STRING ConstantNameB,
  22285. IN BOOLEAN IgnoreCase,
  22286. IN PCWCH UpcaseTable OPTIONAL
  22287. );
  22288. NTKERNELAPI
  22289. BOOLEAN
  22290. FsRtlIsNameInExpression (
  22291. IN PUNICODE_STRING Expression,
  22292. IN PUNICODE_STRING Name,
  22293. IN BOOLEAN IgnoreCase,
  22294. IN PWCH UpcaseTable OPTIONAL
  22295. );
  22296. //
  22297. // Stack Overflow support routine, implemented in StackOvf.c
  22298. //
  22299. typedef
  22300. VOID
  22301. (*PFSRTL_STACK_OVERFLOW_ROUTINE) (
  22302. IN PVOID Context,
  22303. IN PKEVENT Event
  22304. );
  22305. NTKERNELAPI
  22306. VOID
  22307. FsRtlPostStackOverflow (
  22308. IN PVOID Context,
  22309. IN PKEVENT Event,
  22310. IN PFSRTL_STACK_OVERFLOW_ROUTINE StackOverflowRoutine
  22311. );
  22312. NTKERNELAPI
  22313. VOID
  22314. FsRtlPostPagingFileStackOverflow (
  22315. IN PVOID Context,
  22316. IN PKEVENT Event,
  22317. IN PFSRTL_STACK_OVERFLOW_ROUTINE StackOverflowRoutine
  22318. );
  22319. //
  22320. // UNC Provider support
  22321. //
  22322. NTKERNELAPI
  22323. NTSTATUS
  22324. FsRtlRegisterUncProvider(
  22325. IN OUT PHANDLE MupHandle,
  22326. IN PUNICODE_STRING RedirectorDeviceName,
  22327. IN BOOLEAN MailslotsSupported
  22328. );
  22329. NTKERNELAPI
  22330. VOID
  22331. FsRtlDeregisterUncProvider(
  22332. IN HANDLE Handle
  22333. );
  22334. //
  22335. // File System Filter PerStream Context Support
  22336. //
  22337. //
  22338. // Filesystem filter drivers use these APIs to associate context
  22339. // with open streams (for filesystems that support this).
  22340. //
  22341. //
  22342. // OwnerId should uniquely identify a particular filter driver
  22343. // (e.g. the address of the driver's device object).
  22344. // InstanceId can be used to distinguish distinct contexts associated
  22345. // by a filter driver with a single stream (e.g. the address of the
  22346. // PerStream Context structure).
  22347. //
  22348. //
  22349. // This structure needs to be embedded within the users context that
  22350. // they want to associate with a given stream
  22351. //
  22352. typedef struct _FSRTL_PER_STREAM_CONTEXT {
  22353. //
  22354. // This is linked into the StreamContext list inside the
  22355. // FSRTL_ADVANCED_FCB_HEADER structure.
  22356. //
  22357. LIST_ENTRY Links;
  22358. //
  22359. // A Unique ID for this filter (ex: address of Driver Object, Device
  22360. // Object, or Device Extension)
  22361. //
  22362. PVOID OwnerId;
  22363. //
  22364. // An optional ID to differentiate different contexts for the same
  22365. // filter.
  22366. //
  22367. PVOID InstanceId;
  22368. //
  22369. // A callback routine which is called by the underlying file system
  22370. // when the stream is being torn down. When this routine is called
  22371. // the given context has already been removed from the context linked
  22372. // list. The callback routine cannot recursively call down into the
  22373. // filesystem or acquire any of their resources which they might hold
  22374. // when calling the filesystem outside of the callback. This must
  22375. // be defined.
  22376. //
  22377. PFREE_FUNCTION FreeCallback;
  22378. } FSRTL_PER_STREAM_CONTEXT, *PFSRTL_PER_STREAM_CONTEXT;
  22379. //
  22380. // This will initialize the given FSRTL_PER_STREAM_CONTEXT structure. This
  22381. // should be used before calling "FsRtlInsertPerStreamContext".
  22382. //
  22383. #define FsRtlInitPerStreamContext( _fc, _owner, _inst, _cb) \
  22384. ((_fc)->OwnerId = (_owner), \
  22385. (_fc)->InstanceId = (_inst), \
  22386. (_fc)->FreeCallback = (_cb))
  22387. //
  22388. // Given a FileObject this will return the StreamContext pointer that
  22389. // needs to be passed into the other FsRtl PerStream Context routines.
  22390. //
  22391. #define FsRtlGetPerStreamContextPointer(_fo) \
  22392. ((PFSRTL_ADVANCED_FCB_HEADER)((_fo)->FsContext))
  22393. //
  22394. // This will test to see if PerStream contexts are supported for the given
  22395. // FileObject
  22396. //
  22397. #define FsRtlSupportsPerStreamContexts(_fo) \
  22398. ((NULL != FsRtlGetPerStreamContextPointer(_fo)) && \
  22399. FlagOn(FsRtlGetPerStreamContextPointer(_fo)->Flags2, \
  22400. FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS))
  22401. //
  22402. // Associate the context at Ptr with the given stream. The Ptr structure
  22403. // should be filled in by the caller before calling this routine (see
  22404. // FsRtlInitPerStreamContext). If the underlying filesystem does not support
  22405. // filter contexts, STATUS_INVALID_DEVICE_REQUEST will be returned.
  22406. //
  22407. NTKERNELAPI
  22408. NTSTATUS
  22409. FsRtlInsertPerStreamContext (
  22410. IN PFSRTL_ADVANCED_FCB_HEADER PerStreamContext,
  22411. IN PFSRTL_PER_STREAM_CONTEXT Ptr
  22412. );
  22413. //
  22414. // Lookup a filter context associated with the stream specified. The first
  22415. // context matching OwnerId (and InstanceId, if present) is returned. By not
  22416. // specifying InstanceId, a filter driver can search for any context that it
  22417. // has previously associated with a stream. If no matching context is found,
  22418. // NULL is returned. If the file system does not support filter contexts,
  22419. // NULL is returned.
  22420. //
  22421. NTKERNELAPI
  22422. PFSRTL_PER_STREAM_CONTEXT
  22423. FsRtlLookupPerStreamContextInternal (
  22424. IN PFSRTL_ADVANCED_FCB_HEADER StreamContext,
  22425. IN PVOID OwnerId OPTIONAL,
  22426. IN PVOID InstanceId OPTIONAL
  22427. );
  22428. #define FsRtlLookupPerStreamContext(_sc, _oid, _iid) \
  22429. (((NULL != (_sc)) && \
  22430. FlagOn((_sc)->Flags2,FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS) && \
  22431. !IsListEmpty(&(_sc)->FilterContexts)) ? \
  22432. FsRtlLookupPerStreamContextInternal((_sc), (_oid), (_iid)) : \
  22433. NULL)
  22434. //
  22435. // Normally, contexts should be deleted when the file system notifies the
  22436. // filter that the stream is being closed. There are cases when a filter
  22437. // may want to remove all existing contexts for a specific volume. This
  22438. // routine should be called at those times. This routine should NOT be
  22439. // called for the following cases:
  22440. // - Inside your FreeCallback handler - The underlying file system has
  22441. // already removed it from the linked list).
  22442. // - Inside your IRP_CLOSE handler - If you do this then you will not
  22443. // be notified when the stream is torn down.
  22444. //
  22445. // This functions identically to FsRtlLookupPerStreamContext, except that the
  22446. // returned context has been removed from the list.
  22447. //
  22448. NTKERNELAPI
  22449. PFSRTL_PER_STREAM_CONTEXT
  22450. FsRtlRemovePerStreamContext (
  22451. IN PFSRTL_ADVANCED_FCB_HEADER StreamContext,
  22452. IN PVOID OwnerId OPTIONAL,
  22453. IN PVOID InstanceId OPTIONAL
  22454. );
  22455. //
  22456. // APIs for file systems to use for initializing and cleaning up
  22457. // the Advaned FCB Header fields for PerStreamContext support
  22458. //
  22459. //
  22460. // This will properly initialize the advanced header so that it can be
  22461. // used with PerStream contexts.
  22462. // Note: A fast mutex must be placed in an advanced header. It is the
  22463. // caller's responsibility to properly create and initialize this
  22464. // mutex before calling this macro. The mutex field is only set
  22465. // if a non-NULL value is passed in.
  22466. //
  22467. #define FsRtlSetupAdvancedHeader( _advhdr, _fmutx ) \
  22468. { \
  22469. SetFlag( (_advhdr)->Flags, FSRTL_FLAG_ADVANCED_HEADER ); \
  22470. SetFlag( (_advhdr)->Flags2, FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS ); \
  22471. InitializeListHead( &(_advhdr)->FilterContexts ); \
  22472. if ((_fmutx) != NULL) { \
  22473. (_advhdr)->FastMutex = (_fmutx); \
  22474. } \
  22475. }
  22476. //
  22477. // File systems call this API to free any filter contexts still associated
  22478. // with an FSRTL_COMMON_FCB_HEADER that they are tearing down.
  22479. // The FreeCallback routine for each filter context will be called.
  22480. //
  22481. NTKERNELAPI
  22482. VOID
  22483. FsRtlTeardownPerStreamContexts (
  22484. IN PFSRTL_ADVANCED_FCB_HEADER AdvancedHeader
  22485. );
  22486. //++
  22487. //
  22488. // VOID
  22489. // FsRtlCompleteRequest (
  22490. // IN PIRP Irp,
  22491. // IN NTSTATUS Status
  22492. // );
  22493. //
  22494. // Routine Description:
  22495. //
  22496. // This routine is used to complete an IRP with the indicated
  22497. // status. It does the necessary raise and lower of IRQL.
  22498. //
  22499. // Arguments:
  22500. //
  22501. // Irp - Supplies a pointer to the Irp to complete
  22502. //
  22503. // Status - Supplies the completion status for the Irp
  22504. //
  22505. // Return Value:
  22506. //
  22507. // None.
  22508. //
  22509. //--
  22510. #define FsRtlCompleteRequest(IRP,STATUS) { \
  22511. (IRP)->IoStatus.Status = (STATUS); \
  22512. IoCompleteRequest( (IRP), IO_DISK_INCREMENT ); \
  22513. }
  22514. //++
  22515. //
  22516. // VOID
  22517. // FsRtlEnterFileSystem (
  22518. // );
  22519. //
  22520. // Routine Description:
  22521. //
  22522. // This routine is used when entering a file system (e.g., through its
  22523. // Fsd entry point). It ensures that the file system cannot be suspended
  22524. // while running and thus block other file I/O requests. Upon exit
  22525. // the file system must call FsRtlExitFileSystem.
  22526. //
  22527. // Arguments:
  22528. //
  22529. // Return Value:
  22530. //
  22531. // None.
  22532. //
  22533. //--
  22534. #define FsRtlEnterFileSystem() { \
  22535. KeEnterCriticalRegion(); \
  22536. }
  22537. //++
  22538. //
  22539. // VOID
  22540. // FsRtlExitFileSystem (
  22541. // );
  22542. //
  22543. // Routine Description:
  22544. //
  22545. // This routine is used when exiting a file system (e.g., through its
  22546. // Fsd entry point).
  22547. //
  22548. // Arguments:
  22549. //
  22550. // Return Value:
  22551. //
  22552. // None.
  22553. //
  22554. //--
  22555. #define FsRtlExitFileSystem() { \
  22556. KeLeaveCriticalRegion(); \
  22557. }
  22558. VOID
  22559. FsRtlIncrementCcFastReadNotPossible( VOID );
  22560. VOID
  22561. FsRtlIncrementCcFastReadWait( VOID );
  22562. VOID
  22563. FsRtlIncrementCcFastReadNoWait( VOID );
  22564. VOID
  22565. FsRtlIncrementCcFastReadResourceMiss( VOID );
  22566. //
  22567. // Returns TRUE if the given fileObject represents a paging file, returns
  22568. // FALSE otherwise.
  22569. //
  22570. LOGICAL
  22571. FsRtlIsPagingFile (
  22572. IN PFILE_OBJECT FileObject
  22573. );
  22574. //
  22575. // Define two constants describing the view size (and alignment)
  22576. // that the Cache Manager uses to map files.
  22577. //
  22578. #define VACB_MAPPING_GRANULARITY (0x40000)
  22579. #define VACB_OFFSET_SHIFT (18)
  22580. //
  22581. // Public portion of BCB
  22582. //
  22583. typedef struct _PUBLIC_BCB {
  22584. //
  22585. // Type and size of this record
  22586. //
  22587. // NOTE: The first four fields must be the same as the BCB in cc.h.
  22588. //
  22589. CSHORT NodeTypeCode;
  22590. CSHORT NodeByteSize;
  22591. //
  22592. // Description of range of file which is currently mapped.
  22593. //
  22594. ULONG MappedLength;
  22595. LARGE_INTEGER MappedFileOffset;
  22596. } PUBLIC_BCB, *PPUBLIC_BCB;
  22597. //
  22598. // File Sizes structure.
  22599. //
  22600. typedef struct _CC_FILE_SIZES {
  22601. LARGE_INTEGER AllocationSize;
  22602. LARGE_INTEGER FileSize;
  22603. LARGE_INTEGER ValidDataLength;
  22604. } CC_FILE_SIZES, *PCC_FILE_SIZES;
  22605. //
  22606. // Define a Cache Manager callback structure. These routines are required
  22607. // by the Lazy Writer, so that it can acquire resources in the right order
  22608. // to avoid deadlocks. Note that otherwise you would have most FS requests
  22609. // acquiring FS resources first and caching structures second, while the
  22610. // Lazy Writer needs to acquire its own resources first, and then FS
  22611. // structures later as it calls the file system.
  22612. //
  22613. //
  22614. // First define the procedure pointer typedefs
  22615. //
  22616. //
  22617. // This routine is called by the Lazy Writer prior to doing a write,
  22618. // since this will require some file system resources associated with
  22619. // this cached file. The context parameter supplied is whatever the FS
  22620. // passed as the LazyWriteContext parameter when is called
  22621. // CcInitializeCacheMap.
  22622. //
  22623. typedef
  22624. BOOLEAN (*PACQUIRE_FOR_LAZY_WRITE) (
  22625. IN PVOID Context,
  22626. IN BOOLEAN Wait
  22627. );
  22628. //
  22629. // This routine releases the Context acquired above.
  22630. //
  22631. typedef
  22632. VOID (*PRELEASE_FROM_LAZY_WRITE) (
  22633. IN PVOID Context
  22634. );
  22635. //
  22636. // This routine is called by the Lazy Writer prior to doing a readahead.
  22637. //
  22638. typedef
  22639. BOOLEAN (*PACQUIRE_FOR_READ_AHEAD) (
  22640. IN PVOID Context,
  22641. IN BOOLEAN Wait
  22642. );
  22643. //
  22644. // This routine releases the Context acquired above.
  22645. //
  22646. typedef
  22647. VOID (*PRELEASE_FROM_READ_AHEAD) (
  22648. IN PVOID Context
  22649. );
  22650. typedef struct _CACHE_MANAGER_CALLBACKS {
  22651. PACQUIRE_FOR_LAZY_WRITE AcquireForLazyWrite;
  22652. PRELEASE_FROM_LAZY_WRITE ReleaseFromLazyWrite;
  22653. PACQUIRE_FOR_READ_AHEAD AcquireForReadAhead;
  22654. PRELEASE_FROM_READ_AHEAD ReleaseFromReadAhead;
  22655. } CACHE_MANAGER_CALLBACKS, *PCACHE_MANAGER_CALLBACKS;
  22656. //
  22657. // This structure is passed into CcUninitializeCacheMap
  22658. // if the caller wants to know when the cache map is deleted.
  22659. //
  22660. typedef struct _CACHE_UNINITIALIZE_EVENT {
  22661. struct _CACHE_UNINITIALIZE_EVENT *Next;
  22662. KEVENT Event;
  22663. } CACHE_UNINITIALIZE_EVENT, *PCACHE_UNINITIALIZE_EVENT;
  22664. //
  22665. // Callback routine for retrieving dirty pages from Cache Manager.
  22666. //
  22667. typedef
  22668. VOID (*PDIRTY_PAGE_ROUTINE) (
  22669. IN PFILE_OBJECT FileObject,
  22670. IN PLARGE_INTEGER FileOffset,
  22671. IN ULONG Length,
  22672. IN PLARGE_INTEGER OldestLsn,
  22673. IN PLARGE_INTEGER NewestLsn,
  22674. IN PVOID Context1,
  22675. IN PVOID Context2
  22676. );
  22677. //
  22678. // Callback routine for doing log file flushes to Lsn.
  22679. //
  22680. typedef
  22681. VOID (*PFLUSH_TO_LSN) (
  22682. IN PVOID LogHandle,
  22683. IN LARGE_INTEGER Lsn
  22684. );
  22685. //
  22686. // Macro to test whether a file is cached or not.
  22687. //
  22688. #define CcIsFileCached(FO) ( \
  22689. ((FO)->SectionObjectPointer != NULL) && \
  22690. (((PSECTION_OBJECT_POINTERS)(FO)->SectionObjectPointer)->SharedCacheMap != NULL) \
  22691. )
  22692. extern ULONG CcFastMdlReadWait;
  22693. //
  22694. // The following routines are intended for use by File Systems Only.
  22695. //
  22696. NTKERNELAPI
  22697. VOID
  22698. CcInitializeCacheMap (
  22699. IN PFILE_OBJECT FileObject,
  22700. IN PCC_FILE_SIZES FileSizes,
  22701. IN BOOLEAN PinAccess,
  22702. IN PCACHE_MANAGER_CALLBACKS Callbacks,
  22703. IN PVOID LazyWriteContext
  22704. );
  22705. NTKERNELAPI
  22706. BOOLEAN
  22707. CcUninitializeCacheMap (
  22708. IN PFILE_OBJECT FileObject,
  22709. IN PLARGE_INTEGER TruncateSize OPTIONAL,
  22710. IN PCACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent OPTIONAL
  22711. );
  22712. NTKERNELAPI
  22713. VOID
  22714. CcSetFileSizes (
  22715. IN PFILE_OBJECT FileObject,
  22716. IN PCC_FILE_SIZES FileSizes
  22717. );
  22718. //
  22719. // VOID
  22720. // CcFastIoSetFileSizes (
  22721. // IN PFILE_OBJECT FileObject,
  22722. // IN PCC_FILE_SIZES FileSizes
  22723. // );
  22724. //
  22725. #define CcGetFileSizePointer(FO) ( \
  22726. ((PLARGE_INTEGER)((FO)->SectionObjectPointer->SharedCacheMap) + 1) \
  22727. )
  22728. NTKERNELAPI
  22729. BOOLEAN
  22730. CcPurgeCacheSection (
  22731. IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
  22732. IN PLARGE_INTEGER FileOffset OPTIONAL,
  22733. IN ULONG Length,
  22734. IN BOOLEAN UninitializeCacheMaps
  22735. );
  22736. NTKERNELAPI
  22737. VOID
  22738. CcSetDirtyPageThreshold (
  22739. IN PFILE_OBJECT FileObject,
  22740. IN ULONG DirtyPageThreshold
  22741. );
  22742. NTKERNELAPI
  22743. VOID
  22744. CcFlushCache (
  22745. IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
  22746. IN PLARGE_INTEGER FileOffset OPTIONAL,
  22747. IN ULONG Length,
  22748. OUT PIO_STATUS_BLOCK IoStatus OPTIONAL
  22749. );
  22750. NTKERNELAPI
  22751. LARGE_INTEGER
  22752. CcGetFlushedValidData (
  22753. IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
  22754. IN BOOLEAN BcbListHeld
  22755. );
  22756. NTKERNELAPI
  22757. BOOLEAN
  22758. CcZeroData (
  22759. IN PFILE_OBJECT FileObject,
  22760. IN PLARGE_INTEGER StartOffset,
  22761. IN PLARGE_INTEGER EndOffset,
  22762. IN BOOLEAN Wait
  22763. );
  22764. NTKERNELAPI
  22765. PVOID
  22766. CcRemapBcb (
  22767. IN PVOID Bcb
  22768. );
  22769. NTKERNELAPI
  22770. VOID
  22771. CcRepinBcb (
  22772. IN PVOID Bcb
  22773. );
  22774. NTKERNELAPI
  22775. VOID
  22776. CcUnpinRepinnedBcb (
  22777. IN PVOID Bcb,
  22778. IN BOOLEAN WriteThrough,
  22779. OUT PIO_STATUS_BLOCK IoStatus
  22780. );
  22781. NTKERNELAPI
  22782. PFILE_OBJECT
  22783. CcGetFileObjectFromSectionPtrs (
  22784. IN PSECTION_OBJECT_POINTERS SectionObjectPointer
  22785. );
  22786. NTKERNELAPI
  22787. PFILE_OBJECT
  22788. CcGetFileObjectFromBcb (
  22789. IN PVOID Bcb
  22790. );
  22791. //
  22792. // These routines are implemented to support write throttling.
  22793. //
  22794. //
  22795. // BOOLEAN
  22796. // CcCopyWriteWontFlush (
  22797. // IN PFILE_OBJECT FileObject,
  22798. // IN PLARGE_INTEGER FileOffset,
  22799. // IN ULONG Length
  22800. // );
  22801. //
  22802. #define CcCopyWriteWontFlush(FO,FOFF,LEN) ((LEN) <= 0X10000)
  22803. NTKERNELAPI
  22804. BOOLEAN
  22805. CcCanIWrite (
  22806. IN PFILE_OBJECT FileObject,
  22807. IN ULONG BytesToWrite,
  22808. IN BOOLEAN Wait,
  22809. IN BOOLEAN Retrying
  22810. );
  22811. typedef
  22812. VOID (*PCC_POST_DEFERRED_WRITE) (
  22813. IN PVOID Context1,
  22814. IN PVOID Context2
  22815. );
  22816. NTKERNELAPI
  22817. VOID
  22818. CcDeferWrite (
  22819. IN PFILE_OBJECT FileObject,
  22820. IN PCC_POST_DEFERRED_WRITE PostRoutine,
  22821. IN PVOID Context1,
  22822. IN PVOID Context2,
  22823. IN ULONG BytesToWrite,
  22824. IN BOOLEAN Retrying
  22825. );
  22826. //
  22827. // The following routines provide a data copy interface to the cache, and
  22828. // are intended for use by File Servers and File Systems.
  22829. //
  22830. NTKERNELAPI
  22831. BOOLEAN
  22832. CcCopyRead (
  22833. IN PFILE_OBJECT FileObject,
  22834. IN PLARGE_INTEGER FileOffset,
  22835. IN ULONG Length,
  22836. IN BOOLEAN Wait,
  22837. OUT PVOID Buffer,
  22838. OUT PIO_STATUS_BLOCK IoStatus
  22839. );
  22840. NTKERNELAPI
  22841. VOID
  22842. CcFastCopyRead (
  22843. IN PFILE_OBJECT FileObject,
  22844. IN ULONG FileOffset,
  22845. IN ULONG Length,
  22846. IN ULONG PageCount,
  22847. OUT PVOID Buffer,
  22848. OUT PIO_STATUS_BLOCK IoStatus
  22849. );
  22850. NTKERNELAPI
  22851. BOOLEAN
  22852. CcCopyWrite (
  22853. IN PFILE_OBJECT FileObject,
  22854. IN PLARGE_INTEGER FileOffset,
  22855. IN ULONG Length,
  22856. IN BOOLEAN Wait,
  22857. IN PVOID Buffer
  22858. );
  22859. NTKERNELAPI
  22860. VOID
  22861. CcFastCopyWrite (
  22862. IN PFILE_OBJECT FileObject,
  22863. IN ULONG FileOffset,
  22864. IN ULONG Length,
  22865. IN PVOID Buffer
  22866. );
  22867. //
  22868. // The following routines provide an Mdl interface for transfers to and
  22869. // from the cache, and are primarily intended for File Servers.
  22870. //
  22871. // NOBODY SHOULD BE CALLING THESE MDL ROUTINES DIRECTLY, USE FSRTL AND
  22872. // FASTIO INTERFACES.
  22873. //
  22874. NTKERNELAPI
  22875. VOID
  22876. CcMdlRead (
  22877. IN PFILE_OBJECT FileObject,
  22878. IN PLARGE_INTEGER FileOffset,
  22879. IN ULONG Length,
  22880. OUT PMDL *MdlChain,
  22881. OUT PIO_STATUS_BLOCK IoStatus
  22882. );
  22883. //
  22884. // This routine is now a wrapper for FastIo if present or CcMdlReadComplete2
  22885. //
  22886. NTKERNELAPI
  22887. VOID
  22888. CcMdlReadComplete (
  22889. IN PFILE_OBJECT FileObject,
  22890. IN PMDL MdlChain
  22891. );
  22892. NTKERNELAPI
  22893. VOID
  22894. CcPrepareMdlWrite (
  22895. IN PFILE_OBJECT FileObject,
  22896. IN PLARGE_INTEGER FileOffset,
  22897. IN ULONG Length,
  22898. OUT PMDL *MdlChain,
  22899. OUT PIO_STATUS_BLOCK IoStatus
  22900. );
  22901. //
  22902. // This routine is now a wrapper for FastIo if present or CcMdlWriteComplete2
  22903. //
  22904. NTKERNELAPI
  22905. VOID
  22906. CcMdlWriteComplete (
  22907. IN PFILE_OBJECT FileObject,
  22908. IN PLARGE_INTEGER FileOffset,
  22909. IN PMDL MdlChain
  22910. );
  22911. VOID
  22912. CcMdlWriteAbort (
  22913. IN PFILE_OBJECT FileObject,
  22914. IN PMDL MdlChain
  22915. );
  22916. //
  22917. // Common ReadAhead call for Copy Read and Mdl Read.
  22918. //
  22919. // ReadAhead should always be invoked by calling the CcReadAhead macro,
  22920. // which tests first to see if the read is large enough to warrant read
  22921. // ahead. Measurements have shown that, calling the read ahead routine
  22922. // actually decreases performance for small reads, such as issued by
  22923. // many compilers and linkers. Compilers simply want all of the include
  22924. // files to stay in memory after being read the first time.
  22925. //
  22926. #define CcReadAhead(FO,FOFF,LEN) { \
  22927. if ((LEN) >= 256) { \
  22928. CcScheduleReadAhead((FO),(FOFF),(LEN)); \
  22929. } \
  22930. }
  22931. NTKERNELAPI
  22932. VOID
  22933. CcScheduleReadAhead (
  22934. IN PFILE_OBJECT FileObject,
  22935. IN PLARGE_INTEGER FileOffset,
  22936. IN ULONG Length
  22937. );
  22938. //
  22939. // The following routine allows a caller to wait for the next batch
  22940. // of lazy writer work to complete. In particular, this provides a
  22941. // mechanism for a caller to be sure that all avaliable lazy closes
  22942. // at the time of this call have issued.
  22943. //
  22944. NTSTATUS
  22945. CcWaitForCurrentLazyWriterActivity (
  22946. VOID
  22947. );
  22948. //
  22949. // This routine changes the read ahead granularity for a file, which is
  22950. // PAGE_SIZE by default.
  22951. //
  22952. NTKERNELAPI
  22953. VOID
  22954. CcSetReadAheadGranularity (
  22955. IN PFILE_OBJECT FileObject,
  22956. IN ULONG Granularity
  22957. );
  22958. //
  22959. // The following routines provide direct access data which is pinned in the
  22960. // cache, and is primarily intended for use by File Systems. In particular,
  22961. // this mode of access is ideal for dealing with volume structures.
  22962. //
  22963. //
  22964. // Flags for pinning
  22965. //
  22966. //
  22967. // Synchronous Wait - normally specified. This pattern may be specified as TRUE.
  22968. //
  22969. #define PIN_WAIT (1)
  22970. //
  22971. // Acquire metadata Bcb exclusive (default is shared, Lazy Writer uses exclusive).
  22972. //
  22973. // Must be set with PIN_WAIT.
  22974. //
  22975. #define PIN_EXCLUSIVE (2)
  22976. //
  22977. // Acquire metadata Bcb but do not fault data in. Default is to fault the data in.
  22978. // This unusual flag is only used by Ntfs for cache coherency synchronization between
  22979. // compressed and uncompressed streams for the same compressed file.
  22980. //
  22981. // Must be set with PIN_WAIT.
  22982. //
  22983. #define PIN_NO_READ (4)
  22984. //
  22985. // This option may be used to pin data only if the Bcb already exists. If the Bcb
  22986. // does not already exist - the pin is unsuccessful and no Bcb is returned. This routine
  22987. // provides a way to see if data is already pinned (and possibly dirty) in the cache,
  22988. // without forcing a fault if the data is not there.
  22989. //
  22990. #define PIN_IF_BCB (8)
  22991. //
  22992. // Flags for mapping
  22993. //
  22994. //
  22995. // Synchronous Wait - normally specified. This pattern may be specified as TRUE.
  22996. //
  22997. #define MAP_WAIT (1)
  22998. //
  22999. // Acquire metadata Bcb but do not fault data in. Default is to fault the data in.
  23000. // This should not overlap with any of the PIN_ flags so they can be passed down to
  23001. // CcPinFileData
  23002. //
  23003. #define MAP_NO_READ (16)
  23004. NTKERNELAPI
  23005. BOOLEAN
  23006. CcPinRead (
  23007. IN PFILE_OBJECT FileObject,
  23008. IN PLARGE_INTEGER FileOffset,
  23009. IN ULONG Length,
  23010. IN ULONG Flags,
  23011. OUT PVOID *Bcb,
  23012. OUT PVOID *Buffer
  23013. );
  23014. NTKERNELAPI
  23015. BOOLEAN
  23016. CcMapData (
  23017. IN PFILE_OBJECT FileObject,
  23018. IN PLARGE_INTEGER FileOffset,
  23019. IN ULONG Length,
  23020. IN ULONG Flags,
  23021. OUT PVOID *Bcb,
  23022. OUT PVOID *Buffer
  23023. );
  23024. NTKERNELAPI
  23025. BOOLEAN
  23026. CcPinMappedData (
  23027. IN PFILE_OBJECT FileObject,
  23028. IN PLARGE_INTEGER FileOffset,
  23029. IN ULONG Length,
  23030. IN ULONG Flags,
  23031. IN OUT PVOID *Bcb
  23032. );
  23033. NTKERNELAPI
  23034. BOOLEAN
  23035. CcPreparePinWrite (
  23036. IN PFILE_OBJECT FileObject,
  23037. IN PLARGE_INTEGER FileOffset,
  23038. IN ULONG Length,
  23039. IN BOOLEAN Zero,
  23040. IN ULONG Flags,
  23041. OUT PVOID *Bcb,
  23042. OUT PVOID *Buffer
  23043. );
  23044. NTKERNELAPI
  23045. VOID
  23046. CcSetDirtyPinnedData (
  23047. IN PVOID BcbVoid,
  23048. IN PLARGE_INTEGER Lsn OPTIONAL
  23049. );
  23050. NTKERNELAPI
  23051. VOID
  23052. CcUnpinData (
  23053. IN PVOID Bcb
  23054. );
  23055. NTKERNELAPI
  23056. VOID
  23057. CcSetBcbOwnerPointer (
  23058. IN PVOID Bcb,
  23059. IN PVOID OwnerPointer
  23060. );
  23061. NTKERNELAPI
  23062. VOID
  23063. CcUnpinDataForThread (
  23064. IN PVOID Bcb,
  23065. IN ERESOURCE_THREAD ResourceThreadId
  23066. );
  23067. NTKERNELAPI
  23068. VOID
  23069. CcSetAdditionalCacheAttributes (
  23070. IN PFILE_OBJECT FileObject,
  23071. IN BOOLEAN DisableReadAhead,
  23072. IN BOOLEAN DisableWriteBehind
  23073. );
  23074. NTKERNELAPI
  23075. VOID
  23076. CcSetLogHandleForFile (
  23077. IN PFILE_OBJECT FileObject,
  23078. IN PVOID LogHandle,
  23079. IN PFLUSH_TO_LSN FlushToLsnRoutine
  23080. );
  23081. NTKERNELAPI
  23082. LARGE_INTEGER
  23083. CcGetDirtyPages (
  23084. IN PVOID LogHandle,
  23085. IN PDIRTY_PAGE_ROUTINE DirtyPageRoutine,
  23086. IN PVOID Context1,
  23087. IN PVOID Context2
  23088. );
  23089. NTKERNELAPI
  23090. BOOLEAN
  23091. CcIsThereDirtyData (
  23092. IN PVPB Vpb
  23093. );
  23094. #ifndef __SSPI_H__
  23095. #define __SSPI_H__
  23096. #define ISSP_LEVEL 32
  23097. #define ISSP_MODE 0
  23098. typedef WCHAR SEC_WCHAR;
  23099. typedef CHAR SEC_CHAR;
  23100. #ifndef __SECSTATUS_DEFINED__
  23101. typedef LONG SECURITY_STATUS;
  23102. #define __SECSTATUS_DEFINED__
  23103. #endif
  23104. #define SEC_TEXT TEXT
  23105. #define SEC_FAR
  23106. #define SEC_ENTRY __stdcall
  23107. #ifndef __SECHANDLE_DEFINED__
  23108. typedef struct _SecHandle
  23109. {
  23110. ULONG_PTR dwLower ;
  23111. ULONG_PTR dwUpper ;
  23112. } SecHandle, * PSecHandle ;
  23113. #define __SECHANDLE_DEFINED__
  23114. #endif // __SECHANDLE_DEFINED__
  23115. #define SecInvalidateHandle( x ) \
  23116. ((PSecHandle) x)->dwLower = ((ULONG_PTR) ((INT_PTR)-1)) ; \
  23117. ((PSecHandle) x)->dwUpper = ((ULONG_PTR) ((INT_PTR)-1)) ; \
  23118. #define SecIsValidHandle( x ) \
  23119. ( ( ((PSecHandle) x)->dwLower != ((ULONG_PTR) ((INT_PTR) -1 ))) && \
  23120. ( ((PSecHandle) x)->dwUpper != ((ULONG_PTR) ((INT_PTR) -1 ))) )
  23121. typedef SecHandle CredHandle;
  23122. typedef PSecHandle PCredHandle;
  23123. typedef SecHandle CtxtHandle;
  23124. typedef PSecHandle PCtxtHandle;
  23125. typedef LARGE_INTEGER _SECURITY_INTEGER, SECURITY_INTEGER, *PSECURITY_INTEGER;
  23126. typedef SECURITY_INTEGER TimeStamp;
  23127. typedef SECURITY_INTEGER SEC_FAR * PTimeStamp;
  23128. typedef UNICODE_STRING SECURITY_STRING, *PSECURITY_STRING;
  23129. //
  23130. // SecPkgInfo structure
  23131. //
  23132. // Provides general information about a security provider
  23133. //
  23134. typedef struct _SecPkgInfoW
  23135. {
  23136. unsigned long fCapabilities; // Capability bitmask
  23137. unsigned short wVersion; // Version of driver
  23138. unsigned short wRPCID; // ID for RPC Runtime
  23139. unsigned long cbMaxToken; // Size of authentication token (max)
  23140. #ifdef MIDL_PASS
  23141. [string]
  23142. #endif
  23143. SEC_WCHAR SEC_FAR * Name; // Text name
  23144. #ifdef MIDL_PASS
  23145. [string]
  23146. #endif
  23147. SEC_WCHAR SEC_FAR * Comment; // Comment
  23148. } SecPkgInfoW, SEC_FAR * PSecPkgInfoW;
  23149. # define SecPkgInfo SecPkgInfoW
  23150. # define PSecPkgInfo PSecPkgInfoW
  23151. //
  23152. // Security Package Capabilities
  23153. //
  23154. #define SECPKG_FLAG_INTEGRITY 0x00000001 // Supports integrity on messages
  23155. #define SECPKG_FLAG_PRIVACY 0x00000002 // Supports privacy (confidentiality)
  23156. #define SECPKG_FLAG_TOKEN_ONLY 0x00000004 // Only security token needed
  23157. #define SECPKG_FLAG_DATAGRAM 0x00000008 // Datagram RPC support
  23158. #define SECPKG_FLAG_CONNECTION 0x00000010 // Connection oriented RPC support
  23159. #define SECPKG_FLAG_MULTI_REQUIRED 0x00000020 // Full 3-leg required for re-auth.
  23160. #define SECPKG_FLAG_CLIENT_ONLY 0x00000040 // Server side functionality not available
  23161. #define SECPKG_FLAG_EXTENDED_ERROR 0x00000080 // Supports extended error msgs
  23162. #define SECPKG_FLAG_IMPERSONATION 0x00000100 // Supports impersonation
  23163. #define SECPKG_FLAG_ACCEPT_WIN32_NAME 0x00000200 // Accepts Win32 names
  23164. #define SECPKG_FLAG_STREAM 0x00000400 // Supports stream semantics
  23165. #define SECPKG_FLAG_NEGOTIABLE 0x00000800 // Can be used by the negotiate package
  23166. #define SECPKG_FLAG_GSS_COMPATIBLE 0x00001000 // GSS Compatibility Available
  23167. #define SECPKG_FLAG_LOGON 0x00002000 // Supports common LsaLogonUser
  23168. #define SECPKG_FLAG_ASCII_BUFFERS 0x00004000 // Token Buffers are in ASCII
  23169. #define SECPKG_FLAG_FRAGMENT 0x00008000 // Package can fragment to fit
  23170. #define SECPKG_FLAG_MUTUAL_AUTH 0x00010000 // Package can perform mutual authentication
  23171. #define SECPKG_FLAG_DELEGATION 0x00020000 // Package can delegate
  23172. #define SECPKG_ID_NONE 0xFFFF
  23173. //
  23174. // SecBuffer
  23175. //
  23176. // Generic memory descriptors for buffers passed in to the security
  23177. // API
  23178. //
  23179. typedef struct _SecBuffer {
  23180. unsigned long cbBuffer; // Size of the buffer, in bytes
  23181. unsigned long BufferType; // Type of the buffer (below)
  23182. void SEC_FAR * pvBuffer; // Pointer to the buffer
  23183. } SecBuffer, SEC_FAR * PSecBuffer;
  23184. typedef struct _SecBufferDesc {
  23185. unsigned long ulVersion; // Version number
  23186. unsigned long cBuffers; // Number of buffers
  23187. #ifdef MIDL_PASS
  23188. [size_is(cBuffers)]
  23189. #endif
  23190. PSecBuffer pBuffers; // Pointer to array of buffers
  23191. } SecBufferDesc, SEC_FAR * PSecBufferDesc;
  23192. #define SECBUFFER_VERSION 0
  23193. #define SECBUFFER_EMPTY 0 // Undefined, replaced by provider
  23194. #define SECBUFFER_DATA 1 // Packet data
  23195. #define SECBUFFER_TOKEN 2 // Security token
  23196. #define SECBUFFER_PKG_PARAMS 3 // Package specific parameters
  23197. #define SECBUFFER_MISSING 4 // Missing Data indicator
  23198. #define SECBUFFER_EXTRA 5 // Extra data
  23199. #define SECBUFFER_STREAM_TRAILER 6 // Security Trailer
  23200. #define SECBUFFER_STREAM_HEADER 7 // Security Header
  23201. #define SECBUFFER_NEGOTIATION_INFO 8 // Hints from the negotiation pkg
  23202. #define SECBUFFER_PADDING 9 // non-data padding
  23203. #define SECBUFFER_STREAM 10 // whole encrypted message
  23204. #define SECBUFFER_MECHLIST 11
  23205. #define SECBUFFER_MECHLIST_SIGNATURE 12
  23206. #define SECBUFFER_TARGET 13
  23207. #define SECBUFFER_CHANNEL_BINDINGS 14
  23208. #define SECBUFFER_ATTRMASK 0xF0000000
  23209. #define SECBUFFER_READONLY 0x80000000 // Buffer is read-only
  23210. #define SECBUFFER_RESERVED 0x60000000 // Flags reserved to security system
  23211. typedef struct _SEC_NEGOTIATION_INFO {
  23212. unsigned long Size; // Size of this structure
  23213. unsigned long NameLength; // Length of name hint
  23214. SEC_WCHAR SEC_FAR * Name; // Name hint
  23215. void SEC_FAR * Reserved; // Reserved
  23216. } SEC_NEGOTIATION_INFO, SEC_FAR * PSEC_NEGOTIATION_INFO ;
  23217. typedef struct _SEC_CHANNEL_BINDINGS {
  23218. unsigned long dwInitiatorAddrType;
  23219. unsigned long cbInitiatorLength;
  23220. unsigned long dwInitiatorOffset;
  23221. unsigned long dwAcceptorAddrType;
  23222. unsigned long cbAcceptorLength;
  23223. unsigned long dwAcceptorOffset;
  23224. unsigned long cbApplicationDataLength;
  23225. unsigned long dwApplicationDataOffset;
  23226. } SEC_CHANNEL_BINDINGS, SEC_FAR * PSEC_CHANNEL_BINDINGS ;
  23227. //
  23228. // Data Representation Constant:
  23229. //
  23230. #define SECURITY_NATIVE_DREP 0x00000010
  23231. #define SECURITY_NETWORK_DREP 0x00000000
  23232. //
  23233. // Credential Use Flags
  23234. //
  23235. #define SECPKG_CRED_INBOUND 0x00000001
  23236. #define SECPKG_CRED_OUTBOUND 0x00000002
  23237. #define SECPKG_CRED_BOTH 0x00000003
  23238. #define SECPKG_CRED_DEFAULT 0x00000004
  23239. #define SECPKG_CRED_RESERVED 0xF0000000
  23240. //
  23241. // InitializeSecurityContext Requirement and return flags:
  23242. //
  23243. #define ISC_REQ_DELEGATE 0x00000001
  23244. #define ISC_REQ_MUTUAL_AUTH 0x00000002
  23245. #define ISC_REQ_REPLAY_DETECT 0x00000004
  23246. #define ISC_REQ_SEQUENCE_DETECT 0x00000008
  23247. #define ISC_REQ_CONFIDENTIALITY 0x00000010
  23248. #define ISC_REQ_USE_SESSION_KEY 0x00000020
  23249. #define ISC_REQ_PROMPT_FOR_CREDS 0x00000040
  23250. #define ISC_REQ_USE_SUPPLIED_CREDS 0x00000080
  23251. #define ISC_REQ_ALLOCATE_MEMORY 0x00000100
  23252. #define ISC_REQ_USE_DCE_STYLE 0x00000200
  23253. #define ISC_REQ_DATAGRAM 0x00000400
  23254. #define ISC_REQ_CONNECTION 0x00000800
  23255. #define ISC_REQ_CALL_LEVEL 0x00001000
  23256. #define ISC_REQ_FRAGMENT_SUPPLIED 0x00002000
  23257. #define ISC_REQ_EXTENDED_ERROR 0x00004000
  23258. #define ISC_REQ_STREAM 0x00008000
  23259. #define ISC_REQ_INTEGRITY 0x00010000
  23260. #define ISC_REQ_IDENTIFY 0x00020000
  23261. #define ISC_REQ_NULL_SESSION 0x00040000
  23262. #define ISC_REQ_MANUAL_CRED_VALIDATION 0x00080000
  23263. #define ISC_REQ_RESERVED1 0x00100000
  23264. #define ISC_REQ_FRAGMENT_TO_FIT 0x00200000
  23265. #define ISC_RET_DELEGATE 0x00000001
  23266. #define ISC_RET_MUTUAL_AUTH 0x00000002
  23267. #define ISC_RET_REPLAY_DETECT 0x00000004
  23268. #define ISC_RET_SEQUENCE_DETECT 0x00000008
  23269. #define ISC_RET_CONFIDENTIALITY 0x00000010
  23270. #define ISC_RET_USE_SESSION_KEY 0x00000020
  23271. #define ISC_RET_USED_COLLECTED_CREDS 0x00000040
  23272. #define ISC_RET_USED_SUPPLIED_CREDS 0x00000080
  23273. #define ISC_RET_ALLOCATED_MEMORY 0x00000100
  23274. #define ISC_RET_USED_DCE_STYLE 0x00000200
  23275. #define ISC_RET_DATAGRAM 0x00000400
  23276. #define ISC_RET_CONNECTION 0x00000800
  23277. #define ISC_RET_INTERMEDIATE_RETURN 0x00001000
  23278. #define ISC_RET_CALL_LEVEL 0x00002000
  23279. #define ISC_RET_EXTENDED_ERROR 0x00004000
  23280. #define ISC_RET_STREAM 0x00008000
  23281. #define ISC_RET_INTEGRITY 0x00010000
  23282. #define ISC_RET_IDENTIFY 0x00020000
  23283. #define ISC_RET_NULL_SESSION 0x00040000
  23284. #define ISC_RET_MANUAL_CRED_VALIDATION 0x00080000
  23285. #define ISC_RET_RESERVED1 0x00100000
  23286. #define ISC_RET_FRAGMENT_ONLY 0x00200000
  23287. #define ASC_REQ_DELEGATE 0x00000001
  23288. #define ASC_REQ_MUTUAL_AUTH 0x00000002
  23289. #define ASC_REQ_REPLAY_DETECT 0x00000004
  23290. #define ASC_REQ_SEQUENCE_DETECT 0x00000008
  23291. #define ASC_REQ_CONFIDENTIALITY 0x00000010
  23292. #define ASC_REQ_USE_SESSION_KEY 0x00000020
  23293. #define ASC_REQ_ALLOCATE_MEMORY 0x00000100
  23294. #define ASC_REQ_USE_DCE_STYLE 0x00000200
  23295. #define ASC_REQ_DATAGRAM 0x00000400
  23296. #define ASC_REQ_CONNECTION 0x00000800
  23297. #define ASC_REQ_CALL_LEVEL 0x00001000
  23298. #define ASC_REQ_EXTENDED_ERROR 0x00008000
  23299. #define ASC_REQ_STREAM 0x00010000
  23300. #define ASC_REQ_INTEGRITY 0x00020000
  23301. #define ASC_REQ_LICENSING 0x00040000
  23302. #define ASC_REQ_IDENTIFY 0x00080000
  23303. #define ASC_REQ_ALLOW_NULL_SESSION 0x00100000
  23304. #define ASC_REQ_ALLOW_NON_USER_LOGONS 0x00200000
  23305. #define ASC_REQ_ALLOW_CONTEXT_REPLAY 0x00400000
  23306. #define ASC_REQ_FRAGMENT_TO_FIT 0x00800000
  23307. #define ASC_REQ_FRAGMENT_SUPPLIED 0x00002000
  23308. #define ASC_RET_DELEGATE 0x00000001
  23309. #define ASC_RET_MUTUAL_AUTH 0x00000002
  23310. #define ASC_RET_REPLAY_DETECT 0x00000004
  23311. #define ASC_RET_SEQUENCE_DETECT 0x00000008
  23312. #define ASC_RET_CONFIDENTIALITY 0x00000010
  23313. #define ASC_RET_USE_SESSION_KEY 0x00000020
  23314. #define ASC_RET_ALLOCATED_MEMORY 0x00000100
  23315. #define ASC_RET_USED_DCE_STYLE 0x00000200
  23316. #define ASC_RET_DATAGRAM 0x00000400
  23317. #define ASC_RET_CONNECTION 0x00000800
  23318. #define ASC_RET_CALL_LEVEL 0x00002000 // skipped 1000 to be like ISC_
  23319. #define ASC_RET_THIRD_LEG_FAILED 0x00004000
  23320. #define ASC_RET_EXTENDED_ERROR 0x00008000
  23321. #define ASC_RET_STREAM 0x00010000
  23322. #define ASC_RET_INTEGRITY 0x00020000
  23323. #define ASC_RET_LICENSING 0x00040000
  23324. #define ASC_RET_IDENTIFY 0x00080000
  23325. #define ASC_RET_NULL_SESSION 0x00100000
  23326. #define ASC_RET_ALLOW_NON_USER_LOGONS 0x00200000
  23327. #define ASC_RET_ALLOW_CONTEXT_REPLAY 0x00400000
  23328. #define ASC_RET_FRAGMENT_ONLY 0x00800000
  23329. //
  23330. // Security Credentials Attributes:
  23331. //
  23332. #define SECPKG_CRED_ATTR_NAMES 1
  23333. typedef struct _SecPkgCredentials_NamesW
  23334. {
  23335. SEC_WCHAR SEC_FAR * sUserName;
  23336. } SecPkgCredentials_NamesW, SEC_FAR * PSecPkgCredentials_NamesW;
  23337. # define SecPkgCredentials_Names SecPkgCredentials_NamesW
  23338. # define PSecPkgCredentials_Names PSecPkgCredentials_NamesW
  23339. //
  23340. // Security Context Attributes:
  23341. //
  23342. #define SECPKG_ATTR_SIZES 0
  23343. #define SECPKG_ATTR_NAMES 1
  23344. #define SECPKG_ATTR_LIFESPAN 2
  23345. #define SECPKG_ATTR_DCE_INFO 3
  23346. #define SECPKG_ATTR_STREAM_SIZES 4
  23347. #define SECPKG_ATTR_KEY_INFO 5
  23348. #define SECPKG_ATTR_AUTHORITY 6
  23349. #define SECPKG_ATTR_PROTO_INFO 7
  23350. #define SECPKG_ATTR_PASSWORD_EXPIRY 8
  23351. #define SECPKG_ATTR_SESSION_KEY 9
  23352. #define SECPKG_ATTR_PACKAGE_INFO 10
  23353. #define SECPKG_ATTR_USER_FLAGS 11
  23354. #define SECPKG_ATTR_NEGOTIATION_INFO 12
  23355. #define SECPKG_ATTR_NATIVE_NAMES 13
  23356. #define SECPKG_ATTR_FLAGS 14
  23357. #define SECPKG_ATTR_USE_VALIDATED 15
  23358. #define SECPKG_ATTR_CREDENTIAL_NAME 16
  23359. #define SECPKG_ATTR_TARGET_INFORMATION 17
  23360. #define SECPKG_ATTR_ACCESS_TOKEN 18
  23361. typedef struct _SecPkgContext_Sizes
  23362. {
  23363. unsigned long cbMaxToken;
  23364. unsigned long cbMaxSignature;
  23365. unsigned long cbBlockSize;
  23366. unsigned long cbSecurityTrailer;
  23367. } SecPkgContext_Sizes, SEC_FAR * PSecPkgContext_Sizes;
  23368. typedef struct _SecPkgContext_StreamSizes
  23369. {
  23370. unsigned long cbHeader;
  23371. unsigned long cbTrailer;
  23372. unsigned long cbMaximumMessage;
  23373. unsigned long cBuffers;
  23374. unsigned long cbBlockSize;
  23375. } SecPkgContext_StreamSizes, * PSecPkgContext_StreamSizes;
  23376. typedef struct _SecPkgContext_NamesW
  23377. {
  23378. SEC_WCHAR SEC_FAR * sUserName;
  23379. } SecPkgContext_NamesW, SEC_FAR * PSecPkgContext_NamesW;
  23380. # define SecPkgContext_Names SecPkgContext_NamesW
  23381. # define PSecPkgContext_Names PSecPkgContext_NamesW
  23382. typedef struct _SecPkgContext_Lifespan
  23383. {
  23384. TimeStamp tsStart;
  23385. TimeStamp tsExpiry;
  23386. } SecPkgContext_Lifespan, SEC_FAR * PSecPkgContext_Lifespan;
  23387. typedef struct _SecPkgContext_DceInfo
  23388. {
  23389. unsigned long AuthzSvc;
  23390. void SEC_FAR * pPac;
  23391. } SecPkgContext_DceInfo, SEC_FAR * PSecPkgContext_DceInfo;
  23392. typedef struct _SecPkgContext_KeyInfoW
  23393. {
  23394. SEC_WCHAR SEC_FAR * sSignatureAlgorithmName;
  23395. SEC_WCHAR SEC_FAR * sEncryptAlgorithmName;
  23396. unsigned long KeySize;
  23397. unsigned long SignatureAlgorithm;
  23398. unsigned long EncryptAlgorithm;
  23399. } SecPkgContext_KeyInfoW, SEC_FAR * PSecPkgContext_KeyInfoW;
  23400. #define SecPkgContext_KeyInfo SecPkgContext_KeyInfoW
  23401. #define PSecPkgContext_KeyInfo PSecPkgContext_KeyInfoW
  23402. typedef struct _SecPkgContext_AuthorityW
  23403. {
  23404. SEC_WCHAR SEC_FAR * sAuthorityName;
  23405. } SecPkgContext_AuthorityW, * PSecPkgContext_AuthorityW;
  23406. #define SecPkgContext_Authority SecPkgContext_AuthorityW
  23407. #define PSecPkgContext_Authority PSecPkgContext_AuthorityW
  23408. typedef struct _SecPkgContext_ProtoInfoW
  23409. {
  23410. SEC_WCHAR SEC_FAR * sProtocolName;
  23411. unsigned long majorVersion;
  23412. unsigned long minorVersion;
  23413. } SecPkgContext_ProtoInfoW, SEC_FAR * PSecPkgContext_ProtoInfoW;
  23414. #define SecPkgContext_ProtoInfo SecPkgContext_ProtoInfoW
  23415. #define PSecPkgContext_ProtoInfo PSecPkgContext_ProtoInfoW
  23416. typedef struct _SecPkgContext_PasswordExpiry
  23417. {
  23418. TimeStamp tsPasswordExpires;
  23419. } SecPkgContext_PasswordExpiry, SEC_FAR * PSecPkgContext_PasswordExpiry;
  23420. typedef struct _SecPkgContext_SessionKey
  23421. {
  23422. unsigned long SessionKeyLength;
  23423. unsigned char SEC_FAR * SessionKey;
  23424. } SecPkgContext_SessionKey, *PSecPkgContext_SessionKey;
  23425. typedef struct _SecPkgContext_PackageInfoW
  23426. {
  23427. PSecPkgInfoW PackageInfo;
  23428. } SecPkgContext_PackageInfoW, SEC_FAR * PSecPkgContext_PackageInfoW;
  23429. typedef struct _SecPkgContext_UserFlags
  23430. {
  23431. unsigned long UserFlags;
  23432. } SecPkgContext_UserFlags, SEC_FAR * PSecPkgContext_UserFlags;
  23433. typedef struct _SecPkgContext_Flags
  23434. {
  23435. unsigned long Flags;
  23436. } SecPkgContext_Flags, SEC_FAR * PSecPkgContext_Flags;
  23437. #define SecPkgContext_PackageInfo SecPkgContext_PackageInfoW
  23438. #define PSecPkgContext_PackageInfo PSecPkgContext_PackageInfoW
  23439. typedef struct _SecPkgContext_NegotiationInfoW
  23440. {
  23441. PSecPkgInfoW PackageInfo ;
  23442. unsigned long NegotiationState ;
  23443. } SecPkgContext_NegotiationInfoW, SEC_FAR * PSecPkgContext_NegotiationInfoW ;
  23444. # define SecPkgContext_NativeNames SecPkgContext_NativeNamesW
  23445. # define PSecPkgContext_NativeNames PSecPkgContext_NativeNamesW
  23446. typedef struct _SecPkgContext_CredentialNameW
  23447. {
  23448. unsigned long CredentialType;
  23449. SEC_WCHAR SEC_FAR *sCredentialName;
  23450. } SecPkgContext_CredentialNameW, SEC_FAR * PSecPkgContext_CredentialNameW;
  23451. # define SecPkgContext_CredentialName SecPkgContext_CredentialNameW
  23452. # define PSecPkgContext_CredentialName PSecPkgContext_CredentialNameW
  23453. typedef void
  23454. (SEC_ENTRY SEC_FAR * SEC_GET_KEY_FN) (
  23455. void SEC_FAR * Arg, // Argument passed in
  23456. void SEC_FAR * Principal, // Principal ID
  23457. unsigned long KeyVer, // Key Version
  23458. void SEC_FAR * SEC_FAR * Key, // Returned ptr to key
  23459. SECURITY_STATUS SEC_FAR * Status // returned status
  23460. );
  23461. //
  23462. // Flags for ExportSecurityContext
  23463. //
  23464. #define SECPKG_CONTEXT_EXPORT_RESET_NEW 0x00000001 // New context is reset to initial state
  23465. #define SECPKG_CONTEXT_EXPORT_DELETE_OLD 0x00000002 // Old context is deleted during export
  23466. SECURITY_STATUS SEC_ENTRY
  23467. AcquireCredentialsHandleW(
  23468. #if ISSP_MODE == 0 // For Kernel mode
  23469. PSECURITY_STRING pPrincipal,
  23470. PSECURITY_STRING pPackage,
  23471. #else
  23472. SEC_WCHAR SEC_FAR * pszPrincipal, // Name of principal
  23473. SEC_WCHAR SEC_FAR * pszPackage, // Name of package
  23474. #endif
  23475. unsigned long fCredentialUse, // Flags indicating use
  23476. void SEC_FAR * pvLogonId, // Pointer to logon ID
  23477. void SEC_FAR * pAuthData, // Package specific data
  23478. SEC_GET_KEY_FN pGetKeyFn, // Pointer to GetKey() func
  23479. void SEC_FAR * pvGetKeyArgument, // Value to pass to GetKey()
  23480. PCredHandle phCredential, // (out) Cred Handle
  23481. PTimeStamp ptsExpiry // (out) Lifetime (optional)
  23482. );
  23483. typedef SECURITY_STATUS
  23484. (SEC_ENTRY * ACQUIRE_CREDENTIALS_HANDLE_FN_W)(
  23485. #if ISSP_MODE == 0
  23486. PSECURITY_STRING,
  23487. PSECURITY_STRING,
  23488. #else
  23489. SEC_WCHAR SEC_FAR *,
  23490. SEC_WCHAR SEC_FAR *,
  23491. #endif
  23492. unsigned long,
  23493. void SEC_FAR *,
  23494. void SEC_FAR *,
  23495. SEC_GET_KEY_FN,
  23496. void SEC_FAR *,
  23497. PCredHandle,
  23498. PTimeStamp);
  23499. # define AcquireCredentialsHandle AcquireCredentialsHandleW
  23500. # define ACQUIRE_CREDENTIALS_HANDLE_FN ACQUIRE_CREDENTIALS_HANDLE_FN_W
  23501. SECURITY_STATUS SEC_ENTRY
  23502. FreeCredentialsHandle(
  23503. PCredHandle phCredential // Handle to free
  23504. );
  23505. typedef SECURITY_STATUS
  23506. (SEC_ENTRY * FREE_CREDENTIALS_HANDLE_FN)(
  23507. PCredHandle );
  23508. SECURITY_STATUS SEC_ENTRY
  23509. AddCredentialsW(
  23510. PCredHandle hCredentials,
  23511. #if ISSP_MODE == 0 // For Kernel mode
  23512. PSECURITY_STRING pPrincipal,
  23513. PSECURITY_STRING pPackage,
  23514. #else
  23515. SEC_WCHAR SEC_FAR * pszPrincipal, // Name of principal
  23516. SEC_WCHAR SEC_FAR * pszPackage, // Name of package
  23517. #endif
  23518. unsigned long fCredentialUse, // Flags indicating use
  23519. void SEC_FAR * pAuthData, // Package specific data
  23520. SEC_GET_KEY_FN pGetKeyFn, // Pointer to GetKey() func
  23521. void SEC_FAR * pvGetKeyArgument, // Value to pass to GetKey()
  23522. PTimeStamp ptsExpiry // (out) Lifetime (optional)
  23523. );
  23524. typedef SECURITY_STATUS
  23525. (SEC_ENTRY * ADD_CREDENTIALS_FN_W)(
  23526. PCredHandle,
  23527. #if ISSP_MODE == 0
  23528. PSECURITY_STRING,
  23529. PSECURITY_STRING,
  23530. #else
  23531. SEC_WCHAR SEC_FAR *,
  23532. SEC_WCHAR SEC_FAR *,
  23533. #endif
  23534. unsigned long,
  23535. void SEC_FAR *,
  23536. SEC_GET_KEY_FN,
  23537. void SEC_FAR *,
  23538. PTimeStamp);
  23539. SECURITY_STATUS SEC_ENTRY
  23540. AddCredentialsA(
  23541. PCredHandle hCredentials,
  23542. SEC_CHAR SEC_FAR * pszPrincipal, // Name of principal
  23543. SEC_CHAR SEC_FAR * pszPackage, // Name of package
  23544. unsigned long fCredentialUse, // Flags indicating use
  23545. void SEC_FAR * pAuthData, // Package specific data
  23546. SEC_GET_KEY_FN pGetKeyFn, // Pointer to GetKey() func
  23547. void SEC_FAR * pvGetKeyArgument, // Value to pass to GetKey()
  23548. PTimeStamp ptsExpiry // (out) Lifetime (optional)
  23549. );
  23550. typedef SECURITY_STATUS
  23551. (SEC_ENTRY * ADD_CREDENTIALS_FN_A)(
  23552. PCredHandle,
  23553. SEC_CHAR SEC_FAR *,
  23554. SEC_CHAR SEC_FAR *,
  23555. unsigned long,
  23556. void SEC_FAR *,
  23557. SEC_GET_KEY_FN,
  23558. void SEC_FAR *,
  23559. PTimeStamp);
  23560. #ifdef UNICODE
  23561. #define AddCredentials AddCredentialsW
  23562. #define ADD_CREDENTIALS_FN ADD_CREDENTIALS_FN_W
  23563. #else
  23564. #define AddCredentials AddCredentialsA
  23565. #define ADD_CREDENTIALS_FN ADD_CREDENTIALS_FN_A
  23566. #endif
  23567. #define SspiLogonUser SspiLogonUserW
  23568. ////////////////////////////////////////////////////////////////////////
  23569. ///
  23570. /// Context Management Functions
  23571. ///
  23572. ////////////////////////////////////////////////////////////////////////
  23573. SECURITY_STATUS SEC_ENTRY
  23574. InitializeSecurityContextW(
  23575. PCredHandle phCredential, // Cred to base context
  23576. PCtxtHandle phContext, // Existing context (OPT)
  23577. #if ISSP_MODE == 0
  23578. PSECURITY_STRING pTargetName,
  23579. #else
  23580. SEC_WCHAR SEC_FAR * pszTargetName, // Name of target
  23581. #endif
  23582. unsigned long fContextReq, // Context Requirements
  23583. unsigned long Reserved1, // Reserved, MBZ
  23584. unsigned long TargetDataRep, // Data rep of target
  23585. PSecBufferDesc pInput, // Input Buffers
  23586. unsigned long Reserved2, // Reserved, MBZ
  23587. PCtxtHandle phNewContext, // (out) New Context handle
  23588. PSecBufferDesc pOutput, // (inout) Output Buffers
  23589. unsigned long SEC_FAR * pfContextAttr, // (out) Context attrs
  23590. PTimeStamp ptsExpiry // (out) Life span (OPT)
  23591. );
  23592. typedef SECURITY_STATUS
  23593. (SEC_ENTRY * INITIALIZE_SECURITY_CONTEXT_FN_W)(
  23594. PCredHandle,
  23595. PCtxtHandle,
  23596. #if ISSP_MODE == 0
  23597. PSECURITY_STRING,
  23598. #else
  23599. SEC_WCHAR SEC_FAR *,
  23600. #endif
  23601. unsigned long,
  23602. unsigned long,
  23603. unsigned long,
  23604. PSecBufferDesc,
  23605. unsigned long,
  23606. PCtxtHandle,
  23607. PSecBufferDesc,
  23608. unsigned long SEC_FAR *,
  23609. PTimeStamp);
  23610. # define InitializeSecurityContext InitializeSecurityContextW
  23611. # define INITIALIZE_SECURITY_CONTEXT_FN INITIALIZE_SECURITY_CONTEXT_FN_W
  23612. SECURITY_STATUS SEC_ENTRY
  23613. AcceptSecurityContext(
  23614. PCredHandle phCredential, // Cred to base context
  23615. PCtxtHandle phContext, // Existing context (OPT)
  23616. PSecBufferDesc pInput, // Input buffer
  23617. unsigned long fContextReq, // Context Requirements
  23618. unsigned long TargetDataRep, // Target Data Rep
  23619. PCtxtHandle phNewContext, // (out) New context handle
  23620. PSecBufferDesc pOutput, // (inout) Output buffers
  23621. unsigned long SEC_FAR * pfContextAttr, // (out) Context attributes
  23622. PTimeStamp ptsExpiry // (out) Life span (OPT)
  23623. );
  23624. typedef SECURITY_STATUS
  23625. (SEC_ENTRY * ACCEPT_SECURITY_CONTEXT_FN)(
  23626. PCredHandle,
  23627. PCtxtHandle,
  23628. PSecBufferDesc,
  23629. unsigned long,
  23630. unsigned long,
  23631. PCtxtHandle,
  23632. PSecBufferDesc,
  23633. unsigned long SEC_FAR *,
  23634. PTimeStamp);
  23635. SECURITY_STATUS SEC_ENTRY
  23636. CompleteAuthToken(
  23637. PCtxtHandle phContext, // Context to complete
  23638. PSecBufferDesc pToken // Token to complete
  23639. );
  23640. typedef SECURITY_STATUS
  23641. (SEC_ENTRY * COMPLETE_AUTH_TOKEN_FN)(
  23642. PCtxtHandle,
  23643. PSecBufferDesc);
  23644. SECURITY_STATUS SEC_ENTRY
  23645. ImpersonateSecurityContext(
  23646. PCtxtHandle phContext // Context to impersonate
  23647. );
  23648. typedef SECURITY_STATUS
  23649. (SEC_ENTRY * IMPERSONATE_SECURITY_CONTEXT_FN)(
  23650. PCtxtHandle);
  23651. SECURITY_STATUS SEC_ENTRY
  23652. RevertSecurityContext(
  23653. PCtxtHandle phContext // Context from which to re
  23654. );
  23655. typedef SECURITY_STATUS
  23656. (SEC_ENTRY * REVERT_SECURITY_CONTEXT_FN)(
  23657. PCtxtHandle);
  23658. SECURITY_STATUS SEC_ENTRY
  23659. QuerySecurityContextToken(
  23660. PCtxtHandle phContext,
  23661. void SEC_FAR * SEC_FAR * Token
  23662. );
  23663. typedef SECURITY_STATUS
  23664. (SEC_ENTRY * QUERY_SECURITY_CONTEXT_TOKEN_FN)(
  23665. PCtxtHandle, void SEC_FAR * SEC_FAR *);
  23666. SECURITY_STATUS SEC_ENTRY
  23667. DeleteSecurityContext(
  23668. PCtxtHandle phContext // Context to delete
  23669. );
  23670. typedef SECURITY_STATUS
  23671. (SEC_ENTRY * DELETE_SECURITY_CONTEXT_FN)(
  23672. PCtxtHandle);
  23673. SECURITY_STATUS SEC_ENTRY
  23674. ApplyControlToken(
  23675. PCtxtHandle phContext, // Context to modify
  23676. PSecBufferDesc pInput // Input token to apply
  23677. );
  23678. typedef SECURITY_STATUS
  23679. (SEC_ENTRY * APPLY_CONTROL_TOKEN_FN)(
  23680. PCtxtHandle, PSecBufferDesc);
  23681. SECURITY_STATUS SEC_ENTRY
  23682. QueryContextAttributesW(
  23683. PCtxtHandle phContext, // Context to query
  23684. unsigned long ulAttribute, // Attribute to query
  23685. void SEC_FAR * pBuffer // Buffer for attributes
  23686. );
  23687. typedef SECURITY_STATUS
  23688. (SEC_ENTRY * QUERY_CONTEXT_ATTRIBUTES_FN_W)(
  23689. PCtxtHandle,
  23690. unsigned long,
  23691. void SEC_FAR *);
  23692. # define QueryContextAttributes QueryContextAttributesW
  23693. # define QUERY_CONTEXT_ATTRIBUTES_FN QUERY_CONTEXT_ATTRIBUTES_FN_W
  23694. SECURITY_STATUS SEC_ENTRY
  23695. SetContextAttributesW(
  23696. PCtxtHandle phContext, // Context to Set
  23697. unsigned long ulAttribute, // Attribute to Set
  23698. void SEC_FAR * pBuffer, // Buffer for attributes
  23699. unsigned long cbBuffer // Size (in bytes) of Buffer
  23700. );
  23701. typedef SECURITY_STATUS
  23702. (SEC_ENTRY * SET_CONTEXT_ATTRIBUTES_FN_W)(
  23703. PCtxtHandle,
  23704. unsigned long,
  23705. void SEC_FAR *,
  23706. unsigned long );
  23707. # define SetContextAttributes SetContextAttributesW
  23708. # define SET_CONTEXT_ATTRIBUTES_FN SET_CONTEXT_ATTRIBUTES_FN_W
  23709. SECURITY_STATUS SEC_ENTRY
  23710. QueryCredentialsAttributesW(
  23711. PCredHandle phCredential, // Credential to query
  23712. unsigned long ulAttribute, // Attribute to query
  23713. void SEC_FAR * pBuffer // Buffer for attributes
  23714. );
  23715. typedef SECURITY_STATUS
  23716. (SEC_ENTRY * QUERY_CREDENTIALS_ATTRIBUTES_FN_W)(
  23717. PCredHandle,
  23718. unsigned long,
  23719. void SEC_FAR *);
  23720. # define QueryCredentialsAttributes QueryCredentialsAttributesW
  23721. # define QUERY_CREDENTIALS_ATTRIBUTES_FN QUERY_CREDENTIALS_ATTRIBUTES_FN_W
  23722. SECURITY_STATUS SEC_ENTRY
  23723. FreeContextBuffer(
  23724. void SEC_FAR * pvContextBuffer // buffer to free
  23725. );
  23726. typedef SECURITY_STATUS
  23727. (SEC_ENTRY * FREE_CONTEXT_BUFFER_FN)(
  23728. void SEC_FAR *);
  23729. ///////////////////////////////////////////////////////////////////
  23730. ////
  23731. //// Message Support API
  23732. ////
  23733. //////////////////////////////////////////////////////////////////
  23734. SECURITY_STATUS SEC_ENTRY
  23735. MakeSignature(
  23736. PCtxtHandle phContext, // Context to use
  23737. unsigned long fQOP, // Quality of Protection
  23738. PSecBufferDesc pMessage, // Message to sign
  23739. unsigned long MessageSeqNo // Message Sequence Num.
  23740. );
  23741. typedef SECURITY_STATUS
  23742. (SEC_ENTRY * MAKE_SIGNATURE_FN)(
  23743. PCtxtHandle,
  23744. unsigned long,
  23745. PSecBufferDesc,
  23746. unsigned long);
  23747. SECURITY_STATUS SEC_ENTRY
  23748. VerifySignature(
  23749. PCtxtHandle phContext, // Context to use
  23750. PSecBufferDesc pMessage, // Message to verify
  23751. unsigned long MessageSeqNo, // Sequence Num.
  23752. unsigned long SEC_FAR * pfQOP // QOP used
  23753. );
  23754. typedef SECURITY_STATUS
  23755. (SEC_ENTRY * VERIFY_SIGNATURE_FN)(
  23756. PCtxtHandle,
  23757. PSecBufferDesc,
  23758. unsigned long,
  23759. unsigned long SEC_FAR *);
  23760. SECURITY_STATUS SEC_ENTRY
  23761. EncryptMessage( PCtxtHandle phContext,
  23762. unsigned long fQOP,
  23763. PSecBufferDesc pMessage,
  23764. unsigned long MessageSeqNo);
  23765. typedef SECURITY_STATUS
  23766. (SEC_ENTRY * ENCRYPT_MESSAGE_FN)(
  23767. PCtxtHandle, unsigned long, PSecBufferDesc, unsigned long);
  23768. SECURITY_STATUS SEC_ENTRY
  23769. DecryptMessage( PCtxtHandle phContext,
  23770. PSecBufferDesc pMessage,
  23771. unsigned long MessageSeqNo,
  23772. unsigned long * pfQOP);
  23773. typedef SECURITY_STATUS
  23774. (SEC_ENTRY * DECRYPT_MESSAGE_FN)(
  23775. PCtxtHandle, PSecBufferDesc, unsigned long,
  23776. unsigned long SEC_FAR *);
  23777. ///////////////////////////////////////////////////////////////////////////
  23778. ////
  23779. //// Misc.
  23780. ////
  23781. ///////////////////////////////////////////////////////////////////////////
  23782. SECURITY_STATUS SEC_ENTRY
  23783. EnumerateSecurityPackagesW(
  23784. unsigned long SEC_FAR * pcPackages, // Receives num. packages
  23785. PSecPkgInfoW SEC_FAR * ppPackageInfo // Receives array of info
  23786. );
  23787. typedef SECURITY_STATUS
  23788. (SEC_ENTRY * ENUMERATE_SECURITY_PACKAGES_FN_W)(
  23789. unsigned long SEC_FAR *,
  23790. PSecPkgInfoW SEC_FAR *);
  23791. # define EnumerateSecurityPackages EnumerateSecurityPackagesW
  23792. # define ENUMERATE_SECURITY_PACKAGES_FN ENUMERATE_SECURITY_PACKAGES_FN_W
  23793. SECURITY_STATUS SEC_ENTRY
  23794. QuerySecurityPackageInfoW(
  23795. #if ISSP_MODE == 0
  23796. PSECURITY_STRING pPackageName,
  23797. #else
  23798. SEC_WCHAR SEC_FAR * pszPackageName, // Name of package
  23799. #endif
  23800. PSecPkgInfoW SEC_FAR *ppPackageInfo // Receives package info
  23801. );
  23802. typedef SECURITY_STATUS
  23803. (SEC_ENTRY * QUERY_SECURITY_PACKAGE_INFO_FN_W)(
  23804. #if ISSP_MODE == 0
  23805. PSECURITY_STRING,
  23806. #else
  23807. SEC_WCHAR SEC_FAR *,
  23808. #endif
  23809. PSecPkgInfoW SEC_FAR *);
  23810. # define QuerySecurityPackageInfo QuerySecurityPackageInfoW
  23811. # define QUERY_SECURITY_PACKAGE_INFO_FN QUERY_SECURITY_PACKAGE_INFO_FN_W
  23812. ///////////////////////////////////////////////////////////////////////////
  23813. ////
  23814. //// Context export/import
  23815. ////
  23816. ///////////////////////////////////////////////////////////////////////////
  23817. SECURITY_STATUS SEC_ENTRY
  23818. ExportSecurityContext(
  23819. PCtxtHandle phContext, // (in) context to export
  23820. ULONG fFlags, // (in) option flags
  23821. PSecBuffer pPackedContext, // (out) marshalled context
  23822. void SEC_FAR * SEC_FAR * pToken // (out, optional) token handle for impersonation
  23823. );
  23824. typedef SECURITY_STATUS
  23825. (SEC_ENTRY * EXPORT_SECURITY_CONTEXT_FN)(
  23826. PCtxtHandle,
  23827. ULONG,
  23828. PSecBuffer,
  23829. void SEC_FAR * SEC_FAR *
  23830. );
  23831. SECURITY_STATUS SEC_ENTRY
  23832. ImportSecurityContextW(
  23833. #if ISSP_MODE == 0
  23834. PSECURITY_STRING pszPackage,
  23835. #else
  23836. SEC_WCHAR SEC_FAR * pszPackage,
  23837. #endif
  23838. PSecBuffer pPackedContext, // (in) marshalled context
  23839. void SEC_FAR * Token, // (in, optional) handle to token for context
  23840. PCtxtHandle phContext // (out) new context handle
  23841. );
  23842. typedef SECURITY_STATUS
  23843. (SEC_ENTRY * IMPORT_SECURITY_CONTEXT_FN_W)(
  23844. #if ISSP_MODE == 0
  23845. PSECURITY_STRING,
  23846. #else
  23847. SEC_WCHAR SEC_FAR *,
  23848. #endif
  23849. PSecBuffer,
  23850. VOID SEC_FAR *,
  23851. PCtxtHandle
  23852. );
  23853. # define ImportSecurityContext ImportSecurityContextW
  23854. # define IMPORT_SECURITY_CONTEXT_FN IMPORT_SECURITY_CONTEXT_FN_W
  23855. #if ISSP_MODE == 0
  23856. NTSTATUS
  23857. NTAPI
  23858. SecMakeSPN(
  23859. IN PUNICODE_STRING ServiceClass,
  23860. IN PUNICODE_STRING ServiceName,
  23861. IN PUNICODE_STRING InstanceName OPTIONAL,
  23862. IN USHORT InstancePort OPTIONAL,
  23863. IN PUNICODE_STRING Referrer OPTIONAL,
  23864. IN OUT PUNICODE_STRING Spn,
  23865. OUT PULONG Length OPTIONAL,
  23866. IN BOOLEAN Allocate
  23867. );
  23868. NTSTATUS
  23869. NTAPI
  23870. SecMakeSPNEx(
  23871. IN PUNICODE_STRING ServiceClass,
  23872. IN PUNICODE_STRING ServiceName,
  23873. IN PUNICODE_STRING InstanceName OPTIONAL,
  23874. IN USHORT InstancePort OPTIONAL,
  23875. IN PUNICODE_STRING Referrer OPTIONAL,
  23876. IN PUNICODE_STRING TargetInfo OPTIONAL,
  23877. IN OUT PUNICODE_STRING Spn,
  23878. OUT PULONG Length OPTIONAL,
  23879. IN BOOLEAN Allocate
  23880. );
  23881. NTSTATUS
  23882. SEC_ENTRY
  23883. SecLookupAccountSid(
  23884. IN PSID Sid,
  23885. IN OUT PULONG NameSize,
  23886. OUT PUNICODE_STRING NameBuffer,
  23887. IN OUT PULONG DomainSize OPTIONAL,
  23888. OUT PUNICODE_STRING DomainBuffer OPTIONAL,
  23889. OUT PSID_NAME_USE NameUse
  23890. );
  23891. NTSTATUS
  23892. SEC_ENTRY
  23893. SecLookupAccountName(
  23894. IN PUNICODE_STRING Name,
  23895. IN OUT PULONG SidSize,
  23896. OUT PSID Sid,
  23897. OUT PSID_NAME_USE NameUse,
  23898. IN OUT PULONG DomainSize OPTIONAL,
  23899. OUT PUNICODE_STRING ReferencedDomain OPTIONAL
  23900. );
  23901. #endif
  23902. #define SECURITY_ENTRYPOINTW SEC_TEXT("InitSecurityInterfaceW")
  23903. # define SECURITY_ENTRYPOINT SECURITY_ENTRYPOINTW
  23904. #define FreeCredentialHandle FreeCredentialsHandle
  23905. typedef struct _SECURITY_FUNCTION_TABLE_W {
  23906. unsigned long dwVersion;
  23907. ENUMERATE_SECURITY_PACKAGES_FN_W EnumerateSecurityPackagesW;
  23908. QUERY_CREDENTIALS_ATTRIBUTES_FN_W QueryCredentialsAttributesW;
  23909. ACQUIRE_CREDENTIALS_HANDLE_FN_W AcquireCredentialsHandleW;
  23910. FREE_CREDENTIALS_HANDLE_FN FreeCredentialsHandle;
  23911. #ifndef WIN32_CHICAGO
  23912. void SEC_FAR * Reserved2;
  23913. #else // WIN32_CHICAGO
  23914. SSPI_LOGON_USER_FN SspiLogonUserW;
  23915. #endif // WIN32_CHICAGO
  23916. INITIALIZE_SECURITY_CONTEXT_FN_W InitializeSecurityContextW;
  23917. ACCEPT_SECURITY_CONTEXT_FN AcceptSecurityContext;
  23918. COMPLETE_AUTH_TOKEN_FN CompleteAuthToken;
  23919. DELETE_SECURITY_CONTEXT_FN DeleteSecurityContext;
  23920. APPLY_CONTROL_TOKEN_FN ApplyControlToken;
  23921. QUERY_CONTEXT_ATTRIBUTES_FN_W QueryContextAttributesW;
  23922. IMPERSONATE_SECURITY_CONTEXT_FN ImpersonateSecurityContext;
  23923. REVERT_SECURITY_CONTEXT_FN RevertSecurityContext;
  23924. MAKE_SIGNATURE_FN MakeSignature;
  23925. VERIFY_SIGNATURE_FN VerifySignature;
  23926. FREE_CONTEXT_BUFFER_FN FreeContextBuffer;
  23927. QUERY_SECURITY_PACKAGE_INFO_FN_W QuerySecurityPackageInfoW;
  23928. void SEC_FAR * Reserved3;
  23929. void SEC_FAR * Reserved4;
  23930. EXPORT_SECURITY_CONTEXT_FN ExportSecurityContext;
  23931. IMPORT_SECURITY_CONTEXT_FN_W ImportSecurityContextW;
  23932. ADD_CREDENTIALS_FN_W AddCredentialsW ;
  23933. void SEC_FAR * Reserved8;
  23934. QUERY_SECURITY_CONTEXT_TOKEN_FN QuerySecurityContextToken;
  23935. ENCRYPT_MESSAGE_FN EncryptMessage;
  23936. DECRYPT_MESSAGE_FN DecryptMessage;
  23937. SET_CONTEXT_ATTRIBUTES_FN_W SetContextAttributesW;
  23938. } SecurityFunctionTableW, SEC_FAR * PSecurityFunctionTableW;
  23939. # define SecurityFunctionTable SecurityFunctionTableW
  23940. # define PSecurityFunctionTable PSecurityFunctionTableW
  23941. #define SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION 1
  23942. #define SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_2 2
  23943. PSecurityFunctionTableW SEC_ENTRY
  23944. InitSecurityInterfaceW(
  23945. void
  23946. );
  23947. typedef PSecurityFunctionTableW
  23948. (SEC_ENTRY * INIT_SECURITY_INTERFACE_W)(void);
  23949. # define InitSecurityInterface InitSecurityInterfaceW
  23950. # define INIT_SECURITY_INTERFACE INIT_SECURITY_INTERFACE_W
  23951. #ifndef _AUTH_IDENTITY_DEFINED
  23952. #define _AUTH_IDENTITY_DEFINED
  23953. #define SEC_WINNT_AUTH_IDENTITY_ANSI 0x1
  23954. #define SEC_WINNT_AUTH_IDENTITY_UNICODE 0x2
  23955. typedef struct _SEC_WINNT_AUTH_IDENTITY_W {
  23956. unsigned short *User;
  23957. unsigned long UserLength;
  23958. unsigned short *Domain;
  23959. unsigned long DomainLength;
  23960. unsigned short *Password;
  23961. unsigned long PasswordLength;
  23962. unsigned long Flags;
  23963. } SEC_WINNT_AUTH_IDENTITY_W, *PSEC_WINNT_AUTH_IDENTITY_W;
  23964. #define SEC_WINNT_AUTH_IDENTITY SEC_WINNT_AUTH_IDENTITY_W
  23965. #define PSEC_WINNT_AUTH_IDENTITY PSEC_WINNT_AUTH_IDENTITY_W
  23966. #define _SEC_WINNT_AUTH_IDENTITY _SEC_WINNT_AUTH_IDENTITY_W
  23967. #endif
  23968. //
  23969. // This is the combined authentication identity structure that may be
  23970. // used with the negotiate package, NTLM, Kerberos, or SCHANNEL
  23971. //
  23972. #ifndef SEC_WINNT_AUTH_IDENTITY_VERSION
  23973. #define SEC_WINNT_AUTH_IDENTITY_VERSION 0x200
  23974. typedef struct _SEC_WINNT_AUTH_IDENTITY_EXW {
  23975. unsigned long Version;
  23976. unsigned long Length;
  23977. unsigned short SEC_FAR *User;
  23978. unsigned long UserLength;
  23979. unsigned short SEC_FAR *Domain;
  23980. unsigned long DomainLength;
  23981. unsigned short SEC_FAR *Password;
  23982. unsigned long PasswordLength;
  23983. unsigned long Flags;
  23984. unsigned short SEC_FAR * PackageList;
  23985. unsigned long PackageListLength;
  23986. } SEC_WINNT_AUTH_IDENTITY_EXW, *PSEC_WINNT_AUTH_IDENTITY_EXW;
  23987. #define SEC_WINNT_AUTH_IDENTITY_EX SEC_WINNT_AUTH_IDENTITY_EXW
  23988. #define PSEC_WINNT_AUTH_IDENTITY_EX PSEC_WINNT_AUTH_IDENTITY_EXW
  23989. #endif // SEC_WINNT_AUTH_IDENTITY_VERSION
  23990. //
  23991. // Common types used by negotiable security packages
  23992. //
  23993. #define SEC_WINNT_AUTH_IDENTITY_MARSHALLED 0x4 // all data is in one buffer
  23994. #define SEC_WINNT_AUTH_IDENTITY_ONLY 0x8 // these credentials are for identity only - no PAC needed
  23995. #endif // __SSPI_H__
  23996. #ifndef SECURITY_USER_DATA_DEFINED
  23997. #define SECURITY_USER_DATA_DEFINED
  23998. typedef struct _SECURITY_USER_DATA {
  23999. SECURITY_STRING UserName; // User name
  24000. SECURITY_STRING LogonDomainName; // Domain the user logged on to
  24001. SECURITY_STRING LogonServer; // Server that logged the user on
  24002. PSID pSid; // SID of user
  24003. } SECURITY_USER_DATA, *PSECURITY_USER_DATA;
  24004. typedef SECURITY_USER_DATA SecurityUserData, * PSecurityUserData;
  24005. #define UNDERSTANDS_LONG_NAMES 1
  24006. #define NO_LONG_NAMES 2
  24007. #endif // SECURITY_USER_DATA_DEFINED
  24008. HRESULT SEC_ENTRY
  24009. GetSecurityUserInfo(
  24010. IN PLUID LogonId,
  24011. IN ULONG Flags,
  24012. OUT PSecurityUserData * UserInformation
  24013. );
  24014. SECURITY_STATUS SEC_ENTRY
  24015. MapSecurityError( SECURITY_STATUS SecStatus );
  24016. //
  24017. // Define external data.
  24018. // because of indirection for all drivers external to ntoskrnl these are actually ptrs
  24019. //
  24020. #if defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
  24021. extern PBOOLEAN KdDebuggerNotPresent;
  24022. extern PBOOLEAN KdDebuggerEnabled;
  24023. #define KD_DEBUGGER_ENABLED *KdDebuggerEnabled
  24024. #define KD_DEBUGGER_NOT_PRESENT *KdDebuggerNotPresent
  24025. #else
  24026. extern BOOLEAN KdDebuggerNotPresent;
  24027. extern BOOLEAN KdDebuggerEnabled;
  24028. #define KD_DEBUGGER_ENABLED KdDebuggerEnabled
  24029. #define KD_DEBUGGER_NOT_PRESENT KdDebuggerNotPresent
  24030. #endif
  24031. VOID
  24032. KdDisableDebugger(
  24033. VOID
  24034. );
  24035. VOID
  24036. KdEnableDebugger(
  24037. VOID
  24038. );
  24039. #define VOLSNAPCONTROLTYPE ((ULONG) 'S')
  24040. #define IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES CTL_CODE(VOLSNAPCONTROLTYPE, 0, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  24041. //
  24042. // Runtime Library function prototypes.
  24043. //
  24044. NTSYSAPI
  24045. VOID
  24046. NTAPI
  24047. RtlCaptureContext (
  24048. OUT PCONTEXT ContextRecord
  24049. );
  24050. #ifdef POOL_TAGGING
  24051. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,' sfI')
  24052. #define ExAllocatePoolWithQuota(a,b) ExAllocatePoolWithQuotaTag(a,b,' sfI')
  24053. #endif
  24054. extern POBJECT_TYPE *PsThreadType;
  24055. extern POBJECT_TYPE *IoFileObjectType;
  24056. extern POBJECT_TYPE *ExEventObjectType;
  24057. extern POBJECT_TYPE *ExSemaphoreObjectType;
  24058. //
  24059. // Define exported ZwXxx routines to device drivers.
  24060. //
  24061. NTSYSAPI
  24062. NTSTATUS
  24063. NTAPI
  24064. ZwCreateEvent (
  24065. OUT PHANDLE EventHandle,
  24066. IN ACCESS_MASK DesiredAccess,
  24067. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  24068. IN EVENT_TYPE EventType,
  24069. IN BOOLEAN InitialState
  24070. );
  24071. NTSYSAPI
  24072. NTSTATUS
  24073. NTAPI
  24074. ZwCreateFile(
  24075. OUT PHANDLE FileHandle,
  24076. IN ACCESS_MASK DesiredAccess,
  24077. IN POBJECT_ATTRIBUTES ObjectAttributes,
  24078. OUT PIO_STATUS_BLOCK IoStatusBlock,
  24079. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  24080. IN ULONG FileAttributes,
  24081. IN ULONG ShareAccess,
  24082. IN ULONG CreateDisposition,
  24083. IN ULONG CreateOptions,
  24084. IN PVOID EaBuffer OPTIONAL,
  24085. IN ULONG EaLength
  24086. );
  24087. NTSYSAPI
  24088. NTSTATUS
  24089. NTAPI
  24090. ZwDeleteFile(
  24091. IN POBJECT_ATTRIBUTES ObjectAttributes
  24092. );
  24093. NTSYSAPI
  24094. NTSTATUS
  24095. NTAPI
  24096. ZwDeviceIoControlFile(
  24097. IN HANDLE FileHandle,
  24098. IN HANDLE Event OPTIONAL,
  24099. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  24100. IN PVOID ApcContext OPTIONAL,
  24101. OUT PIO_STATUS_BLOCK IoStatusBlock,
  24102. IN ULONG IoControlCode,
  24103. IN PVOID InputBuffer OPTIONAL,
  24104. IN ULONG InputBufferLength,
  24105. OUT PVOID OutputBuffer OPTIONAL,
  24106. IN ULONG OutputBufferLength
  24107. );
  24108. NTSYSAPI
  24109. NTSTATUS
  24110. NTAPI
  24111. ZwOpenFile(
  24112. OUT PHANDLE FileHandle,
  24113. IN ACCESS_MASK DesiredAccess,
  24114. IN POBJECT_ATTRIBUTES ObjectAttributes,
  24115. OUT PIO_STATUS_BLOCK IoStatusBlock,
  24116. IN ULONG ShareAccess,
  24117. IN ULONG OpenOptions
  24118. );
  24119. NTSYSAPI
  24120. NTSTATUS
  24121. NTAPI
  24122. ZwQueryDirectoryFile(
  24123. IN HANDLE FileHandle,
  24124. IN HANDLE Event OPTIONAL,
  24125. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  24126. IN PVOID ApcContext OPTIONAL,
  24127. OUT PIO_STATUS_BLOCK IoStatusBlock,
  24128. OUT PVOID FileInformation,
  24129. IN ULONG Length,
  24130. IN FILE_INFORMATION_CLASS FileInformationClass,
  24131. IN BOOLEAN ReturnSingleEntry,
  24132. IN PUNICODE_STRING FileName OPTIONAL,
  24133. IN BOOLEAN RestartScan
  24134. );
  24135. NTSYSAPI
  24136. NTSTATUS
  24137. NTAPI
  24138. ZwQueryInformationFile(
  24139. IN HANDLE FileHandle,
  24140. OUT PIO_STATUS_BLOCK IoStatusBlock,
  24141. OUT PVOID FileInformation,
  24142. IN ULONG Length,
  24143. IN FILE_INFORMATION_CLASS FileInformationClass
  24144. );
  24145. NTSYSAPI
  24146. NTSTATUS
  24147. NTAPI
  24148. ZwSetInformationFile(
  24149. IN HANDLE FileHandle,
  24150. OUT PIO_STATUS_BLOCK IoStatusBlock,
  24151. IN PVOID FileInformation,
  24152. IN ULONG Length,
  24153. IN FILE_INFORMATION_CLASS FileInformationClass
  24154. );
  24155. NTSYSAPI
  24156. NTSTATUS
  24157. NTAPI
  24158. ZwQueryVolumeInformationFile(
  24159. IN HANDLE FileHandle,
  24160. OUT PIO_STATUS_BLOCK IoStatusBlock,
  24161. OUT PVOID FsInformation,
  24162. IN ULONG Length,
  24163. IN FS_INFORMATION_CLASS FsInformationClass
  24164. );
  24165. NTSYSAPI
  24166. NTSTATUS
  24167. NTAPI
  24168. ZwReadFile(
  24169. IN HANDLE FileHandle,
  24170. IN HANDLE Event OPTIONAL,
  24171. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  24172. IN PVOID ApcContext OPTIONAL,
  24173. OUT PIO_STATUS_BLOCK IoStatusBlock,
  24174. OUT PVOID Buffer,
  24175. IN ULONG Length,
  24176. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  24177. IN PULONG Key OPTIONAL
  24178. );
  24179. NTSYSAPI
  24180. NTSTATUS
  24181. NTAPI
  24182. ZwWriteFile(
  24183. IN HANDLE FileHandle,
  24184. IN HANDLE Event OPTIONAL,
  24185. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  24186. IN PVOID ApcContext OPTIONAL,
  24187. OUT PIO_STATUS_BLOCK IoStatusBlock,
  24188. IN PVOID Buffer,
  24189. IN ULONG Length,
  24190. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  24191. IN PULONG Key OPTIONAL
  24192. );
  24193. NTSYSAPI
  24194. NTSTATUS
  24195. NTAPI
  24196. ZwFsControlFile(
  24197. IN HANDLE FileHandle,
  24198. IN HANDLE Event OPTIONAL,
  24199. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  24200. IN PVOID ApcContext OPTIONAL,
  24201. OUT PIO_STATUS_BLOCK IoStatusBlock,
  24202. IN ULONG FsControlCode,
  24203. IN PVOID InputBuffer OPTIONAL,
  24204. IN ULONG InputBufferLength,
  24205. OUT PVOID OutputBuffer OPTIONAL,
  24206. IN ULONG OutputBufferLength
  24207. );
  24208. NTSYSAPI
  24209. NTSTATUS
  24210. NTAPI
  24211. ZwClose(
  24212. IN HANDLE Handle
  24213. );
  24214. NTSYSAPI
  24215. NTSTATUS
  24216. NTAPI
  24217. ZwDuplicateObject(
  24218. IN HANDLE SourceProcessHandle,
  24219. IN HANDLE SourceHandle,
  24220. IN HANDLE TargetProcessHandle OPTIONAL,
  24221. OUT PHANDLE TargetHandle OPTIONAL,
  24222. IN ACCESS_MASK DesiredAccess,
  24223. IN ULONG HandleAttributes,
  24224. IN ULONG Options
  24225. );
  24226. NTSYSAPI
  24227. NTSTATUS
  24228. NTAPI
  24229. ZwCreateDirectoryObject(
  24230. OUT PHANDLE DirectoryHandle,
  24231. IN ACCESS_MASK DesiredAccess,
  24232. IN POBJECT_ATTRIBUTES ObjectAttributes
  24233. );
  24234. NTSYSAPI
  24235. NTSTATUS
  24236. NTAPI
  24237. ZwOpenDirectoryObject(
  24238. OUT PHANDLE DirectoryHandle,
  24239. IN ACCESS_MASK DesiredAccess,
  24240. IN POBJECT_ATTRIBUTES ObjectAttributes
  24241. );
  24242. NTSYSAPI
  24243. NTSTATUS
  24244. NTAPI
  24245. ZwOpenSymbolicLinkObject(
  24246. OUT PHANDLE LinkHandle,
  24247. IN ACCESS_MASK DesiredAccess,
  24248. IN POBJECT_ATTRIBUTES ObjectAttributes
  24249. );
  24250. NTSYSAPI
  24251. NTSTATUS
  24252. NTAPI
  24253. ZwQuerySymbolicLinkObject(
  24254. IN HANDLE LinkHandle,
  24255. IN OUT PUNICODE_STRING LinkTarget,
  24256. OUT PULONG ReturnedLength OPTIONAL
  24257. );
  24258. NTSYSAPI
  24259. NTSTATUS
  24260. NTAPI
  24261. ZwMakeTemporaryObject(
  24262. IN HANDLE Handle
  24263. );
  24264. NTSYSAPI
  24265. NTSTATUS
  24266. NTAPI
  24267. ZwCreateKey(
  24268. OUT PHANDLE KeyHandle,
  24269. IN ACCESS_MASK DesiredAccess,
  24270. IN POBJECT_ATTRIBUTES ObjectAttributes,
  24271. IN ULONG TitleIndex,
  24272. IN PUNICODE_STRING Class OPTIONAL,
  24273. IN ULONG CreateOptions,
  24274. OUT PULONG Disposition OPTIONAL
  24275. );
  24276. NTSYSAPI
  24277. NTSTATUS
  24278. NTAPI
  24279. ZwOpenKey(
  24280. OUT PHANDLE KeyHandle,
  24281. IN ACCESS_MASK DesiredAccess,
  24282. IN POBJECT_ATTRIBUTES ObjectAttributes
  24283. );
  24284. NTSYSAPI
  24285. NTSTATUS
  24286. NTAPI
  24287. ZwDeleteKey(
  24288. IN HANDLE KeyHandle
  24289. );
  24290. NTSYSAPI
  24291. NTSTATUS
  24292. NTAPI
  24293. ZwDeleteValueKey(
  24294. IN HANDLE KeyHandle,
  24295. IN PUNICODE_STRING ValueName
  24296. );
  24297. NTSYSAPI
  24298. NTSTATUS
  24299. NTAPI
  24300. ZwEnumerateKey(
  24301. IN HANDLE KeyHandle,
  24302. IN ULONG Index,
  24303. IN KEY_INFORMATION_CLASS KeyInformationClass,
  24304. OUT PVOID KeyInformation,
  24305. IN ULONG Length,
  24306. OUT PULONG ResultLength
  24307. );
  24308. NTSYSAPI
  24309. NTSTATUS
  24310. NTAPI
  24311. ZwEnumerateValueKey(
  24312. IN HANDLE KeyHandle,
  24313. IN ULONG Index,
  24314. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  24315. OUT PVOID KeyValueInformation,
  24316. IN ULONG Length,
  24317. OUT PULONG ResultLength
  24318. );
  24319. NTSYSAPI
  24320. NTSTATUS
  24321. NTAPI
  24322. ZwFlushKey(
  24323. IN HANDLE KeyHandle
  24324. );
  24325. NTSYSAPI
  24326. NTSTATUS
  24327. NTAPI
  24328. ZwQueryKey(
  24329. IN HANDLE KeyHandle,
  24330. IN KEY_INFORMATION_CLASS KeyInformationClass,
  24331. OUT PVOID KeyInformation,
  24332. IN ULONG Length,
  24333. OUT PULONG ResultLength
  24334. );
  24335. NTSYSAPI
  24336. NTSTATUS
  24337. NTAPI
  24338. ZwQueryValueKey(
  24339. IN HANDLE KeyHandle,
  24340. IN PUNICODE_STRING ValueName,
  24341. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  24342. OUT PVOID KeyValueInformation,
  24343. IN ULONG Length,
  24344. OUT PULONG ResultLength
  24345. );
  24346. NTSYSAPI
  24347. NTSTATUS
  24348. NTAPI
  24349. ZwSetValueKey(
  24350. IN HANDLE KeyHandle,
  24351. IN PUNICODE_STRING ValueName,
  24352. IN ULONG TitleIndex OPTIONAL,
  24353. IN ULONG Type,
  24354. IN PVOID Data,
  24355. IN ULONG DataSize
  24356. );
  24357. NTSYSAPI
  24358. NTSTATUS
  24359. NTAPI
  24360. ZwOpenSection(
  24361. OUT PHANDLE SectionHandle,
  24362. IN ACCESS_MASK DesiredAccess,
  24363. IN POBJECT_ATTRIBUTES ObjectAttributes
  24364. );
  24365. NTSYSAPI
  24366. NTSTATUS
  24367. NTAPI
  24368. ZwMapViewOfSection(
  24369. IN HANDLE SectionHandle,
  24370. IN HANDLE ProcessHandle,
  24371. IN OUT PVOID *BaseAddress,
  24372. IN ULONG ZeroBits,
  24373. IN ULONG CommitSize,
  24374. IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
  24375. IN OUT PSIZE_T ViewSize,
  24376. IN SECTION_INHERIT InheritDisposition,
  24377. IN ULONG AllocationType,
  24378. IN ULONG Protect
  24379. );
  24380. NTSYSAPI
  24381. NTSTATUS
  24382. NTAPI
  24383. ZwUnmapViewOfSection(
  24384. IN HANDLE ProcessHandle,
  24385. IN PVOID BaseAddress
  24386. );
  24387. NTSYSAPI
  24388. NTSTATUS
  24389. NTAPI
  24390. ZwSetInformationThread(
  24391. IN HANDLE ThreadHandle,
  24392. IN THREADINFOCLASS ThreadInformationClass,
  24393. IN PVOID ThreadInformation,
  24394. IN ULONG ThreadInformationLength
  24395. );
  24396. NTSYSAPI
  24397. NTSTATUS
  24398. NTAPI
  24399. ZwCreateSection (
  24400. OUT PHANDLE SectionHandle,
  24401. IN ACCESS_MASK DesiredAccess,
  24402. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  24403. IN PLARGE_INTEGER MaximumSize OPTIONAL,
  24404. IN ULONG SectionPageProtection,
  24405. IN ULONG AllocationAttributes,
  24406. IN HANDLE FileHandle OPTIONAL
  24407. );
  24408. NTSYSAPI
  24409. NTSTATUS
  24410. NTAPI
  24411. ZwAllocateVirtualMemory(
  24412. IN HANDLE ProcessHandle,
  24413. IN OUT PVOID *BaseAddress,
  24414. IN ULONG ZeroBits,
  24415. IN OUT PSIZE_T RegionSize,
  24416. IN ULONG AllocationType,
  24417. IN ULONG Protect
  24418. );
  24419. NTSYSAPI
  24420. NTSTATUS
  24421. NTAPI
  24422. ZwFreeVirtualMemory(
  24423. IN HANDLE ProcessHandle,
  24424. IN OUT PVOID *BaseAddress,
  24425. IN OUT PSIZE_T RegionSize,
  24426. IN ULONG FreeType
  24427. );
  24428. NTSYSAPI
  24429. NTSTATUS
  24430. NTAPI
  24431. ZwWaitForSingleObject(
  24432. IN HANDLE Handle,
  24433. IN BOOLEAN Alertable,
  24434. IN PLARGE_INTEGER Timeout OPTIONAL
  24435. );
  24436. NTSYSAPI
  24437. NTSTATUS
  24438. NTAPI
  24439. ZwSetEvent (
  24440. IN HANDLE Handle,
  24441. OUT PLONG PreviousState OPTIONAL
  24442. );
  24443. NTSYSAPI
  24444. NTSTATUS
  24445. NTAPI
  24446. ZwFlushVirtualMemory(
  24447. IN HANDLE ProcessHandle,
  24448. IN OUT PVOID *BaseAddress,
  24449. IN OUT PSIZE_T RegionSize,
  24450. OUT PIO_STATUS_BLOCK IoStatus
  24451. );
  24452. NTSYSAPI
  24453. NTSTATUS
  24454. NTAPI
  24455. ZwOpenProcessTokenEx(
  24456. IN HANDLE ProcessHandle,
  24457. IN ACCESS_MASK DesiredAccess,
  24458. IN ULONG HandleAttributes,
  24459. OUT PHANDLE TokenHandle
  24460. );
  24461. NTSYSAPI
  24462. NTSTATUS
  24463. NTAPI
  24464. ZwOpenThreadTokenEx(
  24465. IN HANDLE ThreadHandle,
  24466. IN ACCESS_MASK DesiredAccess,
  24467. IN BOOLEAN OpenAsSelf,
  24468. IN ULONG HandleAttributes,
  24469. OUT PHANDLE TokenHandle
  24470. );
  24471. NTSYSAPI
  24472. NTSTATUS
  24473. NTAPI
  24474. ZwSetInformationToken (
  24475. IN HANDLE TokenHandle,
  24476. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  24477. IN PVOID TokenInformation,
  24478. IN ULONG TokenInformationLength
  24479. );
  24480. NTSYSAPI
  24481. NTSTATUS
  24482. NTAPI
  24483. ZwQueryInformationToken (
  24484. IN HANDLE TokenHandle,
  24485. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  24486. OUT PVOID TokenInformation,
  24487. IN ULONG TokenInformationLength,
  24488. OUT PULONG ReturnLength
  24489. );
  24490. NTSYSAPI
  24491. NTSTATUS
  24492. NTAPI
  24493. ZwSetSecurityObject(
  24494. IN HANDLE Handle,
  24495. IN SECURITY_INFORMATION SecurityInformation,
  24496. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  24497. );
  24498. NTSYSAPI
  24499. NTSTATUS
  24500. NTAPI
  24501. ZwQuerySecurityObject(
  24502. IN HANDLE Handle,
  24503. IN SECURITY_INFORMATION SecurityInformation,
  24504. OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  24505. IN ULONG Length,
  24506. OUT PULONG LengthNeeded
  24507. );
  24508. NTSYSAPI
  24509. NTSTATUS
  24510. NTAPI
  24511. ZwLoadDriver(
  24512. IN PUNICODE_STRING DriverServiceName
  24513. );
  24514. NTSYSAPI
  24515. NTSTATUS
  24516. NTAPI
  24517. ZwUnloadDriver(
  24518. IN PUNICODE_STRING DriverServiceName
  24519. );
  24520. #endif // _NTIFS_