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

31219 lines
785 KiB

  1. /*++ BUILD Version: 0094 // 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. // (Logon IDs) S-1-5-5-X-Y //
  266. // Service S-1-5-6 //
  267. // AnonymousLogon S-1-5-7 (aka null logon session) //
  268. // Proxy S-1-5-8 //
  269. // Enterprise DC (EDC) S-1-5-9 (aka domain controller account) //
  270. // Self S-1-5-10 (self RID) //
  271. // Authenticated User S-1-5-11 (Authenticated user somewhere) //
  272. // Restricted Code S-1-5-12 (Running restricted code) //
  273. // Terminal Server S-1-5-13 (Running on Terminal Server) //
  274. // Remote Logon S-1-5-14 (Remote Interactive Logon) //
  275. // This Organization S-1-5-15 //
  276. // //
  277. // Local System S-1-5-18 //
  278. // Local Service S-1-5-19 //
  279. // Network Service S-1-5-20 //
  280. // //
  281. // (NT non-unique IDs) S-1-5-0x15-... (NT Domain Sids) //
  282. // //
  283. // (Built-in domain) S-1-5-0x20 //
  284. // //
  285. // (Security Package IDs) S-1-5-0x40 //
  286. // NTLM Authentication S-1-5-0x40-10 //
  287. // SChannel Authentication S-1-5-0x40-14 //
  288. // Digest Authentication S-1-5-0x40-21 //
  289. // //
  290. // Other Organization S-1-5-1000 (>=1000 can not be filtered) //
  291. // //
  292. // //
  293. // NOTE: the relative identifier values (RIDs) determine which security //
  294. // boundaries the SID is allowed to cross. Before adding new RIDs, //
  295. // a determination needs to be made regarding which range they should //
  296. // be added to in order to ensure proper "SID filtering" //
  297. // //
  298. ///////////////////////////////////////////////////////////////////////////////
  299. #define SECURITY_NT_AUTHORITY {0,0,0,0,0,5} // ntifs
  300. #define SECURITY_DIALUP_RID (0x00000001L)
  301. #define SECURITY_NETWORK_RID (0x00000002L)
  302. #define SECURITY_BATCH_RID (0x00000003L)
  303. #define SECURITY_INTERACTIVE_RID (0x00000004L)
  304. #define SECURITY_LOGON_IDS_RID (0x00000005L)
  305. #define SECURITY_LOGON_IDS_RID_COUNT (3L)
  306. #define SECURITY_SERVICE_RID (0x00000006L)
  307. #define SECURITY_ANONYMOUS_LOGON_RID (0x00000007L)
  308. #define SECURITY_PROXY_RID (0x00000008L)
  309. #define SECURITY_ENTERPRISE_CONTROLLERS_RID (0x00000009L)
  310. #define SECURITY_SERVER_LOGON_RID SECURITY_ENTERPRISE_CONTROLLERS_RID
  311. #define SECURITY_PRINCIPAL_SELF_RID (0x0000000AL)
  312. #define SECURITY_AUTHENTICATED_USER_RID (0x0000000BL)
  313. #define SECURITY_RESTRICTED_CODE_RID (0x0000000CL)
  314. #define SECURITY_TERMINAL_SERVER_RID (0x0000000DL)
  315. #define SECURITY_REMOTE_LOGON_RID (0x0000000EL)
  316. #define SECURITY_THIS_ORGANIZATION_RID (0x0000000FL)
  317. #define SECURITY_LOCAL_SYSTEM_RID (0x00000012L)
  318. #define SECURITY_LOCAL_SERVICE_RID (0x00000013L)
  319. #define SECURITY_NETWORK_SERVICE_RID (0x00000014L)
  320. #define SECURITY_NT_NON_UNIQUE (0x00000015L)
  321. #define SECURITY_NT_NON_UNIQUE_SUB_AUTH_COUNT (3L)
  322. #define SECURITY_BUILTIN_DOMAIN_RID (0x00000020L)
  323. #define SECURITY_PACKAGE_BASE_RID (0x00000040L)
  324. #define SECURITY_PACKAGE_RID_COUNT (2L)
  325. #define SECURITY_PACKAGE_NTLM_RID (0x0000000AL)
  326. #define SECURITY_PACKAGE_SCHANNEL_RID (0x0000000EL)
  327. #define SECURITY_PACKAGE_DIGEST_RID (0x00000015L)
  328. #define SECURITY_MAX_ALWAYS_FILTERED (0x000003E7L)
  329. #define SECURITY_MIN_NEVER_FILTERED (0x000003E8L)
  330. #define SECURITY_OTHER_ORGANIZATION_RID (0x000003E8L)
  331. /////////////////////////////////////////////////////////////////////////////
  332. // //
  333. // well-known domain relative sub-authority values (RIDs)... //
  334. // //
  335. /////////////////////////////////////////////////////////////////////////////
  336. // Well-known users ...
  337. #define FOREST_USER_RID_MAX (0x000001F3L)
  338. #define DOMAIN_USER_RID_ADMIN (0x000001F4L)
  339. #define DOMAIN_USER_RID_GUEST (0x000001F5L)
  340. #define DOMAIN_USER_RID_KRBTGT (0x000001F6L)
  341. #define DOMAIN_USER_RID_MAX (0x000003E7L)
  342. // well-known groups ...
  343. #define DOMAIN_GROUP_RID_ADMINS (0x00000200L)
  344. #define DOMAIN_GROUP_RID_USERS (0x00000201L)
  345. #define DOMAIN_GROUP_RID_GUESTS (0x00000202L)
  346. #define DOMAIN_GROUP_RID_COMPUTERS (0x00000203L)
  347. #define DOMAIN_GROUP_RID_CONTROLLERS (0x00000204L)
  348. #define DOMAIN_GROUP_RID_CERT_ADMINS (0x00000205L)
  349. #define DOMAIN_GROUP_RID_SCHEMA_ADMINS (0x00000206L)
  350. #define DOMAIN_GROUP_RID_ENTERPRISE_ADMINS (0x00000207L)
  351. #define DOMAIN_GROUP_RID_POLICY_ADMINS (0x00000208L)
  352. // well-known aliases ...
  353. #define DOMAIN_ALIAS_RID_ADMINS (0x00000220L)
  354. #define DOMAIN_ALIAS_RID_USERS (0x00000221L)
  355. #define DOMAIN_ALIAS_RID_GUESTS (0x00000222L)
  356. #define DOMAIN_ALIAS_RID_POWER_USERS (0x00000223L)
  357. #define DOMAIN_ALIAS_RID_ACCOUNT_OPS (0x00000224L)
  358. #define DOMAIN_ALIAS_RID_SYSTEM_OPS (0x00000225L)
  359. #define DOMAIN_ALIAS_RID_PRINT_OPS (0x00000226L)
  360. #define DOMAIN_ALIAS_RID_BACKUP_OPS (0x00000227L)
  361. #define DOMAIN_ALIAS_RID_REPLICATOR (0x00000228L)
  362. #define DOMAIN_ALIAS_RID_RAS_SERVERS (0x00000229L)
  363. #define DOMAIN_ALIAS_RID_PREW2KCOMPACCESS (0x0000022AL)
  364. #define DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS (0x0000022BL)
  365. #define DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS (0x0000022CL)
  366. #define DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS (0x0000022DL)
  367. #define DOMAIN_ALIAS_RID_MONITORING_USERS (0x0000022EL)
  368. #define DOMAIN_ALIAS_RID_LOGGING_USERS (0x0000022FL)
  369. #define DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS (0x00000230L)
  370. #define DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS (0x00000231L)
  371. typedef enum {
  372. WinNullSid = 0,
  373. WinWorldSid = 1,
  374. WinLocalSid = 2,
  375. WinCreatorOwnerSid = 3,
  376. WinCreatorGroupSid = 4,
  377. WinCreatorOwnerServerSid = 5,
  378. WinCreatorGroupServerSid = 6,
  379. WinNtAuthoritySid = 7,
  380. WinDialupSid = 8,
  381. WinNetworkSid = 9,
  382. WinBatchSid = 10,
  383. WinInteractiveSid = 11,
  384. WinServiceSid = 12,
  385. WinAnonymousSid = 13,
  386. WinProxySid = 14,
  387. WinEnterpriseControllersSid = 15,
  388. WinSelfSid = 16,
  389. WinAuthenticatedUserSid = 17,
  390. WinRestrictedCodeSid = 18,
  391. WinTerminalServerSid = 19,
  392. WinRemoteLogonIdSid = 20,
  393. WinLogonIdsSid = 21,
  394. WinLocalSystemSid = 22,
  395. WinLocalServiceSid = 23,
  396. WinNetworkServiceSid = 24,
  397. WinBuiltinDomainSid = 25,
  398. WinBuiltinAdministratorsSid = 26,
  399. WinBuiltinUsersSid = 27,
  400. WinBuiltinGuestsSid = 28,
  401. WinBuiltinPowerUsersSid = 29,
  402. WinBuiltinAccountOperatorsSid = 30,
  403. WinBuiltinSystemOperatorsSid = 31,
  404. WinBuiltinPrintOperatorsSid = 32,
  405. WinBuiltinBackupOperatorsSid = 33,
  406. WinBuiltinReplicatorSid = 34,
  407. WinBuiltinPreWindows2000CompatibleAccessSid = 35,
  408. WinBuiltinRemoteDesktopUsersSid = 36,
  409. WinBuiltinNetworkConfigurationOperatorsSid = 37,
  410. WinAccountAdministratorSid = 38,
  411. WinAccountGuestSid = 39,
  412. WinAccountKrbtgtSid = 40,
  413. WinAccountDomainAdminsSid = 41,
  414. WinAccountDomainUsersSid = 42,
  415. WinAccountDomainGuestsSid = 43,
  416. WinAccountComputersSid = 44,
  417. WinAccountControllersSid = 45,
  418. WinAccountCertAdminsSid = 46,
  419. WinAccountSchemaAdminsSid = 47,
  420. WinAccountEnterpriseAdminsSid = 48,
  421. WinAccountPolicyAdminsSid = 49,
  422. WinAccountRasAndIasServersSid = 50,
  423. WinNTLMAuthenticationSid = 51,
  424. WinDigestAuthenticationSid = 52,
  425. WinSChannelAuthenticationSid = 53,
  426. WinThisOrganizationSid = 54,
  427. WinOtherOrganizationSid = 55,
  428. WinBuiltinIncomingForestTrustBuildersSid = 56,
  429. WinBuiltinPerfMonitoringUsersSid = 57,
  430. WinBuiltinPerfLoggingUsersSid = 58,
  431. WinBuiltinAuthorizationAccessSid = 59,
  432. WinBuiltinTerminalServerLicenseServersSid = 60,
  433. } WELL_KNOWN_SID_TYPE;
  434. //
  435. // Allocate the System Luid. The first 1000 LUIDs are reserved.
  436. // Use #999 here (0x3E7 = 999)
  437. //
  438. #define SYSTEM_LUID { 0x3E7, 0x0 }
  439. #define ANONYMOUS_LOGON_LUID { 0x3e6, 0x0 }
  440. #define LOCALSERVICE_LUID { 0x3e5, 0x0 }
  441. #define NETWORKSERVICE_LUID { 0x3e4, 0x0 }
  442. // This is the *current* ACL revision
  443. #define ACL_REVISION (2)
  444. #define ACL_REVISION_DS (4)
  445. // This is the history of ACL revisions. Add a new one whenever
  446. // ACL_REVISION is updated
  447. #define ACL_REVISION1 (1)
  448. #define MIN_ACL_REVISION ACL_REVISION2
  449. #define ACL_REVISION2 (2)
  450. #define ACL_REVISION3 (3)
  451. #define ACL_REVISION4 (4)
  452. #define MAX_ACL_REVISION ACL_REVISION4
  453. typedef struct _ACL {
  454. UCHAR AclRevision;
  455. UCHAR Sbz1;
  456. USHORT AclSize;
  457. USHORT AceCount;
  458. USHORT Sbz2;
  459. } ACL;
  460. typedef ACL *PACL;
  461. // end_ntddk end_wdm
  462. //
  463. // The structure of an ACE is a common ace header followed by ace type
  464. // specific data. Pictorally the structure of the common ace header is
  465. // as follows:
  466. //
  467. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  468. // 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
  469. // +---------------+-------+-------+---------------+---------------+
  470. // | AceSize | AceFlags | AceType |
  471. // +---------------+-------+-------+---------------+---------------+
  472. //
  473. // AceType denotes the type of the ace, there are some predefined ace
  474. // types
  475. //
  476. // AceSize is the size, in bytes, of ace.
  477. //
  478. // AceFlags are the Ace flags for audit and inheritance, defined shortly.
  479. typedef struct _ACE_HEADER {
  480. UCHAR AceType;
  481. UCHAR AceFlags;
  482. USHORT AceSize;
  483. } ACE_HEADER;
  484. typedef ACE_HEADER *PACE_HEADER;
  485. //
  486. // The following are the predefined ace types that go into the AceType
  487. // field of an Ace header.
  488. //
  489. #define ACCESS_MIN_MS_ACE_TYPE (0x0)
  490. #define ACCESS_ALLOWED_ACE_TYPE (0x0)
  491. #define ACCESS_DENIED_ACE_TYPE (0x1)
  492. #define SYSTEM_AUDIT_ACE_TYPE (0x2)
  493. #define SYSTEM_ALARM_ACE_TYPE (0x3)
  494. #define ACCESS_MAX_MS_V2_ACE_TYPE (0x3)
  495. #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE (0x4)
  496. #define ACCESS_MAX_MS_V3_ACE_TYPE (0x4)
  497. #define ACCESS_MIN_MS_OBJECT_ACE_TYPE (0x5)
  498. #define ACCESS_ALLOWED_OBJECT_ACE_TYPE (0x5)
  499. #define ACCESS_DENIED_OBJECT_ACE_TYPE (0x6)
  500. #define SYSTEM_AUDIT_OBJECT_ACE_TYPE (0x7)
  501. #define SYSTEM_ALARM_OBJECT_ACE_TYPE (0x8)
  502. #define ACCESS_MAX_MS_OBJECT_ACE_TYPE (0x8)
  503. #define ACCESS_MAX_MS_V4_ACE_TYPE (0x8)
  504. #define ACCESS_MAX_MS_ACE_TYPE (0x8)
  505. #define ACCESS_ALLOWED_CALLBACK_ACE_TYPE (0x9)
  506. #define ACCESS_DENIED_CALLBACK_ACE_TYPE (0xA)
  507. #define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE (0xB)
  508. #define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE (0xC)
  509. #define SYSTEM_AUDIT_CALLBACK_ACE_TYPE (0xD)
  510. #define SYSTEM_ALARM_CALLBACK_ACE_TYPE (0xE)
  511. #define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE (0xF)
  512. #define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE (0x10)
  513. #define ACCESS_MAX_MS_V5_ACE_TYPE (0x10)
  514. // end_winnt
  515. // begin_winnt
  516. //
  517. // The following are the inherit flags that go into the AceFlags field
  518. // of an Ace header.
  519. //
  520. #define OBJECT_INHERIT_ACE (0x1)
  521. #define CONTAINER_INHERIT_ACE (0x2)
  522. #define NO_PROPAGATE_INHERIT_ACE (0x4)
  523. #define INHERIT_ONLY_ACE (0x8)
  524. #define INHERITED_ACE (0x10)
  525. #define VALID_INHERIT_FLAGS (0x1F)
  526. // The following are the currently defined ACE flags that go into the
  527. // AceFlags field of an ACE header. Each ACE type has its own set of
  528. // AceFlags.
  529. //
  530. // SUCCESSFUL_ACCESS_ACE_FLAG - used only with system audit and alarm ACE
  531. // types to indicate that a message is generated for successful accesses.
  532. //
  533. // FAILED_ACCESS_ACE_FLAG - used only with system audit and alarm ACE types
  534. // to indicate that a message is generated for failed accesses.
  535. //
  536. //
  537. // SYSTEM_AUDIT and SYSTEM_ALARM AceFlags
  538. //
  539. // These control the signaling of audit and alarms for success or failure.
  540. //
  541. #define SUCCESSFUL_ACCESS_ACE_FLAG (0x40)
  542. #define FAILED_ACCESS_ACE_FLAG (0x80)
  543. //
  544. // We'll define the structure of the predefined ACE types. Pictorally
  545. // the structure of the predefined ACE's is as follows:
  546. //
  547. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  548. // 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
  549. // +---------------+-------+-------+---------------+---------------+
  550. // | AceFlags | Resd |Inherit| AceSize | AceType |
  551. // +---------------+-------+-------+---------------+---------------+
  552. // | Mask |
  553. // +---------------------------------------------------------------+
  554. // | |
  555. // + +
  556. // | |
  557. // + Sid +
  558. // | |
  559. // + +
  560. // | |
  561. // +---------------------------------------------------------------+
  562. //
  563. // Mask is the access mask associated with the ACE. This is either the
  564. // access allowed, access denied, audit, or alarm mask.
  565. //
  566. // Sid is the Sid associated with the ACE.
  567. //
  568. // The following are the four predefined ACE types.
  569. // Examine the AceType field in the Header to determine
  570. // which structure is appropriate to use for casting.
  571. typedef struct _ACCESS_ALLOWED_ACE {
  572. ACE_HEADER Header;
  573. ACCESS_MASK Mask;
  574. ULONG SidStart;
  575. } ACCESS_ALLOWED_ACE;
  576. typedef ACCESS_ALLOWED_ACE *PACCESS_ALLOWED_ACE;
  577. typedef struct _ACCESS_DENIED_ACE {
  578. ACE_HEADER Header;
  579. ACCESS_MASK Mask;
  580. ULONG SidStart;
  581. } ACCESS_DENIED_ACE;
  582. typedef ACCESS_DENIED_ACE *PACCESS_DENIED_ACE;
  583. typedef struct _SYSTEM_AUDIT_ACE {
  584. ACE_HEADER Header;
  585. ACCESS_MASK Mask;
  586. ULONG SidStart;
  587. } SYSTEM_AUDIT_ACE;
  588. typedef SYSTEM_AUDIT_ACE *PSYSTEM_AUDIT_ACE;
  589. typedef struct _SYSTEM_ALARM_ACE {
  590. ACE_HEADER Header;
  591. ACCESS_MASK Mask;
  592. ULONG SidStart;
  593. } SYSTEM_ALARM_ACE;
  594. typedef SYSTEM_ALARM_ACE *PSYSTEM_ALARM_ACE;
  595. //
  596. // Current security descriptor revision value
  597. //
  598. #define SECURITY_DESCRIPTOR_REVISION (1)
  599. #define SECURITY_DESCRIPTOR_REVISION1 (1)
  600. // end_wdm end_ntddk
  601. #define SECURITY_DESCRIPTOR_MIN_LENGTH (sizeof(SECURITY_DESCRIPTOR))
  602. typedef USHORT SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
  603. #define SE_OWNER_DEFAULTED (0x0001)
  604. #define SE_GROUP_DEFAULTED (0x0002)
  605. #define SE_DACL_PRESENT (0x0004)
  606. #define SE_DACL_DEFAULTED (0x0008)
  607. #define SE_SACL_PRESENT (0x0010)
  608. #define SE_SACL_DEFAULTED (0x0020)
  609. // end_winnt
  610. #define SE_DACL_UNTRUSTED (0x0040)
  611. #define SE_SERVER_SECURITY (0x0080)
  612. // begin_winnt
  613. #define SE_DACL_AUTO_INHERIT_REQ (0x0100)
  614. #define SE_SACL_AUTO_INHERIT_REQ (0x0200)
  615. #define SE_DACL_AUTO_INHERITED (0x0400)
  616. #define SE_SACL_AUTO_INHERITED (0x0800)
  617. #define SE_DACL_PROTECTED (0x1000)
  618. #define SE_SACL_PROTECTED (0x2000)
  619. #define SE_RM_CONTROL_VALID (0x4000)
  620. #define SE_SELF_RELATIVE (0x8000)
  621. //
  622. // Where:
  623. //
  624. // SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the
  625. // SID pointed to by the Owner field was provided by a
  626. // defaulting mechanism rather than explicitly provided by the
  627. // original provider of the security descriptor. This may
  628. // affect the treatment of the SID with respect to inheritence
  629. // of an owner.
  630. //
  631. // SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the
  632. // SID in the Group field was provided by a defaulting mechanism
  633. // rather than explicitly provided by the original provider of
  634. // the security descriptor. This may affect the treatment of
  635. // the SID with respect to inheritence of a primary group.
  636. //
  637. // SE_DACL_PRESENT - This boolean flag, when set, indicates that the
  638. // security descriptor contains a discretionary ACL. If this
  639. // flag is set and the Dacl field of the SECURITY_DESCRIPTOR is
  640. // null, then a null ACL is explicitly being specified.
  641. //
  642. // SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the
  643. // ACL pointed to by the Dacl field was provided by a defaulting
  644. // mechanism rather than explicitly provided by the original
  645. // provider of the security descriptor. This may affect the
  646. // treatment of the ACL with respect to inheritence of an ACL.
  647. // This flag is ignored if the DaclPresent flag is not set.
  648. //
  649. // SE_SACL_PRESENT - This boolean flag, when set, indicates that the
  650. // security descriptor contains a system ACL pointed to by the
  651. // Sacl field. If this flag is set and the Sacl field of the
  652. // SECURITY_DESCRIPTOR is null, then an empty (but present)
  653. // ACL is being specified.
  654. //
  655. // SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the
  656. // ACL pointed to by the Sacl field was provided by a defaulting
  657. // mechanism rather than explicitly provided by the original
  658. // provider of the security descriptor. This may affect the
  659. // treatment of the ACL with respect to inheritence of an ACL.
  660. // This flag is ignored if the SaclPresent flag is not set.
  661. //
  662. // end_winnt
  663. // SE_DACL_TRUSTED - This boolean flag, when set, indicates that the
  664. // ACL pointed to by the Dacl field was provided by a trusted source
  665. // and does not require any editing of compound ACEs. If this flag
  666. // is not set and a compound ACE is encountered, the system will
  667. // substitute known valid SIDs for the server SIDs in the ACEs.
  668. //
  669. // SE_SERVER_SECURITY - This boolean flag, when set, indicates that the
  670. // caller wishes the system to create a Server ACL based on the
  671. // input ACL, regardess of its source (explicit or defaulting.
  672. // This is done by replacing all of the GRANT ACEs with compound
  673. // ACEs granting the current server. This flag is only
  674. // meaningful if the subject is impersonating.
  675. //
  676. // begin_winnt
  677. // SE_SELF_RELATIVE - This boolean flag, when set, indicates that the
  678. // security descriptor is in self-relative form. In this form,
  679. // all fields of the security descriptor are contiguous in memory
  680. // and all pointer fields are expressed as offsets from the
  681. // beginning of the security descriptor. This form is useful
  682. // for treating security descriptors as opaque data structures
  683. // for transmission in communication protocol or for storage on
  684. // secondary media.
  685. //
  686. //
  687. //
  688. // Pictorially the structure of a security descriptor is as follows:
  689. //
  690. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  691. // 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
  692. // +---------------------------------------------------------------+
  693. // | Control |Reserved1 (SBZ)| Revision |
  694. // +---------------------------------------------------------------+
  695. // | Owner |
  696. // +---------------------------------------------------------------+
  697. // | Group |
  698. // +---------------------------------------------------------------+
  699. // | Sacl |
  700. // +---------------------------------------------------------------+
  701. // | Dacl |
  702. // +---------------------------------------------------------------+
  703. //
  704. // In general, this data structure should be treated opaquely to ensure future
  705. // compatibility.
  706. //
  707. //
  708. typedef struct _SECURITY_DESCRIPTOR_RELATIVE {
  709. UCHAR Revision;
  710. UCHAR Sbz1;
  711. SECURITY_DESCRIPTOR_CONTROL Control;
  712. ULONG Owner;
  713. ULONG Group;
  714. ULONG Sacl;
  715. ULONG Dacl;
  716. } SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
  717. typedef struct _SECURITY_DESCRIPTOR {
  718. UCHAR Revision;
  719. UCHAR Sbz1;
  720. SECURITY_DESCRIPTOR_CONTROL Control;
  721. PSID Owner;
  722. PSID Group;
  723. PACL Sacl;
  724. PACL Dacl;
  725. } SECURITY_DESCRIPTOR, *PISECURITY_DESCRIPTOR;
  726. ////////////////////////////////////////////////////////////////////////
  727. // //
  728. // Object Type list for AccessCheckByType //
  729. // //
  730. ////////////////////////////////////////////////////////////////////////
  731. typedef struct _OBJECT_TYPE_LIST {
  732. USHORT Level;
  733. USHORT Sbz;
  734. GUID *ObjectType;
  735. } OBJECT_TYPE_LIST, *POBJECT_TYPE_LIST;
  736. //
  737. // DS values for Level
  738. //
  739. #define ACCESS_OBJECT_GUID 0
  740. #define ACCESS_PROPERTY_SET_GUID 1
  741. #define ACCESS_PROPERTY_GUID 2
  742. #define ACCESS_MAX_LEVEL 4
  743. //
  744. // Parameters to NtAccessCheckByTypeAndAditAlarm
  745. //
  746. typedef enum _AUDIT_EVENT_TYPE {
  747. AuditEventObjectAccess,
  748. AuditEventDirectoryServiceAccess
  749. } AUDIT_EVENT_TYPE, *PAUDIT_EVENT_TYPE;
  750. #define AUDIT_ALLOW_NO_PRIVILEGE 0x1
  751. //
  752. // DS values for Source and ObjectTypeName
  753. //
  754. #define ACCESS_DS_SOURCE_A "DS"
  755. #define ACCESS_DS_SOURCE_W L"DS"
  756. #define ACCESS_DS_OBJECT_TYPE_NAME_A "Directory Service Object"
  757. #define ACCESS_DS_OBJECT_TYPE_NAME_W L"Directory Service Object"
  758. ////////////////////////////////////////////////////////////////////////
  759. // //
  760. // Privilege Related Data Structures //
  761. // //
  762. ////////////////////////////////////////////////////////////////////////
  763. // begin_wdm begin_ntddk begin_nthal
  764. //
  765. // Privilege attributes
  766. //
  767. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  768. #define SE_PRIVILEGE_ENABLED (0x00000002L)
  769. #define SE_PRIVILEGE_REMOVED (0X00000004L)
  770. #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
  771. //
  772. // Privilege Set Control flags
  773. //
  774. #define PRIVILEGE_SET_ALL_NECESSARY (1)
  775. //
  776. // Privilege Set - This is defined for a privilege set of one.
  777. // If more than one privilege is needed, then this structure
  778. // will need to be allocated with more space.
  779. //
  780. // Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  781. // structure (defined in se.h)
  782. //
  783. typedef struct _PRIVILEGE_SET {
  784. ULONG PrivilegeCount;
  785. ULONG Control;
  786. LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  787. } PRIVILEGE_SET, * PPRIVILEGE_SET;
  788. //
  789. // These must be converted to LUIDs before use.
  790. //
  791. #define SE_MIN_WELL_KNOWN_PRIVILEGE (2L)
  792. #define SE_CREATE_TOKEN_PRIVILEGE (2L)
  793. #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE (3L)
  794. #define SE_LOCK_MEMORY_PRIVILEGE (4L)
  795. #define SE_INCREASE_QUOTA_PRIVILEGE (5L)
  796. // end_wdm
  797. //
  798. // Unsolicited Input is obsolete and unused.
  799. //
  800. #define SE_UNSOLICITED_INPUT_PRIVILEGE (6L)
  801. // begin_wdm
  802. #define SE_MACHINE_ACCOUNT_PRIVILEGE (6L)
  803. #define SE_TCB_PRIVILEGE (7L)
  804. #define SE_SECURITY_PRIVILEGE (8L)
  805. #define SE_TAKE_OWNERSHIP_PRIVILEGE (9L)
  806. #define SE_LOAD_DRIVER_PRIVILEGE (10L)
  807. #define SE_SYSTEM_PROFILE_PRIVILEGE (11L)
  808. #define SE_SYSTEMTIME_PRIVILEGE (12L)
  809. #define SE_PROF_SINGLE_PROCESS_PRIVILEGE (13L)
  810. #define SE_INC_BASE_PRIORITY_PRIVILEGE (14L)
  811. #define SE_CREATE_PAGEFILE_PRIVILEGE (15L)
  812. #define SE_CREATE_PERMANENT_PRIVILEGE (16L)
  813. #define SE_BACKUP_PRIVILEGE (17L)
  814. #define SE_RESTORE_PRIVILEGE (18L)
  815. #define SE_SHUTDOWN_PRIVILEGE (19L)
  816. #define SE_DEBUG_PRIVILEGE (20L)
  817. #define SE_AUDIT_PRIVILEGE (21L)
  818. #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE (22L)
  819. #define SE_CHANGE_NOTIFY_PRIVILEGE (23L)
  820. #define SE_REMOTE_SHUTDOWN_PRIVILEGE (24L)
  821. #define SE_UNDOCK_PRIVILEGE (25L)
  822. #define SE_SYNC_AGENT_PRIVILEGE (26L)
  823. #define SE_ENABLE_DELEGATION_PRIVILEGE (27L)
  824. #define SE_MANAGE_VOLUME_PRIVILEGE (28L)
  825. #define SE_IMPERSONATE_PRIVILEGE (29L)
  826. #define SE_CREATE_GLOBAL_PRIVILEGE (30L)
  827. #define SE_MAX_WELL_KNOWN_PRIVILEGE (SE_CREATE_GLOBAL_PRIVILEGE)
  828. //
  829. // Impersonation Level
  830. //
  831. // Impersonation level is represented by a pair of bits in Windows.
  832. // If a new impersonation level is added or lowest value is changed from
  833. // 0 to something else, fix the Windows CreateFile call.
  834. //
  835. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  836. SecurityAnonymous,
  837. SecurityIdentification,
  838. SecurityImpersonation,
  839. SecurityDelegation
  840. } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  841. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  842. #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
  843. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  844. #define VALID_IMPERSONATION_LEVEL(L) (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL))
  845. ////////////////////////////////////////////////////////////////////
  846. // //
  847. // Token Object Definitions //
  848. // //
  849. // //
  850. ////////////////////////////////////////////////////////////////////
  851. //
  852. // Token Specific Access Rights.
  853. //
  854. #define TOKEN_ASSIGN_PRIMARY (0x0001)
  855. #define TOKEN_DUPLICATE (0x0002)
  856. #define TOKEN_IMPERSONATE (0x0004)
  857. #define TOKEN_QUERY (0x0008)
  858. #define TOKEN_QUERY_SOURCE (0x0010)
  859. #define TOKEN_ADJUST_PRIVILEGES (0x0020)
  860. #define TOKEN_ADJUST_GROUPS (0x0040)
  861. #define TOKEN_ADJUST_DEFAULT (0x0080)
  862. #define TOKEN_ADJUST_SESSIONID (0x0100)
  863. #define TOKEN_ALL_ACCESS_P (STANDARD_RIGHTS_REQUIRED |\
  864. TOKEN_ASSIGN_PRIMARY |\
  865. TOKEN_DUPLICATE |\
  866. TOKEN_IMPERSONATE |\
  867. TOKEN_QUERY |\
  868. TOKEN_QUERY_SOURCE |\
  869. TOKEN_ADJUST_PRIVILEGES |\
  870. TOKEN_ADJUST_GROUPS |\
  871. TOKEN_ADJUST_DEFAULT )
  872. #if ((defined(_WIN32_WINNT) && (_WIN32_WINNT > 0x0400)) || (!defined(_WIN32_WINNT)))
  873. #define TOKEN_ALL_ACCESS (TOKEN_ALL_ACCESS_P |\
  874. TOKEN_ADJUST_SESSIONID )
  875. #else
  876. #define TOKEN_ALL_ACCESS (TOKEN_ALL_ACCESS_P)
  877. #endif
  878. #define TOKEN_READ (STANDARD_RIGHTS_READ |\
  879. TOKEN_QUERY)
  880. #define TOKEN_WRITE (STANDARD_RIGHTS_WRITE |\
  881. TOKEN_ADJUST_PRIVILEGES |\
  882. TOKEN_ADJUST_GROUPS |\
  883. TOKEN_ADJUST_DEFAULT)
  884. #define TOKEN_EXECUTE (STANDARD_RIGHTS_EXECUTE)
  885. //
  886. //
  887. // Token Types
  888. //
  889. typedef enum _TOKEN_TYPE {
  890. TokenPrimary = 1,
  891. TokenImpersonation
  892. } TOKEN_TYPE;
  893. typedef TOKEN_TYPE *PTOKEN_TYPE;
  894. //
  895. // Token Information Classes.
  896. //
  897. typedef enum _TOKEN_INFORMATION_CLASS {
  898. TokenUser = 1,
  899. TokenGroups,
  900. TokenPrivileges,
  901. TokenOwner,
  902. TokenPrimaryGroup,
  903. TokenDefaultDacl,
  904. TokenSource,
  905. TokenType,
  906. TokenImpersonationLevel,
  907. TokenStatistics,
  908. TokenRestrictedSids,
  909. TokenSessionId,
  910. TokenGroupsAndPrivileges,
  911. TokenSessionReference,
  912. TokenSandBoxInert,
  913. TokenAuditPolicy,
  914. TokenOrigin,
  915. MaxTokenInfoClass // MaxTokenInfoClass should always be the last enum
  916. } TOKEN_INFORMATION_CLASS, *PTOKEN_INFORMATION_CLASS;
  917. //
  918. // Token information class structures
  919. //
  920. typedef struct _TOKEN_USER {
  921. SID_AND_ATTRIBUTES User;
  922. } TOKEN_USER, *PTOKEN_USER;
  923. typedef struct _TOKEN_GROUPS {
  924. ULONG GroupCount;
  925. SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
  926. } TOKEN_GROUPS, *PTOKEN_GROUPS;
  927. typedef struct _TOKEN_PRIVILEGES {
  928. ULONG PrivilegeCount;
  929. LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
  930. } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
  931. typedef struct _TOKEN_OWNER {
  932. PSID Owner;
  933. } TOKEN_OWNER, *PTOKEN_OWNER;
  934. typedef struct _TOKEN_PRIMARY_GROUP {
  935. PSID PrimaryGroup;
  936. } TOKEN_PRIMARY_GROUP, *PTOKEN_PRIMARY_GROUP;
  937. typedef struct _TOKEN_DEFAULT_DACL {
  938. PACL DefaultDacl;
  939. } TOKEN_DEFAULT_DACL, *PTOKEN_DEFAULT_DACL;
  940. typedef struct _TOKEN_GROUPS_AND_PRIVILEGES {
  941. ULONG SidCount;
  942. ULONG SidLength;
  943. PSID_AND_ATTRIBUTES Sids;
  944. ULONG RestrictedSidCount;
  945. ULONG RestrictedSidLength;
  946. PSID_AND_ATTRIBUTES RestrictedSids;
  947. ULONG PrivilegeCount;
  948. ULONG PrivilegeLength;
  949. PLUID_AND_ATTRIBUTES Privileges;
  950. LUID AuthenticationId;
  951. } TOKEN_GROUPS_AND_PRIVILEGES, *PTOKEN_GROUPS_AND_PRIVILEGES;
  952. //
  953. // Valid bits for each TOKEN_AUDIT_POLICY policy mask field.
  954. //
  955. #define TOKEN_AUDIT_SUCCESS_INCLUDE 0x1
  956. #define TOKEN_AUDIT_SUCCESS_EXCLUDE 0x2
  957. #define TOKEN_AUDIT_FAILURE_INCLUDE 0x4
  958. #define TOKEN_AUDIT_FAILURE_EXCLUDE 0x8
  959. #define VALID_AUDIT_POLICY_BITS (TOKEN_AUDIT_SUCCESS_INCLUDE | \
  960. TOKEN_AUDIT_SUCCESS_EXCLUDE | \
  961. TOKEN_AUDIT_FAILURE_INCLUDE | \
  962. TOKEN_AUDIT_FAILURE_EXCLUDE)
  963. #define VALID_TOKEN_AUDIT_POLICY_ELEMENT(P) ((((P).PolicyMask & ~VALID_AUDIT_POLICY_BITS) == 0) && \
  964. ((P).Category <= AuditEventMaxType))
  965. typedef struct _TOKEN_AUDIT_POLICY_ELEMENT {
  966. ULONG Category;
  967. ULONG PolicyMask;
  968. } TOKEN_AUDIT_POLICY_ELEMENT, *PTOKEN_AUDIT_POLICY_ELEMENT;
  969. typedef struct _TOKEN_AUDIT_POLICY {
  970. ULONG PolicyCount;
  971. TOKEN_AUDIT_POLICY_ELEMENT Policy[ANYSIZE_ARRAY];
  972. } TOKEN_AUDIT_POLICY, *PTOKEN_AUDIT_POLICY;
  973. #define PER_USER_AUDITING_POLICY_SIZE(p) \
  974. ( sizeof(TOKEN_AUDIT_POLICY) + (((p)->PolicyCount > ANYSIZE_ARRAY) ? (sizeof(TOKEN_AUDIT_POLICY_ELEMENT) * ((p)->PolicyCount - ANYSIZE_ARRAY)) : 0) )
  975. #define PER_USER_AUDITING_POLICY_SIZE_BY_COUNT(C) \
  976. ( sizeof(TOKEN_AUDIT_POLICY) + (((C) > ANYSIZE_ARRAY) ? (sizeof(TOKEN_AUDIT_POLICY_ELEMENT) * ((C) - ANYSIZE_ARRAY)) : 0) )
  977. #define TOKEN_SOURCE_LENGTH 8
  978. typedef struct _TOKEN_SOURCE {
  979. CHAR SourceName[TOKEN_SOURCE_LENGTH];
  980. LUID SourceIdentifier;
  981. } TOKEN_SOURCE, *PTOKEN_SOURCE;
  982. typedef struct _TOKEN_STATISTICS {
  983. LUID TokenId;
  984. LUID AuthenticationId;
  985. LARGE_INTEGER ExpirationTime;
  986. TOKEN_TYPE TokenType;
  987. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  988. ULONG DynamicCharged;
  989. ULONG DynamicAvailable;
  990. ULONG GroupCount;
  991. ULONG PrivilegeCount;
  992. LUID ModifiedId;
  993. } TOKEN_STATISTICS, *PTOKEN_STATISTICS;
  994. typedef struct _TOKEN_CONTROL {
  995. LUID TokenId;
  996. LUID AuthenticationId;
  997. LUID ModifiedId;
  998. TOKEN_SOURCE TokenSource;
  999. } TOKEN_CONTROL, *PTOKEN_CONTROL;
  1000. typedef struct _TOKEN_ORIGIN {
  1001. LUID OriginatingLogonSession ;
  1002. } TOKEN_ORIGIN, * PTOKEN_ORIGIN ;
  1003. // end_winnt
  1004. //
  1005. // Security Tracking Mode
  1006. //
  1007. #define SECURITY_DYNAMIC_TRACKING (TRUE)
  1008. #define SECURITY_STATIC_TRACKING (FALSE)
  1009. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  1010. * PSECURITY_CONTEXT_TRACKING_MODE;
  1011. //
  1012. // Quality Of Service
  1013. //
  1014. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  1015. ULONG Length;
  1016. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  1017. SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  1018. BOOLEAN EffectiveOnly;
  1019. } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  1020. //
  1021. // Used to represent information related to a thread impersonation
  1022. //
  1023. typedef struct _SE_IMPERSONATION_STATE {
  1024. PACCESS_TOKEN Token;
  1025. BOOLEAN CopyOnOpen;
  1026. BOOLEAN EffectiveOnly;
  1027. SECURITY_IMPERSONATION_LEVEL Level;
  1028. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  1029. typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  1030. #define OWNER_SECURITY_INFORMATION (0x00000001L)
  1031. #define GROUP_SECURITY_INFORMATION (0x00000002L)
  1032. #define DACL_SECURITY_INFORMATION (0x00000004L)
  1033. #define SACL_SECURITY_INFORMATION (0x00000008L)
  1034. #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
  1035. #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
  1036. #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
  1037. #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
  1038. NTSYSCALLAPI
  1039. NTSTATUS
  1040. NTAPI
  1041. NtOpenThreadToken(
  1042. IN HANDLE ThreadHandle,
  1043. IN ACCESS_MASK DesiredAccess,
  1044. IN BOOLEAN OpenAsSelf,
  1045. OUT PHANDLE TokenHandle
  1046. );
  1047. NTSYSCALLAPI
  1048. NTSTATUS
  1049. NTAPI
  1050. NtOpenThreadTokenEx(
  1051. IN HANDLE ThreadHandle,
  1052. IN ACCESS_MASK DesiredAccess,
  1053. IN BOOLEAN OpenAsSelf,
  1054. IN ULONG HandleAttributes,
  1055. OUT PHANDLE TokenHandle
  1056. );
  1057. NTSYSCALLAPI
  1058. NTSTATUS
  1059. NTAPI
  1060. NtOpenProcessToken(
  1061. IN HANDLE ProcessHandle,
  1062. IN ACCESS_MASK DesiredAccess,
  1063. OUT PHANDLE TokenHandle
  1064. );
  1065. NTSYSCALLAPI
  1066. NTSTATUS
  1067. NTAPI
  1068. NtOpenProcessTokenEx(
  1069. IN HANDLE ProcessHandle,
  1070. IN ACCESS_MASK DesiredAccess,
  1071. IN ULONG HandleAttributes,
  1072. OUT PHANDLE TokenHandle
  1073. );
  1074. NTSYSAPI
  1075. NTSTATUS
  1076. NTAPI
  1077. NtOpenJobObjectToken(
  1078. IN HANDLE JobHandle,
  1079. IN ACCESS_MASK DesiredAccess,
  1080. OUT PHANDLE TokenHandle
  1081. );
  1082. NTSYSCALLAPI
  1083. NTSTATUS
  1084. NTAPI
  1085. NtDuplicateToken(
  1086. IN HANDLE ExistingTokenHandle,
  1087. IN ACCESS_MASK DesiredAccess,
  1088. IN POBJECT_ATTRIBUTES ObjectAttributes,
  1089. IN BOOLEAN EffectiveOnly,
  1090. IN TOKEN_TYPE TokenType,
  1091. OUT PHANDLE NewTokenHandle
  1092. );
  1093. NTSYSCALLAPI
  1094. NTSTATUS
  1095. NTAPI
  1096. NtFilterToken (
  1097. IN HANDLE ExistingTokenHandle,
  1098. IN ULONG Flags,
  1099. IN PTOKEN_GROUPS SidsToDisable OPTIONAL,
  1100. IN PTOKEN_PRIVILEGES PrivilegesToDelete OPTIONAL,
  1101. IN PTOKEN_GROUPS RestrictedSids OPTIONAL,
  1102. OUT PHANDLE NewTokenHandle
  1103. );
  1104. NTSYSCALLAPI
  1105. NTSTATUS
  1106. NTAPI
  1107. NtImpersonateAnonymousToken(
  1108. IN HANDLE ThreadHandle
  1109. );
  1110. NTSYSCALLAPI
  1111. NTSTATUS
  1112. NTAPI
  1113. NtQueryInformationToken (
  1114. IN HANDLE TokenHandle,
  1115. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  1116. OUT PVOID TokenInformation,
  1117. IN ULONG TokenInformationLength,
  1118. OUT PULONG ReturnLength
  1119. );
  1120. NTSYSCALLAPI
  1121. NTSTATUS
  1122. NTAPI
  1123. NtSetInformationToken (
  1124. IN HANDLE TokenHandle,
  1125. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  1126. IN PVOID TokenInformation,
  1127. IN ULONG TokenInformationLength
  1128. );
  1129. NTSYSCALLAPI
  1130. NTSTATUS
  1131. NTAPI
  1132. NtAdjustPrivilegesToken (
  1133. IN HANDLE TokenHandle,
  1134. IN BOOLEAN DisableAllPrivileges,
  1135. IN PTOKEN_PRIVILEGES NewState OPTIONAL,
  1136. IN ULONG BufferLength OPTIONAL,
  1137. OUT PTOKEN_PRIVILEGES PreviousState OPTIONAL,
  1138. OUT PULONG ReturnLength
  1139. );
  1140. NTSYSCALLAPI
  1141. NTSTATUS
  1142. NTAPI
  1143. NtAdjustGroupsToken (
  1144. IN HANDLE TokenHandle,
  1145. IN BOOLEAN ResetToDefault,
  1146. IN PTOKEN_GROUPS NewState OPTIONAL,
  1147. IN ULONG BufferLength OPTIONAL,
  1148. OUT PTOKEN_GROUPS PreviousState OPTIONAL,
  1149. OUT PULONG ReturnLength
  1150. );
  1151. NTSYSCALLAPI
  1152. NTSTATUS
  1153. NTAPI
  1154. NtPrivilegeCheck (
  1155. IN HANDLE ClientToken,
  1156. IN OUT PPRIVILEGE_SET RequiredPrivileges,
  1157. OUT PBOOLEAN Result
  1158. );
  1159. NTSYSCALLAPI
  1160. NTSTATUS
  1161. NTAPI
  1162. NtAccessCheckAndAuditAlarm (
  1163. IN PUNICODE_STRING SubsystemName,
  1164. IN PVOID HandleId,
  1165. IN PUNICODE_STRING ObjectTypeName,
  1166. IN PUNICODE_STRING ObjectName,
  1167. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  1168. IN ACCESS_MASK DesiredAccess,
  1169. IN PGENERIC_MAPPING GenericMapping,
  1170. IN BOOLEAN ObjectCreation,
  1171. OUT PACCESS_MASK GrantedAccess,
  1172. OUT PNTSTATUS AccessStatus,
  1173. OUT PBOOLEAN GenerateOnClose
  1174. );
  1175. NTSYSCALLAPI
  1176. NTSTATUS
  1177. NTAPI
  1178. NtAccessCheckByTypeAndAuditAlarm (
  1179. IN PUNICODE_STRING SubsystemName,
  1180. IN PVOID HandleId,
  1181. IN PUNICODE_STRING ObjectTypeName,
  1182. IN PUNICODE_STRING ObjectName,
  1183. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  1184. IN PSID PrincipalSelfSid,
  1185. IN ACCESS_MASK DesiredAccess,
  1186. IN AUDIT_EVENT_TYPE AuditType,
  1187. IN ULONG Flags,
  1188. IN POBJECT_TYPE_LIST ObjectTypeList OPTIONAL,
  1189. IN ULONG ObjectTypeListLength,
  1190. IN PGENERIC_MAPPING GenericMapping,
  1191. IN BOOLEAN ObjectCreation,
  1192. OUT PACCESS_MASK GrantedAccess,
  1193. OUT PNTSTATUS AccessStatus,
  1194. OUT PBOOLEAN GenerateOnClose
  1195. );
  1196. NTSYSCALLAPI
  1197. NTSTATUS
  1198. NTAPI
  1199. NtAccessCheckByTypeResultListAndAuditAlarm (
  1200. IN PUNICODE_STRING SubsystemName,
  1201. IN PVOID HandleId,
  1202. IN PUNICODE_STRING ObjectTypeName,
  1203. IN PUNICODE_STRING ObjectName,
  1204. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  1205. IN PSID PrincipalSelfSid,
  1206. IN ACCESS_MASK DesiredAccess,
  1207. IN AUDIT_EVENT_TYPE AuditType,
  1208. IN ULONG Flags,
  1209. IN POBJECT_TYPE_LIST ObjectTypeList OPTIONAL,
  1210. IN ULONG ObjectTypeListLength,
  1211. IN PGENERIC_MAPPING GenericMapping,
  1212. IN BOOLEAN ObjectCreation,
  1213. OUT PACCESS_MASK GrantedAccess,
  1214. OUT PNTSTATUS AccessStatus,
  1215. OUT PBOOLEAN GenerateOnClose
  1216. );
  1217. NTSYSCALLAPI
  1218. NTSTATUS
  1219. NTAPI
  1220. NtAccessCheckByTypeResultListAndAuditAlarmByHandle (
  1221. IN PUNICODE_STRING SubsystemName,
  1222. IN PVOID HandleId,
  1223. IN HANDLE ClientToken,
  1224. IN PUNICODE_STRING ObjectTypeName,
  1225. IN PUNICODE_STRING ObjectName,
  1226. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  1227. IN PSID PrincipalSelfSid,
  1228. IN ACCESS_MASK DesiredAccess,
  1229. IN AUDIT_EVENT_TYPE AuditType,
  1230. IN ULONG Flags,
  1231. IN POBJECT_TYPE_LIST ObjectTypeList OPTIONAL,
  1232. IN ULONG ObjectTypeListLength,
  1233. IN PGENERIC_MAPPING GenericMapping,
  1234. IN BOOLEAN ObjectCreation,
  1235. OUT PACCESS_MASK GrantedAccess,
  1236. OUT PNTSTATUS AccessStatus,
  1237. OUT PBOOLEAN GenerateOnClose
  1238. );
  1239. NTSYSCALLAPI
  1240. NTSTATUS
  1241. NTAPI
  1242. NtOpenObjectAuditAlarm (
  1243. IN PUNICODE_STRING SubsystemName,
  1244. IN PVOID HandleId OPTIONAL,
  1245. IN PUNICODE_STRING ObjectTypeName,
  1246. IN PUNICODE_STRING ObjectName,
  1247. IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
  1248. IN HANDLE ClientToken,
  1249. IN ACCESS_MASK DesiredAccess,
  1250. IN ACCESS_MASK GrantedAccess,
  1251. IN PPRIVILEGE_SET Privileges OPTIONAL,
  1252. IN BOOLEAN ObjectCreation,
  1253. IN BOOLEAN AccessGranted,
  1254. OUT PBOOLEAN GenerateOnClose
  1255. );
  1256. NTSYSCALLAPI
  1257. NTSTATUS
  1258. NTAPI
  1259. NtPrivilegeObjectAuditAlarm (
  1260. IN PUNICODE_STRING SubsystemName,
  1261. IN PVOID HandleId,
  1262. IN HANDLE ClientToken,
  1263. IN ACCESS_MASK DesiredAccess,
  1264. IN PPRIVILEGE_SET Privileges,
  1265. IN BOOLEAN AccessGranted
  1266. );
  1267. NTSYSCALLAPI
  1268. NTSTATUS
  1269. NTAPI
  1270. NtCloseObjectAuditAlarm (
  1271. IN PUNICODE_STRING SubsystemName,
  1272. IN PVOID HandleId,
  1273. IN BOOLEAN GenerateOnClose
  1274. );
  1275. NTSYSCALLAPI
  1276. NTSTATUS
  1277. NTAPI
  1278. NtDeleteObjectAuditAlarm (
  1279. IN PUNICODE_STRING SubsystemName,
  1280. IN PVOID HandleId,
  1281. IN BOOLEAN GenerateOnClose
  1282. );
  1283. NTSYSCALLAPI
  1284. NTSTATUS
  1285. NTAPI
  1286. NtPrivilegedServiceAuditAlarm (
  1287. IN PUNICODE_STRING SubsystemName,
  1288. IN PUNICODE_STRING ServiceName,
  1289. IN HANDLE ClientToken,
  1290. IN PPRIVILEGE_SET Privileges,
  1291. IN BOOLEAN AccessGranted
  1292. );
  1293. //
  1294. // Define alignment macros to align structure sizes and pointers up and down.
  1295. //
  1296. #define ALIGN_DOWN(length, type) \
  1297. ((ULONG)(length) & ~(sizeof(type) - 1))
  1298. #define ALIGN_UP(length, type) \
  1299. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  1300. #define ALIGN_DOWN_POINTER(address, type) \
  1301. ((PVOID)((ULONG_PTR)(address) & ~((ULONG_PTR)sizeof(type) - 1)))
  1302. #define ALIGN_UP_POINTER(address, type) \
  1303. (ALIGN_DOWN_POINTER(((ULONG_PTR)(address) + sizeof(type) - 1), type))
  1304. #define POOL_TAGGING 1
  1305. #ifndef DBG
  1306. #define DBG 0
  1307. #endif
  1308. #if DBG
  1309. #define IF_DEBUG if (TRUE)
  1310. #else
  1311. #define IF_DEBUG if (FALSE)
  1312. #endif
  1313. #if DEVL
  1314. extern ULONG NtGlobalFlag;
  1315. #define IF_NTOS_DEBUG( FlagName ) \
  1316. if (NtGlobalFlag & (FLG_ ## FlagName))
  1317. #else
  1318. #define IF_NTOS_DEBUG( FlagName ) if (FALSE)
  1319. #endif
  1320. //
  1321. // Kernel definitions that need to be here for forward reference purposes
  1322. //
  1323. // begin_ntndis
  1324. //
  1325. // Processor modes.
  1326. //
  1327. typedef CCHAR KPROCESSOR_MODE;
  1328. typedef enum _MODE {
  1329. KernelMode,
  1330. UserMode,
  1331. MaximumMode
  1332. } MODE;
  1333. // end_ntndis
  1334. //
  1335. // APC function types
  1336. //
  1337. //
  1338. // Put in an empty definition for the KAPC so that the
  1339. // routines can reference it before it is declared.
  1340. //
  1341. struct _KAPC;
  1342. typedef
  1343. VOID
  1344. (*PKNORMAL_ROUTINE) (
  1345. IN PVOID NormalContext,
  1346. IN PVOID SystemArgument1,
  1347. IN PVOID SystemArgument2
  1348. );
  1349. typedef
  1350. VOID
  1351. (*PKKERNEL_ROUTINE) (
  1352. IN struct _KAPC *Apc,
  1353. IN OUT PKNORMAL_ROUTINE *NormalRoutine,
  1354. IN OUT PVOID *NormalContext,
  1355. IN OUT PVOID *SystemArgument1,
  1356. IN OUT PVOID *SystemArgument2
  1357. );
  1358. typedef
  1359. VOID
  1360. (*PKRUNDOWN_ROUTINE) (
  1361. IN struct _KAPC *Apc
  1362. );
  1363. typedef
  1364. BOOLEAN
  1365. (*PKSYNCHRONIZE_ROUTINE) (
  1366. IN PVOID SynchronizeContext
  1367. );
  1368. typedef
  1369. BOOLEAN
  1370. (*PKTRANSFER_ROUTINE) (
  1371. VOID
  1372. );
  1373. //
  1374. //
  1375. // Asynchronous Procedure Call (APC) object
  1376. //
  1377. //
  1378. typedef struct _KAPC {
  1379. CSHORT Type;
  1380. CSHORT Size;
  1381. ULONG Spare0;
  1382. struct _KTHREAD *Thread;
  1383. LIST_ENTRY ApcListEntry;
  1384. PKKERNEL_ROUTINE KernelRoutine;
  1385. PKRUNDOWN_ROUTINE RundownRoutine;
  1386. PKNORMAL_ROUTINE NormalRoutine;
  1387. PVOID NormalContext;
  1388. //
  1389. // N.B. The following two members MUST be together.
  1390. //
  1391. PVOID SystemArgument1;
  1392. PVOID SystemArgument2;
  1393. CCHAR ApcStateIndex;
  1394. KPROCESSOR_MODE ApcMode;
  1395. BOOLEAN Inserted;
  1396. } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
  1397. // begin_ntndis
  1398. //
  1399. // DPC routine
  1400. //
  1401. struct _KDPC;
  1402. typedef
  1403. VOID
  1404. (*PKDEFERRED_ROUTINE) (
  1405. IN struct _KDPC *Dpc,
  1406. IN PVOID DeferredContext,
  1407. IN PVOID SystemArgument1,
  1408. IN PVOID SystemArgument2
  1409. );
  1410. //
  1411. // Define DPC importance.
  1412. //
  1413. // LowImportance - Queue DPC at end of target DPC queue.
  1414. // MediumImportance - Queue DPC at end of target DPC queue.
  1415. // HighImportance - Queue DPC at front of target DPC DPC queue.
  1416. //
  1417. // If there is currently a DPC active on the target processor, or a DPC
  1418. // interrupt has already been requested on the target processor when a
  1419. // DPC is queued, then no further action is necessary. The DPC will be
  1420. // executed on the target processor when its queue entry is processed.
  1421. //
  1422. // If there is not a DPC active on the target processor and a DPC interrupt
  1423. // has not been requested on the target processor, then the exact treatment
  1424. // of the DPC is dependent on whether the host system is a UP system or an
  1425. // MP system.
  1426. //
  1427. // UP system.
  1428. //
  1429. // If the DPC is of medium or high importance, the current DPC queue depth
  1430. // is greater than the maximum target depth, or current DPC request rate is
  1431. // less the minimum target rate, then a DPC interrupt is requested on the
  1432. // host processor and the DPC will be processed when the interrupt occurs.
  1433. // Otherwise, no DPC interupt is requested and the DPC execution will be
  1434. // delayed until the DPC queue depth is greater that the target depth or the
  1435. // minimum DPC rate is less than the target rate.
  1436. //
  1437. // MP system.
  1438. //
  1439. // If the DPC is being queued to another processor and the depth of the DPC
  1440. // queue on the target processor is greater than the maximum target depth or
  1441. // the DPC is of high importance, then a DPC interrupt is requested on the
  1442. // target processor and the DPC will be processed when the interrupt occurs.
  1443. // Otherwise, the DPC execution will be delayed on the target processor until
  1444. // the DPC queue depth on the target processor is greater that the maximum
  1445. // target depth or the minimum DPC rate on the target processor is less than
  1446. // the target mimimum rate.
  1447. //
  1448. // If the DPC is being queued to the current processor and the DPC is not of
  1449. // low importance, the current DPC queue depth is greater than the maximum
  1450. // target depth, or the minimum DPC rate is less than the minimum target rate,
  1451. // then a DPC interrupt is request on the current processor and the DPV will
  1452. // be processed whne the interrupt occurs. Otherwise, no DPC interupt is
  1453. // requested and the DPC execution will be delayed until the DPC queue depth
  1454. // is greater that the target depth or the minimum DPC rate is less than the
  1455. // target rate.
  1456. //
  1457. typedef enum _KDPC_IMPORTANCE {
  1458. LowImportance,
  1459. MediumImportance,
  1460. HighImportance
  1461. } KDPC_IMPORTANCE;
  1462. //
  1463. // Define DPC type indicies.
  1464. //
  1465. #define DPC_NORMAL 0
  1466. #define DPC_THREADED 1
  1467. //
  1468. // Deferred Procedure Call (DPC) object
  1469. //
  1470. typedef struct _KDPC {
  1471. CSHORT Type;
  1472. UCHAR Number;
  1473. UCHAR Importance;
  1474. LIST_ENTRY DpcListEntry;
  1475. PKDEFERRED_ROUTINE DeferredRoutine;
  1476. PVOID DeferredContext;
  1477. PVOID SystemArgument1;
  1478. PVOID SystemArgument2;
  1479. PVOID DpcData;
  1480. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  1481. //
  1482. // Interprocessor interrupt worker routine function prototype.
  1483. //
  1484. typedef PVOID PKIPI_CONTEXT;
  1485. typedef
  1486. VOID
  1487. (*PKIPI_WORKER)(
  1488. IN PKIPI_CONTEXT PacketContext,
  1489. IN PVOID Parameter1,
  1490. IN PVOID Parameter2,
  1491. IN PVOID Parameter3
  1492. );
  1493. //
  1494. // Define interprocessor interrupt performance counters.
  1495. //
  1496. typedef struct _KIPI_COUNTS {
  1497. ULONG Freeze;
  1498. ULONG Packet;
  1499. ULONG DPC;
  1500. ULONG APC;
  1501. ULONG FlushSingleTb;
  1502. ULONG FlushMultipleTb;
  1503. ULONG FlushEntireTb;
  1504. ULONG GenericCall;
  1505. ULONG ChangeColor;
  1506. ULONG SweepDcache;
  1507. ULONG SweepIcache;
  1508. ULONG SweepIcacheRange;
  1509. ULONG FlushIoBuffers;
  1510. ULONG GratuitousDPC;
  1511. } KIPI_COUNTS, *PKIPI_COUNTS;
  1512. //
  1513. // I/O system definitions.
  1514. //
  1515. // Define a Memory Descriptor List (MDL)
  1516. //
  1517. // An MDL describes pages in a virtual buffer in terms of physical pages. The
  1518. // pages associated with the buffer are described in an array that is allocated
  1519. // just after the MDL header structure itself.
  1520. //
  1521. // One simply calculates the base of the array by adding one to the base
  1522. // MDL pointer:
  1523. //
  1524. // Pages = (PPFN_NUMBER) (Mdl + 1);
  1525. //
  1526. // Notice that while in the context of the subject thread, the base virtual
  1527. // address of a buffer mapped by an MDL may be referenced using the following:
  1528. //
  1529. // Mdl->StartVa | Mdl->ByteOffset
  1530. //
  1531. typedef struct _MDL {
  1532. struct _MDL *Next;
  1533. CSHORT Size;
  1534. CSHORT MdlFlags;
  1535. struct _EPROCESS *Process;
  1536. PVOID MappedSystemVa;
  1537. PVOID StartVa;
  1538. ULONG ByteCount;
  1539. ULONG ByteOffset;
  1540. } MDL, *PMDL;
  1541. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  1542. #define MDL_PAGES_LOCKED 0x0002
  1543. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  1544. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  1545. #define MDL_PARTIAL 0x0010
  1546. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  1547. #define MDL_IO_PAGE_READ 0x0040
  1548. #define MDL_WRITE_OPERATION 0x0080
  1549. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  1550. #define MDL_FREE_EXTRA_PTES 0x0200
  1551. #define MDL_DESCRIBES_AWE 0x0400
  1552. #define MDL_IO_SPACE 0x0800
  1553. #define MDL_NETWORK_HEADER 0x1000
  1554. #define MDL_MAPPING_CAN_FAIL 0x2000
  1555. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  1556. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  1557. MDL_PAGES_LOCKED | \
  1558. MDL_SOURCE_IS_NONPAGED_POOL | \
  1559. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  1560. MDL_PARENT_MAPPED_SYSTEM_VA | \
  1561. MDL_SYSTEM_VA | \
  1562. MDL_IO_SPACE )
  1563. // end_ntndis
  1564. //
  1565. // switch to DBG when appropriate
  1566. //
  1567. #if DBG
  1568. #define PAGED_CODE() \
  1569. { if (KeGetCurrentIrql() > APC_LEVEL) { \
  1570. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  1571. ASSERT(FALSE); \
  1572. } \
  1573. }
  1574. #else
  1575. #define PAGED_CODE() NOP_FUNCTION;
  1576. #endif
  1577. //
  1578. // Data structure used to represent client security context for a thread.
  1579. // This data structure is used to support impersonation.
  1580. //
  1581. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  1582. // BY ALL EXCEPT THE SECURITY ROUTINES.
  1583. //
  1584. typedef struct _SECURITY_CLIENT_CONTEXT {
  1585. SECURITY_QUALITY_OF_SERVICE SecurityQos;
  1586. PACCESS_TOKEN ClientToken;
  1587. BOOLEAN DirectlyAccessClientToken;
  1588. BOOLEAN DirectAccessEffectiveOnly;
  1589. BOOLEAN ServerIsRemote;
  1590. TOKEN_CONTROL ClientTokenControl;
  1591. } SECURITY_CLIENT_CONTEXT, *PSECURITY_CLIENT_CONTEXT;
  1592. //
  1593. // where
  1594. //
  1595. // SecurityQos - is the security quality of service information in effect
  1596. // for this client. This information is used when directly accessing
  1597. // the client's token. In this case, the information here over-rides
  1598. // the information in the client's token. If a copy of the client's
  1599. // token is requested, it must be generated using this information,
  1600. // not the information in the client's token. In all cases, this
  1601. // information may not provide greater access than the information
  1602. // in the client's token. In particular, if the client's token is
  1603. // an impersonation token with an impersonation level of
  1604. // "SecurityDelegation", but the information in this field indicates
  1605. // an impersonation level of "SecurityIdentification", then
  1606. // the server may only get a copy of the token with an Identification
  1607. // level of impersonation.
  1608. //
  1609. // ClientToken - If the DirectlyAccessClientToken field is FALSE,
  1610. // then this field contains a pointer to a duplicate of the
  1611. // client's token. Otherwise, this field points directly to
  1612. // the client's token.
  1613. //
  1614. // DirectlyAccessClientToken - This boolean flag indicates whether the
  1615. // token pointed to by ClientToken is a copy of the client's token
  1616. // or is a direct reference to the client's token. A value of TRUE
  1617. // indicates the client's token is directly accessed, FALSE indicates
  1618. // a copy has been made.
  1619. //
  1620. // DirectAccessEffectiveOnly - This boolean flag indicates whether the
  1621. // the disabled portions of the token that is currently directly
  1622. // referenced may be enabled. This field is only valid if the
  1623. // DirectlyAccessClientToken field is TRUE. In that case, this
  1624. // value supersedes the EffectiveOnly value in the SecurityQos
  1625. // FOR THE CURRENT TOKEN ONLY! If the client changes to impersonate
  1626. // another client, this value may change. This value is always
  1627. // minimized by the EffectiveOnly flag in the SecurityQos field.
  1628. //
  1629. // ServerIsRemote - If TRUE indicates that the server of the client's
  1630. // request is remote. This is used for determining the legitimacy
  1631. // of certain levels of impersonation and to determine how to
  1632. // track context.
  1633. //
  1634. // ClientTokenControl - If the ServerIsRemote flag is TRUE, and the
  1635. // tracking mode is DYNAMIC, then this field contains a copy of
  1636. // the TOKEN_SOURCE from the client's token to assist in deciding
  1637. // whether the information at the remote server needs to be
  1638. // updated to match the current state of the client's security
  1639. // context.
  1640. //
  1641. //
  1642. // NOTE: At some point, we may find it worthwhile to keep an array of
  1643. // elements in this data structure, where each element of the
  1644. // array contains {ClientToken, ClientTokenControl} fields.
  1645. // This would allow efficient handling of the case where a client
  1646. // thread was constantly switching between a couple different
  1647. // contexts - presumably impersonating client's of its own.
  1648. //
  1649. #define NTKERNELAPI DECLSPEC_IMPORT
  1650. #define NTHALAPI DECLSPEC_IMPORT
  1651. //
  1652. // Common dispatcher object header
  1653. //
  1654. // N.B. The size field contains the number of dwords in the structure.
  1655. //
  1656. typedef struct _DISPATCHER_HEADER {
  1657. union {
  1658. struct {
  1659. UCHAR Type;
  1660. UCHAR Absolute;
  1661. UCHAR Size;
  1662. union {
  1663. UCHAR Inserted;
  1664. BOOLEAN DebugActive;
  1665. };
  1666. };
  1667. volatile LONG Lock;
  1668. };
  1669. LONG SignalState;
  1670. LIST_ENTRY WaitListHead;
  1671. } DISPATCHER_HEADER;
  1672. //
  1673. // Event object
  1674. //
  1675. typedef struct _KEVENT {
  1676. DISPATCHER_HEADER Header;
  1677. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  1678. //
  1679. // Timer object
  1680. //
  1681. typedef struct _KTIMER {
  1682. DISPATCHER_HEADER Header;
  1683. ULARGE_INTEGER DueTime;
  1684. LIST_ENTRY TimerListEntry;
  1685. struct _KDPC *Dpc;
  1686. LONG Period;
  1687. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  1688. typedef enum _LOCK_OPERATION {
  1689. IoReadAccess,
  1690. IoWriteAccess,
  1691. IoModifyAccess
  1692. } LOCK_OPERATION;
  1693. #define LOW_PRIORITY 0 // Lowest thread priority level
  1694. #define LOW_REALTIME_PRIORITY 16 // Lowest realtime priority level
  1695. #define HIGH_PRIORITY 31 // Highest thread priority level
  1696. #define MAXIMUM_PRIORITY 32 // Number of thread priority levels
  1697. // begin_winnt
  1698. #define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
  1699. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  1700. // end_winnt
  1701. //
  1702. // Define system time structure.
  1703. //
  1704. typedef struct _KSYSTEM_TIME {
  1705. ULONG LowPart;
  1706. LONG High1Time;
  1707. LONG High2Time;
  1708. } KSYSTEM_TIME, *PKSYSTEM_TIME;
  1709. //
  1710. // Thread priority
  1711. //
  1712. typedef LONG KPRIORITY;
  1713. //
  1714. // Spin Lock
  1715. //
  1716. // begin_ntndis begin_winnt
  1717. typedef ULONG_PTR KSPIN_LOCK;
  1718. typedef KSPIN_LOCK *PKSPIN_LOCK;
  1719. // end_ntndis end_winnt end_wdm
  1720. //
  1721. // Define per processor lock queue structure.
  1722. //
  1723. // N.B. The lock field of the spin lock queue structure contains the address
  1724. // of the associated kernel spin lock, an owner bit, and a lock bit. Bit
  1725. // 0 of the spin lock address is the wait bit and bit 1 is the owner bit.
  1726. // The use of this field is such that the bits can be set and cleared
  1727. // noninterlocked, however, the back pointer must be preserved.
  1728. //
  1729. // The lock wait bit is set when a processor enqueues itself on the lock
  1730. // queue and it is not the only entry in the queue. The processor will
  1731. // spin on this bit waiting for the lock to be granted.
  1732. //
  1733. // The owner bit is set when the processor owns the respective lock.
  1734. //
  1735. // The next field of the spin lock queue structure is used to line the
  1736. // queued lock structures together in fifo order. It also can set set and
  1737. // cleared noninterlocked.
  1738. //
  1739. #define LOCK_QUEUE_WAIT 1
  1740. #define LOCK_QUEUE_OWNER 2
  1741. typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
  1742. LockQueueDispatcherLock,
  1743. LockQueueUnusedSpare1,
  1744. LockQueuePfnLock,
  1745. LockQueueSystemSpaceLock,
  1746. LockQueueVacbLock,
  1747. LockQueueMasterLock,
  1748. LockQueueNonPagedPoolLock,
  1749. LockQueueIoCancelLock,
  1750. LockQueueWorkQueueLock,
  1751. LockQueueIoVpbLock,
  1752. LockQueueIoDatabaseLock,
  1753. LockQueueIoCompletionLock,
  1754. LockQueueNtfsStructLock,
  1755. LockQueueAfdWorkQueueLock,
  1756. LockQueueBcbLock,
  1757. LockQueueMmNonPagedPoolLock,
  1758. LockQueueMaximumLock
  1759. } KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
  1760. typedef struct _KSPIN_LOCK_QUEUE {
  1761. struct _KSPIN_LOCK_QUEUE * volatile Next;
  1762. PKSPIN_LOCK volatile Lock;
  1763. } KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
  1764. typedef struct _KLOCK_QUEUE_HANDLE {
  1765. KSPIN_LOCK_QUEUE LockQueue;
  1766. KIRQL OldIrql;
  1767. } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
  1768. // begin_wdm
  1769. //
  1770. // Interrupt routine (first level dispatch)
  1771. //
  1772. typedef
  1773. VOID
  1774. (*PKINTERRUPT_ROUTINE) (
  1775. VOID
  1776. );
  1777. //
  1778. // Profile source types
  1779. //
  1780. typedef enum _KPROFILE_SOURCE {
  1781. ProfileTime,
  1782. ProfileAlignmentFixup,
  1783. ProfileTotalIssues,
  1784. ProfilePipelineDry,
  1785. ProfileLoadInstructions,
  1786. ProfilePipelineFrozen,
  1787. ProfileBranchInstructions,
  1788. ProfileTotalNonissues,
  1789. ProfileDcacheMisses,
  1790. ProfileIcacheMisses,
  1791. ProfileCacheMisses,
  1792. ProfileBranchMispredictions,
  1793. ProfileStoreInstructions,
  1794. ProfileFpInstructions,
  1795. ProfileIntegerInstructions,
  1796. Profile2Issue,
  1797. Profile3Issue,
  1798. Profile4Issue,
  1799. ProfileSpecialInstructions,
  1800. ProfileTotalCycles,
  1801. ProfileIcacheIssues,
  1802. ProfileDcacheAccesses,
  1803. ProfileMemoryBarrierCycles,
  1804. ProfileLoadLinkedIssues,
  1805. ProfileMaximum
  1806. } KPROFILE_SOURCE;
  1807. #ifdef _X86_
  1808. //
  1809. // Disable these two pragmas that evaluate to "sti" "cli" on x86 so that driver
  1810. // writers to not leave them inadvertantly in their code.
  1811. //
  1812. #if !defined(MIDL_PASS)
  1813. #if !defined(RC_INVOKED)
  1814. #if _MSC_VER >= 1200
  1815. #pragma warning(push)
  1816. #endif
  1817. #pragma warning(disable:4164) // disable C4164 warning so that apps that
  1818. // build with /Od don't get weird errors !
  1819. #ifdef _M_IX86
  1820. #pragma function(_enable)
  1821. #pragma function(_disable)
  1822. #endif
  1823. #if _MSC_VER >= 1200
  1824. #pragma warning(pop)
  1825. #else
  1826. #pragma warning(default:4164) // reenable C4164 warning
  1827. #endif
  1828. #endif
  1829. #endif
  1830. #if !defined(MIDL_PASS) || defined(_M_IX86)
  1831. #if (_MSC_FULL_VER >= 13012035)
  1832. //
  1833. // Define bit scan intrinsics.
  1834. //
  1835. //#define BitScanForward _BitScanForward
  1836. //#define BitScanReverse _BitScanReverse
  1837. //BOOLEAN
  1838. //_BitScanForward (
  1839. // OUT ULONG *Index,
  1840. // IN ULONG Mask
  1841. // );
  1842. //BOOLEAN
  1843. //_BitScanReverse (
  1844. // OUT ULONG *Index,
  1845. // IN ULONG Mask
  1846. // );
  1847. //#pragma intrinsic(_BitScanForward)
  1848. //#pragma intrinsic(_BitScanReverse)
  1849. //
  1850. // Define FS referencing intrinsics
  1851. //
  1852. #ifdef __cplusplus
  1853. extern "C" {
  1854. #endif
  1855. UCHAR
  1856. __readfsbyte (
  1857. IN ULONG Offset
  1858. );
  1859. USHORT
  1860. __readfsword (
  1861. IN ULONG Offset
  1862. );
  1863. ULONG
  1864. __readfsdword (
  1865. IN ULONG Offset
  1866. );
  1867. VOID
  1868. __writefsbyte (
  1869. IN ULONG Offset,
  1870. IN UCHAR Data
  1871. );
  1872. VOID
  1873. __writefsword (
  1874. IN ULONG Offset,
  1875. IN USHORT Data
  1876. );
  1877. VOID
  1878. __writefsdword (
  1879. IN ULONG Offset,
  1880. IN ULONG Data
  1881. );
  1882. #ifdef __cplusplus
  1883. }
  1884. #endif
  1885. #pragma intrinsic(__readfsbyte)
  1886. #pragma intrinsic(__readfsword)
  1887. #pragma intrinsic(__readfsdword)
  1888. #pragma intrinsic(__writefsbyte)
  1889. #pragma intrinsic(__writefsword)
  1890. #pragma intrinsic(__writefsdword)
  1891. #endif
  1892. #endif
  1893. //
  1894. // Size of kernel mode stack.
  1895. //
  1896. #define KERNEL_STACK_SIZE 12288
  1897. //
  1898. // Define size of large kernel mode stack for callbacks.
  1899. //
  1900. #define KERNEL_LARGE_STACK_SIZE 61440
  1901. //
  1902. // Define number of pages to initialize in a large kernel stack.
  1903. //
  1904. #define KERNEL_LARGE_STACK_COMMIT 12288
  1905. #ifdef _X86_
  1906. #if !defined(MIDL_PASS) && defined(_M_IX86)
  1907. FORCEINLINE
  1908. VOID
  1909. MemoryBarrier (
  1910. VOID
  1911. )
  1912. {
  1913. LONG Barrier;
  1914. __asm {
  1915. xchg Barrier, eax
  1916. }
  1917. }
  1918. #define YieldProcessor() __asm { rep nop }
  1919. //
  1920. // Prefetch is not supported on all x86 procssors.
  1921. //
  1922. #define PreFetchCacheLine(l, a)
  1923. //
  1924. // PreFetchCacheLine level defines.
  1925. //
  1926. #define PF_TEMPORAL_LEVEL_1
  1927. #define PF_NON_TEMPORAL_LEVEL_ALL
  1928. #endif
  1929. // begin_wx86
  1930. //
  1931. // Define the size of the 80387 save area, which is in the context frame.
  1932. //
  1933. #define SIZE_OF_80387_REGISTERS 80
  1934. //
  1935. // The following flags control the contents of the CONTEXT structure.
  1936. //
  1937. #if !defined(RC_INVOKED)
  1938. #define CONTEXT_i386 0x00010000 // this assumes that i386 and
  1939. #define CONTEXT_i486 0x00010000 // i486 have identical context records
  1940. // end_wx86
  1941. #define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  1942. #define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  1943. #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  1944. #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
  1945. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  1946. #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
  1947. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  1948. CONTEXT_SEGMENTS)
  1949. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
  1950. // begin_wx86
  1951. #endif
  1952. #define MAXIMUM_SUPPORTED_EXTENSION 512
  1953. typedef struct _FLOATING_SAVE_AREA {
  1954. ULONG ControlWord;
  1955. ULONG StatusWord;
  1956. ULONG TagWord;
  1957. ULONG ErrorOffset;
  1958. ULONG ErrorSelector;
  1959. ULONG DataOffset;
  1960. ULONG DataSelector;
  1961. UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
  1962. ULONG Cr0NpxState;
  1963. } FLOATING_SAVE_AREA;
  1964. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  1965. //
  1966. // Context Frame
  1967. //
  1968. // This frame has a several purposes: 1) it is used as an argument to
  1969. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  1970. // and 3) it is used in the user level thread creation routines.
  1971. //
  1972. // The layout of the record conforms to a standard call frame.
  1973. //
  1974. typedef struct _CONTEXT {
  1975. //
  1976. // The flags values within this flag control the contents of
  1977. // a CONTEXT record.
  1978. //
  1979. // If the context record is used as an input parameter, then
  1980. // for each portion of the context record controlled by a flag
  1981. // whose value is set, it is assumed that that portion of the
  1982. // context record contains valid context. If the context record
  1983. // is being used to modify a threads context, then only that
  1984. // portion of the threads context will be modified.
  1985. //
  1986. // If the context record is used as an IN OUT parameter to capture
  1987. // the context of a thread, then only those portions of the thread's
  1988. // context corresponding to set flags will be returned.
  1989. //
  1990. // The context record is never used as an OUT only parameter.
  1991. //
  1992. ULONG ContextFlags;
  1993. //
  1994. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  1995. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  1996. // included in CONTEXT_FULL.
  1997. //
  1998. ULONG Dr0;
  1999. ULONG Dr1;
  2000. ULONG Dr2;
  2001. ULONG Dr3;
  2002. ULONG Dr6;
  2003. ULONG Dr7;
  2004. //
  2005. // This section is specified/returned if the
  2006. // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  2007. //
  2008. FLOATING_SAVE_AREA FloatSave;
  2009. //
  2010. // This section is specified/returned if the
  2011. // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  2012. //
  2013. ULONG SegGs;
  2014. ULONG SegFs;
  2015. ULONG SegEs;
  2016. ULONG SegDs;
  2017. //
  2018. // This section is specified/returned if the
  2019. // ContextFlags word contians the flag CONTEXT_INTEGER.
  2020. //
  2021. ULONG Edi;
  2022. ULONG Esi;
  2023. ULONG Ebx;
  2024. ULONG Edx;
  2025. ULONG Ecx;
  2026. ULONG Eax;
  2027. //
  2028. // This section is specified/returned if the
  2029. // ContextFlags word contians the flag CONTEXT_CONTROL.
  2030. //
  2031. ULONG Ebp;
  2032. ULONG Eip;
  2033. ULONG SegCs; // MUST BE SANITIZED
  2034. ULONG EFlags; // MUST BE SANITIZED
  2035. ULONG Esp;
  2036. ULONG SegSs;
  2037. //
  2038. // This section is specified/returned if the ContextFlags word
  2039. // contains the flag CONTEXT_EXTENDED_REGISTERS.
  2040. // The format and contexts are processor specific
  2041. //
  2042. UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
  2043. } CONTEXT;
  2044. typedef CONTEXT *PCONTEXT;
  2045. // begin_ntminiport
  2046. #endif //_X86_
  2047. #endif // _X86_
  2048. #if defined(_AMD64_)
  2049. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  2050. //
  2051. // Define bit test intrinsics.
  2052. //
  2053. #ifdef __cplusplus
  2054. extern "C" {
  2055. #endif
  2056. #define BitTest _bittest
  2057. #define BitTestAndComplement _bittestandcomplement
  2058. #define BitTestAndSet _bittestandset
  2059. #define BitTestAndReset _bittestandreset
  2060. #define InterlockedBitTestAndSet _interlockedbittestandset
  2061. #define InterlockedBitTestAndReset _interlockedbittestandreset
  2062. #define BitTest64 _bittest64
  2063. #define BitTestAndComplement64 _bittestandcomplement64
  2064. #define BitTestAndSet64 _bittestandset64
  2065. #define BitTestAndReset64 _bittestandreset64
  2066. #define InterlockedBitTestAndSet64 _interlockedbittestandset64
  2067. #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
  2068. BOOLEAN
  2069. _bittest (
  2070. IN LONG *Base,
  2071. IN LONG Offset
  2072. );
  2073. BOOLEAN
  2074. _bittestandcomplement (
  2075. IN LONG *Base,
  2076. IN LONG Offset
  2077. );
  2078. BOOLEAN
  2079. _bittestandset (
  2080. IN LONG *Base,
  2081. IN LONG Offset
  2082. );
  2083. BOOLEAN
  2084. _bittestandreset (
  2085. IN LONG *Base,
  2086. IN LONG Offset
  2087. );
  2088. BOOLEAN
  2089. _interlockedbittestandset (
  2090. IN LONG *Base,
  2091. IN LONG Offset
  2092. );
  2093. BOOLEAN
  2094. _interlockedbittestandreset (
  2095. IN LONG *Base,
  2096. IN LONG Offset
  2097. );
  2098. BOOLEAN
  2099. _bittest64 (
  2100. IN LONG64 *Base,
  2101. IN LONG64 Offset
  2102. );
  2103. BOOLEAN
  2104. _bittestandcomplement64 (
  2105. IN LONG64 *Base,
  2106. IN LONG64 Offset
  2107. );
  2108. BOOLEAN
  2109. _bittestandset64 (
  2110. IN LONG64 *Base,
  2111. IN LONG64 Offset
  2112. );
  2113. BOOLEAN
  2114. _bittestandreset64 (
  2115. IN LONG64 *Base,
  2116. IN LONG64 Offset
  2117. );
  2118. BOOLEAN
  2119. _interlockedbittestandset64 (
  2120. IN LONG64 *Base,
  2121. IN LONG64 Offset
  2122. );
  2123. BOOLEAN
  2124. _interlockedbittestandreset64 (
  2125. IN LONG64 *Base,
  2126. IN LONG64 Offset
  2127. );
  2128. #pragma intrinsic(_bittest)
  2129. #pragma intrinsic(_bittestandcomplement)
  2130. #pragma intrinsic(_bittestandset)
  2131. #pragma intrinsic(_bittestandreset)
  2132. #pragma intrinsic(_interlockedbittestandset)
  2133. #pragma intrinsic(_interlockedbittestandreset)
  2134. #pragma intrinsic(_bittest64)
  2135. #pragma intrinsic(_bittestandcomplement64)
  2136. #pragma intrinsic(_bittestandset64)
  2137. #pragma intrinsic(_bittestandreset64)
  2138. #pragma intrinsic(_interlockedbittestandset64)
  2139. #pragma intrinsic(_interlockedbittestandreset64)
  2140. //
  2141. // Define bit scan intrinsics.
  2142. //
  2143. #define BitScanForward _BitScanForward
  2144. #define BitScanReverse _BitScanReverse
  2145. #define BitScanForward64 _BitScanForward64
  2146. #define BitScanReverse64 _BitScanReverse64
  2147. BOOLEAN
  2148. _BitScanForward (
  2149. OUT ULONG *Index,
  2150. IN ULONG Mask
  2151. );
  2152. BOOLEAN
  2153. _BitScanReverse (
  2154. OUT ULONG *Index,
  2155. IN ULONG Mask
  2156. );
  2157. BOOLEAN
  2158. _BitScanForward64 (
  2159. OUT ULONG *Index,
  2160. IN ULONG64 Mask
  2161. );
  2162. BOOLEAN
  2163. _BitScanReverse64 (
  2164. OUT ULONG *Index,
  2165. IN ULONG64 Mask
  2166. );
  2167. #pragma intrinsic(_BitScanForward)
  2168. #pragma intrinsic(_BitScanReverse)
  2169. #pragma intrinsic(_BitScanForward64)
  2170. #pragma intrinsic(_BitScanReverse64)
  2171. //
  2172. // Define function to flush a cache line.
  2173. //
  2174. #define CacheLineFlush(Address) _mm_clflush(Address)
  2175. VOID
  2176. _mm_clflush (
  2177. PVOID Address
  2178. );
  2179. #pragma intrinsic(_mm_clflush)
  2180. //
  2181. // Define memory fence intrinsics
  2182. //
  2183. #define LoadFence _mm_lfence
  2184. #define MemoryFence _mm_mfence
  2185. #define StoreFence _mm_sfence
  2186. VOID
  2187. _mm_lfence (
  2188. VOID
  2189. );
  2190. VOID
  2191. _mm_mfence (
  2192. VOID
  2193. );
  2194. VOID
  2195. _mm_sfence (
  2196. VOID
  2197. );
  2198. void
  2199. _mm_prefetch(
  2200. CHAR CONST *a,
  2201. int sel
  2202. );
  2203. /* constants for use with _mm_prefetch */
  2204. #define _MM_HINT_T0 1
  2205. #define _MM_HINT_T1 2
  2206. #define _MM_HINT_T2 3
  2207. #define _MM_HINT_NTA 0
  2208. #pragma intrinsic(_mm_prefetch)
  2209. #pragma intrinsic(_mm_lfence)
  2210. #pragma intrinsic(_mm_mfence)
  2211. #pragma intrinsic(_mm_sfence)
  2212. #define YieldProcessor()
  2213. #define MemoryBarrier _mm_mfence
  2214. #define PreFetchCacheLine(l, a) _mm_prefetch((CHAR CONST *) a, l)
  2215. //
  2216. // PreFetchCacheLine level defines.
  2217. //
  2218. #define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0
  2219. #define PF_NON_TEMPORAL_LEVEL_ALL _MM_HINT_NTA
  2220. //
  2221. // Define function to get the caller's EFLAGs value.
  2222. //
  2223. #define GetCallersEflags() __getcallerseflags()
  2224. unsigned __int32
  2225. __getcallerseflags (
  2226. VOID
  2227. );
  2228. #pragma intrinsic(__getcallerseflags)
  2229. //
  2230. // Define function to read the value of the time stamp counter
  2231. //
  2232. #define ReadTimeStampCounter() __rdtsc()
  2233. ULONG64
  2234. __rdtsc (
  2235. VOID
  2236. );
  2237. #pragma intrinsic(__rdtsc)
  2238. //
  2239. // Define functions to move strings as bytes, words, dwords, and qwords.
  2240. //
  2241. VOID
  2242. __movsb (
  2243. IN PUCHAR Destination,
  2244. IN PUCHAR Source,
  2245. IN SIZE_T Count
  2246. );
  2247. VOID
  2248. __movsw (
  2249. IN PUSHORT Destination,
  2250. IN PUSHORT Source,
  2251. IN SIZE_T Count
  2252. );
  2253. VOID
  2254. __movsd (
  2255. IN PULONG Destination,
  2256. IN PULONG Source,
  2257. IN SIZE_T Count
  2258. );
  2259. VOID
  2260. __movsq (
  2261. IN PULONGLONG Destination,
  2262. IN PULONGLONG Source,
  2263. IN SIZE_T Count
  2264. );
  2265. #pragma intrinsic(__movsb)
  2266. #pragma intrinsic(__movsw)
  2267. #pragma intrinsic(__movsd)
  2268. #pragma intrinsic(__movsq)
  2269. //
  2270. // Define functions to store strings as bytes, words, dwords, and qwords.
  2271. //
  2272. VOID
  2273. __stosb (
  2274. IN PUCHAR Destination,
  2275. IN UCHAR Value,
  2276. IN SIZE_T Count
  2277. );
  2278. VOID
  2279. __stosw (
  2280. IN PUSHORT Destination,
  2281. IN USHORT Value,
  2282. IN SIZE_T Count
  2283. );
  2284. VOID
  2285. __stosd (
  2286. IN PULONG Destination,
  2287. IN ULONG Value,
  2288. IN SIZE_T Count
  2289. );
  2290. VOID
  2291. __stosq (
  2292. IN PULONG64 Destination,
  2293. IN ULONG64 Value,
  2294. IN SIZE_T Count
  2295. );
  2296. #pragma intrinsic(__stosb)
  2297. #pragma intrinsic(__stosw)
  2298. #pragma intrinsic(__stosd)
  2299. #pragma intrinsic(__stosq)
  2300. //
  2301. // Define functions to capture the high 64-bits of a 128-bit multiply.
  2302. //
  2303. #define MultiplyHigh __mulh
  2304. #define UnsignedMultiplyHigh __umulh
  2305. LONGLONG
  2306. MultiplyHigh (
  2307. IN LONGLONG Multiplier,
  2308. IN LONGLONG Multiplicand
  2309. );
  2310. ULONGLONG
  2311. UnsignedMultiplyHigh (
  2312. IN ULONGLONG Multiplier,
  2313. IN ULONGLONG Multiplicand
  2314. );
  2315. #pragma intrinsic(__mulh)
  2316. #pragma intrinsic(__umulh)
  2317. //
  2318. // Define functions to read and write the uer TEB and the system PCR/PRCB.
  2319. //
  2320. UCHAR
  2321. __readgsbyte (
  2322. IN ULONG Offset
  2323. );
  2324. USHORT
  2325. __readgsword (
  2326. IN ULONG Offset
  2327. );
  2328. ULONG
  2329. __readgsdword (
  2330. IN ULONG Offset
  2331. );
  2332. ULONG64
  2333. __readgsqword (
  2334. IN ULONG Offset
  2335. );
  2336. VOID
  2337. __writegsbyte (
  2338. IN ULONG Offset,
  2339. IN UCHAR Data
  2340. );
  2341. VOID
  2342. __writegsword (
  2343. IN ULONG Offset,
  2344. IN USHORT Data
  2345. );
  2346. VOID
  2347. __writegsdword (
  2348. IN ULONG Offset,
  2349. IN ULONG Data
  2350. );
  2351. VOID
  2352. __writegsqword (
  2353. IN ULONG Offset,
  2354. IN ULONG64 Data
  2355. );
  2356. #pragma intrinsic(__readgsbyte)
  2357. #pragma intrinsic(__readgsword)
  2358. #pragma intrinsic(__readgsdword)
  2359. #pragma intrinsic(__readgsqword)
  2360. #pragma intrinsic(__writegsbyte)
  2361. #pragma intrinsic(__writegsword)
  2362. #pragma intrinsic(__writegsdword)
  2363. #pragma intrinsic(__writegsqword)
  2364. #ifdef __cplusplus
  2365. }
  2366. #endif
  2367. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  2368. //
  2369. // Size of kernel mode stack.
  2370. //
  2371. #define KERNEL_STACK_SIZE 0x6000
  2372. //
  2373. // Define size of large kernel mode stack for callbacks.
  2374. //
  2375. #define KERNEL_LARGE_STACK_SIZE 0xf000
  2376. //
  2377. // Define number of pages to initialize in a large kernel stack.
  2378. //
  2379. #define KERNEL_LARGE_STACK_COMMIT 0x5000
  2380. //
  2381. // Define the size of the stack used for processing an MCA exception.
  2382. //
  2383. #define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
  2384. //
  2385. // The following flags control the contents of the CONTEXT structure.
  2386. //
  2387. #if !defined(RC_INVOKED)
  2388. #define CONTEXT_AMD64 0x100000
  2389. // end_wx86
  2390. #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
  2391. #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
  2392. #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
  2393. #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
  2394. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
  2395. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  2396. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
  2397. // begin_wx86
  2398. #endif // !defined(RC_INVOKED)
  2399. //
  2400. // Define initial MxCsr control.
  2401. //
  2402. #define INITIAL_MXCSR 0x1f80 // initial MXCSR value
  2403. //
  2404. // Define 128-bit 16-byte aligned xmm register type.
  2405. //
  2406. typedef struct DECLSPEC_ALIGN(16) _M128 {
  2407. ULONGLONG Low;
  2408. LONGLONG High;
  2409. } M128, *PM128;
  2410. //
  2411. // Format of data for fnsave/frstor instructions.
  2412. //
  2413. // This structure is used to store the legacy floating point state.
  2414. //
  2415. typedef struct _LEGACY_SAVE_AREA {
  2416. USHORT ControlWord;
  2417. USHORT Reserved0;
  2418. USHORT StatusWord;
  2419. USHORT Reserved1;
  2420. USHORT TagWord;
  2421. USHORT Reserved2;
  2422. ULONG ErrorOffset;
  2423. USHORT ErrorSelector;
  2424. USHORT ErrorOpcode;
  2425. ULONG DataOffset;
  2426. USHORT DataSelector;
  2427. USHORT Reserved3;
  2428. UCHAR FloatRegisters[8 * 10];
  2429. } LEGACY_SAVE_AREA, *PLEGACY_SAVE_AREA;
  2430. #define LEGACY_SAVE_AREA_LENGTH ((sizeof(LEGACY_SAVE_AREA) + 15) & ~15)
  2431. //
  2432. // Context Frame
  2433. //
  2434. // This frame has a several purposes: 1) it is used as an argument to
  2435. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  2436. // and 3) it is used in the user level thread creation routines.
  2437. //
  2438. //
  2439. // The flags field within this record controls the contents of a CONTEXT
  2440. // record.
  2441. //
  2442. // If the context record is used as an input parameter, then for each
  2443. // portion of the context record controlled by a flag whose value is
  2444. // set, it is assumed that that portion of the context record contains
  2445. // valid context. If the context record is being used to modify a threads
  2446. // context, then only that portion of the threads context is modified.
  2447. //
  2448. // If the context record is used as an output parameter to capture the
  2449. // context of a thread, then only those portions of the thread's context
  2450. // corresponding to set flags will be returned.
  2451. //
  2452. // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
  2453. //
  2454. // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
  2455. //
  2456. // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
  2457. //
  2458. // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
  2459. //
  2460. // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
  2461. // Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
  2462. //
  2463. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
  2464. //
  2465. // Register parameter home addresses.
  2466. //
  2467. ULONG64 P1Home;
  2468. ULONG64 P2Home;
  2469. ULONG64 P3Home;
  2470. ULONG64 P4Home;
  2471. ULONG64 P5Home;
  2472. ULONG64 P6Home;
  2473. //
  2474. // Control flags.
  2475. //
  2476. ULONG ContextFlags;
  2477. ULONG MxCsr;
  2478. //
  2479. // Segment Registers and processor flags.
  2480. //
  2481. USHORT SegCs;
  2482. USHORT SegDs;
  2483. USHORT SegEs;
  2484. USHORT SegFs;
  2485. USHORT SegGs;
  2486. USHORT SegSs;
  2487. ULONG EFlags;
  2488. //
  2489. // Debug registers
  2490. //
  2491. ULONG64 Dr0;
  2492. ULONG64 Dr1;
  2493. ULONG64 Dr2;
  2494. ULONG64 Dr3;
  2495. ULONG64 Dr6;
  2496. ULONG64 Dr7;
  2497. //
  2498. // Integer registers.
  2499. //
  2500. ULONG64 Rax;
  2501. ULONG64 Rcx;
  2502. ULONG64 Rdx;
  2503. ULONG64 Rbx;
  2504. ULONG64 Rsp;
  2505. ULONG64 Rbp;
  2506. ULONG64 Rsi;
  2507. ULONG64 Rdi;
  2508. ULONG64 R8;
  2509. ULONG64 R9;
  2510. ULONG64 R10;
  2511. ULONG64 R11;
  2512. ULONG64 R12;
  2513. ULONG64 R13;
  2514. ULONG64 R14;
  2515. ULONG64 R15;
  2516. //
  2517. // Program counter.
  2518. //
  2519. ULONG64 Rip;
  2520. //
  2521. // MMX/floating point state.
  2522. //
  2523. M128 Xmm0;
  2524. M128 Xmm1;
  2525. M128 Xmm2;
  2526. M128 Xmm3;
  2527. M128 Xmm4;
  2528. M128 Xmm5;
  2529. M128 Xmm6;
  2530. M128 Xmm7;
  2531. M128 Xmm8;
  2532. M128 Xmm9;
  2533. M128 Xmm10;
  2534. M128 Xmm11;
  2535. M128 Xmm12;
  2536. M128 Xmm13;
  2537. M128 Xmm14;
  2538. M128 Xmm15;
  2539. //
  2540. // Legacy floating point state.
  2541. //
  2542. LEGACY_SAVE_AREA FltSave;
  2543. ULONG Fill;
  2544. //
  2545. // Special debug control registers.
  2546. //
  2547. ULONG64 DebugControl;
  2548. ULONG64 LastBranchToRip;
  2549. ULONG64 LastBranchFromRip;
  2550. ULONG64 LastExceptionToRip;
  2551. ULONG64 LastExceptionFromRip;
  2552. ULONG64 Fill1;
  2553. } CONTEXT, *PCONTEXT;
  2554. #endif // _AMD64_
  2555. #ifdef _IA64_
  2556. //
  2557. // Define size of kernel mode stack.
  2558. //
  2559. #define KERNEL_STACK_SIZE 0x8000
  2560. //
  2561. // Define size of large kernel mode stack for callbacks.
  2562. //
  2563. #define KERNEL_LARGE_STACK_SIZE 0x1A000
  2564. //
  2565. // Define number of pages to initialize in a large kernel stack.
  2566. //
  2567. #define KERNEL_LARGE_STACK_COMMIT 0x8000
  2568. //
  2569. // Define size of kernel mode backing store stack.
  2570. //
  2571. #define KERNEL_BSTORE_SIZE 0x8000
  2572. //
  2573. // Define size of large kernel mode backing store for callbacks.
  2574. //
  2575. #define KERNEL_LARGE_BSTORE_SIZE 0x10000
  2576. //
  2577. // Define number of pages to initialize in a large kernel backing store.
  2578. //
  2579. #define KERNEL_LARGE_BSTORE_COMMIT 0x8000
  2580. //
  2581. // Define base address for kernel and user space.
  2582. //
  2583. #define UREGION_INDEX 0
  2584. #define KREGION_INDEX 7
  2585. #define UADDRESS_BASE ((ULONGLONG)UREGION_INDEX << 61)
  2586. #define KADDRESS_BASE ((ULONGLONG)KREGION_INDEX << 61)
  2587. void
  2588. __yield(
  2589. void
  2590. );
  2591. void
  2592. __mf(
  2593. void
  2594. );
  2595. void
  2596. __lfetch(
  2597. int Level,
  2598. VOID CONST *Address
  2599. );
  2600. void
  2601. __lfetchfault(
  2602. int Level,
  2603. VOID CONST *Address
  2604. );
  2605. //
  2606. // __lfetch control defines.
  2607. //
  2608. #define MD_LFHINT_NONE 0x00
  2609. #define MD_LFHINT_NT1 0x01
  2610. #define MD_LFHINT_NT2 0x02
  2611. #define MD_LFHINT_NTA 0x03
  2612. #pragma intrinsic (__yield)
  2613. #pragma intrinsic (__lfetch)
  2614. #pragma intrinsic (__lfetchfault)
  2615. #pragma intrinsic (__mf)
  2616. #define YieldProcessor __yield
  2617. #define MemoryBarrier __mf
  2618. #define PreFetchCacheLine __lfetch
  2619. //
  2620. // PreFetchCacheLine level defines.
  2621. //
  2622. #define PF_TEMPORAL_LEVEL_1 MD_LFHINT_NONE
  2623. #define PF_NON_TEMPORAL_LEVEL_ALL MD_LFHINT_NTA
  2624. //
  2625. // The following flags control the contents of the CONTEXT structure.
  2626. //
  2627. #if !defined(RC_INVOKED)
  2628. #define CONTEXT_IA64 0x00080000
  2629. #define CONTEXT_CONTROL (CONTEXT_IA64 | 0x00000001L)
  2630. #define CONTEXT_LOWER_FLOATING_POINT (CONTEXT_IA64 | 0x00000002L)
  2631. #define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004L)
  2632. #define CONTEXT_INTEGER (CONTEXT_IA64 | 0x00000008L)
  2633. #define CONTEXT_DEBUG (CONTEXT_IA64 | 0x00000010L)
  2634. #define CONTEXT_IA32_CONTROL (CONTEXT_IA64 | 0x00000020L) // Includes StIPSR
  2635. #define CONTEXT_FLOATING_POINT (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
  2636. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
  2637. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_DEBUG | CONTEXT_IA32_CONTROL)
  2638. #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
  2639. #define CONTEXT_SERVICE_ACTIVE 0x10000000
  2640. #define CONTEXT_EXCEPTION_REQUEST 0x40000000
  2641. #define CONTEXT_EXCEPTION_REPORTING 0x80000000
  2642. #endif // !defined(RC_INVOKED)
  2643. //
  2644. // Context Frame
  2645. //
  2646. // This frame has a several purposes: 1) it is used as an argument to
  2647. // NtContinue, 2) it is used to construct a call frame for APC delivery,
  2648. // 3) it is used to construct a call frame for exception dispatching
  2649. // in user mode, 4) it is used in the user level thread creation
  2650. // routines, and 5) it is used to to pass thread state to debuggers.
  2651. //
  2652. // N.B. Because this record is used as a call frame, it must be EXACTLY
  2653. // a multiple of 16 bytes in length and aligned on a 16-byte boundary.
  2654. //
  2655. typedef struct _CONTEXT {
  2656. //
  2657. // The flags values within this flag control the contents of
  2658. // a CONTEXT record.
  2659. //
  2660. // If the context record is used as an input parameter, then
  2661. // for each portion of the context record controlled by a flag
  2662. // whose value is set, it is assumed that that portion of the
  2663. // context record contains valid context. If the context record
  2664. // is being used to modify a thread's context, then only that
  2665. // portion of the threads context will be modified.
  2666. //
  2667. // If the context record is used as an IN OUT parameter to capture
  2668. // the context of a thread, then only those portions of the thread's
  2669. // context corresponding to set flags will be returned.
  2670. //
  2671. // The context record is never used as an OUT only parameter.
  2672. //
  2673. ULONG ContextFlags;
  2674. ULONG Fill1[3]; // for alignment of following on 16-byte boundary
  2675. //
  2676. // This section is specified/returned if the ContextFlags word contains
  2677. // the flag CONTEXT_DEBUG.
  2678. //
  2679. // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
  2680. //
  2681. ULONGLONG DbI0;
  2682. ULONGLONG DbI1;
  2683. ULONGLONG DbI2;
  2684. ULONGLONG DbI3;
  2685. ULONGLONG DbI4;
  2686. ULONGLONG DbI5;
  2687. ULONGLONG DbI6;
  2688. ULONGLONG DbI7;
  2689. ULONGLONG DbD0;
  2690. ULONGLONG DbD1;
  2691. ULONGLONG DbD2;
  2692. ULONGLONG DbD3;
  2693. ULONGLONG DbD4;
  2694. ULONGLONG DbD5;
  2695. ULONGLONG DbD6;
  2696. ULONGLONG DbD7;
  2697. //
  2698. // This section is specified/returned if the ContextFlags word contains
  2699. // the flag CONTEXT_LOWER_FLOATING_POINT.
  2700. //
  2701. FLOAT128 FltS0;
  2702. FLOAT128 FltS1;
  2703. FLOAT128 FltS2;
  2704. FLOAT128 FltS3;
  2705. FLOAT128 FltT0;
  2706. FLOAT128 FltT1;
  2707. FLOAT128 FltT2;
  2708. FLOAT128 FltT3;
  2709. FLOAT128 FltT4;
  2710. FLOAT128 FltT5;
  2711. FLOAT128 FltT6;
  2712. FLOAT128 FltT7;
  2713. FLOAT128 FltT8;
  2714. FLOAT128 FltT9;
  2715. //
  2716. // This section is specified/returned if the ContextFlags word contains
  2717. // the flag CONTEXT_HIGHER_FLOATING_POINT.
  2718. //
  2719. FLOAT128 FltS4;
  2720. FLOAT128 FltS5;
  2721. FLOAT128 FltS6;
  2722. FLOAT128 FltS7;
  2723. FLOAT128 FltS8;
  2724. FLOAT128 FltS9;
  2725. FLOAT128 FltS10;
  2726. FLOAT128 FltS11;
  2727. FLOAT128 FltS12;
  2728. FLOAT128 FltS13;
  2729. FLOAT128 FltS14;
  2730. FLOAT128 FltS15;
  2731. FLOAT128 FltS16;
  2732. FLOAT128 FltS17;
  2733. FLOAT128 FltS18;
  2734. FLOAT128 FltS19;
  2735. FLOAT128 FltF32;
  2736. FLOAT128 FltF33;
  2737. FLOAT128 FltF34;
  2738. FLOAT128 FltF35;
  2739. FLOAT128 FltF36;
  2740. FLOAT128 FltF37;
  2741. FLOAT128 FltF38;
  2742. FLOAT128 FltF39;
  2743. FLOAT128 FltF40;
  2744. FLOAT128 FltF41;
  2745. FLOAT128 FltF42;
  2746. FLOAT128 FltF43;
  2747. FLOAT128 FltF44;
  2748. FLOAT128 FltF45;
  2749. FLOAT128 FltF46;
  2750. FLOAT128 FltF47;
  2751. FLOAT128 FltF48;
  2752. FLOAT128 FltF49;
  2753. FLOAT128 FltF50;
  2754. FLOAT128 FltF51;
  2755. FLOAT128 FltF52;
  2756. FLOAT128 FltF53;
  2757. FLOAT128 FltF54;
  2758. FLOAT128 FltF55;
  2759. FLOAT128 FltF56;
  2760. FLOAT128 FltF57;
  2761. FLOAT128 FltF58;
  2762. FLOAT128 FltF59;
  2763. FLOAT128 FltF60;
  2764. FLOAT128 FltF61;
  2765. FLOAT128 FltF62;
  2766. FLOAT128 FltF63;
  2767. FLOAT128 FltF64;
  2768. FLOAT128 FltF65;
  2769. FLOAT128 FltF66;
  2770. FLOAT128 FltF67;
  2771. FLOAT128 FltF68;
  2772. FLOAT128 FltF69;
  2773. FLOAT128 FltF70;
  2774. FLOAT128 FltF71;
  2775. FLOAT128 FltF72;
  2776. FLOAT128 FltF73;
  2777. FLOAT128 FltF74;
  2778. FLOAT128 FltF75;
  2779. FLOAT128 FltF76;
  2780. FLOAT128 FltF77;
  2781. FLOAT128 FltF78;
  2782. FLOAT128 FltF79;
  2783. FLOAT128 FltF80;
  2784. FLOAT128 FltF81;
  2785. FLOAT128 FltF82;
  2786. FLOAT128 FltF83;
  2787. FLOAT128 FltF84;
  2788. FLOAT128 FltF85;
  2789. FLOAT128 FltF86;
  2790. FLOAT128 FltF87;
  2791. FLOAT128 FltF88;
  2792. FLOAT128 FltF89;
  2793. FLOAT128 FltF90;
  2794. FLOAT128 FltF91;
  2795. FLOAT128 FltF92;
  2796. FLOAT128 FltF93;
  2797. FLOAT128 FltF94;
  2798. FLOAT128 FltF95;
  2799. FLOAT128 FltF96;
  2800. FLOAT128 FltF97;
  2801. FLOAT128 FltF98;
  2802. FLOAT128 FltF99;
  2803. FLOAT128 FltF100;
  2804. FLOAT128 FltF101;
  2805. FLOAT128 FltF102;
  2806. FLOAT128 FltF103;
  2807. FLOAT128 FltF104;
  2808. FLOAT128 FltF105;
  2809. FLOAT128 FltF106;
  2810. FLOAT128 FltF107;
  2811. FLOAT128 FltF108;
  2812. FLOAT128 FltF109;
  2813. FLOAT128 FltF110;
  2814. FLOAT128 FltF111;
  2815. FLOAT128 FltF112;
  2816. FLOAT128 FltF113;
  2817. FLOAT128 FltF114;
  2818. FLOAT128 FltF115;
  2819. FLOAT128 FltF116;
  2820. FLOAT128 FltF117;
  2821. FLOAT128 FltF118;
  2822. FLOAT128 FltF119;
  2823. FLOAT128 FltF120;
  2824. FLOAT128 FltF121;
  2825. FLOAT128 FltF122;
  2826. FLOAT128 FltF123;
  2827. FLOAT128 FltF124;
  2828. FLOAT128 FltF125;
  2829. FLOAT128 FltF126;
  2830. FLOAT128 FltF127;
  2831. //
  2832. // This section is specified/returned if the ContextFlags word contains
  2833. // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
  2834. //
  2835. ULONGLONG StFPSR; // FP status
  2836. //
  2837. // This section is specified/returned if the ContextFlags word contains
  2838. // the flag CONTEXT_INTEGER.
  2839. //
  2840. // N.B. The registers gp, sp, rp are part of the control context
  2841. //
  2842. ULONGLONG IntGp; // r1, volatile
  2843. ULONGLONG IntT0; // r2-r3, volatile
  2844. ULONGLONG IntT1; //
  2845. ULONGLONG IntS0; // r4-r7, preserved
  2846. ULONGLONG IntS1;
  2847. ULONGLONG IntS2;
  2848. ULONGLONG IntS3;
  2849. ULONGLONG IntV0; // r8, volatile
  2850. ULONGLONG IntT2; // r9-r11, volatile
  2851. ULONGLONG IntT3;
  2852. ULONGLONG IntT4;
  2853. ULONGLONG IntSp; // stack pointer (r12), special
  2854. ULONGLONG IntTeb; // teb (r13), special
  2855. ULONGLONG IntT5; // r14-r31, volatile
  2856. ULONGLONG IntT6;
  2857. ULONGLONG IntT7;
  2858. ULONGLONG IntT8;
  2859. ULONGLONG IntT9;
  2860. ULONGLONG IntT10;
  2861. ULONGLONG IntT11;
  2862. ULONGLONG IntT12;
  2863. ULONGLONG IntT13;
  2864. ULONGLONG IntT14;
  2865. ULONGLONG IntT15;
  2866. ULONGLONG IntT16;
  2867. ULONGLONG IntT17;
  2868. ULONGLONG IntT18;
  2869. ULONGLONG IntT19;
  2870. ULONGLONG IntT20;
  2871. ULONGLONG IntT21;
  2872. ULONGLONG IntT22;
  2873. ULONGLONG IntNats; // Nat bits for r1-r31
  2874. // r1-r31 in bits 1 thru 31.
  2875. ULONGLONG Preds; // predicates, preserved
  2876. ULONGLONG BrRp; // return pointer, b0, preserved
  2877. ULONGLONG BrS0; // b1-b5, preserved
  2878. ULONGLONG BrS1;
  2879. ULONGLONG BrS2;
  2880. ULONGLONG BrS3;
  2881. ULONGLONG BrS4;
  2882. ULONGLONG BrT0; // b6-b7, volatile
  2883. ULONGLONG BrT1;
  2884. //
  2885. // This section is specified/returned if the ContextFlags word contains
  2886. // the flag CONTEXT_CONTROL.
  2887. //
  2888. // Other application registers
  2889. ULONGLONG ApUNAT; // User Nat collection register, preserved
  2890. ULONGLONG ApLC; // Loop counter register, preserved
  2891. ULONGLONG ApEC; // Epilog counter register, preserved
  2892. ULONGLONG ApCCV; // CMPXCHG value register, volatile
  2893. ULONGLONG ApDCR; // Default control register (TBD)
  2894. // Register stack info
  2895. ULONGLONG RsPFS; // Previous function state, preserved
  2896. ULONGLONG RsBSP; // Backing store pointer, preserved
  2897. ULONGLONG RsBSPSTORE;
  2898. ULONGLONG RsRSC; // RSE configuration, volatile
  2899. ULONGLONG RsRNAT; // RSE Nat collection register, preserved
  2900. // Trap Status Information
  2901. ULONGLONG StIPSR; // Interruption Processor Status
  2902. ULONGLONG StIIP; // Interruption IP
  2903. ULONGLONG StIFS; // Interruption Function State
  2904. // iA32 related control registers
  2905. ULONGLONG StFCR; // copy of Ar21
  2906. ULONGLONG Eflag; // Eflag copy of Ar24
  2907. ULONGLONG SegCSD; // iA32 CSDescriptor (Ar25)
  2908. ULONGLONG SegSSD; // iA32 SSDescriptor (Ar26)
  2909. ULONGLONG Cflag; // Cr0+Cr4 copy of Ar27
  2910. ULONGLONG StFSR; // x86 FP status (copy of AR28)
  2911. ULONGLONG StFIR; // x86 FP status (copy of AR29)
  2912. ULONGLONG StFDR; // x86 FP status (copy of AR30)
  2913. ULONGLONG UNUSEDPACK; // added to pack StFDR to 16-bytes
  2914. } CONTEXT, *PCONTEXT;
  2915. //
  2916. // Plabel descriptor structure definition
  2917. //
  2918. typedef struct _PLABEL_DESCRIPTOR {
  2919. ULONGLONG EntryPoint;
  2920. ULONGLONG GlobalPointer;
  2921. } PLABEL_DESCRIPTOR, *PPLABEL_DESCRIPTOR;
  2922. // end_winnt
  2923. #endif // _IA64_
  2924. //
  2925. // for move macros
  2926. //
  2927. #ifdef _MAC
  2928. #ifndef _INC_STRING
  2929. #include <string.h>
  2930. #endif /* _INC_STRING */
  2931. #else
  2932. #include <string.h>
  2933. #endif // _MAC
  2934. #ifndef _SLIST_HEADER_
  2935. #define _SLIST_HEADER_
  2936. #if defined(_WIN64)
  2937. //
  2938. // The type SINGLE_LIST_ENTRY is not suitable for use with SLISTs. For
  2939. // WIN64, an entry on an SLIST is required to be 16-byte aligned, while a
  2940. // SINGLE_LIST_ENTRY structure has only 8 byte alignment.
  2941. //
  2942. // Therefore, all SLIST code should use the SLIST_ENTRY type instead of the
  2943. // SINGLE_LIST_ENTRY type.
  2944. //
  2945. #pragma warning(push)
  2946. #pragma warning(disable:4324) // structure padded due to align()
  2947. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
  2948. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
  2949. PSLIST_ENTRY Next;
  2950. } SLIST_ENTRY;
  2951. #pragma warning(pop)
  2952. #else
  2953. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  2954. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  2955. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  2956. #endif
  2957. #if defined(_WIN64)
  2958. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  2959. ULONGLONG Alignment;
  2960. ULONGLONG Region;
  2961. } SLIST_HEADER;
  2962. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  2963. #else
  2964. typedef union _SLIST_HEADER {
  2965. ULONGLONG Alignment;
  2966. struct {
  2967. SLIST_ENTRY Next;
  2968. USHORT Depth;
  2969. USHORT Sequence;
  2970. };
  2971. } SLIST_HEADER, *PSLIST_HEADER;
  2972. #endif
  2973. #endif
  2974. //
  2975. // If debugging support enabled, define an ASSERT macro that works. Otherwise
  2976. // define the ASSERT macro to expand to an empty expression.
  2977. //
  2978. // The ASSERT macro has been updated to be an expression instead of a statement.
  2979. //
  2980. NTSYSAPI
  2981. VOID
  2982. NTAPI
  2983. RtlAssert(
  2984. PVOID FailedAssertion,
  2985. PVOID FileName,
  2986. ULONG LineNumber,
  2987. PCHAR Message
  2988. );
  2989. #if DBG
  2990. #define ASSERT( exp ) \
  2991. ((!(exp)) ? \
  2992. (RtlAssert( #exp, __FILE__, __LINE__, NULL ),FALSE) : \
  2993. TRUE)
  2994. #define ASSERTMSG( msg, exp ) \
  2995. ((!(exp)) ? \
  2996. (RtlAssert( #exp, __FILE__, __LINE__, msg ),FALSE) : \
  2997. TRUE)
  2998. #define RTL_SOFT_ASSERT(_exp) \
  2999. ((!(_exp)) ? \
  3000. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #_exp),FALSE) : \
  3001. TRUE)
  3002. #define RTL_SOFT_ASSERTMSG(_msg, _exp) \
  3003. ((!(_exp)) ? \
  3004. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #_exp, (_msg)),FALSE) : \
  3005. TRUE)
  3006. #define RTL_VERIFY ASSERT
  3007. #define RTL_VERIFYMSG ASSERTMSG
  3008. #define RTL_SOFT_VERIFY RTL_SOFT_ASSERT
  3009. #define RTL_SOFT_VERIFYMSG RTL_SOFT_ASSERTMSG
  3010. #else
  3011. #define ASSERT( exp ) ((void) 0)
  3012. #define ASSERTMSG( msg, exp ) ((void) 0)
  3013. #define RTL_SOFT_ASSERT(_exp) ((void) 0)
  3014. #define RTL_SOFT_ASSERTMSG(_msg, _exp) ((void) 0)
  3015. #define RTL_VERIFY( exp ) ((exp) ? TRUE : FALSE)
  3016. #define RTL_VERIFYMSG( msg, exp ) ((exp) ? TRUE : FALSE)
  3017. #define RTL_SOFT_VERIFY(_exp) ((_exp) ? TRUE : FALSE)
  3018. #define RTL_SOFT_VERIFYMSG(msg, _exp) ((_exp) ? TRUE : FALSE)
  3019. #endif // DBG
  3020. //
  3021. // Doubly-linked list manipulation routines.
  3022. //
  3023. //
  3024. // VOID
  3025. // InitializeListHead32(
  3026. // PLIST_ENTRY32 ListHead
  3027. // );
  3028. //
  3029. #define InitializeListHead32(ListHead) (\
  3030. (ListHead)->Flink = (ListHead)->Blink = PtrToUlong((ListHead)))
  3031. #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
  3032. VOID
  3033. FORCEINLINE
  3034. InitializeListHead(
  3035. IN PLIST_ENTRY ListHead
  3036. )
  3037. {
  3038. ListHead->Flink = ListHead->Blink = ListHead;
  3039. }
  3040. //
  3041. // BOOLEAN
  3042. // IsListEmpty(
  3043. // PLIST_ENTRY ListHead
  3044. // );
  3045. //
  3046. #define IsListEmpty(ListHead) \
  3047. ((ListHead)->Flink == (ListHead))
  3048. BOOLEAN
  3049. FORCEINLINE
  3050. RemoveEntryList(
  3051. IN PLIST_ENTRY Entry
  3052. )
  3053. {
  3054. PLIST_ENTRY Blink;
  3055. PLIST_ENTRY Flink;
  3056. Flink = Entry->Flink;
  3057. Blink = Entry->Blink;
  3058. Blink->Flink = Flink;
  3059. Flink->Blink = Blink;
  3060. return (BOOLEAN)(Flink == Blink);
  3061. }
  3062. PLIST_ENTRY
  3063. FORCEINLINE
  3064. RemoveHeadList(
  3065. IN PLIST_ENTRY ListHead
  3066. )
  3067. {
  3068. PLIST_ENTRY Flink;
  3069. PLIST_ENTRY Entry;
  3070. Entry = ListHead->Flink;
  3071. Flink = Entry->Flink;
  3072. ListHead->Flink = Flink;
  3073. Flink->Blink = ListHead;
  3074. return Entry;
  3075. }
  3076. PLIST_ENTRY
  3077. FORCEINLINE
  3078. RemoveTailList(
  3079. IN PLIST_ENTRY ListHead
  3080. )
  3081. {
  3082. PLIST_ENTRY Blink;
  3083. PLIST_ENTRY Entry;
  3084. Entry = ListHead->Blink;
  3085. Blink = Entry->Blink;
  3086. ListHead->Blink = Blink;
  3087. Blink->Flink = ListHead;
  3088. return Entry;
  3089. }
  3090. VOID
  3091. FORCEINLINE
  3092. InsertTailList(
  3093. IN PLIST_ENTRY ListHead,
  3094. IN PLIST_ENTRY Entry
  3095. )
  3096. {
  3097. PLIST_ENTRY Blink;
  3098. Blink = ListHead->Blink;
  3099. Entry->Flink = ListHead;
  3100. Entry->Blink = Blink;
  3101. Blink->Flink = Entry;
  3102. ListHead->Blink = Entry;
  3103. }
  3104. VOID
  3105. FORCEINLINE
  3106. InsertHeadList(
  3107. IN PLIST_ENTRY ListHead,
  3108. IN PLIST_ENTRY Entry
  3109. )
  3110. {
  3111. PLIST_ENTRY Flink;
  3112. Flink = ListHead->Flink;
  3113. Entry->Flink = Flink;
  3114. Entry->Blink = ListHead;
  3115. Flink->Blink = Entry;
  3116. ListHead->Flink = Entry;
  3117. }
  3118. //
  3119. //
  3120. // PSINGLE_LIST_ENTRY
  3121. // PopEntryList(
  3122. // PSINGLE_LIST_ENTRY ListHead
  3123. // );
  3124. //
  3125. #define PopEntryList(ListHead) \
  3126. (ListHead)->Next;\
  3127. {\
  3128. PSINGLE_LIST_ENTRY FirstEntry;\
  3129. FirstEntry = (ListHead)->Next;\
  3130. if (FirstEntry != NULL) { \
  3131. (ListHead)->Next = FirstEntry->Next;\
  3132. } \
  3133. }
  3134. //
  3135. // VOID
  3136. // PushEntryList(
  3137. // PSINGLE_LIST_ENTRY ListHead,
  3138. // PSINGLE_LIST_ENTRY Entry
  3139. // );
  3140. //
  3141. #define PushEntryList(ListHead,Entry) \
  3142. (Entry)->Next = (ListHead)->Next; \
  3143. (ListHead)->Next = (Entry)
  3144. #endif // !MIDL_PASS
  3145. //
  3146. // This enumerated type is used as the function return value of the function
  3147. // that is used to search the tree for a key. FoundNode indicates that the
  3148. // function found the key. Insert as left indicates that the key was not found
  3149. // and the node should be inserted as the left child of the parent. Insert as
  3150. // right indicates that the key was not found and the node should be inserted
  3151. // as the right child of the parent.
  3152. //
  3153. typedef enum _TABLE_SEARCH_RESULT{
  3154. TableEmptyTree,
  3155. TableFoundNode,
  3156. TableInsertAsLeft,
  3157. TableInsertAsRight
  3158. } TABLE_SEARCH_RESULT;
  3159. //
  3160. // The results of a compare can be less than, equal, or greater than.
  3161. //
  3162. typedef enum _RTL_GENERIC_COMPARE_RESULTS {
  3163. GenericLessThan,
  3164. GenericGreaterThan,
  3165. GenericEqual
  3166. } RTL_GENERIC_COMPARE_RESULTS;
  3167. //
  3168. // Define the Avl version of the generic table package. Note a generic table
  3169. // should really be an opaque type. We provide routines to manipulate the structure.
  3170. //
  3171. // A generic table is package for inserting, deleting, and looking up elements
  3172. // in a table (e.g., in a symbol table). To use this package the user
  3173. // defines the structure of the elements stored in the table, provides a
  3174. // comparison function, a memory allocation function, and a memory
  3175. // deallocation function.
  3176. //
  3177. // Note: the user compare function must impose a complete ordering among
  3178. // all of the elements, and the table does not allow for duplicate entries.
  3179. //
  3180. //
  3181. // Add an empty typedef so that functions can reference the
  3182. // a pointer to the generic table struct before it is declared.
  3183. //
  3184. struct _RTL_AVL_TABLE;
  3185. //
  3186. // The comparison function takes as input pointers to elements containing
  3187. // user defined structures and returns the results of comparing the two
  3188. // elements.
  3189. //
  3190. typedef
  3191. RTL_GENERIC_COMPARE_RESULTS
  3192. (NTAPI *PRTL_AVL_COMPARE_ROUTINE) (
  3193. struct _RTL_AVL_TABLE *Table,
  3194. PVOID FirstStruct,
  3195. PVOID SecondStruct
  3196. );
  3197. //
  3198. // The allocation function is called by the generic table package whenever
  3199. // it needs to allocate memory for the table.
  3200. //
  3201. typedef
  3202. PVOID
  3203. (NTAPI *PRTL_AVL_ALLOCATE_ROUTINE) (
  3204. struct _RTL_AVL_TABLE *Table,
  3205. CLONG ByteSize
  3206. );
  3207. //
  3208. // The deallocation function is called by the generic table package whenever
  3209. // it needs to deallocate memory from the table that was allocated by calling
  3210. // the user supplied allocation function.
  3211. //
  3212. typedef
  3213. VOID
  3214. (NTAPI *PRTL_AVL_FREE_ROUTINE) (
  3215. struct _RTL_AVL_TABLE *Table,
  3216. PVOID Buffer
  3217. );
  3218. //
  3219. // The match function takes as input the user data to be matched and a pointer
  3220. // to some match data, which was passed along with the function pointer. It
  3221. // returns TRUE for a match and FALSE for no match.
  3222. //
  3223. // RTL_AVL_MATCH_FUNCTION returns
  3224. // STATUS_SUCCESS if the IndexRow matches
  3225. // STATUS_NO_MATCH if the IndexRow does not match, but the enumeration should
  3226. // continue
  3227. // STATUS_NO_MORE_MATCHES if the IndexRow does not match, and the enumeration
  3228. // should terminate
  3229. //
  3230. typedef
  3231. NTSTATUS
  3232. (NTAPI *PRTL_AVL_MATCH_FUNCTION) (
  3233. struct _RTL_AVL_TABLE *Table,
  3234. PVOID UserData,
  3235. PVOID MatchData
  3236. );
  3237. //
  3238. // Define the balanced tree links and Balance field. (No Rank field
  3239. // defined at this time.)
  3240. //
  3241. // Callers should treat this structure as opaque!
  3242. //
  3243. // The root of a balanced binary tree is not a real node in the tree
  3244. // but rather points to a real node which is the root. It is always
  3245. // in the table below, and its fields are used as follows:
  3246. //
  3247. // Parent Pointer to self, to allow for detection of the root.
  3248. // LeftChild NULL
  3249. // RightChild Pointer to real root
  3250. // Balance Undefined, however it is set to a convenient value
  3251. // (depending on the algorithm) prior to rebalancing
  3252. // in insert and delete routines.
  3253. //
  3254. typedef struct _RTL_BALANCED_LINKS {
  3255. struct _RTL_BALANCED_LINKS *Parent;
  3256. struct _RTL_BALANCED_LINKS *LeftChild;
  3257. struct _RTL_BALANCED_LINKS *RightChild;
  3258. CHAR Balance;
  3259. UCHAR Reserved[3];
  3260. } RTL_BALANCED_LINKS;
  3261. typedef RTL_BALANCED_LINKS *PRTL_BALANCED_LINKS;
  3262. //
  3263. // To use the generic table package the user declares a variable of type
  3264. // GENERIC_TABLE and then uses the routines described below to initialize
  3265. // the table and to manipulate the table. Note that the generic table
  3266. // should really be an opaque type.
  3267. //
  3268. typedef struct _RTL_AVL_TABLE {
  3269. RTL_BALANCED_LINKS BalancedRoot;
  3270. PVOID OrderedPointer;
  3271. ULONG WhichOrderedElement;
  3272. ULONG NumberGenericTableElements;
  3273. ULONG DepthOfTree;
  3274. PRTL_BALANCED_LINKS RestartKey;
  3275. ULONG DeleteCount;
  3276. PRTL_AVL_COMPARE_ROUTINE CompareRoutine;
  3277. PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine;
  3278. PRTL_AVL_FREE_ROUTINE FreeRoutine;
  3279. PVOID TableContext;
  3280. } RTL_AVL_TABLE;
  3281. typedef RTL_AVL_TABLE *PRTL_AVL_TABLE;
  3282. //
  3283. // The procedure InitializeGenericTable takes as input an uninitialized
  3284. // generic table variable and pointers to the three user supplied routines.
  3285. // This must be called for every individual generic table variable before
  3286. // it can be used.
  3287. //
  3288. NTSYSAPI
  3289. VOID
  3290. NTAPI
  3291. RtlInitializeGenericTableAvl (
  3292. PRTL_AVL_TABLE Table,
  3293. PRTL_AVL_COMPARE_ROUTINE CompareRoutine,
  3294. PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine,
  3295. PRTL_AVL_FREE_ROUTINE FreeRoutine,
  3296. PVOID TableContext
  3297. );
  3298. //
  3299. // The function InsertElementGenericTable will insert a new element
  3300. // in a table. It does this by allocating space for the new element
  3301. // (this includes AVL links), inserting the element in the table, and
  3302. // then returning to the user a pointer to the new element. If an element
  3303. // with the same key already exists in the table the return value is a pointer
  3304. // to the old element. The optional output parameter NewElement is used
  3305. // to indicate if the element previously existed in the table. Note: the user
  3306. // supplied Buffer is only used for searching the table, upon insertion its
  3307. // contents are copied to the newly created element. This means that
  3308. // pointer to the input buffer will not point to the new element.
  3309. //
  3310. NTSYSAPI
  3311. PVOID
  3312. NTAPI
  3313. RtlInsertElementGenericTableAvl (
  3314. PRTL_AVL_TABLE Table,
  3315. PVOID Buffer,
  3316. CLONG BufferSize,
  3317. PBOOLEAN NewElement OPTIONAL
  3318. );
  3319. //
  3320. // The function InsertElementGenericTableFull will insert a new element
  3321. // in a table. It does this by allocating space for the new element
  3322. // (this includes AVL links), inserting the element in the table, and
  3323. // then returning to the user a pointer to the new element. If an element
  3324. // with the same key already exists in the table the return value is a pointer
  3325. // to the old element. The optional output parameter NewElement is used
  3326. // to indicate if the element previously existed in the table. Note: the user
  3327. // supplied Buffer is only used for searching the table, upon insertion its
  3328. // contents are copied to the newly created element. This means that
  3329. // pointer to the input buffer will not point to the new element.
  3330. // This routine is passed the NodeOrParent and SearchResult from a
  3331. // previous RtlLookupElementGenericTableFull.
  3332. //
  3333. NTSYSAPI
  3334. PVOID
  3335. NTAPI
  3336. RtlInsertElementGenericTableFullAvl (
  3337. PRTL_AVL_TABLE Table,
  3338. PVOID Buffer,
  3339. CLONG BufferSize,
  3340. PBOOLEAN NewElement OPTIONAL,
  3341. PVOID NodeOrParent,
  3342. TABLE_SEARCH_RESULT SearchResult
  3343. );
  3344. //
  3345. // The function DeleteElementGenericTable will find and delete an element
  3346. // from a generic table. If the element is located and deleted the return
  3347. // value is TRUE, otherwise if the element is not located the return value
  3348. // is FALSE. The user supplied input buffer is only used as a key in
  3349. // locating the element in the table.
  3350. //
  3351. NTSYSAPI
  3352. BOOLEAN
  3353. NTAPI
  3354. RtlDeleteElementGenericTableAvl (
  3355. PRTL_AVL_TABLE Table,
  3356. PVOID Buffer
  3357. );
  3358. //
  3359. // The function LookupElementGenericTable will find an element in a generic
  3360. // table. If the element is located the return value is a pointer to
  3361. // the user defined structure associated with the element, otherwise if
  3362. // the element is not located the return value is NULL. The user supplied
  3363. // input buffer is only used as a key in locating the element in the table.
  3364. //
  3365. NTSYSAPI
  3366. PVOID
  3367. NTAPI
  3368. RtlLookupElementGenericTableAvl (
  3369. PRTL_AVL_TABLE Table,
  3370. PVOID Buffer
  3371. );
  3372. //
  3373. // The function LookupElementGenericTableFull will find an element in a generic
  3374. // table. If the element is located the return value is a pointer to
  3375. // the user defined structure associated with the element. If the element is not
  3376. // located then a pointer to the parent for the insert location is returned. The
  3377. // user must look at the SearchResult value to determine which is being returned.
  3378. // The user can use the SearchResult and parent for a subsequent FullInsertElement
  3379. // call to optimize the insert.
  3380. //
  3381. NTSYSAPI
  3382. PVOID
  3383. NTAPI
  3384. RtlLookupElementGenericTableFullAvl (
  3385. PRTL_AVL_TABLE Table,
  3386. PVOID Buffer,
  3387. OUT PVOID *NodeOrParent,
  3388. OUT TABLE_SEARCH_RESULT *SearchResult
  3389. );
  3390. //
  3391. // The function EnumerateGenericTable will return to the caller one-by-one
  3392. // the elements of of a table. The return value is a pointer to the user
  3393. // defined structure associated with the element. The input parameter
  3394. // Restart indicates if the enumeration should start from the beginning
  3395. // or should return the next element. If the are no more new elements to
  3396. // return the return value is NULL. As an example of its use, to enumerate
  3397. // all of the elements in a table the user would write:
  3398. //
  3399. // for (ptr = EnumerateGenericTable(Table, TRUE);
  3400. // ptr != NULL;
  3401. // ptr = EnumerateGenericTable(Table, FALSE)) {
  3402. // :
  3403. // }
  3404. //
  3405. // NOTE: This routine does not modify the structure of the tree, but saves
  3406. // the last node returned in the generic table itself, and for this
  3407. // reason requires exclusive access to the table for the duration of
  3408. // the enumeration.
  3409. //
  3410. NTSYSAPI
  3411. PVOID
  3412. NTAPI
  3413. RtlEnumerateGenericTableAvl (
  3414. PRTL_AVL_TABLE Table,
  3415. BOOLEAN Restart
  3416. );
  3417. //
  3418. // The function EnumerateGenericTableWithoutSplaying will return to the
  3419. // caller one-by-one the elements of of a table. The return value is a
  3420. // pointer to the user defined structure associated with the element.
  3421. // The input parameter RestartKey indicates if the enumeration should
  3422. // start from the beginning or should return the next element. If the
  3423. // are no more new elements to return the return value is NULL. As an
  3424. // example of its use, to enumerate all of the elements in a table the
  3425. // user would write:
  3426. //
  3427. // RestartKey = NULL;
  3428. // for (ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey);
  3429. // ptr != NULL;
  3430. // ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey)) {
  3431. // :
  3432. // }
  3433. //
  3434. // If RestartKey is NULL, the package will start from the least entry in the
  3435. // table, otherwise it will start from the last entry returned.
  3436. //
  3437. // NOTE: This routine does not modify either the structure of the tree
  3438. // or the generic table itself, but must insure that no deletes
  3439. // occur for the duration of the enumeration, typically by having
  3440. // at least shared access to the table for the duration.
  3441. //
  3442. NTSYSAPI
  3443. PVOID
  3444. NTAPI
  3445. RtlEnumerateGenericTableWithoutSplayingAvl (
  3446. PRTL_AVL_TABLE Table,
  3447. PVOID *RestartKey
  3448. );
  3449. //
  3450. // The function EnumerateGenericTableLikeADirectory will return to the
  3451. // caller one-by-one the elements of of a table. The return value is a
  3452. // pointer to the user defined structure associated with the element.
  3453. // The input parameter RestartKey indicates if the enumeration should
  3454. // start from the beginning or should return the next element. If the
  3455. // are no more new elements to return the return value is NULL. As an
  3456. // example of its use, to enumerate all of the elements in a table the
  3457. // user would write:
  3458. //
  3459. // RestartKey = NULL;
  3460. // for (ptr = EnumerateGenericTableLikeADirectory(Table, &RestartKey, ...);
  3461. // ptr != NULL;
  3462. // ptr = EnumerateGenericTableLikeADirectory(Table, &RestartKey, ...)) {
  3463. // :
  3464. // }
  3465. //
  3466. // If RestartKey is NULL, the package will start from the least entry in the
  3467. // table, otherwise it will start from the last entry returned.
  3468. //
  3469. // NOTE: This routine does not modify either the structure of the tree
  3470. // or the generic table itself. The table must only be acquired
  3471. // shared for the duration of this call, and all synchronization
  3472. // may optionally be dropped between calls. Enumeration is always
  3473. // correctly resumed in the most efficient manner possible via the
  3474. // IN OUT parameters provided.
  3475. //
  3476. // ****** Explain NextFlag. Directory enumeration resumes from a key
  3477. // requires more thought. Also need the match pattern and IgnoreCase.
  3478. // Should some structure be introduced to carry it all?
  3479. //
  3480. NTSYSAPI
  3481. PVOID
  3482. NTAPI
  3483. RtlEnumerateGenericTableLikeADirectory (
  3484. IN PRTL_AVL_TABLE Table,
  3485. IN PRTL_AVL_MATCH_FUNCTION MatchFunction,
  3486. IN PVOID MatchData,
  3487. IN ULONG NextFlag,
  3488. IN OUT PVOID *RestartKey,
  3489. IN OUT PULONG DeleteCount,
  3490. IN OUT PVOID Buffer
  3491. );
  3492. //
  3493. // The function GetElementGenericTable will return the i'th element
  3494. // inserted in the generic table. I = 0 implies the first element,
  3495. // I = (RtlNumberGenericTableElements(Table)-1) will return the last element
  3496. // inserted into the generic table. The type of I is ULONG. Values
  3497. // of I > than (NumberGenericTableElements(Table)-1) will return NULL. If
  3498. // an arbitrary element is deleted from the generic table it will cause
  3499. // all elements inserted after the deleted element to "move up".
  3500. NTSYSAPI
  3501. PVOID
  3502. NTAPI
  3503. RtlGetElementGenericTableAvl (
  3504. PRTL_AVL_TABLE Table,
  3505. ULONG I
  3506. );
  3507. //
  3508. // The function NumberGenericTableElements returns a ULONG value
  3509. // which is the number of generic table elements currently inserted
  3510. // in the generic table.
  3511. NTSYSAPI
  3512. ULONG
  3513. NTAPI
  3514. RtlNumberGenericTableElementsAvl (
  3515. PRTL_AVL_TABLE Table
  3516. );
  3517. //
  3518. // The function IsGenericTableEmpty will return to the caller TRUE if
  3519. // the input table is empty (i.e., does not contain any elements) and
  3520. // FALSE otherwise.
  3521. //
  3522. NTSYSAPI
  3523. BOOLEAN
  3524. NTAPI
  3525. RtlIsGenericTableEmptyAvl (
  3526. PRTL_AVL_TABLE Table
  3527. );
  3528. //
  3529. // As an aid to allowing existing generic table users to do (in most
  3530. // cases) a single-line edit to switch over to Avl table use, we
  3531. // have the following defines and inline routine definitions which
  3532. // redirect calls and types. Note that the type override (performed
  3533. // by #define below) will not work in the unexpected event that someone
  3534. // has used a pointer or type specifier in their own #define, since
  3535. // #define processing is one pass and does not nest. The __inline
  3536. // declarations below do not have this limitation, however.
  3537. //
  3538. // To switch to using Avl tables, add the following line before your
  3539. // includes:
  3540. //
  3541. // #define RTL_USE_AVL_TABLES 0
  3542. //
  3543. #ifdef RTL_USE_AVL_TABLES
  3544. #undef PRTL_GENERIC_COMPARE_ROUTINE
  3545. #undef PRTL_GENERIC_ALLOCATE_ROUTINE
  3546. #undef PRTL_GENERIC_FREE_ROUTINE
  3547. #undef RTL_GENERIC_TABLE
  3548. #undef PRTL_GENERIC_TABLE
  3549. #define PRTL_GENERIC_COMPARE_ROUTINE PRTL_AVL_COMPARE_ROUTINE
  3550. #define PRTL_GENERIC_ALLOCATE_ROUTINE PRTL_AVL_ALLOCATE_ROUTINE
  3551. #define PRTL_GENERIC_FREE_ROUTINE PRTL_AVL_FREE_ROUTINE
  3552. #define RTL_GENERIC_TABLE RTL_AVL_TABLE
  3553. #define PRTL_GENERIC_TABLE PRTL_AVL_TABLE
  3554. #define RtlInitializeGenericTable RtlInitializeGenericTableAvl
  3555. #define RtlInsertElementGenericTable RtlInsertElementGenericTableAvl
  3556. #define RtlInsertElementGenericTableFull RtlInsertElementGenericTableFullAvl
  3557. #define RtlDeleteElementGenericTable RtlDeleteElementGenericTableAvl
  3558. #define RtlLookupElementGenericTable RtlLookupElementGenericTableAvl
  3559. #define RtlLookupElementGenericTableFull RtlLookupElementGenericTableFullAvl
  3560. #define RtlEnumerateGenericTable RtlEnumerateGenericTableAvl
  3561. #define RtlEnumerateGenericTableWithoutSplaying RtlEnumerateGenericTableWithoutSplayingAvl
  3562. #define RtlGetElementGenericTable RtlGetElementGenericTableAvl
  3563. #define RtlNumberGenericTableElements RtlNumberGenericTableElementsAvl
  3564. #define RtlIsGenericTableEmpty RtlIsGenericTableEmptyAvl
  3565. #endif // RTL_USE_AVL_TABLES
  3566. //
  3567. // Define the splay links and the associated manipuliation macros and
  3568. // routines. Note that the splay_links should be an opaque type.
  3569. // Routine are provided to traverse and manipulate the structure.
  3570. //
  3571. typedef struct _RTL_SPLAY_LINKS {
  3572. struct _RTL_SPLAY_LINKS *Parent;
  3573. struct _RTL_SPLAY_LINKS *LeftChild;
  3574. struct _RTL_SPLAY_LINKS *RightChild;
  3575. } RTL_SPLAY_LINKS;
  3576. typedef RTL_SPLAY_LINKS *PRTL_SPLAY_LINKS;
  3577. //
  3578. // The macro procedure InitializeSplayLinks takes as input a pointer to
  3579. // splay link and initializes its substructure. All splay link nodes must
  3580. // be initialized before they are used in the different splay routines and
  3581. // macros.
  3582. //
  3583. // VOID
  3584. // RtlInitializeSplayLinks (
  3585. // PRTL_SPLAY_LINKS Links
  3586. // );
  3587. //
  3588. #define RtlInitializeSplayLinks(Links) { \
  3589. PRTL_SPLAY_LINKS _SplayLinks; \
  3590. _SplayLinks = (PRTL_SPLAY_LINKS)(Links); \
  3591. _SplayLinks->Parent = _SplayLinks; \
  3592. _SplayLinks->LeftChild = NULL; \
  3593. _SplayLinks->RightChild = NULL; \
  3594. }
  3595. //
  3596. // The macro function Parent takes as input a pointer to a splay link in a
  3597. // tree and returns a pointer to the splay link of the parent of the input
  3598. // node. If the input node is the root of the tree the return value is
  3599. // equal to the input value.
  3600. //
  3601. // PRTL_SPLAY_LINKS
  3602. // RtlParent (
  3603. // PRTL_SPLAY_LINKS Links
  3604. // );
  3605. //
  3606. #define RtlParent(Links) ( \
  3607. (PRTL_SPLAY_LINKS)(Links)->Parent \
  3608. )
  3609. //
  3610. // The macro function LeftChild takes as input a pointer to a splay link in
  3611. // a tree and returns a pointer to the splay link of the left child of the
  3612. // input node. If the left child does not exist, the return value is NULL.
  3613. //
  3614. // PRTL_SPLAY_LINKS
  3615. // RtlLeftChild (
  3616. // PRTL_SPLAY_LINKS Links
  3617. // );
  3618. //
  3619. #define RtlLeftChild(Links) ( \
  3620. (PRTL_SPLAY_LINKS)(Links)->LeftChild \
  3621. )
  3622. //
  3623. // The macro function RightChild takes as input a pointer to a splay link
  3624. // in a tree and returns a pointer to the splay link of the right child of
  3625. // the input node. If the right child does not exist, the return value is
  3626. // NULL.
  3627. //
  3628. // PRTL_SPLAY_LINKS
  3629. // RtlRightChild (
  3630. // PRTL_SPLAY_LINKS Links
  3631. // );
  3632. //
  3633. #define RtlRightChild(Links) ( \
  3634. (PRTL_SPLAY_LINKS)(Links)->RightChild \
  3635. )
  3636. //
  3637. // The macro function IsRoot takes as input a pointer to a splay link
  3638. // in a tree and returns TRUE if the input node is the root of the tree,
  3639. // otherwise it returns FALSE.
  3640. //
  3641. // BOOLEAN
  3642. // RtlIsRoot (
  3643. // PRTL_SPLAY_LINKS Links
  3644. // );
  3645. //
  3646. #define RtlIsRoot(Links) ( \
  3647. (RtlParent(Links) == (PRTL_SPLAY_LINKS)(Links)) \
  3648. )
  3649. //
  3650. // The macro function IsLeftChild takes as input a pointer to a splay link
  3651. // in a tree and returns TRUE if the input node is the left child of its
  3652. // parent, otherwise it returns FALSE.
  3653. //
  3654. // BOOLEAN
  3655. // RtlIsLeftChild (
  3656. // PRTL_SPLAY_LINKS Links
  3657. // );
  3658. //
  3659. #define RtlIsLeftChild(Links) ( \
  3660. (RtlLeftChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links)) \
  3661. )
  3662. //
  3663. // The macro function IsRightChild takes as input a pointer to a splay link
  3664. // in a tree and returns TRUE if the input node is the right child of its
  3665. // parent, otherwise it returns FALSE.
  3666. //
  3667. // BOOLEAN
  3668. // RtlIsRightChild (
  3669. // PRTL_SPLAY_LINKS Links
  3670. // );
  3671. //
  3672. #define RtlIsRightChild(Links) ( \
  3673. (RtlRightChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links)) \
  3674. )
  3675. //
  3676. // The macro procedure InsertAsLeftChild takes as input a pointer to a splay
  3677. // link in a tree and a pointer to a node not in a tree. It inserts the
  3678. // second node as the left child of the first node. The first node must not
  3679. // already have a left child, and the second node must not already have a
  3680. // parent.
  3681. //
  3682. // VOID
  3683. // RtlInsertAsLeftChild (
  3684. // PRTL_SPLAY_LINKS ParentLinks,
  3685. // PRTL_SPLAY_LINKS ChildLinks
  3686. // );
  3687. //
  3688. #define RtlInsertAsLeftChild(ParentLinks,ChildLinks) { \
  3689. PRTL_SPLAY_LINKS _SplayParent; \
  3690. PRTL_SPLAY_LINKS _SplayChild; \
  3691. _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
  3692. _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
  3693. _SplayParent->LeftChild = _SplayChild; \
  3694. _SplayChild->Parent = _SplayParent; \
  3695. }
  3696. //
  3697. // The macro procedure InsertAsRightChild takes as input a pointer to a splay
  3698. // link in a tree and a pointer to a node not in a tree. It inserts the
  3699. // second node as the right child of the first node. The first node must not
  3700. // already have a right child, and the second node must not already have a
  3701. // parent.
  3702. //
  3703. // VOID
  3704. // RtlInsertAsRightChild (
  3705. // PRTL_SPLAY_LINKS ParentLinks,
  3706. // PRTL_SPLAY_LINKS ChildLinks
  3707. // );
  3708. //
  3709. #define RtlInsertAsRightChild(ParentLinks,ChildLinks) { \
  3710. PRTL_SPLAY_LINKS _SplayParent; \
  3711. PRTL_SPLAY_LINKS _SplayChild; \
  3712. _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
  3713. _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
  3714. _SplayParent->RightChild = _SplayChild; \
  3715. _SplayChild->Parent = _SplayParent; \
  3716. }
  3717. //
  3718. // The Splay function takes as input a pointer to a splay link in a tree
  3719. // and splays the tree. Its function return value is a pointer to the
  3720. // root of the splayed tree.
  3721. //
  3722. NTSYSAPI
  3723. PRTL_SPLAY_LINKS
  3724. NTAPI
  3725. RtlSplay (
  3726. PRTL_SPLAY_LINKS Links
  3727. );
  3728. //
  3729. // The Delete function takes as input a pointer to a splay link in a tree
  3730. // and deletes that node from the tree. Its function return value is a
  3731. // pointer to the root of the tree. If the tree is now empty, the return
  3732. // value is NULL.
  3733. //
  3734. NTSYSAPI
  3735. PRTL_SPLAY_LINKS
  3736. NTAPI
  3737. RtlDelete (
  3738. PRTL_SPLAY_LINKS Links
  3739. );
  3740. //
  3741. // The DeleteNoSplay function takes as input a pointer to a splay link in a tree,
  3742. // the caller's pointer to the root of the tree and deletes that node from the
  3743. // tree. Upon return the caller's pointer to the root node will correctly point
  3744. // at the root of the tree.
  3745. //
  3746. // It operationally differs from RtlDelete only in that it will not splay the tree.
  3747. //
  3748. NTSYSAPI
  3749. VOID
  3750. NTAPI
  3751. RtlDeleteNoSplay (
  3752. PRTL_SPLAY_LINKS Links,
  3753. PRTL_SPLAY_LINKS *Root
  3754. );
  3755. //
  3756. // The SubtreeSuccessor function takes as input a pointer to a splay link
  3757. // in a tree and returns a pointer to the successor of the input node of
  3758. // the substree rooted at the input node. If there is not a successor, the
  3759. // return value is NULL.
  3760. //
  3761. NTSYSAPI
  3762. PRTL_SPLAY_LINKS
  3763. NTAPI
  3764. RtlSubtreeSuccessor (
  3765. PRTL_SPLAY_LINKS Links
  3766. );
  3767. //
  3768. // The SubtreePredecessor function takes as input a pointer to a splay link
  3769. // in a tree and returns a pointer to the predecessor of the input node of
  3770. // the substree rooted at the input node. If there is not a predecessor,
  3771. // the return value is NULL.
  3772. //
  3773. NTSYSAPI
  3774. PRTL_SPLAY_LINKS
  3775. NTAPI
  3776. RtlSubtreePredecessor (
  3777. PRTL_SPLAY_LINKS Links
  3778. );
  3779. //
  3780. // The RealSuccessor function takes as input a pointer to a splay link
  3781. // in a tree and returns a pointer to the successor of the input node within
  3782. // the entire tree. If there is not a successor, the return value is NULL.
  3783. //
  3784. NTSYSAPI
  3785. PRTL_SPLAY_LINKS
  3786. NTAPI
  3787. RtlRealSuccessor (
  3788. PRTL_SPLAY_LINKS Links
  3789. );
  3790. //
  3791. // The RealPredecessor function takes as input a pointer to a splay link
  3792. // in a tree and returns a pointer to the predecessor of the input node
  3793. // within the entire tree. If there is not a predecessor, the return value
  3794. // is NULL.
  3795. //
  3796. NTSYSAPI
  3797. PRTL_SPLAY_LINKS
  3798. NTAPI
  3799. RtlRealPredecessor (
  3800. PRTL_SPLAY_LINKS Links
  3801. );
  3802. //
  3803. // Define the generic table package. Note a generic table should really
  3804. // be an opaque type. We provide routines to manipulate the structure.
  3805. //
  3806. // A generic table is package for inserting, deleting, and looking up elements
  3807. // in a table (e.g., in a symbol table). To use this package the user
  3808. // defines the structure of the elements stored in the table, provides a
  3809. // comparison function, a memory allocation function, and a memory
  3810. // deallocation function.
  3811. //
  3812. // Note: the user compare function must impose a complete ordering among
  3813. // all of the elements, and the table does not allow for duplicate entries.
  3814. //
  3815. //
  3816. // Do not do the following defines if using Avl
  3817. //
  3818. #ifndef RTL_USE_AVL_TABLES
  3819. //
  3820. // Add an empty typedef so that functions can reference the
  3821. // a pointer to the generic table struct before it is declared.
  3822. //
  3823. struct _RTL_GENERIC_TABLE;
  3824. //
  3825. // The comparison function takes as input pointers to elements containing
  3826. // user defined structures and returns the results of comparing the two
  3827. // elements.
  3828. //
  3829. typedef
  3830. RTL_GENERIC_COMPARE_RESULTS
  3831. (NTAPI *PRTL_GENERIC_COMPARE_ROUTINE) (
  3832. struct _RTL_GENERIC_TABLE *Table,
  3833. PVOID FirstStruct,
  3834. PVOID SecondStruct
  3835. );
  3836. //
  3837. // The allocation function is called by the generic table package whenever
  3838. // it needs to allocate memory for the table.
  3839. //
  3840. typedef
  3841. PVOID
  3842. (NTAPI *PRTL_GENERIC_ALLOCATE_ROUTINE) (
  3843. struct _RTL_GENERIC_TABLE *Table,
  3844. CLONG ByteSize
  3845. );
  3846. //
  3847. // The deallocation function is called by the generic table package whenever
  3848. // it needs to deallocate memory from the table that was allocated by calling
  3849. // the user supplied allocation function.
  3850. //
  3851. typedef
  3852. VOID
  3853. (NTAPI *PRTL_GENERIC_FREE_ROUTINE) (
  3854. struct _RTL_GENERIC_TABLE *Table,
  3855. PVOID Buffer
  3856. );
  3857. //
  3858. // To use the generic table package the user declares a variable of type
  3859. // GENERIC_TABLE and then uses the routines described below to initialize
  3860. // the table and to manipulate the table. Note that the generic table
  3861. // should really be an opaque type.
  3862. //
  3863. typedef struct _RTL_GENERIC_TABLE {
  3864. PRTL_SPLAY_LINKS TableRoot;
  3865. LIST_ENTRY InsertOrderList;
  3866. PLIST_ENTRY OrderedPointer;
  3867. ULONG WhichOrderedElement;
  3868. ULONG NumberGenericTableElements;
  3869. PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine;
  3870. PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine;
  3871. PRTL_GENERIC_FREE_ROUTINE FreeRoutine;
  3872. PVOID TableContext;
  3873. } RTL_GENERIC_TABLE;
  3874. typedef RTL_GENERIC_TABLE *PRTL_GENERIC_TABLE;
  3875. //
  3876. // The procedure InitializeGenericTable takes as input an uninitialized
  3877. // generic table variable and pointers to the three user supplied routines.
  3878. // This must be called for every individual generic table variable before
  3879. // it can be used.
  3880. //
  3881. NTSYSAPI
  3882. VOID
  3883. NTAPI
  3884. RtlInitializeGenericTable (
  3885. PRTL_GENERIC_TABLE Table,
  3886. PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine,
  3887. PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine,
  3888. PRTL_GENERIC_FREE_ROUTINE FreeRoutine,
  3889. PVOID TableContext
  3890. );
  3891. //
  3892. // The function InsertElementGenericTable will insert a new element
  3893. // in a table. It does this by allocating space for the new element
  3894. // (this includes splay links), inserting the element in the table, and
  3895. // then returning to the user a pointer to the new element. If an element
  3896. // with the same key already exists in the table the return value is a pointer
  3897. // to the old element. The optional output parameter NewElement is used
  3898. // to indicate if the element previously existed in the table. Note: the user
  3899. // supplied Buffer is only used for searching the table, upon insertion its
  3900. // contents are copied to the newly created element. This means that
  3901. // pointer to the input buffer will not point to the new element.
  3902. //
  3903. NTSYSAPI
  3904. PVOID
  3905. NTAPI
  3906. RtlInsertElementGenericTable (
  3907. PRTL_GENERIC_TABLE Table,
  3908. PVOID Buffer,
  3909. CLONG BufferSize,
  3910. PBOOLEAN NewElement OPTIONAL
  3911. );
  3912. //
  3913. // The function InsertElementGenericTableFull will insert a new element
  3914. // in a table. It does this by allocating space for the new element
  3915. // (this includes splay links), inserting the element in the table, and
  3916. // then returning to the user a pointer to the new element. If an element
  3917. // with the same key already exists in the table the return value is a pointer
  3918. // to the old element. The optional output parameter NewElement is used
  3919. // to indicate if the element previously existed in the table. Note: the user
  3920. // supplied Buffer is only used for searching the table, upon insertion its
  3921. // contents are copied to the newly created element. This means that
  3922. // pointer to the input buffer will not point to the new element.
  3923. // This routine is passed the NodeOrParent and SearchResult from a
  3924. // previous RtlLookupElementGenericTableFull.
  3925. //
  3926. NTSYSAPI
  3927. PVOID
  3928. NTAPI
  3929. RtlInsertElementGenericTableFull (
  3930. PRTL_GENERIC_TABLE Table,
  3931. PVOID Buffer,
  3932. CLONG BufferSize,
  3933. PBOOLEAN NewElement OPTIONAL,
  3934. PVOID NodeOrParent,
  3935. TABLE_SEARCH_RESULT SearchResult
  3936. );
  3937. //
  3938. // The function DeleteElementGenericTable will find and delete an element
  3939. // from a generic table. If the element is located and deleted the return
  3940. // value is TRUE, otherwise if the element is not located the return value
  3941. // is FALSE. The user supplied input buffer is only used as a key in
  3942. // locating the element in the table.
  3943. //
  3944. NTSYSAPI
  3945. BOOLEAN
  3946. NTAPI
  3947. RtlDeleteElementGenericTable (
  3948. PRTL_GENERIC_TABLE Table,
  3949. PVOID Buffer
  3950. );
  3951. //
  3952. // The function LookupElementGenericTable will find an element in a generic
  3953. // table. If the element is located the return value is a pointer to
  3954. // the user defined structure associated with the element, otherwise if
  3955. // the element is not located the return value is NULL. The user supplied
  3956. // input buffer is only used as a key in locating the element in the table.
  3957. //
  3958. NTSYSAPI
  3959. PVOID
  3960. NTAPI
  3961. RtlLookupElementGenericTable (
  3962. PRTL_GENERIC_TABLE Table,
  3963. PVOID Buffer
  3964. );
  3965. //
  3966. // The function LookupElementGenericTableFull will find an element in a generic
  3967. // table. If the element is located the return value is a pointer to
  3968. // the user defined structure associated with the element. If the element is not
  3969. // located then a pointer to the parent for the insert location is returned. The
  3970. // user must look at the SearchResult value to determine which is being returned.
  3971. // The user can use the SearchResult and parent for a subsequent FullInsertElement
  3972. // call to optimize the insert.
  3973. //
  3974. NTSYSAPI
  3975. PVOID
  3976. NTAPI
  3977. RtlLookupElementGenericTableFull (
  3978. PRTL_GENERIC_TABLE Table,
  3979. PVOID Buffer,
  3980. OUT PVOID *NodeOrParent,
  3981. OUT TABLE_SEARCH_RESULT *SearchResult
  3982. );
  3983. //
  3984. // The function EnumerateGenericTable will return to the caller one-by-one
  3985. // the elements of of a table. The return value is a pointer to the user
  3986. // defined structure associated with the element. The input parameter
  3987. // Restart indicates if the enumeration should start from the beginning
  3988. // or should return the next element. If the are no more new elements to
  3989. // return the return value is NULL. As an example of its use, to enumerate
  3990. // all of the elements in a table the user would write:
  3991. //
  3992. // for (ptr = EnumerateGenericTable(Table, TRUE);
  3993. // ptr != NULL;
  3994. // ptr = EnumerateGenericTable(Table, FALSE)) {
  3995. // :
  3996. // }
  3997. //
  3998. //
  3999. // PLEASE NOTE:
  4000. //
  4001. // If you enumerate a GenericTable using RtlEnumerateGenericTable, you
  4002. // will flatten the table, turning it into a sorted linked list.
  4003. // To enumerate the table without perturbing the splay links, use
  4004. // RtlEnumerateGenericTableWithoutSplaying
  4005. NTSYSAPI
  4006. PVOID
  4007. NTAPI
  4008. RtlEnumerateGenericTable (
  4009. PRTL_GENERIC_TABLE Table,
  4010. BOOLEAN Restart
  4011. );
  4012. //
  4013. // The function EnumerateGenericTableWithoutSplaying will return to the
  4014. // caller one-by-one the elements of of a table. The return value is a
  4015. // pointer to the user defined structure associated with the element.
  4016. // The input parameter RestartKey indicates if the enumeration should
  4017. // start from the beginning or should return the next element. If the
  4018. // are no more new elements to return the return value is NULL. As an
  4019. // example of its use, to enumerate all of the elements in a table the
  4020. // user would write:
  4021. //
  4022. // RestartKey = NULL;
  4023. // for (ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey);
  4024. // ptr != NULL;
  4025. // ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey)) {
  4026. // :
  4027. // }
  4028. //
  4029. // If RestartKey is NULL, the package will start from the least entry in the
  4030. // table, otherwise it will start from the last entry returned.
  4031. //
  4032. //
  4033. // Note that unlike RtlEnumerateGenericTable, this routine will NOT perturb
  4034. // the splay order of the tree.
  4035. //
  4036. NTSYSAPI
  4037. PVOID
  4038. NTAPI
  4039. RtlEnumerateGenericTableWithoutSplaying (
  4040. PRTL_GENERIC_TABLE Table,
  4041. PVOID *RestartKey
  4042. );
  4043. //
  4044. // The function GetElementGenericTable will return the i'th element
  4045. // inserted in the generic table. I = 0 implies the first element,
  4046. // I = (RtlNumberGenericTableElements(Table)-1) will return the last element
  4047. // inserted into the generic table. The type of I is ULONG. Values
  4048. // of I > than (NumberGenericTableElements(Table)-1) will return NULL. If
  4049. // an arbitrary element is deleted from the generic table it will cause
  4050. // all elements inserted after the deleted element to "move up".
  4051. NTSYSAPI
  4052. PVOID
  4053. NTAPI
  4054. RtlGetElementGenericTable(
  4055. PRTL_GENERIC_TABLE Table,
  4056. ULONG I
  4057. );
  4058. //
  4059. // The function NumberGenericTableElements returns a ULONG value
  4060. // which is the number of generic table elements currently inserted
  4061. // in the generic table.
  4062. NTSYSAPI
  4063. ULONG
  4064. NTAPI
  4065. RtlNumberGenericTableElements(
  4066. PRTL_GENERIC_TABLE Table
  4067. );
  4068. //
  4069. // The function IsGenericTableEmpty will return to the caller TRUE if
  4070. // the input table is empty (i.e., does not contain any elements) and
  4071. // FALSE otherwise.
  4072. //
  4073. NTSYSAPI
  4074. BOOLEAN
  4075. NTAPI
  4076. RtlIsGenericTableEmpty (
  4077. PRTL_GENERIC_TABLE Table
  4078. );
  4079. #endif // RTL_USE_AVL_TABLES
  4080. typedef NTSTATUS
  4081. (NTAPI * PRTL_HEAP_COMMIT_ROUTINE)(
  4082. IN PVOID Base,
  4083. IN OUT PVOID *CommitAddress,
  4084. IN OUT PSIZE_T CommitSize
  4085. );
  4086. typedef struct _RTL_HEAP_PARAMETERS {
  4087. ULONG Length;
  4088. SIZE_T SegmentReserve;
  4089. SIZE_T SegmentCommit;
  4090. SIZE_T DeCommitFreeBlockThreshold;
  4091. SIZE_T DeCommitTotalFreeThreshold;
  4092. SIZE_T MaximumAllocationSize;
  4093. SIZE_T VirtualMemoryThreshold;
  4094. SIZE_T InitialCommit;
  4095. SIZE_T InitialReserve;
  4096. PRTL_HEAP_COMMIT_ROUTINE CommitRoutine;
  4097. SIZE_T Reserved[ 2 ];
  4098. } RTL_HEAP_PARAMETERS, *PRTL_HEAP_PARAMETERS;
  4099. NTSYSAPI
  4100. PVOID
  4101. NTAPI
  4102. RtlCreateHeap(
  4103. IN ULONG Flags,
  4104. IN PVOID HeapBase OPTIONAL,
  4105. IN SIZE_T ReserveSize OPTIONAL,
  4106. IN SIZE_T CommitSize OPTIONAL,
  4107. IN PVOID Lock OPTIONAL,
  4108. IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL
  4109. );
  4110. #define HEAP_NO_SERIALIZE 0x00000001 // winnt
  4111. #define HEAP_GROWABLE 0x00000002 // winnt
  4112. #define HEAP_GENERATE_EXCEPTIONS 0x00000004 // winnt
  4113. #define HEAP_ZERO_MEMORY 0x00000008 // winnt
  4114. #define HEAP_REALLOC_IN_PLACE_ONLY 0x00000010 // winnt
  4115. #define HEAP_TAIL_CHECKING_ENABLED 0x00000020 // winnt
  4116. #define HEAP_FREE_CHECKING_ENABLED 0x00000040 // winnt
  4117. #define HEAP_DISABLE_COALESCE_ON_FREE 0x00000080 // winnt
  4118. #define HEAP_CREATE_ALIGN_16 0x00010000 // winnt Create heap with 16 byte alignment (obsolete)
  4119. #define HEAP_CREATE_ENABLE_TRACING 0x00020000 // winnt Create heap call tracing enabled (obsolete)
  4120. #define HEAP_SETTABLE_USER_VALUE 0x00000100
  4121. #define HEAP_SETTABLE_USER_FLAG1 0x00000200
  4122. #define HEAP_SETTABLE_USER_FLAG2 0x00000400
  4123. #define HEAP_SETTABLE_USER_FLAG3 0x00000800
  4124. #define HEAP_SETTABLE_USER_FLAGS 0x00000E00
  4125. #define HEAP_CLASS_0 0x00000000 // process heap
  4126. #define HEAP_CLASS_1 0x00001000 // private heap
  4127. #define HEAP_CLASS_2 0x00002000 // Kernel Heap
  4128. #define HEAP_CLASS_3 0x00003000 // GDI heap
  4129. #define HEAP_CLASS_4 0x00004000 // User heap
  4130. #define HEAP_CLASS_5 0x00005000 // Console heap
  4131. #define HEAP_CLASS_6 0x00006000 // User Desktop heap
  4132. #define HEAP_CLASS_7 0x00007000 // Csrss Shared heap
  4133. #define HEAP_CLASS_8 0x00008000 // Csr Port heap
  4134. #define HEAP_CLASS_MASK 0x0000F000
  4135. #define HEAP_MAXIMUM_TAG 0x0FFF // winnt
  4136. #define HEAP_GLOBAL_TAG 0x0800
  4137. #define HEAP_PSEUDO_TAG_FLAG 0x8000 // winnt
  4138. #define HEAP_TAG_SHIFT 18 // winnt
  4139. #define HEAP_MAKE_TAG_FLAGS( b, o ) ((ULONG)((b) + ((o) << 18))) // winnt
  4140. #define HEAP_TAG_MASK (HEAP_MAXIMUM_TAG << HEAP_TAG_SHIFT)
  4141. #define HEAP_CREATE_VALID_MASK (HEAP_NO_SERIALIZE | \
  4142. HEAP_GROWABLE | \
  4143. HEAP_GENERATE_EXCEPTIONS | \
  4144. HEAP_ZERO_MEMORY | \
  4145. HEAP_REALLOC_IN_PLACE_ONLY | \
  4146. HEAP_TAIL_CHECKING_ENABLED | \
  4147. HEAP_FREE_CHECKING_ENABLED | \
  4148. HEAP_DISABLE_COALESCE_ON_FREE | \
  4149. HEAP_CLASS_MASK | \
  4150. HEAP_CREATE_ALIGN_16 | \
  4151. HEAP_CREATE_ENABLE_TRACING)
  4152. NTSYSAPI
  4153. PVOID
  4154. NTAPI
  4155. RtlDestroyHeap(
  4156. IN PVOID HeapHandle
  4157. );
  4158. NTSYSAPI
  4159. PVOID
  4160. NTAPI
  4161. RtlAllocateHeap(
  4162. IN PVOID HeapHandle,
  4163. IN ULONG Flags,
  4164. IN SIZE_T Size
  4165. );
  4166. NTSYSAPI
  4167. BOOLEAN
  4168. NTAPI
  4169. RtlFreeHeap(
  4170. IN PVOID HeapHandle,
  4171. IN ULONG Flags,
  4172. IN PVOID BaseAddress
  4173. );
  4174. #if defined (_MSC_VER) && ( _MSC_VER >= 900 )
  4175. PVOID
  4176. _ReturnAddress (
  4177. VOID
  4178. );
  4179. #pragma intrinsic(_ReturnAddress)
  4180. #endif
  4181. #if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
  4182. #define RtlGetCallersAddress(CallersAddress, CallersCaller) \
  4183. *CallersAddress = (PVOID)_ReturnAddress(); \
  4184. *CallersCaller = NULL;
  4185. #else
  4186. NTSYSAPI
  4187. VOID
  4188. NTAPI
  4189. RtlGetCallersAddress(
  4190. OUT PVOID *CallersAddress,
  4191. OUT PVOID *CallersCaller
  4192. );
  4193. #endif
  4194. NTSYSAPI
  4195. ULONG
  4196. NTAPI
  4197. RtlWalkFrameChain (
  4198. OUT PVOID *Callers,
  4199. IN ULONG Count,
  4200. IN ULONG Flags
  4201. );
  4202. typedef NTSTATUS (NTAPI * PRTL_QUERY_REGISTRY_ROUTINE)(
  4203. IN PWSTR ValueName,
  4204. IN ULONG ValueType,
  4205. IN PVOID ValueData,
  4206. IN ULONG ValueLength,
  4207. IN PVOID Context,
  4208. IN PVOID EntryContext
  4209. );
  4210. typedef struct _RTL_QUERY_REGISTRY_TABLE {
  4211. PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
  4212. ULONG Flags;
  4213. PWSTR Name;
  4214. PVOID EntryContext;
  4215. ULONG DefaultType;
  4216. PVOID DefaultData;
  4217. ULONG DefaultLength;
  4218. } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
  4219. //
  4220. // The following flags specify how the Name field of a RTL_QUERY_REGISTRY_TABLE
  4221. // entry is interpreted. A NULL name indicates the end of the table.
  4222. //
  4223. #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001 // Name is a subkey and remainder of
  4224. // table or until next subkey are value
  4225. // names for that subkey to look at.
  4226. #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002 // Reset current key to original key for
  4227. // this and all following table entries.
  4228. #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004 // Fail if no match found for this table
  4229. // entry.
  4230. #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008 // Used to mark a table entry that has no
  4231. // value name, just wants a call out, not
  4232. // an enumeration of all values.
  4233. #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010 // Used to suppress the expansion of
  4234. // REG_MULTI_SZ into multiple callouts or
  4235. // to prevent the expansion of environment
  4236. // variable values in REG_EXPAND_SZ
  4237. #define RTL_QUERY_REGISTRY_DIRECT 0x00000020 // QueryRoutine field ignored. EntryContext
  4238. // field points to location to store value.
  4239. // For null terminated strings, EntryContext
  4240. // points to UNICODE_STRING structure that
  4241. // that describes maximum size of buffer.
  4242. // If .Buffer field is NULL then a buffer is
  4243. // allocated.
  4244. //
  4245. #define RTL_QUERY_REGISTRY_DELETE 0x00000040 // Used to delete value keys after they
  4246. // are queried.
  4247. NTSYSAPI
  4248. NTSTATUS
  4249. NTAPI
  4250. RtlQueryRegistryValues(
  4251. IN ULONG RelativeTo,
  4252. IN PCWSTR Path,
  4253. IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
  4254. IN PVOID Context,
  4255. IN PVOID Environment OPTIONAL
  4256. );
  4257. NTSYSAPI
  4258. NTSTATUS
  4259. NTAPI
  4260. RtlWriteRegistryValue(
  4261. IN ULONG RelativeTo,
  4262. IN PCWSTR Path,
  4263. IN PCWSTR ValueName,
  4264. IN ULONG ValueType,
  4265. IN PVOID ValueData,
  4266. IN ULONG ValueLength
  4267. );
  4268. NTSYSAPI
  4269. NTSTATUS
  4270. NTAPI
  4271. RtlDeleteRegistryValue(
  4272. IN ULONG RelativeTo,
  4273. IN PCWSTR Path,
  4274. IN PCWSTR ValueName
  4275. );
  4276. // end_wdm
  4277. NTSYSAPI
  4278. NTSTATUS
  4279. NTAPI
  4280. RtlCreateRegistryKey(
  4281. IN ULONG RelativeTo,
  4282. IN PWSTR Path
  4283. );
  4284. NTSYSAPI
  4285. NTSTATUS
  4286. NTAPI
  4287. RtlCheckRegistryKey(
  4288. IN ULONG RelativeTo,
  4289. IN PWSTR Path
  4290. );
  4291. // begin_wdm
  4292. //
  4293. // The following values for the RelativeTo parameter determine what the
  4294. // Path parameter to RtlQueryRegistryValues is relative to.
  4295. //
  4296. #define RTL_REGISTRY_ABSOLUTE 0 // Path is a full path
  4297. #define RTL_REGISTRY_SERVICES 1 // \Registry\Machine\System\CurrentControlSet\Services
  4298. #define RTL_REGISTRY_CONTROL 2 // \Registry\Machine\System\CurrentControlSet\Control
  4299. #define RTL_REGISTRY_WINDOWS_NT 3 // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
  4300. #define RTL_REGISTRY_DEVICEMAP 4 // \Registry\Machine\Hardware\DeviceMap
  4301. #define RTL_REGISTRY_USER 5 // \Registry\User\CurrentUser
  4302. #define RTL_REGISTRY_MAXIMUM 6
  4303. #define RTL_REGISTRY_HANDLE 0x40000000 // Low order bits are registry handle
  4304. #define RTL_REGISTRY_OPTIONAL 0x80000000 // Indicates the key node is optional
  4305. NTSYSAPI
  4306. ULONG
  4307. NTAPI
  4308. RtlRandom (
  4309. PULONG Seed
  4310. );
  4311. NTSYSAPI
  4312. ULONG
  4313. NTAPI
  4314. RtlRandomEx (
  4315. PULONG Seed
  4316. );
  4317. NTSYSAPI
  4318. NTSTATUS
  4319. NTAPI
  4320. RtlCharToInteger (
  4321. PCSZ String,
  4322. ULONG Base,
  4323. PULONG Value
  4324. );
  4325. NTSYSAPI
  4326. NTSTATUS
  4327. NTAPI
  4328. RtlIntegerToUnicodeString (
  4329. ULONG Value,
  4330. ULONG Base,
  4331. PUNICODE_STRING String
  4332. );
  4333. NTSYSAPI
  4334. NTSTATUS
  4335. NTAPI
  4336. RtlInt64ToUnicodeString (
  4337. IN ULONGLONG Value,
  4338. IN ULONG Base OPTIONAL,
  4339. IN OUT PUNICODE_STRING String
  4340. );
  4341. #ifdef _WIN64
  4342. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlInt64ToUnicodeString(Value, Base, String)
  4343. #else
  4344. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlIntegerToUnicodeString(Value, Base, String)
  4345. #endif
  4346. NTSYSAPI
  4347. NTSTATUS
  4348. NTAPI
  4349. RtlUnicodeStringToInteger (
  4350. PCUNICODE_STRING String,
  4351. ULONG Base,
  4352. PULONG Value
  4353. );
  4354. //
  4355. // String manipulation routines
  4356. //
  4357. #ifdef _NTSYSTEM_
  4358. #define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
  4359. #define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
  4360. #else
  4361. #define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
  4362. #define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  4363. #endif // _NTSYSTEM_
  4364. extern BOOLEAN NLS_MB_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  4365. extern BOOLEAN NLS_MB_OEM_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  4366. NTSYSAPI
  4367. VOID
  4368. NTAPI
  4369. RtlInitString(
  4370. PSTRING DestinationString,
  4371. PCSZ SourceString
  4372. );
  4373. NTSYSAPI
  4374. VOID
  4375. NTAPI
  4376. RtlInitAnsiString(
  4377. PANSI_STRING DestinationString,
  4378. PCSZ SourceString
  4379. );
  4380. NTSYSAPI
  4381. VOID
  4382. NTAPI
  4383. RtlInitUnicodeString(
  4384. PUNICODE_STRING DestinationString,
  4385. PCWSTR SourceString
  4386. );
  4387. #define RtlInitEmptyUnicodeString(_ucStr,_buf,_bufSize) \
  4388. ((_ucStr)->Buffer = (_buf), \
  4389. (_ucStr)->Length = 0, \
  4390. (_ucStr)->MaximumLength = (USHORT)(_bufSize))
  4391. // end_ntddk end_wdm
  4392. NTSYSAPI
  4393. NTSTATUS
  4394. NTAPI
  4395. RtlInitUnicodeStringEx(
  4396. PUNICODE_STRING DestinationString,
  4397. PCWSTR SourceString
  4398. );
  4399. NTSYSAPI
  4400. NTSTATUS
  4401. NTAPI
  4402. RtlInitAnsiStringEx(
  4403. OUT PANSI_STRING DestinationString,
  4404. IN PCSZ SourceString OPTIONAL
  4405. );
  4406. NTSYSAPI
  4407. BOOLEAN
  4408. NTAPI
  4409. RtlCreateUnicodeString(
  4410. OUT PUNICODE_STRING DestinationString,
  4411. IN PCWSTR SourceString
  4412. );
  4413. NTSYSAPI
  4414. VOID
  4415. NTAPI
  4416. RtlCopyString(
  4417. PSTRING DestinationString,
  4418. const STRING * SourceString
  4419. );
  4420. NTSYSAPI
  4421. CHAR
  4422. NTAPI
  4423. RtlUpperChar (
  4424. CHAR Character
  4425. );
  4426. NTSYSAPI
  4427. LONG
  4428. NTAPI
  4429. RtlCompareString(
  4430. const STRING * String1,
  4431. const STRING * String2,
  4432. BOOLEAN CaseInSensitive
  4433. );
  4434. NTSYSAPI
  4435. BOOLEAN
  4436. NTAPI
  4437. RtlEqualString(
  4438. const STRING * String1,
  4439. const STRING * String2,
  4440. BOOLEAN CaseInSensitive
  4441. );
  4442. NTSYSAPI
  4443. VOID
  4444. NTAPI
  4445. RtlUpperString(
  4446. PSTRING DestinationString,
  4447. const STRING * SourceString
  4448. );
  4449. NTSYSAPI
  4450. NTSTATUS
  4451. NTAPI
  4452. RtlAppendStringToString (
  4453. PSTRING Destination,
  4454. const STRING * Source
  4455. );
  4456. // begin_ntddk begin_wdm
  4457. //
  4458. // NLS String functions
  4459. //
  4460. NTSYSAPI
  4461. NTSTATUS
  4462. NTAPI
  4463. RtlAnsiStringToUnicodeString(
  4464. PUNICODE_STRING DestinationString,
  4465. PCANSI_STRING SourceString,
  4466. BOOLEAN AllocateDestinationString
  4467. );
  4468. NTSYSAPI
  4469. NTSTATUS
  4470. NTAPI
  4471. RtlUnicodeStringToAnsiString(
  4472. PANSI_STRING DestinationString,
  4473. PCUNICODE_STRING SourceString,
  4474. BOOLEAN AllocateDestinationString
  4475. );
  4476. NTSYSAPI
  4477. NTSTATUS
  4478. NTAPI
  4479. RtlOemStringToUnicodeString(
  4480. PUNICODE_STRING DestinationString,
  4481. PCOEM_STRING SourceString,
  4482. BOOLEAN AllocateDestinationString
  4483. );
  4484. NTSYSAPI
  4485. NTSTATUS
  4486. NTAPI
  4487. RtlUnicodeStringToOemString(
  4488. POEM_STRING DestinationString,
  4489. PCUNICODE_STRING SourceString,
  4490. BOOLEAN AllocateDestinationString
  4491. );
  4492. NTSYSAPI
  4493. NTSTATUS
  4494. NTAPI
  4495. RtlUpcaseUnicodeStringToOemString(
  4496. POEM_STRING DestinationString,
  4497. PCUNICODE_STRING SourceString,
  4498. BOOLEAN AllocateDestinationString
  4499. );
  4500. NTSYSAPI
  4501. NTSTATUS
  4502. NTAPI
  4503. RtlOemStringToCountedUnicodeString(
  4504. PUNICODE_STRING DestinationString,
  4505. PCOEM_STRING SourceString,
  4506. BOOLEAN AllocateDestinationString
  4507. );
  4508. NTSYSAPI
  4509. NTSTATUS
  4510. NTAPI
  4511. RtlUnicodeStringToCountedOemString(
  4512. POEM_STRING DestinationString,
  4513. PCUNICODE_STRING SourceString,
  4514. BOOLEAN AllocateDestinationString
  4515. );
  4516. NTSYSAPI
  4517. NTSTATUS
  4518. NTAPI
  4519. RtlUpcaseUnicodeStringToCountedOemString(
  4520. POEM_STRING DestinationString,
  4521. PCUNICODE_STRING SourceString,
  4522. BOOLEAN AllocateDestinationString
  4523. );
  4524. // begin_ntddk begin_wdm begin_ntndis
  4525. NTSYSAPI
  4526. LONG
  4527. NTAPI
  4528. RtlCompareUnicodeString(
  4529. PCUNICODE_STRING String1,
  4530. PCUNICODE_STRING String2,
  4531. BOOLEAN CaseInSensitive
  4532. );
  4533. NTSYSAPI
  4534. BOOLEAN
  4535. NTAPI
  4536. RtlEqualUnicodeString(
  4537. PCUNICODE_STRING String1,
  4538. PCUNICODE_STRING String2,
  4539. BOOLEAN CaseInSensitive
  4540. );
  4541. #define HASH_STRING_ALGORITHM_DEFAULT (0)
  4542. #define HASH_STRING_ALGORITHM_X65599 (1)
  4543. #define HASH_STRING_ALGORITHM_INVALID (0xffffffff)
  4544. NTSYSAPI
  4545. NTSTATUS
  4546. NTAPI
  4547. RtlHashUnicodeString(
  4548. IN const UNICODE_STRING *String,
  4549. IN BOOLEAN CaseInSensitive,
  4550. IN ULONG HashAlgorithm,
  4551. OUT PULONG HashValue
  4552. );
  4553. // end_ntddk end_wdm end_ntndis
  4554. NTSYSAPI
  4555. NTSTATUS
  4556. NTAPI
  4557. RtlValidateUnicodeString(
  4558. IN ULONG Flags,
  4559. IN const UNICODE_STRING *String
  4560. );
  4561. #define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE (0x00000001)
  4562. #define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING (0x00000002)
  4563. NTSYSAPI
  4564. NTSTATUS
  4565. NTAPI
  4566. RtlDuplicateUnicodeString(
  4567. IN ULONG Flags,
  4568. IN const UNICODE_STRING *StringIn,
  4569. OUT UNICODE_STRING *StringOut
  4570. );
  4571. // begin_ntddk begin_ntndis
  4572. NTSYSAPI
  4573. BOOLEAN
  4574. NTAPI
  4575. RtlPrefixUnicodeString(
  4576. IN PCUNICODE_STRING String1,
  4577. IN PCUNICODE_STRING String2,
  4578. IN BOOLEAN CaseInSensitive
  4579. );
  4580. NTSYSAPI
  4581. NTSTATUS
  4582. NTAPI
  4583. RtlUpcaseUnicodeString(
  4584. PUNICODE_STRING DestinationString,
  4585. PCUNICODE_STRING SourceString,
  4586. BOOLEAN AllocateDestinationString
  4587. );
  4588. NTSTATUS
  4589. RtlDowncaseUnicodeString(
  4590. OUT PUNICODE_STRING DestinationString,
  4591. IN PCUNICODE_STRING SourceString,
  4592. IN BOOLEAN AllocateDestinationString
  4593. );
  4594. NTSYSAPI
  4595. VOID
  4596. NTAPI
  4597. RtlCopyUnicodeString(
  4598. PUNICODE_STRING DestinationString,
  4599. PCUNICODE_STRING SourceString
  4600. );
  4601. NTSYSAPI
  4602. NTSTATUS
  4603. NTAPI
  4604. RtlAppendUnicodeStringToString (
  4605. PUNICODE_STRING Destination,
  4606. PCUNICODE_STRING Source
  4607. );
  4608. NTSYSAPI
  4609. NTSTATUS
  4610. NTAPI
  4611. RtlAppendUnicodeToString (
  4612. PUNICODE_STRING Destination,
  4613. PCWSTR Source
  4614. );
  4615. // end_ntndis end_wdm
  4616. NTSYSAPI
  4617. WCHAR
  4618. NTAPI
  4619. RtlUpcaseUnicodeChar(
  4620. WCHAR SourceCharacter
  4621. );
  4622. NTSYSAPI
  4623. WCHAR
  4624. NTAPI
  4625. RtlDowncaseUnicodeChar(
  4626. WCHAR SourceCharacter
  4627. );
  4628. // begin_wdm
  4629. NTSYSAPI
  4630. VOID
  4631. NTAPI
  4632. RtlFreeUnicodeString(
  4633. PUNICODE_STRING UnicodeString
  4634. );
  4635. NTSYSAPI
  4636. VOID
  4637. NTAPI
  4638. RtlFreeAnsiString(
  4639. PANSI_STRING AnsiString
  4640. );
  4641. // end_ntddk end_wdm end_nthal
  4642. NTSYSAPI
  4643. VOID
  4644. NTAPI
  4645. RtlFreeOemString(
  4646. POEM_STRING OemString
  4647. );
  4648. // begin_wdm
  4649. NTSYSAPI
  4650. ULONG
  4651. NTAPI
  4652. RtlxUnicodeStringToAnsiSize(
  4653. PCUNICODE_STRING UnicodeString
  4654. );
  4655. //
  4656. // NTSYSAPI
  4657. // ULONG
  4658. // NTAPI
  4659. // RtlUnicodeStringToAnsiSize(
  4660. // PUNICODE_STRING UnicodeString
  4661. // );
  4662. //
  4663. #define RtlUnicodeStringToAnsiSize(STRING) ( \
  4664. NLS_MB_CODE_PAGE_TAG ? \
  4665. RtlxUnicodeStringToAnsiSize(STRING) : \
  4666. ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
  4667. )
  4668. // end_wdm
  4669. NTSYSAPI
  4670. ULONG
  4671. NTAPI
  4672. RtlxUnicodeStringToOemSize(
  4673. PCUNICODE_STRING UnicodeString
  4674. );
  4675. //
  4676. // NTSYSAPI
  4677. // ULONG
  4678. // NTAPI
  4679. // RtlUnicodeStringToOemSize(
  4680. // PUNICODE_STRING UnicodeString
  4681. // );
  4682. //
  4683. #define RtlUnicodeStringToOemSize(STRING) ( \
  4684. NLS_MB_OEM_CODE_PAGE_TAG ? \
  4685. RtlxUnicodeStringToOemSize(STRING) : \
  4686. ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
  4687. )
  4688. NTSYSAPI
  4689. ULONG
  4690. NTAPI
  4691. RtlxAnsiStringToUnicodeSize(
  4692. PCANSI_STRING AnsiString
  4693. );
  4694. //
  4695. // NTSYSAPI
  4696. // ULONG
  4697. // NTAPI
  4698. // RtlAnsiStringToUnicodeSize(
  4699. // PANSI_STRING AnsiString
  4700. // );
  4701. //
  4702. #define RtlAnsiStringToUnicodeSize(STRING) ( \
  4703. NLS_MB_CODE_PAGE_TAG ? \
  4704. RtlxAnsiStringToUnicodeSize(STRING) : \
  4705. ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
  4706. )
  4707. // end_ntddk end_wdm
  4708. NTSYSAPI
  4709. ULONG
  4710. NTAPI
  4711. RtlxOemStringToUnicodeSize(
  4712. PCOEM_STRING OemString
  4713. );
  4714. //
  4715. // NTSYSAPI
  4716. // ULONG
  4717. // NTAPI
  4718. // RtlOemStringToUnicodeSize(
  4719. // POEM_STRING OemString
  4720. // );
  4721. //
  4722. #define RtlOemStringToUnicodeSize(STRING) ( \
  4723. NLS_MB_OEM_CODE_PAGE_TAG ? \
  4724. RtlxOemStringToUnicodeSize(STRING) : \
  4725. ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
  4726. )
  4727. //
  4728. // ULONG
  4729. // RtlOemStringToCountedUnicodeSize(
  4730. // POEM_STRING OemString
  4731. // );
  4732. //
  4733. #define RtlOemStringToCountedUnicodeSize(STRING) ( \
  4734. (ULONG)(RtlOemStringToUnicodeSize(STRING) - sizeof(UNICODE_NULL)) \
  4735. )
  4736. NTSYSAPI
  4737. NTSTATUS
  4738. NTAPI
  4739. RtlMultiByteToUnicodeN(
  4740. PWSTR UnicodeString,
  4741. ULONG MaxBytesInUnicodeString,
  4742. PULONG BytesInUnicodeString,
  4743. PCSTR MultiByteString,
  4744. ULONG BytesInMultiByteString
  4745. );
  4746. NTSYSAPI
  4747. NTSTATUS
  4748. NTAPI
  4749. RtlMultiByteToUnicodeSize(
  4750. PULONG BytesInUnicodeString,
  4751. PCSTR MultiByteString,
  4752. ULONG BytesInMultiByteString
  4753. );
  4754. NTSYSAPI
  4755. NTSTATUS
  4756. NTAPI
  4757. RtlUnicodeToMultiByteSize(
  4758. PULONG BytesInMultiByteString,
  4759. IN PWSTR UnicodeString,
  4760. ULONG BytesInUnicodeString
  4761. );
  4762. NTSYSAPI
  4763. NTSTATUS
  4764. NTAPI
  4765. RtlUnicodeToMultiByteN(
  4766. PCHAR MultiByteString,
  4767. ULONG MaxBytesInMultiByteString,
  4768. PULONG BytesInMultiByteString,
  4769. PWSTR UnicodeString,
  4770. ULONG BytesInUnicodeString
  4771. );
  4772. NTSYSAPI
  4773. NTSTATUS
  4774. NTAPI
  4775. RtlUpcaseUnicodeToMultiByteN(
  4776. PCHAR MultiByteString,
  4777. ULONG MaxBytesInMultiByteString,
  4778. PULONG BytesInMultiByteString,
  4779. PWSTR UnicodeString,
  4780. ULONG BytesInUnicodeString
  4781. );
  4782. NTSYSAPI
  4783. NTSTATUS
  4784. NTAPI
  4785. RtlOemToUnicodeN(
  4786. PWSTR UnicodeString,
  4787. ULONG MaxBytesInUnicodeString,
  4788. PULONG BytesInUnicodeString,
  4789. IN PCHAR OemString,
  4790. ULONG BytesInOemString
  4791. );
  4792. NTSYSAPI
  4793. NTSTATUS
  4794. NTAPI
  4795. RtlUnicodeToOemN(
  4796. PCHAR OemString,
  4797. ULONG MaxBytesInOemString,
  4798. PULONG BytesInOemString,
  4799. PWSTR UnicodeString,
  4800. ULONG BytesInUnicodeString
  4801. );
  4802. NTSYSAPI
  4803. NTSTATUS
  4804. NTAPI
  4805. RtlUpcaseUnicodeToOemN(
  4806. PCHAR OemString,
  4807. ULONG MaxBytesInOemString,
  4808. PULONG BytesInOemString,
  4809. PWSTR UnicodeString,
  4810. ULONG BytesInUnicodeString
  4811. );
  4812. typedef
  4813. PVOID
  4814. (NTAPI *PRTL_ALLOCATE_STRING_ROUTINE) (
  4815. SIZE_T NumberOfBytes
  4816. );
  4817. typedef
  4818. VOID
  4819. (NTAPI *PRTL_FREE_STRING_ROUTINE) (
  4820. PVOID Buffer
  4821. );
  4822. extern const PRTL_ALLOCATE_STRING_ROUTINE RtlAllocateStringRoutine;
  4823. extern const PRTL_FREE_STRING_ROUTINE RtlFreeStringRoutine;
  4824. //
  4825. // Defines and Routines for handling GUID's.
  4826. //
  4827. // begin_ntddk begin_wdm begin_nthal
  4828. // begin_ntminiport
  4829. #include <guiddef.h>
  4830. // end_ntminiport
  4831. #ifndef DEFINE_GUIDEX
  4832. #define DEFINE_GUIDEX(name) EXTERN_C const CDECL GUID name
  4833. #endif // !defined(DEFINE_GUIDEX)
  4834. #ifndef STATICGUIDOF
  4835. #define STATICGUIDOF(guid) STATIC_##guid
  4836. #endif // !defined(STATICGUIDOF)
  4837. #ifndef __IID_ALIGNED__
  4838. #define __IID_ALIGNED__
  4839. #ifdef __cplusplus
  4840. inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
  4841. {
  4842. return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
  4843. }
  4844. #else // !__cplusplus
  4845. #define IsEqualGUIDAligned(guid1, guid2) \
  4846. ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
  4847. #endif // !__cplusplus
  4848. #endif // !__IID_ALIGNED__
  4849. NTSYSAPI
  4850. NTSTATUS
  4851. NTAPI
  4852. RtlStringFromGUID(
  4853. IN REFGUID Guid,
  4854. OUT PUNICODE_STRING GuidString
  4855. );
  4856. NTSYSAPI
  4857. NTSTATUS
  4858. NTAPI
  4859. RtlGUIDFromString(
  4860. IN PUNICODE_STRING GuidString,
  4861. OUT GUID* Guid
  4862. );
  4863. // end_ntddk end_wdm end_nthal
  4864. //
  4865. // Routine for generating 8.3 names from long names.
  4866. //
  4867. //
  4868. // The context structure is used when generating 8.3 names. The caller must
  4869. // always zero out the structure before starting a new generation sequence
  4870. //
  4871. typedef struct _GENERATE_NAME_CONTEXT {
  4872. //
  4873. // The structure is divided into two strings. The Name, and extension.
  4874. // Each part contains the value that was last inserted in the name.
  4875. // The length values are in terms of wchars and not bytes. We also
  4876. // store the last index value used in the generation collision algorithm.
  4877. //
  4878. USHORT Checksum;
  4879. BOOLEAN ChecksumInserted;
  4880. UCHAR NameLength; // not including extension
  4881. WCHAR NameBuffer[8]; // e.g., "ntoskrnl"
  4882. ULONG ExtensionLength; // including dot
  4883. WCHAR ExtensionBuffer[4]; // e.g., ".exe"
  4884. ULONG LastIndexValue;
  4885. } GENERATE_NAME_CONTEXT;
  4886. typedef GENERATE_NAME_CONTEXT *PGENERATE_NAME_CONTEXT;
  4887. NTSYSAPI
  4888. VOID
  4889. NTAPI
  4890. RtlGenerate8dot3Name (
  4891. IN PUNICODE_STRING Name,
  4892. IN BOOLEAN AllowExtendedCharacters,
  4893. IN OUT PGENERATE_NAME_CONTEXT Context,
  4894. OUT PUNICODE_STRING Name8dot3
  4895. );
  4896. NTSYSAPI
  4897. BOOLEAN
  4898. NTAPI
  4899. RtlIsNameLegalDOS8Dot3 (
  4900. IN PUNICODE_STRING Name,
  4901. IN OUT POEM_STRING OemName OPTIONAL,
  4902. IN OUT PBOOLEAN NameContainsSpaces OPTIONAL
  4903. );
  4904. BOOLEAN
  4905. RtlIsValidOemCharacter (
  4906. IN PWCHAR Char
  4907. );
  4908. //
  4909. // Prefix package types and procedures.
  4910. //
  4911. // Note that the following two record structures should really be opaque
  4912. // to the user of this package. The only information about the two
  4913. // structures available for the user should be the size and alignment
  4914. // of the structures.
  4915. //
  4916. typedef struct _PREFIX_TABLE_ENTRY {
  4917. CSHORT NodeTypeCode;
  4918. CSHORT NameLength;
  4919. struct _PREFIX_TABLE_ENTRY *NextPrefixTree;
  4920. RTL_SPLAY_LINKS Links;
  4921. PSTRING Prefix;
  4922. } PREFIX_TABLE_ENTRY;
  4923. typedef PREFIX_TABLE_ENTRY *PPREFIX_TABLE_ENTRY;
  4924. typedef struct _PREFIX_TABLE {
  4925. CSHORT NodeTypeCode;
  4926. CSHORT NameLength;
  4927. PPREFIX_TABLE_ENTRY NextPrefixTree;
  4928. } PREFIX_TABLE;
  4929. typedef PREFIX_TABLE *PPREFIX_TABLE;
  4930. //
  4931. // The procedure prototypes for the prefix package
  4932. //
  4933. NTSYSAPI
  4934. VOID
  4935. NTAPI
  4936. PfxInitialize (
  4937. PPREFIX_TABLE PrefixTable
  4938. );
  4939. NTSYSAPI
  4940. BOOLEAN
  4941. NTAPI
  4942. PfxInsertPrefix (
  4943. PPREFIX_TABLE PrefixTable,
  4944. PSTRING Prefix,
  4945. PPREFIX_TABLE_ENTRY PrefixTableEntry
  4946. );
  4947. NTSYSAPI
  4948. VOID
  4949. NTAPI
  4950. PfxRemovePrefix (
  4951. PPREFIX_TABLE PrefixTable,
  4952. PPREFIX_TABLE_ENTRY PrefixTableEntry
  4953. );
  4954. NTSYSAPI
  4955. PPREFIX_TABLE_ENTRY
  4956. NTAPI
  4957. PfxFindPrefix (
  4958. PPREFIX_TABLE PrefixTable,
  4959. PSTRING FullName
  4960. );
  4961. //
  4962. // The following definitions are for the unicode version of the prefix
  4963. // package.
  4964. //
  4965. typedef struct _UNICODE_PREFIX_TABLE_ENTRY {
  4966. CSHORT NodeTypeCode;
  4967. CSHORT NameLength;
  4968. struct _UNICODE_PREFIX_TABLE_ENTRY *NextPrefixTree;
  4969. struct _UNICODE_PREFIX_TABLE_ENTRY *CaseMatch;
  4970. RTL_SPLAY_LINKS Links;
  4971. PUNICODE_STRING Prefix;
  4972. } UNICODE_PREFIX_TABLE_ENTRY;
  4973. typedef UNICODE_PREFIX_TABLE_ENTRY *PUNICODE_PREFIX_TABLE_ENTRY;
  4974. typedef struct _UNICODE_PREFIX_TABLE {
  4975. CSHORT NodeTypeCode;
  4976. CSHORT NameLength;
  4977. PUNICODE_PREFIX_TABLE_ENTRY NextPrefixTree;
  4978. PUNICODE_PREFIX_TABLE_ENTRY LastNextEntry;
  4979. } UNICODE_PREFIX_TABLE;
  4980. typedef UNICODE_PREFIX_TABLE *PUNICODE_PREFIX_TABLE;
  4981. NTSYSAPI
  4982. VOID
  4983. NTAPI
  4984. RtlInitializeUnicodePrefix (
  4985. PUNICODE_PREFIX_TABLE PrefixTable
  4986. );
  4987. NTSYSAPI
  4988. BOOLEAN
  4989. NTAPI
  4990. RtlInsertUnicodePrefix (
  4991. PUNICODE_PREFIX_TABLE PrefixTable,
  4992. PUNICODE_STRING Prefix,
  4993. PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry
  4994. );
  4995. NTSYSAPI
  4996. VOID
  4997. NTAPI
  4998. RtlRemoveUnicodePrefix (
  4999. PUNICODE_PREFIX_TABLE PrefixTable,
  5000. PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry
  5001. );
  5002. NTSYSAPI
  5003. PUNICODE_PREFIX_TABLE_ENTRY
  5004. NTAPI
  5005. RtlFindUnicodePrefix (
  5006. PUNICODE_PREFIX_TABLE PrefixTable,
  5007. PUNICODE_STRING FullName,
  5008. ULONG CaseInsensitiveIndex
  5009. );
  5010. NTSYSAPI
  5011. PUNICODE_PREFIX_TABLE_ENTRY
  5012. NTAPI
  5013. RtlNextUnicodePrefix (
  5014. PUNICODE_PREFIX_TABLE PrefixTable,
  5015. BOOLEAN Restart
  5016. );
  5017. //
  5018. //
  5019. // Compression package types and procedures.
  5020. //
  5021. #define COMPRESSION_FORMAT_NONE (0x0000) // winnt
  5022. #define COMPRESSION_FORMAT_DEFAULT (0x0001) // winnt
  5023. #define COMPRESSION_FORMAT_LZNT1 (0x0002) // winnt
  5024. #define COMPRESSION_ENGINE_STANDARD (0x0000) // winnt
  5025. #define COMPRESSION_ENGINE_MAXIMUM (0x0100) // winnt
  5026. #define COMPRESSION_ENGINE_HIBER (0x0200) // winnt
  5027. //
  5028. // Compressed Data Information structure. This structure is
  5029. // used to describe the state of a compressed data buffer,
  5030. // whose uncompressed size is known. All compressed chunks
  5031. // described by this structure must be compressed with the
  5032. // same format. On compressed reads, this entire structure
  5033. // is an output, and on compressed writes the entire structure
  5034. // is an input.
  5035. //
  5036. typedef struct _COMPRESSED_DATA_INFO {
  5037. //
  5038. // Code for the compression format (and engine) as
  5039. // defined in ntrtl.h. Note that COMPRESSION_FORMAT_NONE
  5040. // and COMPRESSION_FORMAT_DEFAULT are invalid if
  5041. // any of the described chunks are compressed.
  5042. //
  5043. USHORT CompressionFormatAndEngine;
  5044. //
  5045. // Since chunks and compression units are expected to be
  5046. // powers of 2 in size, we express then log2. So, for
  5047. // example (1 << ChunkShift) == ChunkSizeInBytes. The
  5048. // ClusterShift indicates how much space must be saved
  5049. // to successfully compress a compression unit - each
  5050. // successfully compressed compression unit must occupy
  5051. // at least one cluster less in bytes than an uncompressed
  5052. // compression unit.
  5053. //
  5054. UCHAR CompressionUnitShift;
  5055. UCHAR ChunkShift;
  5056. UCHAR ClusterShift;
  5057. UCHAR Reserved;
  5058. //
  5059. // This is the number of entries in the CompressedChunkSizes
  5060. // array.
  5061. //
  5062. USHORT NumberOfChunks;
  5063. //
  5064. // This is an array of the sizes of all chunks resident
  5065. // in the compressed data buffer. There must be one entry
  5066. // in this array for each chunk possible in the uncompressed
  5067. // buffer size. A size of FSRTL_CHUNK_SIZE indicates the
  5068. // corresponding chunk is uncompressed and occupies exactly
  5069. // that size. A size of 0 indicates that the corresponding
  5070. // chunk contains nothing but binary 0's, and occupies no
  5071. // space in the compressed data. All other sizes must be
  5072. // less than FSRTL_CHUNK_SIZE, and indicate the exact size
  5073. // of the compressed data in bytes.
  5074. //
  5075. ULONG CompressedChunkSizes[ANYSIZE_ARRAY];
  5076. } COMPRESSED_DATA_INFO;
  5077. typedef COMPRESSED_DATA_INFO *PCOMPRESSED_DATA_INFO;
  5078. NTSYSAPI
  5079. NTSTATUS
  5080. NTAPI
  5081. RtlGetCompressionWorkSpaceSize (
  5082. IN USHORT CompressionFormatAndEngine,
  5083. OUT PULONG CompressBufferWorkSpaceSize,
  5084. OUT PULONG CompressFragmentWorkSpaceSize
  5085. );
  5086. NTSYSAPI
  5087. NTSTATUS
  5088. NTAPI
  5089. RtlCompressBuffer (
  5090. IN USHORT CompressionFormatAndEngine,
  5091. IN PUCHAR UncompressedBuffer,
  5092. IN ULONG UncompressedBufferSize,
  5093. OUT PUCHAR CompressedBuffer,
  5094. IN ULONG CompressedBufferSize,
  5095. IN ULONG UncompressedChunkSize,
  5096. OUT PULONG FinalCompressedSize,
  5097. IN PVOID WorkSpace
  5098. );
  5099. NTSYSAPI
  5100. NTSTATUS
  5101. NTAPI
  5102. RtlDecompressBuffer (
  5103. IN USHORT CompressionFormat,
  5104. OUT PUCHAR UncompressedBuffer,
  5105. IN ULONG UncompressedBufferSize,
  5106. IN PUCHAR CompressedBuffer,
  5107. IN ULONG CompressedBufferSize,
  5108. OUT PULONG FinalUncompressedSize
  5109. );
  5110. NTSYSAPI
  5111. NTSTATUS
  5112. NTAPI
  5113. RtlDecompressFragment (
  5114. IN USHORT CompressionFormat,
  5115. OUT PUCHAR UncompressedFragment,
  5116. IN ULONG UncompressedFragmentSize,
  5117. IN PUCHAR CompressedBuffer,
  5118. IN ULONG CompressedBufferSize,
  5119. IN ULONG FragmentOffset,
  5120. OUT PULONG FinalUncompressedSize,
  5121. IN PVOID WorkSpace
  5122. );
  5123. NTSYSAPI
  5124. NTSTATUS
  5125. NTAPI
  5126. RtlDescribeChunk (
  5127. IN USHORT CompressionFormat,
  5128. IN OUT PUCHAR *CompressedBuffer,
  5129. IN PUCHAR EndOfCompressedBufferPlus1,
  5130. OUT PUCHAR *ChunkBuffer,
  5131. OUT PULONG ChunkSize
  5132. );
  5133. NTSYSAPI
  5134. NTSTATUS
  5135. NTAPI
  5136. RtlReserveChunk (
  5137. IN USHORT CompressionFormat,
  5138. IN OUT PUCHAR *CompressedBuffer,
  5139. IN PUCHAR EndOfCompressedBufferPlus1,
  5140. OUT PUCHAR *ChunkBuffer,
  5141. IN ULONG ChunkSize
  5142. );
  5143. NTSYSAPI
  5144. NTSTATUS
  5145. NTAPI
  5146. RtlDecompressChunks (
  5147. OUT PUCHAR UncompressedBuffer,
  5148. IN ULONG UncompressedBufferSize,
  5149. IN PUCHAR CompressedBuffer,
  5150. IN ULONG CompressedBufferSize,
  5151. IN PUCHAR CompressedTail,
  5152. IN ULONG CompressedTailSize,
  5153. IN PCOMPRESSED_DATA_INFO CompressedDataInfo
  5154. );
  5155. NTSYSAPI
  5156. NTSTATUS
  5157. NTAPI
  5158. RtlCompressChunks (
  5159. IN PUCHAR UncompressedBuffer,
  5160. IN ULONG UncompressedBufferSize,
  5161. OUT PUCHAR CompressedBuffer,
  5162. IN ULONG CompressedBufferSize,
  5163. IN OUT PCOMPRESSED_DATA_INFO CompressedDataInfo,
  5164. IN ULONG CompressedDataInfoLength,
  5165. IN PVOID WorkSpace
  5166. );
  5167. //
  5168. // Fast primitives to compare, move, and zero memory
  5169. //
  5170. // begin_winnt begin_ntndis
  5171. NTSYSAPI
  5172. SIZE_T
  5173. NTAPI
  5174. RtlCompareMemory (
  5175. const VOID *Source1,
  5176. const VOID *Source2,
  5177. SIZE_T Length
  5178. );
  5179. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  5180. #if defined(_M_AMD64)
  5181. NTSYSAPI
  5182. VOID
  5183. NTAPI
  5184. RtlCopyMemory (
  5185. VOID UNALIGNED *Destination,
  5186. CONST VOID UNALIGNED *Source,
  5187. SIZE_T Length
  5188. );
  5189. NTSYSAPI
  5190. VOID
  5191. NTAPI
  5192. RtlMoveMemory (
  5193. VOID UNALIGNED *Destination,
  5194. CONST VOID UNALIGNED *Source,
  5195. SIZE_T Length
  5196. );
  5197. NTSYSAPI
  5198. VOID
  5199. NTAPI
  5200. RtlFillMemory (
  5201. VOID UNALIGNED *Destination,
  5202. SIZE_T Length,
  5203. IN UCHAR Fill
  5204. );
  5205. NTSYSAPI
  5206. VOID
  5207. NTAPI
  5208. RtlZeroMemory (
  5209. VOID UNALIGNED *Destination,
  5210. SIZE_T Length
  5211. );
  5212. #else
  5213. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  5214. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  5215. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  5216. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  5217. #endif
  5218. #if !defined(MIDL_PASS)
  5219. FORCEINLINE
  5220. PVOID
  5221. RtlSecureZeroMemory(
  5222. IN PVOID ptr,
  5223. IN SIZE_T cnt
  5224. )
  5225. {
  5226. volatile char *vptr = (volatile char *)ptr;
  5227. while (cnt) {
  5228. *vptr = 0;
  5229. vptr++;
  5230. cnt--;
  5231. }
  5232. return ptr;
  5233. }
  5234. #endif
  5235. // end_ntndis end_winnt
  5236. #define RtlCopyBytes RtlCopyMemory
  5237. #define RtlZeroBytes RtlZeroMemory
  5238. #define RtlFillBytes RtlFillMemory
  5239. #if defined(_M_AMD64)
  5240. NTSYSAPI
  5241. VOID
  5242. NTAPI
  5243. RtlCopyMemoryNonTemporal (
  5244. VOID UNALIGNED *Destination,
  5245. CONST VOID UNALIGNED *Source,
  5246. SIZE_T Length
  5247. );
  5248. #else
  5249. #define RtlCopyMemoryNonTemporal RtlCopyMemory
  5250. #endif
  5251. NTSYSAPI
  5252. VOID
  5253. FASTCALL
  5254. RtlPrefetchMemoryNonTemporal(
  5255. IN PVOID Source,
  5256. IN SIZE_T Length
  5257. );
  5258. // end_ntddk end_wdm end_nthal
  5259. NTSYSAPI
  5260. SIZE_T
  5261. NTAPI
  5262. RtlCompareMemoryUlong (
  5263. PVOID Source,
  5264. SIZE_T Length,
  5265. ULONG Pattern
  5266. );
  5267. #if defined(_M_AMD64)
  5268. #define RtlFillMemoryUlong(Destination, Length, Pattern) \
  5269. __stosd((PULONG)(Destination), Pattern, (Length) / 4)
  5270. #define RtlFillMemoryUlonglong(Destination, Length, Pattern) \
  5271. __stosq((PULONG64)(Destination), Pattern, (Length) / 8)
  5272. #else
  5273. NTSYSAPI
  5274. VOID
  5275. NTAPI
  5276. RtlFillMemoryUlong (
  5277. PVOID Destination,
  5278. SIZE_T Length,
  5279. ULONG Pattern
  5280. );
  5281. NTSYSAPI
  5282. VOID
  5283. NTAPI
  5284. RtlFillMemoryUlonglong (
  5285. PVOID Destination,
  5286. SIZE_T Length,
  5287. ULONGLONG Pattern
  5288. );
  5289. #endif
  5290. //
  5291. // Define kernel debugger print prototypes and macros.
  5292. //
  5293. // N.B. The following function cannot be directly imported because there are
  5294. // a few places in the source tree where this function is redefined.
  5295. //
  5296. VOID
  5297. NTAPI
  5298. DbgBreakPoint(
  5299. VOID
  5300. );
  5301. // end_wdm
  5302. NTSYSAPI
  5303. VOID
  5304. NTAPI
  5305. DbgBreakPointWithStatus(
  5306. IN ULONG Status
  5307. );
  5308. // begin_wdm
  5309. #define DBG_STATUS_CONTROL_C 1
  5310. #define DBG_STATUS_SYSRQ 2
  5311. #define DBG_STATUS_BUGCHECK_FIRST 3
  5312. #define DBG_STATUS_BUGCHECK_SECOND 4
  5313. #define DBG_STATUS_FATAL 5
  5314. #define DBG_STATUS_DEBUG_CONTROL 6
  5315. #define DBG_STATUS_WORKER 7
  5316. #if DBG
  5317. #define KdPrint(_x_) DbgPrint _x_
  5318. // end_wdm
  5319. #define KdPrintEx(_x_) DbgPrintEx _x_
  5320. #define vKdPrintEx(_x_) vDbgPrintEx _x_
  5321. #define vKdPrintExWithPrefix(_x_) vDbgPrintExWithPrefix _x_
  5322. // begin_wdm
  5323. #define KdBreakPoint() DbgBreakPoint()
  5324. // end_wdm
  5325. #define KdBreakPointWithStatus(s) DbgBreakPointWithStatus(s)
  5326. // begin_wdm
  5327. #else
  5328. #define KdPrint(_x_)
  5329. // end_wdm
  5330. #define KdPrintEx(_x_)
  5331. #define vKdPrintEx(_x_)
  5332. #define vKdPrintExWithPrefix(_x_)
  5333. // begin_wdm
  5334. #define KdBreakPoint()
  5335. // end_wdm
  5336. #define KdBreakPointWithStatus(s)
  5337. // begin_wdm
  5338. #endif
  5339. #ifndef _DBGNT_
  5340. ULONG
  5341. __cdecl
  5342. DbgPrint(
  5343. PCH Format,
  5344. ...
  5345. );
  5346. // end_wdm
  5347. ULONG
  5348. __cdecl
  5349. DbgPrintEx(
  5350. IN ULONG ComponentId,
  5351. IN ULONG Level,
  5352. IN PCH Format,
  5353. ...
  5354. );
  5355. #ifdef _VA_LIST_DEFINED
  5356. ULONG
  5357. vDbgPrintEx(
  5358. IN ULONG ComponentId,
  5359. IN ULONG Level,
  5360. IN PCH Format,
  5361. va_list arglist
  5362. );
  5363. ULONG
  5364. vDbgPrintExWithPrefix(
  5365. IN PCH Prefix,
  5366. IN ULONG ComponentId,
  5367. IN ULONG Level,
  5368. IN PCH Format,
  5369. va_list arglist
  5370. );
  5371. #endif
  5372. ULONG
  5373. __cdecl
  5374. DbgPrintReturnControlC(
  5375. PCH Format,
  5376. ...
  5377. );
  5378. NTSYSAPI
  5379. NTSTATUS
  5380. DbgQueryDebugFilterState(
  5381. IN ULONG ComponentId,
  5382. IN ULONG Level
  5383. );
  5384. NTSYSAPI
  5385. NTSTATUS
  5386. DbgSetDebugFilterState(
  5387. IN ULONG ComponentId,
  5388. IN ULONG Level,
  5389. IN BOOLEAN State
  5390. );
  5391. // begin_wdm
  5392. #endif // _DBGNT_
  5393. //
  5394. // Large integer arithmetic routines.
  5395. //
  5396. //
  5397. // Large integer add - 64-bits + 64-bits -> 64-bits
  5398. //
  5399. #if !defined(MIDL_PASS)
  5400. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5401. __inline
  5402. LARGE_INTEGER
  5403. NTAPI
  5404. RtlLargeIntegerAdd (
  5405. LARGE_INTEGER Addend1,
  5406. LARGE_INTEGER Addend2
  5407. )
  5408. {
  5409. LARGE_INTEGER Sum;
  5410. Sum.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
  5411. return Sum;
  5412. }
  5413. //
  5414. // Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  5415. //
  5416. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5417. __inline
  5418. LARGE_INTEGER
  5419. NTAPI
  5420. RtlEnlargedIntegerMultiply (
  5421. LONG Multiplicand,
  5422. LONG Multiplier
  5423. )
  5424. {
  5425. LARGE_INTEGER Product;
  5426. Product.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  5427. return Product;
  5428. }
  5429. //
  5430. // Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  5431. //
  5432. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5433. __inline
  5434. LARGE_INTEGER
  5435. NTAPI
  5436. RtlEnlargedUnsignedMultiply (
  5437. ULONG Multiplicand,
  5438. ULONG Multiplier
  5439. )
  5440. {
  5441. LARGE_INTEGER Product;
  5442. Product.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  5443. return Product;
  5444. }
  5445. //
  5446. // Enlarged integer divide - 64-bits / 32-bits > 32-bits
  5447. //
  5448. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5449. __inline
  5450. ULONG
  5451. NTAPI
  5452. RtlEnlargedUnsignedDivide (
  5453. IN ULARGE_INTEGER Dividend,
  5454. IN ULONG Divisor,
  5455. IN PULONG Remainder OPTIONAL
  5456. )
  5457. {
  5458. ULONG Quotient;
  5459. Quotient = (ULONG)(Dividend.QuadPart / Divisor);
  5460. if (ARGUMENT_PRESENT(Remainder)) {
  5461. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  5462. }
  5463. return Quotient;
  5464. }
  5465. //
  5466. // Large integer negation - -(64-bits)
  5467. //
  5468. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5469. __inline
  5470. LARGE_INTEGER
  5471. NTAPI
  5472. RtlLargeIntegerNegate (
  5473. LARGE_INTEGER Subtrahend
  5474. )
  5475. {
  5476. LARGE_INTEGER Difference;
  5477. Difference.QuadPart = -Subtrahend.QuadPart;
  5478. return Difference;
  5479. }
  5480. //
  5481. // Large integer subtract - 64-bits - 64-bits -> 64-bits.
  5482. //
  5483. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5484. __inline
  5485. LARGE_INTEGER
  5486. NTAPI
  5487. RtlLargeIntegerSubtract (
  5488. LARGE_INTEGER Minuend,
  5489. LARGE_INTEGER Subtrahend
  5490. )
  5491. {
  5492. LARGE_INTEGER Difference;
  5493. Difference.QuadPart = Minuend.QuadPart - Subtrahend.QuadPart;
  5494. return Difference;
  5495. }
  5496. //
  5497. // Extended large integer magic divide - 64-bits / 32-bits -> 64-bits
  5498. //
  5499. #if defined(_AMD64_)
  5500. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5501. __inline
  5502. LARGE_INTEGER
  5503. NTAPI
  5504. RtlExtendedMagicDivide (
  5505. LARGE_INTEGER Dividend,
  5506. LARGE_INTEGER MagicDivisor,
  5507. CCHAR ShiftCount
  5508. )
  5509. {
  5510. LARGE_INTEGER Quotient;
  5511. if (Dividend.QuadPart >= 0) {
  5512. Quotient.QuadPart = UnsignedMultiplyHigh(Dividend.QuadPart,
  5513. (ULONG64)MagicDivisor.QuadPart);
  5514. } else {
  5515. Quotient.QuadPart = UnsignedMultiplyHigh(-Dividend.QuadPart,
  5516. (ULONG64)MagicDivisor.QuadPart);
  5517. }
  5518. Quotient.QuadPart = (ULONG64)Quotient.QuadPart >> ShiftCount;
  5519. if (Dividend.QuadPart < 0) {
  5520. Quotient.QuadPart = - Quotient.QuadPart;
  5521. }
  5522. return Quotient;
  5523. }
  5524. #endif // defined(_AMD64_)
  5525. #if defined(_X86_) || defined(_IA64_)
  5526. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5527. NTSYSAPI
  5528. LARGE_INTEGER
  5529. NTAPI
  5530. RtlExtendedMagicDivide (
  5531. LARGE_INTEGER Dividend,
  5532. LARGE_INTEGER MagicDivisor,
  5533. CCHAR ShiftCount
  5534. );
  5535. #endif // defined(_X86_) || defined(_IA64_)
  5536. #if defined(_AMD64_) || defined(_IA64_)
  5537. //
  5538. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  5539. //
  5540. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5541. __inline
  5542. LARGE_INTEGER
  5543. NTAPI
  5544. RtlExtendedLargeIntegerDivide (
  5545. LARGE_INTEGER Dividend,
  5546. ULONG Divisor,
  5547. PULONG Remainder OPTIONAL
  5548. )
  5549. {
  5550. LARGE_INTEGER Quotient;
  5551. Quotient.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
  5552. if (ARGUMENT_PRESENT(Remainder)) {
  5553. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  5554. }
  5555. return Quotient;
  5556. }
  5557. // end_wdm
  5558. //
  5559. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  5560. //
  5561. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5562. __inline
  5563. LARGE_INTEGER
  5564. NTAPI
  5565. RtlLargeIntegerDivide (
  5566. LARGE_INTEGER Dividend,
  5567. LARGE_INTEGER Divisor,
  5568. PLARGE_INTEGER Remainder OPTIONAL
  5569. )
  5570. {
  5571. LARGE_INTEGER Quotient;
  5572. Quotient.QuadPart = Dividend.QuadPart / Divisor.QuadPart;
  5573. if (ARGUMENT_PRESENT(Remainder)) {
  5574. Remainder->QuadPart = Dividend.QuadPart % Divisor.QuadPart;
  5575. }
  5576. return Quotient;
  5577. }
  5578. // begin_wdm
  5579. //
  5580. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  5581. //
  5582. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5583. __inline
  5584. LARGE_INTEGER
  5585. NTAPI
  5586. RtlExtendedIntegerMultiply (
  5587. LARGE_INTEGER Multiplicand,
  5588. LONG Multiplier
  5589. )
  5590. {
  5591. LARGE_INTEGER Product;
  5592. Product.QuadPart = Multiplicand.QuadPart * Multiplier;
  5593. return Product;
  5594. }
  5595. #else
  5596. //
  5597. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  5598. //
  5599. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5600. NTSYSAPI
  5601. LARGE_INTEGER
  5602. NTAPI
  5603. RtlExtendedLargeIntegerDivide (
  5604. LARGE_INTEGER Dividend,
  5605. ULONG Divisor,
  5606. PULONG Remainder
  5607. );
  5608. // end_wdm
  5609. //
  5610. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  5611. //
  5612. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5613. NTSYSAPI
  5614. LARGE_INTEGER
  5615. NTAPI
  5616. RtlLargeIntegerDivide (
  5617. LARGE_INTEGER Dividend,
  5618. LARGE_INTEGER Divisor,
  5619. PLARGE_INTEGER Remainder
  5620. );
  5621. // begin_wdm
  5622. //
  5623. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  5624. //
  5625. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5626. NTSYSAPI
  5627. LARGE_INTEGER
  5628. NTAPI
  5629. RtlExtendedIntegerMultiply (
  5630. LARGE_INTEGER Multiplicand,
  5631. LONG Multiplier
  5632. );
  5633. #endif // defined(_AMD64_) || defined(_IA64_)
  5634. //
  5635. // Large integer and - 64-bite & 64-bits -> 64-bits.
  5636. //
  5637. #if PRAGMA_DEPRECATED_DDK
  5638. #pragma deprecated(RtlLargeIntegerAnd) // Use native __int64 math
  5639. #endif
  5640. #define RtlLargeIntegerAnd(Result, Source, Mask) \
  5641. Result.QuadPart = Source.QuadPart & Mask.QuadPart
  5642. //
  5643. // Convert signed integer to large integer.
  5644. //
  5645. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5646. __inline
  5647. LARGE_INTEGER
  5648. NTAPI
  5649. RtlConvertLongToLargeInteger (
  5650. LONG SignedInteger
  5651. )
  5652. {
  5653. LARGE_INTEGER Result;
  5654. Result.QuadPart = SignedInteger;
  5655. return Result;
  5656. }
  5657. //
  5658. // Convert unsigned integer to large integer.
  5659. //
  5660. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5661. __inline
  5662. LARGE_INTEGER
  5663. NTAPI
  5664. RtlConvertUlongToLargeInteger (
  5665. ULONG UnsignedInteger
  5666. )
  5667. {
  5668. LARGE_INTEGER Result;
  5669. Result.QuadPart = UnsignedInteger;
  5670. return Result;
  5671. }
  5672. //
  5673. // Large integer shift routines.
  5674. //
  5675. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5676. __inline
  5677. LARGE_INTEGER
  5678. NTAPI
  5679. RtlLargeIntegerShiftLeft (
  5680. LARGE_INTEGER LargeInteger,
  5681. CCHAR ShiftCount
  5682. )
  5683. {
  5684. LARGE_INTEGER Result;
  5685. Result.QuadPart = LargeInteger.QuadPart << ShiftCount;
  5686. return Result;
  5687. }
  5688. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5689. __inline
  5690. LARGE_INTEGER
  5691. NTAPI
  5692. RtlLargeIntegerShiftRight (
  5693. LARGE_INTEGER LargeInteger,
  5694. CCHAR ShiftCount
  5695. )
  5696. {
  5697. LARGE_INTEGER Result;
  5698. Result.QuadPart = (ULONG64)LargeInteger.QuadPart >> ShiftCount;
  5699. return Result;
  5700. }
  5701. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  5702. __inline
  5703. LARGE_INTEGER
  5704. NTAPI
  5705. RtlLargeIntegerArithmeticShift (
  5706. LARGE_INTEGER LargeInteger,
  5707. CCHAR ShiftCount
  5708. )
  5709. {
  5710. LARGE_INTEGER Result;
  5711. Result.QuadPart = LargeInteger.QuadPart >> ShiftCount;
  5712. return Result;
  5713. }
  5714. //
  5715. // Large integer comparison routines.
  5716. //
  5717. #if PRAGMA_DEPRECATED_DDK
  5718. #pragma deprecated(RtlLargeIntegerGreaterThan) // Use native __int64 math
  5719. #pragma deprecated(RtlLargeIntegerGreaterThanOrEqualTo) // Use native __int64 math
  5720. #pragma deprecated(RtlLargeIntegerEqualTo) // Use native __int64 math
  5721. #pragma deprecated(RtlLargeIntegerNotEqualTo) // Use native __int64 math
  5722. #pragma deprecated(RtlLargeIntegerLessThan) // Use native __int64 math
  5723. #pragma deprecated(RtlLargeIntegerLessThanOrEqualTo) // Use native __int64 math
  5724. #pragma deprecated(RtlLargeIntegerGreaterThanZero) // Use native __int64 math
  5725. #pragma deprecated(RtlLargeIntegerGreaterOrEqualToZero) // Use native __int64 math
  5726. #pragma deprecated(RtlLargeIntegerEqualToZero) // Use native __int64 math
  5727. #pragma deprecated(RtlLargeIntegerNotEqualToZero) // Use native __int64 math
  5728. #pragma deprecated(RtlLargeIntegerLessThanZero) // Use native __int64 math
  5729. #pragma deprecated(RtlLargeIntegerLessOrEqualToZero) // Use native __int64 math
  5730. #endif
  5731. #define RtlLargeIntegerGreaterThan(X,Y) ( \
  5732. (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
  5733. ((X).HighPart > (Y).HighPart) \
  5734. )
  5735. #define RtlLargeIntegerGreaterThanOrEqualTo(X,Y) ( \
  5736. (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
  5737. ((X).HighPart > (Y).HighPart) \
  5738. )
  5739. #define RtlLargeIntegerEqualTo(X,Y) ( \
  5740. !(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  5741. )
  5742. #define RtlLargeIntegerNotEqualTo(X,Y) ( \
  5743. (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  5744. )
  5745. #define RtlLargeIntegerLessThan(X,Y) ( \
  5746. (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
  5747. ((X).HighPart < (Y).HighPart) \
  5748. )
  5749. #define RtlLargeIntegerLessThanOrEqualTo(X,Y) ( \
  5750. (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
  5751. ((X).HighPart < (Y).HighPart) \
  5752. )
  5753. #define RtlLargeIntegerGreaterThanZero(X) ( \
  5754. (((X).HighPart == 0) && ((X).LowPart > 0)) || \
  5755. ((X).HighPart > 0 ) \
  5756. )
  5757. #define RtlLargeIntegerGreaterOrEqualToZero(X) ( \
  5758. (X).HighPart >= 0 \
  5759. )
  5760. #define RtlLargeIntegerEqualToZero(X) ( \
  5761. !((X).LowPart | (X).HighPart) \
  5762. )
  5763. #define RtlLargeIntegerNotEqualToZero(X) ( \
  5764. ((X).LowPart | (X).HighPart) \
  5765. )
  5766. #define RtlLargeIntegerLessThanZero(X) ( \
  5767. ((X).HighPart < 0) \
  5768. )
  5769. #define RtlLargeIntegerLessOrEqualToZero(X) ( \
  5770. ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) \
  5771. )
  5772. #endif // !defined(MIDL_PASS)
  5773. //
  5774. // Time conversion routines
  5775. //
  5776. typedef struct _TIME_FIELDS {
  5777. CSHORT Year; // range [1601...]
  5778. CSHORT Month; // range [1..12]
  5779. CSHORT Day; // range [1..31]
  5780. CSHORT Hour; // range [0..23]
  5781. CSHORT Minute; // range [0..59]
  5782. CSHORT Second; // range [0..59]
  5783. CSHORT Milliseconds;// range [0..999]
  5784. CSHORT Weekday; // range [0..6] == [Sunday..Saturday]
  5785. } TIME_FIELDS;
  5786. typedef TIME_FIELDS *PTIME_FIELDS;
  5787. NTSYSAPI
  5788. VOID
  5789. NTAPI
  5790. RtlTimeToTimeFields (
  5791. PLARGE_INTEGER Time,
  5792. PTIME_FIELDS TimeFields
  5793. );
  5794. //
  5795. // A time field record (Weekday ignored) -> 64 bit Time value
  5796. //
  5797. NTSYSAPI
  5798. BOOLEAN
  5799. NTAPI
  5800. RtlTimeFieldsToTime (
  5801. PTIME_FIELDS TimeFields,
  5802. PLARGE_INTEGER Time
  5803. );
  5804. // end_ntddk end_wdm
  5805. //
  5806. // A 64 bit Time value -> Seconds since the start of 1980
  5807. //
  5808. NTSYSAPI
  5809. BOOLEAN
  5810. NTAPI
  5811. RtlTimeToSecondsSince1980 (
  5812. PLARGE_INTEGER Time,
  5813. PULONG ElapsedSeconds
  5814. );
  5815. //
  5816. // Seconds since the start of 1980 -> 64 bit Time value
  5817. //
  5818. NTSYSAPI
  5819. VOID
  5820. NTAPI
  5821. RtlSecondsSince1980ToTime (
  5822. ULONG ElapsedSeconds,
  5823. PLARGE_INTEGER Time
  5824. );
  5825. //
  5826. // A 64 bit Time value -> Seconds since the start of 1970
  5827. //
  5828. NTSYSAPI
  5829. BOOLEAN
  5830. NTAPI
  5831. RtlTimeToSecondsSince1970 (
  5832. PLARGE_INTEGER Time,
  5833. PULONG ElapsedSeconds
  5834. );
  5835. //
  5836. // Seconds since the start of 1970 -> 64 bit Time value
  5837. //
  5838. NTSYSAPI
  5839. VOID
  5840. NTAPI
  5841. RtlSecondsSince1970ToTime (
  5842. ULONG ElapsedSeconds,
  5843. PLARGE_INTEGER Time
  5844. );
  5845. //
  5846. // The following macros store and retrieve USHORTS and ULONGS from potentially
  5847. // unaligned addresses, avoiding alignment faults. they should probably be
  5848. // rewritten in assembler
  5849. //
  5850. #define SHORT_SIZE (sizeof(USHORT))
  5851. #define SHORT_MASK (SHORT_SIZE - 1)
  5852. #define LONG_SIZE (sizeof(LONG))
  5853. #define LONGLONG_SIZE (sizeof(LONGLONG))
  5854. #define LONG_MASK (LONG_SIZE - 1)
  5855. #define LONGLONG_MASK (LONGLONG_SIZE - 1)
  5856. #define LOWBYTE_MASK 0x00FF
  5857. #define FIRSTBYTE(VALUE) ((VALUE) & LOWBYTE_MASK)
  5858. #define SECONDBYTE(VALUE) (((VALUE) >> 8) & LOWBYTE_MASK)
  5859. #define THIRDBYTE(VALUE) (((VALUE) >> 16) & LOWBYTE_MASK)
  5860. #define FOURTHBYTE(VALUE) (((VALUE) >> 24) & LOWBYTE_MASK)
  5861. //
  5862. // if MIPS Big Endian, order of bytes is reversed.
  5863. //
  5864. #define SHORT_LEAST_SIGNIFICANT_BIT 0
  5865. #define SHORT_MOST_SIGNIFICANT_BIT 1
  5866. #define LONG_LEAST_SIGNIFICANT_BIT 0
  5867. #define LONG_3RD_MOST_SIGNIFICANT_BIT 1
  5868. #define LONG_2ND_MOST_SIGNIFICANT_BIT 2
  5869. #define LONG_MOST_SIGNIFICANT_BIT 3
  5870. //++
  5871. //
  5872. // VOID
  5873. // RtlStoreUshort (
  5874. // PUSHORT ADDRESS
  5875. // USHORT VALUE
  5876. // )
  5877. //
  5878. // Routine Description:
  5879. //
  5880. // This macro stores a USHORT value in at a particular address, avoiding
  5881. // alignment faults.
  5882. //
  5883. // Arguments:
  5884. //
  5885. // ADDRESS - where to store USHORT value
  5886. // VALUE - USHORT to store
  5887. //
  5888. // Return Value:
  5889. //
  5890. // none.
  5891. //
  5892. //--
  5893. #define RtlStoreUshort(ADDRESS,VALUE) \
  5894. if ((ULONG_PTR)(ADDRESS) & SHORT_MASK) { \
  5895. ((PUCHAR) (ADDRESS))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(VALUE)); \
  5896. ((PUCHAR) (ADDRESS))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  5897. } \
  5898. else { \
  5899. *((PUSHORT) (ADDRESS)) = (USHORT) VALUE; \
  5900. }
  5901. //++
  5902. //
  5903. // VOID
  5904. // RtlStoreUlong (
  5905. // PULONG ADDRESS
  5906. // ULONG VALUE
  5907. // )
  5908. //
  5909. // Routine Description:
  5910. //
  5911. // This macro stores a ULONG value in at a particular address, avoiding
  5912. // alignment faults.
  5913. //
  5914. // Arguments:
  5915. //
  5916. // ADDRESS - where to store ULONG value
  5917. // VALUE - ULONG to store
  5918. //
  5919. // Return Value:
  5920. //
  5921. // none.
  5922. //
  5923. // Note:
  5924. // Depending on the machine, we might want to call storeushort in the
  5925. // unaligned case.
  5926. //
  5927. //--
  5928. #define RtlStoreUlong(ADDRESS,VALUE) \
  5929. if ((ULONG_PTR)(ADDRESS) & LONG_MASK) { \
  5930. ((PUCHAR) (ADDRESS))[LONG_LEAST_SIGNIFICANT_BIT ] = (UCHAR)(FIRSTBYTE(VALUE)); \
  5931. ((PUCHAR) (ADDRESS))[LONG_3RD_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  5932. ((PUCHAR) (ADDRESS))[LONG_2ND_MOST_SIGNIFICANT_BIT ] = (UCHAR)(THIRDBYTE(VALUE)); \
  5933. ((PUCHAR) (ADDRESS))[LONG_MOST_SIGNIFICANT_BIT ] = (UCHAR)(FOURTHBYTE(VALUE)); \
  5934. } \
  5935. else { \
  5936. *((PULONG) (ADDRESS)) = (ULONG) (VALUE); \
  5937. }
  5938. //++
  5939. //
  5940. // VOID
  5941. // RtlStoreUlonglong (
  5942. // PULONGLONG ADDRESS
  5943. // ULONG VALUE
  5944. // )
  5945. //
  5946. // Routine Description:
  5947. //
  5948. // This macro stores a ULONGLONG value in at a particular address, avoiding
  5949. // alignment faults.
  5950. //
  5951. // Arguments:
  5952. //
  5953. // ADDRESS - where to store ULONGLONG value
  5954. // VALUE - ULONGLONG to store
  5955. //
  5956. // Return Value:
  5957. //
  5958. // none.
  5959. //
  5960. //--
  5961. #define RtlStoreUlonglong(ADDRESS,VALUE) \
  5962. if ((ULONG_PTR)(ADDRESS) & LONGLONG_MASK) { \
  5963. RtlStoreUlong((ULONG_PTR)(ADDRESS), \
  5964. (ULONGLONG)(VALUE) & 0xFFFFFFFF); \
  5965. RtlStoreUlong((ULONG_PTR)(ADDRESS)+sizeof(ULONG), \
  5966. (ULONGLONG)(VALUE) >> 32); \
  5967. } else { \
  5968. *((PULONGLONG)(ADDRESS)) = (ULONGLONG)(VALUE); \
  5969. }
  5970. //++
  5971. //
  5972. // VOID
  5973. // RtlStoreUlongPtr (
  5974. // PULONG_PTR ADDRESS
  5975. // ULONG_PTR VALUE
  5976. // )
  5977. //
  5978. // Routine Description:
  5979. //
  5980. // This macro stores a ULONG_PTR value in at a particular address, avoiding
  5981. // alignment faults.
  5982. //
  5983. // Arguments:
  5984. //
  5985. // ADDRESS - where to store ULONG_PTR value
  5986. // VALUE - ULONG_PTR to store
  5987. //
  5988. // Return Value:
  5989. //
  5990. // none.
  5991. //
  5992. //--
  5993. #ifdef _WIN64
  5994. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  5995. RtlStoreUlonglong(ADDRESS,VALUE)
  5996. #else
  5997. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  5998. RtlStoreUlong(ADDRESS,VALUE)
  5999. #endif
  6000. //++
  6001. //
  6002. // VOID
  6003. // RtlRetrieveUshort (
  6004. // PUSHORT DESTINATION_ADDRESS
  6005. // PUSHORT SOURCE_ADDRESS
  6006. // )
  6007. //
  6008. // Routine Description:
  6009. //
  6010. // This macro retrieves a USHORT value from the SOURCE address, avoiding
  6011. // alignment faults. The DESTINATION address is assumed to be aligned.
  6012. //
  6013. // Arguments:
  6014. //
  6015. // DESTINATION_ADDRESS - where to store USHORT value
  6016. // SOURCE_ADDRESS - where to retrieve USHORT value from
  6017. //
  6018. // Return Value:
  6019. //
  6020. // none.
  6021. //
  6022. //--
  6023. #define RtlRetrieveUshort(DEST_ADDRESS,SRC_ADDRESS) \
  6024. if ((ULONG_PTR)SRC_ADDRESS & SHORT_MASK) { \
  6025. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  6026. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  6027. } \
  6028. else { \
  6029. *((PUSHORT) DEST_ADDRESS) = *((PUSHORT) SRC_ADDRESS); \
  6030. } \
  6031. //++
  6032. //
  6033. // VOID
  6034. // RtlRetrieveUlong (
  6035. // PULONG DESTINATION_ADDRESS
  6036. // PULONG SOURCE_ADDRESS
  6037. // )
  6038. //
  6039. // Routine Description:
  6040. //
  6041. // This macro retrieves a ULONG value from the SOURCE address, avoiding
  6042. // alignment faults. The DESTINATION address is assumed to be aligned.
  6043. //
  6044. // Arguments:
  6045. //
  6046. // DESTINATION_ADDRESS - where to store ULONG value
  6047. // SOURCE_ADDRESS - where to retrieve ULONG value from
  6048. //
  6049. // Return Value:
  6050. //
  6051. // none.
  6052. //
  6053. // Note:
  6054. // Depending on the machine, we might want to call retrieveushort in the
  6055. // unaligned case.
  6056. //
  6057. //--
  6058. #define RtlRetrieveUlong(DEST_ADDRESS,SRC_ADDRESS) \
  6059. if ((ULONG_PTR)SRC_ADDRESS & LONG_MASK) { \
  6060. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  6061. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  6062. ((PUCHAR) DEST_ADDRESS)[2] = ((PUCHAR) SRC_ADDRESS)[2]; \
  6063. ((PUCHAR) DEST_ADDRESS)[3] = ((PUCHAR) SRC_ADDRESS)[3]; \
  6064. } \
  6065. else { \
  6066. *((PULONG) DEST_ADDRESS) = *((PULONG) SRC_ADDRESS); \
  6067. }
  6068. // end_ntddk end_wdm
  6069. //++
  6070. //
  6071. // PCHAR
  6072. // RtlOffsetToPointer (
  6073. // PVOID Base,
  6074. // ULONG Offset
  6075. // )
  6076. //
  6077. // Routine Description:
  6078. //
  6079. // This macro generates a pointer which points to the byte that is 'Offset'
  6080. // bytes beyond 'Base'. This is useful for referencing fields within
  6081. // self-relative data structures.
  6082. //
  6083. // Arguments:
  6084. //
  6085. // Base - The address of the base of the structure.
  6086. //
  6087. // Offset - An unsigned integer offset of the byte whose address is to
  6088. // be generated.
  6089. //
  6090. // Return Value:
  6091. //
  6092. // A PCHAR pointer to the byte that is 'Offset' bytes beyond 'Base'.
  6093. //
  6094. //
  6095. //--
  6096. #define RtlOffsetToPointer(B,O) ((PCHAR)( ((PCHAR)(B)) + ((ULONG_PTR)(O)) ))
  6097. //++
  6098. //
  6099. // ULONG
  6100. // RtlPointerToOffset (
  6101. // PVOID Base,
  6102. // PVOID Pointer
  6103. // )
  6104. //
  6105. // Routine Description:
  6106. //
  6107. // This macro calculates the offset from Base to Pointer. This is useful
  6108. // for producing self-relative offsets for structures.
  6109. //
  6110. // Arguments:
  6111. //
  6112. // Base - The address of the base of the structure.
  6113. //
  6114. // Pointer - A pointer to a field, presumably within the structure
  6115. // pointed to by Base. This value must be larger than that specified
  6116. // for Base.
  6117. //
  6118. // Return Value:
  6119. //
  6120. // A ULONG offset from Base to Pointer.
  6121. //
  6122. //
  6123. //--
  6124. #define RtlPointerToOffset(B,P) ((ULONG)( ((PCHAR)(P)) - ((PCHAR)(B)) ))
  6125. //
  6126. // BitMap routines. The following structure, routines, and macros are
  6127. // for manipulating bitmaps. The user is responsible for allocating a bitmap
  6128. // structure (which is really a header) and a buffer (which must be longword
  6129. // aligned and multiple longwords in size).
  6130. //
  6131. typedef struct _RTL_BITMAP {
  6132. ULONG SizeOfBitMap; // Number of bits in bit map
  6133. PULONG Buffer; // Pointer to the bit map itself
  6134. } RTL_BITMAP;
  6135. typedef RTL_BITMAP *PRTL_BITMAP;
  6136. //
  6137. // The following routine initializes a new bitmap. It does not alter the
  6138. // data currently in the bitmap. This routine must be called before
  6139. // any other bitmap routine/macro.
  6140. //
  6141. NTSYSAPI
  6142. VOID
  6143. NTAPI
  6144. RtlInitializeBitMap (
  6145. PRTL_BITMAP BitMapHeader,
  6146. PULONG BitMapBuffer,
  6147. ULONG SizeOfBitMap
  6148. );
  6149. //
  6150. // The following three routines clear, set, and test the state of a
  6151. // single bit in a bitmap.
  6152. //
  6153. NTSYSAPI
  6154. VOID
  6155. NTAPI
  6156. RtlClearBit (
  6157. PRTL_BITMAP BitMapHeader,
  6158. ULONG BitNumber
  6159. );
  6160. NTSYSAPI
  6161. VOID
  6162. NTAPI
  6163. RtlSetBit (
  6164. PRTL_BITMAP BitMapHeader,
  6165. ULONG BitNumber
  6166. );
  6167. NTSYSAPI
  6168. BOOLEAN
  6169. NTAPI
  6170. RtlTestBit (
  6171. PRTL_BITMAP BitMapHeader,
  6172. ULONG BitNumber
  6173. );
  6174. //
  6175. // The following two routines either clear or set all of the bits
  6176. // in a bitmap.
  6177. //
  6178. NTSYSAPI
  6179. VOID
  6180. NTAPI
  6181. RtlClearAllBits (
  6182. PRTL_BITMAP BitMapHeader
  6183. );
  6184. NTSYSAPI
  6185. VOID
  6186. NTAPI
  6187. RtlSetAllBits (
  6188. PRTL_BITMAP BitMapHeader
  6189. );
  6190. //
  6191. // The following two routines locate a contiguous region of either
  6192. // clear or set bits within the bitmap. The region will be at least
  6193. // as large as the number specified, and the search of the bitmap will
  6194. // begin at the specified hint index (which is a bit index within the
  6195. // bitmap, zero based). The return value is the bit index of the located
  6196. // region (zero based) or -1 (i.e., 0xffffffff) if such a region cannot
  6197. // be located
  6198. //
  6199. NTSYSAPI
  6200. ULONG
  6201. NTAPI
  6202. RtlFindClearBits (
  6203. PRTL_BITMAP BitMapHeader,
  6204. ULONG NumberToFind,
  6205. ULONG HintIndex
  6206. );
  6207. NTSYSAPI
  6208. ULONG
  6209. NTAPI
  6210. RtlFindSetBits (
  6211. PRTL_BITMAP BitMapHeader,
  6212. ULONG NumberToFind,
  6213. ULONG HintIndex
  6214. );
  6215. //
  6216. // The following two routines locate a contiguous region of either
  6217. // clear or set bits within the bitmap and either set or clear the bits
  6218. // within the located region. The region will be as large as the number
  6219. // specified, and the search for the region will begin at the specified
  6220. // hint index (which is a bit index within the bitmap, zero based). The
  6221. // return value is the bit index of the located region (zero based) or
  6222. // -1 (i.e., 0xffffffff) if such a region cannot be located. If a region
  6223. // cannot be located then the setting/clearing of the bitmap is not performed.
  6224. //
  6225. NTSYSAPI
  6226. ULONG
  6227. NTAPI
  6228. RtlFindClearBitsAndSet (
  6229. PRTL_BITMAP BitMapHeader,
  6230. ULONG NumberToFind,
  6231. ULONG HintIndex
  6232. );
  6233. NTSYSAPI
  6234. ULONG
  6235. NTAPI
  6236. RtlFindSetBitsAndClear (
  6237. PRTL_BITMAP BitMapHeader,
  6238. ULONG NumberToFind,
  6239. ULONG HintIndex
  6240. );
  6241. //
  6242. // The following two routines clear or set bits within a specified region
  6243. // of the bitmap. The starting index is zero based.
  6244. //
  6245. NTSYSAPI
  6246. VOID
  6247. NTAPI
  6248. RtlClearBits (
  6249. PRTL_BITMAP BitMapHeader,
  6250. ULONG StartingIndex,
  6251. ULONG NumberToClear
  6252. );
  6253. NTSYSAPI
  6254. VOID
  6255. NTAPI
  6256. RtlSetBits (
  6257. PRTL_BITMAP BitMapHeader,
  6258. ULONG StartingIndex,
  6259. ULONG NumberToSet
  6260. );
  6261. //
  6262. // The following routine locates a set of contiguous regions of clear
  6263. // bits within the bitmap. The caller specifies whether to return the
  6264. // longest runs or just the first found lcoated. The following structure is
  6265. // used to denote a contiguous run of bits. The two routines return an array
  6266. // of this structure, one for each run located.
  6267. //
  6268. typedef struct _RTL_BITMAP_RUN {
  6269. ULONG StartingIndex;
  6270. ULONG NumberOfBits;
  6271. } RTL_BITMAP_RUN;
  6272. typedef RTL_BITMAP_RUN *PRTL_BITMAP_RUN;
  6273. NTSYSAPI
  6274. ULONG
  6275. NTAPI
  6276. RtlFindClearRuns (
  6277. PRTL_BITMAP BitMapHeader,
  6278. PRTL_BITMAP_RUN RunArray,
  6279. ULONG SizeOfRunArray,
  6280. BOOLEAN LocateLongestRuns
  6281. );
  6282. //
  6283. // The following routine locates the longest contiguous region of
  6284. // clear bits within the bitmap. The returned starting index value
  6285. // denotes the first contiguous region located satisfying our requirements
  6286. // The return value is the length (in bits) of the longest region found.
  6287. //
  6288. NTSYSAPI
  6289. ULONG
  6290. NTAPI
  6291. RtlFindLongestRunClear (
  6292. PRTL_BITMAP BitMapHeader,
  6293. PULONG StartingIndex
  6294. );
  6295. //
  6296. // The following routine locates the first contiguous region of
  6297. // clear bits within the bitmap. The returned starting index value
  6298. // denotes the first contiguous region located satisfying our requirements
  6299. // The return value is the length (in bits) of the region found.
  6300. //
  6301. NTSYSAPI
  6302. ULONG
  6303. NTAPI
  6304. RtlFindFirstRunClear (
  6305. PRTL_BITMAP BitMapHeader,
  6306. PULONG StartingIndex
  6307. );
  6308. //
  6309. // The following macro returns the value of the bit stored within the
  6310. // bitmap at the specified location. If the bit is set a value of 1 is
  6311. // returned otherwise a value of 0 is returned.
  6312. //
  6313. // ULONG
  6314. // RtlCheckBit (
  6315. // PRTL_BITMAP BitMapHeader,
  6316. // ULONG BitPosition
  6317. // );
  6318. //
  6319. //
  6320. // To implement CheckBit the macro retrieves the longword containing the
  6321. // bit in question, shifts the longword to get the bit in question into the
  6322. // low order bit position and masks out all other bits.
  6323. //
  6324. #define RtlCheckBit(BMH,BP) ((((BMH)->Buffer[(BP) / 32]) >> ((BP) % 32)) & 0x1)
  6325. //
  6326. // The following two procedures return to the caller the total number of
  6327. // clear or set bits within the specified bitmap.
  6328. //
  6329. NTSYSAPI
  6330. ULONG
  6331. NTAPI
  6332. RtlNumberOfClearBits (
  6333. PRTL_BITMAP BitMapHeader
  6334. );
  6335. NTSYSAPI
  6336. ULONG
  6337. NTAPI
  6338. RtlNumberOfSetBits (
  6339. PRTL_BITMAP BitMapHeader
  6340. );
  6341. //
  6342. // The following two procedures return to the caller a boolean value
  6343. // indicating if the specified range of bits are all clear or set.
  6344. //
  6345. NTSYSAPI
  6346. BOOLEAN
  6347. NTAPI
  6348. RtlAreBitsClear (
  6349. PRTL_BITMAP BitMapHeader,
  6350. ULONG StartingIndex,
  6351. ULONG Length
  6352. );
  6353. NTSYSAPI
  6354. BOOLEAN
  6355. NTAPI
  6356. RtlAreBitsSet (
  6357. PRTL_BITMAP BitMapHeader,
  6358. ULONG StartingIndex,
  6359. ULONG Length
  6360. );
  6361. NTSYSAPI
  6362. ULONG
  6363. NTAPI
  6364. RtlFindNextForwardRunClear (
  6365. IN PRTL_BITMAP BitMapHeader,
  6366. IN ULONG FromIndex,
  6367. IN PULONG StartingRunIndex
  6368. );
  6369. NTSYSAPI
  6370. ULONG
  6371. NTAPI
  6372. RtlFindLastBackwardRunClear (
  6373. IN PRTL_BITMAP BitMapHeader,
  6374. IN ULONG FromIndex,
  6375. IN PULONG StartingRunIndex
  6376. );
  6377. //
  6378. // The following two procedures return to the caller a value indicating
  6379. // the position within a ULONGLONG of the most or least significant non-zero
  6380. // bit. A value of zero results in a return value of -1.
  6381. //
  6382. NTSYSAPI
  6383. CCHAR
  6384. NTAPI
  6385. RtlFindLeastSignificantBit (
  6386. IN ULONGLONG Set
  6387. );
  6388. NTSYSAPI
  6389. CCHAR
  6390. NTAPI
  6391. RtlFindMostSignificantBit (
  6392. IN ULONGLONG Set
  6393. );
  6394. //
  6395. // Security ID RTL routine definitions
  6396. //
  6397. NTSYSAPI
  6398. BOOLEAN
  6399. NTAPI
  6400. RtlValidSid (
  6401. PSID Sid
  6402. );
  6403. NTSYSAPI
  6404. BOOLEAN
  6405. NTAPI
  6406. RtlEqualSid (
  6407. PSID Sid1,
  6408. PSID Sid2
  6409. );
  6410. NTSYSAPI
  6411. BOOLEAN
  6412. NTAPI
  6413. RtlEqualPrefixSid (
  6414. PSID Sid1,
  6415. PSID Sid2
  6416. );
  6417. NTSYSAPI
  6418. ULONG
  6419. NTAPI
  6420. RtlLengthRequiredSid (
  6421. ULONG SubAuthorityCount
  6422. );
  6423. NTSYSAPI
  6424. PVOID
  6425. NTAPI
  6426. RtlFreeSid(
  6427. IN PSID Sid
  6428. );
  6429. NTSYSAPI
  6430. NTSTATUS
  6431. NTAPI
  6432. RtlAllocateAndInitializeSid(
  6433. IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
  6434. IN UCHAR SubAuthorityCount,
  6435. IN ULONG SubAuthority0,
  6436. IN ULONG SubAuthority1,
  6437. IN ULONG SubAuthority2,
  6438. IN ULONG SubAuthority3,
  6439. IN ULONG SubAuthority4,
  6440. IN ULONG SubAuthority5,
  6441. IN ULONG SubAuthority6,
  6442. IN ULONG SubAuthority7,
  6443. OUT PSID *Sid
  6444. );
  6445. NTSYSAPI // ntifs
  6446. NTSTATUS // ntifs
  6447. NTAPI // ntifs
  6448. RtlInitializeSid ( // ntifs
  6449. PSID Sid, // ntifs
  6450. PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, // ntifs
  6451. UCHAR SubAuthorityCount // ntifs
  6452. ); // ntifs
  6453. NTSYSAPI
  6454. PSID_IDENTIFIER_AUTHORITY
  6455. NTAPI
  6456. RtlIdentifierAuthoritySid (
  6457. PSID Sid
  6458. );
  6459. NTSYSAPI // ntifs
  6460. PULONG // ntifs
  6461. NTAPI // ntifs
  6462. RtlSubAuthoritySid ( // ntifs
  6463. PSID Sid, // ntifs
  6464. ULONG SubAuthority // ntifs
  6465. ); // ntifs
  6466. NTSYSAPI
  6467. PUCHAR
  6468. NTAPI
  6469. RtlSubAuthorityCountSid (
  6470. PSID Sid
  6471. );
  6472. // begin_ntifs
  6473. NTSYSAPI
  6474. ULONG
  6475. NTAPI
  6476. RtlLengthSid (
  6477. PSID Sid
  6478. );
  6479. NTSYSAPI
  6480. NTSTATUS
  6481. NTAPI
  6482. RtlCopySid (
  6483. ULONG DestinationSidLength,
  6484. PSID DestinationSid,
  6485. PSID SourceSid
  6486. );
  6487. //
  6488. // BOOLEAN
  6489. // RtlEqualLuid(
  6490. // PLUID L1,
  6491. // PLUID L2
  6492. // );
  6493. #define RtlEqualLuid(L1, L2) (((L1)->LowPart == (L2)->LowPart) && \
  6494. ((L1)->HighPart == (L2)->HighPart))
  6495. //
  6496. // BOOLEAN
  6497. // RtlIsZeroLuid(
  6498. // PLUID L1
  6499. // );
  6500. //
  6501. #define RtlIsZeroLuid(L1) ((BOOLEAN) (((L1)->LowPart | (L1)->HighPart) == 0))
  6502. #if !defined(MIDL_PASS)
  6503. FORCEINLINE LUID
  6504. NTAPI
  6505. RtlConvertLongToLuid(
  6506. LONG Long
  6507. )
  6508. {
  6509. LUID TempLuid;
  6510. LARGE_INTEGER TempLi;
  6511. TempLi.QuadPart = Long;
  6512. TempLuid.LowPart = TempLi.LowPart;
  6513. TempLuid.HighPart = TempLi.HighPart;
  6514. return(TempLuid);
  6515. }
  6516. FORCEINLINE
  6517. LUID
  6518. NTAPI
  6519. RtlConvertUlongToLuid(
  6520. ULONG Ulong
  6521. )
  6522. {
  6523. LUID TempLuid;
  6524. TempLuid.LowPart = Ulong;
  6525. TempLuid.HighPart = 0;
  6526. return(TempLuid);
  6527. }
  6528. #endif
  6529. // end_ntddk
  6530. NTSYSAPI
  6531. VOID
  6532. NTAPI
  6533. RtlCopyLuid (
  6534. PLUID DestinationLuid,
  6535. PLUID SourceLuid
  6536. );
  6537. NTSYSAPI
  6538. VOID
  6539. NTAPI
  6540. RtlMapGenericMask(
  6541. PACCESS_MASK AccessMask,
  6542. PGENERIC_MAPPING GenericMapping
  6543. );
  6544. NTSYSAPI
  6545. NTSTATUS
  6546. NTAPI
  6547. RtlCreateAcl (
  6548. PACL Acl,
  6549. ULONG AclLength,
  6550. ULONG AclRevision
  6551. );
  6552. NTSYSAPI
  6553. NTSTATUS
  6554. NTAPI
  6555. RtlGetAce (
  6556. PACL Acl,
  6557. ULONG AceIndex,
  6558. PVOID *Ace
  6559. );
  6560. NTSYSAPI
  6561. NTSTATUS
  6562. NTAPI
  6563. RtlAddAccessAllowedAce (
  6564. PACL Acl,
  6565. ULONG AceRevision,
  6566. ACCESS_MASK AccessMask,
  6567. PSID Sid
  6568. );
  6569. //
  6570. // SecurityDescriptor RTL routine definitions
  6571. //
  6572. NTSYSAPI
  6573. NTSTATUS
  6574. NTAPI
  6575. RtlCreateSecurityDescriptor (
  6576. PSECURITY_DESCRIPTOR SecurityDescriptor,
  6577. ULONG Revision
  6578. );
  6579. // end_wdm end_ntddk
  6580. NTSYSAPI
  6581. NTSTATUS
  6582. NTAPI
  6583. RtlCreateSecurityDescriptorRelative (
  6584. PISECURITY_DESCRIPTOR_RELATIVE SecurityDescriptor,
  6585. ULONG Revision
  6586. );
  6587. // begin_wdm begin_ntddk
  6588. NTSYSAPI
  6589. BOOLEAN
  6590. NTAPI
  6591. RtlValidSecurityDescriptor (
  6592. PSECURITY_DESCRIPTOR SecurityDescriptor
  6593. );
  6594. NTSYSAPI
  6595. ULONG
  6596. NTAPI
  6597. RtlLengthSecurityDescriptor (
  6598. PSECURITY_DESCRIPTOR SecurityDescriptor
  6599. );
  6600. NTSYSAPI
  6601. BOOLEAN
  6602. NTAPI
  6603. RtlValidRelativeSecurityDescriptor (
  6604. IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
  6605. IN ULONG SecurityDescriptorLength,
  6606. IN SECURITY_INFORMATION RequiredInformation
  6607. );
  6608. NTSYSAPI
  6609. NTSTATUS
  6610. NTAPI
  6611. RtlSetDaclSecurityDescriptor (
  6612. PSECURITY_DESCRIPTOR SecurityDescriptor,
  6613. BOOLEAN DaclPresent,
  6614. PACL Dacl,
  6615. BOOLEAN DaclDefaulted
  6616. );
  6617. // end_wdm end_ntddk
  6618. NTSYSAPI
  6619. NTSTATUS
  6620. NTAPI
  6621. RtlGetDaclSecurityDescriptor (
  6622. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  6623. OUT PBOOLEAN DaclPresent,
  6624. OUT PACL *Dacl,
  6625. OUT PBOOLEAN DaclDefaulted
  6626. );
  6627. NTSYSAPI
  6628. NTSTATUS
  6629. NTAPI
  6630. RtlSetOwnerSecurityDescriptor (
  6631. PSECURITY_DESCRIPTOR SecurityDescriptor,
  6632. PSID Owner,
  6633. BOOLEAN OwnerDefaulted
  6634. );
  6635. NTSYSAPI
  6636. NTSTATUS
  6637. NTAPI
  6638. RtlGetOwnerSecurityDescriptor (
  6639. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  6640. OUT PSID *Owner,
  6641. OUT PBOOLEAN OwnerDefaulted
  6642. );
  6643. NTSYSAPI
  6644. ULONG
  6645. NTAPI
  6646. RtlNtStatusToDosError (
  6647. NTSTATUS Status
  6648. );
  6649. NTSYSAPI
  6650. ULONG
  6651. NTAPI
  6652. RtlNtStatusToDosErrorNoTeb (
  6653. NTSTATUS Status
  6654. );
  6655. NTSYSAPI
  6656. NTSTATUS
  6657. NTAPI
  6658. RtlCustomCPToUnicodeN(
  6659. IN PCPTABLEINFO CustomCP,
  6660. OUT PWCH UnicodeString,
  6661. IN ULONG MaxBytesInUnicodeString,
  6662. OUT PULONG BytesInUnicodeString OPTIONAL,
  6663. IN PCH CustomCPString,
  6664. IN ULONG BytesInCustomCPString
  6665. );
  6666. NTSYSAPI
  6667. NTSTATUS
  6668. NTAPI
  6669. RtlUnicodeToCustomCPN(
  6670. IN PCPTABLEINFO CustomCP,
  6671. OUT PCH CustomCPString,
  6672. IN ULONG MaxBytesInCustomCPString,
  6673. OUT PULONG BytesInCustomCPString OPTIONAL,
  6674. IN PWCH UnicodeString,
  6675. IN ULONG BytesInUnicodeString
  6676. );
  6677. NTSYSAPI
  6678. NTSTATUS
  6679. NTAPI
  6680. RtlUpcaseUnicodeToCustomCPN(
  6681. IN PCPTABLEINFO CustomCP,
  6682. OUT PCH CustomCPString,
  6683. IN ULONG MaxBytesInCustomCPString,
  6684. OUT PULONG BytesInCustomCPString OPTIONAL,
  6685. IN PWCH UnicodeString,
  6686. IN ULONG BytesInUnicodeString
  6687. );
  6688. NTSYSAPI
  6689. VOID
  6690. NTAPI
  6691. RtlInitCodePageTable(
  6692. IN PUSHORT TableBase,
  6693. OUT PCPTABLEINFO CodePageTable
  6694. );
  6695. //
  6696. // Routine for converting from a volume device object to a DOS name.
  6697. //
  6698. NTSYSAPI
  6699. NTSTATUS
  6700. NTAPI
  6701. RtlVolumeDeviceToDosName(
  6702. IN PVOID VolumeDeviceObject,
  6703. OUT PUNICODE_STRING DosName
  6704. );
  6705. //
  6706. // Routine for verifying or creating the "System Volume Information"
  6707. // folder on NTFS volumes.
  6708. //
  6709. NTSYSAPI
  6710. NTSTATUS
  6711. NTAPI
  6712. RtlCreateSystemVolumeInformationFolder(
  6713. IN PUNICODE_STRING VolumeRootPath
  6714. );
  6715. #define RTL_SYSTEM_VOLUME_INFORMATION_FOLDER L"System Volume Information"
  6716. typedef struct _OSVERSIONINFOA {
  6717. ULONG dwOSVersionInfoSize;
  6718. ULONG dwMajorVersion;
  6719. ULONG dwMinorVersion;
  6720. ULONG dwBuildNumber;
  6721. ULONG dwPlatformId;
  6722. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6723. } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
  6724. typedef struct _OSVERSIONINFOW {
  6725. ULONG dwOSVersionInfoSize;
  6726. ULONG dwMajorVersion;
  6727. ULONG dwMinorVersion;
  6728. ULONG dwBuildNumber;
  6729. ULONG dwPlatformId;
  6730. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6731. } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;
  6732. #ifdef UNICODE
  6733. typedef OSVERSIONINFOW OSVERSIONINFO;
  6734. typedef POSVERSIONINFOW POSVERSIONINFO;
  6735. typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
  6736. #else
  6737. typedef OSVERSIONINFOA OSVERSIONINFO;
  6738. typedef POSVERSIONINFOA POSVERSIONINFO;
  6739. typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
  6740. #endif // UNICODE
  6741. typedef struct _OSVERSIONINFOEXA {
  6742. ULONG dwOSVersionInfoSize;
  6743. ULONG dwMajorVersion;
  6744. ULONG dwMinorVersion;
  6745. ULONG dwBuildNumber;
  6746. ULONG dwPlatformId;
  6747. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6748. USHORT wServicePackMajor;
  6749. USHORT wServicePackMinor;
  6750. USHORT wSuiteMask;
  6751. UCHAR wProductType;
  6752. UCHAR wReserved;
  6753. } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
  6754. typedef struct _OSVERSIONINFOEXW {
  6755. ULONG dwOSVersionInfoSize;
  6756. ULONG dwMajorVersion;
  6757. ULONG dwMinorVersion;
  6758. ULONG dwBuildNumber;
  6759. ULONG dwPlatformId;
  6760. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6761. USHORT wServicePackMajor;
  6762. USHORT wServicePackMinor;
  6763. USHORT wSuiteMask;
  6764. UCHAR wProductType;
  6765. UCHAR wReserved;
  6766. } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW, RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
  6767. #ifdef UNICODE
  6768. typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
  6769. typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
  6770. typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
  6771. #else
  6772. typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
  6773. typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
  6774. typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
  6775. #endif // UNICODE
  6776. //
  6777. // RtlVerifyVersionInfo() conditions
  6778. //
  6779. #define VER_EQUAL 1
  6780. #define VER_GREATER 2
  6781. #define VER_GREATER_EQUAL 3
  6782. #define VER_LESS 4
  6783. #define VER_LESS_EQUAL 5
  6784. #define VER_AND 6
  6785. #define VER_OR 7
  6786. #define VER_CONDITION_MASK 7
  6787. #define VER_NUM_BITS_PER_CONDITION_MASK 3
  6788. //
  6789. // RtlVerifyVersionInfo() type mask bits
  6790. //
  6791. #define VER_MINORVERSION 0x0000001
  6792. #define VER_MAJORVERSION 0x0000002
  6793. #define VER_BUILDNUMBER 0x0000004
  6794. #define VER_PLATFORMID 0x0000008
  6795. #define VER_SERVICEPACKMINOR 0x0000010
  6796. #define VER_SERVICEPACKMAJOR 0x0000020
  6797. #define VER_SUITENAME 0x0000040
  6798. #define VER_PRODUCT_TYPE 0x0000080
  6799. //
  6800. // RtlVerifyVersionInfo() os product type values
  6801. //
  6802. #define VER_NT_WORKSTATION 0x0000001
  6803. #define VER_NT_DOMAIN_CONTROLLER 0x0000002
  6804. #define VER_NT_SERVER 0x0000003
  6805. //
  6806. // dwPlatformId defines:
  6807. //
  6808. #define VER_PLATFORM_WIN32s 0
  6809. #define VER_PLATFORM_WIN32_WINDOWS 1
  6810. #define VER_PLATFORM_WIN32_NT 2
  6811. //
  6812. //
  6813. // VerifyVersionInfo() macro to set the condition mask
  6814. //
  6815. // For documentation sakes here's the old version of the macro that got
  6816. // changed to call an API
  6817. // #define VER_SET_CONDITION(_m_,_t_,_c_) _m_=(_m_|(_c_<<(1<<_t_)))
  6818. //
  6819. #define VER_SET_CONDITION(_m_,_t_,_c_) \
  6820. ((_m_)=VerSetConditionMask((_m_),(_t_),(_c_)))
  6821. ULONGLONG
  6822. NTAPI
  6823. VerSetConditionMask(
  6824. IN ULONGLONG ConditionMask,
  6825. IN ULONG TypeMask,
  6826. IN UCHAR Condition
  6827. );
  6828. //
  6829. // end_winnt
  6830. //
  6831. NTSYSAPI
  6832. NTSTATUS
  6833. RtlGetVersion(
  6834. OUT PRTL_OSVERSIONINFOW lpVersionInformation
  6835. );
  6836. NTSYSAPI
  6837. NTSTATUS
  6838. RtlVerifyVersionInfo(
  6839. IN PRTL_OSVERSIONINFOEXW VersionInfo,
  6840. IN ULONG TypeMask,
  6841. IN ULONGLONG ConditionMask
  6842. );
  6843. //
  6844. //
  6845. // Interlocked bit manipulation interfaces
  6846. //
  6847. #define RtlInterlockedSetBits(Flags, Flag) \
  6848. InterlockedOr((PLONG)(Flags), Flag)
  6849. #define RtlInterlockedAndBits(Flags, Flag) \
  6850. InterlockedAnd((PLONG)(Flags), Flag)
  6851. #define RtlInterlockedClearBits(Flags, Flag) \
  6852. RtlInterlockedAndBits(Flags, ~(Flag))
  6853. #define RtlInterlockedXorBits(Flags, Flag) \
  6854. InterlockedXor(Flags, Flag)
  6855. #define RtlInterlockedSetBitsDiscardReturn(Flags, Flag) \
  6856. (VOID) RtlInterlockedSetBits(Flags, Flag)
  6857. #define RtlInterlockedAndBitsDiscardReturn(Flags, Flag) \
  6858. (VOID) RtlInterlockedAndBits(Flags, Flag)
  6859. #define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
  6860. RtlInterlockedAndBitsDiscardReturn(Flags, ~(Flag))
  6861. //
  6862. // Component name filter id enumeration and levels.
  6863. //
  6864. #define DPFLTR_ERROR_LEVEL 0
  6865. #define DPFLTR_WARNING_LEVEL 1
  6866. #define DPFLTR_TRACE_LEVEL 2
  6867. #define DPFLTR_INFO_LEVEL 3
  6868. #define DPFLTR_MASK 0x80000000
  6869. typedef enum _DPFLTR_TYPE {
  6870. DPFLTR_SYSTEM_ID = 0,
  6871. DPFLTR_SMSS_ID = 1,
  6872. DPFLTR_SETUP_ID = 2,
  6873. DPFLTR_NTFS_ID = 3,
  6874. DPFLTR_FSTUB_ID = 4,
  6875. DPFLTR_CRASHDUMP_ID = 5,
  6876. DPFLTR_CDAUDIO_ID = 6,
  6877. DPFLTR_CDROM_ID = 7,
  6878. DPFLTR_CLASSPNP_ID = 8,
  6879. DPFLTR_DISK_ID = 9,
  6880. DPFLTR_REDBOOK_ID = 10,
  6881. DPFLTR_STORPROP_ID = 11,
  6882. DPFLTR_SCSIPORT_ID = 12,
  6883. DPFLTR_SCSIMINIPORT_ID = 13,
  6884. DPFLTR_CONFIG_ID = 14,
  6885. DPFLTR_I8042PRT_ID = 15,
  6886. DPFLTR_SERMOUSE_ID = 16,
  6887. DPFLTR_LSERMOUS_ID = 17,
  6888. DPFLTR_KBDHID_ID = 18,
  6889. DPFLTR_MOUHID_ID = 19,
  6890. DPFLTR_KBDCLASS_ID = 20,
  6891. DPFLTR_MOUCLASS_ID = 21,
  6892. DPFLTR_TWOTRACK_ID = 22,
  6893. DPFLTR_WMILIB_ID = 23,
  6894. DPFLTR_ACPI_ID = 24,
  6895. DPFLTR_AMLI_ID = 25,
  6896. DPFLTR_HALIA64_ID = 26,
  6897. DPFLTR_VIDEO_ID = 27,
  6898. DPFLTR_SVCHOST_ID = 28,
  6899. DPFLTR_VIDEOPRT_ID = 29,
  6900. DPFLTR_TCPIP_ID = 30,
  6901. DPFLTR_DMSYNTH_ID = 31,
  6902. DPFLTR_NTOSPNP_ID = 32,
  6903. DPFLTR_FASTFAT_ID = 33,
  6904. DPFLTR_SAMSS_ID = 34,
  6905. DPFLTR_PNPMGR_ID = 35,
  6906. DPFLTR_NETAPI_ID = 36,
  6907. DPFLTR_SCSERVER_ID = 37,
  6908. DPFLTR_SCCLIENT_ID = 38,
  6909. DPFLTR_SERIAL_ID = 39,
  6910. DPFLTR_SERENUM_ID = 40,
  6911. DPFLTR_UHCD_ID = 41,
  6912. DPFLTR_RPCPROXY_ID = 42,
  6913. DPFLTR_AUTOCHK_ID = 43,
  6914. DPFLTR_DCOMSS_ID = 44,
  6915. DPFLTR_UNIMODEM_ID = 45,
  6916. DPFLTR_SIS_ID = 46,
  6917. DPFLTR_FLTMGR_ID = 47,
  6918. DPFLTR_WMICORE_ID = 48,
  6919. DPFLTR_BURNENG_ID = 49,
  6920. DPFLTR_IMAPI_ID = 50,
  6921. DPFLTR_SXS_ID = 51,
  6922. DPFLTR_FUSION_ID = 52,
  6923. DPFLTR_IDLETASK_ID = 53,
  6924. DPFLTR_SOFTPCI_ID = 54,
  6925. DPFLTR_TAPE_ID = 55,
  6926. DPFLTR_MCHGR_ID = 56,
  6927. DPFLTR_IDEP_ID = 57,
  6928. DPFLTR_PCIIDE_ID = 58,
  6929. DPFLTR_FLOPPY_ID = 59,
  6930. DPFLTR_FDC_ID = 60,
  6931. DPFLTR_TERMSRV_ID = 61,
  6932. DPFLTR_W32TIME_ID = 62,
  6933. DPFLTR_PREFETCHER_ID = 63,
  6934. DPFLTR_RSFILTER_ID = 64,
  6935. DPFLTR_FCPORT_ID = 65,
  6936. DPFLTR_PCI_ID = 66,
  6937. DPFLTR_DMIO_ID = 67,
  6938. DPFLTR_DMCONFIG_ID = 68,
  6939. DPFLTR_DMADMIN_ID = 69,
  6940. DPFLTR_WSOCKTRANSPORT_ID = 70,
  6941. DPFLTR_VSS_ID = 71,
  6942. DPFLTR_PNPMEM_ID = 72,
  6943. DPFLTR_PROCESSOR_ID = 73,
  6944. DPFLTR_DMSERVER_ID = 74,
  6945. DPFLTR_SR_ID = 75,
  6946. DPFLTR_INFINIBAND_ID = 76,
  6947. DPFLTR_IHVDRIVER_ID = 77,
  6948. DPFLTR_IHVVIDEO_ID = 78,
  6949. DPFLTR_IHVAUDIO_ID = 79,
  6950. DPFLTR_IHVNETWORK_ID = 80,
  6951. DPFLTR_IHVSTREAMING_ID = 81,
  6952. DPFLTR_IHVBUS_ID = 82,
  6953. DPFLTR_HPS_ID = 83,
  6954. DPFLTR_RTLTHREADPOOL_ID = 84,
  6955. DPFLTR_LDR_ID = 85,
  6956. DPFLTR_TCPIP6_ID = 86,
  6957. DPFLTR_ISAPNP_ID = 87,
  6958. DPFLTR_SHPC_ID = 88,
  6959. DPFLTR_STORPORT_ID = 89,
  6960. DPFLTR_STORMINIPORT_ID = 90,
  6961. DPFLTR_PRINTSPOOLER_ID = 91,
  6962. DPFLTR_VSSDYNDISK_ID = 92,
  6963. DPFLTR_VERIFIER_ID = 93,
  6964. DPFLTR_VDS_ID = 94,
  6965. DPFLTR_VDSBAS_ID = 95,
  6966. DPFLTR_VDSDYNDR_ID = 96,
  6967. DPFLTR_VDSUTIL_ID = 97,
  6968. DPFLTR_DFRGIFC_ID = 98,
  6969. DPFLTR_ENDOFTABLE_ID
  6970. } DPFLTR_TYPE;
  6971. #ifndef _PO_DDK_
  6972. #define _PO_DDK_
  6973. // begin_winnt
  6974. typedef enum _SYSTEM_POWER_STATE {
  6975. PowerSystemUnspecified = 0,
  6976. PowerSystemWorking = 1,
  6977. PowerSystemSleeping1 = 2,
  6978. PowerSystemSleeping2 = 3,
  6979. PowerSystemSleeping3 = 4,
  6980. PowerSystemHibernate = 5,
  6981. PowerSystemShutdown = 6,
  6982. PowerSystemMaximum = 7
  6983. } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
  6984. #define POWER_SYSTEM_MAXIMUM 7
  6985. typedef enum {
  6986. PowerActionNone = 0,
  6987. PowerActionReserved,
  6988. PowerActionSleep,
  6989. PowerActionHibernate,
  6990. PowerActionShutdown,
  6991. PowerActionShutdownReset,
  6992. PowerActionShutdownOff,
  6993. PowerActionWarmEject
  6994. } POWER_ACTION, *PPOWER_ACTION;
  6995. typedef enum _DEVICE_POWER_STATE {
  6996. PowerDeviceUnspecified = 0,
  6997. PowerDeviceD0,
  6998. PowerDeviceD1,
  6999. PowerDeviceD2,
  7000. PowerDeviceD3,
  7001. PowerDeviceMaximum
  7002. } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
  7003. // end_winnt
  7004. typedef union _POWER_STATE {
  7005. SYSTEM_POWER_STATE SystemState;
  7006. DEVICE_POWER_STATE DeviceState;
  7007. } POWER_STATE, *PPOWER_STATE;
  7008. typedef enum _POWER_STATE_TYPE {
  7009. SystemPowerState = 0,
  7010. DevicePowerState
  7011. } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
  7012. //
  7013. // Generic power related IOCTLs
  7014. //
  7015. #define IOCTL_QUERY_DEVICE_POWER_STATE \
  7016. CTL_CODE(FILE_DEVICE_BATTERY, 0x0, METHOD_BUFFERED, FILE_READ_ACCESS)
  7017. #define IOCTL_SET_DEVICE_WAKE \
  7018. CTL_CODE(FILE_DEVICE_BATTERY, 0x1, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  7019. #define IOCTL_CANCEL_DEVICE_WAKE \
  7020. CTL_CODE(FILE_DEVICE_BATTERY, 0x2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  7021. //
  7022. // Defines for W32 interfaces
  7023. //
  7024. // begin_winnt
  7025. #define ES_SYSTEM_REQUIRED ((ULONG)0x00000001)
  7026. #define ES_DISPLAY_REQUIRED ((ULONG)0x00000002)
  7027. #define ES_USER_PRESENT ((ULONG)0x00000004)
  7028. #define ES_CONTINUOUS ((ULONG)0x80000000)
  7029. typedef ULONG EXECUTION_STATE;
  7030. typedef enum {
  7031. LT_DONT_CARE,
  7032. LT_LOWEST_LATENCY
  7033. } LATENCY_TIME;
  7034. #endif // !_PO_DDK_
  7035. //
  7036. // Define the various device type values. Note that values used by Microsoft
  7037. // Corporation are in the range 0-32767, and 32768-65535 are reserved for use
  7038. // by customers.
  7039. //
  7040. #define DEVICE_TYPE ULONG
  7041. #define FILE_DEVICE_BEEP 0x00000001
  7042. #define FILE_DEVICE_CD_ROM 0x00000002
  7043. #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
  7044. #define FILE_DEVICE_CONTROLLER 0x00000004
  7045. #define FILE_DEVICE_DATALINK 0x00000005
  7046. #define FILE_DEVICE_DFS 0x00000006
  7047. #define FILE_DEVICE_DISK 0x00000007
  7048. #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
  7049. #define FILE_DEVICE_FILE_SYSTEM 0x00000009
  7050. #define FILE_DEVICE_INPORT_PORT 0x0000000a
  7051. #define FILE_DEVICE_KEYBOARD 0x0000000b
  7052. #define FILE_DEVICE_MAILSLOT 0x0000000c
  7053. #define FILE_DEVICE_MIDI_IN 0x0000000d
  7054. #define FILE_DEVICE_MIDI_OUT 0x0000000e
  7055. #define FILE_DEVICE_MOUSE 0x0000000f
  7056. #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
  7057. #define FILE_DEVICE_NAMED_PIPE 0x00000011
  7058. #define FILE_DEVICE_NETWORK 0x00000012
  7059. #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
  7060. #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
  7061. #define FILE_DEVICE_NULL 0x00000015
  7062. #define FILE_DEVICE_PARALLEL_PORT 0x00000016
  7063. #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
  7064. #define FILE_DEVICE_PRINTER 0x00000018
  7065. #define FILE_DEVICE_SCANNER 0x00000019
  7066. #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
  7067. #define FILE_DEVICE_SERIAL_PORT 0x0000001b
  7068. #define FILE_DEVICE_SCREEN 0x0000001c
  7069. #define FILE_DEVICE_SOUND 0x0000001d
  7070. #define FILE_DEVICE_STREAMS 0x0000001e
  7071. #define FILE_DEVICE_TAPE 0x0000001f
  7072. #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
  7073. #define FILE_DEVICE_TRANSPORT 0x00000021
  7074. #define FILE_DEVICE_UNKNOWN 0x00000022
  7075. #define FILE_DEVICE_VIDEO 0x00000023
  7076. #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
  7077. #define FILE_DEVICE_WAVE_IN 0x00000025
  7078. #define FILE_DEVICE_WAVE_OUT 0x00000026
  7079. #define FILE_DEVICE_8042_PORT 0x00000027
  7080. #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
  7081. #define FILE_DEVICE_BATTERY 0x00000029
  7082. #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
  7083. #define FILE_DEVICE_MODEM 0x0000002b
  7084. #define FILE_DEVICE_VDM 0x0000002c
  7085. #define FILE_DEVICE_MASS_STORAGE 0x0000002d
  7086. #define FILE_DEVICE_SMB 0x0000002e
  7087. #define FILE_DEVICE_KS 0x0000002f
  7088. #define FILE_DEVICE_CHANGER 0x00000030
  7089. #define FILE_DEVICE_SMARTCARD 0x00000031
  7090. #define FILE_DEVICE_ACPI 0x00000032
  7091. #define FILE_DEVICE_DVD 0x00000033
  7092. #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
  7093. #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
  7094. #define FILE_DEVICE_DFS_VOLUME 0x00000036
  7095. #define FILE_DEVICE_SERENUM 0x00000037
  7096. #define FILE_DEVICE_TERMSRV 0x00000038
  7097. #define FILE_DEVICE_KSEC 0x00000039
  7098. #define FILE_DEVICE_FIPS 0x0000003A
  7099. #define FILE_DEVICE_INFINIBAND 0x0000003B
  7100. //
  7101. // Macro definition for defining IOCTL and FSCTL function control codes. Note
  7102. // that function codes 0-2047 are reserved for Microsoft Corporation, and
  7103. // 2048-4095 are reserved for customers.
  7104. //
  7105. #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
  7106. ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  7107. )
  7108. //
  7109. // Macro to extract device type out of the device io control code
  7110. //
  7111. #define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0xffff0000)) >> 16)
  7112. //
  7113. // Define the method codes for how buffers are passed for I/O and FS controls
  7114. //
  7115. #define METHOD_BUFFERED 0
  7116. #define METHOD_IN_DIRECT 1
  7117. #define METHOD_OUT_DIRECT 2
  7118. #define METHOD_NEITHER 3
  7119. //
  7120. // Define some easier to comprehend aliases:
  7121. // METHOD_DIRECT_TO_HARDWARE (writes, aka METHOD_IN_DIRECT)
  7122. // METHOD_DIRECT_FROM_HARDWARE (reads, aka METHOD_OUT_DIRECT)
  7123. //
  7124. #define METHOD_DIRECT_TO_HARDWARE METHOD_IN_DIRECT
  7125. #define METHOD_DIRECT_FROM_HARDWARE METHOD_OUT_DIRECT
  7126. //
  7127. // Define the access check value for any access
  7128. //
  7129. //
  7130. // The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
  7131. // ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
  7132. // constants *MUST* always be in sync.
  7133. //
  7134. //
  7135. // FILE_SPECIAL_ACCESS is checked by the NT I/O system the same as FILE_ANY_ACCESS.
  7136. // The file systems, however, may add additional access checks for I/O and FS controls
  7137. // that use this value.
  7138. //
  7139. #define FILE_ANY_ACCESS 0
  7140. #define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
  7141. #define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
  7142. #define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
  7143. #define PROCESS_DUP_HANDLE (0x0040) // winnt
  7144. #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  7145. 0xFFF)
  7146. // begin_nthal
  7147. #if defined(_WIN64)
  7148. #define MAXIMUM_PROCESSORS 64
  7149. #else
  7150. #define MAXIMUM_PROCESSORS 32
  7151. #endif
  7152. // end_nthal
  7153. // end_winnt
  7154. //
  7155. // Thread Specific Access Rights
  7156. //
  7157. #define THREAD_TERMINATE (0x0001) // winnt
  7158. #define THREAD_SET_INFORMATION (0x0020) // winnt
  7159. #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  7160. 0x3FF)
  7161. //
  7162. // ClientId
  7163. //
  7164. typedef struct _CLIENT_ID {
  7165. HANDLE UniqueProcess;
  7166. HANDLE UniqueThread;
  7167. } CLIENT_ID;
  7168. typedef CLIENT_ID *PCLIENT_ID;
  7169. //
  7170. // Thread Environment Block (and portable part of Thread Information Block)
  7171. //
  7172. //
  7173. // NT_TIB - Thread Information Block - Portable part.
  7174. //
  7175. // This is the subsystem portable part of the Thread Information Block.
  7176. // It appears as the first part of the TEB for all threads which have
  7177. // a user mode component.
  7178. //
  7179. //
  7180. // begin_winnt
  7181. typedef struct _NT_TIB {
  7182. struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
  7183. PVOID StackBase;
  7184. PVOID StackLimit;
  7185. PVOID SubSystemTib;
  7186. union {
  7187. PVOID FiberData;
  7188. ULONG Version;
  7189. };
  7190. PVOID ArbitraryUserPointer;
  7191. struct _NT_TIB *Self;
  7192. } NT_TIB;
  7193. typedef NT_TIB *PNT_TIB;
  7194. //
  7195. // 32 and 64 bit specific version for wow64 and the debugger
  7196. //
  7197. typedef struct _NT_TIB32 {
  7198. ULONG ExceptionList;
  7199. ULONG StackBase;
  7200. ULONG StackLimit;
  7201. ULONG SubSystemTib;
  7202. union {
  7203. ULONG FiberData;
  7204. ULONG Version;
  7205. };
  7206. ULONG ArbitraryUserPointer;
  7207. ULONG Self;
  7208. } NT_TIB32, *PNT_TIB32;
  7209. typedef struct _NT_TIB64 {
  7210. ULONG64 ExceptionList;
  7211. ULONG64 StackBase;
  7212. ULONG64 StackLimit;
  7213. ULONG64 SubSystemTib;
  7214. union {
  7215. ULONG64 FiberData;
  7216. ULONG Version;
  7217. };
  7218. ULONG64 ArbitraryUserPointer;
  7219. ULONG64 Self;
  7220. } NT_TIB64, *PNT_TIB64;
  7221. //
  7222. // Process Information Classes
  7223. //
  7224. typedef enum _PROCESSINFOCLASS {
  7225. ProcessBasicInformation,
  7226. ProcessQuotaLimits,
  7227. ProcessIoCounters,
  7228. ProcessVmCounters,
  7229. ProcessTimes,
  7230. ProcessBasePriority,
  7231. ProcessRaisePriority,
  7232. ProcessDebugPort,
  7233. ProcessExceptionPort,
  7234. ProcessAccessToken,
  7235. ProcessLdtInformation,
  7236. ProcessLdtSize,
  7237. ProcessDefaultHardErrorMode,
  7238. ProcessIoPortHandlers, // Note: this is kernel mode only
  7239. ProcessPooledUsageAndLimits,
  7240. ProcessWorkingSetWatch,
  7241. ProcessUserModeIOPL,
  7242. ProcessEnableAlignmentFaultFixup,
  7243. ProcessPriorityClass,
  7244. ProcessWx86Information,
  7245. ProcessHandleCount,
  7246. ProcessAffinityMask,
  7247. ProcessPriorityBoost,
  7248. ProcessDeviceMap,
  7249. ProcessSessionInformation,
  7250. ProcessForegroundInformation,
  7251. ProcessWow64Information,
  7252. ProcessImageFileName,
  7253. ProcessLUIDDeviceMapsEnabled,
  7254. ProcessBreakOnTermination,
  7255. ProcessDebugObjectHandle,
  7256. ProcessDebugFlags,
  7257. ProcessHandleTracing,
  7258. MaxProcessInfoClass // MaxProcessInfoClass should always be the last enum
  7259. } PROCESSINFOCLASS;
  7260. //
  7261. // Thread Information Classes
  7262. //
  7263. typedef enum _THREADINFOCLASS {
  7264. ThreadBasicInformation,
  7265. ThreadTimes,
  7266. ThreadPriority,
  7267. ThreadBasePriority,
  7268. ThreadAffinityMask,
  7269. ThreadImpersonationToken,
  7270. ThreadDescriptorTableEntry,
  7271. ThreadEnableAlignmentFaultFixup,
  7272. ThreadEventPair_Reusable,
  7273. ThreadQuerySetWin32StartAddress,
  7274. ThreadZeroTlsCell,
  7275. ThreadPerformanceCount,
  7276. ThreadAmILastThread,
  7277. ThreadIdealProcessor,
  7278. ThreadPriorityBoost,
  7279. ThreadSetTlsArrayAddress,
  7280. ThreadIsIoPending,
  7281. ThreadHideFromDebugger,
  7282. ThreadBreakOnTermination,
  7283. MaxThreadInfoClass
  7284. } THREADINFOCLASS;
  7285. //
  7286. // Process Information Structures
  7287. //
  7288. //
  7289. // PageFaultHistory Information
  7290. // NtQueryInformationProcess using ProcessWorkingSetWatch
  7291. //
  7292. typedef struct _PROCESS_WS_WATCH_INFORMATION {
  7293. PVOID FaultingPc;
  7294. PVOID FaultingVa;
  7295. } PROCESS_WS_WATCH_INFORMATION, *PPROCESS_WS_WATCH_INFORMATION;
  7296. //
  7297. // Basic Process Information
  7298. // NtQueryInformationProcess using ProcessBasicInfo
  7299. //
  7300. typedef struct _PROCESS_BASIC_INFORMATION {
  7301. NTSTATUS ExitStatus;
  7302. PPEB PebBaseAddress;
  7303. ULONG_PTR AffinityMask;
  7304. KPRIORITY BasePriority;
  7305. ULONG_PTR UniqueProcessId;
  7306. ULONG_PTR InheritedFromUniqueProcessId;
  7307. } PROCESS_BASIC_INFORMATION;
  7308. typedef PROCESS_BASIC_INFORMATION *PPROCESS_BASIC_INFORMATION;
  7309. //
  7310. // Process Device Map information
  7311. // NtQueryInformationProcess using ProcessDeviceMap
  7312. // NtSetInformationProcess using ProcessDeviceMap
  7313. //
  7314. typedef struct _PROCESS_DEVICEMAP_INFORMATION {
  7315. union {
  7316. struct {
  7317. HANDLE DirectoryHandle;
  7318. } Set;
  7319. struct {
  7320. ULONG DriveMap;
  7321. UCHAR DriveType[ 32 ];
  7322. } Query;
  7323. };
  7324. } PROCESS_DEVICEMAP_INFORMATION, *PPROCESS_DEVICEMAP_INFORMATION;
  7325. typedef struct _PROCESS_DEVICEMAP_INFORMATION_EX {
  7326. union {
  7327. struct {
  7328. HANDLE DirectoryHandle;
  7329. } Set;
  7330. struct {
  7331. ULONG DriveMap;
  7332. UCHAR DriveType[ 32 ];
  7333. } Query;
  7334. };
  7335. ULONG Flags; // specifies that the query type
  7336. } PROCESS_DEVICEMAP_INFORMATION_EX, *PPROCESS_DEVICEMAP_INFORMATION_EX;
  7337. //
  7338. // PROCESS_DEVICEMAP_INFORMATION_EX flags
  7339. //
  7340. #define PROCESS_LUID_DOSDEVICES_ONLY 0x00000001
  7341. //
  7342. // Multi-User Session specific Process Information
  7343. // NtQueryInformationProcess using ProcessSessionInformation
  7344. //
  7345. typedef struct _PROCESS_SESSION_INFORMATION {
  7346. ULONG SessionId;
  7347. } PROCESS_SESSION_INFORMATION, *PPROCESS_SESSION_INFORMATION;
  7348. typedef struct _PROCESS_HANDLE_TRACING_ENABLE {
  7349. ULONG Flags;
  7350. } PROCESS_HANDLE_TRACING_ENABLE, *PPROCESS_HANDLE_TRACING_ENABLE;
  7351. typedef struct _PROCESS_HANDLE_TRACING_ENABLE_EX {
  7352. ULONG Flags;
  7353. ULONG TotalSlots;
  7354. } PROCESS_HANDLE_TRACING_ENABLE_EX, *PPROCESS_HANDLE_TRACING_ENABLE_EX;
  7355. #define PROCESS_HANDLE_TRACING_MAX_STACKS 16
  7356. typedef struct _PROCESS_HANDLE_TRACING_ENTRY {
  7357. HANDLE Handle;
  7358. CLIENT_ID ClientId;
  7359. ULONG Type;
  7360. PVOID Stacks[PROCESS_HANDLE_TRACING_MAX_STACKS];
  7361. } PROCESS_HANDLE_TRACING_ENTRY, *PPROCESS_HANDLE_TRACING_ENTRY;
  7362. typedef struct _PROCESS_HANDLE_TRACING_QUERY {
  7363. HANDLE Handle;
  7364. ULONG TotalTraces;
  7365. PROCESS_HANDLE_TRACING_ENTRY HandleTrace[1];
  7366. } PROCESS_HANDLE_TRACING_QUERY, *PPROCESS_HANDLE_TRACING_QUERY;
  7367. //
  7368. // Process Quotas
  7369. // NtQueryInformationProcess using ProcessQuotaLimits
  7370. // NtQueryInformationProcess using ProcessPooledQuotaLimits
  7371. // NtSetInformationProcess using ProcessQuotaLimits
  7372. //
  7373. // begin_winnt
  7374. typedef struct _QUOTA_LIMITS {
  7375. SIZE_T PagedPoolLimit;
  7376. SIZE_T NonPagedPoolLimit;
  7377. SIZE_T MinimumWorkingSetSize;
  7378. SIZE_T MaximumWorkingSetSize;
  7379. SIZE_T PagefileLimit;
  7380. LARGE_INTEGER TimeLimit;
  7381. } QUOTA_LIMITS, *PQUOTA_LIMITS;
  7382. #define QUOTA_LIMITS_HARDWS_MIN_ENABLE 0x00000001
  7383. #define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002
  7384. #define QUOTA_LIMITS_HARDWS_MAX_ENABLE 0x00000004
  7385. #define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008
  7386. typedef struct _QUOTA_LIMITS_EX {
  7387. SIZE_T PagedPoolLimit;
  7388. SIZE_T NonPagedPoolLimit;
  7389. SIZE_T MinimumWorkingSetSize;
  7390. SIZE_T MaximumWorkingSetSize;
  7391. SIZE_T PagefileLimit;
  7392. LARGE_INTEGER TimeLimit;
  7393. SIZE_T Reserved1;
  7394. SIZE_T Reserved2;
  7395. SIZE_T Reserved3;
  7396. SIZE_T Reserved4;
  7397. ULONG Flags;
  7398. ULONG Reserved5;
  7399. } QUOTA_LIMITS_EX, *PQUOTA_LIMITS_EX;
  7400. // end_winnt
  7401. //
  7402. // Process I/O Counters
  7403. // NtQueryInformationProcess using ProcessIoCounters
  7404. //
  7405. // begin_winnt
  7406. typedef struct _IO_COUNTERS {
  7407. ULONGLONG ReadOperationCount;
  7408. ULONGLONG WriteOperationCount;
  7409. ULONGLONG OtherOperationCount;
  7410. ULONGLONG ReadTransferCount;
  7411. ULONGLONG WriteTransferCount;
  7412. ULONGLONG OtherTransferCount;
  7413. } IO_COUNTERS;
  7414. typedef IO_COUNTERS *PIO_COUNTERS;
  7415. // end_winnt
  7416. //
  7417. // Process Virtual Memory Counters
  7418. // NtQueryInformationProcess using ProcessVmCounters
  7419. //
  7420. typedef struct _VM_COUNTERS {
  7421. SIZE_T PeakVirtualSize;
  7422. SIZE_T VirtualSize;
  7423. ULONG PageFaultCount;
  7424. SIZE_T PeakWorkingSetSize;
  7425. SIZE_T WorkingSetSize;
  7426. SIZE_T QuotaPeakPagedPoolUsage;
  7427. SIZE_T QuotaPagedPoolUsage;
  7428. SIZE_T QuotaPeakNonPagedPoolUsage;
  7429. SIZE_T QuotaNonPagedPoolUsage;
  7430. SIZE_T PagefileUsage;
  7431. SIZE_T PeakPagefileUsage;
  7432. } VM_COUNTERS;
  7433. typedef VM_COUNTERS *PVM_COUNTERS;
  7434. typedef struct _VM_COUNTERS_EX {
  7435. SIZE_T PeakVirtualSize;
  7436. SIZE_T VirtualSize;
  7437. ULONG PageFaultCount;
  7438. SIZE_T PeakWorkingSetSize;
  7439. SIZE_T WorkingSetSize;
  7440. SIZE_T QuotaPeakPagedPoolUsage;
  7441. SIZE_T QuotaPagedPoolUsage;
  7442. SIZE_T QuotaPeakNonPagedPoolUsage;
  7443. SIZE_T QuotaNonPagedPoolUsage;
  7444. SIZE_T PagefileUsage;
  7445. SIZE_T PeakPagefileUsage;
  7446. SIZE_T PrivateUsage;
  7447. } VM_COUNTERS_EX;
  7448. typedef VM_COUNTERS_EX *PVM_COUNTERS_EX;
  7449. //
  7450. // Process Pooled Quota Usage and Limits
  7451. // NtQueryInformationProcess using ProcessPooledUsageAndLimits
  7452. //
  7453. typedef struct _POOLED_USAGE_AND_LIMITS {
  7454. SIZE_T PeakPagedPoolUsage;
  7455. SIZE_T PagedPoolUsage;
  7456. SIZE_T PagedPoolLimit;
  7457. SIZE_T PeakNonPagedPoolUsage;
  7458. SIZE_T NonPagedPoolUsage;
  7459. SIZE_T NonPagedPoolLimit;
  7460. SIZE_T PeakPagefileUsage;
  7461. SIZE_T PagefileUsage;
  7462. SIZE_T PagefileLimit;
  7463. } POOLED_USAGE_AND_LIMITS;
  7464. typedef POOLED_USAGE_AND_LIMITS *PPOOLED_USAGE_AND_LIMITS;
  7465. //
  7466. // Process Security Context Information
  7467. // NtSetInformationProcess using ProcessAccessToken
  7468. // PROCESS_SET_ACCESS_TOKEN access to the process is needed
  7469. // to use this info level.
  7470. //
  7471. typedef struct _PROCESS_ACCESS_TOKEN {
  7472. //
  7473. // Handle to Primary token to assign to the process.
  7474. // TOKEN_ASSIGN_PRIMARY access to this token is needed.
  7475. //
  7476. HANDLE Token;
  7477. //
  7478. // Handle to the initial thread of the process.
  7479. // A process's access token can only be changed if the process has
  7480. // no threads or one thread. If the process has no threads, this
  7481. // field must be set to NULL. Otherwise, it must contain a handle
  7482. // open to the process's only thread. THREAD_QUERY_INFORMATION access
  7483. // is needed via this handle.
  7484. HANDLE Thread;
  7485. } PROCESS_ACCESS_TOKEN, *PPROCESS_ACCESS_TOKEN;
  7486. //
  7487. // Process/Thread System and User Time
  7488. // NtQueryInformationProcess using ProcessTimes
  7489. // NtQueryInformationThread using ThreadTimes
  7490. //
  7491. typedef struct _KERNEL_USER_TIMES {
  7492. LARGE_INTEGER CreateTime;
  7493. LARGE_INTEGER ExitTime;
  7494. LARGE_INTEGER KernelTime;
  7495. LARGE_INTEGER UserTime;
  7496. } KERNEL_USER_TIMES;
  7497. typedef KERNEL_USER_TIMES *PKERNEL_USER_TIMES;
  7498. NTSYSCALLAPI
  7499. NTSTATUS
  7500. NTAPI
  7501. NtOpenProcess (
  7502. OUT PHANDLE ProcessHandle,
  7503. IN ACCESS_MASK DesiredAccess,
  7504. IN POBJECT_ATTRIBUTES ObjectAttributes,
  7505. IN PCLIENT_ID ClientId OPTIONAL
  7506. );
  7507. #define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
  7508. #define ZwCurrentProcess() NtCurrentProcess()
  7509. NTSYSCALLAPI
  7510. NTSTATUS
  7511. NTAPI
  7512. NtQueryInformationProcess(
  7513. IN HANDLE ProcessHandle,
  7514. IN PROCESSINFOCLASS ProcessInformationClass,
  7515. OUT PVOID ProcessInformation,
  7516. IN ULONG ProcessInformationLength,
  7517. OUT PULONG ReturnLength OPTIONAL
  7518. );
  7519. #define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
  7520. #define ZwCurrentThread() NtCurrentThread()
  7521. NTSYSCALLAPI
  7522. NTSTATUS
  7523. NTAPI
  7524. NtSetInformationThread(
  7525. IN HANDLE ThreadHandle,
  7526. IN THREADINFOCLASS ThreadInformationClass,
  7527. IN PVOID ThreadInformation,
  7528. IN ULONG ThreadInformationLength
  7529. );
  7530. //
  7531. // Security operation mode of the system is held in a control
  7532. // longword.
  7533. //
  7534. typedef ULONG LSA_OPERATIONAL_MODE, *PLSA_OPERATIONAL_MODE;
  7535. //
  7536. // Used by a logon process to indicate what type of logon is being
  7537. // requested.
  7538. //
  7539. typedef enum _SECURITY_LOGON_TYPE {
  7540. Interactive = 2, // Interactively logged on (locally or remotely)
  7541. Network, // Accessing system via network
  7542. Batch, // Started via a batch queue
  7543. Service, // Service started by service controller
  7544. Proxy, // Proxy logon
  7545. Unlock, // Unlock workstation
  7546. NetworkCleartext, // Network logon with cleartext credentials
  7547. NewCredentials, // Clone caller, new default credentials
  7548. RemoteInteractive, // Remote, yet interactive. Terminal server
  7549. CachedInteractive, // Try cached credentials without hitting the net.
  7550. CachedRemoteInteractive, // Same as RemoteInteractive, this is used internally for auditing purpose
  7551. CachedUnlock // Cached Unlock workstation
  7552. } SECURITY_LOGON_TYPE, *PSECURITY_LOGON_TYPE;
  7553. typedef UNICODE_STRING LSA_UNICODE_STRING, *PLSA_UNICODE_STRING;
  7554. typedef STRING LSA_STRING, *PLSA_STRING;
  7555. typedef OBJECT_ATTRIBUTES LSA_OBJECT_ATTRIBUTES, *PLSA_OBJECT_ATTRIBUTES;
  7556. NTSTATUS
  7557. NTAPI
  7558. LsaRegisterLogonProcess (
  7559. IN PLSA_STRING LogonProcessName,
  7560. OUT PHANDLE LsaHandle,
  7561. OUT PLSA_OPERATIONAL_MODE SecurityMode
  7562. );
  7563. NTSTATUS
  7564. NTAPI
  7565. LsaLogonUser (
  7566. IN HANDLE LsaHandle,
  7567. IN PLSA_STRING OriginName,
  7568. IN SECURITY_LOGON_TYPE LogonType,
  7569. IN ULONG AuthenticationPackage,
  7570. IN PVOID AuthenticationInformation,
  7571. IN ULONG AuthenticationInformationLength,
  7572. IN PTOKEN_GROUPS LocalGroups OPTIONAL,
  7573. IN PTOKEN_SOURCE SourceContext,
  7574. OUT PVOID *ProfileBuffer,
  7575. OUT PULONG ProfileBufferLength,
  7576. OUT PLUID LogonId,
  7577. OUT PHANDLE Token,
  7578. OUT PQUOTA_LIMITS Quotas,
  7579. OUT PNTSTATUS SubStatus
  7580. );
  7581. NTSTATUS
  7582. NTAPI
  7583. LsaFreeReturnBuffer (
  7584. IN PVOID Buffer
  7585. );
  7586. #ifndef _NTLSA_IFS_
  7587. #define _NTLSA_IFS_
  7588. #endif
  7589. /////////////////////////////////////////////////////////////////////////
  7590. // //
  7591. // Name of the MSV1_0 authentication package //
  7592. // //
  7593. /////////////////////////////////////////////////////////////////////////
  7594. #define MSV1_0_PACKAGE_NAME "MICROSOFT_AUTHENTICATION_PACKAGE_V1_0"
  7595. #define MSV1_0_PACKAGE_NAMEW L"MICROSOFT_AUTHENTICATION_PACKAGE_V1_0"
  7596. #define MSV1_0_PACKAGE_NAMEW_LENGTH sizeof(MSV1_0_PACKAGE_NAMEW) - sizeof(WCHAR)
  7597. //
  7598. // Location of MSV authentication package data
  7599. //
  7600. #define MSV1_0_SUBAUTHENTICATION_KEY "SYSTEM\\CurrentControlSet\\Control\\Lsa\\MSV1_0"
  7601. #define MSV1_0_SUBAUTHENTICATION_VALUE "Auth"
  7602. /////////////////////////////////////////////////////////////////////////
  7603. // //
  7604. // Widely used MSV1_0 data types //
  7605. // //
  7606. /////////////////////////////////////////////////////////////////////////
  7607. ///////////////////////////////////////////////////////////////////////////////
  7608. // //
  7609. // LOGON Related Data Structures
  7610. //
  7611. // //
  7612. ///////////////////////////////////////////////////////////////////////////////
  7613. //
  7614. // When a LsaLogonUser() call is dispatched to the MsV1_0 authentication
  7615. // package, the beginning of the AuthenticationInformation buffer is
  7616. // cast to a MSV1_0_LOGON_SUBMIT_TYPE to determine the type of logon
  7617. // being requested. Similarly, upon return, the type of profile buffer
  7618. // can be determined by typecasting it to a MSV_1_0_PROFILE_BUFFER_TYPE.
  7619. //
  7620. //
  7621. // MSV1.0 LsaLogonUser() submission message types.
  7622. //
  7623. typedef enum _MSV1_0_LOGON_SUBMIT_TYPE {
  7624. MsV1_0InteractiveLogon = 2,
  7625. MsV1_0Lm20Logon,
  7626. MsV1_0NetworkLogon,
  7627. MsV1_0SubAuthLogon,
  7628. MsV1_0WorkstationUnlockLogon = 7
  7629. } MSV1_0_LOGON_SUBMIT_TYPE, *PMSV1_0_LOGON_SUBMIT_TYPE;
  7630. //
  7631. // MSV1.0 LsaLogonUser() profile buffer types.
  7632. //
  7633. typedef enum _MSV1_0_PROFILE_BUFFER_TYPE {
  7634. MsV1_0InteractiveProfile = 2,
  7635. MsV1_0Lm20LogonProfile,
  7636. MsV1_0SmartCardProfile
  7637. } MSV1_0_PROFILE_BUFFER_TYPE, *PMSV1_0_PROFILE_BUFFER_TYPE;
  7638. //
  7639. // MsV1_0InteractiveLogon
  7640. //
  7641. // The AuthenticationInformation buffer of an LsaLogonUser() call to
  7642. // perform an interactive logon contains the following data structure:
  7643. //
  7644. typedef struct _MSV1_0_INTERACTIVE_LOGON {
  7645. MSV1_0_LOGON_SUBMIT_TYPE MessageType;
  7646. UNICODE_STRING LogonDomainName;
  7647. UNICODE_STRING UserName;
  7648. UNICODE_STRING Password;
  7649. } MSV1_0_INTERACTIVE_LOGON, *PMSV1_0_INTERACTIVE_LOGON;
  7650. //
  7651. // Where:
  7652. //
  7653. // MessageType - Contains the type of logon being requested. This
  7654. // field must be set to MsV1_0InteractiveLogon.
  7655. //
  7656. // UserName - Is a string representing the user's account name. The
  7657. // name may be up to 255 characters long. The name is treated case
  7658. // insensitive.
  7659. //
  7660. // Password - Is a string containing the user's cleartext password.
  7661. // The password may be up to 255 characters long and contain any
  7662. // UNICODE value.
  7663. //
  7664. //
  7665. //
  7666. // The ProfileBuffer returned upon a successful logon of this type
  7667. // contains the following data structure:
  7668. //
  7669. typedef struct _MSV1_0_INTERACTIVE_PROFILE {
  7670. MSV1_0_PROFILE_BUFFER_TYPE MessageType;
  7671. USHORT LogonCount;
  7672. USHORT BadPasswordCount;
  7673. LARGE_INTEGER LogonTime;
  7674. LARGE_INTEGER LogoffTime;
  7675. LARGE_INTEGER KickOffTime;
  7676. LARGE_INTEGER PasswordLastSet;
  7677. LARGE_INTEGER PasswordCanChange;
  7678. LARGE_INTEGER PasswordMustChange;
  7679. UNICODE_STRING LogonScript;
  7680. UNICODE_STRING HomeDirectory;
  7681. UNICODE_STRING FullName;
  7682. UNICODE_STRING ProfilePath;
  7683. UNICODE_STRING HomeDirectoryDrive;
  7684. UNICODE_STRING LogonServer;
  7685. ULONG UserFlags;
  7686. } MSV1_0_INTERACTIVE_PROFILE, *PMSV1_0_INTERACTIVE_PROFILE;
  7687. //
  7688. // where:
  7689. //
  7690. // MessageType - Identifies the type of profile data being returned.
  7691. // Contains the type of logon being requested. This field must
  7692. // be set to MsV1_0InteractiveProfile.
  7693. //
  7694. // LogonCount - Number of times the user is currently logged on.
  7695. //
  7696. // BadPasswordCount - Number of times a bad password was applied to
  7697. // the account since last successful logon.
  7698. //
  7699. // LogonTime - Time when user last logged on. This is an absolute
  7700. // format NT standard time value.
  7701. //
  7702. // LogoffTime - Time when user should log off. This is an absolute
  7703. // format NT standard time value.
  7704. //
  7705. // KickOffTime - Time when system should force user logoff. This is
  7706. // an absolute format NT standard time value.
  7707. //
  7708. // PasswordLastChanged - Time and date the password was last
  7709. // changed. This is an absolute format NT standard time
  7710. // value.
  7711. //
  7712. // PasswordCanChange - Time and date when the user can change the
  7713. // password. This is an absolute format NT time value. To
  7714. // prevent a password from ever changing, set this field to a
  7715. // date very far into the future.
  7716. //
  7717. // PasswordMustChange - Time and date when the user must change the
  7718. // password. If the user can never change the password, this
  7719. // field is undefined. This is an absolute format NT time
  7720. // value.
  7721. //
  7722. // LogonScript - The (relative) path to the account's logon
  7723. // script.
  7724. //
  7725. // HomeDirectory - The home directory for the user.
  7726. //
  7727. //
  7728. // MsV1_0Lm20Logon and MsV1_0NetworkLogon
  7729. //
  7730. // The AuthenticationInformation buffer of an LsaLogonUser() call to
  7731. // perform an network logon contains the following data structure:
  7732. //
  7733. // MsV1_0NetworkLogon logon differs from MsV1_0Lm20Logon in that the
  7734. // ParameterControl field exists.
  7735. //
  7736. #define MSV1_0_CHALLENGE_LENGTH 8
  7737. #define MSV1_0_USER_SESSION_KEY_LENGTH 16
  7738. #define MSV1_0_LANMAN_SESSION_KEY_LENGTH 8
  7739. //
  7740. // Values for ParameterControl.
  7741. //
  7742. #define MSV1_0_CLEARTEXT_PASSWORD_ALLOWED 0x02
  7743. #define MSV1_0_UPDATE_LOGON_STATISTICS 0x04
  7744. #define MSV1_0_RETURN_USER_PARAMETERS 0x08
  7745. #define MSV1_0_DONT_TRY_GUEST_ACCOUNT 0x10
  7746. #define MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT 0x20
  7747. #define MSV1_0_RETURN_PASSWORD_EXPIRY 0x40
  7748. // this next flag says that CaseInsensitiveChallengeResponse
  7749. // (aka LmResponse) contains a client challenge in the first 8 bytes
  7750. #define MSV1_0_USE_CLIENT_CHALLENGE 0x80
  7751. #define MSV1_0_TRY_GUEST_ACCOUNT_ONLY 0x100
  7752. #define MSV1_0_RETURN_PROFILE_PATH 0x200
  7753. #define MSV1_0_TRY_SPECIFIED_DOMAIN_ONLY 0x400
  7754. #define MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT 0x800
  7755. #define MSV1_0_DISABLE_PERSONAL_FALLBACK 0x00001000
  7756. #define MSV1_0_ALLOW_FORCE_GUEST 0x00002000
  7757. #define MSV1_0_CLEARTEXT_PASSWORD_SUPPLIED 0x00004000
  7758. #define MSV1_0_USE_DOMAIN_FOR_ROUTING_ONLY 0x00008000
  7759. #define MSV1_0_SUBAUTHENTICATION_DLL_EX 0x00100000
  7760. //
  7761. // The high order byte is a value indicating the SubAuthentication DLL.
  7762. // Zero indicates no SubAuthentication DLL.
  7763. //
  7764. #define MSV1_0_SUBAUTHENTICATION_DLL 0xFF000000
  7765. #define MSV1_0_SUBAUTHENTICATION_DLL_SHIFT 24
  7766. #define MSV1_0_MNS_LOGON 0x01000000
  7767. //
  7768. // This is the list of subauthentication dlls used in MS
  7769. //
  7770. #define MSV1_0_SUBAUTHENTICATION_DLL_RAS 2
  7771. #define MSV1_0_SUBAUTHENTICATION_DLL_IIS 132
  7772. typedef struct _MSV1_0_LM20_LOGON {
  7773. MSV1_0_LOGON_SUBMIT_TYPE MessageType;
  7774. UNICODE_STRING LogonDomainName;
  7775. UNICODE_STRING UserName;
  7776. UNICODE_STRING Workstation;
  7777. UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  7778. STRING CaseSensitiveChallengeResponse;
  7779. STRING CaseInsensitiveChallengeResponse;
  7780. ULONG ParameterControl;
  7781. } MSV1_0_LM20_LOGON, * PMSV1_0_LM20_LOGON;
  7782. //
  7783. // NT 5.0 SubAuth dlls can use this struct
  7784. //
  7785. typedef struct _MSV1_0_SUBAUTH_LOGON{
  7786. MSV1_0_LOGON_SUBMIT_TYPE MessageType;
  7787. UNICODE_STRING LogonDomainName;
  7788. UNICODE_STRING UserName;
  7789. UNICODE_STRING Workstation;
  7790. UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  7791. STRING AuthenticationInfo1;
  7792. STRING AuthenticationInfo2;
  7793. ULONG ParameterControl;
  7794. ULONG SubAuthPackageId;
  7795. } MSV1_0_SUBAUTH_LOGON, * PMSV1_0_SUBAUTH_LOGON;
  7796. //
  7797. // Values for UserFlags.
  7798. //
  7799. #define LOGON_GUEST 0x01
  7800. #define LOGON_NOENCRYPTION 0x02
  7801. #define LOGON_CACHED_ACCOUNT 0x04
  7802. #define LOGON_USED_LM_PASSWORD 0x08
  7803. #define LOGON_EXTRA_SIDS 0x20
  7804. #define LOGON_SUBAUTH_SESSION_KEY 0x40
  7805. #define LOGON_SERVER_TRUST_ACCOUNT 0x80
  7806. #define LOGON_NTLMV2_ENABLED 0x100 // says DC understands NTLMv2
  7807. #define LOGON_RESOURCE_GROUPS 0x200
  7808. #define LOGON_PROFILE_PATH_RETURNED 0x400
  7809. //
  7810. // The high order byte is reserved for return by SubAuthentication DLLs.
  7811. //
  7812. #define MSV1_0_SUBAUTHENTICATION_FLAGS 0xFF000000
  7813. // Values returned by the MSV1_0_MNS_LOGON SubAuthentication DLL
  7814. #define LOGON_GRACE_LOGON 0x01000000
  7815. typedef struct _MSV1_0_LM20_LOGON_PROFILE {
  7816. MSV1_0_PROFILE_BUFFER_TYPE MessageType;
  7817. LARGE_INTEGER KickOffTime;
  7818. LARGE_INTEGER LogoffTime;
  7819. ULONG UserFlags;
  7820. UCHAR UserSessionKey[MSV1_0_USER_SESSION_KEY_LENGTH];
  7821. UNICODE_STRING LogonDomainName;
  7822. UCHAR LanmanSessionKey[MSV1_0_LANMAN_SESSION_KEY_LENGTH];
  7823. UNICODE_STRING LogonServer;
  7824. UNICODE_STRING UserParameters;
  7825. } MSV1_0_LM20_LOGON_PROFILE, * PMSV1_0_LM20_LOGON_PROFILE;
  7826. //
  7827. // Supplemental credentials structure used for passing credentials into
  7828. // MSV1_0 from other packages
  7829. //
  7830. #define MSV1_0_OWF_PASSWORD_LENGTH 16
  7831. #define MSV1_0_CRED_LM_PRESENT 0x1
  7832. #define MSV1_0_CRED_NT_PRESENT 0x2
  7833. #define MSV1_0_CRED_VERSION 0
  7834. typedef struct _MSV1_0_SUPPLEMENTAL_CREDENTIAL {
  7835. ULONG Version;
  7836. ULONG Flags;
  7837. UCHAR LmPassword[MSV1_0_OWF_PASSWORD_LENGTH];
  7838. UCHAR NtPassword[MSV1_0_OWF_PASSWORD_LENGTH];
  7839. } MSV1_0_SUPPLEMENTAL_CREDENTIAL, *PMSV1_0_SUPPLEMENTAL_CREDENTIAL;
  7840. //
  7841. // NTLM3 definitions.
  7842. //
  7843. #define MSV1_0_NTLM3_RESPONSE_LENGTH 16
  7844. #define MSV1_0_NTLM3_OWF_LENGTH 16
  7845. //
  7846. // this is the longest amount of time we'll allow challenge response
  7847. // pairs to be used. Note that this also has to allow for worst case clock skew
  7848. //
  7849. #define MSV1_0_MAX_NTLM3_LIFE 129600 // 36 hours (in seconds)
  7850. #define MSV1_0_MAX_AVL_SIZE 64000
  7851. //
  7852. // MsvAvFlags bit values
  7853. //
  7854. #define MSV1_0_AV_FLAG_FORCE_GUEST 0x00000001
  7855. // this is an MSV1_0 private data structure, defining the layout of an NTLM3 response, as sent by a
  7856. // client in the NtChallengeResponse field of the NETLOGON_NETWORK_INFO structure. If can be differentiated
  7857. // from an old style NT response by its length. This is crude, but it needs to pass through servers and
  7858. // the servers' DCs that do not understand NTLM3 but that are willing to pass longer responses.
  7859. typedef struct _MSV1_0_NTLM3_RESPONSE {
  7860. UCHAR Response[MSV1_0_NTLM3_RESPONSE_LENGTH]; // hash of OWF of password with all the following fields
  7861. UCHAR RespType; // id number of response; current is 1
  7862. UCHAR HiRespType; // highest id number understood by client
  7863. USHORT Flags; // reserved; must be sent as zero at this version
  7864. ULONG MsgWord; // 32 bit message from client to server (for use by auth protocol)
  7865. ULONGLONG TimeStamp; // time stamp when client generated response -- NT system time, quad part
  7866. UCHAR ChallengeFromClient[MSV1_0_CHALLENGE_LENGTH];
  7867. ULONG AvPairsOff; // offset to start of AvPairs (to allow future expansion)
  7868. UCHAR Buffer[1]; // start of buffer with AV pairs (or future stuff -- so use the offset)
  7869. } MSV1_0_NTLM3_RESPONSE, *PMSV1_0_NTLM3_RESPONSE;
  7870. #define MSV1_0_NTLM3_INPUT_LENGTH (sizeof(MSV1_0_NTLM3_RESPONSE) - MSV1_0_NTLM3_RESPONSE_LENGTH)
  7871. #define MSV1_0_NTLM3_MIN_NT_RESPONSE_LENGTH RTL_SIZEOF_THROUGH_FIELD(MSV1_0_NTLM3_RESPONSE, AvPairsOff)
  7872. typedef enum {
  7873. MsvAvEOL, // end of list
  7874. MsvAvNbComputerName, // server's computer name -- NetBIOS
  7875. MsvAvNbDomainName, // server's domain name -- NetBIOS
  7876. MsvAvDnsComputerName, // server's computer name -- DNS
  7877. MsvAvDnsDomainName, // server's domain name -- DNS
  7878. MsvAvDnsTreeName, // server's tree name -- DNS
  7879. MsvAvFlags // server's extended flags -- DWORD mask
  7880. } MSV1_0_AVID;
  7881. typedef struct _MSV1_0_AV_PAIR {
  7882. USHORT AvId;
  7883. USHORT AvLen;
  7884. // Data is treated as byte array following structure
  7885. } MSV1_0_AV_PAIR, *PMSV1_0_AV_PAIR;
  7886. ///////////////////////////////////////////////////////////////////////////////
  7887. // //
  7888. // CALL PACKAGE Related Data Structures //
  7889. // //
  7890. ///////////////////////////////////////////////////////////////////////////////
  7891. //
  7892. // MSV1.0 LsaCallAuthenticationPackage() submission and response
  7893. // message types.
  7894. //
  7895. typedef enum _MSV1_0_PROTOCOL_MESSAGE_TYPE {
  7896. MsV1_0Lm20ChallengeRequest = 0, // Both submission and response
  7897. MsV1_0Lm20GetChallengeResponse, // Both submission and response
  7898. MsV1_0EnumerateUsers, // Both submission and response
  7899. MsV1_0GetUserInfo, // Both submission and response
  7900. MsV1_0ReLogonUsers, // Submission only
  7901. MsV1_0ChangePassword, // Both submission and response
  7902. MsV1_0ChangeCachedPassword, // Both submission and response
  7903. MsV1_0GenericPassthrough, // Both submission and response
  7904. MsV1_0CacheLogon, // Submission only, no response
  7905. MsV1_0SubAuth, // Both submission and response
  7906. MsV1_0DeriveCredential, // Both submission and response
  7907. MsV1_0CacheLookup, // Both submission and response
  7908. MsV1_0SetProcessOption, // Submission only, no response
  7909. } MSV1_0_PROTOCOL_MESSAGE_TYPE, *PMSV1_0_PROTOCOL_MESSAGE_TYPE;
  7910. // end_ntsecapi
  7911. //
  7912. // MsV1_0Lm20ChallengeRequest submit buffer and response
  7913. //
  7914. typedef struct _MSV1_0_LM20_CHALLENGE_REQUEST {
  7915. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7916. } MSV1_0_LM20_CHALLENGE_REQUEST, *PMSV1_0_LM20_CHALLENGE_REQUEST;
  7917. typedef struct _MSV1_0_LM20_CHALLENGE_RESPONSE {
  7918. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7919. UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  7920. } MSV1_0_LM20_CHALLENGE_RESPONSE, *PMSV1_0_LM20_CHALLENGE_RESPONSE;
  7921. //
  7922. // MsV1_0Lm20GetChallengeResponse submit buffer and response
  7923. //
  7924. #define USE_PRIMARY_PASSWORD 0x01
  7925. #define RETURN_PRIMARY_USERNAME 0x02
  7926. #define RETURN_PRIMARY_LOGON_DOMAINNAME 0x04
  7927. #define RETURN_NON_NT_USER_SESSION_KEY 0x08
  7928. #define GENERATE_CLIENT_CHALLENGE 0x10
  7929. #define GCR_NTLM3_PARMS 0x20
  7930. #define GCR_TARGET_INFO 0x40 // ServerName field contains target info AV pairs
  7931. #define RETURN_RESERVED_PARAMETER 0x80 // was 0x10
  7932. #define GCR_ALLOW_NTLM 0x100 // allow the use of NTLM
  7933. #define GCR_USE_OEM_SET 0x200 // response uses oem character set
  7934. #define GCR_MACHINE_CREDENTIAL 0x400
  7935. #define GCR_USE_OWF_PASSWORD 0x800 // use owf passwords
  7936. #define GCR_ALLOW_LM 0x1000 // allow the use of LM
  7937. //
  7938. // version 1 of the GETCHALLENRESP structure, which was used by RAS and others.
  7939. // compiled before the additional fields added to GETCHALLENRESP_REQUEST.
  7940. // here to allow sizing operations for backwards compatibility.
  7941. //
  7942. typedef struct _MSV1_0_GETCHALLENRESP_REQUEST_V1 {
  7943. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7944. ULONG ParameterControl;
  7945. LUID LogonId;
  7946. UNICODE_STRING Password;
  7947. UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  7948. } MSV1_0_GETCHALLENRESP_REQUEST_V1, *PMSV1_0_GETCHALLENRESP_REQUEST_V1;
  7949. typedef struct _MSV1_0_GETCHALLENRESP_REQUEST {
  7950. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7951. ULONG ParameterControl;
  7952. LUID LogonId;
  7953. UNICODE_STRING Password;
  7954. UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  7955. //
  7956. // the following 3 fields are only present if GCR_NTLM3_PARMS is set in ParameterControl
  7957. //
  7958. UNICODE_STRING UserName;
  7959. UNICODE_STRING LogonDomainName;
  7960. UNICODE_STRING ServerName; // server domain or target info AV pairs
  7961. } MSV1_0_GETCHALLENRESP_REQUEST, *PMSV1_0_GETCHALLENRESP_REQUEST;
  7962. typedef struct _MSV1_0_GETCHALLENRESP_RESPONSE {
  7963. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7964. STRING CaseSensitiveChallengeResponse;
  7965. STRING CaseInsensitiveChallengeResponse;
  7966. UNICODE_STRING UserName;
  7967. UNICODE_STRING LogonDomainName;
  7968. UCHAR UserSessionKey[MSV1_0_USER_SESSION_KEY_LENGTH];
  7969. UCHAR LanmanSessionKey[MSV1_0_LANMAN_SESSION_KEY_LENGTH];
  7970. } MSV1_0_GETCHALLENRESP_RESPONSE, *PMSV1_0_GETCHALLENRESP_RESPONSE;
  7971. //
  7972. // MsV1_0EnumerateUsers submit buffer and response
  7973. //
  7974. typedef struct _MSV1_0_ENUMUSERS_REQUEST {
  7975. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7976. } MSV1_0_ENUMUSERS_REQUEST, *PMSV1_0_ENUMUSERS_REQUEST;
  7977. typedef struct _MSV1_0_ENUMUSERS_RESPONSE {
  7978. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7979. ULONG NumberOfLoggedOnUsers;
  7980. PLUID LogonIds;
  7981. PULONG EnumHandles;
  7982. } MSV1_0_ENUMUSERS_RESPONSE, *PMSV1_0_ENUMUSERS_RESPONSE;
  7983. //
  7984. // MsV1_0GetUserInfo submit buffer and response
  7985. //
  7986. typedef struct _MSV1_0_GETUSERINFO_REQUEST {
  7987. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7988. LUID LogonId;
  7989. } MSV1_0_GETUSERINFO_REQUEST, *PMSV1_0_GETUSERINFO_REQUEST;
  7990. typedef struct _MSV1_0_GETUSERINFO_RESPONSE {
  7991. MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
  7992. PSID UserSid;
  7993. UNICODE_STRING UserName;
  7994. UNICODE_STRING LogonDomainName;
  7995. UNICODE_STRING LogonServer;
  7996. SECURITY_LOGON_TYPE LogonType;
  7997. } MSV1_0_GETUSERINFO_RESPONSE, *PMSV1_0_GETUSERINFO_RESPONSE;
  7998. // begin_winnt
  7999. //
  8000. // Define access rights to files and directories
  8001. //
  8002. //
  8003. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  8004. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  8005. // constants *MUST* always be in sync.
  8006. // The values are redefined in devioctl.h because they must be available to
  8007. // both DOS and NT.
  8008. //
  8009. #define FILE_READ_DATA ( 0x0001 ) // file & pipe
  8010. #define FILE_LIST_DIRECTORY ( 0x0001 ) // directory
  8011. #define FILE_WRITE_DATA ( 0x0002 ) // file & pipe
  8012. #define FILE_ADD_FILE ( 0x0002 ) // directory
  8013. #define FILE_APPEND_DATA ( 0x0004 ) // file
  8014. #define FILE_ADD_SUBDIRECTORY ( 0x0004 ) // directory
  8015. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 ) // named pipe
  8016. #define FILE_READ_EA ( 0x0008 ) // file & directory
  8017. #define FILE_WRITE_EA ( 0x0010 ) // file & directory
  8018. #define FILE_EXECUTE ( 0x0020 ) // file
  8019. #define FILE_TRAVERSE ( 0x0020 ) // directory
  8020. #define FILE_DELETE_CHILD ( 0x0040 ) // directory
  8021. #define FILE_READ_ATTRIBUTES ( 0x0080 ) // all
  8022. #define FILE_WRITE_ATTRIBUTES ( 0x0100 ) // all
  8023. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  8024. #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\
  8025. FILE_READ_DATA |\
  8026. FILE_READ_ATTRIBUTES |\
  8027. FILE_READ_EA |\
  8028. SYNCHRONIZE)
  8029. #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE |\
  8030. FILE_WRITE_DATA |\
  8031. FILE_WRITE_ATTRIBUTES |\
  8032. FILE_WRITE_EA |\
  8033. FILE_APPEND_DATA |\
  8034. SYNCHRONIZE)
  8035. #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE |\
  8036. FILE_READ_ATTRIBUTES |\
  8037. FILE_EXECUTE |\
  8038. SYNCHRONIZE)
  8039. // end_winnt
  8040. //
  8041. // Define share access rights to files and directories
  8042. //
  8043. #define FILE_SHARE_READ 0x00000001 // winnt
  8044. #define FILE_SHARE_WRITE 0x00000002 // winnt
  8045. #define FILE_SHARE_DELETE 0x00000004 // winnt
  8046. #define FILE_SHARE_VALID_FLAGS 0x00000007
  8047. //
  8048. // Define the file attributes values
  8049. //
  8050. // Note: 0x00000008 is reserved for use for the old DOS VOLID (volume ID)
  8051. // and is therefore not considered valid in NT.
  8052. //
  8053. // Note: 0x00000010 is reserved for use for the old DOS SUBDIRECTORY flag
  8054. // and is therefore not considered valid in NT. This flag has
  8055. // been disassociated with file attributes since the other flags are
  8056. // protected with READ_ and WRITE_ATTRIBUTES access to the file.
  8057. //
  8058. // Note: Note also that the order of these flags is set to allow both the
  8059. // FAT and the Pinball File Systems to directly set the attributes
  8060. // flags in attributes words without having to pick each flag out
  8061. // individually. The order of these flags should not be changed!
  8062. //
  8063. #define FILE_ATTRIBUTE_READONLY 0x00000001 // winnt
  8064. #define FILE_ATTRIBUTE_HIDDEN 0x00000002 // winnt
  8065. #define FILE_ATTRIBUTE_SYSTEM 0x00000004 // winnt
  8066. //OLD DOS VOLID 0x00000008
  8067. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010 // winnt
  8068. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020 // winnt
  8069. #define FILE_ATTRIBUTE_DEVICE 0x00000040 // winnt
  8070. #define FILE_ATTRIBUTE_NORMAL 0x00000080 // winnt
  8071. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100 // winnt
  8072. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 // winnt
  8073. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 // winnt
  8074. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800 // winnt
  8075. #define FILE_ATTRIBUTE_OFFLINE 0x00001000 // winnt
  8076. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 // winnt
  8077. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 // winnt
  8078. #define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
  8079. #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x000031a7
  8080. //
  8081. // Define the create disposition values
  8082. //
  8083. #define FILE_SUPERSEDE 0x00000000
  8084. #define FILE_OPEN 0x00000001
  8085. #define FILE_CREATE 0x00000002
  8086. #define FILE_OPEN_IF 0x00000003
  8087. #define FILE_OVERWRITE 0x00000004
  8088. #define FILE_OVERWRITE_IF 0x00000005
  8089. #define FILE_MAXIMUM_DISPOSITION 0x00000005
  8090. //
  8091. // Define the create/open option flags
  8092. //
  8093. #define FILE_DIRECTORY_FILE 0x00000001
  8094. #define FILE_WRITE_THROUGH 0x00000002
  8095. #define FILE_SEQUENTIAL_ONLY 0x00000004
  8096. #define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
  8097. #define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
  8098. #define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
  8099. #define FILE_NON_DIRECTORY_FILE 0x00000040
  8100. #define FILE_CREATE_TREE_CONNECTION 0x00000080
  8101. #define FILE_COMPLETE_IF_OPLOCKED 0x00000100
  8102. #define FILE_NO_EA_KNOWLEDGE 0x00000200
  8103. #define FILE_OPEN_FOR_RECOVERY 0x00000400
  8104. #define FILE_RANDOM_ACCESS 0x00000800
  8105. #define FILE_DELETE_ON_CLOSE 0x00001000
  8106. #define FILE_OPEN_BY_FILE_ID 0x00002000
  8107. #define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
  8108. #define FILE_NO_COMPRESSION 0x00008000
  8109. #define FILE_RESERVE_OPFILTER 0x00100000
  8110. #define FILE_OPEN_REPARSE_POINT 0x00200000
  8111. #define FILE_OPEN_NO_RECALL 0x00400000
  8112. #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
  8113. #define FILE_COPY_STRUCTURED_STORAGE 0x00000041
  8114. #define FILE_STRUCTURED_STORAGE 0x00000441
  8115. #define FILE_VALID_OPTION_FLAGS 0x00ffffff
  8116. #define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
  8117. #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
  8118. #define FILE_VALID_SET_FLAGS 0x00000036
  8119. //
  8120. // Define the I/O status information return values for NtCreateFile/NtOpenFile
  8121. //
  8122. #define FILE_SUPERSEDED 0x00000000
  8123. #define FILE_OPENED 0x00000001
  8124. #define FILE_CREATED 0x00000002
  8125. #define FILE_OVERWRITTEN 0x00000003
  8126. #define FILE_EXISTS 0x00000004
  8127. #define FILE_DOES_NOT_EXIST 0x00000005
  8128. // end_ntddk end_wdm end_nthal
  8129. //
  8130. // Define the I/O status information return values for requests for oplocks
  8131. // via NtFsControlFile
  8132. //
  8133. #define FILE_OPLOCK_BROKEN_TO_LEVEL_2 0x00000007
  8134. #define FILE_OPLOCK_BROKEN_TO_NONE 0x00000008
  8135. //
  8136. // Define the I/O status information return values for NtCreateFile/NtOpenFile
  8137. // when the sharing access fails but a batch oplock break is in progress
  8138. //
  8139. #define FILE_OPBATCH_BREAK_UNDERWAY 0x00000009
  8140. //
  8141. // Define the filter flags for NtNotifyChangeDirectoryFile
  8142. //
  8143. #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001 // winnt
  8144. #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002 // winnt
  8145. #define FILE_NOTIFY_CHANGE_NAME 0x00000003
  8146. #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004 // winnt
  8147. #define FILE_NOTIFY_CHANGE_SIZE 0x00000008 // winnt
  8148. #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010 // winnt
  8149. #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020 // winnt
  8150. #define FILE_NOTIFY_CHANGE_CREATION 0x00000040 // winnt
  8151. #define FILE_NOTIFY_CHANGE_EA 0x00000080
  8152. #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100 // winnt
  8153. #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
  8154. #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
  8155. #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
  8156. #define FILE_NOTIFY_VALID_MASK 0x00000fff
  8157. //
  8158. // Define the file action type codes for NtNotifyChangeDirectoryFile
  8159. //
  8160. #define FILE_ACTION_ADDED 0x00000001 // winnt
  8161. #define FILE_ACTION_REMOVED 0x00000002 // winnt
  8162. #define FILE_ACTION_MODIFIED 0x00000003 // winnt
  8163. #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004 // winnt
  8164. #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005 // winnt
  8165. #define FILE_ACTION_ADDED_STREAM 0x00000006
  8166. #define FILE_ACTION_REMOVED_STREAM 0x00000007
  8167. #define FILE_ACTION_MODIFIED_STREAM 0x00000008
  8168. #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
  8169. #define FILE_ACTION_ID_NOT_TUNNELLED 0x0000000A
  8170. #define FILE_ACTION_TUNNELLED_ID_COLLISION 0x0000000B
  8171. //
  8172. // Define the NamedPipeType flags for NtCreateNamedPipeFile
  8173. //
  8174. #define FILE_PIPE_BYTE_STREAM_TYPE 0x00000000
  8175. #define FILE_PIPE_MESSAGE_TYPE 0x00000001
  8176. //
  8177. // Define the CompletionMode flags for NtCreateNamedPipeFile
  8178. //
  8179. #define FILE_PIPE_QUEUE_OPERATION 0x00000000
  8180. #define FILE_PIPE_COMPLETE_OPERATION 0x00000001
  8181. //
  8182. // Define the ReadMode flags for NtCreateNamedPipeFile
  8183. //
  8184. #define FILE_PIPE_BYTE_STREAM_MODE 0x00000000
  8185. #define FILE_PIPE_MESSAGE_MODE 0x00000001
  8186. //
  8187. // Define the NamedPipeConfiguration flags for NtQueryInformation
  8188. //
  8189. #define FILE_PIPE_INBOUND 0x00000000
  8190. #define FILE_PIPE_OUTBOUND 0x00000001
  8191. #define FILE_PIPE_FULL_DUPLEX 0x00000002
  8192. //
  8193. // Define the NamedPipeState flags for NtQueryInformation
  8194. //
  8195. #define FILE_PIPE_DISCONNECTED_STATE 0x00000001
  8196. #define FILE_PIPE_LISTENING_STATE 0x00000002
  8197. #define FILE_PIPE_CONNECTED_STATE 0x00000003
  8198. #define FILE_PIPE_CLOSING_STATE 0x00000004
  8199. //
  8200. // Define the NamedPipeEnd flags for NtQueryInformation
  8201. //
  8202. #define FILE_PIPE_CLIENT_END 0x00000000
  8203. #define FILE_PIPE_SERVER_END 0x00000001
  8204. //
  8205. // Define special ByteOffset parameters for read and write operations
  8206. //
  8207. #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
  8208. #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
  8209. //
  8210. // Define alignment requirement values
  8211. //
  8212. #define FILE_BYTE_ALIGNMENT 0x00000000
  8213. #define FILE_WORD_ALIGNMENT 0x00000001
  8214. #define FILE_LONG_ALIGNMENT 0x00000003
  8215. #define FILE_QUAD_ALIGNMENT 0x00000007
  8216. #define FILE_OCTA_ALIGNMENT 0x0000000f
  8217. #define FILE_32_BYTE_ALIGNMENT 0x0000001f
  8218. #define FILE_64_BYTE_ALIGNMENT 0x0000003f
  8219. #define FILE_128_BYTE_ALIGNMENT 0x0000007f
  8220. #define FILE_256_BYTE_ALIGNMENT 0x000000ff
  8221. #define FILE_512_BYTE_ALIGNMENT 0x000001ff
  8222. //
  8223. // Define the maximum length of a filename string
  8224. //
  8225. #define MAXIMUM_FILENAME_LENGTH 256
  8226. // end_ntddk end_wdm end_nthal
  8227. //
  8228. // Define the file system attributes flags
  8229. //
  8230. #define FILE_CASE_SENSITIVE_SEARCH 0x00000001 // winnt
  8231. #define FILE_CASE_PRESERVED_NAMES 0x00000002 // winnt
  8232. #define FILE_UNICODE_ON_DISK 0x00000004 // winnt
  8233. #define FILE_PERSISTENT_ACLS 0x00000008 // winnt
  8234. #define FILE_FILE_COMPRESSION 0x00000010 // winnt
  8235. #define FILE_VOLUME_QUOTAS 0x00000020 // winnt
  8236. #define FILE_SUPPORTS_SPARSE_FILES 0x00000040 // winnt
  8237. #define FILE_SUPPORTS_REPARSE_POINTS 0x00000080 // winnt
  8238. #define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100 // winnt
  8239. #define FILE_VOLUME_IS_COMPRESSED 0x00008000 // winnt
  8240. #define FILE_SUPPORTS_OBJECT_IDS 0x00010000 // winnt
  8241. #define FILE_SUPPORTS_ENCRYPTION 0x00020000 // winnt
  8242. #define FILE_NAMED_STREAMS 0x00040000 // winnt
  8243. #define FILE_READ_ONLY_VOLUME 0x00080000 // winnt
  8244. //
  8245. // Define the flags for NtSet(Query)EaFile service structure entries
  8246. //
  8247. #define FILE_NEED_EA 0x00000080
  8248. //
  8249. // Define EA type values
  8250. //
  8251. #define FILE_EA_TYPE_BINARY 0xfffe
  8252. #define FILE_EA_TYPE_ASCII 0xfffd
  8253. #define FILE_EA_TYPE_BITMAP 0xfffb
  8254. #define FILE_EA_TYPE_METAFILE 0xfffa
  8255. #define FILE_EA_TYPE_ICON 0xfff9
  8256. #define FILE_EA_TYPE_EA 0xffee
  8257. #define FILE_EA_TYPE_MVMT 0xffdf
  8258. #define FILE_EA_TYPE_MVST 0xffde
  8259. #define FILE_EA_TYPE_ASN1 0xffdd
  8260. #define FILE_EA_TYPE_FAMILY_IDS 0xff01
  8261. // begin_ntddk begin_wdm begin_nthal
  8262. //
  8263. // Define the various device characteristics flags
  8264. //
  8265. #define FILE_REMOVABLE_MEDIA 0x00000001
  8266. #define FILE_READ_ONLY_DEVICE 0x00000002
  8267. #define FILE_FLOPPY_DISKETTE 0x00000004
  8268. #define FILE_WRITE_ONCE_MEDIA 0x00000008
  8269. #define FILE_REMOTE_DEVICE 0x00000010
  8270. #define FILE_DEVICE_IS_MOUNTED 0x00000020
  8271. #define FILE_VIRTUAL_VOLUME 0x00000040
  8272. #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
  8273. #define FILE_DEVICE_SECURE_OPEN 0x00000100
  8274. #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
  8275. // end_wdm
  8276. //
  8277. // The FILE_EXPECT flags will only exist for WinXP. After that they will be
  8278. // ignored and an IRP will be sent in their place.
  8279. //
  8280. #define FILE_CHARACTERISTICS_EXPECT_ORDERLY_REMOVAL 0x00000200
  8281. #define FILE_CHARACTERISTICS_EXPECT_SURPRISE_REMOVAL 0x00000300
  8282. #define FILE_CHARACTERISTICS_REMOVAL_POLICY_MASK 0x00000300
  8283. //
  8284. // flags specified here will be propagated up and down a device stack
  8285. // after FDO and all filter devices are added, but before the device
  8286. // stack is started
  8287. //
  8288. #define FILE_CHARACTERISTICS_PROPAGATED ( FILE_REMOVABLE_MEDIA | \
  8289. FILE_READ_ONLY_DEVICE | \
  8290. FILE_FLOPPY_DISKETTE | \
  8291. FILE_WRITE_ONCE_MEDIA | \
  8292. FILE_DEVICE_SECURE_OPEN )
  8293. // end_ntddk end_nthal
  8294. // begin_ntddk begin_wdm begin_nthal
  8295. //
  8296. // Define the base asynchronous I/O argument types
  8297. //
  8298. typedef struct _IO_STATUS_BLOCK {
  8299. union {
  8300. NTSTATUS Status;
  8301. PVOID Pointer;
  8302. };
  8303. ULONG_PTR Information;
  8304. } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
  8305. #if defined(_WIN64)
  8306. typedef struct _IO_STATUS_BLOCK32 {
  8307. NTSTATUS Status;
  8308. ULONG Information;
  8309. } IO_STATUS_BLOCK32, *PIO_STATUS_BLOCK32;
  8310. #endif
  8311. //
  8312. // Define an Asynchronous Procedure Call from I/O viewpoint
  8313. //
  8314. typedef
  8315. VOID
  8316. (NTAPI *PIO_APC_ROUTINE) (
  8317. IN PVOID ApcContext,
  8318. IN PIO_STATUS_BLOCK IoStatusBlock,
  8319. IN ULONG Reserved
  8320. );
  8321. #define PIO_APC_ROUTINE_DEFINED
  8322. // end_ntddk end_wdm end_nthal
  8323. // begin_winnt
  8324. //
  8325. // Define the file notification information structure
  8326. //
  8327. typedef struct _FILE_NOTIFY_INFORMATION {
  8328. ULONG NextEntryOffset;
  8329. ULONG Action;
  8330. ULONG FileNameLength;
  8331. WCHAR FileName[1];
  8332. } FILE_NOTIFY_INFORMATION, *PFILE_NOTIFY_INFORMATION;
  8333. // end_winnt
  8334. // begin_ntddk begin_wdm begin_nthal
  8335. //
  8336. // Define the file information class values
  8337. //
  8338. // WARNING: The order of the following values are assumed by the I/O system.
  8339. // Any changes made here should be reflected there as well.
  8340. //
  8341. typedef enum _FILE_INFORMATION_CLASS {
  8342. // end_wdm
  8343. FileDirectoryInformation = 1,
  8344. FileFullDirectoryInformation, // 2
  8345. FileBothDirectoryInformation, // 3
  8346. FileBasicInformation, // 4 wdm
  8347. FileStandardInformation, // 5 wdm
  8348. FileInternalInformation, // 6
  8349. FileEaInformation, // 7
  8350. FileAccessInformation, // 8
  8351. FileNameInformation, // 9
  8352. FileRenameInformation, // 10
  8353. FileLinkInformation, // 11
  8354. FileNamesInformation, // 12
  8355. FileDispositionInformation, // 13
  8356. FilePositionInformation, // 14 wdm
  8357. FileFullEaInformation, // 15
  8358. FileModeInformation, // 16
  8359. FileAlignmentInformation, // 17
  8360. FileAllInformation, // 18
  8361. FileAllocationInformation, // 19
  8362. FileEndOfFileInformation, // 20 wdm
  8363. FileAlternateNameInformation, // 21
  8364. FileStreamInformation, // 22
  8365. FilePipeInformation, // 23
  8366. FilePipeLocalInformation, // 24
  8367. FilePipeRemoteInformation, // 25
  8368. FileMailslotQueryInformation, // 26
  8369. FileMailslotSetInformation, // 27
  8370. FileCompressionInformation, // 28
  8371. FileObjectIdInformation, // 29
  8372. FileCompletionInformation, // 30
  8373. FileMoveClusterInformation, // 31
  8374. FileQuotaInformation, // 32
  8375. FileReparsePointInformation, // 33
  8376. FileNetworkOpenInformation, // 34
  8377. FileAttributeTagInformation, // 35
  8378. FileTrackingInformation, // 36
  8379. FileIdBothDirectoryInformation, // 37
  8380. FileIdFullDirectoryInformation, // 38
  8381. FileValidDataLengthInformation, // 39
  8382. FileShortNameInformation, // 40
  8383. FileMaximumInformation
  8384. // begin_wdm
  8385. } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
  8386. //
  8387. // Define the various structures which are returned on query operations
  8388. //
  8389. // end_ntddk end_wdm end_nthal
  8390. //
  8391. // NtQueryDirectoryFile return types:
  8392. //
  8393. // FILE_DIRECTORY_INFORMATION
  8394. // FILE_FULL_DIR_INFORMATION
  8395. // FILE_ID_FULL_DIR_INFORMATION
  8396. // FILE_BOTH_DIR_INFORMATION
  8397. // FILE_ID_BOTH_DIR_INFORMATION
  8398. // FILE_NAMES_INFORMATION
  8399. // FILE_OBJECTID_INFORMATION
  8400. //
  8401. typedef struct _FILE_DIRECTORY_INFORMATION {
  8402. ULONG NextEntryOffset;
  8403. ULONG FileIndex;
  8404. LARGE_INTEGER CreationTime;
  8405. LARGE_INTEGER LastAccessTime;
  8406. LARGE_INTEGER LastWriteTime;
  8407. LARGE_INTEGER ChangeTime;
  8408. LARGE_INTEGER EndOfFile;
  8409. LARGE_INTEGER AllocationSize;
  8410. ULONG FileAttributes;
  8411. ULONG FileNameLength;
  8412. WCHAR FileName[1];
  8413. } FILE_DIRECTORY_INFORMATION, *PFILE_DIRECTORY_INFORMATION;
  8414. typedef struct _FILE_FULL_DIR_INFORMATION {
  8415. ULONG NextEntryOffset;
  8416. ULONG FileIndex;
  8417. LARGE_INTEGER CreationTime;
  8418. LARGE_INTEGER LastAccessTime;
  8419. LARGE_INTEGER LastWriteTime;
  8420. LARGE_INTEGER ChangeTime;
  8421. LARGE_INTEGER EndOfFile;
  8422. LARGE_INTEGER AllocationSize;
  8423. ULONG FileAttributes;
  8424. ULONG FileNameLength;
  8425. ULONG EaSize;
  8426. WCHAR FileName[1];
  8427. } FILE_FULL_DIR_INFORMATION, *PFILE_FULL_DIR_INFORMATION;
  8428. typedef struct _FILE_ID_FULL_DIR_INFORMATION {
  8429. ULONG NextEntryOffset;
  8430. ULONG FileIndex;
  8431. LARGE_INTEGER CreationTime;
  8432. LARGE_INTEGER LastAccessTime;
  8433. LARGE_INTEGER LastWriteTime;
  8434. LARGE_INTEGER ChangeTime;
  8435. LARGE_INTEGER EndOfFile;
  8436. LARGE_INTEGER AllocationSize;
  8437. ULONG FileAttributes;
  8438. ULONG FileNameLength;
  8439. ULONG EaSize;
  8440. LARGE_INTEGER FileId;
  8441. WCHAR FileName[1];
  8442. } FILE_ID_FULL_DIR_INFORMATION, *PFILE_ID_FULL_DIR_INFORMATION;
  8443. typedef struct _FILE_BOTH_DIR_INFORMATION {
  8444. ULONG NextEntryOffset;
  8445. ULONG FileIndex;
  8446. LARGE_INTEGER CreationTime;
  8447. LARGE_INTEGER LastAccessTime;
  8448. LARGE_INTEGER LastWriteTime;
  8449. LARGE_INTEGER ChangeTime;
  8450. LARGE_INTEGER EndOfFile;
  8451. LARGE_INTEGER AllocationSize;
  8452. ULONG FileAttributes;
  8453. ULONG FileNameLength;
  8454. ULONG EaSize;
  8455. CCHAR ShortNameLength;
  8456. WCHAR ShortName[12];
  8457. WCHAR FileName[1];
  8458. } FILE_BOTH_DIR_INFORMATION, *PFILE_BOTH_DIR_INFORMATION;
  8459. typedef struct _FILE_ID_BOTH_DIR_INFORMATION {
  8460. ULONG NextEntryOffset;
  8461. ULONG FileIndex;
  8462. LARGE_INTEGER CreationTime;
  8463. LARGE_INTEGER LastAccessTime;
  8464. LARGE_INTEGER LastWriteTime;
  8465. LARGE_INTEGER ChangeTime;
  8466. LARGE_INTEGER EndOfFile;
  8467. LARGE_INTEGER AllocationSize;
  8468. ULONG FileAttributes;
  8469. ULONG FileNameLength;
  8470. ULONG EaSize;
  8471. CCHAR ShortNameLength;
  8472. WCHAR ShortName[12];
  8473. LARGE_INTEGER FileId;
  8474. WCHAR FileName[1];
  8475. } FILE_ID_BOTH_DIR_INFORMATION, *PFILE_ID_BOTH_DIR_INFORMATION;
  8476. typedef struct _FILE_NAMES_INFORMATION {
  8477. ULONG NextEntryOffset;
  8478. ULONG FileIndex;
  8479. ULONG FileNameLength;
  8480. WCHAR FileName[1];
  8481. } FILE_NAMES_INFORMATION, *PFILE_NAMES_INFORMATION;
  8482. typedef struct _FILE_OBJECTID_INFORMATION {
  8483. LONGLONG FileReference;
  8484. UCHAR ObjectId[16];
  8485. union {
  8486. struct {
  8487. UCHAR BirthVolumeId[16];
  8488. UCHAR BirthObjectId[16];
  8489. UCHAR DomainId[16];
  8490. } ;
  8491. UCHAR ExtendedInfo[48];
  8492. };
  8493. } FILE_OBJECTID_INFORMATION, *PFILE_OBJECTID_INFORMATION;
  8494. //
  8495. // The following constants provide addition meta characters to fully
  8496. // support the more obscure aspects of DOS wild card processing.
  8497. //
  8498. #define ANSI_DOS_STAR ('<')
  8499. #define ANSI_DOS_QM ('>')
  8500. #define ANSI_DOS_DOT ('"')
  8501. #define DOS_STAR (L'<')
  8502. #define DOS_QM (L'>')
  8503. #define DOS_DOT (L'"')
  8504. //
  8505. // NtQuery(Set)InformationFile return types:
  8506. //
  8507. // FILE_BASIC_INFORMATION
  8508. // FILE_STANDARD_INFORMATION
  8509. // FILE_INTERNAL_INFORMATION
  8510. // FILE_EA_INFORMATION
  8511. // FILE_ACCESS_INFORMATION
  8512. // FILE_POSITION_INFORMATION
  8513. // FILE_MODE_INFORMATION
  8514. // FILE_ALIGNMENT_INFORMATION
  8515. // FILE_NAME_INFORMATION
  8516. // FILE_ALL_INFORMATION
  8517. //
  8518. // FILE_NETWORK_OPEN_INFORMATION
  8519. //
  8520. // FILE_ALLOCATION_INFORMATION
  8521. // FILE_COMPRESSION_INFORMATION
  8522. // FILE_DISPOSITION_INFORMATION
  8523. // FILE_END_OF_FILE_INFORMATION
  8524. // FILE_LINK_INFORMATION
  8525. // FILE_MOVE_CLUSTER_INFORMATION
  8526. // FILE_RENAME_INFORMATION
  8527. // FILE_SHORT_NAME_INFORMATION
  8528. // FILE_STREAM_INFORMATION
  8529. // FILE_COMPLETION_INFORMATION
  8530. //
  8531. // FILE_PIPE_INFORMATION
  8532. // FILE_PIPE_LOCAL_INFORMATION
  8533. // FILE_PIPE_REMOTE_INFORMATION
  8534. //
  8535. // FILE_MAILSLOT_QUERY_INFORMATION
  8536. // FILE_MAILSLOT_SET_INFORMATION
  8537. // FILE_REPARSE_POINT_INFORMATION
  8538. //
  8539. typedef struct _FILE_BASIC_INFORMATION { // ntddk wdm nthal
  8540. LARGE_INTEGER CreationTime; // ntddk wdm nthal
  8541. LARGE_INTEGER LastAccessTime; // ntddk wdm nthal
  8542. LARGE_INTEGER LastWriteTime; // ntddk wdm nthal
  8543. LARGE_INTEGER ChangeTime; // ntddk wdm nthal
  8544. ULONG FileAttributes; // ntddk wdm nthal
  8545. } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION; // ntddk wdm nthal
  8546. // ntddk wdm nthal
  8547. typedef struct _FILE_STANDARD_INFORMATION { // ntddk wdm nthal
  8548. LARGE_INTEGER AllocationSize; // ntddk wdm nthal
  8549. LARGE_INTEGER EndOfFile; // ntddk wdm nthal
  8550. ULONG NumberOfLinks; // ntddk wdm nthal
  8551. BOOLEAN DeletePending; // ntddk wdm nthal
  8552. BOOLEAN Directory; // ntddk wdm nthal
  8553. } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION; // ntddk wdm nthal
  8554. // ntddk wdm nthal
  8555. typedef struct _FILE_INTERNAL_INFORMATION {
  8556. LARGE_INTEGER IndexNumber;
  8557. } FILE_INTERNAL_INFORMATION, *PFILE_INTERNAL_INFORMATION;
  8558. typedef struct _FILE_EA_INFORMATION {
  8559. ULONG EaSize;
  8560. } FILE_EA_INFORMATION, *PFILE_EA_INFORMATION;
  8561. typedef struct _FILE_ACCESS_INFORMATION {
  8562. ACCESS_MASK AccessFlags;
  8563. } FILE_ACCESS_INFORMATION, *PFILE_ACCESS_INFORMATION;
  8564. typedef struct _FILE_POSITION_INFORMATION { // ntddk wdm nthal
  8565. LARGE_INTEGER CurrentByteOffset; // ntddk wdm nthal
  8566. } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION; // ntddk wdm nthal
  8567. // ntddk wdm nthal
  8568. typedef struct _FILE_MODE_INFORMATION {
  8569. ULONG Mode;
  8570. } FILE_MODE_INFORMATION, *PFILE_MODE_INFORMATION;
  8571. typedef struct _FILE_ALIGNMENT_INFORMATION { // ntddk nthal
  8572. ULONG AlignmentRequirement; // ntddk nthal
  8573. } FILE_ALIGNMENT_INFORMATION, *PFILE_ALIGNMENT_INFORMATION; // ntddk nthal
  8574. // ntddk nthal
  8575. typedef struct _FILE_NAME_INFORMATION { // ntddk
  8576. ULONG FileNameLength; // ntddk
  8577. WCHAR FileName[1]; // ntddk
  8578. } FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION; // ntddk
  8579. // ntddk
  8580. typedef struct _FILE_ALL_INFORMATION {
  8581. FILE_BASIC_INFORMATION BasicInformation;
  8582. FILE_STANDARD_INFORMATION StandardInformation;
  8583. FILE_INTERNAL_INFORMATION InternalInformation;
  8584. FILE_EA_INFORMATION EaInformation;
  8585. FILE_ACCESS_INFORMATION AccessInformation;
  8586. FILE_POSITION_INFORMATION PositionInformation;
  8587. FILE_MODE_INFORMATION ModeInformation;
  8588. FILE_ALIGNMENT_INFORMATION AlignmentInformation;
  8589. FILE_NAME_INFORMATION NameInformation;
  8590. } FILE_ALL_INFORMATION, *PFILE_ALL_INFORMATION;
  8591. typedef struct _FILE_NETWORK_OPEN_INFORMATION { // ntddk wdm nthal
  8592. LARGE_INTEGER CreationTime; // ntddk wdm nthal
  8593. LARGE_INTEGER LastAccessTime; // ntddk wdm nthal
  8594. LARGE_INTEGER LastWriteTime; // ntddk wdm nthal
  8595. LARGE_INTEGER ChangeTime; // ntddk wdm nthal
  8596. LARGE_INTEGER AllocationSize; // ntddk wdm nthal
  8597. LARGE_INTEGER EndOfFile; // ntddk wdm nthal
  8598. ULONG FileAttributes; // ntddk wdm nthal
  8599. } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION; // ntddk wdm nthal
  8600. // ntddk wdm nthal
  8601. typedef struct _FILE_ATTRIBUTE_TAG_INFORMATION { // ntddk nthal
  8602. ULONG FileAttributes; // ntddk nthal
  8603. ULONG ReparseTag; // ntddk nthal
  8604. } FILE_ATTRIBUTE_TAG_INFORMATION, *PFILE_ATTRIBUTE_TAG_INFORMATION; // ntddk nthal
  8605. // ntddk nthal
  8606. typedef struct _FILE_ALLOCATION_INFORMATION {
  8607. LARGE_INTEGER AllocationSize;
  8608. } FILE_ALLOCATION_INFORMATION, *PFILE_ALLOCATION_INFORMATION;
  8609. typedef struct _FILE_COMPRESSION_INFORMATION {
  8610. LARGE_INTEGER CompressedFileSize;
  8611. USHORT CompressionFormat;
  8612. UCHAR CompressionUnitShift;
  8613. UCHAR ChunkShift;
  8614. UCHAR ClusterShift;
  8615. UCHAR Reserved[3];
  8616. } FILE_COMPRESSION_INFORMATION, *PFILE_COMPRESSION_INFORMATION;
  8617. typedef struct _FILE_DISPOSITION_INFORMATION { // ntddk nthal
  8618. BOOLEAN DeleteFile; // ntddk nthal
  8619. } FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION; // ntddk nthal
  8620. // ntddk nthal
  8621. typedef struct _FILE_END_OF_FILE_INFORMATION { // ntddk nthal
  8622. LARGE_INTEGER EndOfFile; // ntddk nthal
  8623. } FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION; // ntddk nthal
  8624. // ntddk nthal
  8625. typedef struct _FILE_VALID_DATA_LENGTH_INFORMATION { // ntddk nthal
  8626. LARGE_INTEGER ValidDataLength; // ntddk nthal
  8627. } FILE_VALID_DATA_LENGTH_INFORMATION, *PFILE_VALID_DATA_LENGTH_INFORMATION; // ntddk nthal
  8628. #ifdef _MAC
  8629. #pragma warning( disable : 4121)
  8630. #endif
  8631. typedef struct _FILE_LINK_INFORMATION {
  8632. BOOLEAN ReplaceIfExists;
  8633. HANDLE RootDirectory;
  8634. ULONG FileNameLength;
  8635. WCHAR FileName[1];
  8636. } FILE_LINK_INFORMATION, *PFILE_LINK_INFORMATION;
  8637. #ifdef _MAC
  8638. #pragma warning( default : 4121 )
  8639. #endif
  8640. typedef struct _FILE_MOVE_CLUSTER_INFORMATION {
  8641. ULONG ClusterCount;
  8642. HANDLE RootDirectory;
  8643. ULONG FileNameLength;
  8644. WCHAR FileName[1];
  8645. } FILE_MOVE_CLUSTER_INFORMATION, *PFILE_MOVE_CLUSTER_INFORMATION;
  8646. #ifdef _MAC
  8647. #pragma warning( disable : 4121)
  8648. #endif
  8649. typedef struct _FILE_RENAME_INFORMATION {
  8650. BOOLEAN ReplaceIfExists;
  8651. HANDLE RootDirectory;
  8652. ULONG FileNameLength;
  8653. WCHAR FileName[1];
  8654. } FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION;
  8655. #ifdef _MAC
  8656. #pragma warning( default : 4121 )
  8657. #endif
  8658. typedef struct _FILE_STREAM_INFORMATION {
  8659. ULONG NextEntryOffset;
  8660. ULONG StreamNameLength;
  8661. LARGE_INTEGER StreamSize;
  8662. LARGE_INTEGER StreamAllocationSize;
  8663. WCHAR StreamName[1];
  8664. } FILE_STREAM_INFORMATION, *PFILE_STREAM_INFORMATION;
  8665. typedef struct _FILE_TRACKING_INFORMATION {
  8666. HANDLE DestinationFile;
  8667. ULONG ObjectInformationLength;
  8668. CHAR ObjectInformation[1];
  8669. } FILE_TRACKING_INFORMATION, *PFILE_TRACKING_INFORMATION;
  8670. typedef struct _FILE_COMPLETION_INFORMATION {
  8671. HANDLE Port;
  8672. PVOID Key;
  8673. } FILE_COMPLETION_INFORMATION, *PFILE_COMPLETION_INFORMATION;
  8674. typedef struct _FILE_PIPE_INFORMATION {
  8675. ULONG ReadMode;
  8676. ULONG CompletionMode;
  8677. } FILE_PIPE_INFORMATION, *PFILE_PIPE_INFORMATION;
  8678. typedef struct _FILE_PIPE_LOCAL_INFORMATION {
  8679. ULONG NamedPipeType;
  8680. ULONG NamedPipeConfiguration;
  8681. ULONG MaximumInstances;
  8682. ULONG CurrentInstances;
  8683. ULONG InboundQuota;
  8684. ULONG ReadDataAvailable;
  8685. ULONG OutboundQuota;
  8686. ULONG WriteQuotaAvailable;
  8687. ULONG NamedPipeState;
  8688. ULONG NamedPipeEnd;
  8689. } FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION;
  8690. typedef struct _FILE_PIPE_REMOTE_INFORMATION {
  8691. LARGE_INTEGER CollectDataTime;
  8692. ULONG MaximumCollectionCount;
  8693. } FILE_PIPE_REMOTE_INFORMATION, *PFILE_PIPE_REMOTE_INFORMATION;
  8694. typedef struct _FILE_MAILSLOT_QUERY_INFORMATION {
  8695. ULONG MaximumMessageSize;
  8696. ULONG MailslotQuota;
  8697. ULONG NextMessageSize;
  8698. ULONG MessagesAvailable;
  8699. LARGE_INTEGER ReadTimeout;
  8700. } FILE_MAILSLOT_QUERY_INFORMATION, *PFILE_MAILSLOT_QUERY_INFORMATION;
  8701. typedef struct _FILE_MAILSLOT_SET_INFORMATION {
  8702. PLARGE_INTEGER ReadTimeout;
  8703. } FILE_MAILSLOT_SET_INFORMATION, *PFILE_MAILSLOT_SET_INFORMATION;
  8704. typedef struct _FILE_REPARSE_POINT_INFORMATION {
  8705. LONGLONG FileReference;
  8706. ULONG Tag;
  8707. } FILE_REPARSE_POINT_INFORMATION, *PFILE_REPARSE_POINT_INFORMATION;
  8708. //
  8709. // NtQuery(Set)EaFile
  8710. //
  8711. // The offset for the start of EaValue is EaName[EaNameLength + 1]
  8712. //
  8713. // begin_ntddk begin_wdm
  8714. typedef struct _FILE_FULL_EA_INFORMATION {
  8715. ULONG NextEntryOffset;
  8716. UCHAR Flags;
  8717. UCHAR EaNameLength;
  8718. USHORT EaValueLength;
  8719. CHAR EaName[1];
  8720. } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
  8721. // end_ntddk end_wdm
  8722. typedef struct _FILE_GET_EA_INFORMATION {
  8723. ULONG NextEntryOffset;
  8724. UCHAR EaNameLength;
  8725. CHAR EaName[1];
  8726. } FILE_GET_EA_INFORMATION, *PFILE_GET_EA_INFORMATION;
  8727. //
  8728. // NtQuery(Set)QuotaInformationFile
  8729. //
  8730. typedef struct _FILE_GET_QUOTA_INFORMATION {
  8731. ULONG NextEntryOffset;
  8732. ULONG SidLength;
  8733. SID Sid;
  8734. } FILE_GET_QUOTA_INFORMATION, *PFILE_GET_QUOTA_INFORMATION;
  8735. typedef struct _FILE_QUOTA_INFORMATION {
  8736. ULONG NextEntryOffset;
  8737. ULONG SidLength;
  8738. LARGE_INTEGER ChangeTime;
  8739. LARGE_INTEGER QuotaUsed;
  8740. LARGE_INTEGER QuotaThreshold;
  8741. LARGE_INTEGER QuotaLimit;
  8742. SID Sid;
  8743. } FILE_QUOTA_INFORMATION, *PFILE_QUOTA_INFORMATION;
  8744. // begin_ntddk begin_wdm begin_nthal
  8745. //
  8746. // Define the file system information class values
  8747. //
  8748. // WARNING: The order of the following values are assumed by the I/O system.
  8749. // Any changes made here should be reflected there as well.
  8750. typedef enum _FSINFOCLASS {
  8751. FileFsVolumeInformation = 1,
  8752. FileFsLabelInformation, // 2
  8753. FileFsSizeInformation, // 3
  8754. FileFsDeviceInformation, // 4
  8755. FileFsAttributeInformation, // 5
  8756. FileFsControlInformation, // 6
  8757. FileFsFullSizeInformation, // 7
  8758. FileFsObjectIdInformation, // 8
  8759. FileFsDriverPathInformation, // 9
  8760. FileFsMaximumInformation
  8761. } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
  8762. // end_ntddk end_wdm end_nthal
  8763. //
  8764. // NtQuery[Set]VolumeInformationFile types:
  8765. //
  8766. // FILE_FS_LABEL_INFORMATION
  8767. // FILE_FS_VOLUME_INFORMATION
  8768. // FILE_FS_SIZE_INFORMATION
  8769. // FILE_FS_DEVICE_INFORMATION
  8770. // FILE_FS_ATTRIBUTE_INFORMATION
  8771. // FILE_FS_CONTROL_INFORMATION
  8772. // FILE_FS_OBJECTID_INFORMATION
  8773. //
  8774. typedef struct _FILE_FS_LABEL_INFORMATION {
  8775. ULONG VolumeLabelLength;
  8776. WCHAR VolumeLabel[1];
  8777. } FILE_FS_LABEL_INFORMATION, *PFILE_FS_LABEL_INFORMATION;
  8778. typedef struct _FILE_FS_VOLUME_INFORMATION {
  8779. LARGE_INTEGER VolumeCreationTime;
  8780. ULONG VolumeSerialNumber;
  8781. ULONG VolumeLabelLength;
  8782. BOOLEAN SupportsObjects;
  8783. WCHAR VolumeLabel[1];
  8784. } FILE_FS_VOLUME_INFORMATION, *PFILE_FS_VOLUME_INFORMATION;
  8785. typedef struct _FILE_FS_SIZE_INFORMATION {
  8786. LARGE_INTEGER TotalAllocationUnits;
  8787. LARGE_INTEGER AvailableAllocationUnits;
  8788. ULONG SectorsPerAllocationUnit;
  8789. ULONG BytesPerSector;
  8790. } FILE_FS_SIZE_INFORMATION, *PFILE_FS_SIZE_INFORMATION;
  8791. typedef struct _FILE_FS_FULL_SIZE_INFORMATION {
  8792. LARGE_INTEGER TotalAllocationUnits;
  8793. LARGE_INTEGER CallerAvailableAllocationUnits;
  8794. LARGE_INTEGER ActualAvailableAllocationUnits;
  8795. ULONG SectorsPerAllocationUnit;
  8796. ULONG BytesPerSector;
  8797. } FILE_FS_FULL_SIZE_INFORMATION, *PFILE_FS_FULL_SIZE_INFORMATION;
  8798. typedef struct _FILE_FS_OBJECTID_INFORMATION {
  8799. UCHAR ObjectId[16];
  8800. UCHAR ExtendedInfo[48];
  8801. } FILE_FS_OBJECTID_INFORMATION, *PFILE_FS_OBJECTID_INFORMATION;
  8802. typedef struct _FILE_FS_DEVICE_INFORMATION { // ntddk wdm nthal
  8803. DEVICE_TYPE DeviceType; // ntddk wdm nthal
  8804. ULONG Characteristics; // ntddk wdm nthal
  8805. } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION; // ntddk wdm nthal
  8806. // ntddk wdm nthal
  8807. typedef struct _FILE_FS_ATTRIBUTE_INFORMATION {
  8808. ULONG FileSystemAttributes;
  8809. LONG MaximumComponentNameLength;
  8810. ULONG FileSystemNameLength;
  8811. WCHAR FileSystemName[1];
  8812. } FILE_FS_ATTRIBUTE_INFORMATION, *PFILE_FS_ATTRIBUTE_INFORMATION;
  8813. typedef struct _FILE_FS_DRIVER_PATH_INFORMATION {
  8814. BOOLEAN DriverInPath;
  8815. ULONG DriverNameLength;
  8816. WCHAR DriverName[1];
  8817. } FILE_FS_DRIVER_PATH_INFORMATION, *PFILE_FS_DRIVER_PATH_INFORMATION;
  8818. //
  8819. // File system control flags
  8820. //
  8821. #define FILE_VC_QUOTA_NONE 0x00000000
  8822. #define FILE_VC_QUOTA_TRACK 0x00000001
  8823. #define FILE_VC_QUOTA_ENFORCE 0x00000002
  8824. #define FILE_VC_QUOTA_MASK 0x00000003
  8825. #define FILE_VC_CONTENT_INDEX_DISABLED 0x00000008
  8826. #define FILE_VC_LOG_QUOTA_THRESHOLD 0x00000010
  8827. #define FILE_VC_LOG_QUOTA_LIMIT 0x00000020
  8828. #define FILE_VC_LOG_VOLUME_THRESHOLD 0x00000040
  8829. #define FILE_VC_LOG_VOLUME_LIMIT 0x00000080
  8830. #define FILE_VC_QUOTAS_INCOMPLETE 0x00000100
  8831. #define FILE_VC_QUOTAS_REBUILDING 0x00000200
  8832. #define FILE_VC_VALID_MASK 0x000003ff
  8833. typedef struct _FILE_FS_CONTROL_INFORMATION {
  8834. LARGE_INTEGER FreeSpaceStartFiltering;
  8835. LARGE_INTEGER FreeSpaceThreshold;
  8836. LARGE_INTEGER FreeSpaceStopFiltering;
  8837. LARGE_INTEGER DefaultQuotaThreshold;
  8838. LARGE_INTEGER DefaultQuotaLimit;
  8839. ULONG FileSystemControlFlags;
  8840. } FILE_FS_CONTROL_INFORMATION, *PFILE_FS_CONTROL_INFORMATION;
  8841. // begin_winnt begin_ntddk begin_nthal
  8842. //
  8843. // Define segement buffer structure for scatter/gather read/write.
  8844. //
  8845. typedef union _FILE_SEGMENT_ELEMENT {
  8846. PVOID64 Buffer;
  8847. ULONGLONG Alignment;
  8848. }FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
  8849. NTSYSCALLAPI
  8850. NTSTATUS
  8851. NTAPI
  8852. NtCreateFile(
  8853. OUT PHANDLE FileHandle,
  8854. IN ACCESS_MASK DesiredAccess,
  8855. IN POBJECT_ATTRIBUTES ObjectAttributes,
  8856. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8857. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  8858. IN ULONG FileAttributes,
  8859. IN ULONG ShareAccess,
  8860. IN ULONG CreateDisposition,
  8861. IN ULONG CreateOptions,
  8862. IN PVOID EaBuffer OPTIONAL,
  8863. IN ULONG EaLength
  8864. );
  8865. NTSYSCALLAPI
  8866. NTSTATUS
  8867. NTAPI
  8868. NtDeviceIoControlFile(
  8869. IN HANDLE FileHandle,
  8870. IN HANDLE Event OPTIONAL,
  8871. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8872. IN PVOID ApcContext OPTIONAL,
  8873. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8874. IN ULONG IoControlCode,
  8875. IN PVOID InputBuffer OPTIONAL,
  8876. IN ULONG InputBufferLength,
  8877. OUT PVOID OutputBuffer OPTIONAL,
  8878. IN ULONG OutputBufferLength
  8879. );
  8880. NTSYSCALLAPI
  8881. NTSTATUS
  8882. NTAPI
  8883. NtFsControlFile(
  8884. IN HANDLE FileHandle,
  8885. IN HANDLE Event OPTIONAL,
  8886. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8887. IN PVOID ApcContext OPTIONAL,
  8888. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8889. IN ULONG FsControlCode,
  8890. IN PVOID InputBuffer OPTIONAL,
  8891. IN ULONG InputBufferLength,
  8892. OUT PVOID OutputBuffer OPTIONAL,
  8893. IN ULONG OutputBufferLength
  8894. );
  8895. NTSYSCALLAPI
  8896. NTSTATUS
  8897. NTAPI
  8898. NtLockFile(
  8899. IN HANDLE FileHandle,
  8900. IN HANDLE Event OPTIONAL,
  8901. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8902. IN PVOID ApcContext OPTIONAL,
  8903. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8904. IN PLARGE_INTEGER ByteOffset,
  8905. IN PLARGE_INTEGER Length,
  8906. IN ULONG Key,
  8907. IN BOOLEAN FailImmediately,
  8908. IN BOOLEAN ExclusiveLock
  8909. );
  8910. NTSYSCALLAPI
  8911. NTSTATUS
  8912. NTAPI
  8913. NtOpenFile(
  8914. OUT PHANDLE FileHandle,
  8915. IN ACCESS_MASK DesiredAccess,
  8916. IN POBJECT_ATTRIBUTES ObjectAttributes,
  8917. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8918. IN ULONG ShareAccess,
  8919. IN ULONG OpenOptions
  8920. );
  8921. NTSYSCALLAPI
  8922. NTSTATUS
  8923. NTAPI
  8924. NtQueryDirectoryFile(
  8925. IN HANDLE FileHandle,
  8926. IN HANDLE Event OPTIONAL,
  8927. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8928. IN PVOID ApcContext OPTIONAL,
  8929. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8930. OUT PVOID FileInformation,
  8931. IN ULONG Length,
  8932. IN FILE_INFORMATION_CLASS FileInformationClass,
  8933. IN BOOLEAN ReturnSingleEntry,
  8934. IN PUNICODE_STRING FileName OPTIONAL,
  8935. IN BOOLEAN RestartScan
  8936. );
  8937. NTSYSCALLAPI
  8938. NTSTATUS
  8939. NTAPI
  8940. NtQueryInformationFile(
  8941. IN HANDLE FileHandle,
  8942. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8943. OUT PVOID FileInformation,
  8944. IN ULONG Length,
  8945. IN FILE_INFORMATION_CLASS FileInformationClass
  8946. );
  8947. NTSYSCALLAPI
  8948. NTSTATUS
  8949. NTAPI
  8950. NtQueryQuotaInformationFile(
  8951. IN HANDLE FileHandle,
  8952. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8953. OUT PVOID Buffer,
  8954. IN ULONG Length,
  8955. IN BOOLEAN ReturnSingleEntry,
  8956. IN PVOID SidList OPTIONAL,
  8957. IN ULONG SidListLength,
  8958. IN PSID StartSid OPTIONAL,
  8959. IN BOOLEAN RestartScan
  8960. );
  8961. NTSYSCALLAPI
  8962. NTSTATUS
  8963. NTAPI
  8964. NtQueryVolumeInformationFile(
  8965. IN HANDLE FileHandle,
  8966. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8967. OUT PVOID FsInformation,
  8968. IN ULONG Length,
  8969. IN FS_INFORMATION_CLASS FsInformationClass
  8970. );
  8971. NTSYSCALLAPI
  8972. NTSTATUS
  8973. NTAPI
  8974. NtReadFile(
  8975. IN HANDLE FileHandle,
  8976. IN HANDLE Event OPTIONAL,
  8977. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  8978. IN PVOID ApcContext OPTIONAL,
  8979. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8980. OUT PVOID Buffer,
  8981. IN ULONG Length,
  8982. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  8983. IN PULONG Key OPTIONAL
  8984. );
  8985. NTSYSCALLAPI
  8986. NTSTATUS
  8987. NTAPI
  8988. NtSetInformationFile(
  8989. IN HANDLE FileHandle,
  8990. OUT PIO_STATUS_BLOCK IoStatusBlock,
  8991. IN PVOID FileInformation,
  8992. IN ULONG Length,
  8993. IN FILE_INFORMATION_CLASS FileInformationClass
  8994. );
  8995. NTSYSCALLAPI
  8996. NTSTATUS
  8997. NTAPI
  8998. NtSetQuotaInformationFile(
  8999. IN HANDLE FileHandle,
  9000. OUT PIO_STATUS_BLOCK IoStatusBlock,
  9001. IN PVOID Buffer,
  9002. IN ULONG Length
  9003. );
  9004. NTSYSCALLAPI
  9005. NTSTATUS
  9006. NTAPI
  9007. NtSetVolumeInformationFile(
  9008. IN HANDLE FileHandle,
  9009. OUT PIO_STATUS_BLOCK IoStatusBlock,
  9010. IN PVOID FsInformation,
  9011. IN ULONG Length,
  9012. IN FS_INFORMATION_CLASS FsInformationClass
  9013. );
  9014. NTSYSCALLAPI
  9015. NTSTATUS
  9016. NTAPI
  9017. NtWriteFile(
  9018. IN HANDLE FileHandle,
  9019. IN HANDLE Event OPTIONAL,
  9020. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  9021. IN PVOID ApcContext OPTIONAL,
  9022. OUT PIO_STATUS_BLOCK IoStatusBlock,
  9023. IN PVOID Buffer,
  9024. IN ULONG Length,
  9025. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  9026. IN PULONG Key OPTIONAL
  9027. );
  9028. NTSYSCALLAPI
  9029. NTSTATUS
  9030. NTAPI
  9031. NtUnlockFile(
  9032. IN HANDLE FileHandle,
  9033. OUT PIO_STATUS_BLOCK IoStatusBlock,
  9034. IN PLARGE_INTEGER ByteOffset,
  9035. IN PLARGE_INTEGER Length,
  9036. IN ULONG Key
  9037. );
  9038. //
  9039. // Macro definition for defining IOCTL and FSCTL function control codes. Note
  9040. // that function codes 0-2047 are reserved for Microsoft Corporation, and
  9041. // 2048-4095 are reserved for customers.
  9042. //
  9043. // These macros are defined in devioctl.h which contains the portable IO
  9044. // definitions (for use by both DOS and NT)
  9045. //
  9046. //
  9047. // The IoGetFunctionCodeFromCtlCode( ControlCode ) Macro is defined in io.h
  9048. // This macro is used to extract the function code from an IOCTL (or FSCTL).
  9049. // The macro can only be used in kernel mode code.
  9050. //
  9051. //
  9052. // General File System control codes - Note that these values are valid
  9053. // regardless of the actual file system type
  9054. //
  9055. //
  9056. // IMPORTANT: These values have been arranged in order of increasing
  9057. // control codes. Do NOT breaks this!! Add all new codes
  9058. // at end of list regardless of functionality type.
  9059. //
  9060. // Note: FSCTL_QUERY_RETRIEVAL_POINTER and FSCTL_MARK_AS_SYSTEM_HIVE only
  9061. // work from Kernel mode on local paging files or the system hives.
  9062. //
  9063. // begin_winioctl
  9064. #ifndef _FILESYSTEMFSCTL_
  9065. #define _FILESYSTEMFSCTL_
  9066. //
  9067. // The following is a list of the native file system fsctls followed by
  9068. // additional network file system fsctls. Some values have been
  9069. // decommissioned.
  9070. //
  9071. #define FSCTL_REQUEST_OPLOCK_LEVEL_1 CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 0, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9072. #define FSCTL_REQUEST_OPLOCK_LEVEL_2 CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 1, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9073. #define FSCTL_REQUEST_BATCH_OPLOCK CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9074. #define FSCTL_OPLOCK_BREAK_ACKNOWLEDGE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 3, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9075. #define FSCTL_OPBATCH_ACK_CLOSE_PENDING CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 4, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9076. #define FSCTL_OPLOCK_BREAK_NOTIFY CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 5, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9077. #define FSCTL_LOCK_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 6, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9078. #define FSCTL_UNLOCK_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 7, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9079. #define FSCTL_DISMOUNT_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 8, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9080. // decommissioned fsctl value 9
  9081. #define FSCTL_IS_VOLUME_MOUNTED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 10, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9082. #define FSCTL_IS_PATHNAME_VALID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 11, METHOD_BUFFERED, FILE_ANY_ACCESS) // PATHNAME_BUFFER,
  9083. #define FSCTL_MARK_VOLUME_DIRTY CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 12, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9084. // decommissioned fsctl value 13
  9085. #define FSCTL_QUERY_RETRIEVAL_POINTERS CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 14, METHOD_NEITHER, FILE_ANY_ACCESS)
  9086. #define FSCTL_GET_COMPRESSION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9087. #define FSCTL_SET_COMPRESSION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 16, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
  9088. // decommissioned fsctl value 17
  9089. // decommissioned fsctl value 18
  9090. #define FSCTL_MARK_AS_SYSTEM_HIVE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 19, METHOD_NEITHER, FILE_ANY_ACCESS)
  9091. #define FSCTL_OPLOCK_BREAK_ACK_NO_2 CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 20, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9092. #define FSCTL_INVALIDATE_VOLUMES CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 21, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9093. #define FSCTL_QUERY_FAT_BPB CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 22, METHOD_BUFFERED, FILE_ANY_ACCESS) // FSCTL_QUERY_FAT_BPB_BUFFER
  9094. #define FSCTL_REQUEST_FILTER_OPLOCK CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 23, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9095. #define FSCTL_FILESYSTEM_GET_STATISTICS CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 24, METHOD_BUFFERED, FILE_ANY_ACCESS) // FILESYSTEM_STATISTICS
  9096. #if(_WIN32_WINNT >= 0x0400)
  9097. #define FSCTL_GET_NTFS_VOLUME_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 25, METHOD_BUFFERED, FILE_ANY_ACCESS) // NTFS_VOLUME_DATA_BUFFER
  9098. #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
  9099. #define FSCTL_GET_VOLUME_BITMAP CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 27, METHOD_NEITHER, FILE_ANY_ACCESS) // STARTING_LCN_INPUT_BUFFER, VOLUME_BITMAP_BUFFER
  9100. #define FSCTL_GET_RETRIEVAL_POINTERS CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 28, METHOD_NEITHER, FILE_ANY_ACCESS) // STARTING_VCN_INPUT_BUFFER, RETRIEVAL_POINTERS_BUFFER
  9101. #define FSCTL_MOVE_FILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 29, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // MOVE_FILE_DATA,
  9102. #define FSCTL_IS_VOLUME_DIRTY CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 30, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9103. // decomissioned fsctl value 31
  9104. #define FSCTL_ALLOW_EXTENDED_DASD_IO CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 32, METHOD_NEITHER, FILE_ANY_ACCESS)
  9105. #endif /* _WIN32_WINNT >= 0x0400 */
  9106. #if(_WIN32_WINNT >= 0x0500)
  9107. // decommissioned fsctl value 33
  9108. // decommissioned fsctl value 34
  9109. #define FSCTL_FIND_FILES_BY_SID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 35, METHOD_NEITHER, FILE_ANY_ACCESS) // FIND_BY_SID_DATA, FIND_BY_SID_OUTPUT
  9110. // decommissioned fsctl value 36
  9111. // decommissioned fsctl value 37
  9112. #define FSCTL_SET_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 38, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // FILE_OBJECTID_BUFFER
  9113. #define FSCTL_GET_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 39, METHOD_BUFFERED, FILE_ANY_ACCESS) // FILE_OBJECTID_BUFFER
  9114. #define FSCTL_DELETE_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 40, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
  9115. #define FSCTL_SET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // REPARSE_DATA_BUFFER,
  9116. #define FSCTL_GET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_ANY_ACCESS) // REPARSE_DATA_BUFFER
  9117. #define FSCTL_DELETE_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 43, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // REPARSE_DATA_BUFFER,
  9118. #define FSCTL_ENUM_USN_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 44, METHOD_NEITHER, FILE_ANY_ACCESS) // MFT_ENUM_DATA,
  9119. #define FSCTL_SECURITY_ID_CHECK CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 45, METHOD_NEITHER, FILE_READ_DATA) // BULK_SECURITY_TEST_DATA,
  9120. #define FSCTL_READ_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 46, METHOD_NEITHER, FILE_ANY_ACCESS) // READ_USN_JOURNAL_DATA, USN
  9121. #define FSCTL_SET_OBJECT_ID_EXTENDED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 47, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
  9122. #define FSCTL_CREATE_OR_GET_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 48, METHOD_BUFFERED, FILE_ANY_ACCESS) // FILE_OBJECTID_BUFFER
  9123. #define FSCTL_SET_SPARSE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
  9124. #define FSCTL_SET_ZERO_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 50, METHOD_BUFFERED, FILE_WRITE_DATA) // FILE_ZERO_DATA_INFORMATION,
  9125. #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
  9126. // decommissioned fsctl value 52
  9127. #define FSCTL_SET_ENCRYPTION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 53, METHOD_NEITHER, FILE_ANY_ACCESS) // ENCRYPTION_BUFFER, DECRYPTION_STATUS_BUFFER
  9128. #define FSCTL_ENCRYPTION_FSCTL_IO CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 54, METHOD_NEITHER, FILE_ANY_ACCESS)
  9129. #define FSCTL_WRITE_RAW_ENCRYPTED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 55, METHOD_NEITHER, FILE_SPECIAL_ACCESS) // ENCRYPTED_DATA_INFO,
  9130. #define FSCTL_READ_RAW_ENCRYPTED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 56, METHOD_NEITHER, FILE_SPECIAL_ACCESS) // REQUEST_RAW_ENCRYPTED_DATA, ENCRYPTED_DATA_INFO
  9131. #define FSCTL_CREATE_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 57, METHOD_NEITHER, FILE_ANY_ACCESS) // CREATE_USN_JOURNAL_DATA,
  9132. #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
  9133. #define FSCTL_WRITE_USN_CLOSE_RECORD CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 59, METHOD_NEITHER, FILE_ANY_ACCESS) // Generate Close Usn Record
  9134. #define FSCTL_EXTEND_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 60, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9135. #define FSCTL_QUERY_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 61, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9136. #define FSCTL_DELETE_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 62, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9137. #define FSCTL_MARK_HANDLE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 63, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9138. #define FSCTL_SIS_COPYFILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 64, METHOD_BUFFERED, FILE_ANY_ACCESS)
  9139. #define FSCTL_SIS_LINK_FILES CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 65, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
  9140. #define FSCTL_HSM_MSG CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 66, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
  9141. // decommissioned fsctl value 67
  9142. #define FSCTL_HSM_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 68, METHOD_NEITHER, FILE_READ_DATA | FILE_WRITE_DATA)
  9143. #define FSCTL_RECALL_FILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 69, METHOD_NEITHER, FILE_ANY_ACCESS)
  9144. // decommissioned fsctl value 70
  9145. #define FSCTL_READ_FROM_PLEX CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 71, METHOD_OUT_DIRECT, FILE_READ_DATA)
  9146. #define FSCTL_FILE_PREFETCH CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 72, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // FILE_PREFETCH
  9147. #endif /* _WIN32_WINNT >= 0x0500 */
  9148. //
  9149. // The following long list of structs are associated with the preceeding
  9150. // file system fsctls.
  9151. //
  9152. //
  9153. // Structure for FSCTL_IS_PATHNAME_VALID
  9154. //
  9155. typedef struct _PATHNAME_BUFFER {
  9156. ULONG PathNameLength;
  9157. WCHAR Name[1];
  9158. } PATHNAME_BUFFER, *PPATHNAME_BUFFER;
  9159. //
  9160. // Structure for FSCTL_QUERY_BPB_INFO
  9161. //
  9162. typedef struct _FSCTL_QUERY_FAT_BPB_BUFFER {
  9163. UCHAR First0x24BytesOfBootSector[0x24];
  9164. } FSCTL_QUERY_FAT_BPB_BUFFER, *PFSCTL_QUERY_FAT_BPB_BUFFER;
  9165. #if(_WIN32_WINNT >= 0x0400)
  9166. //
  9167. // Structures for FSCTL_GET_NTFS_VOLUME_DATA.
  9168. // The user must pass the basic buffer below. Ntfs
  9169. // will return as many fields as available in the extended
  9170. // buffer which follows immediately after the VOLUME_DATA_BUFFER.
  9171. //
  9172. typedef struct {
  9173. LARGE_INTEGER VolumeSerialNumber;
  9174. LARGE_INTEGER NumberSectors;
  9175. LARGE_INTEGER TotalClusters;
  9176. LARGE_INTEGER FreeClusters;
  9177. LARGE_INTEGER TotalReserved;
  9178. ULONG BytesPerSector;
  9179. ULONG BytesPerCluster;
  9180. ULONG BytesPerFileRecordSegment;
  9181. ULONG ClustersPerFileRecordSegment;
  9182. LARGE_INTEGER MftValidDataLength;
  9183. LARGE_INTEGER MftStartLcn;
  9184. LARGE_INTEGER Mft2StartLcn;
  9185. LARGE_INTEGER MftZoneStart;
  9186. LARGE_INTEGER MftZoneEnd;
  9187. } NTFS_VOLUME_DATA_BUFFER, *PNTFS_VOLUME_DATA_BUFFER;
  9188. typedef struct {
  9189. ULONG ByteCount;
  9190. USHORT MajorVersion;
  9191. USHORT MinorVersion;
  9192. } NTFS_EXTENDED_VOLUME_DATA, *PNTFS_EXTENDED_VOLUME_DATA;
  9193. #endif /* _WIN32_WINNT >= 0x0400 */
  9194. #if(_WIN32_WINNT >= 0x0400)
  9195. //
  9196. // Structure for FSCTL_GET_VOLUME_BITMAP
  9197. //
  9198. typedef struct {
  9199. LARGE_INTEGER StartingLcn;
  9200. } STARTING_LCN_INPUT_BUFFER, *PSTARTING_LCN_INPUT_BUFFER;
  9201. typedef struct {
  9202. LARGE_INTEGER StartingLcn;
  9203. LARGE_INTEGER BitmapSize;
  9204. UCHAR Buffer[1];
  9205. } VOLUME_BITMAP_BUFFER, *PVOLUME_BITMAP_BUFFER;
  9206. #endif /* _WIN32_WINNT >= 0x0400 */
  9207. #if(_WIN32_WINNT >= 0x0400)
  9208. //
  9209. // Structure for FSCTL_GET_RETRIEVAL_POINTERS
  9210. //
  9211. typedef struct {
  9212. LARGE_INTEGER StartingVcn;
  9213. } STARTING_VCN_INPUT_BUFFER, *PSTARTING_VCN_INPUT_BUFFER;
  9214. typedef struct RETRIEVAL_POINTERS_BUFFER {
  9215. ULONG ExtentCount;
  9216. LARGE_INTEGER StartingVcn;
  9217. struct {
  9218. LARGE_INTEGER NextVcn;
  9219. LARGE_INTEGER Lcn;
  9220. } Extents[1];
  9221. } RETRIEVAL_POINTERS_BUFFER, *PRETRIEVAL_POINTERS_BUFFER;
  9222. #endif /* _WIN32_WINNT >= 0x0400 */
  9223. #if(_WIN32_WINNT >= 0x0400)
  9224. //
  9225. // Structures for FSCTL_GET_NTFS_FILE_RECORD
  9226. //
  9227. typedef struct {
  9228. LARGE_INTEGER FileReferenceNumber;
  9229. } NTFS_FILE_RECORD_INPUT_BUFFER, *PNTFS_FILE_RECORD_INPUT_BUFFER;
  9230. typedef struct {
  9231. LARGE_INTEGER FileReferenceNumber;
  9232. ULONG FileRecordLength;
  9233. UCHAR FileRecordBuffer[1];
  9234. } NTFS_FILE_RECORD_OUTPUT_BUFFER, *PNTFS_FILE_RECORD_OUTPUT_BUFFER;
  9235. #endif /* _WIN32_WINNT >= 0x0400 */
  9236. #if(_WIN32_WINNT >= 0x0400)
  9237. //
  9238. // Structure for FSCTL_MOVE_FILE
  9239. //
  9240. typedef struct {
  9241. HANDLE FileHandle;
  9242. LARGE_INTEGER StartingVcn;
  9243. LARGE_INTEGER StartingLcn;
  9244. ULONG ClusterCount;
  9245. } MOVE_FILE_DATA, *PMOVE_FILE_DATA;
  9246. #if defined(_WIN64)
  9247. //
  9248. // 32/64 Bit thunking support structure
  9249. //
  9250. typedef struct _MOVE_FILE_DATA32 {
  9251. UINT32 FileHandle;
  9252. LARGE_INTEGER StartingVcn;
  9253. LARGE_INTEGER StartingLcn;
  9254. ULONG ClusterCount;
  9255. } MOVE_FILE_DATA32, *PMOVE_FILE_DATA32;
  9256. #endif
  9257. #endif /* _WIN32_WINNT >= 0x0400 */
  9258. #if(_WIN32_WINNT >= 0x0500)
  9259. //
  9260. // Structures for FSCTL_FIND_FILES_BY_SID
  9261. //
  9262. typedef struct {
  9263. ULONG Restart;
  9264. SID Sid;
  9265. } FIND_BY_SID_DATA, *PFIND_BY_SID_DATA;
  9266. typedef struct {
  9267. ULONG NextEntryOffset;
  9268. ULONG FileIndex;
  9269. ULONG FileNameLength;
  9270. WCHAR FileName[1];
  9271. } FIND_BY_SID_OUTPUT, *PFIND_BY_SID_OUTPUT;
  9272. #endif /* _WIN32_WINNT >= 0x0500 */
  9273. #if(_WIN32_WINNT >= 0x0500)
  9274. //
  9275. // The following structures apply to Usn operations.
  9276. //
  9277. //
  9278. // Structure for FSCTL_ENUM_USN_DATA
  9279. //
  9280. typedef struct {
  9281. ULONGLONG StartFileReferenceNumber;
  9282. USN LowUsn;
  9283. USN HighUsn;
  9284. } MFT_ENUM_DATA, *PMFT_ENUM_DATA;
  9285. //
  9286. // Structure for FSCTL_CREATE_USN_JOURNAL
  9287. //
  9288. typedef struct {
  9289. ULONGLONG MaximumSize;
  9290. ULONGLONG AllocationDelta;
  9291. } CREATE_USN_JOURNAL_DATA, *PCREATE_USN_JOURNAL_DATA;
  9292. //
  9293. // Structure for FSCTL_READ_USN_JOURNAL
  9294. //
  9295. typedef struct {
  9296. USN StartUsn;
  9297. ULONG ReasonMask;
  9298. ULONG ReturnOnlyOnClose;
  9299. ULONGLONG Timeout;
  9300. ULONGLONG BytesToWaitFor;
  9301. ULONGLONG UsnJournalID;
  9302. } READ_USN_JOURNAL_DATA, *PREAD_USN_JOURNAL_DATA;
  9303. //
  9304. // The initial Major.Minor version of the Usn record will be 2.0.
  9305. // In general, the MinorVersion may be changed if fields are added
  9306. // to this structure in such a way that the previous version of the
  9307. // software can still correctly the fields it knows about. The
  9308. // MajorVersion should only be changed if the previous version of
  9309. // any software using this structure would incorrectly handle new
  9310. // records due to structure changes.
  9311. //
  9312. // The first update to this will force the structure to version 2.0.
  9313. // This will add the extended information about the source as
  9314. // well as indicate the file name offset within the structure.
  9315. //
  9316. // The following structure is returned with these fsctls.
  9317. //
  9318. // FSCTL_READ_USN_JOURNAL
  9319. // FSCTL_READ_FILE_USN_DATA
  9320. // FSCTL_ENUM_USN_DATA
  9321. //
  9322. typedef struct {
  9323. ULONG RecordLength;
  9324. USHORT MajorVersion;
  9325. USHORT MinorVersion;
  9326. ULONGLONG FileReferenceNumber;
  9327. ULONGLONG ParentFileReferenceNumber;
  9328. USN Usn;
  9329. LARGE_INTEGER TimeStamp;
  9330. ULONG Reason;
  9331. ULONG SourceInfo;
  9332. ULONG SecurityId;
  9333. ULONG FileAttributes;
  9334. USHORT FileNameLength;
  9335. USHORT FileNameOffset;
  9336. WCHAR FileName[1];
  9337. } USN_RECORD, *PUSN_RECORD;
  9338. #define USN_PAGE_SIZE (0x1000)
  9339. #define USN_REASON_DATA_OVERWRITE (0x00000001)
  9340. #define USN_REASON_DATA_EXTEND (0x00000002)
  9341. #define USN_REASON_DATA_TRUNCATION (0x00000004)
  9342. #define USN_REASON_NAMED_DATA_OVERWRITE (0x00000010)
  9343. #define USN_REASON_NAMED_DATA_EXTEND (0x00000020)
  9344. #define USN_REASON_NAMED_DATA_TRUNCATION (0x00000040)
  9345. #define USN_REASON_FILE_CREATE (0x00000100)
  9346. #define USN_REASON_FILE_DELETE (0x00000200)
  9347. #define USN_REASON_EA_CHANGE (0x00000400)
  9348. #define USN_REASON_SECURITY_CHANGE (0x00000800)
  9349. #define USN_REASON_RENAME_OLD_NAME (0x00001000)
  9350. #define USN_REASON_RENAME_NEW_NAME (0x00002000)
  9351. #define USN_REASON_INDEXABLE_CHANGE (0x00004000)
  9352. #define USN_REASON_BASIC_INFO_CHANGE (0x00008000)
  9353. #define USN_REASON_HARD_LINK_CHANGE (0x00010000)
  9354. #define USN_REASON_COMPRESSION_CHANGE (0x00020000)
  9355. #define USN_REASON_ENCRYPTION_CHANGE (0x00040000)
  9356. #define USN_REASON_OBJECT_ID_CHANGE (0x00080000)
  9357. #define USN_REASON_REPARSE_POINT_CHANGE (0x00100000)
  9358. #define USN_REASON_STREAM_CHANGE (0x00200000)
  9359. #define USN_REASON_CLOSE (0x80000000)
  9360. //
  9361. // Structure for FSCTL_QUERY_USN_JOUNAL
  9362. //
  9363. typedef struct {
  9364. ULONGLONG UsnJournalID;
  9365. USN FirstUsn;
  9366. USN NextUsn;
  9367. USN LowestValidUsn;
  9368. USN MaxUsn;
  9369. ULONGLONG MaximumSize;
  9370. ULONGLONG AllocationDelta;
  9371. } USN_JOURNAL_DATA, *PUSN_JOURNAL_DATA;
  9372. //
  9373. // Structure for FSCTL_DELETE_USN_JOURNAL
  9374. //
  9375. typedef struct {
  9376. ULONGLONG UsnJournalID;
  9377. ULONG DeleteFlags;
  9378. } DELETE_USN_JOURNAL_DATA, *PDELETE_USN_JOURNAL_DATA;
  9379. #define USN_DELETE_FLAG_DELETE (0x00000001)
  9380. #define USN_DELETE_FLAG_NOTIFY (0x00000002)
  9381. #define USN_DELETE_VALID_FLAGS (0x00000003)
  9382. //
  9383. // Structure for FSCTL_MARK_HANDLE
  9384. //
  9385. typedef struct {
  9386. ULONG UsnSourceInfo;
  9387. HANDLE VolumeHandle;
  9388. ULONG HandleInfo;
  9389. } MARK_HANDLE_INFO, *PMARK_HANDLE_INFO;
  9390. #if defined(_WIN64)
  9391. //
  9392. // 32/64 Bit thunking support structure
  9393. //
  9394. typedef struct {
  9395. ULONG UsnSourceInfo;
  9396. UINT32 VolumeHandle;
  9397. ULONG HandleInfo;
  9398. } MARK_HANDLE_INFO32, *PMARK_HANDLE_INFO32;
  9399. #endif
  9400. //
  9401. // Flags for the additional source information above.
  9402. //
  9403. // USN_SOURCE_DATA_MANAGEMENT - Service is not modifying the external view
  9404. // of any part of the file. Typical case is HSM moving data to
  9405. // and from external storage.
  9406. //
  9407. // USN_SOURCE_AUXILIARY_DATA - Service is not modifying the external view
  9408. // of the file with regard to the application that created this file.
  9409. // Can be used to add private data streams to a file.
  9410. //
  9411. // USN_SOURCE_REPLICATION_MANAGEMENT - Service is modifying a file to match
  9412. // the contents of the same file which exists in another member of the
  9413. // replica set.
  9414. //
  9415. #define USN_SOURCE_DATA_MANAGEMENT (0x00000001)
  9416. #define USN_SOURCE_AUXILIARY_DATA (0x00000002)
  9417. #define USN_SOURCE_REPLICATION_MANAGEMENT (0x00000004)
  9418. //
  9419. // Flags for the HandleInfo field above
  9420. //
  9421. // MARK_HANDLE_PROTECT_CLUSTERS - disallow any defragmenting (FSCTL_MOVE_FILE) until the
  9422. // the handle is closed
  9423. //
  9424. #define MARK_HANDLE_PROTECT_CLUSTERS (0x00000001)
  9425. #endif /* _WIN32_WINNT >= 0x0500 */
  9426. #if(_WIN32_WINNT >= 0x0500)
  9427. //
  9428. // Structure for FSCTL_SECURITY_ID_CHECK
  9429. //
  9430. typedef struct {
  9431. ACCESS_MASK DesiredAccess;
  9432. ULONG SecurityIds[1];
  9433. } BULK_SECURITY_TEST_DATA, *PBULK_SECURITY_TEST_DATA;
  9434. #endif /* _WIN32_WINNT >= 0x0500 */
  9435. #if(_WIN32_WINNT >= 0x0500)
  9436. //
  9437. // Output flags for the FSCTL_IS_VOLUME_DIRTY
  9438. //
  9439. #define VOLUME_IS_DIRTY (0x00000001)
  9440. #define VOLUME_UPGRADE_SCHEDULED (0x00000002)
  9441. #endif /* _WIN32_WINNT >= 0x0500 */
  9442. //
  9443. // Structures for FSCTL_FILE_PREFETCH
  9444. //
  9445. typedef struct _FILE_PREFETCH {
  9446. ULONG Type;
  9447. ULONG Count;
  9448. ULONGLONG Prefetch[1];
  9449. } FILE_PREFETCH, *PFILE_PREFETCH;
  9450. #define FILE_PREFETCH_TYPE_FOR_CREATE 0x1
  9451. // Structures for FSCTL_FILESYSTEM_GET_STATISTICS
  9452. //
  9453. // Filesystem performance counters
  9454. //
  9455. typedef struct _FILESYSTEM_STATISTICS {
  9456. USHORT FileSystemType;
  9457. USHORT Version; // currently version 1
  9458. ULONG SizeOfCompleteStructure; // must by a mutiple of 64 bytes
  9459. ULONG UserFileReads;
  9460. ULONG UserFileReadBytes;
  9461. ULONG UserDiskReads;
  9462. ULONG UserFileWrites;
  9463. ULONG UserFileWriteBytes;
  9464. ULONG UserDiskWrites;
  9465. ULONG MetaDataReads;
  9466. ULONG MetaDataReadBytes;
  9467. ULONG MetaDataDiskReads;
  9468. ULONG MetaDataWrites;
  9469. ULONG MetaDataWriteBytes;
  9470. ULONG MetaDataDiskWrites;
  9471. //
  9472. // The file system's private structure is appended here.
  9473. //
  9474. } FILESYSTEM_STATISTICS, *PFILESYSTEM_STATISTICS;
  9475. // values for FS_STATISTICS.FileSystemType
  9476. #define FILESYSTEM_STATISTICS_TYPE_NTFS 1
  9477. #define FILESYSTEM_STATISTICS_TYPE_FAT 2
  9478. //
  9479. // File System Specific Statistics Data
  9480. //
  9481. typedef struct _FAT_STATISTICS {
  9482. ULONG CreateHits;
  9483. ULONG SuccessfulCreates;
  9484. ULONG FailedCreates;
  9485. ULONG NonCachedReads;
  9486. ULONG NonCachedReadBytes;
  9487. ULONG NonCachedWrites;
  9488. ULONG NonCachedWriteBytes;
  9489. ULONG NonCachedDiskReads;
  9490. ULONG NonCachedDiskWrites;
  9491. } FAT_STATISTICS, *PFAT_STATISTICS;
  9492. typedef struct _NTFS_STATISTICS {
  9493. ULONG LogFileFullExceptions;
  9494. ULONG OtherExceptions;
  9495. //
  9496. // Other meta data io's
  9497. //
  9498. ULONG MftReads;
  9499. ULONG MftReadBytes;
  9500. ULONG MftWrites;
  9501. ULONG MftWriteBytes;
  9502. struct {
  9503. USHORT Write;
  9504. USHORT Create;
  9505. USHORT SetInfo;
  9506. USHORT Flush;
  9507. } MftWritesUserLevel;
  9508. USHORT MftWritesFlushForLogFileFull;
  9509. USHORT MftWritesLazyWriter;
  9510. USHORT MftWritesUserRequest;
  9511. ULONG Mft2Writes;
  9512. ULONG Mft2WriteBytes;
  9513. struct {
  9514. USHORT Write;
  9515. USHORT Create;
  9516. USHORT SetInfo;
  9517. USHORT Flush;
  9518. } Mft2WritesUserLevel;
  9519. USHORT Mft2WritesFlushForLogFileFull;
  9520. USHORT Mft2WritesLazyWriter;
  9521. USHORT Mft2WritesUserRequest;
  9522. ULONG RootIndexReads;
  9523. ULONG RootIndexReadBytes;
  9524. ULONG RootIndexWrites;
  9525. ULONG RootIndexWriteBytes;
  9526. ULONG BitmapReads;
  9527. ULONG BitmapReadBytes;
  9528. ULONG BitmapWrites;
  9529. ULONG BitmapWriteBytes;
  9530. USHORT BitmapWritesFlushForLogFileFull;
  9531. USHORT BitmapWritesLazyWriter;
  9532. USHORT BitmapWritesUserRequest;
  9533. struct {
  9534. USHORT Write;
  9535. USHORT Create;
  9536. USHORT SetInfo;
  9537. } BitmapWritesUserLevel;
  9538. ULONG MftBitmapReads;
  9539. ULONG MftBitmapReadBytes;
  9540. ULONG MftBitmapWrites;
  9541. ULONG MftBitmapWriteBytes;
  9542. USHORT MftBitmapWritesFlushForLogFileFull;
  9543. USHORT MftBitmapWritesLazyWriter;
  9544. USHORT MftBitmapWritesUserRequest;
  9545. struct {
  9546. USHORT Write;
  9547. USHORT Create;
  9548. USHORT SetInfo;
  9549. USHORT Flush;
  9550. } MftBitmapWritesUserLevel;
  9551. ULONG UserIndexReads;
  9552. ULONG UserIndexReadBytes;
  9553. ULONG UserIndexWrites;
  9554. ULONG UserIndexWriteBytes;
  9555. //
  9556. // Additions for NT 5.0
  9557. //
  9558. ULONG LogFileReads;
  9559. ULONG LogFileReadBytes;
  9560. ULONG LogFileWrites;
  9561. ULONG LogFileWriteBytes;
  9562. struct {
  9563. ULONG Calls; // number of individual calls to allocate clusters
  9564. ULONG Clusters; // number of clusters allocated
  9565. ULONG Hints; // number of times a hint was specified
  9566. ULONG RunsReturned; // number of runs used to satisify all the requests
  9567. ULONG HintsHonored; // number of times the hint was useful
  9568. ULONG HintsClusters; // number of clusters allocated via the hint
  9569. ULONG Cache; // number of times the cache was useful other than the hint
  9570. ULONG CacheClusters; // number of clusters allocated via the cache other than the hint
  9571. ULONG CacheMiss; // number of times the cache wasn't useful
  9572. ULONG CacheMissClusters; // number of clusters allocated without the cache
  9573. } Allocate;
  9574. } NTFS_STATISTICS, *PNTFS_STATISTICS;
  9575. #if(_WIN32_WINNT >= 0x0500)
  9576. //
  9577. // Structure for FSCTL_SET_OBJECT_ID, FSCTL_GET_OBJECT_ID, and FSCTL_CREATE_OR_GET_OBJECT_ID
  9578. //
  9579. #if _MSC_VER >= 1200
  9580. #pragma warning(push)
  9581. #endif
  9582. #pragma warning(disable:4201) // unnamed struct
  9583. typedef struct _FILE_OBJECTID_BUFFER {
  9584. //
  9585. // This is the portion of the object id that is indexed.
  9586. //
  9587. UCHAR ObjectId[16];
  9588. //
  9589. // This portion of the object id is not indexed, it's just
  9590. // some metadata for the user's benefit.
  9591. //
  9592. union {
  9593. struct {
  9594. UCHAR BirthVolumeId[16];
  9595. UCHAR BirthObjectId[16];
  9596. UCHAR DomainId[16];
  9597. } ;
  9598. UCHAR ExtendedInfo[48];
  9599. };
  9600. } FILE_OBJECTID_BUFFER, *PFILE_OBJECTID_BUFFER;
  9601. #if _MSC_VER >= 1200
  9602. #pragma warning(pop)
  9603. #else
  9604. #pragma warning( default : 4201 )
  9605. #endif
  9606. #endif /* _WIN32_WINNT >= 0x0500 */
  9607. #if(_WIN32_WINNT >= 0x0500)
  9608. //
  9609. // Structure for FSCTL_SET_SPARSE
  9610. //
  9611. typedef struct _FILE_SET_SPARSE_BUFFER {
  9612. BOOLEAN SetSparse;
  9613. } FILE_SET_SPARSE_BUFFER, *PFILE_SET_SPARSE_BUFFER;
  9614. #endif /* _WIN32_WINNT >= 0x0500 */
  9615. #if(_WIN32_WINNT >= 0x0500)
  9616. //
  9617. // Structure for FSCTL_SET_ZERO_DATA
  9618. //
  9619. typedef struct _FILE_ZERO_DATA_INFORMATION {
  9620. LARGE_INTEGER FileOffset;
  9621. LARGE_INTEGER BeyondFinalZero;
  9622. } FILE_ZERO_DATA_INFORMATION, *PFILE_ZERO_DATA_INFORMATION;
  9623. #endif /* _WIN32_WINNT >= 0x0500 */
  9624. #if(_WIN32_WINNT >= 0x0500)
  9625. //
  9626. // Structure for FSCTL_QUERY_ALLOCATED_RANGES
  9627. //
  9628. //
  9629. // Querying the allocated ranges requires an output buffer to store the
  9630. // allocated ranges and an input buffer to specify the range to query.
  9631. // The input buffer contains a single entry, the output buffer is an
  9632. // array of the following structure.
  9633. //
  9634. typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
  9635. LARGE_INTEGER FileOffset;
  9636. LARGE_INTEGER Length;
  9637. } FILE_ALLOCATED_RANGE_BUFFER, *PFILE_ALLOCATED_RANGE_BUFFER;
  9638. #endif /* _WIN32_WINNT >= 0x0500 */
  9639. #if(_WIN32_WINNT >= 0x0500)
  9640. //
  9641. // Structures for FSCTL_SET_ENCRYPTION, FSCTL_WRITE_RAW_ENCRYPTED, and FSCTL_READ_RAW_ENCRYPTED
  9642. //
  9643. //
  9644. // The input buffer to set encryption indicates whether we are to encrypt/decrypt a file
  9645. // or an individual stream.
  9646. //
  9647. typedef struct _ENCRYPTION_BUFFER {
  9648. ULONG EncryptionOperation;
  9649. UCHAR Private[1];
  9650. } ENCRYPTION_BUFFER, *PENCRYPTION_BUFFER;
  9651. #define FILE_SET_ENCRYPTION 0x00000001
  9652. #define FILE_CLEAR_ENCRYPTION 0x00000002
  9653. #define STREAM_SET_ENCRYPTION 0x00000003
  9654. #define STREAM_CLEAR_ENCRYPTION 0x00000004
  9655. #define MAXIMUM_ENCRYPTION_VALUE 0x00000004
  9656. //
  9657. // The optional output buffer to set encryption indicates that the last encrypted
  9658. // stream in a file has been marked as decrypted.
  9659. //
  9660. typedef struct _DECRYPTION_STATUS_BUFFER {
  9661. BOOLEAN NoEncryptedStreams;
  9662. } DECRYPTION_STATUS_BUFFER, *PDECRYPTION_STATUS_BUFFER;
  9663. #define ENCRYPTION_FORMAT_DEFAULT (0x01)
  9664. #define COMPRESSION_FORMAT_SPARSE (0x4000)
  9665. //
  9666. // Request Encrypted Data structure. This is used to indicate
  9667. // the range of the file to read. It also describes the
  9668. // output buffer used to return the data.
  9669. //
  9670. typedef struct _REQUEST_RAW_ENCRYPTED_DATA {
  9671. //
  9672. // Requested file offset and requested length to read.
  9673. // The fsctl will round the starting offset down
  9674. // to a file system boundary. It will also
  9675. // round the length up to a file system boundary.
  9676. //
  9677. LONGLONG FileOffset;
  9678. ULONG Length;
  9679. } REQUEST_RAW_ENCRYPTED_DATA, *PREQUEST_RAW_ENCRYPTED_DATA;
  9680. //
  9681. // Encrypted Data Information structure. This structure
  9682. // is used to return raw encrypted data from a file in
  9683. // order to perform off-line recovery. The data will be
  9684. // encrypted or encrypted and compressed. The off-line
  9685. // service will need to use the encryption and compression
  9686. // format information to recover the file data. In the
  9687. // event that the data is both encrypted and compressed then
  9688. // the decryption must occur before decompression. All
  9689. // the data units below must be encrypted and compressed
  9690. // with the same format.
  9691. //
  9692. // The data will be returned in units. The data unit size
  9693. // will be fixed per request. If the data is compressed
  9694. // then the data unit size will be the compression unit size.
  9695. //
  9696. // This structure is at the beginning of the buffer used to
  9697. // return the encrypted data. The actual raw bytes from
  9698. // the file will follow this buffer. The offset of the
  9699. // raw bytes from the beginning of this structure is
  9700. // specified in the REQUEST_RAW_ENCRYPTED_DATA structure
  9701. // described above.
  9702. //
  9703. typedef struct _ENCRYPTED_DATA_INFO {
  9704. //
  9705. // This is the file offset for the first entry in the
  9706. // data block array. The file system will round
  9707. // the requested start offset down to a boundary
  9708. // that is consistent with the format of the file.
  9709. //
  9710. ULONGLONG StartingFileOffset;
  9711. //
  9712. // Data offset in output buffer. The output buffer
  9713. // begins with an ENCRYPTED_DATA_INFO structure.
  9714. // The file system will then store the raw bytes from
  9715. // disk beginning at the following offset within the
  9716. // output buffer.
  9717. //
  9718. ULONG OutputBufferOffset;
  9719. //
  9720. // The number of bytes being returned that are within
  9721. // the size of the file. If this value is less than
  9722. // (NumberOfDataBlocks << DataUnitShift), it means the
  9723. // end of the file occurs within this transfer. Any
  9724. // data beyond file size is invalid and was never
  9725. // passed to the encryption driver.
  9726. //
  9727. ULONG BytesWithinFileSize;
  9728. //
  9729. // The number of bytes being returned that are below
  9730. // valid data length. If this value is less than
  9731. // (NumberOfDataBlocks << DataUnitShift), it means the
  9732. // end of the valid data occurs within this transfer.
  9733. // After decrypting the data from this transfer, any
  9734. // byte(s) beyond valid data length must be zeroed.
  9735. //
  9736. ULONG BytesWithinValidDataLength;
  9737. //
  9738. // Code for the compression format as defined in
  9739. // ntrtl.h. Note that COMPRESSION_FORMAT_NONE
  9740. // and COMPRESSION_FORMAT_DEFAULT are invalid if
  9741. // any of the described chunks are compressed.
  9742. //
  9743. USHORT CompressionFormat;
  9744. //
  9745. // The DataUnit is the granularity used to access the
  9746. // disk. It will be the same as the compression unit
  9747. // size for a compressed file. For an uncompressed
  9748. // file, it will be some cluster-aligned power of 2 that
  9749. // the file system deems convenient. A caller should
  9750. // not expect that successive calls will have the
  9751. // same data unit shift value as the previous call.
  9752. //
  9753. // Since chunks and compression units are expected to be
  9754. // powers of 2 in size, we express them log2. So, for
  9755. // example (1 << ChunkShift) == ChunkSizeInBytes. The
  9756. // ClusterShift indicates how much space must be saved
  9757. // to successfully compress a compression unit - each
  9758. // successfully compressed data unit must occupy
  9759. // at least one cluster less in bytes than an uncompressed
  9760. // data block unit.
  9761. //
  9762. UCHAR DataUnitShift;
  9763. UCHAR ChunkShift;
  9764. UCHAR ClusterShift;
  9765. //
  9766. // The format for the encryption.
  9767. //
  9768. UCHAR EncryptionFormat;
  9769. //
  9770. // This is the number of entries in the data block size
  9771. // array.
  9772. //
  9773. USHORT NumberOfDataBlocks;
  9774. //
  9775. // This is an array of sizes in the data block array. There
  9776. // must be one entry in this array for each data block
  9777. // read from disk. The size has a different meaning
  9778. // depending on whether the file is compressed.
  9779. //
  9780. // A size of zero always indicates that the final data consists entirely
  9781. // of zeroes. There is no decryption or decompression to
  9782. // perform.
  9783. //
  9784. // If the file is compressed then the data block size indicates
  9785. // whether this block is compressed. A size equal to
  9786. // the block size indicates that the corresponding block did
  9787. // not compress. Any other non-zero size indicates the
  9788. // size of the compressed data which needs to be
  9789. // decrypted/decompressed.
  9790. //
  9791. // If the file is not compressed then the data block size
  9792. // indicates the amount of data within the block that
  9793. // needs to be decrypted. Any other non-zero size indicates
  9794. // that the remaining bytes in the data unit within the file
  9795. // consists of zeros. An example of this is when the
  9796. // the read spans the valid data length of the file. There
  9797. // is no data to decrypt past the valid data length.
  9798. //
  9799. ULONG DataBlockSize[ANYSIZE_ARRAY];
  9800. } ENCRYPTED_DATA_INFO;
  9801. typedef ENCRYPTED_DATA_INFO *PENCRYPTED_DATA_INFO;
  9802. #endif /* _WIN32_WINNT >= 0x0500 */
  9803. #if(_WIN32_WINNT >= 0x0500)
  9804. //
  9805. // FSCTL_READ_FROM_PLEX support
  9806. // Request Plex Read Data structure. This is used to indicate
  9807. // the range of the file to read. It also describes
  9808. // which plex to perform the read from.
  9809. //
  9810. typedef struct _PLEX_READ_DATA_REQUEST {
  9811. //
  9812. // Requested offset and length to read.
  9813. // The offset can be the virtual offset (vbo) in to a file,
  9814. // or a volume. In the case of a file offset,
  9815. // the fsd will round the starting offset down
  9816. // to a file system boundary. It will also
  9817. // round the length up to a file system boundary and
  9818. // enforce any other applicable limits.
  9819. //
  9820. LARGE_INTEGER ByteOffset;
  9821. ULONG ByteLength;
  9822. ULONG PlexNumber;
  9823. } PLEX_READ_DATA_REQUEST, *PPLEX_READ_DATA_REQUEST;
  9824. #endif /* _WIN32_WINNT >= 0x0500 */
  9825. #if(_WIN32_WINNT >= 0x0500)
  9826. //
  9827. // FSCTL_SIS_COPYFILE support
  9828. // Source and destination file names are passed in the FileNameBuffer.
  9829. // Both strings are null terminated, with the source name starting at
  9830. // the beginning of FileNameBuffer, and the destination name immediately
  9831. // following. Length fields include terminating nulls.
  9832. //
  9833. typedef struct _SI_COPYFILE {
  9834. ULONG SourceFileNameLength;
  9835. ULONG DestinationFileNameLength;
  9836. ULONG Flags;
  9837. WCHAR FileNameBuffer[1];
  9838. } SI_COPYFILE, *PSI_COPYFILE;
  9839. #define COPYFILE_SIS_LINK 0x0001 // Copy only if source is SIS
  9840. #define COPYFILE_SIS_REPLACE 0x0002 // Replace destination if it exists, otherwise don't.
  9841. #define COPYFILE_SIS_FLAGS 0x0003
  9842. #endif /* _WIN32_WINNT >= 0x0500 */
  9843. #endif // _FILESYSTEMFSCTL_
  9844. // end_winioctl
  9845. //
  9846. // Structures for FSCTL_SET_REPARSE_POINT, FSCTL_GET_REPARSE_POINT, and FSCTL_DELETE_REPARSE_POINT
  9847. //
  9848. //
  9849. // The reparse structure is used by layered drivers to store data in a
  9850. // reparse point. The constraints on reparse tags are defined below.
  9851. // This version of the reparse data buffer is only for Microsoft tags.
  9852. //
  9853. #if _MSC_VER >= 1200
  9854. #pragma warning(push)
  9855. #endif
  9856. #pragma warning(disable:4201) // unnamed struct
  9857. typedef struct _REPARSE_DATA_BUFFER {
  9858. ULONG ReparseTag;
  9859. USHORT ReparseDataLength;
  9860. USHORT Reserved;
  9861. union {
  9862. struct {
  9863. USHORT SubstituteNameOffset;
  9864. USHORT SubstituteNameLength;
  9865. USHORT PrintNameOffset;
  9866. USHORT PrintNameLength;
  9867. WCHAR PathBuffer[1];
  9868. } SymbolicLinkReparseBuffer;
  9869. struct {
  9870. USHORT SubstituteNameOffset;
  9871. USHORT SubstituteNameLength;
  9872. USHORT PrintNameOffset;
  9873. USHORT PrintNameLength;
  9874. WCHAR PathBuffer[1];
  9875. } MountPointReparseBuffer;
  9876. struct {
  9877. UCHAR DataBuffer[1];
  9878. } GenericReparseBuffer;
  9879. };
  9880. } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
  9881. #if _MSC_VER >= 1200
  9882. #pragma warning(pop)
  9883. #else
  9884. #pragma warning( default : 4201 )
  9885. #endif
  9886. #define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer)
  9887. // begin_winnt
  9888. //
  9889. // The reparse GUID structure is used by all 3rd party layered drivers to
  9890. // store data in a reparse point. For non-Microsoft tags, The GUID field
  9891. // cannot be GUID_NULL.
  9892. // The constraints on reparse tags are defined below.
  9893. // Microsoft tags can also be used with this format of the reparse point buffer.
  9894. //
  9895. typedef struct _REPARSE_GUID_DATA_BUFFER {
  9896. ULONG ReparseTag;
  9897. USHORT ReparseDataLength;
  9898. USHORT Reserved;
  9899. GUID ReparseGuid;
  9900. struct {
  9901. UCHAR DataBuffer[1];
  9902. } GenericReparseBuffer;
  9903. } REPARSE_GUID_DATA_BUFFER, *PREPARSE_GUID_DATA_BUFFER;
  9904. #define REPARSE_GUID_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_GUID_DATA_BUFFER, GenericReparseBuffer)
  9905. //
  9906. // Maximum allowed size of the reparse data.
  9907. //
  9908. #define MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 )
  9909. //
  9910. // Predefined reparse tags.
  9911. // These tags need to avoid conflicting with IO_REMOUNT defined in ntos\inc\io.h
  9912. //
  9913. #define IO_REPARSE_TAG_RESERVED_ZERO (0)
  9914. #define IO_REPARSE_TAG_RESERVED_ONE (1)
  9915. //
  9916. // The value of the following constant needs to satisfy the following conditions:
  9917. // (1) Be at least as large as the largest of the reserved tags.
  9918. // (2) Be strictly smaller than all the tags in use.
  9919. //
  9920. #define IO_REPARSE_TAG_RESERVED_RANGE IO_REPARSE_TAG_RESERVED_ONE
  9921. //
  9922. // The reparse tags are a ULONG. The 32 bits are laid out as follows:
  9923. //
  9924. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  9925. // 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
  9926. // +-+-+-+-+-----------------------+-------------------------------+
  9927. // |M|R|N|R| Reserved bits | Reparse Tag Value |
  9928. // +-+-+-+-+-----------------------+-------------------------------+
  9929. //
  9930. // M is the Microsoft bit. When set to 1, it denotes a tag owned by Microsoft.
  9931. // All ISVs must use a tag with a 0 in this position.
  9932. // Note: If a Microsoft tag is used by non-Microsoft software, the
  9933. // behavior is not defined.
  9934. //
  9935. // R is reserved. Must be zero for non-Microsoft tags.
  9936. //
  9937. // N is name surrogate. When set to 1, the file represents another named
  9938. // entity in the system.
  9939. //
  9940. // The M and N bits are OR-able.
  9941. // The following macros check for the M and N bit values:
  9942. //
  9943. //
  9944. // Macro to determine whether a reparse point tag corresponds to a tag
  9945. // owned by Microsoft.
  9946. //
  9947. #define IsReparseTagMicrosoft(_tag) ( \
  9948. ((_tag) & 0x80000000) \
  9949. )
  9950. //
  9951. // Macro to determine whether a reparse point tag is a name surrogate
  9952. //
  9953. #define IsReparseTagNameSurrogate(_tag) ( \
  9954. ((_tag) & 0x20000000) \
  9955. )
  9956. // end_winnt
  9957. //
  9958. // The following constant represents the bits that are valid to use in
  9959. // reparse tags.
  9960. //
  9961. #define IO_REPARSE_TAG_VALID_VALUES (0xF000FFFF)
  9962. //
  9963. // Macro to determine whether a reparse tag is a valid tag.
  9964. //
  9965. #define IsReparseTagValid(_tag) ( \
  9966. !((_tag) & ~IO_REPARSE_TAG_VALID_VALUES) && \
  9967. ((_tag) > IO_REPARSE_TAG_RESERVED_RANGE) \
  9968. )
  9969. //
  9970. // Microsoft tags for reparse points.
  9971. //
  9972. #define IO_REPARSE_TAG_SYMBOLIC_LINK IO_REPARSE_TAG_RESERVED_ZERO
  9973. #define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L) // winnt ntifs
  9974. #define IO_REPARSE_TAG_HSM (0xC0000004L) // winnt ntifs
  9975. #define IO_REPARSE_TAG_SIS (0x80000007L) // winnt ntifs
  9976. //
  9977. // The reparse tag 0x80000008 is reserved for Microsoft internal use
  9978. // (may be published in the future)
  9979. //
  9980. //
  9981. // Microsoft reparse tag reserved for DFS
  9982. //
  9983. #define IO_REPARSE_TAG_DFS (0x8000000AL) // winnt ntifs
  9984. //
  9985. // Microsoft reparse tag reserved for the file system filter manager
  9986. //
  9987. #define IO_REPARSE_TAG_FILTER_MANAGER (0x8000000BL) // winnt ntifs
  9988. //
  9989. // Non-Microsoft tags for reparse points
  9990. //
  9991. //
  9992. // Tag allocated to CONGRUENT, May 2000. Used by IFSTEST
  9993. //
  9994. #define IO_REPARSE_TAG_IFSTEST_CONGRUENT (0x00000009L)
  9995. //
  9996. // Tag allocated to ARKIVIO
  9997. //
  9998. #define IO_REPARSE_TAG_ARKIVIO (0x0000000CL)
  9999. //
  10000. // Tag allocated to SOLUTIONSOFT
  10001. //
  10002. #define IO_REPARSE_TAG_SOLUTIONSOFT (0x2000000DL)
  10003. //
  10004. // Tag allocated to COMMVAULT
  10005. //
  10006. #define IO_REPARSE_TAG_COMMVAULT (0x0000000EL)
  10007. //
  10008. // The following three FSCTLs are placed in this file to facilitate sharing
  10009. // between the redirector and the IO subsystem
  10010. //
  10011. // This FSCTL is used to garner the link tracking information for a file.
  10012. // The data structures used for retreving the information are
  10013. // LINK_TRACKING_INFORMATION defined further down in this file.
  10014. //
  10015. #define FSCTL_LMR_GET_LINK_TRACKING_INFORMATION CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM,58,METHOD_BUFFERED,FILE_ANY_ACCESS)
  10016. //
  10017. // This FSCTL is used to update the link tracking information on a server for
  10018. // an intra machine/ inter volume move on that server
  10019. //
  10020. #define FSCTL_LMR_SET_LINK_TRACKING_INFORMATION CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM,59,METHOD_BUFFERED,FILE_ANY_ACCESS)
  10021. //
  10022. // The following IOCTL is used in link tracking implementation. It determines if the
  10023. // two file objects passed in are on the same server. This IOCTL is available in
  10024. // kernel mode only since it accepts FILE_OBJECT as parameters
  10025. //
  10026. #define IOCTL_LMR_ARE_FILE_OBJECTS_ON_SAME_SERVER CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM,60,METHOD_BUFFERED,FILE_ANY_ACCESS)
  10027. //
  10028. // Named Pipe file control code and structure declarations
  10029. //
  10030. //
  10031. // External named pipe file control operations
  10032. //
  10033. #define FSCTL_PIPE_ASSIGN_EVENT CTL_CODE(FILE_DEVICE_NAMED_PIPE, 0, METHOD_BUFFERED, FILE_ANY_ACCESS)
  10034. #define FSCTL_PIPE_DISCONNECT CTL_CODE(FILE_DEVICE_NAMED_PIPE, 1, METHOD_BUFFERED, FILE_ANY_ACCESS)
  10035. #define FSCTL_PIPE_LISTEN CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
  10036. #define FSCTL_PIPE_PEEK CTL_CODE(FILE_DEVICE_NAMED_PIPE, 3, METHOD_BUFFERED, FILE_READ_DATA)
  10037. #define FSCTL_PIPE_QUERY_EVENT CTL_CODE(FILE_DEVICE_NAMED_PIPE, 4, METHOD_BUFFERED, FILE_ANY_ACCESS)
  10038. #define FSCTL_PIPE_TRANSCEIVE CTL_CODE(FILE_DEVICE_NAMED_PIPE, 5, METHOD_NEITHER, FILE_READ_DATA | FILE_WRITE_DATA)
  10039. #define FSCTL_PIPE_WAIT CTL_CODE(FILE_DEVICE_NAMED_PIPE, 6, METHOD_BUFFERED, FILE_ANY_ACCESS)
  10040. #define FSCTL_PIPE_IMPERSONATE CTL_CODE(FILE_DEVICE_NAMED_PIPE, 7, METHOD_BUFFERED, FILE_ANY_ACCESS)
  10041. #define FSCTL_PIPE_SET_CLIENT_PROCESS CTL_CODE(FILE_DEVICE_NAMED_PIPE, 8, METHOD_BUFFERED, FILE_ANY_ACCESS)
  10042. #define FSCTL_PIPE_QUERY_CLIENT_PROCESS CTL_CODE(FILE_DEVICE_NAMED_PIPE, 9, METHOD_BUFFERED, FILE_ANY_ACCESS)
  10043. //
  10044. // Internal named pipe file control operations
  10045. //
  10046. #define FSCTL_PIPE_INTERNAL_READ CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2045, METHOD_BUFFERED, FILE_READ_DATA)
  10047. #define FSCTL_PIPE_INTERNAL_WRITE CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2046, METHOD_BUFFERED, FILE_WRITE_DATA)
  10048. #define FSCTL_PIPE_INTERNAL_TRANSCEIVE CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2047, METHOD_NEITHER, FILE_READ_DATA | FILE_WRITE_DATA)
  10049. #define FSCTL_PIPE_INTERNAL_READ_OVFLOW CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2048, METHOD_BUFFERED, FILE_READ_DATA)
  10050. //
  10051. // Define entry types for query event information
  10052. //
  10053. #define FILE_PIPE_READ_DATA 0x00000000
  10054. #define FILE_PIPE_WRITE_SPACE 0x00000001
  10055. //
  10056. // Named pipe file system control structure declarations
  10057. //
  10058. // Control structure for FSCTL_PIPE_ASSIGN_EVENT
  10059. typedef struct _FILE_PIPE_ASSIGN_EVENT_BUFFER {
  10060. HANDLE EventHandle;
  10061. ULONG KeyValue;
  10062. } FILE_PIPE_ASSIGN_EVENT_BUFFER, *PFILE_PIPE_ASSIGN_EVENT_BUFFER;
  10063. // Control structure for FSCTL_PIPE_PEEK
  10064. typedef struct _FILE_PIPE_PEEK_BUFFER {
  10065. ULONG NamedPipeState;
  10066. ULONG ReadDataAvailable;
  10067. ULONG NumberOfMessages;
  10068. ULONG MessageLength;
  10069. CHAR Data[1];
  10070. } FILE_PIPE_PEEK_BUFFER, *PFILE_PIPE_PEEK_BUFFER;
  10071. // Control structure for FSCTL_PIPE_QUERY_EVENT
  10072. typedef struct _FILE_PIPE_EVENT_BUFFER {
  10073. ULONG NamedPipeState;
  10074. ULONG EntryType;
  10075. ULONG ByteCount;
  10076. ULONG KeyValue;
  10077. ULONG NumberRequests;
  10078. } FILE_PIPE_EVENT_BUFFER, *PFILE_PIPE_EVENT_BUFFER;
  10079. // Control structure for FSCTL_PIPE_WAIT
  10080. typedef struct _FILE_PIPE_WAIT_FOR_BUFFER {
  10081. LARGE_INTEGER Timeout;
  10082. ULONG NameLength;
  10083. BOOLEAN TimeoutSpecified;
  10084. WCHAR Name[1];
  10085. } FILE_PIPE_WAIT_FOR_BUFFER, *PFILE_PIPE_WAIT_FOR_BUFFER;
  10086. // Control structure for FSCTL_PIPE_SET_CLIENT_PROCESS and FSCTL_PIPE_QUERY_CLIENT_PROCESS
  10087. typedef struct _FILE_PIPE_CLIENT_PROCESS_BUFFER {
  10088. #if !defined(BUILD_WOW6432)
  10089. PVOID ClientSession;
  10090. PVOID ClientProcess;
  10091. #else
  10092. ULONGLONG ClientSession;
  10093. ULONGLONG ClientProcess;
  10094. #endif
  10095. } FILE_PIPE_CLIENT_PROCESS_BUFFER, *PFILE_PIPE_CLIENT_PROCESS_BUFFER;
  10096. // This is an extension to the client process info buffer containing the client
  10097. // computer name
  10098. #define FILE_PIPE_COMPUTER_NAME_LENGTH 15
  10099. typedef struct _FILE_PIPE_CLIENT_PROCESS_BUFFER_EX {
  10100. #if !defined(BUILD_WOW6432)
  10101. PVOID ClientSession;
  10102. PVOID ClientProcess;
  10103. #else
  10104. ULONGLONG ClientSession;
  10105. ULONGLONG ClientProcess;
  10106. #endif
  10107. USHORT ClientComputerNameLength; // in bytes
  10108. WCHAR ClientComputerBuffer[FILE_PIPE_COMPUTER_NAME_LENGTH+1]; // terminated
  10109. } FILE_PIPE_CLIENT_PROCESS_BUFFER_EX, *PFILE_PIPE_CLIENT_PROCESS_BUFFER_EX;
  10110. #define FSCTL_MAILSLOT_PEEK CTL_CODE(FILE_DEVICE_MAILSLOT, 0, METHOD_NEITHER, FILE_READ_DATA)
  10111. //
  10112. // Control structure for FSCTL_LMR_GET_LINK_TRACKING_INFORMATION
  10113. //
  10114. //
  10115. // For links on DFS volumes the volume id and machine id are returned for
  10116. // link tracking
  10117. //
  10118. typedef enum _LINK_TRACKING_INFORMATION_TYPE {
  10119. NtfsLinkTrackingInformation,
  10120. DfsLinkTrackingInformation
  10121. } LINK_TRACKING_INFORMATION_TYPE, *PLINK_TRACKING_INFORMATION_TYPE;
  10122. typedef struct _LINK_TRACKING_INFORMATION {
  10123. LINK_TRACKING_INFORMATION_TYPE Type;
  10124. UCHAR VolumeId[16];
  10125. } LINK_TRACKING_INFORMATION, *PLINK_TRACKING_INFORMATION;
  10126. //
  10127. // Control structure for FSCTL_LMR_SET_LINK_TRACKING_INFORMATION
  10128. //
  10129. typedef struct _REMOTE_LINK_TRACKING_INFORMATION_ {
  10130. PVOID TargetFileObject;
  10131. ULONG TargetLinkTrackingInformationLength;
  10132. UCHAR TargetLinkTrackingInformationBuffer[1];
  10133. } REMOTE_LINK_TRACKING_INFORMATION,
  10134. *PREMOTE_LINK_TRACKING_INFORMATION;
  10135. //
  10136. // Define the I/O bus interface types.
  10137. //
  10138. typedef enum _INTERFACE_TYPE {
  10139. InterfaceTypeUndefined = -1,
  10140. Internal,
  10141. Isa,
  10142. Eisa,
  10143. MicroChannel,
  10144. TurboChannel,
  10145. PCIBus,
  10146. VMEBus,
  10147. NuBus,
  10148. PCMCIABus,
  10149. CBus,
  10150. MPIBus,
  10151. MPSABus,
  10152. ProcessorInternal,
  10153. InternalPowerBus,
  10154. PNPISABus,
  10155. PNPBus,
  10156. MaximumInterfaceType
  10157. }INTERFACE_TYPE, *PINTERFACE_TYPE;
  10158. //
  10159. // Define the DMA transfer widths.
  10160. //
  10161. typedef enum _DMA_WIDTH {
  10162. Width8Bits,
  10163. Width16Bits,
  10164. Width32Bits,
  10165. MaximumDmaWidth
  10166. }DMA_WIDTH, *PDMA_WIDTH;
  10167. //
  10168. // Define DMA transfer speeds.
  10169. //
  10170. typedef enum _DMA_SPEED {
  10171. Compatible,
  10172. TypeA,
  10173. TypeB,
  10174. TypeC,
  10175. TypeF,
  10176. MaximumDmaSpeed
  10177. }DMA_SPEED, *PDMA_SPEED;
  10178. //
  10179. // Define Interface reference/dereference routines for
  10180. // Interfaces exported by IRP_MN_QUERY_INTERFACE
  10181. //
  10182. typedef VOID (*PINTERFACE_REFERENCE)(PVOID Context);
  10183. typedef VOID (*PINTERFACE_DEREFERENCE)(PVOID Context);
  10184. // end_wdm
  10185. //
  10186. // Define types of bus information.
  10187. //
  10188. typedef enum _BUS_DATA_TYPE {
  10189. ConfigurationSpaceUndefined = -1,
  10190. Cmos,
  10191. EisaConfiguration,
  10192. Pos,
  10193. CbusConfiguration,
  10194. PCIConfiguration,
  10195. VMEConfiguration,
  10196. NuBusConfiguration,
  10197. PCMCIAConfiguration,
  10198. MPIConfiguration,
  10199. MPSAConfiguration,
  10200. PNPISAConfiguration,
  10201. SgiInternalConfiguration,
  10202. MaximumBusDataType
  10203. } BUS_DATA_TYPE, *PBUS_DATA_TYPE;
  10204. #if defined(USE_LPC6432)
  10205. #define LPC_CLIENT_ID CLIENT_ID64
  10206. #define LPC_SIZE_T ULONGLONG
  10207. #define LPC_PVOID ULONGLONG
  10208. #define LPC_HANDLE ULONGLONG
  10209. #else
  10210. #define LPC_CLIENT_ID CLIENT_ID
  10211. #define LPC_SIZE_T SIZE_T
  10212. #define LPC_PVOID PVOID
  10213. #define LPC_HANDLE HANDLE
  10214. #endif
  10215. typedef struct _PORT_MESSAGE {
  10216. union {
  10217. struct {
  10218. CSHORT DataLength;
  10219. CSHORT TotalLength;
  10220. } s1;
  10221. ULONG Length;
  10222. } u1;
  10223. union {
  10224. struct {
  10225. CSHORT Type;
  10226. CSHORT DataInfoOffset;
  10227. } s2;
  10228. ULONG ZeroInit;
  10229. } u2;
  10230. union {
  10231. LPC_CLIENT_ID ClientId;
  10232. double DoNotUseThisField; // Force quadword alignment
  10233. };
  10234. ULONG MessageId;
  10235. union {
  10236. LPC_SIZE_T ClientViewSize; // Only valid on LPC_CONNECTION_REQUEST message
  10237. ULONG CallbackId; // Only valid on LPC_REQUEST message
  10238. };
  10239. // UCHAR Data[];
  10240. } PORT_MESSAGE, *PPORT_MESSAGE;
  10241. //
  10242. // The following bit may be placed in the Type field of a message
  10243. // prior calling NtRequestPort or NtRequestWaitReplyPort. If the
  10244. // previous mode is KernelMode, the bit it left as is and passed
  10245. // to the receiver of the message. Otherwise the bit is clear.
  10246. //
  10247. #define LPC_KERNELMODE_MESSAGE (CSHORT)0x8000
  10248. typedef struct _PORT_VIEW {
  10249. ULONG Length;
  10250. LPC_HANDLE SectionHandle;
  10251. ULONG SectionOffset;
  10252. LPC_SIZE_T ViewSize;
  10253. LPC_PVOID ViewBase;
  10254. LPC_PVOID ViewRemoteBase;
  10255. } PORT_VIEW, *PPORT_VIEW;
  10256. typedef struct _REMOTE_PORT_VIEW {
  10257. ULONG Length;
  10258. LPC_SIZE_T ViewSize;
  10259. LPC_PVOID ViewBase;
  10260. } REMOTE_PORT_VIEW, *PREMOTE_PORT_VIEW;
  10261. NTSYSCALLAPI
  10262. NTSTATUS
  10263. NTAPI
  10264. NtConnectPort(
  10265. OUT PHANDLE PortHandle,
  10266. IN PUNICODE_STRING PortName,
  10267. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
  10268. IN OUT PPORT_VIEW ClientView OPTIONAL,
  10269. IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL,
  10270. OUT PULONG MaxMessageLength OPTIONAL,
  10271. IN OUT PVOID ConnectionInformation OPTIONAL,
  10272. IN OUT PULONG ConnectionInformationLength OPTIONAL
  10273. );
  10274. NTSYSCALLAPI
  10275. NTSTATUS
  10276. NTAPI
  10277. NtSecureConnectPort(
  10278. OUT PHANDLE PortHandle,
  10279. IN PUNICODE_STRING PortName,
  10280. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
  10281. IN OUT PPORT_VIEW ClientView OPTIONAL,
  10282. IN PSID RequiredServerSid,
  10283. IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL,
  10284. OUT PULONG MaxMessageLength OPTIONAL,
  10285. IN OUT PVOID ConnectionInformation OPTIONAL,
  10286. IN OUT PULONG ConnectionInformationLength OPTIONAL
  10287. );
  10288. NTSYSCALLAPI
  10289. NTSTATUS
  10290. NTAPI
  10291. NtRequestWaitReplyPort(
  10292. IN HANDLE PortHandle,
  10293. IN PPORT_MESSAGE RequestMessage,
  10294. OUT PPORT_MESSAGE ReplyMessage
  10295. );
  10296. NTSYSCALLAPI
  10297. NTSTATUS
  10298. NTAPI
  10299. NtSetSecurityObject(
  10300. IN HANDLE Handle,
  10301. IN SECURITY_INFORMATION SecurityInformation,
  10302. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  10303. );
  10304. NTSYSCALLAPI
  10305. NTSTATUS
  10306. NTAPI
  10307. NtQuerySecurityObject(
  10308. IN HANDLE Handle,
  10309. IN SECURITY_INFORMATION SecurityInformation,
  10310. OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  10311. IN ULONG Length,
  10312. OUT PULONG LengthNeeded
  10313. );
  10314. NTSYSCALLAPI
  10315. NTSTATUS
  10316. NTAPI
  10317. NtClose(
  10318. IN HANDLE Handle
  10319. );
  10320. #define SEC_COMMIT 0x8000000
  10321. NTSYSCALLAPI
  10322. NTSTATUS
  10323. NTAPI
  10324. NtCreateSection (
  10325. OUT PHANDLE SectionHandle,
  10326. IN ACCESS_MASK DesiredAccess,
  10327. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  10328. IN PLARGE_INTEGER MaximumSize OPTIONAL,
  10329. IN ULONG SectionPageProtection,
  10330. IN ULONG AllocationAttributes,
  10331. IN HANDLE FileHandle OPTIONAL
  10332. );
  10333. NTSYSCALLAPI
  10334. NTSTATUS
  10335. NTAPI
  10336. NtAllocateVirtualMemory(
  10337. IN HANDLE ProcessHandle,
  10338. IN OUT PVOID *BaseAddress,
  10339. IN ULONG_PTR ZeroBits,
  10340. IN OUT PSIZE_T RegionSize,
  10341. IN ULONG AllocationType,
  10342. IN ULONG Protect
  10343. );
  10344. NTSYSCALLAPI
  10345. NTSTATUS
  10346. NTAPI
  10347. NtFreeVirtualMemory(
  10348. IN HANDLE ProcessHandle,
  10349. IN OUT PVOID *BaseAddress,
  10350. IN OUT PSIZE_T RegionSize,
  10351. IN ULONG FreeType
  10352. );
  10353. //
  10354. // Priority increment definitions. The comment for each definition gives
  10355. // the names of the system services that use the definition when satisfying
  10356. // a wait.
  10357. //
  10358. //
  10359. // Priority increment used when satisfying a wait on an executive event
  10360. // (NtPulseEvent and NtSetEvent)
  10361. //
  10362. #define EVENT_INCREMENT 1
  10363. //
  10364. // Priority increment when no I/O has been done. This is used by device
  10365. // and file system drivers when completing an IRP (IoCompleteRequest).
  10366. //
  10367. #define IO_NO_INCREMENT 0
  10368. //
  10369. // Priority increment for completing CD-ROM I/O. This is used by CD-ROM device
  10370. // and file system drivers when completing an IRP (IoCompleteRequest)
  10371. //
  10372. #define IO_CD_ROM_INCREMENT 1
  10373. //
  10374. // Priority increment for completing disk I/O. This is used by disk device
  10375. // and file system drivers when completing an IRP (IoCompleteRequest)
  10376. //
  10377. #define IO_DISK_INCREMENT 1
  10378. //
  10379. // Priority increment for completing mailslot I/O. This is used by the mail-
  10380. // slot file system driver when completing an IRP (IoCompleteRequest).
  10381. //
  10382. #define IO_MAILSLOT_INCREMENT 2
  10383. //
  10384. // Priority increment for completing named pipe I/O. This is used by the
  10385. // named pipe file system driver when completing an IRP (IoCompleteRequest).
  10386. //
  10387. #define IO_NAMED_PIPE_INCREMENT 2
  10388. //
  10389. // Priority increment for completing network I/O. This is used by network
  10390. // device and network file system drivers when completing an IRP
  10391. // (IoCompleteRequest).
  10392. //
  10393. #define IO_NETWORK_INCREMENT 2
  10394. //
  10395. // Priority increment used when satisfying a wait on an executive semaphore
  10396. // (NtReleaseSemaphore)
  10397. //
  10398. #define SEMAPHORE_INCREMENT 1
  10399. #if defined(_X86_)
  10400. //
  10401. // Types to use to contain PFNs and their counts.
  10402. //
  10403. typedef ULONG PFN_COUNT;
  10404. typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
  10405. typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
  10406. //
  10407. // Define maximum size of flush multiple TB request.
  10408. //
  10409. #define FLUSH_MULTIPLE_MAXIMUM 32
  10410. //
  10411. // Indicate that the i386 compiler supports the pragma textout construct.
  10412. //
  10413. #define ALLOC_PRAGMA 1
  10414. //
  10415. // Indicate that the i386 compiler supports the DATA_SEG("INIT") and
  10416. // DATA_SEG("PAGE") pragmas
  10417. //
  10418. #define ALLOC_DATA_PRAGMA 1
  10419. #define NORMAL_DISPATCH_LENGTH 106
  10420. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  10421. //
  10422. // Interrupt Request Level definitions
  10423. //
  10424. #define PASSIVE_LEVEL 0 // Passive release level
  10425. #define LOW_LEVEL 0 // Lowest interrupt level
  10426. #define APC_LEVEL 1 // APC interrupt level
  10427. #define DISPATCH_LEVEL 2 // Dispatcher level
  10428. #define PROFILE_LEVEL 27 // timer used for profiling.
  10429. #define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
  10430. #define CLOCK2_LEVEL 28 // Interval clock 2 level
  10431. #define IPI_LEVEL 29 // Interprocessor interrupt level
  10432. #define POWER_LEVEL 30 // Power failure level
  10433. #define HIGH_LEVEL 31 // Highest interrupt level
  10434. #define SYNCH_LEVEL (IPI_LEVEL-2)
  10435. //
  10436. // I/O space read and write macros.
  10437. //
  10438. // These have to be actual functions on the 386, because we need
  10439. // to use assembler, but cannot return a value if we inline it.
  10440. //
  10441. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  10442. // (Use x86 move instructions, with LOCK prefix to force correct behavior
  10443. // w.r.t. caches and write buffers.)
  10444. //
  10445. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  10446. // (Use x86 in/out instructions.)
  10447. //
  10448. NTKERNELAPI
  10449. UCHAR
  10450. NTAPI
  10451. READ_REGISTER_UCHAR(
  10452. PUCHAR Register
  10453. );
  10454. NTKERNELAPI
  10455. USHORT
  10456. NTAPI
  10457. READ_REGISTER_USHORT(
  10458. PUSHORT Register
  10459. );
  10460. NTKERNELAPI
  10461. ULONG
  10462. NTAPI
  10463. READ_REGISTER_ULONG(
  10464. PULONG Register
  10465. );
  10466. NTKERNELAPI
  10467. VOID
  10468. NTAPI
  10469. READ_REGISTER_BUFFER_UCHAR(
  10470. PUCHAR Register,
  10471. PUCHAR Buffer,
  10472. ULONG Count
  10473. );
  10474. NTKERNELAPI
  10475. VOID
  10476. NTAPI
  10477. READ_REGISTER_BUFFER_USHORT(
  10478. PUSHORT Register,
  10479. PUSHORT Buffer,
  10480. ULONG Count
  10481. );
  10482. NTKERNELAPI
  10483. VOID
  10484. NTAPI
  10485. READ_REGISTER_BUFFER_ULONG(
  10486. PULONG Register,
  10487. PULONG Buffer,
  10488. ULONG Count
  10489. );
  10490. NTKERNELAPI
  10491. VOID
  10492. NTAPI
  10493. WRITE_REGISTER_UCHAR(
  10494. PUCHAR Register,
  10495. UCHAR Value
  10496. );
  10497. NTKERNELAPI
  10498. VOID
  10499. NTAPI
  10500. WRITE_REGISTER_USHORT(
  10501. PUSHORT Register,
  10502. USHORT Value
  10503. );
  10504. NTKERNELAPI
  10505. VOID
  10506. NTAPI
  10507. WRITE_REGISTER_ULONG(
  10508. PULONG Register,
  10509. ULONG Value
  10510. );
  10511. NTKERNELAPI
  10512. VOID
  10513. NTAPI
  10514. WRITE_REGISTER_BUFFER_UCHAR(
  10515. PUCHAR Register,
  10516. PUCHAR Buffer,
  10517. ULONG Count
  10518. );
  10519. NTKERNELAPI
  10520. VOID
  10521. NTAPI
  10522. WRITE_REGISTER_BUFFER_USHORT(
  10523. PUSHORT Register,
  10524. PUSHORT Buffer,
  10525. ULONG Count
  10526. );
  10527. NTKERNELAPI
  10528. VOID
  10529. NTAPI
  10530. WRITE_REGISTER_BUFFER_ULONG(
  10531. PULONG Register,
  10532. PULONG Buffer,
  10533. ULONG Count
  10534. );
  10535. NTHALAPI
  10536. UCHAR
  10537. NTAPI
  10538. READ_PORT_UCHAR(
  10539. PUCHAR Port
  10540. );
  10541. NTHALAPI
  10542. USHORT
  10543. NTAPI
  10544. READ_PORT_USHORT(
  10545. PUSHORT Port
  10546. );
  10547. NTHALAPI
  10548. ULONG
  10549. NTAPI
  10550. READ_PORT_ULONG(
  10551. PULONG Port
  10552. );
  10553. NTHALAPI
  10554. VOID
  10555. NTAPI
  10556. READ_PORT_BUFFER_UCHAR(
  10557. PUCHAR Port,
  10558. PUCHAR Buffer,
  10559. ULONG Count
  10560. );
  10561. NTHALAPI
  10562. VOID
  10563. NTAPI
  10564. READ_PORT_BUFFER_USHORT(
  10565. PUSHORT Port,
  10566. PUSHORT Buffer,
  10567. ULONG Count
  10568. );
  10569. NTHALAPI
  10570. VOID
  10571. NTAPI
  10572. READ_PORT_BUFFER_ULONG(
  10573. PULONG Port,
  10574. PULONG Buffer,
  10575. ULONG Count
  10576. );
  10577. NTHALAPI
  10578. VOID
  10579. NTAPI
  10580. WRITE_PORT_UCHAR(
  10581. PUCHAR Port,
  10582. UCHAR Value
  10583. );
  10584. NTHALAPI
  10585. VOID
  10586. NTAPI
  10587. WRITE_PORT_USHORT(
  10588. PUSHORT Port,
  10589. USHORT Value
  10590. );
  10591. NTHALAPI
  10592. VOID
  10593. NTAPI
  10594. WRITE_PORT_ULONG(
  10595. PULONG Port,
  10596. ULONG Value
  10597. );
  10598. NTHALAPI
  10599. VOID
  10600. NTAPI
  10601. WRITE_PORT_BUFFER_UCHAR(
  10602. PUCHAR Port,
  10603. PUCHAR Buffer,
  10604. ULONG Count
  10605. );
  10606. NTHALAPI
  10607. VOID
  10608. NTAPI
  10609. WRITE_PORT_BUFFER_USHORT(
  10610. PUSHORT Port,
  10611. PUSHORT Buffer,
  10612. ULONG Count
  10613. );
  10614. NTHALAPI
  10615. VOID
  10616. NTAPI
  10617. WRITE_PORT_BUFFER_ULONG(
  10618. PULONG Port,
  10619. PULONG Buffer,
  10620. ULONG Count
  10621. );
  10622. // end_ntndis
  10623. //
  10624. // Get data cache fill size.
  10625. //
  10626. #if PRAGMA_DEPRECATED_DDK
  10627. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  10628. #endif
  10629. #define KeGetDcacheFillSize() 1L
  10630. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  10631. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  10632. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  10633. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  10634. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  10635. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  10636. // begin_wdm
  10637. #define KeQueryTickCount(CurrentCount ) { \
  10638. volatile PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  10639. while (TRUE) { \
  10640. (CurrentCount)->HighPart = _TickCount->High1Time; \
  10641. (CurrentCount)->LowPart = _TickCount->LowPart; \
  10642. if ((CurrentCount)->HighPart == _TickCount->High2Time) break; \
  10643. _asm { rep nop } \
  10644. } \
  10645. }
  10646. // end_wdm
  10647. #else
  10648. VOID
  10649. NTAPI
  10650. KeQueryTickCount (
  10651. OUT PLARGE_INTEGER CurrentCount
  10652. );
  10653. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  10654. //
  10655. // Processor Control Region Structure Definition
  10656. //
  10657. #define PCR_MINOR_VERSION 1
  10658. #define PCR_MAJOR_VERSION 1
  10659. typedef struct _KPCR {
  10660. //
  10661. // Start of the architecturally defined section of the PCR. This section
  10662. // may be directly addressed by vendor/platform specific HAL code and will
  10663. // not change from version to version of NT.
  10664. //
  10665. // Certain fields in the TIB are not used in kernel mode. These include the
  10666. // stack limit, subsystem TIB, fiber data, arbitrary user pointer, and the
  10667. // self address of then PCR itself (another field has been added for that
  10668. // purpose). Therefore, these fields are overlaid with other data to get
  10669. // better cache locality.
  10670. //
  10671. union {
  10672. NT_TIB NtTib;
  10673. struct {
  10674. struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
  10675. PVOID Used_StackBase;
  10676. PVOID PerfGlobalGroupMask;
  10677. PVOID TssCopy;
  10678. ULONG ContextSwitches;
  10679. KAFFINITY SetMemberCopy;
  10680. PVOID Used_Self;
  10681. };
  10682. };
  10683. struct _KPCR *SelfPcr; // flat address of this PCR
  10684. struct _KPRCB *Prcb; // pointer to Prcb
  10685. KIRQL Irql; // do not use 3 bytes after this as
  10686. // HALs assume they are zero.
  10687. ULONG IRR;
  10688. ULONG IrrActive;
  10689. ULONG IDR;
  10690. PVOID KdVersionBlock;
  10691. struct _KIDTENTRY *IDT;
  10692. struct _KGDTENTRY *GDT;
  10693. struct _KTSS *TSS;
  10694. USHORT MajorVersion;
  10695. USHORT MinorVersion;
  10696. KAFFINITY SetMember;
  10697. ULONG StallScaleFactor;
  10698. UCHAR SpareUnused;
  10699. UCHAR Number;
  10700. } KPCR, *PKPCR;
  10701. //
  10702. // The non-volatile 387 state
  10703. //
  10704. typedef struct _KFLOATING_SAVE {
  10705. ULONG ControlWord;
  10706. ULONG StatusWord;
  10707. ULONG ErrorOffset;
  10708. ULONG ErrorSelector;
  10709. ULONG DataOffset; // Not used in wdm
  10710. ULONG DataSelector;
  10711. ULONG Cr0NpxState;
  10712. ULONG Spare1; // Not used in wdm
  10713. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  10714. //
  10715. // i386 Specific portions of mm component
  10716. //
  10717. //
  10718. // Define the page size for the Intel 386 as 4096 (0x1000).
  10719. //
  10720. #define PAGE_SIZE 0x1000
  10721. //
  10722. // Define the number of trailing zeroes in a page aligned virtual address.
  10723. // This is used as the shift count when shifting virtual addresses to
  10724. // virtual page numbers.
  10725. //
  10726. #define PAGE_SHIFT 12L
  10727. // end_ntndis end_wdm
  10728. //
  10729. // Define the number of bits to shift to right justify the Page Directory Index
  10730. // field of a PTE.
  10731. //
  10732. #define PDI_SHIFT_X86 22
  10733. #define PDI_SHIFT_X86PAE 21
  10734. #if !defined (_X86PAE_)
  10735. #define PDI_SHIFT PDI_SHIFT_X86
  10736. #else
  10737. #define PDI_SHIFT PDI_SHIFT_X86PAE
  10738. #define PPI_SHIFT 30
  10739. #endif
  10740. //
  10741. // Define the number of bits to shift to right justify the Page Table Index
  10742. // field of a PTE.
  10743. //
  10744. #define PTI_SHIFT 12
  10745. //
  10746. // Define the highest user address and user probe address.
  10747. //
  10748. extern PVOID *MmHighestUserAddress;
  10749. extern PVOID *MmSystemRangeStart;
  10750. extern ULONG *MmUserProbeAddress;
  10751. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  10752. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  10753. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  10754. //
  10755. // The lowest user address reserves the low 64k.
  10756. //
  10757. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  10758. //
  10759. // The lowest address for system space.
  10760. //
  10761. #if !defined (_X86PAE_)
  10762. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  10763. #else
  10764. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
  10765. #endif
  10766. // begin_wdm
  10767. #define MmGetProcedureAddress(Address) (Address)
  10768. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  10769. #define KIP0PCRADDRESS 0xffdff000
  10770. #define KI_USER_SHARED_DATA 0xffdf0000
  10771. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  10772. //
  10773. // Result type definition for i386. (Machine specific enumerate type
  10774. // which is return type for portable exinterlockedincrement/decrement
  10775. // procedures.) In general, you should use the enumerated type defined
  10776. // in ex.h instead of directly referencing these constants.
  10777. //
  10778. // Flags loaded into AH by LAHF instruction
  10779. #define EFLAG_SIGN 0x8000
  10780. #define EFLAG_ZERO 0x4000
  10781. #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
  10782. #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  10783. #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
  10784. #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
  10785. //
  10786. // Convert various portable ExInterlock APIs into their architectural
  10787. // equivalents.
  10788. //
  10789. #if PRAGMA_DEPRECATED_DDK
  10790. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  10791. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  10792. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  10793. #endif
  10794. #define ExInterlockedIncrementLong(Addend,Lock) \
  10795. Exfi386InterlockedIncrementLong(Addend)
  10796. #define ExInterlockedDecrementLong(Addend,Lock) \
  10797. Exfi386InterlockedDecrementLong(Addend)
  10798. #define ExInterlockedExchangeUlong(Target,Value,Lock) \
  10799. Exfi386InterlockedExchangeUlong(Target,Value)
  10800. // begin_wdm
  10801. #define ExInterlockedAddUlong ExfInterlockedAddUlong
  10802. #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
  10803. #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
  10804. #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
  10805. #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
  10806. #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
  10807. // end_wdm
  10808. //
  10809. // Prototypes for architectural specific versions of Exi386 Api
  10810. //
  10811. //
  10812. // Interlocked result type is portable, but its values are machine specific.
  10813. // Constants for value are in i386.h, mips.h, etc.
  10814. //
  10815. typedef enum _INTERLOCKED_RESULT {
  10816. ResultNegative = RESULT_NEGATIVE,
  10817. ResultZero = RESULT_ZERO,
  10818. ResultPositive = RESULT_POSITIVE
  10819. } INTERLOCKED_RESULT;
  10820. NTKERNELAPI
  10821. INTERLOCKED_RESULT
  10822. FASTCALL
  10823. Exfi386InterlockedIncrementLong (
  10824. IN PLONG Addend
  10825. );
  10826. NTKERNELAPI
  10827. INTERLOCKED_RESULT
  10828. FASTCALL
  10829. Exfi386InterlockedDecrementLong (
  10830. IN PLONG Addend
  10831. );
  10832. NTKERNELAPI
  10833. ULONG
  10834. FASTCALL
  10835. Exfi386InterlockedExchangeUlong (
  10836. IN PULONG Target,
  10837. IN ULONG Value
  10838. );
  10839. #if !defined(_WINBASE_) && !defined(NONTOSPINTERLOCK)
  10840. #if !defined(MIDL_PASS) // wdm
  10841. #if defined(NO_INTERLOCKED_INTRINSICS) || defined(_CROSS_PLATFORM_)
  10842. // begin_wdm
  10843. NTKERNELAPI
  10844. LONG
  10845. FASTCALL
  10846. InterlockedIncrement(
  10847. IN LONG volatile *Addend
  10848. );
  10849. NTKERNELAPI
  10850. LONG
  10851. FASTCALL
  10852. InterlockedDecrement(
  10853. IN LONG volatile *Addend
  10854. );
  10855. NTKERNELAPI
  10856. LONG
  10857. FASTCALL
  10858. InterlockedExchange(
  10859. IN OUT LONG volatile *Target,
  10860. IN LONG Value
  10861. );
  10862. #define InterlockedExchangePointer(Target, Value) \
  10863. (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value))
  10864. LONG
  10865. FASTCALL
  10866. InterlockedExchangeAdd(
  10867. IN OUT LONG volatile *Addend,
  10868. IN LONG Increment
  10869. );
  10870. NTKERNELAPI
  10871. LONG
  10872. FASTCALL
  10873. InterlockedCompareExchange(
  10874. IN OUT LONG volatile *Destination,
  10875. IN LONG ExChange,
  10876. IN LONG Comperand
  10877. );
  10878. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  10879. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  10880. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  10881. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  10882. NTKERNELAPI
  10883. LONGLONG
  10884. FASTCALL
  10885. ExfInterlockedCompareExchange64(
  10886. IN OUT LONGLONG volatile *Destination,
  10887. IN PLONGLONG ExChange,
  10888. IN PLONGLONG Comperand
  10889. );
  10890. // end_wdm
  10891. #else // NO_INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  10892. #define InterlockedExchangePointer(Target, Value) \
  10893. (PVOID)InterlockedExchange((PLONG)Target, (LONG)Value)
  10894. #if (_MSC_FULL_VER > 13009037)
  10895. LONG
  10896. __cdecl
  10897. _InterlockedExchange(
  10898. IN OUT LONG volatile *Target,
  10899. IN LONG Value
  10900. );
  10901. #pragma intrinsic (_InterlockedExchange)
  10902. #define InterlockedExchange _InterlockedExchange
  10903. #else
  10904. FORCEINLINE
  10905. LONG
  10906. FASTCALL
  10907. InterlockedExchange(
  10908. IN OUT LONG volatile *Target,
  10909. IN LONG Value
  10910. )
  10911. {
  10912. __asm {
  10913. mov eax, Value
  10914. mov ecx, Target
  10915. xchg [ecx], eax
  10916. }
  10917. }
  10918. #endif
  10919. #if (_MSC_FULL_VER > 13009037)
  10920. LONG
  10921. __cdecl
  10922. _InterlockedIncrement(
  10923. IN LONG volatile *Addend
  10924. );
  10925. #pragma intrinsic (_InterlockedIncrement)
  10926. #define InterlockedIncrement _InterlockedIncrement
  10927. #else
  10928. #define InterlockedIncrement(Addend) (InterlockedExchangeAdd (Addend, 1)+1)
  10929. #endif
  10930. #if (_MSC_FULL_VER > 13009037)
  10931. LONG
  10932. __cdecl
  10933. _InterlockedDecrement(
  10934. IN LONG volatile *Addend
  10935. );
  10936. #pragma intrinsic (_InterlockedDecrement)
  10937. #define InterlockedDecrement _InterlockedDecrement
  10938. #else
  10939. #define InterlockedDecrement(Addend) (InterlockedExchangeAdd (Addend, -1)-1)
  10940. #endif
  10941. #if (_MSC_FULL_VER > 13009037)
  10942. LONG
  10943. __cdecl
  10944. _InterlockedExchangeAdd(
  10945. IN OUT LONG volatile *Addend,
  10946. IN LONG Increment
  10947. );
  10948. #pragma intrinsic (_InterlockedExchangeAdd)
  10949. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  10950. #else
  10951. // begin_wdm
  10952. FORCEINLINE
  10953. LONG
  10954. FASTCALL
  10955. InterlockedExchangeAdd(
  10956. IN OUT LONG volatile *Addend,
  10957. IN LONG Increment
  10958. )
  10959. {
  10960. __asm {
  10961. mov eax, Increment
  10962. mov ecx, Addend
  10963. lock xadd [ecx], eax
  10964. }
  10965. }
  10966. // end_wdm
  10967. #endif
  10968. #if (_MSC_FULL_VER > 13009037)
  10969. LONG
  10970. __cdecl
  10971. _InterlockedCompareExchange (
  10972. IN OUT LONG volatile *Destination,
  10973. IN LONG ExChange,
  10974. IN LONG Comperand
  10975. );
  10976. #pragma intrinsic (_InterlockedCompareExchange)
  10977. #define InterlockedCompareExchange (LONG)_InterlockedCompareExchange
  10978. #else
  10979. FORCEINLINE
  10980. LONG
  10981. FASTCALL
  10982. InterlockedCompareExchange(
  10983. IN OUT LONG volatile *Destination,
  10984. IN LONG Exchange,
  10985. IN LONG Comperand
  10986. )
  10987. {
  10988. __asm {
  10989. mov eax, Comperand
  10990. mov ecx, Destination
  10991. mov edx, Exchange
  10992. lock cmpxchg [ecx], edx
  10993. }
  10994. }
  10995. #endif
  10996. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  10997. (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
  10998. #define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
  10999. ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
  11000. NTKERNELAPI
  11001. LONGLONG
  11002. FASTCALL
  11003. ExfInterlockedCompareExchange64(
  11004. IN OUT LONGLONG volatile *Destination,
  11005. IN PLONGLONG ExChange,
  11006. IN PLONGLONG Comperand
  11007. );
  11008. #endif // INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
  11009. // begin_wdm
  11010. #endif // MIDL_PASS
  11011. #define InterlockedIncrementAcquire InterlockedIncrement
  11012. #define InterlockedIncrementRelease InterlockedIncrement
  11013. #define InterlockedDecrementAcquire InterlockedDecrement
  11014. #define InterlockedDecrementRelease InterlockedDecrement
  11015. #define InterlockedExchangeAcquire64 InterlockedExchange64
  11016. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  11017. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  11018. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  11019. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  11020. #endif // __WINBASE__ && !NONTOSPINTERLOCK
  11021. //
  11022. // Turn these instrinsics off until the compiler can handle them
  11023. //
  11024. #if (_MSC_FULL_VER > 13009037)
  11025. LONG
  11026. _InterlockedOr (
  11027. IN OUT LONG volatile *Target,
  11028. IN LONG Set
  11029. );
  11030. #pragma intrinsic (_InterlockedOr)
  11031. #define InterlockedOr _InterlockedOr
  11032. LONG
  11033. _InterlockedAnd (
  11034. IN OUT LONG volatile *Target,
  11035. IN LONG Set
  11036. );
  11037. #pragma intrinsic (_InterlockedAnd)
  11038. #define InterlockedAnd _InterlockedAnd
  11039. LONG
  11040. _InterlockedXor (
  11041. IN OUT LONG volatile *Target,
  11042. IN LONG Set
  11043. );
  11044. #pragma intrinsic (_InterlockedXor)
  11045. #define InterlockedXor _InterlockedXor
  11046. #else // compiler version
  11047. FORCEINLINE
  11048. LONG
  11049. InterlockedAnd (
  11050. IN OUT LONG volatile *Target,
  11051. LONG Set
  11052. )
  11053. {
  11054. LONG i;
  11055. LONG j;
  11056. j = *Target;
  11057. do {
  11058. i = j;
  11059. j = InterlockedCompareExchange(Target,
  11060. i & Set,
  11061. i);
  11062. } while (i != j);
  11063. return j;
  11064. }
  11065. FORCEINLINE
  11066. LONG
  11067. InterlockedOr (
  11068. IN OUT LONG volatile *Target,
  11069. IN LONG Set
  11070. )
  11071. {
  11072. LONG i;
  11073. LONG j;
  11074. j = *Target;
  11075. do {
  11076. i = j;
  11077. j = InterlockedCompareExchange(Target,
  11078. i | Set,
  11079. i);
  11080. } while (i != j);
  11081. return j;
  11082. }
  11083. #endif // compiler version
  11084. #if !defined(MIDL_PASS) && defined(_M_IX86)
  11085. //
  11086. // i386 function definitions
  11087. //
  11088. // end_wdm
  11089. #if _MSC_VER >= 1200
  11090. #pragma warning(push)
  11091. #endif
  11092. #pragma warning(disable:4035) // re-enable below
  11093. #define _PCR fs:[0]
  11094. //
  11095. // Get current IRQL.
  11096. //
  11097. // On x86 this function resides in the HAL
  11098. //
  11099. NTHALAPI
  11100. KIRQL
  11101. NTAPI
  11102. KeGetCurrentIrql();
  11103. // end_wdm
  11104. //
  11105. // Get the current processor number
  11106. //
  11107. FORCEINLINE
  11108. ULONG
  11109. NTAPI
  11110. KeGetCurrentProcessorNumber(VOID)
  11111. {
  11112. #if (_MSC_FULL_VER >= 13012035)
  11113. return (ULONG) __readfsbyte (FIELD_OFFSET (KPCR, Number));
  11114. #else
  11115. __asm { movzx eax, _PCR KPCR.Number }
  11116. #endif
  11117. }
  11118. #if _MSC_VER >= 1200
  11119. #pragma warning(pop)
  11120. #else
  11121. #pragma warning(default:4035)
  11122. #endif
  11123. // begin_wdm
  11124. #endif // !defined(MIDL_PASS) && defined(_M_IX86)
  11125. //++
  11126. //
  11127. // VOID
  11128. // KeMemoryBarrier (
  11129. // VOID
  11130. // )
  11131. //
  11132. // VOID
  11133. // KeMemoryBarrierWithoutFence (
  11134. // VOID
  11135. // )
  11136. //
  11137. //
  11138. // Routine Description:
  11139. //
  11140. // These functions order memory accesses as seen by other processors.
  11141. //
  11142. // Arguments:
  11143. //
  11144. // None.
  11145. //
  11146. // Return Value:
  11147. //
  11148. // None.
  11149. //
  11150. //--
  11151. #ifdef __cplusplus
  11152. extern "C" {
  11153. #endif
  11154. VOID
  11155. _ReadWriteBarrier(
  11156. VOID
  11157. );
  11158. #ifdef __cplusplus
  11159. }
  11160. #endif
  11161. #pragma intrinsic (_ReadWriteBarrier)
  11162. FORCEINLINE
  11163. VOID
  11164. KeMemoryBarrier (
  11165. VOID
  11166. )
  11167. {
  11168. LONG Barrier;
  11169. __asm {
  11170. xchg Barrier, eax
  11171. }
  11172. }
  11173. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  11174. NTKERNELAPI
  11175. NTSTATUS
  11176. NTAPI
  11177. KeSaveFloatingPointState (
  11178. OUT PKFLOATING_SAVE FloatSave
  11179. );
  11180. NTKERNELAPI
  11181. NTSTATUS
  11182. NTAPI
  11183. KeRestoreFloatingPointState (
  11184. IN PKFLOATING_SAVE FloatSave
  11185. );
  11186. #endif // defined(_X86_)
  11187. // Use the following for kernel mode runtime checks of X86 system architecture
  11188. #ifdef _X86_
  11189. #ifdef IsNEC_98
  11190. #undef IsNEC_98
  11191. #endif
  11192. #ifdef IsNotNEC_98
  11193. #undef IsNotNEC_98
  11194. #endif
  11195. #ifdef SetNEC_98
  11196. #undef SetNEC_98
  11197. #endif
  11198. #ifdef SetNotNEC_98
  11199. #undef SetNotNEC_98
  11200. #endif
  11201. #define IsNEC_98 (SharedUserData->AlternativeArchitecture == NEC98x86)
  11202. #define IsNotNEC_98 (SharedUserData->AlternativeArchitecture != NEC98x86)
  11203. #define SetNEC_98 SharedUserData->AlternativeArchitecture = NEC98x86
  11204. #define SetNotNEC_98 SharedUserData->AlternativeArchitecture = StandardDesign
  11205. #endif
  11206. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  11207. //
  11208. // Define intrinsic function to do in's and out's.
  11209. //
  11210. #ifdef __cplusplus
  11211. extern "C" {
  11212. #endif
  11213. UCHAR
  11214. __inbyte (
  11215. IN USHORT Port
  11216. );
  11217. USHORT
  11218. __inword (
  11219. IN USHORT Port
  11220. );
  11221. ULONG
  11222. __indword (
  11223. IN USHORT Port
  11224. );
  11225. VOID
  11226. __outbyte (
  11227. IN USHORT Port,
  11228. IN UCHAR Data
  11229. );
  11230. VOID
  11231. __outword (
  11232. IN USHORT Port,
  11233. IN USHORT Data
  11234. );
  11235. VOID
  11236. __outdword (
  11237. IN USHORT Port,
  11238. IN ULONG Data
  11239. );
  11240. VOID
  11241. __inbytestring (
  11242. IN USHORT Port,
  11243. IN PUCHAR Buffer,
  11244. IN ULONG Count
  11245. );
  11246. VOID
  11247. __inwordstring (
  11248. IN USHORT Port,
  11249. IN PUSHORT Buffer,
  11250. IN ULONG Count
  11251. );
  11252. VOID
  11253. __indwordstring (
  11254. IN USHORT Port,
  11255. IN PULONG Buffer,
  11256. IN ULONG Count
  11257. );
  11258. VOID
  11259. __outbytestring (
  11260. IN USHORT Port,
  11261. IN PUCHAR Buffer,
  11262. IN ULONG Count
  11263. );
  11264. VOID
  11265. __outwordstring (
  11266. IN USHORT Port,
  11267. IN PUSHORT Buffer,
  11268. IN ULONG Count
  11269. );
  11270. VOID
  11271. __outdwordstring (
  11272. IN USHORT Port,
  11273. IN PULONG Buffer,
  11274. IN ULONG Count
  11275. );
  11276. #ifdef __cplusplus
  11277. }
  11278. #endif
  11279. #pragma intrinsic(__inbyte)
  11280. #pragma intrinsic(__inword)
  11281. #pragma intrinsic(__indword)
  11282. #pragma intrinsic(__outbyte)
  11283. #pragma intrinsic(__outword)
  11284. #pragma intrinsic(__outdword)
  11285. #pragma intrinsic(__inbytestring)
  11286. #pragma intrinsic(__inwordstring)
  11287. #pragma intrinsic(__indwordstring)
  11288. #pragma intrinsic(__outbytestring)
  11289. #pragma intrinsic(__outwordstring)
  11290. #pragma intrinsic(__outdwordstring)
  11291. //
  11292. // Interlocked intrinsic functions.
  11293. //
  11294. #define InterlockedAnd _InterlockedAnd
  11295. #define InterlockedOr _InterlockedOr
  11296. #define InterlockedXor _InterlockedXor
  11297. #define InterlockedIncrement _InterlockedIncrement
  11298. #define InterlockedIncrementAcquire InterlockedIncrement
  11299. #define InterlockedIncrementRelease InterlockedIncrement
  11300. #define InterlockedDecrement _InterlockedDecrement
  11301. #define InterlockedDecrementAcquire InterlockedDecrement
  11302. #define InterlockedDecrementRelease InterlockedDecrement
  11303. #define InterlockedAdd _InterlockedAdd
  11304. #define InterlockedExchange _InterlockedExchange
  11305. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  11306. #define InterlockedCompareExchange _InterlockedCompareExchange
  11307. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  11308. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  11309. #define InterlockedAnd64 _InterlockedAnd64
  11310. #define InterlockedOr64 _InterlockedOr64
  11311. #define InterlockedXor64 _InterlockedXor64
  11312. #define InterlockedIncrement64 _InterlockedIncrement64
  11313. #define InterlockedDecrement64 _InterlockedDecrement64
  11314. #define InterlockedAdd64 _InterlockedAdd64
  11315. #define InterlockedExchange64 _InterlockedExchange64
  11316. #define InterlockedExchangeAcquire64 InterlockedExchange64
  11317. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  11318. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  11319. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  11320. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  11321. #define InterlockedExchangePointer _InterlockedExchangePointer
  11322. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  11323. #ifdef __cplusplus
  11324. extern "C" {
  11325. #endif
  11326. LONG
  11327. InterlockedAnd (
  11328. IN OUT LONG volatile *Destination,
  11329. IN LONG Value
  11330. );
  11331. LONG
  11332. InterlockedOr (
  11333. IN OUT LONG volatile *Destination,
  11334. IN LONG Value
  11335. );
  11336. LONG
  11337. InterlockedXor (
  11338. IN OUT LONG volatile *Destination,
  11339. IN LONG Value
  11340. );
  11341. LONG64
  11342. InterlockedAnd64 (
  11343. IN OUT LONG64 volatile *Destination,
  11344. IN LONG64 Value
  11345. );
  11346. LONG64
  11347. InterlockedOr64 (
  11348. IN OUT LONG64 volatile *Destination,
  11349. IN LONG64 Value
  11350. );
  11351. LONG64
  11352. InterlockedXor64 (
  11353. IN OUT LONG64 volatile *Destination,
  11354. IN LONG64 Value
  11355. );
  11356. LONG
  11357. InterlockedIncrement(
  11358. IN OUT LONG volatile *Addend
  11359. );
  11360. LONG
  11361. InterlockedDecrement(
  11362. IN OUT LONG volatile *Addend
  11363. );
  11364. LONG
  11365. InterlockedExchange(
  11366. IN OUT LONG volatile *Target,
  11367. IN LONG Value
  11368. );
  11369. LONG
  11370. InterlockedExchangeAdd(
  11371. IN OUT LONG volatile *Addend,
  11372. IN LONG Value
  11373. );
  11374. #if !defined(_X86AMD64_)
  11375. __forceinline
  11376. LONG
  11377. InterlockedAdd(
  11378. IN OUT LONG volatile *Addend,
  11379. IN LONG Value
  11380. )
  11381. {
  11382. return InterlockedExchangeAdd(Addend, Value) + Value;
  11383. }
  11384. #endif
  11385. LONG
  11386. InterlockedCompareExchange (
  11387. IN OUT LONG volatile *Destination,
  11388. IN LONG ExChange,
  11389. IN LONG Comperand
  11390. );
  11391. LONG64
  11392. InterlockedIncrement64(
  11393. IN OUT LONG64 volatile *Addend
  11394. );
  11395. LONG64
  11396. InterlockedDecrement64(
  11397. IN OUT LONG64 volatile *Addend
  11398. );
  11399. LONG64
  11400. InterlockedExchange64(
  11401. IN OUT LONG64 volatile *Target,
  11402. IN LONG64 Value
  11403. );
  11404. LONG64
  11405. InterlockedExchangeAdd64(
  11406. IN OUT LONG64 volatile *Addend,
  11407. IN LONG64 Value
  11408. );
  11409. #if !defined(_X86AMD64_)
  11410. __forceinline
  11411. LONG64
  11412. InterlockedAdd64(
  11413. IN OUT LONG64 volatile *Addend,
  11414. IN LONG64 Value
  11415. )
  11416. {
  11417. return InterlockedExchangeAdd64(Addend, Value) + Value;
  11418. }
  11419. #endif
  11420. LONG64
  11421. InterlockedCompareExchange64 (
  11422. IN OUT LONG64 volatile *Destination,
  11423. IN LONG64 ExChange,
  11424. IN LONG64 Comperand
  11425. );
  11426. PVOID
  11427. InterlockedCompareExchangePointer (
  11428. IN OUT PVOID volatile *Destination,
  11429. IN PVOID Exchange,
  11430. IN PVOID Comperand
  11431. );
  11432. PVOID
  11433. InterlockedExchangePointer(
  11434. IN OUT PVOID volatile *Target,
  11435. IN PVOID Value
  11436. );
  11437. #pragma intrinsic(_InterlockedAnd)
  11438. #pragma intrinsic(_InterlockedOr)
  11439. #pragma intrinsic(_InterlockedXor)
  11440. #pragma intrinsic(_InterlockedIncrement)
  11441. #pragma intrinsic(_InterlockedDecrement)
  11442. #pragma intrinsic(_InterlockedExchange)
  11443. #pragma intrinsic(_InterlockedExchangeAdd)
  11444. #pragma intrinsic(_InterlockedCompareExchange)
  11445. #pragma intrinsic(_InterlockedAnd64)
  11446. #pragma intrinsic(_InterlockedOr64)
  11447. #pragma intrinsic(_InterlockedXor64)
  11448. #pragma intrinsic(_InterlockedIncrement64)
  11449. #pragma intrinsic(_InterlockedDecrement64)
  11450. #pragma intrinsic(_InterlockedExchange64)
  11451. #pragma intrinsic(_InterlockedExchangeAdd64)
  11452. #pragma intrinsic(_InterlockedCompareExchange64)
  11453. #pragma intrinsic(_InterlockedExchangePointer)
  11454. #pragma intrinsic(_InterlockedCompareExchangePointer)
  11455. #ifdef __cplusplus
  11456. }
  11457. #endif
  11458. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  11459. #if defined(_AMD64_)
  11460. //
  11461. // Types to use to contain PFNs and their counts.
  11462. //
  11463. typedef ULONG PFN_COUNT;
  11464. typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
  11465. typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
  11466. //
  11467. // Define maximum size of flush multiple TB request.
  11468. //
  11469. #define FLUSH_MULTIPLE_MAXIMUM 32
  11470. //
  11471. // Indicate that the AMD64 compiler supports the allocate pragmas.
  11472. //
  11473. #define ALLOC_PRAGMA 1
  11474. #define ALLOC_DATA_PRAGMA 1
  11475. #define NORMAL_DISPATCH_LENGTH 106
  11476. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  11477. //
  11478. // Interrupt Request Level definitions
  11479. //
  11480. #define PASSIVE_LEVEL 0 // Passive release level
  11481. #define LOW_LEVEL 0 // Lowest interrupt level
  11482. #define APC_LEVEL 1 // APC interrupt level
  11483. #define DISPATCH_LEVEL 2 // Dispatcher level
  11484. #define CLOCK_LEVEL 13 // Interval clock level
  11485. #define IPI_LEVEL 14 // Interprocessor interrupt level
  11486. #define POWER_LEVEL 14 // Power failure level
  11487. #define PROFILE_LEVEL 15 // timer used for profiling.
  11488. #define HIGH_LEVEL 15 // Highest interrupt level
  11489. #define SYNCH_LEVEL (IPI_LEVEL-2)
  11490. //
  11491. // I/O space read and write macros.
  11492. //
  11493. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  11494. //
  11495. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  11496. //
  11497. __forceinline
  11498. UCHAR
  11499. READ_REGISTER_UCHAR (
  11500. volatile UCHAR *Register
  11501. )
  11502. {
  11503. return *Register;
  11504. }
  11505. __forceinline
  11506. USHORT
  11507. READ_REGISTER_USHORT (
  11508. volatile USHORT *Register
  11509. )
  11510. {
  11511. return *Register;
  11512. }
  11513. __forceinline
  11514. ULONG
  11515. READ_REGISTER_ULONG (
  11516. volatile ULONG *Register
  11517. )
  11518. {
  11519. return *Register;
  11520. }
  11521. __forceinline
  11522. VOID
  11523. READ_REGISTER_BUFFER_UCHAR (
  11524. PUCHAR Register,
  11525. PUCHAR Buffer,
  11526. ULONG Count
  11527. )
  11528. {
  11529. __movsb(Buffer, Register, Count);
  11530. return;
  11531. }
  11532. __forceinline
  11533. VOID
  11534. READ_REGISTER_BUFFER_USHORT (
  11535. PUSHORT Register,
  11536. PUSHORT Buffer,
  11537. ULONG Count
  11538. )
  11539. {
  11540. __movsw(Buffer, Register, Count);
  11541. return;
  11542. }
  11543. __forceinline
  11544. VOID
  11545. READ_REGISTER_BUFFER_ULONG (
  11546. PULONG Register,
  11547. PULONG Buffer,
  11548. ULONG Count
  11549. )
  11550. {
  11551. __movsd(Buffer, Register, Count);
  11552. return;
  11553. }
  11554. __forceinline
  11555. VOID
  11556. WRITE_REGISTER_UCHAR (
  11557. PUCHAR Register,
  11558. UCHAR Value
  11559. )
  11560. {
  11561. *Register = Value;
  11562. StoreFence();
  11563. return;
  11564. }
  11565. __forceinline
  11566. VOID
  11567. WRITE_REGISTER_USHORT (
  11568. PUSHORT Register,
  11569. USHORT Value
  11570. )
  11571. {
  11572. *Register = Value;
  11573. StoreFence();
  11574. return;
  11575. }
  11576. __forceinline
  11577. VOID
  11578. WRITE_REGISTER_ULONG (
  11579. PULONG Register,
  11580. ULONG Value
  11581. )
  11582. {
  11583. *Register = Value;
  11584. StoreFence();
  11585. return;
  11586. }
  11587. __forceinline
  11588. VOID
  11589. WRITE_REGISTER_BUFFER_UCHAR (
  11590. PUCHAR Register,
  11591. PUCHAR Buffer,
  11592. ULONG Count
  11593. )
  11594. {
  11595. __movsb(Register, Buffer, Count);
  11596. StoreFence();
  11597. return;
  11598. }
  11599. __forceinline
  11600. VOID
  11601. WRITE_REGISTER_BUFFER_USHORT (
  11602. PUSHORT Register,
  11603. PUSHORT Buffer,
  11604. ULONG Count
  11605. )
  11606. {
  11607. __movsw(Register, Buffer, Count);
  11608. StoreFence();
  11609. return;
  11610. }
  11611. __forceinline
  11612. VOID
  11613. WRITE_REGISTER_BUFFER_ULONG (
  11614. PULONG Register,
  11615. PULONG Buffer,
  11616. ULONG Count
  11617. )
  11618. {
  11619. __movsd(Register, Buffer, Count);
  11620. StoreFence();
  11621. return;
  11622. }
  11623. __forceinline
  11624. UCHAR
  11625. READ_PORT_UCHAR (
  11626. PUCHAR Port
  11627. )
  11628. {
  11629. return __inbyte((USHORT)((ULONG64)Port));
  11630. }
  11631. __forceinline
  11632. USHORT
  11633. READ_PORT_USHORT (
  11634. PUSHORT Port
  11635. )
  11636. {
  11637. return __inword((USHORT)((ULONG64)Port));
  11638. }
  11639. __forceinline
  11640. ULONG
  11641. READ_PORT_ULONG (
  11642. PULONG Port
  11643. )
  11644. {
  11645. return __indword((USHORT)((ULONG64)Port));
  11646. }
  11647. __forceinline
  11648. VOID
  11649. READ_PORT_BUFFER_UCHAR (
  11650. PUCHAR Port,
  11651. PUCHAR Buffer,
  11652. ULONG Count
  11653. )
  11654. {
  11655. __inbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  11656. return;
  11657. }
  11658. __forceinline
  11659. VOID
  11660. READ_PORT_BUFFER_USHORT (
  11661. PUSHORT Port,
  11662. PUSHORT Buffer,
  11663. ULONG Count
  11664. )
  11665. {
  11666. __inwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  11667. return;
  11668. }
  11669. __forceinline
  11670. VOID
  11671. READ_PORT_BUFFER_ULONG (
  11672. PULONG Port,
  11673. PULONG Buffer,
  11674. ULONG Count
  11675. )
  11676. {
  11677. __indwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  11678. return;
  11679. }
  11680. __forceinline
  11681. VOID
  11682. WRITE_PORT_UCHAR (
  11683. PUCHAR Port,
  11684. UCHAR Value
  11685. )
  11686. {
  11687. __outbyte((USHORT)((ULONG64)Port), Value);
  11688. return;
  11689. }
  11690. __forceinline
  11691. VOID
  11692. WRITE_PORT_USHORT (
  11693. PUSHORT Port,
  11694. USHORT Value
  11695. )
  11696. {
  11697. __outword((USHORT)((ULONG64)Port), Value);
  11698. return;
  11699. }
  11700. __forceinline
  11701. VOID
  11702. WRITE_PORT_ULONG (
  11703. PULONG Port,
  11704. ULONG Value
  11705. )
  11706. {
  11707. __outdword((USHORT)((ULONG64)Port), Value);
  11708. return;
  11709. }
  11710. __forceinline
  11711. VOID
  11712. WRITE_PORT_BUFFER_UCHAR (
  11713. PUCHAR Port,
  11714. PUCHAR Buffer,
  11715. ULONG Count
  11716. )
  11717. {
  11718. __outbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  11719. return;
  11720. }
  11721. __forceinline
  11722. VOID
  11723. WRITE_PORT_BUFFER_USHORT (
  11724. PUSHORT Port,
  11725. PUSHORT Buffer,
  11726. ULONG Count
  11727. )
  11728. {
  11729. __outwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  11730. return;
  11731. }
  11732. __forceinline
  11733. VOID
  11734. WRITE_PORT_BUFFER_ULONG (
  11735. PULONG Port,
  11736. PULONG Buffer,
  11737. ULONG Count
  11738. )
  11739. {
  11740. __outdwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  11741. return;
  11742. }
  11743. // end_ntndis
  11744. //
  11745. // Get data cache fill size.
  11746. //
  11747. #if PRAGMA_DEPRECATED_DDK
  11748. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  11749. #endif
  11750. #define KeGetDcacheFillSize() 1L
  11751. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  11752. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  11753. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  11754. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  11755. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  11756. #define KI_USER_SHARED_DATA 0xFFFFF78000000000UI64
  11757. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  11758. #define SharedInterruptTime (KI_USER_SHARED_DATA + 0x8)
  11759. #define SharedSystemTime (KI_USER_SHARED_DATA + 0x14)
  11760. #define SharedTickCount (KI_USER_SHARED_DATA + 0x320)
  11761. #define KeQueryInterruptTime() *((volatile ULONG64 *)(SharedInterruptTime))
  11762. #define KeQuerySystemTime(CurrentCount) \
  11763. *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedSystemTime))
  11764. #define KeQueryTickCount(CurrentCount) \
  11765. *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedTickCount))
  11766. //
  11767. // Processor Control Region Structure Definition
  11768. //
  11769. #define PCR_MINOR_VERSION 1
  11770. #define PCR_MAJOR_VERSION 1
  11771. typedef struct _KPCR {
  11772. //
  11773. // Start of the architecturally defined section of the PCR. This section
  11774. // may be directly addressed by vendor/platform specific HAL code and will
  11775. // not change from version to version of NT.
  11776. //
  11777. // Certain fields in the TIB are not used in kernel mode. These include the
  11778. // exception list, stack base, stack limit, subsystem TIB, fiber data, and
  11779. // the arbitrary user pointer. Therefore, these fields are overlaid with
  11780. // other data to get better cache locality.
  11781. union {
  11782. NT_TIB NtTib;
  11783. struct {
  11784. union _KGDTENTRY64 *GdtBase;
  11785. struct _KTSS64 *TssBase;
  11786. PVOID PerfGlobalGroupMask;
  11787. struct _KPCR *Self;
  11788. ULONG ContextSwitches;
  11789. ULONG NotUsed;
  11790. KAFFINITY SetMember;
  11791. PVOID Used_Self;
  11792. };
  11793. };
  11794. struct _KPRCB *CurrentPrcb;
  11795. ULONG64 SavedRcx;
  11796. ULONG64 SavedR11;
  11797. KIRQL Irql;
  11798. UCHAR SecondLevelCacheAssociativity;
  11799. UCHAR Number;
  11800. UCHAR Fill0;
  11801. ULONG Irr;
  11802. ULONG IrrActive;
  11803. ULONG Idr;
  11804. USHORT MajorVersion;
  11805. USHORT MinorVersion;
  11806. ULONG StallScaleFactor;
  11807. union _KIDTENTRY64 *IdtBase;
  11808. PVOID Unused1;
  11809. PVOID Unused2;
  11810. } KPCR, *PKPCR;
  11811. //
  11812. // Exception frame
  11813. //
  11814. // This frame is established when handling an exception. It provides a place
  11815. // to save all nonvolatile registers. The volatile registers will already
  11816. // have been saved in a trap frame.
  11817. //
  11818. // N.B. The exception frame has a built in exception record capable of
  11819. // storing information for four parameter values. This exception
  11820. // record is used exclusively within the trap handling code.
  11821. //
  11822. #define EXCEPTION_AREA_SIZE 64
  11823. typedef struct _KEXCEPTION_FRAME {
  11824. //
  11825. // Home address for the parameter registers.
  11826. //
  11827. ULONG64 P1Home;
  11828. ULONG64 P2Home;
  11829. ULONG64 P3Home;
  11830. ULONG64 P4Home;
  11831. ULONG64 P5;
  11832. //
  11833. // Kernel callout initial stack value.
  11834. //
  11835. ULONG64 InitialStack;
  11836. //
  11837. // Saved nonvolatile floating registers.
  11838. //
  11839. M128 Xmm6;
  11840. M128 Xmm7;
  11841. M128 Xmm8;
  11842. M128 Xmm9;
  11843. M128 Xmm10;
  11844. M128 Xmm11;
  11845. M128 Xmm12;
  11846. M128 Xmm13;
  11847. M128 Xmm14;
  11848. M128 Xmm15;
  11849. //
  11850. // Kernel callout frame variables.
  11851. //
  11852. ULONG64 TrapFrame;
  11853. ULONG64 CallbackStack;
  11854. ULONG64 OutputBuffer;
  11855. ULONG64 OutputLength;
  11856. //
  11857. // Exception record for exceptions.
  11858. //
  11859. UCHAR ExceptionRecord[EXCEPTION_AREA_SIZE];
  11860. //
  11861. // Saved nonvolatile register - not always saved.
  11862. //
  11863. ULONG64 Fill1;
  11864. ULONG64 Rbp;
  11865. //
  11866. // Saved nonvolatile registers.
  11867. //
  11868. ULONG64 Rbx;
  11869. ULONG64 Rdi;
  11870. ULONG64 Rsi;
  11871. ULONG64 R12;
  11872. ULONG64 R13;
  11873. ULONG64 R14;
  11874. ULONG64 R15;
  11875. //
  11876. // EFLAGS and return address.
  11877. //
  11878. ULONG64 Return;
  11879. } KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
  11880. //
  11881. // Trap frame
  11882. //
  11883. // This frame is established when handling a trap. It provides a place to
  11884. // save all volatile registers. The nonvolatile registers are saved in an
  11885. // exception frame or through the normal C calling conventions for saved
  11886. // registers.
  11887. //
  11888. typedef struct _KTRAP_FRAME {
  11889. //
  11890. // Home address for the parameter registers.
  11891. //
  11892. ULONG64 P1Home;
  11893. ULONG64 P2Home;
  11894. ULONG64 P3Home;
  11895. ULONG64 P4Home;
  11896. ULONG64 P5;
  11897. //
  11898. // Previous processor mode (system services only) and previous IRQL
  11899. // (interrupts only).
  11900. //
  11901. KPROCESSOR_MODE PreviousMode;
  11902. KIRQL PreviousIrql;
  11903. //
  11904. // Page fault load/store indicator.
  11905. //
  11906. UCHAR FaultIndicator;
  11907. UCHAR Fill0;
  11908. //
  11909. // Floating point state.
  11910. //
  11911. ULONG MxCsr;
  11912. //
  11913. // Volatile registers.
  11914. //
  11915. // N.B. These registers are only saved on exceptions and interrupts. They
  11916. // are not saved for system calls.
  11917. //
  11918. ULONG64 Rax;
  11919. ULONG64 Rcx;
  11920. ULONG64 Rdx;
  11921. ULONG64 R8;
  11922. ULONG64 R9;
  11923. ULONG64 R10;
  11924. ULONG64 R11;
  11925. ULONG64 Spare0;
  11926. //
  11927. // Volatile floating registers.
  11928. //
  11929. // N.B. These registers are only saved on exceptions and interrupts. They
  11930. // are not saved for system calls.
  11931. //
  11932. M128 Xmm0;
  11933. M128 Xmm1;
  11934. M128 Xmm2;
  11935. M128 Xmm3;
  11936. M128 Xmm4;
  11937. M128 Xmm5;
  11938. //
  11939. // Page fault address.
  11940. //
  11941. ULONG64 FaultAddress;
  11942. //
  11943. // Debug registers.
  11944. //
  11945. ULONG64 Dr0;
  11946. ULONG64 Dr1;
  11947. ULONG64 Dr2;
  11948. ULONG64 Dr3;
  11949. ULONG64 Dr6;
  11950. ULONG64 Dr7;
  11951. //
  11952. // Special debug registers.
  11953. //
  11954. ULONG64 DebugControl;
  11955. ULONG64 LastBranchToRip;
  11956. ULONG64 LastBranchFromRip;
  11957. ULONG64 LastExceptionToRip;
  11958. ULONG64 LastExceptionFromRip;
  11959. //
  11960. // Segment registers
  11961. //
  11962. USHORT SegDs;
  11963. USHORT SegEs;
  11964. USHORT SegFs;
  11965. USHORT SegGs;
  11966. //
  11967. // Previous trap frame address.
  11968. //
  11969. ULONG64 TrapFrame;
  11970. //
  11971. // Saved nonvolatile registers RBX, RDI and RSI. These registers are only
  11972. // saved in system service trap frames.
  11973. //
  11974. ULONG64 Rbx;
  11975. ULONG64 Rdi;
  11976. ULONG64 Rsi;
  11977. //
  11978. // Saved nonvolatile register RBP. This register is used as a frame
  11979. // pointer during trap processing and is saved in all trap frames.
  11980. //
  11981. ULONG64 Rbp;
  11982. //
  11983. // Information pushed by hardware.
  11984. //
  11985. // N.B. The error code is not always pushed by hardware. For those cases
  11986. // where it is not pushed by hardware a dummy error code is allocated
  11987. // on the stack.
  11988. //
  11989. ULONG64 ErrorCode;
  11990. ULONG64 Rip;
  11991. USHORT SegCs;
  11992. USHORT Fill1[3];
  11993. ULONG EFlags;
  11994. ULONG Fill2;
  11995. ULONG64 Rsp;
  11996. USHORT SegSs;
  11997. USHORT Fill3[3];
  11998. } KTRAP_FRAME, *PKTRAP_FRAME;
  11999. //
  12000. // The nonvolatile floating state
  12001. //
  12002. typedef struct _KFLOATING_SAVE {
  12003. ULONG MxCsr;
  12004. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  12005. //
  12006. // AMD64 Specific portions of mm component.
  12007. //
  12008. // Define the page size for the AMD64 as 4096 (0x1000).
  12009. //
  12010. #define PAGE_SIZE 0x1000
  12011. //
  12012. // Define the number of trailing zeroes in a page aligned virtual address.
  12013. // This is used as the shift count when shifting virtual addresses to
  12014. // virtual page numbers.
  12015. //
  12016. #define PAGE_SHIFT 12L
  12017. // end_ntndis end_wdm
  12018. #define PXE_BASE 0xFFFFF6FB7DBED000UI64
  12019. #define PXE_SELFMAP 0xFFFFF6FB7DBEDF68UI64
  12020. #define PPE_BASE 0xFFFFF6FB7DA00000UI64
  12021. #define PDE_BASE 0xFFFFF6FB40000000UI64
  12022. #define PTE_BASE 0xFFFFF68000000000UI64
  12023. #define PXE_TOP 0xFFFFF6FB7DBEDFFFUI64
  12024. #define PPE_TOP 0xFFFFF6FB7DBFFFFFUI64
  12025. #define PDE_TOP 0xFFFFF6FB7FFFFFFFUI64
  12026. #define PTE_TOP 0xFFFFF6FFFFFFFFFFUI64
  12027. #define PDE_KTBASE_AMD64 PPE_BASE
  12028. #define PTI_SHIFT 12
  12029. #define PDI_SHIFT 21
  12030. #define PPI_SHIFT 30
  12031. #define PXI_SHIFT 39
  12032. #define PTE_PER_PAGE 512
  12033. #define PDE_PER_PAGE 512
  12034. #define PPE_PER_PAGE 512
  12035. #define PXE_PER_PAGE 512
  12036. #define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
  12037. #define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
  12038. #define PPI_MASK (PPE_PER_PAGE - 1)
  12039. #define PXI_MASK (PXE_PER_PAGE - 1)
  12040. //
  12041. // Define the highest user address and user probe address.
  12042. //
  12043. extern PVOID *MmHighestUserAddress;
  12044. extern PVOID *MmSystemRangeStart;
  12045. extern ULONG64 *MmUserProbeAddress;
  12046. #define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
  12047. #define MM_SYSTEM_RANGE_START *MmSystemRangeStart
  12048. #define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
  12049. //
  12050. // The lowest user address reserves the low 64k.
  12051. //
  12052. #define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
  12053. //
  12054. // The lowest address for system space.
  12055. //
  12056. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000
  12057. // begin_wdm
  12058. #define MmGetProcedureAddress(Address) (Address)
  12059. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  12060. //
  12061. // Intrinsic functions
  12062. //
  12063. // begin_wdm
  12064. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  12065. // end_wdm
  12066. //
  12067. // The following routines are provided for backward compatibility with old
  12068. // code. They are no longer the preferred way to accomplish these functions.
  12069. //
  12070. #if PRAGMA_DEPRECATED_DDK
  12071. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  12072. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  12073. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  12074. #endif
  12075. #define RESULT_ZERO 0
  12076. #define RESULT_NEGATIVE 1
  12077. #define RESULT_POSITIVE 2
  12078. typedef enum _INTERLOCKED_RESULT {
  12079. ResultNegative = RESULT_NEGATIVE,
  12080. ResultZero = RESULT_ZERO,
  12081. ResultPositive = RESULT_POSITIVE
  12082. } INTERLOCKED_RESULT;
  12083. #define ExInterlockedDecrementLong(Addend, Lock) \
  12084. _ExInterlockedDecrementLong(Addend)
  12085. __forceinline
  12086. LONG
  12087. _ExInterlockedDecrementLong (
  12088. IN OUT PLONG Addend
  12089. )
  12090. {
  12091. LONG Result;
  12092. Result = InterlockedDecrement(Addend);
  12093. if (Result < 0) {
  12094. return ResultNegative;
  12095. } else if (Result > 0) {
  12096. return ResultPositive;
  12097. } else {
  12098. return ResultZero;
  12099. }
  12100. }
  12101. #define ExInterlockedIncrementLong(Addend, Lock) \
  12102. _ExInterlockedIncrementLong(Addend)
  12103. __forceinline
  12104. LONG
  12105. _ExInterlockedIncrementLong (
  12106. IN OUT PLONG Addend
  12107. )
  12108. {
  12109. LONG Result;
  12110. Result = InterlockedIncrement(Addend);
  12111. if (Result < 0) {
  12112. return ResultNegative;
  12113. } else if (Result > 0) {
  12114. return ResultPositive;
  12115. } else {
  12116. return ResultZero;
  12117. }
  12118. }
  12119. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  12120. _ExInterlockedExchangeUlong(Target, Value)
  12121. __forceinline
  12122. _ExInterlockedExchangeUlong (
  12123. IN OUT PULONG Target,
  12124. IN ULONG Value
  12125. )
  12126. {
  12127. return (ULONG)InterlockedExchange((PLONG)Target, (LONG)Value);
  12128. }
  12129. // begin_wdm
  12130. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  12131. #if !defined(MIDL_PASS) && defined(_M_AMD64)
  12132. //
  12133. // AMD646 function prototype definitions
  12134. //
  12135. // end_wdm
  12136. //
  12137. // Get the current processor number
  12138. //
  12139. __forceinline
  12140. ULONG
  12141. KeGetCurrentProcessorNumber (
  12142. VOID
  12143. )
  12144. {
  12145. return (ULONG)__readgsbyte(FIELD_OFFSET(KPCR, Number));
  12146. }
  12147. // begin_wdm
  12148. #endif // !defined(MIDL_PASS) && defined(_M_AMD64)
  12149. //++
  12150. //
  12151. //
  12152. // VOID
  12153. // KeMemoryBarrier (
  12154. // VOID
  12155. // )
  12156. //
  12157. // VOID
  12158. // KeMemoryBarrierWithoutFence (
  12159. // VOID
  12160. // )
  12161. //
  12162. //
  12163. // Routine Description:
  12164. //
  12165. // These functions order memory accesses as seen by other processors.
  12166. //
  12167. // Arguments:
  12168. //
  12169. // None.
  12170. //
  12171. // Return Value:
  12172. //
  12173. // None.
  12174. //
  12175. //--
  12176. #if !defined(_CROSS_PLATFORM_)
  12177. #ifdef __cplusplus
  12178. extern "C" {
  12179. #endif
  12180. VOID
  12181. _ReadWriteBarrier (
  12182. VOID
  12183. );
  12184. #pragma intrinsic(_ReadWriteBarrier)
  12185. #ifdef __cplusplus
  12186. }
  12187. #endif
  12188. #define KeMemoryBarrier() _ReadWriteBarrier()
  12189. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  12190. #else
  12191. #define KeMemoryBarrier()
  12192. #define KeMemoryBarrierWithoutFence()
  12193. #endif
  12194. NTKERNELAPI
  12195. NTSTATUS
  12196. KeSaveFloatingPointState (
  12197. OUT PKFLOATING_SAVE SaveArea
  12198. );
  12199. NTKERNELAPI
  12200. NTSTATUS
  12201. KeRestoreFloatingPointState (
  12202. IN PKFLOATING_SAVE SaveArea
  12203. );
  12204. #endif // defined(_AMD64_)
  12205. #if defined(_AMD64_)
  12206. NTKERNELAPI
  12207. KIRQL
  12208. KeGetCurrentIrql (
  12209. VOID
  12210. );
  12211. NTKERNELAPI
  12212. VOID
  12213. KeLowerIrql (
  12214. IN KIRQL NewIrql
  12215. );
  12216. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  12217. NTKERNELAPI
  12218. KIRQL
  12219. KfRaiseIrql (
  12220. IN KIRQL NewIrql
  12221. );
  12222. // end_wdm
  12223. NTKERNELAPI
  12224. KIRQL
  12225. KeRaiseIrqlToDpcLevel (
  12226. VOID
  12227. );
  12228. NTKERNELAPI
  12229. KIRQL
  12230. KeRaiseIrqlToSynchLevel (
  12231. VOID
  12232. );
  12233. // begin_wdm
  12234. #endif // defined(_AMD64_)
  12235. #if defined(_IA64_)
  12236. //
  12237. // Types to use to contain PFNs and their counts.
  12238. //
  12239. typedef ULONG PFN_COUNT;
  12240. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  12241. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  12242. //
  12243. // Indicate that the IA64 compiler supports the pragma textout construct.
  12244. //
  12245. #define ALLOC_PRAGMA 1
  12246. //
  12247. // Define intrinsic calls and their prototypes
  12248. //
  12249. #include "ia64reg.h"
  12250. #ifdef __cplusplus
  12251. extern "C" {
  12252. #endif
  12253. unsigned __int64 __getReg (int);
  12254. void __setReg (int, unsigned __int64);
  12255. void __isrlz (void);
  12256. void __dsrlz (void);
  12257. void __fwb (void);
  12258. void __mf (void);
  12259. void __mfa (void);
  12260. void __synci (void);
  12261. __int64 __thash (__int64);
  12262. __int64 __ttag (__int64);
  12263. void __ptcl (__int64, __int64);
  12264. void __ptcg (__int64, __int64);
  12265. void __ptcga (__int64, __int64);
  12266. void __ptri (__int64, __int64);
  12267. void __ptrd (__int64, __int64);
  12268. void __invalat (void);
  12269. void __break (int);
  12270. void __fc (__int64);
  12271. void __fci (__int64);
  12272. void __sum (int);
  12273. void __rsm (int);
  12274. void _ReleaseSpinLock( unsigned __int64 *);
  12275. void __yield();
  12276. void __lfetch(int, void const *);
  12277. void __lfetchfault(int, void const *);
  12278. #ifdef _M_IA64
  12279. #pragma intrinsic (__getReg)
  12280. #pragma intrinsic (__setReg)
  12281. #pragma intrinsic (__isrlz)
  12282. #pragma intrinsic (__dsrlz)
  12283. #pragma intrinsic (__fwb)
  12284. #pragma intrinsic (__mf)
  12285. #pragma intrinsic (__mfa)
  12286. #pragma intrinsic (__synci)
  12287. #pragma intrinsic (__thash)
  12288. #pragma intrinsic (__ttag)
  12289. #pragma intrinsic (__ptcl)
  12290. #pragma intrinsic (__ptcg)
  12291. #pragma intrinsic (__ptcga)
  12292. #pragma intrinsic (__ptri)
  12293. #pragma intrinsic (__ptrd)
  12294. #pragma intrinsic (__invalat)
  12295. #pragma intrinsic (__break)
  12296. #pragma intrinsic (__fc)
  12297. #pragma intrinsic (__fci)
  12298. #pragma intrinsic (__sum)
  12299. #pragma intrinsic (__rsm)
  12300. #pragma intrinsic (_ReleaseSpinLock)
  12301. #pragma intrinsic (__yield)
  12302. #pragma intrinsic (__lfetch)
  12303. #pragma intrinsic (__lfetchfault)
  12304. #endif // _M_IA64
  12305. #ifdef __cplusplus
  12306. }
  12307. #endif
  12308. // end_ntndis
  12309. //
  12310. // Define length of interrupt vector table.
  12311. //
  12312. #define MAXIMUM_VECTOR 256
  12313. // end_wdm
  12314. //
  12315. // IA64 specific interlocked operation result values.
  12316. //
  12317. #define RESULT_ZERO 0
  12318. #define RESULT_NEGATIVE 1
  12319. #define RESULT_POSITIVE 2
  12320. //
  12321. // Interlocked result type is portable, but its values are machine specific.
  12322. // Constants for values are in i386.h, mips.h, etc.
  12323. //
  12324. typedef enum _INTERLOCKED_RESULT {
  12325. ResultNegative = RESULT_NEGATIVE,
  12326. ResultZero = RESULT_ZERO,
  12327. ResultPositive = RESULT_POSITIVE
  12328. } INTERLOCKED_RESULT;
  12329. //
  12330. // Convert portable interlock interfaces to architecture specific interfaces.
  12331. //
  12332. #if PRAGMA_DEPRECATED_DDK
  12333. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  12334. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  12335. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  12336. #endif
  12337. #define ExInterlockedIncrementLong(Addend, Lock) \
  12338. ExIa64InterlockedIncrementLong(Addend)
  12339. #define ExInterlockedDecrementLong(Addend, Lock) \
  12340. ExIa64InterlockedDecrementLong(Addend)
  12341. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  12342. ExIa64InterlockedExchangeUlong(Target, Value)
  12343. NTKERNELAPI
  12344. INTERLOCKED_RESULT
  12345. ExIa64InterlockedIncrementLong (
  12346. IN PLONG Addend
  12347. );
  12348. NTKERNELAPI
  12349. INTERLOCKED_RESULT
  12350. ExIa64InterlockedDecrementLong (
  12351. IN PLONG Addend
  12352. );
  12353. NTKERNELAPI
  12354. ULONG
  12355. ExIa64InterlockedExchangeUlong (
  12356. IN PULONG Target,
  12357. IN ULONG Value
  12358. );
  12359. // begin_wdm
  12360. //
  12361. // IA64 Interrupt Definitions.
  12362. //
  12363. //
  12364. // Define length of interrupt object dispatch code in longwords.
  12365. //
  12366. #define DISPATCH_LENGTH 2*2 // Length of dispatch code template in 32-bit words
  12367. // Begin of a block of definitions that must be synchronized with kxia64.h.
  12368. //
  12369. //
  12370. // Define Interrupt Request Levels.
  12371. //
  12372. #define PASSIVE_LEVEL 0 // Passive release level
  12373. #define LOW_LEVEL 0 // Lowest interrupt level
  12374. #define APC_LEVEL 1 // APC interrupt level
  12375. #define DISPATCH_LEVEL 2 // Dispatcher level
  12376. #define CMC_LEVEL 3 // Correctable machine check level
  12377. #define DEVICE_LEVEL_BASE 4 // 4 - 11 - Device IRQLs
  12378. #define PC_LEVEL 12 // Performance Counter IRQL
  12379. #define IPI_LEVEL 14 // IPI IRQL
  12380. #define CLOCK_LEVEL 13 // Clock Timer IRQL
  12381. #define POWER_LEVEL 15 // Power failure level
  12382. #define PROFILE_LEVEL 15 // Profiling level
  12383. #define HIGH_LEVEL 15 // Highest interrupt level
  12384. #if defined(_M_IA64) && !defined(RC_INVOKED)
  12385. #define InterlockedAdd _InterlockedAdd
  12386. #define InterlockedIncrement _InterlockedIncrement
  12387. #define InterlockedIncrementAcquire _InterlockedIncrement_acq
  12388. #define InterlockedIncrementRelease _InterlockedIncrement_rel
  12389. #define InterlockedDecrement _InterlockedDecrement
  12390. #define InterlockedDecrementAcquire _InterlockedDecrement_acq
  12391. #define InterlockedDecrementRelease _InterlockedDecrement_rel
  12392. #define InterlockedExchange _InterlockedExchange
  12393. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  12394. #define InterlockedAdd64 _InterlockedAdd64
  12395. #define InterlockedIncrement64 _InterlockedIncrement64
  12396. #define InterlockedDecrement64 _InterlockedDecrement64
  12397. #define InterlockedExchange64 _InterlockedExchange64
  12398. #define InterlockedExchangeAcquire64 _InterlockedExchange64_acq
  12399. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  12400. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  12401. #define InterlockedCompareExchangeAcquire64 _InterlockedCompareExchange64_acq
  12402. #define InterlockedCompareExchangeRelease64 _InterlockedCompareExchange64_rel
  12403. #define InterlockedCompareExchange _InterlockedCompareExchange
  12404. #define InterlockedCompareExchangeAcquire _InterlockedCompareExchange_acq
  12405. #define InterlockedCompareExchangeRelease _InterlockedCompareExchange_rel
  12406. #define InterlockedExchangePointer _InterlockedExchangePointer
  12407. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  12408. #ifdef __cplusplus
  12409. extern "C" {
  12410. #endif
  12411. LONG
  12412. __cdecl
  12413. InterlockedAdd (
  12414. LONG volatile *Addend,
  12415. LONG Value
  12416. );
  12417. LONGLONG
  12418. __cdecl
  12419. InterlockedAdd64 (
  12420. LONGLONG volatile *Addend,
  12421. LONGLONG Value
  12422. );
  12423. LONG
  12424. __cdecl
  12425. InterlockedIncrement(
  12426. IN OUT LONG volatile *Addend
  12427. );
  12428. LONG
  12429. __cdecl
  12430. InterlockedDecrement(
  12431. IN OUT LONG volatile *Addend
  12432. );
  12433. LONG
  12434. __cdecl
  12435. InterlockedIncrementAcquire(
  12436. IN OUT LONG volatile *Addend
  12437. );
  12438. LONG
  12439. __cdecl
  12440. InterlockedDecrementAcquire(
  12441. IN OUT LONG volatile *Addend
  12442. );
  12443. LONG
  12444. __cdecl
  12445. InterlockedIncrementRelease(
  12446. IN OUT LONG volatile *Addend
  12447. );
  12448. LONG
  12449. __cdecl
  12450. InterlockedDecrementRelease(
  12451. IN OUT LONG volatile *Addend
  12452. );
  12453. LONG
  12454. __cdecl
  12455. InterlockedExchange(
  12456. IN OUT LONG volatile *Target,
  12457. IN LONG Value
  12458. );
  12459. LONG
  12460. __cdecl
  12461. InterlockedExchangeAdd(
  12462. IN OUT LONG volatile *Addend,
  12463. IN LONG Value
  12464. );
  12465. LONG
  12466. __cdecl
  12467. InterlockedCompareExchange (
  12468. IN OUT LONG volatile *Destination,
  12469. IN LONG ExChange,
  12470. IN LONG Comperand
  12471. );
  12472. LONG
  12473. __cdecl
  12474. InterlockedCompareExchangeRelease (
  12475. IN OUT LONG volatile *Destination,
  12476. IN LONG ExChange,
  12477. IN LONG Comperand
  12478. );
  12479. LONG
  12480. __cdecl
  12481. InterlockedCompareExchangeAcquire (
  12482. IN OUT LONG volatile *Destination,
  12483. IN LONG ExChange,
  12484. IN LONG Comperand
  12485. );
  12486. LONGLONG
  12487. __cdecl
  12488. InterlockedIncrement64(
  12489. IN OUT LONGLONG volatile *Addend
  12490. );
  12491. LONGLONG
  12492. __cdecl
  12493. InterlockedDecrement64(
  12494. IN OUT LONGLONG volatile *Addend
  12495. );
  12496. LONGLONG
  12497. __cdecl
  12498. InterlockedExchange64(
  12499. IN OUT LONGLONG volatile *Target,
  12500. IN LONGLONG Value
  12501. );
  12502. LONGLONG
  12503. __cdecl
  12504. InterlockedExchangeAcquire64(
  12505. IN OUT LONGLONG volatile *Target,
  12506. IN LONGLONG Value
  12507. );
  12508. LONGLONG
  12509. __cdecl
  12510. InterlockedExchangeAdd64(
  12511. IN OUT LONGLONG volatile *Addend,
  12512. IN LONGLONG Value
  12513. );
  12514. LONGLONG
  12515. __cdecl
  12516. InterlockedCompareExchange64 (
  12517. IN OUT LONGLONG volatile *Destination,
  12518. IN LONGLONG ExChange,
  12519. IN LONGLONG Comperand
  12520. );
  12521. LONGLONG
  12522. __cdecl
  12523. InterlockedCompareExchangeAcquire64 (
  12524. IN OUT LONGLONG volatile *Destination,
  12525. IN LONGLONG ExChange,
  12526. IN LONGLONG Comperand
  12527. );
  12528. LONGLONG
  12529. __cdecl
  12530. InterlockedCompareExchangeRelease64 (
  12531. IN OUT LONGLONG volatile *Destination,
  12532. IN LONGLONG ExChange,
  12533. IN LONGLONG Comperand
  12534. );
  12535. PVOID
  12536. __cdecl
  12537. InterlockedCompareExchangePointer (
  12538. IN OUT PVOID volatile *Destination,
  12539. IN PVOID Exchange,
  12540. IN PVOID Comperand
  12541. );
  12542. PVOID
  12543. __cdecl
  12544. InterlockedExchangePointer(
  12545. IN OUT PVOID volatile *Target,
  12546. IN PVOID Value
  12547. );
  12548. #if !defined (InterlockedAnd64)
  12549. #define InterlockedAnd64 InterlockedAnd64_Inline
  12550. LONGLONG
  12551. FORCEINLINE
  12552. InterlockedAnd64_Inline (
  12553. IN OUT LONGLONG volatile *Destination,
  12554. IN LONGLONG Value
  12555. )
  12556. {
  12557. LONGLONG Old;
  12558. do {
  12559. Old = *Destination;
  12560. } while (InterlockedCompareExchange64(Destination,
  12561. Old & Value,
  12562. Old) != Old);
  12563. return Old;
  12564. }
  12565. #endif
  12566. #if !defined (InterlockedOr64)
  12567. #define InterlockedOr64 InterlockedOr64_Inline
  12568. LONGLONG
  12569. FORCEINLINE
  12570. InterlockedOr64_Inline (
  12571. IN OUT LONGLONG volatile *Destination,
  12572. IN LONGLONG Value
  12573. )
  12574. {
  12575. LONGLONG Old;
  12576. do {
  12577. Old = *Destination;
  12578. } while (InterlockedCompareExchange64(Destination,
  12579. Old | Value,
  12580. Old) != Old);
  12581. return Old;
  12582. }
  12583. #endif
  12584. #if !defined (InterlockedXor64)
  12585. #define InterlockedXor64 InterlockedXor64_Inline
  12586. LONGLONG
  12587. FORCEINLINE
  12588. InterlockedXor64_Inline (
  12589. IN OUT LONGLONG volatile *Destination,
  12590. IN LONGLONG Value
  12591. )
  12592. {
  12593. LONGLONG Old;
  12594. do {
  12595. Old = *Destination;
  12596. } while (InterlockedCompareExchange64(Destination,
  12597. Old ^ Value,
  12598. Old) != Old);
  12599. return Old;
  12600. }
  12601. #endif
  12602. #pragma intrinsic(_InterlockedAdd)
  12603. #pragma intrinsic(_InterlockedIncrement)
  12604. #pragma intrinsic(_InterlockedIncrement_acq)
  12605. #pragma intrinsic(_InterlockedIncrement_rel)
  12606. #pragma intrinsic(_InterlockedDecrement)
  12607. #pragma intrinsic(_InterlockedDecrement_acq)
  12608. #pragma intrinsic(_InterlockedDecrement_rel)
  12609. #pragma intrinsic(_InterlockedExchange)
  12610. #pragma intrinsic(_InterlockedCompareExchange)
  12611. #pragma intrinsic(_InterlockedCompareExchange_acq)
  12612. #pragma intrinsic(_InterlockedCompareExchange_rel)
  12613. #pragma intrinsic(_InterlockedExchangeAdd)
  12614. #pragma intrinsic(_InterlockedAdd64)
  12615. #pragma intrinsic(_InterlockedIncrement64)
  12616. #pragma intrinsic(_InterlockedDecrement64)
  12617. #pragma intrinsic(_InterlockedExchange64)
  12618. #pragma intrinsic(_InterlockedExchange64_acq)
  12619. #pragma intrinsic(_InterlockedCompareExchange64)
  12620. #pragma intrinsic(_InterlockedCompareExchange64_acq)
  12621. #pragma intrinsic(_InterlockedCompareExchange64_rel)
  12622. #pragma intrinsic(_InterlockedExchangeAdd64)
  12623. #pragma intrinsic(_InterlockedExchangePointer)
  12624. #pragma intrinsic(_InterlockedCompareExchangePointer)
  12625. #ifdef __cplusplus
  12626. }
  12627. #endif
  12628. #endif // defined(_M_IA64) && !defined(RC_INVOKED)
  12629. // end_wdm
  12630. __forceinline
  12631. LONG
  12632. InterlockedAnd (
  12633. IN OUT LONG volatile *Target,
  12634. LONG Set
  12635. )
  12636. {
  12637. LONG i;
  12638. LONG j;
  12639. j = *Target;
  12640. do {
  12641. i = j;
  12642. j = InterlockedCompareExchange(Target,
  12643. i & Set,
  12644. i);
  12645. } while (i != j);
  12646. return j;
  12647. }
  12648. __forceinline
  12649. LONG
  12650. InterlockedOr (
  12651. IN OUT LONG volatile *Target,
  12652. IN LONG Set
  12653. )
  12654. {
  12655. LONG i;
  12656. LONG j;
  12657. j = *Target;
  12658. do {
  12659. i = j;
  12660. j = InterlockedCompareExchange(Target,
  12661. i | Set,
  12662. i);
  12663. } while (i != j);
  12664. return j;
  12665. }
  12666. __forceinline
  12667. LONG
  12668. InterlockedXor (
  12669. IN OUT LONG volatile *Target,
  12670. IN LONG Set
  12671. )
  12672. {
  12673. LONG i;
  12674. LONG j;
  12675. j = *Target;
  12676. do {
  12677. i = j;
  12678. j = InterlockedCompareExchange(Target,
  12679. i ^ Set,
  12680. i);
  12681. } while (i != j);
  12682. return j;
  12683. }
  12684. #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
  12685. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  12686. // end_wdm
  12687. //
  12688. // Get address of processor control region.
  12689. //
  12690. #define KeGetPcr() PCR
  12691. //
  12692. // Get address of current kernel thread object.
  12693. //
  12694. #if defined(_M_IA64)
  12695. #define KeGetCurrentThread() PCR->CurrentThread
  12696. #endif
  12697. //
  12698. // Get current processor number.
  12699. //
  12700. #define KeGetCurrentProcessorNumber() ((ULONG)(PCR->Number))
  12701. //
  12702. // Get data cache fill size.
  12703. //
  12704. #if PRAGMA_DEPRECATED_DDK
  12705. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  12706. #endif
  12707. #define KeGetDcacheFillSize() PCR->DcacheFillSize
  12708. #define KeSaveFloatingPointState(a) STATUS_SUCCESS
  12709. #define KeRestoreFloatingPointState(a) STATUS_SUCCESS
  12710. //
  12711. //
  12712. // VOID
  12713. // KeMemoryBarrierWithoutFence (
  12714. // VOID
  12715. // )
  12716. //
  12717. //
  12718. // Routine Description:
  12719. //
  12720. // This function cases ordering of memory acceses generated by the compiler.
  12721. //
  12722. //
  12723. // Arguments:
  12724. //
  12725. // None.
  12726. //
  12727. // Return Value:
  12728. //
  12729. // None.
  12730. //--
  12731. #ifdef __cplusplus
  12732. extern "C" {
  12733. #endif
  12734. VOID
  12735. _ReadWriteBarrier (
  12736. VOID
  12737. );
  12738. #ifdef __cplusplus
  12739. }
  12740. #endif
  12741. #pragma intrinsic(_ReadWriteBarrier)
  12742. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  12743. //++
  12744. //
  12745. //
  12746. // VOID
  12747. // KeMemoryBarrier (
  12748. // VOID
  12749. // )
  12750. //
  12751. //
  12752. // Routine Description:
  12753. //
  12754. // This function cases ordering of memory acceses as generated by the compiler and
  12755. // as seen by other processors.
  12756. //
  12757. //
  12758. // Arguments:
  12759. //
  12760. // None.
  12761. //
  12762. // Return Value:
  12763. //
  12764. // None.
  12765. //--
  12766. #define KE_MEMORY_BARRIER_REQUIRED
  12767. #define KeMemoryBarrier() {_ReadWriteBarrier();__mf ();_ReadWriteBarrier();}
  12768. //
  12769. // Define the page size
  12770. //
  12771. #define PAGE_SIZE 0x2000
  12772. //
  12773. // Define the number of trailing zeroes in a page aligned virtual address.
  12774. // This is used as the shift count when shifting virtual addresses to
  12775. // virtual page numbers.
  12776. //
  12777. #define PAGE_SHIFT 13L
  12778. //
  12779. // Cache and write buffer flush functions.
  12780. //
  12781. NTKERNELAPI
  12782. VOID
  12783. KeFlushIoBuffers (
  12784. IN PMDL Mdl,
  12785. IN BOOLEAN ReadOperation,
  12786. IN BOOLEAN DmaOperation
  12787. );
  12788. //
  12789. // Kernel breakin breakpoint
  12790. //
  12791. VOID
  12792. KeBreakinBreakpoint (
  12793. VOID
  12794. );
  12795. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  12796. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  12797. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  12798. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  12799. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  12800. // begin_wdm
  12801. #define KeQueryTickCount(CurrentCount ) \
  12802. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  12803. // end_wdm
  12804. #else
  12805. NTKERNELAPI
  12806. VOID
  12807. KeQueryTickCount (
  12808. OUT PLARGE_INTEGER CurrentCount
  12809. );
  12810. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  12811. //
  12812. // I/O space read and write macros.
  12813. //
  12814. NTHALAPI
  12815. UCHAR
  12816. READ_PORT_UCHAR (
  12817. PUCHAR RegisterAddress
  12818. );
  12819. NTHALAPI
  12820. USHORT
  12821. READ_PORT_USHORT (
  12822. PUSHORT RegisterAddress
  12823. );
  12824. NTHALAPI
  12825. ULONG
  12826. READ_PORT_ULONG (
  12827. PULONG RegisterAddress
  12828. );
  12829. NTHALAPI
  12830. VOID
  12831. READ_PORT_BUFFER_UCHAR (
  12832. PUCHAR portAddress,
  12833. PUCHAR readBuffer,
  12834. ULONG readCount
  12835. );
  12836. NTHALAPI
  12837. VOID
  12838. READ_PORT_BUFFER_USHORT (
  12839. PUSHORT portAddress,
  12840. PUSHORT readBuffer,
  12841. ULONG readCount
  12842. );
  12843. NTHALAPI
  12844. VOID
  12845. READ_PORT_BUFFER_ULONG (
  12846. PULONG portAddress,
  12847. PULONG readBuffer,
  12848. ULONG readCount
  12849. );
  12850. NTHALAPI
  12851. VOID
  12852. WRITE_PORT_UCHAR (
  12853. PUCHAR portAddress,
  12854. UCHAR Data
  12855. );
  12856. NTHALAPI
  12857. VOID
  12858. WRITE_PORT_USHORT (
  12859. PUSHORT portAddress,
  12860. USHORT Data
  12861. );
  12862. NTHALAPI
  12863. VOID
  12864. WRITE_PORT_ULONG (
  12865. PULONG portAddress,
  12866. ULONG Data
  12867. );
  12868. NTHALAPI
  12869. VOID
  12870. WRITE_PORT_BUFFER_UCHAR (
  12871. PUCHAR portAddress,
  12872. PUCHAR writeBuffer,
  12873. ULONG writeCount
  12874. );
  12875. NTHALAPI
  12876. VOID
  12877. WRITE_PORT_BUFFER_USHORT (
  12878. PUSHORT portAddress,
  12879. PUSHORT writeBuffer,
  12880. ULONG writeCount
  12881. );
  12882. NTHALAPI
  12883. VOID
  12884. WRITE_PORT_BUFFER_ULONG (
  12885. PULONG portAddress,
  12886. PULONG writeBuffer,
  12887. ULONG writeCount
  12888. );
  12889. #define READ_REGISTER_UCHAR(x) \
  12890. (__mf(), *(volatile UCHAR * const)(x))
  12891. #define READ_REGISTER_USHORT(x) \
  12892. (__mf(), *(volatile USHORT * const)(x))
  12893. #define READ_REGISTER_ULONG(x) \
  12894. (__mf(), *(volatile ULONG * const)(x))
  12895. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  12896. PUCHAR registerBuffer = x; \
  12897. PUCHAR readBuffer = y; \
  12898. ULONG readCount; \
  12899. __mf(); \
  12900. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  12901. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  12902. } \
  12903. }
  12904. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  12905. PUSHORT registerBuffer = x; \
  12906. PUSHORT readBuffer = y; \
  12907. ULONG readCount; \
  12908. __mf(); \
  12909. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  12910. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  12911. } \
  12912. }
  12913. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  12914. PULONG registerBuffer = x; \
  12915. PULONG readBuffer = y; \
  12916. ULONG readCount; \
  12917. __mf(); \
  12918. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  12919. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  12920. } \
  12921. }
  12922. #define WRITE_REGISTER_UCHAR(x, y) { \
  12923. *(volatile UCHAR * const)(x) = y; \
  12924. KeFlushWriteBuffer(); \
  12925. }
  12926. #define WRITE_REGISTER_USHORT(x, y) { \
  12927. *(volatile USHORT * const)(x) = y; \
  12928. KeFlushWriteBuffer(); \
  12929. }
  12930. #define WRITE_REGISTER_ULONG(x, y) { \
  12931. *(volatile ULONG * const)(x) = y; \
  12932. KeFlushWriteBuffer(); \
  12933. }
  12934. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  12935. PUCHAR registerBuffer = x; \
  12936. PUCHAR writeBuffer = y; \
  12937. ULONG writeCount; \
  12938. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  12939. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  12940. } \
  12941. KeFlushWriteBuffer(); \
  12942. }
  12943. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  12944. PUSHORT registerBuffer = x; \
  12945. PUSHORT writeBuffer = y; \
  12946. ULONG writeCount; \
  12947. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  12948. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  12949. } \
  12950. KeFlushWriteBuffer(); \
  12951. }
  12952. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  12953. PULONG registerBuffer = x; \
  12954. PULONG writeBuffer = y; \
  12955. ULONG writeCount; \
  12956. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  12957. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  12958. } \
  12959. KeFlushWriteBuffer(); \
  12960. }
  12961. //
  12962. // Non-volatile floating point state
  12963. //
  12964. typedef struct _KFLOATING_SAVE {
  12965. ULONG Reserved;
  12966. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  12967. //
  12968. // Define Processor Control Region Structure.
  12969. //
  12970. #define PCR_MINOR_VERSION 1
  12971. #define PCR_MAJOR_VERSION 1
  12972. typedef struct _KPCR {
  12973. //
  12974. // Major and minor version numbers of the PCR.
  12975. //
  12976. ULONG MinorVersion;
  12977. ULONG MajorVersion;
  12978. //
  12979. // Start of the architecturally defined section of the PCR. This section
  12980. // may be directly addressed by vendor/platform specific HAL code and will
  12981. // not change from version to version of NT.
  12982. //
  12983. //
  12984. // First and second level cache parameters.
  12985. //
  12986. ULONG FirstLevelDcacheSize;
  12987. ULONG FirstLevelDcacheFillSize;
  12988. ULONG FirstLevelIcacheSize;
  12989. ULONG FirstLevelIcacheFillSize;
  12990. ULONG SecondLevelDcacheSize;
  12991. ULONG SecondLevelDcacheFillSize;
  12992. ULONG SecondLevelIcacheSize;
  12993. ULONG SecondLevelIcacheFillSize;
  12994. //
  12995. // Data cache alignment and fill size used for cache flushing and alignment.
  12996. // These fields are set to the larger of the first and second level data
  12997. // cache fill sizes.
  12998. //
  12999. ULONG DcacheAlignment;
  13000. ULONG DcacheFillSize;
  13001. //
  13002. // Instruction cache alignment and fill size used for cache flushing and
  13003. // alignment. These fields are set to the larger of the first and second
  13004. // level data cache fill sizes.
  13005. //
  13006. ULONG IcacheAlignment;
  13007. ULONG IcacheFillSize;
  13008. //
  13009. // Processor identification from PrId register.
  13010. //
  13011. ULONG ProcessorId;
  13012. //
  13013. // Profiling data.
  13014. //
  13015. ULONG ProfileInterval;
  13016. ULONG ProfileCount;
  13017. //
  13018. // Stall execution count and scale factor.
  13019. //
  13020. ULONG StallExecutionCount;
  13021. ULONG StallScaleFactor;
  13022. ULONG InterruptionCount;
  13023. //
  13024. // Space reserved for the system.
  13025. //
  13026. ULONGLONG SystemReserved[6];
  13027. //
  13028. // Space reserved for the HAL
  13029. //
  13030. ULONGLONG HalReserved[64];
  13031. //
  13032. // IRQL mapping tables.
  13033. //
  13034. UCHAR IrqlMask[64];
  13035. UCHAR IrqlTable[64];
  13036. //
  13037. // External Interrupt vectors.
  13038. //
  13039. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  13040. //
  13041. // Reserved interrupt vector mask.
  13042. //
  13043. ULONG ReservedVectors;
  13044. //
  13045. // Processor affinity mask.
  13046. //
  13047. KAFFINITY SetMember;
  13048. //
  13049. // Complement of the processor affinity mask.
  13050. //
  13051. KAFFINITY NotMember;
  13052. //
  13053. // Pointer to processor control block.
  13054. //
  13055. struct _KPRCB *Prcb;
  13056. //
  13057. // Shadow copy of Prcb->CurrentThread for fast access
  13058. //
  13059. struct _KTHREAD *CurrentThread;
  13060. //
  13061. // Processor number.
  13062. //
  13063. CCHAR Number; // Processor Number
  13064. } KPCR, *PKPCR;
  13065. NTKERNELAPI
  13066. KIRQL
  13067. KeGetCurrentIrql();
  13068. NTKERNELAPI
  13069. VOID
  13070. KeLowerIrql (
  13071. IN KIRQL NewIrql
  13072. );
  13073. NTKERNELAPI
  13074. VOID
  13075. KeRaiseIrql (
  13076. IN KIRQL NewIrql,
  13077. OUT PKIRQL OldIrql
  13078. );
  13079. // end_wdm
  13080. NTKERNELAPI
  13081. KIRQL
  13082. KeRaiseIrqlToDpcLevel (
  13083. VOID
  13084. );
  13085. NTKERNELAPI
  13086. KIRQL
  13087. KeRaiseIrqlToSynchLevel (
  13088. VOID
  13089. );
  13090. //
  13091. // The highest user address reserves 64K bytes for a guard page. This
  13092. // the probing of address from kernel mode to only have to check the
  13093. // starting address for structures of 64k bytes or less.
  13094. //
  13095. extern NTKERNELAPI PVOID MmHighestUserAddress;
  13096. extern NTKERNELAPI PVOID MmSystemRangeStart;
  13097. extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
  13098. #define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
  13099. #define MM_USER_PROBE_ADDRESS MmUserProbeAddress
  13100. #define MM_SYSTEM_RANGE_START MmSystemRangeStart
  13101. //
  13102. // The lowest user address reserves the low 64k.
  13103. //
  13104. #define MM_LOWEST_USER_ADDRESS (PVOID)((ULONG_PTR)(UADDRESS_BASE+0x00010000))
  13105. // begin_wdm
  13106. #define MmGetProcedureAddress(Address) (Address)
  13107. #define MmLockPagableCodeSection(PLabelAddress) \
  13108. MmLockPagableDataSection((PVOID)(*((PULONGLONG)PLabelAddress)))
  13109. #define VRN_MASK 0xE000000000000000UI64 // Virtual Region Number mask
  13110. //
  13111. // The lowest address for system space.
  13112. //
  13113. #define MM_LOWEST_SYSTEM_ADDRESS ((PVOID)((ULONG_PTR)(KADDRESS_BASE + 0xC0C00000)))
  13114. #endif // defined(_IA64_)
  13115. //
  13116. // Define configuration routine types.
  13117. //
  13118. // Configuration information.
  13119. //
  13120. typedef enum _CONFIGURATION_TYPE {
  13121. ArcSystem,
  13122. CentralProcessor,
  13123. FloatingPointProcessor,
  13124. PrimaryIcache,
  13125. PrimaryDcache,
  13126. SecondaryIcache,
  13127. SecondaryDcache,
  13128. SecondaryCache,
  13129. EisaAdapter,
  13130. TcAdapter,
  13131. ScsiAdapter,
  13132. DtiAdapter,
  13133. MultiFunctionAdapter,
  13134. DiskController,
  13135. TapeController,
  13136. CdromController,
  13137. WormController,
  13138. SerialController,
  13139. NetworkController,
  13140. DisplayController,
  13141. ParallelController,
  13142. PointerController,
  13143. KeyboardController,
  13144. AudioController,
  13145. OtherController,
  13146. DiskPeripheral,
  13147. FloppyDiskPeripheral,
  13148. TapePeripheral,
  13149. ModemPeripheral,
  13150. MonitorPeripheral,
  13151. PrinterPeripheral,
  13152. PointerPeripheral,
  13153. KeyboardPeripheral,
  13154. TerminalPeripheral,
  13155. OtherPeripheral,
  13156. LinePeripheral,
  13157. NetworkPeripheral,
  13158. SystemMemory,
  13159. DockingInformation,
  13160. RealModeIrqRoutingTable,
  13161. RealModePCIEnumeration,
  13162. MaximumType
  13163. } CONFIGURATION_TYPE, *PCONFIGURATION_TYPE;
  13164. #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
  13165. //
  13166. // Object Manager Object Type Specific Access Rights.
  13167. //
  13168. #define OBJECT_TYPE_CREATE (0x0001)
  13169. #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  13170. //
  13171. // Object Manager Directory Specific Access Rights.
  13172. //
  13173. #define DIRECTORY_QUERY (0x0001)
  13174. #define DIRECTORY_TRAVERSE (0x0002)
  13175. #define DIRECTORY_CREATE_OBJECT (0x0004)
  13176. #define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
  13177. #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
  13178. //
  13179. // Object Manager Symbolic Link Specific Access Rights.
  13180. //
  13181. #define SYMBOLIC_LINK_QUERY (0x0001)
  13182. #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  13183. typedef struct _OBJECT_NAME_INFORMATION {
  13184. UNICODE_STRING Name;
  13185. } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
  13186. #define DUPLICATE_CLOSE_SOURCE 0x00000001 // winnt
  13187. #define DUPLICATE_SAME_ACCESS 0x00000002 // winnt
  13188. #define DUPLICATE_SAME_ATTRIBUTES 0x00000004
  13189. // begin_winnt
  13190. //
  13191. // Predefined Value Types.
  13192. //
  13193. #define REG_NONE ( 0 ) // No value type
  13194. #define REG_SZ ( 1 ) // Unicode nul terminated string
  13195. #define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string
  13196. // (with environment variable references)
  13197. #define REG_BINARY ( 3 ) // Free form binary
  13198. #define REG_DWORD ( 4 ) // 32-bit number
  13199. #define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD)
  13200. #define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
  13201. #define REG_LINK ( 6 ) // Symbolic Link (unicode)
  13202. #define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings
  13203. #define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
  13204. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
  13205. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  13206. #define REG_QWORD ( 11 ) // 64-bit number
  13207. #define REG_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as REG_QWORD)
  13208. //
  13209. // Service Types (Bit Mask)
  13210. //
  13211. #define SERVICE_KERNEL_DRIVER 0x00000001
  13212. #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
  13213. #define SERVICE_ADAPTER 0x00000004
  13214. #define SERVICE_RECOGNIZER_DRIVER 0x00000008
  13215. #define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | \
  13216. SERVICE_FILE_SYSTEM_DRIVER | \
  13217. SERVICE_RECOGNIZER_DRIVER)
  13218. #define SERVICE_WIN32_OWN_PROCESS 0x00000010
  13219. #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
  13220. #define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | \
  13221. SERVICE_WIN32_SHARE_PROCESS)
  13222. #define SERVICE_INTERACTIVE_PROCESS 0x00000100
  13223. #define SERVICE_TYPE_ALL (SERVICE_WIN32 | \
  13224. SERVICE_ADAPTER | \
  13225. SERVICE_DRIVER | \
  13226. SERVICE_INTERACTIVE_PROCESS)
  13227. //
  13228. // Start Type
  13229. //
  13230. #define SERVICE_BOOT_START 0x00000000
  13231. #define SERVICE_SYSTEM_START 0x00000001
  13232. #define SERVICE_AUTO_START 0x00000002
  13233. #define SERVICE_DEMAND_START 0x00000003
  13234. #define SERVICE_DISABLED 0x00000004
  13235. //
  13236. // Error control type
  13237. //
  13238. #define SERVICE_ERROR_IGNORE 0x00000000
  13239. #define SERVICE_ERROR_NORMAL 0x00000001
  13240. #define SERVICE_ERROR_SEVERE 0x00000002
  13241. #define SERVICE_ERROR_CRITICAL 0x00000003
  13242. //
  13243. //
  13244. // Define the registry driver node enumerations
  13245. //
  13246. typedef enum _CM_SERVICE_NODE_TYPE {
  13247. DriverType = SERVICE_KERNEL_DRIVER,
  13248. FileSystemType = SERVICE_FILE_SYSTEM_DRIVER,
  13249. Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS,
  13250. Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  13251. AdapterType = SERVICE_ADAPTER,
  13252. RecognizerType = SERVICE_RECOGNIZER_DRIVER
  13253. } SERVICE_NODE_TYPE;
  13254. typedef enum _CM_SERVICE_LOAD_TYPE {
  13255. BootLoad = SERVICE_BOOT_START,
  13256. SystemLoad = SERVICE_SYSTEM_START,
  13257. AutoLoad = SERVICE_AUTO_START,
  13258. DemandLoad = SERVICE_DEMAND_START,
  13259. DisableLoad = SERVICE_DISABLED
  13260. } SERVICE_LOAD_TYPE;
  13261. typedef enum _CM_ERROR_CONTROL_TYPE {
  13262. IgnoreError = SERVICE_ERROR_IGNORE,
  13263. NormalError = SERVICE_ERROR_NORMAL,
  13264. SevereError = SERVICE_ERROR_SEVERE,
  13265. CriticalError = SERVICE_ERROR_CRITICAL
  13266. } SERVICE_ERROR_TYPE;
  13267. // end_winnt
  13268. //
  13269. // Resource List definitions
  13270. //
  13271. // begin_ntminiport begin_ntndis
  13272. //
  13273. // Defines the Type in the RESOURCE_DESCRIPTOR
  13274. //
  13275. // NOTE: For all CM_RESOURCE_TYPE values, there must be a
  13276. // corresponding ResType value in the 32-bit ConfigMgr headerfile
  13277. // (cfgmgr32.h). Values in the range [0x6,0x80) use the same values
  13278. // as their ConfigMgr counterparts. CM_RESOURCE_TYPE values with
  13279. // the high bit set (i.e., in the range [0x80,0xFF]), are
  13280. // non-arbitrated resources. These correspond to the same values
  13281. // in cfgmgr32.h that have their high bit set (however, since
  13282. // cfgmgr32.h uses 16 bits for ResType values, these values are in
  13283. // the range [0x8000,0x807F). Note that ConfigMgr ResType values
  13284. // cannot be in the range [0x8080,0xFFFF), because they would not
  13285. // be able to map into CM_RESOURCE_TYPE values. (0xFFFF itself is
  13286. // a special value, because it maps to CmResourceTypeDeviceSpecific.)
  13287. //
  13288. typedef int CM_RESOURCE_TYPE;
  13289. // CmResourceTypeNull is reserved
  13290. #define CmResourceTypeNull 0 // ResType_All or ResType_None (0x0000)
  13291. #define CmResourceTypePort 1 // ResType_IO (0x0002)
  13292. #define CmResourceTypeInterrupt 2 // ResType_IRQ (0x0004)
  13293. #define CmResourceTypeMemory 3 // ResType_Mem (0x0001)
  13294. #define CmResourceTypeDma 4 // ResType_DMA (0x0003)
  13295. #define CmResourceTypeDeviceSpecific 5 // ResType_ClassSpecific (0xFFFF)
  13296. #define CmResourceTypeBusNumber 6 // ResType_BusNumber (0x0006)
  13297. // end_wdm
  13298. #define CmResourceTypeMaximum 7
  13299. // begin_wdm
  13300. #define CmResourceTypeNonArbitrated 128 // Not arbitrated if 0x80 bit set
  13301. #define CmResourceTypeConfigData 128 // ResType_Reserved (0x8000)
  13302. #define CmResourceTypeDevicePrivate 129 // ResType_DevicePrivate (0x8001)
  13303. #define CmResourceTypePcCardConfig 130 // ResType_PcCardConfig (0x8002)
  13304. #define CmResourceTypeMfCardConfig 131 // ResType_MfCardConfig (0x8003)
  13305. //
  13306. // Defines the ShareDisposition in the RESOURCE_DESCRIPTOR
  13307. //
  13308. typedef enum _CM_SHARE_DISPOSITION {
  13309. CmResourceShareUndetermined = 0, // Reserved
  13310. CmResourceShareDeviceExclusive,
  13311. CmResourceShareDriverExclusive,
  13312. CmResourceShareShared
  13313. } CM_SHARE_DISPOSITION;
  13314. //
  13315. // Define the bit masks for Flags when type is CmResourceTypeInterrupt
  13316. //
  13317. #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
  13318. #define CM_RESOURCE_INTERRUPT_LATCHED 1
  13319. //
  13320. // Define the bit masks for Flags when type is CmResourceTypeMemory
  13321. //
  13322. #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
  13323. #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
  13324. #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
  13325. #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
  13326. #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
  13327. #define CM_RESOURCE_MEMORY_24 0x0010
  13328. #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
  13329. //
  13330. // Define the bit masks for Flags when type is CmResourceTypePort
  13331. //
  13332. #define CM_RESOURCE_PORT_MEMORY 0x0000
  13333. #define CM_RESOURCE_PORT_IO 0x0001
  13334. #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
  13335. #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
  13336. #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
  13337. #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
  13338. #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
  13339. #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
  13340. //
  13341. // Define the bit masks for Flags when type is CmResourceTypeDma
  13342. //
  13343. #define CM_RESOURCE_DMA_8 0x0000
  13344. #define CM_RESOURCE_DMA_16 0x0001
  13345. #define CM_RESOURCE_DMA_32 0x0002
  13346. #define CM_RESOURCE_DMA_8_AND_16 0x0004
  13347. #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
  13348. #define CM_RESOURCE_DMA_TYPE_A 0x0010
  13349. #define CM_RESOURCE_DMA_TYPE_B 0x0020
  13350. #define CM_RESOURCE_DMA_TYPE_F 0x0040
  13351. // end_ntminiport end_ntndis
  13352. //
  13353. // This structure defines one type of resource used by a driver.
  13354. //
  13355. // There can only be *1* DeviceSpecificData block. It must be located at
  13356. // the end of all resource descriptors in a full descriptor block.
  13357. //
  13358. //
  13359. // Make sure alignment is made properly by compiler; otherwise move
  13360. // flags back to the top of the structure (common to all members of the
  13361. // union).
  13362. //
  13363. // begin_ntndis
  13364. #include "pshpack4.h"
  13365. typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
  13366. UCHAR Type;
  13367. UCHAR ShareDisposition;
  13368. USHORT Flags;
  13369. union {
  13370. //
  13371. // Range of resources, inclusive. These are physical, bus relative.
  13372. // It is known that Port and Memory below have the exact same layout
  13373. // as Generic.
  13374. //
  13375. struct {
  13376. PHYSICAL_ADDRESS Start;
  13377. ULONG Length;
  13378. } Generic;
  13379. //
  13380. // end_wdm
  13381. // Range of port numbers, inclusive. These are physical, bus
  13382. // relative. The value should be the same as the one passed to
  13383. // HalTranslateBusAddress().
  13384. // begin_wdm
  13385. //
  13386. struct {
  13387. PHYSICAL_ADDRESS Start;
  13388. ULONG Length;
  13389. } Port;
  13390. //
  13391. // end_wdm
  13392. // IRQL and vector. Should be same values as were passed to
  13393. // HalGetInterruptVector().
  13394. // begin_wdm
  13395. //
  13396. struct {
  13397. ULONG Level;
  13398. ULONG Vector;
  13399. KAFFINITY Affinity;
  13400. } Interrupt;
  13401. //
  13402. // Range of memory addresses, inclusive. These are physical, bus
  13403. // relative. The value should be the same as the one passed to
  13404. // HalTranslateBusAddress().
  13405. //
  13406. struct {
  13407. PHYSICAL_ADDRESS Start; // 64 bit physical addresses.
  13408. ULONG Length;
  13409. } Memory;
  13410. //
  13411. // Physical DMA channel.
  13412. //
  13413. struct {
  13414. ULONG Channel;
  13415. ULONG Port;
  13416. ULONG Reserved1;
  13417. } Dma;
  13418. //
  13419. // Device driver private data, usually used to help it figure
  13420. // what the resource assignments decisions that were made.
  13421. //
  13422. struct {
  13423. ULONG Data[3];
  13424. } DevicePrivate;
  13425. //
  13426. // Bus Number information.
  13427. //
  13428. struct {
  13429. ULONG Start;
  13430. ULONG Length;
  13431. ULONG Reserved;
  13432. } BusNumber;
  13433. //
  13434. // Device Specific information defined by the driver.
  13435. // The DataSize field indicates the size of the data in bytes. The
  13436. // data is located immediately after the DeviceSpecificData field in
  13437. // the structure.
  13438. //
  13439. struct {
  13440. ULONG DataSize;
  13441. ULONG Reserved1;
  13442. ULONG Reserved2;
  13443. } DeviceSpecificData;
  13444. } u;
  13445. } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
  13446. #include "poppack.h"
  13447. //
  13448. // A Partial Resource List is what can be found in the ARC firmware
  13449. // or will be generated by ntdetect.com.
  13450. // The configuration manager will transform this structure into a Full
  13451. // resource descriptor when it is about to store it in the regsitry.
  13452. //
  13453. // Note: There must a be a convention to the order of fields of same type,
  13454. // (defined on a device by device basis) so that the fields can make sense
  13455. // to a driver (i.e. when multiple memory ranges are necessary).
  13456. //
  13457. typedef struct _CM_PARTIAL_RESOURCE_LIST {
  13458. USHORT Version;
  13459. USHORT Revision;
  13460. ULONG Count;
  13461. CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
  13462. } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
  13463. //
  13464. // A Full Resource Descriptor is what can be found in the registry.
  13465. // This is what will be returned to a driver when it queries the registry
  13466. // to get device information; it will be stored under a key in the hardware
  13467. // description tree.
  13468. //
  13469. // end_wdm
  13470. // Note: The BusNumber and Type are redundant information, but we will keep
  13471. // it since it allows the driver _not_ to append it when it is creating
  13472. // a resource list which could possibly span multiple buses.
  13473. //
  13474. // begin_wdm
  13475. // Note: There must a be a convention to the order of fields of same type,
  13476. // (defined on a device by device basis) so that the fields can make sense
  13477. // to a driver (i.e. when multiple memory ranges are necessary).
  13478. //
  13479. typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
  13480. INTERFACE_TYPE InterfaceType; // unused for WDM
  13481. ULONG BusNumber; // unused for WDM
  13482. CM_PARTIAL_RESOURCE_LIST PartialResourceList;
  13483. } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
  13484. //
  13485. // The Resource list is what will be stored by the drivers into the
  13486. // resource map via the IO API.
  13487. //
  13488. typedef struct _CM_RESOURCE_LIST {
  13489. ULONG Count;
  13490. CM_FULL_RESOURCE_DESCRIPTOR List[1];
  13491. } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
  13492. // end_ntndis
  13493. //
  13494. // Define the structures used to interpret configuration data of
  13495. // \\Registry\machine\hardware\description tree.
  13496. // Basically, these structures are used to interpret component
  13497. // sepcific data.
  13498. //
  13499. //
  13500. // Define DEVICE_FLAGS
  13501. //
  13502. typedef struct _DEVICE_FLAGS {
  13503. ULONG Failed : 1;
  13504. ULONG ReadOnly : 1;
  13505. ULONG Removable : 1;
  13506. ULONG ConsoleIn : 1;
  13507. ULONG ConsoleOut : 1;
  13508. ULONG Input : 1;
  13509. ULONG Output : 1;
  13510. } DEVICE_FLAGS, *PDEVICE_FLAGS;
  13511. //
  13512. // Define Component Information structure
  13513. //
  13514. typedef struct _CM_COMPONENT_INFORMATION {
  13515. DEVICE_FLAGS Flags;
  13516. ULONG Version;
  13517. ULONG Key;
  13518. KAFFINITY AffinityMask;
  13519. } CM_COMPONENT_INFORMATION, *PCM_COMPONENT_INFORMATION;
  13520. //
  13521. // The following structures are used to interpret x86
  13522. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  13523. // (Most of the structures are defined by BIOS. They are
  13524. // not aligned on word (or dword) boundary.
  13525. //
  13526. //
  13527. // Define the Rom Block structure
  13528. //
  13529. typedef struct _CM_ROM_BLOCK {
  13530. ULONG Address;
  13531. ULONG Size;
  13532. } CM_ROM_BLOCK, *PCM_ROM_BLOCK;
  13533. // begin_ntminiport begin_ntndis
  13534. #include "pshpack1.h"
  13535. // end_ntminiport end_ntndis
  13536. //
  13537. // Define INT13 driver parameter block
  13538. //
  13539. typedef struct _CM_INT13_DRIVE_PARAMETER {
  13540. USHORT DriveSelect;
  13541. ULONG MaxCylinders;
  13542. USHORT SectorsPerTrack;
  13543. USHORT MaxHeads;
  13544. USHORT NumberDrives;
  13545. } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
  13546. // begin_ntminiport begin_ntndis
  13547. //
  13548. // Define Mca POS data block for slot
  13549. //
  13550. typedef struct _CM_MCA_POS_DATA {
  13551. USHORT AdapterId;
  13552. UCHAR PosData1;
  13553. UCHAR PosData2;
  13554. UCHAR PosData3;
  13555. UCHAR PosData4;
  13556. } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
  13557. //
  13558. // Memory configuration of eisa data block structure
  13559. //
  13560. typedef struct _EISA_MEMORY_TYPE {
  13561. UCHAR ReadWrite: 1;
  13562. UCHAR Cached : 1;
  13563. UCHAR Reserved0 :1;
  13564. UCHAR Type:2;
  13565. UCHAR Shared:1;
  13566. UCHAR Reserved1 :1;
  13567. UCHAR MoreEntries : 1;
  13568. } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
  13569. typedef struct _EISA_MEMORY_CONFIGURATION {
  13570. EISA_MEMORY_TYPE ConfigurationByte;
  13571. UCHAR DataSize;
  13572. USHORT AddressLowWord;
  13573. UCHAR AddressHighByte;
  13574. USHORT MemorySize;
  13575. } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
  13576. //
  13577. // Interrupt configurationn of eisa data block structure
  13578. //
  13579. typedef struct _EISA_IRQ_DESCRIPTOR {
  13580. UCHAR Interrupt : 4;
  13581. UCHAR Reserved :1;
  13582. UCHAR LevelTriggered :1;
  13583. UCHAR Shared : 1;
  13584. UCHAR MoreEntries : 1;
  13585. } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
  13586. typedef struct _EISA_IRQ_CONFIGURATION {
  13587. EISA_IRQ_DESCRIPTOR ConfigurationByte;
  13588. UCHAR Reserved;
  13589. } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
  13590. //
  13591. // DMA description of eisa data block structure
  13592. //
  13593. typedef struct _DMA_CONFIGURATION_BYTE0 {
  13594. UCHAR Channel : 3;
  13595. UCHAR Reserved : 3;
  13596. UCHAR Shared :1;
  13597. UCHAR MoreEntries :1;
  13598. } DMA_CONFIGURATION_BYTE0;
  13599. typedef struct _DMA_CONFIGURATION_BYTE1 {
  13600. UCHAR Reserved0 : 2;
  13601. UCHAR TransferSize : 2;
  13602. UCHAR Timing : 2;
  13603. UCHAR Reserved1 : 2;
  13604. } DMA_CONFIGURATION_BYTE1;
  13605. typedef struct _EISA_DMA_CONFIGURATION {
  13606. DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
  13607. DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
  13608. } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
  13609. //
  13610. // Port description of eisa data block structure
  13611. //
  13612. typedef struct _EISA_PORT_DESCRIPTOR {
  13613. UCHAR NumberPorts : 5;
  13614. UCHAR Reserved :1;
  13615. UCHAR Shared :1;
  13616. UCHAR MoreEntries : 1;
  13617. } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
  13618. typedef struct _EISA_PORT_CONFIGURATION {
  13619. EISA_PORT_DESCRIPTOR Configuration;
  13620. USHORT PortAddress;
  13621. } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
  13622. //
  13623. // Eisa slot information definition
  13624. // N.B. This structure is different from the one defined
  13625. // in ARC eisa addendum.
  13626. //
  13627. typedef struct _CM_EISA_SLOT_INFORMATION {
  13628. UCHAR ReturnCode;
  13629. UCHAR ReturnFlags;
  13630. UCHAR MajorRevision;
  13631. UCHAR MinorRevision;
  13632. USHORT Checksum;
  13633. UCHAR NumberFunctions;
  13634. UCHAR FunctionInformation;
  13635. ULONG CompressedId;
  13636. } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
  13637. //
  13638. // Eisa function information definition
  13639. //
  13640. typedef struct _CM_EISA_FUNCTION_INFORMATION {
  13641. ULONG CompressedId;
  13642. UCHAR IdSlotFlags1;
  13643. UCHAR IdSlotFlags2;
  13644. UCHAR MinorRevision;
  13645. UCHAR MajorRevision;
  13646. UCHAR Selections[26];
  13647. UCHAR FunctionFlags;
  13648. UCHAR TypeString[80];
  13649. EISA_MEMORY_CONFIGURATION EisaMemory[9];
  13650. EISA_IRQ_CONFIGURATION EisaIrq[7];
  13651. EISA_DMA_CONFIGURATION EisaDma[4];
  13652. EISA_PORT_CONFIGURATION EisaPort[20];
  13653. UCHAR InitializationData[60];
  13654. } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
  13655. //
  13656. // The following defines the way pnp bios information is stored in
  13657. // the registry \\HKEY_LOCAL_MACHINE\HARDWARE\Description\System\MultifunctionAdapter\x
  13658. // key, where x is an integer number indicating adapter instance. The
  13659. // "Identifier" of the key must equal to "PNP BIOS" and the
  13660. // "ConfigurationData" is organized as follow:
  13661. //
  13662. // CM_PNP_BIOS_INSTALLATION_CHECK +
  13663. // CM_PNP_BIOS_DEVICE_NODE for device 1 +
  13664. // CM_PNP_BIOS_DEVICE_NODE for device 2 +
  13665. // ...
  13666. // CM_PNP_BIOS_DEVICE_NODE for device n
  13667. //
  13668. //
  13669. // Pnp BIOS device node structure
  13670. //
  13671. typedef struct _CM_PNP_BIOS_DEVICE_NODE {
  13672. USHORT Size;
  13673. UCHAR Node;
  13674. ULONG ProductId;
  13675. UCHAR DeviceType[3];
  13676. USHORT DeviceAttributes;
  13677. // followed by AllocatedResourceBlock, PossibleResourceBlock
  13678. // and CompatibleDeviceId
  13679. } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
  13680. //
  13681. // Pnp BIOS Installation check
  13682. //
  13683. typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK {
  13684. UCHAR Signature[4]; // $PnP (ascii)
  13685. UCHAR Revision;
  13686. UCHAR Length;
  13687. USHORT ControlField;
  13688. UCHAR Checksum;
  13689. ULONG EventFlagAddress; // Physical address
  13690. USHORT RealModeEntryOffset;
  13691. USHORT RealModeEntrySegment;
  13692. USHORT ProtectedModeEntryOffset;
  13693. ULONG ProtectedModeCodeBaseAddress;
  13694. ULONG OemDeviceId;
  13695. USHORT RealModeDataBaseAddress;
  13696. ULONG ProtectedModeDataBaseAddress;
  13697. } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
  13698. #include "poppack.h"
  13699. //
  13700. // Masks for EISA function information
  13701. //
  13702. #define EISA_FUNCTION_ENABLED 0x80
  13703. #define EISA_FREE_FORM_DATA 0x40
  13704. #define EISA_HAS_PORT_INIT_ENTRY 0x20
  13705. #define EISA_HAS_PORT_RANGE 0x10
  13706. #define EISA_HAS_DMA_ENTRY 0x08
  13707. #define EISA_HAS_IRQ_ENTRY 0x04
  13708. #define EISA_HAS_MEMORY_ENTRY 0x02
  13709. #define EISA_HAS_TYPE_ENTRY 0x01
  13710. #define EISA_HAS_INFORMATION EISA_HAS_PORT_RANGE + \
  13711. EISA_HAS_DMA_ENTRY + \
  13712. EISA_HAS_IRQ_ENTRY + \
  13713. EISA_HAS_MEMORY_ENTRY + \
  13714. EISA_HAS_TYPE_ENTRY
  13715. //
  13716. // Masks for EISA memory configuration
  13717. //
  13718. #define EISA_MORE_ENTRIES 0x80
  13719. #define EISA_SYSTEM_MEMORY 0x00
  13720. #define EISA_MEMORY_TYPE_RAM 0x01
  13721. //
  13722. // Returned error code for EISA bios call
  13723. //
  13724. #define EISA_INVALID_SLOT 0x80
  13725. #define EISA_INVALID_FUNCTION 0x81
  13726. #define EISA_INVALID_CONFIGURATION 0x82
  13727. #define EISA_EMPTY_SLOT 0x83
  13728. #define EISA_INVALID_BIOS_CALL 0x86
  13729. // end_ntminiport end_ntndis
  13730. //
  13731. // The following structures are used to interpret mips
  13732. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  13733. //
  13734. //
  13735. // Device data records for adapters.
  13736. //
  13737. //
  13738. // The device data record for the Emulex SCSI controller.
  13739. //
  13740. typedef struct _CM_SCSI_DEVICE_DATA {
  13741. USHORT Version;
  13742. USHORT Revision;
  13743. UCHAR HostIdentifier;
  13744. } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
  13745. //
  13746. // Device data records for controllers.
  13747. //
  13748. //
  13749. // The device data record for the Video controller.
  13750. //
  13751. typedef struct _CM_VIDEO_DEVICE_DATA {
  13752. USHORT Version;
  13753. USHORT Revision;
  13754. ULONG VideoClock;
  13755. } CM_VIDEO_DEVICE_DATA, *PCM_VIDEO_DEVICE_DATA;
  13756. //
  13757. // The device data record for the SONIC network controller.
  13758. //
  13759. typedef struct _CM_SONIC_DEVICE_DATA {
  13760. USHORT Version;
  13761. USHORT Revision;
  13762. USHORT DataConfigurationRegister;
  13763. UCHAR EthernetAddress[8];
  13764. } CM_SONIC_DEVICE_DATA, *PCM_SONIC_DEVICE_DATA;
  13765. //
  13766. // The device data record for the serial controller.
  13767. //
  13768. typedef struct _CM_SERIAL_DEVICE_DATA {
  13769. USHORT Version;
  13770. USHORT Revision;
  13771. ULONG BaudClock;
  13772. } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
  13773. //
  13774. // Device data records for peripherals.
  13775. //
  13776. //
  13777. // The device data record for the Monitor peripheral.
  13778. //
  13779. typedef struct _CM_MONITOR_DEVICE_DATA {
  13780. USHORT Version;
  13781. USHORT Revision;
  13782. USHORT HorizontalScreenSize;
  13783. USHORT VerticalScreenSize;
  13784. USHORT HorizontalResolution;
  13785. USHORT VerticalResolution;
  13786. USHORT HorizontalDisplayTimeLow;
  13787. USHORT HorizontalDisplayTime;
  13788. USHORT HorizontalDisplayTimeHigh;
  13789. USHORT HorizontalBackPorchLow;
  13790. USHORT HorizontalBackPorch;
  13791. USHORT HorizontalBackPorchHigh;
  13792. USHORT HorizontalFrontPorchLow;
  13793. USHORT HorizontalFrontPorch;
  13794. USHORT HorizontalFrontPorchHigh;
  13795. USHORT HorizontalSyncLow;
  13796. USHORT HorizontalSync;
  13797. USHORT HorizontalSyncHigh;
  13798. USHORT VerticalBackPorchLow;
  13799. USHORT VerticalBackPorch;
  13800. USHORT VerticalBackPorchHigh;
  13801. USHORT VerticalFrontPorchLow;
  13802. USHORT VerticalFrontPorch;
  13803. USHORT VerticalFrontPorchHigh;
  13804. USHORT VerticalSyncLow;
  13805. USHORT VerticalSync;
  13806. USHORT VerticalSyncHigh;
  13807. } CM_MONITOR_DEVICE_DATA, *PCM_MONITOR_DEVICE_DATA;
  13808. //
  13809. // The device data record for the Floppy peripheral.
  13810. //
  13811. typedef struct _CM_FLOPPY_DEVICE_DATA {
  13812. USHORT Version;
  13813. USHORT Revision;
  13814. CHAR Size[8];
  13815. ULONG MaxDensity;
  13816. ULONG MountDensity;
  13817. //
  13818. // New data fields for version >= 2.0
  13819. //
  13820. UCHAR StepRateHeadUnloadTime;
  13821. UCHAR HeadLoadTime;
  13822. UCHAR MotorOffTime;
  13823. UCHAR SectorLengthCode;
  13824. UCHAR SectorPerTrack;
  13825. UCHAR ReadWriteGapLength;
  13826. UCHAR DataTransferLength;
  13827. UCHAR FormatGapLength;
  13828. UCHAR FormatFillCharacter;
  13829. UCHAR HeadSettleTime;
  13830. UCHAR MotorSettleTime;
  13831. UCHAR MaximumTrackValue;
  13832. UCHAR DataTransferRate;
  13833. } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
  13834. //
  13835. // The device data record for the Keyboard peripheral.
  13836. // The KeyboardFlags is defined (by x86 BIOS INT 16h, function 02) as:
  13837. // bit 7 : Insert on
  13838. // bit 6 : Caps Lock on
  13839. // bit 5 : Num Lock on
  13840. // bit 4 : Scroll Lock on
  13841. // bit 3 : Alt Key is down
  13842. // bit 2 : Ctrl Key is down
  13843. // bit 1 : Left shift key is down
  13844. // bit 0 : Right shift key is down
  13845. //
  13846. typedef struct _CM_KEYBOARD_DEVICE_DATA {
  13847. USHORT Version;
  13848. USHORT Revision;
  13849. UCHAR Type;
  13850. UCHAR Subtype;
  13851. USHORT KeyboardFlags;
  13852. } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
  13853. //
  13854. // Declaration of the structure for disk geometries
  13855. //
  13856. typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA {
  13857. ULONG BytesPerSector;
  13858. ULONG NumberOfCylinders;
  13859. ULONG SectorsPerTrack;
  13860. ULONG NumberOfHeads;
  13861. } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
  13862. // end_wdm
  13863. //
  13864. // Declaration of the structure for the PcCard ISA IRQ map
  13865. //
  13866. typedef struct _CM_PCCARD_DEVICE_DATA {
  13867. UCHAR Flags;
  13868. UCHAR ErrorCode;
  13869. USHORT Reserved;
  13870. ULONG BusData;
  13871. ULONG DeviceId;
  13872. ULONG LegacyBaseAddress;
  13873. UCHAR IRQMap[16];
  13874. } CM_PCCARD_DEVICE_DATA, *PCM_PCCARD_DEVICE_DATA;
  13875. // Definitions for Flags
  13876. #define PCCARD_MAP_ERROR 0x01
  13877. #define PCCARD_DEVICE_PCI 0x10
  13878. #define PCCARD_SCAN_DISABLED 0x01
  13879. #define PCCARD_MAP_ZERO 0x02
  13880. #define PCCARD_NO_TIMER 0x03
  13881. #define PCCARD_NO_PIC 0x04
  13882. #define PCCARD_NO_LEGACY_BASE 0x05
  13883. #define PCCARD_DUP_LEGACY_BASE 0x06
  13884. #define PCCARD_NO_CONTROLLERS 0x07
  13885. // begin_wdm
  13886. // begin_ntminiport
  13887. //
  13888. // Defines Resource Options
  13889. //
  13890. #define IO_RESOURCE_PREFERRED 0x01
  13891. #define IO_RESOURCE_DEFAULT 0x02
  13892. #define IO_RESOURCE_ALTERNATIVE 0x08
  13893. //
  13894. // This structure defines one type of resource requested by the driver
  13895. //
  13896. typedef struct _IO_RESOURCE_DESCRIPTOR {
  13897. UCHAR Option;
  13898. UCHAR Type; // use CM_RESOURCE_TYPE
  13899. UCHAR ShareDisposition; // use CM_SHARE_DISPOSITION
  13900. UCHAR Spare1;
  13901. USHORT Flags; // use CM resource flag defines
  13902. USHORT Spare2; // align
  13903. union {
  13904. struct {
  13905. ULONG Length;
  13906. ULONG Alignment;
  13907. PHYSICAL_ADDRESS MinimumAddress;
  13908. PHYSICAL_ADDRESS MaximumAddress;
  13909. } Port;
  13910. struct {
  13911. ULONG Length;
  13912. ULONG Alignment;
  13913. PHYSICAL_ADDRESS MinimumAddress;
  13914. PHYSICAL_ADDRESS MaximumAddress;
  13915. } Memory;
  13916. struct {
  13917. ULONG MinimumVector;
  13918. ULONG MaximumVector;
  13919. } Interrupt;
  13920. struct {
  13921. ULONG MinimumChannel;
  13922. ULONG MaximumChannel;
  13923. } Dma;
  13924. struct {
  13925. ULONG Length;
  13926. ULONG Alignment;
  13927. PHYSICAL_ADDRESS MinimumAddress;
  13928. PHYSICAL_ADDRESS MaximumAddress;
  13929. } Generic;
  13930. struct {
  13931. ULONG Data[3];
  13932. } DevicePrivate;
  13933. //
  13934. // Bus Number information.
  13935. //
  13936. struct {
  13937. ULONG Length;
  13938. ULONG MinBusNumber;
  13939. ULONG MaxBusNumber;
  13940. ULONG Reserved;
  13941. } BusNumber;
  13942. struct {
  13943. ULONG Priority; // use LCPRI_Xxx values in cfg.h
  13944. ULONG Reserved1;
  13945. ULONG Reserved2;
  13946. } ConfigData;
  13947. } u;
  13948. } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
  13949. // end_ntminiport
  13950. typedef struct _IO_RESOURCE_LIST {
  13951. USHORT Version;
  13952. USHORT Revision;
  13953. ULONG Count;
  13954. IO_RESOURCE_DESCRIPTOR Descriptors[1];
  13955. } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
  13956. typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
  13957. ULONG ListSize;
  13958. INTERFACE_TYPE InterfaceType; // unused for WDM
  13959. ULONG BusNumber; // unused for WDM
  13960. ULONG SlotNumber;
  13961. ULONG Reserved[3];
  13962. ULONG AlternativeLists;
  13963. IO_RESOURCE_LIST List[1];
  13964. } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
  13965. //
  13966. // Registry Specific Access Rights.
  13967. //
  13968. #define KEY_QUERY_VALUE (0x0001)
  13969. #define KEY_SET_VALUE (0x0002)
  13970. #define KEY_CREATE_SUB_KEY (0x0004)
  13971. #define KEY_ENUMERATE_SUB_KEYS (0x0008)
  13972. #define KEY_NOTIFY (0x0010)
  13973. #define KEY_CREATE_LINK (0x0020)
  13974. #define KEY_WOW64_32KEY (0x0200)
  13975. #define KEY_WOW64_64KEY (0x0100)
  13976. #define KEY_WOW64_RES (0x0300)
  13977. #define KEY_READ ((STANDARD_RIGHTS_READ |\
  13978. KEY_QUERY_VALUE |\
  13979. KEY_ENUMERATE_SUB_KEYS |\
  13980. KEY_NOTIFY) \
  13981. & \
  13982. (~SYNCHRONIZE))
  13983. #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
  13984. KEY_SET_VALUE |\
  13985. KEY_CREATE_SUB_KEY) \
  13986. & \
  13987. (~SYNCHRONIZE))
  13988. #define KEY_EXECUTE ((KEY_READ) \
  13989. & \
  13990. (~SYNCHRONIZE))
  13991. #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
  13992. KEY_QUERY_VALUE |\
  13993. KEY_SET_VALUE |\
  13994. KEY_CREATE_SUB_KEY |\
  13995. KEY_ENUMERATE_SUB_KEYS |\
  13996. KEY_NOTIFY |\
  13997. KEY_CREATE_LINK) \
  13998. & \
  13999. (~SYNCHRONIZE))
  14000. //
  14001. // Open/Create Options
  14002. //
  14003. #define REG_OPTION_RESERVED (0x00000000L) // Parameter is reserved
  14004. #define REG_OPTION_NON_VOLATILE (0x00000000L) // Key is preserved
  14005. // when system is rebooted
  14006. #define REG_OPTION_VOLATILE (0x00000001L) // Key is not preserved
  14007. // when system is rebooted
  14008. #define REG_OPTION_CREATE_LINK (0x00000002L) // Created key is a
  14009. // symbolic link
  14010. #define REG_OPTION_BACKUP_RESTORE (0x00000004L) // open for backup or restore
  14011. // special access rules
  14012. // privilege required
  14013. #define REG_OPTION_OPEN_LINK (0x00000008L) // Open symbolic link
  14014. #define REG_LEGAL_OPTION \
  14015. (REG_OPTION_RESERVED |\
  14016. REG_OPTION_NON_VOLATILE |\
  14017. REG_OPTION_VOLATILE |\
  14018. REG_OPTION_CREATE_LINK |\
  14019. REG_OPTION_BACKUP_RESTORE |\
  14020. REG_OPTION_OPEN_LINK)
  14021. //
  14022. // Key creation/open disposition
  14023. //
  14024. #define REG_CREATED_NEW_KEY (0x00000001L) // New Registry Key created
  14025. #define REG_OPENED_EXISTING_KEY (0x00000002L) // Existing Key opened
  14026. //
  14027. // hive format to be used by Reg(Nt)SaveKeyEx
  14028. //
  14029. #define REG_STANDARD_FORMAT 1
  14030. #define REG_LATEST_FORMAT 2
  14031. #define REG_NO_COMPRESSION 4
  14032. //
  14033. // Key restore flags
  14034. //
  14035. #define REG_WHOLE_HIVE_VOLATILE (0x00000001L) // Restore whole hive volatile
  14036. #define REG_REFRESH_HIVE (0x00000002L) // Unwind changes to last flush
  14037. #define REG_NO_LAZY_FLUSH (0x00000004L) // Never lazy flush this hive
  14038. #define REG_FORCE_RESTORE (0x00000008L) // Force the restore process even when we have open handles on subkeys
  14039. //
  14040. // Unload Flags
  14041. //
  14042. #define REG_FORCE_UNLOAD 1
  14043. //
  14044. // Key query structures
  14045. //
  14046. typedef struct _KEY_BASIC_INFORMATION {
  14047. LARGE_INTEGER LastWriteTime;
  14048. ULONG TitleIndex;
  14049. ULONG NameLength;
  14050. WCHAR Name[1]; // Variable length string
  14051. } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
  14052. typedef struct _KEY_NODE_INFORMATION {
  14053. LARGE_INTEGER LastWriteTime;
  14054. ULONG TitleIndex;
  14055. ULONG ClassOffset;
  14056. ULONG ClassLength;
  14057. ULONG NameLength;
  14058. WCHAR Name[1]; // Variable length string
  14059. // Class[1]; // Variable length string not declared
  14060. } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
  14061. typedef struct _KEY_FULL_INFORMATION {
  14062. LARGE_INTEGER LastWriteTime;
  14063. ULONG TitleIndex;
  14064. ULONG ClassOffset;
  14065. ULONG ClassLength;
  14066. ULONG SubKeys;
  14067. ULONG MaxNameLen;
  14068. ULONG MaxClassLen;
  14069. ULONG Values;
  14070. ULONG MaxValueNameLen;
  14071. ULONG MaxValueDataLen;
  14072. WCHAR Class[1]; // Variable length
  14073. } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
  14074. // end_wdm
  14075. typedef struct _KEY_NAME_INFORMATION {
  14076. ULONG NameLength;
  14077. WCHAR Name[1]; // Variable length string
  14078. } KEY_NAME_INFORMATION, *PKEY_NAME_INFORMATION;
  14079. typedef struct _KEY_CACHED_INFORMATION {
  14080. LARGE_INTEGER LastWriteTime;
  14081. ULONG TitleIndex;
  14082. ULONG SubKeys;
  14083. ULONG MaxNameLen;
  14084. ULONG Values;
  14085. ULONG MaxValueNameLen;
  14086. ULONG MaxValueDataLen;
  14087. ULONG NameLength;
  14088. WCHAR Name[1]; // Variable length string
  14089. } KEY_CACHED_INFORMATION, *PKEY_CACHED_INFORMATION;
  14090. typedef struct _KEY_FLAGS_INFORMATION {
  14091. ULONG UserFlags;
  14092. } KEY_FLAGS_INFORMATION, *PKEY_FLAGS_INFORMATION;
  14093. // begin_wdm
  14094. typedef enum _KEY_INFORMATION_CLASS {
  14095. KeyBasicInformation,
  14096. KeyNodeInformation,
  14097. KeyFullInformation
  14098. // end_wdm
  14099. ,
  14100. KeyNameInformation,
  14101. KeyCachedInformation,
  14102. KeyFlagsInformation,
  14103. MaxKeyInfoClass // MaxKeyInfoClass should always be the last enum
  14104. // begin_wdm
  14105. } KEY_INFORMATION_CLASS;
  14106. typedef struct _KEY_WRITE_TIME_INFORMATION {
  14107. LARGE_INTEGER LastWriteTime;
  14108. } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
  14109. typedef struct _KEY_USER_FLAGS_INFORMATION {
  14110. ULONG UserFlags;
  14111. } KEY_USER_FLAGS_INFORMATION, *PKEY_USER_FLAGS_INFORMATION;
  14112. typedef enum _KEY_SET_INFORMATION_CLASS {
  14113. KeyWriteTimeInformation,
  14114. KeyUserFlagsInformation,
  14115. MaxKeySetInfoClass // MaxKeySetInfoClass should always be the last enum
  14116. } KEY_SET_INFORMATION_CLASS;
  14117. //
  14118. // Value entry query structures
  14119. //
  14120. typedef struct _KEY_VALUE_BASIC_INFORMATION {
  14121. ULONG TitleIndex;
  14122. ULONG Type;
  14123. ULONG NameLength;
  14124. WCHAR Name[1]; // Variable size
  14125. } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
  14126. typedef struct _KEY_VALUE_FULL_INFORMATION {
  14127. ULONG TitleIndex;
  14128. ULONG Type;
  14129. ULONG DataOffset;
  14130. ULONG DataLength;
  14131. ULONG NameLength;
  14132. WCHAR Name[1]; // Variable size
  14133. // Data[1]; // Variable size data not declared
  14134. } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
  14135. typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
  14136. ULONG TitleIndex;
  14137. ULONG Type;
  14138. ULONG DataLength;
  14139. UCHAR Data[1]; // Variable size
  14140. } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
  14141. typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
  14142. ULONG Type;
  14143. ULONG DataLength;
  14144. UCHAR Data[1]; // Variable size
  14145. } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
  14146. typedef struct _KEY_VALUE_ENTRY {
  14147. PUNICODE_STRING ValueName;
  14148. ULONG DataLength;
  14149. ULONG DataOffset;
  14150. ULONG Type;
  14151. } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
  14152. typedef enum _KEY_VALUE_INFORMATION_CLASS {
  14153. KeyValueBasicInformation,
  14154. KeyValueFullInformation,
  14155. KeyValuePartialInformation,
  14156. KeyValueFullInformationAlign64,
  14157. KeyValuePartialInformationAlign64,
  14158. MaxKeyValueInfoClass // MaxKeyValueInfoClass should always be the last enum
  14159. } KEY_VALUE_INFORMATION_CLASS;
  14160. //
  14161. // Section Information Structures.
  14162. //
  14163. typedef enum _SECTION_INHERIT {
  14164. ViewShare = 1,
  14165. ViewUnmap = 2
  14166. } SECTION_INHERIT;
  14167. //
  14168. // Section Access Rights.
  14169. //
  14170. // begin_winnt
  14171. #define SECTION_QUERY 0x0001
  14172. #define SECTION_MAP_WRITE 0x0002
  14173. #define SECTION_MAP_READ 0x0004
  14174. #define SECTION_MAP_EXECUTE 0x0008
  14175. #define SECTION_EXTEND_SIZE 0x0010
  14176. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  14177. SECTION_MAP_WRITE | \
  14178. SECTION_MAP_READ | \
  14179. SECTION_MAP_EXECUTE | \
  14180. SECTION_EXTEND_SIZE)
  14181. // end_winnt
  14182. #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
  14183. #define PAGE_NOACCESS 0x01 // winnt
  14184. #define PAGE_READONLY 0x02 // winnt
  14185. #define PAGE_READWRITE 0x04 // winnt
  14186. #define PAGE_WRITECOPY 0x08 // winnt
  14187. #define PAGE_EXECUTE 0x10 // winnt
  14188. #define PAGE_EXECUTE_READ 0x20 // winnt
  14189. #define PAGE_EXECUTE_READWRITE 0x40 // winnt
  14190. #define PAGE_EXECUTE_WRITECOPY 0x80 // winnt
  14191. #define PAGE_GUARD 0x100 // winnt
  14192. #define PAGE_NOCACHE 0x200 // winnt
  14193. #define PAGE_WRITECOMBINE 0x400 // winnt
  14194. #define MEM_COMMIT 0x1000
  14195. #define MEM_RESERVE 0x2000
  14196. #define MEM_DECOMMIT 0x4000
  14197. #define MEM_RELEASE 0x8000
  14198. #define MEM_FREE 0x10000
  14199. #define MEM_PRIVATE 0x20000
  14200. #define MEM_MAPPED 0x40000
  14201. #define MEM_RESET 0x80000
  14202. #define MEM_TOP_DOWN 0x100000
  14203. #define MEM_LARGE_PAGES 0x20000000
  14204. #define MEM_4MB_PAGES 0x80000000
  14205. #define SEC_RESERVE 0x4000000
  14206. //
  14207. // Exception flag definitions.
  14208. //
  14209. // begin_winnt
  14210. #define EXCEPTION_NONCONTINUABLE 0x1 // Noncontinuable exception
  14211. // end_winnt
  14212. //
  14213. // Define maximum number of exception parameters.
  14214. //
  14215. // begin_winnt
  14216. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  14217. //
  14218. // Exception record definition.
  14219. //
  14220. typedef struct _EXCEPTION_RECORD {
  14221. NTSTATUS ExceptionCode;
  14222. ULONG ExceptionFlags;
  14223. struct _EXCEPTION_RECORD *ExceptionRecord;
  14224. PVOID ExceptionAddress;
  14225. ULONG NumberParameters;
  14226. ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  14227. } EXCEPTION_RECORD;
  14228. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  14229. typedef struct _EXCEPTION_RECORD32 {
  14230. NTSTATUS ExceptionCode;
  14231. ULONG ExceptionFlags;
  14232. ULONG ExceptionRecord;
  14233. ULONG ExceptionAddress;
  14234. ULONG NumberParameters;
  14235. ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  14236. } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
  14237. typedef struct _EXCEPTION_RECORD64 {
  14238. NTSTATUS ExceptionCode;
  14239. ULONG ExceptionFlags;
  14240. ULONG64 ExceptionRecord;
  14241. ULONG64 ExceptionAddress;
  14242. ULONG NumberParameters;
  14243. ULONG __unusedAlignment;
  14244. ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  14245. } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
  14246. //
  14247. // Typedef for pointer returned by exception_info()
  14248. //
  14249. typedef struct _EXCEPTION_POINTERS {
  14250. PEXCEPTION_RECORD ExceptionRecord;
  14251. PCONTEXT ContextRecord;
  14252. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  14253. // end_winnt
  14254. #ifdef _WIN64
  14255. #define PORT_MAXIMUM_MESSAGE_LENGTH 512
  14256. #else
  14257. #define PORT_MAXIMUM_MESSAGE_LENGTH 256
  14258. #endif
  14259. //
  14260. // Define I/O Driver error log packet structure. This structure is filled in
  14261. // by the driver.
  14262. //
  14263. typedef struct _IO_ERROR_LOG_PACKET {
  14264. UCHAR MajorFunctionCode;
  14265. UCHAR RetryCount;
  14266. USHORT DumpDataSize;
  14267. USHORT NumberOfStrings;
  14268. USHORT StringOffset;
  14269. USHORT EventCategory;
  14270. NTSTATUS ErrorCode;
  14271. ULONG UniqueErrorValue;
  14272. NTSTATUS FinalStatus;
  14273. ULONG SequenceNumber;
  14274. ULONG IoControlCode;
  14275. LARGE_INTEGER DeviceOffset;
  14276. ULONG DumpData[1];
  14277. }IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
  14278. //
  14279. // Define the I/O error log message. This message is sent by the error log
  14280. // thread over the lpc port.
  14281. //
  14282. typedef struct _IO_ERROR_LOG_MESSAGE {
  14283. USHORT Type;
  14284. USHORT Size;
  14285. USHORT DriverNameLength;
  14286. LARGE_INTEGER TimeStamp;
  14287. ULONG DriverNameOffset;
  14288. IO_ERROR_LOG_PACKET EntryData;
  14289. }IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
  14290. //
  14291. // Define the maximum message size that will be sent over the LPC to the
  14292. // application reading the error log entries.
  14293. //
  14294. //
  14295. // Regardless of LPC size restrictions, ERROR_LOG_MAXIMUM_SIZE must remain
  14296. // a value that can fit in a UCHAR.
  14297. //
  14298. #define ERROR_LOG_LIMIT_SIZE (256-16)
  14299. //
  14300. // This limit, exclusive of IO_ERROR_LOG_MESSAGE_HEADER_LENGTH, also applies
  14301. // to IO_ERROR_LOG_MESSAGE_LENGTH
  14302. //
  14303. #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
  14304. sizeof(IO_ERROR_LOG_PACKET) + \
  14305. (sizeof(WCHAR) * 40))
  14306. #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
  14307. (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  14308. //
  14309. // IO_ERROR_LOG_MESSAGE_LENGTH is
  14310. // min(PORT_MAXIMUM_MESSAGE_LENGTH, ERROR_LOG_MESSAGE_LIMIT_SIZE)
  14311. //
  14312. #define IO_ERROR_LOG_MESSAGE_LENGTH \
  14313. ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
  14314. ERROR_LOG_MESSAGE_LIMIT_SIZE : \
  14315. PORT_MAXIMUM_MESSAGE_LENGTH)
  14316. //
  14317. // Define the maximum packet size a driver can allocate.
  14318. //
  14319. #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
  14320. IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  14321. //
  14322. // Event Specific Access Rights.
  14323. //
  14324. #define EVENT_QUERY_STATE 0x0001
  14325. #define EVENT_MODIFY_STATE 0x0002 // winnt
  14326. #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) // winnt
  14327. //
  14328. // Semaphore Specific Access Rights.
  14329. //
  14330. #define SEMAPHORE_QUERY_STATE 0x0001
  14331. #define SEMAPHORE_MODIFY_STATE 0x0002 // winnt
  14332. #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3) // winnt
  14333. //
  14334. // Driver Verifier Definitions
  14335. //
  14336. typedef ULONG_PTR (*PDRIVER_VERIFIER_THUNK_ROUTINE) (
  14337. IN PVOID Context
  14338. );
  14339. //
  14340. // This structure is passed in by drivers that want to thunk callers of
  14341. // their exports.
  14342. //
  14343. typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
  14344. PDRIVER_VERIFIER_THUNK_ROUTINE PristineRoutine;
  14345. PDRIVER_VERIFIER_THUNK_ROUTINE NewRoutine;
  14346. } DRIVER_VERIFIER_THUNK_PAIRS, *PDRIVER_VERIFIER_THUNK_PAIRS;
  14347. //
  14348. // Driver Verifier flags.
  14349. //
  14350. #define DRIVER_VERIFIER_SPECIAL_POOLING 0x0001
  14351. #define DRIVER_VERIFIER_FORCE_IRQL_CHECKING 0x0002
  14352. #define DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES 0x0004
  14353. #define DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS 0x0008
  14354. #define DRIVER_VERIFIER_IO_CHECKING 0x0010
  14355. //
  14356. // Defined processor features
  14357. //
  14358. #define PF_FLOATING_POINT_PRECISION_ERRATA 0 // winnt
  14359. #define PF_FLOATING_POINT_EMULATED 1 // winnt
  14360. #define PF_COMPARE_EXCHANGE_DOUBLE 2 // winnt
  14361. #define PF_MMX_INSTRUCTIONS_AVAILABLE 3 // winnt
  14362. #define PF_PPC_MOVEMEM_64BIT_OK 4 // winnt
  14363. #define PF_ALPHA_BYTE_INSTRUCTIONS 5 // winnt
  14364. #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6 // winnt
  14365. #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7 // winnt
  14366. #define PF_RDTSC_INSTRUCTION_AVAILABLE 8 // winnt
  14367. #define PF_PAE_ENABLED 9 // winnt
  14368. #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10 // winnt
  14369. typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE {
  14370. StandardDesign, // None == 0 == standard design
  14371. NEC98x86, // NEC PC98xx series on X86
  14372. EndAlternatives // past end of known alternatives
  14373. } ALTERNATIVE_ARCHITECTURE_TYPE;
  14374. // correctly define these run-time definitions for non X86 machines
  14375. #ifndef _X86_
  14376. #ifndef IsNEC_98
  14377. #define IsNEC_98 (FALSE)
  14378. #endif
  14379. #ifndef IsNotNEC_98
  14380. #define IsNotNEC_98 (TRUE)
  14381. #endif
  14382. #ifndef SetNEC_98
  14383. #define SetNEC_98
  14384. #endif
  14385. #ifndef SetNotNEC_98
  14386. #define SetNotNEC_98
  14387. #endif
  14388. #endif
  14389. #define PROCESSOR_FEATURE_MAX 64
  14390. // end_wdm
  14391. #if defined(REMOTE_BOOT)
  14392. //
  14393. // Defined system flags.
  14394. //
  14395. /* the following two lines should be tagged with "winnt" when REMOTE_BOOT is on. */
  14396. #define SYSTEM_FLAG_REMOTE_BOOT_CLIENT 0x00000001
  14397. #define SYSTEM_FLAG_DISKLESS_CLIENT 0x00000002
  14398. #endif // defined(REMOTE_BOOT)
  14399. //
  14400. // Define data shared between kernel and user mode.
  14401. //
  14402. // N.B. User mode has read only access to this data
  14403. //
  14404. #ifdef _MAC
  14405. #pragma warning( disable : 4121)
  14406. #endif
  14407. //
  14408. // WARNING: This structure must have exactly the same layout for 32- and
  14409. // 64-bit systems. The layout of this structure cannot change and new
  14410. // fields can only be added to the end of the structure. Deprecated
  14411. // fields cannot be deleted. Platform specific fields are included on
  14412. // all systems.
  14413. //
  14414. // Layout exactness is required for Wow64 support of 32bit applications
  14415. // on Win64 systems.
  14416. //
  14417. // The layout itself cannot change since this sturcture has been exported
  14418. // in ntddk, ntifs.h, and nthal.h for some time.
  14419. //
  14420. typedef struct _KUSER_SHARED_DATA {
  14421. //
  14422. // Current low 32-bit of tick count and tick count multiplier.
  14423. //
  14424. // N.B. The tick count is updated each time the clock ticks.
  14425. //
  14426. ULONG TickCountLowDeprecated;
  14427. ULONG TickCountMultiplier;
  14428. //
  14429. // Current 64-bit interrupt time in 100ns units.
  14430. //
  14431. volatile KSYSTEM_TIME InterruptTime;
  14432. //
  14433. // Current 64-bit system time in 100ns units.
  14434. //
  14435. volatile KSYSTEM_TIME SystemTime;
  14436. //
  14437. // Current 64-bit time zone bias.
  14438. //
  14439. volatile KSYSTEM_TIME TimeZoneBias;
  14440. //
  14441. // Support image magic number range for the host system.
  14442. //
  14443. // N.B. This is an inclusive range.
  14444. //
  14445. USHORT ImageNumberLow;
  14446. USHORT ImageNumberHigh;
  14447. //
  14448. // Copy of system root in Unicode
  14449. //
  14450. WCHAR NtSystemRoot[ 260 ];
  14451. //
  14452. // Maximum stack trace depth if tracing enabled.
  14453. //
  14454. ULONG MaxStackTraceDepth;
  14455. //
  14456. // Crypto Exponent
  14457. //
  14458. ULONG CryptoExponent;
  14459. //
  14460. // TimeZoneId
  14461. //
  14462. ULONG TimeZoneId;
  14463. ULONG LargePageMinimum;
  14464. ULONG Reserved2[ 7 ];
  14465. //
  14466. // product type
  14467. //
  14468. NT_PRODUCT_TYPE NtProductType;
  14469. BOOLEAN ProductTypeIsValid;
  14470. //
  14471. // NT Version. Note that each process sees a version from its PEB, but
  14472. // if the process is running with an altered view of the system version,
  14473. // the following two fields are used to correctly identify the version
  14474. //
  14475. ULONG NtMajorVersion;
  14476. ULONG NtMinorVersion;
  14477. //
  14478. // Processor Feature Bits
  14479. //
  14480. BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
  14481. //
  14482. // Reserved fields - do not use
  14483. //
  14484. ULONG Reserved1;
  14485. ULONG Reserved3;
  14486. //
  14487. // Time slippage while in debugger
  14488. //
  14489. volatile ULONG TimeSlip;
  14490. //
  14491. // Alternative system architecture. Example: NEC PC98xx on x86
  14492. //
  14493. ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
  14494. //
  14495. // If the system is an evaluation unit, the following field contains the
  14496. // date and time that the evaluation unit expires. A value of 0 indicates
  14497. // that there is no expiration. A non-zero value is the UTC absolute time
  14498. // that the system expires.
  14499. //
  14500. LARGE_INTEGER SystemExpirationDate;
  14501. //
  14502. // Suite Support
  14503. //
  14504. ULONG SuiteMask;
  14505. //
  14506. // TRUE if a kernel debugger is connected/enabled
  14507. //
  14508. BOOLEAN KdDebuggerEnabled;
  14509. //
  14510. // Current console session Id. Always zero on non-TS systems
  14511. //
  14512. volatile ULONG ActiveConsoleId;
  14513. //
  14514. // Force-dismounts cause handles to become invalid. Rather than
  14515. // always probe handles, we maintain a serial number of
  14516. // dismounts that clients can use to see if they need to probe
  14517. // handles.
  14518. //
  14519. volatile ULONG DismountCount;
  14520. //
  14521. // This field indicates the status of the 64-bit COM+ package on the system.
  14522. // It indicates whether the Itermediate Language (IL) COM+ images need to
  14523. // use the 64-bit COM+ runtime or the 32-bit COM+ runtime.
  14524. //
  14525. ULONG ComPlusPackage;
  14526. //
  14527. // Time in tick count for system-wide last user input across all
  14528. // terminal sessions. For MP performance, it is not updated all
  14529. // the time (e.g. once a minute per session). It is used for idle
  14530. // detection.
  14531. //
  14532. ULONG LastSystemRITEventTickCount;
  14533. //
  14534. // Number of physical pages in the system. This can dynamically
  14535. // change as physical memory can be added or removed from a running
  14536. // system.
  14537. //
  14538. ULONG NumberOfPhysicalPages;
  14539. //
  14540. // True if the system was booted in safe boot mode.
  14541. //
  14542. BOOLEAN SafeBootMode;
  14543. //
  14544. // The following field is used for Heap and CritSec Tracing
  14545. // The last bit is set for Critical Sec Collision tracing and
  14546. // second Last bit is for Heap Tracing
  14547. // Also the first 16 bits are used as counter.
  14548. //
  14549. ULONG TraceLogging;
  14550. //
  14551. // Depending on the processor, the code for fast system call
  14552. // will differ, the following buffer is filled with the appropriate
  14553. // code sequence and user mode code will branch through it.
  14554. //
  14555. // (32 bytes, using ULONGLONG for alignment).
  14556. //
  14557. // N.B. The following two fields are only used on 32-bit systems.
  14558. //
  14559. ULONGLONG Fill0; // alignment
  14560. ULONGLONG SystemCall[4];
  14561. //
  14562. // The 64-bit tick count.
  14563. //
  14564. union {
  14565. volatile KSYSTEM_TIME TickCount;
  14566. volatile ULONG64 TickCountQuad;
  14567. };
  14568. } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
  14569. #ifdef _MAC
  14570. #pragma warning( default : 4121 )
  14571. #endif
  14572. //
  14573. #if defined(_X86_)
  14574. #define PAUSE_PROCESSOR _asm { rep nop }
  14575. #else
  14576. #define PAUSE_PROCESSOR
  14577. #endif
  14578. //
  14579. // Interrupt modes.
  14580. //
  14581. typedef enum _KINTERRUPT_MODE {
  14582. LevelSensitive,
  14583. Latched
  14584. } KINTERRUPT_MODE;
  14585. //
  14586. // Wait reasons
  14587. //
  14588. typedef enum _KWAIT_REASON {
  14589. Executive,
  14590. FreePage,
  14591. PageIn,
  14592. PoolAllocation,
  14593. DelayExecution,
  14594. Suspended,
  14595. UserRequest,
  14596. WrExecutive,
  14597. WrFreePage,
  14598. WrPageIn,
  14599. WrPoolAllocation,
  14600. WrDelayExecution,
  14601. WrSuspended,
  14602. WrUserRequest,
  14603. WrEventPair,
  14604. WrQueue,
  14605. WrLpcReceive,
  14606. WrLpcReply,
  14607. WrVirtualMemory,
  14608. WrPageOut,
  14609. WrRendezvous,
  14610. Spare2,
  14611. Spare3,
  14612. Spare4,
  14613. Spare5,
  14614. Spare6,
  14615. WrKernel,
  14616. WrResource,
  14617. WrPushLock,
  14618. WrMutex,
  14619. WrQuantumEnd,
  14620. WrDispatchInt,
  14621. WrPreempted,
  14622. WrYieldExecution,
  14623. MaximumWaitReason
  14624. } KWAIT_REASON;
  14625. // end_ntddk end_wdm end_nthal
  14626. //
  14627. // Miscellaneous type definitions
  14628. //
  14629. // APC state
  14630. //
  14631. typedef struct _KAPC_STATE {
  14632. LIST_ENTRY ApcListHead[MaximumMode];
  14633. struct _KPROCESS *Process;
  14634. BOOLEAN KernelApcInProgress;
  14635. BOOLEAN KernelApcPending;
  14636. BOOLEAN UserApcPending;
  14637. } KAPC_STATE, *PKAPC_STATE, *RESTRICTED_POINTER PRKAPC_STATE;
  14638. typedef struct _KWAIT_BLOCK {
  14639. LIST_ENTRY WaitListEntry;
  14640. struct _KTHREAD *RESTRICTED_POINTER Thread;
  14641. PVOID Object;
  14642. struct _KWAIT_BLOCK *RESTRICTED_POINTER NextWaitBlock;
  14643. USHORT WaitKey;
  14644. USHORT WaitType;
  14645. } KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
  14646. //
  14647. // Thread start function
  14648. //
  14649. typedef
  14650. VOID
  14651. (*PKSTART_ROUTINE) (
  14652. IN PVOID StartContext
  14653. );
  14654. //
  14655. // Kernel object structure definitions
  14656. //
  14657. //
  14658. // Device Queue object and entry
  14659. //
  14660. typedef struct _KDEVICE_QUEUE {
  14661. CSHORT Type;
  14662. CSHORT Size;
  14663. LIST_ENTRY DeviceListHead;
  14664. KSPIN_LOCK Lock;
  14665. BOOLEAN Busy;
  14666. } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
  14667. typedef struct _KDEVICE_QUEUE_ENTRY {
  14668. LIST_ENTRY DeviceListEntry;
  14669. ULONG SortKey;
  14670. BOOLEAN Inserted;
  14671. } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY, *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
  14672. //
  14673. // Define the interrupt service function type and the empty struct
  14674. // type.
  14675. //
  14676. typedef
  14677. BOOLEAN
  14678. (*PKSERVICE_ROUTINE) (
  14679. IN struct _KINTERRUPT *Interrupt,
  14680. IN PVOID ServiceContext
  14681. );
  14682. //
  14683. // Mutant object
  14684. //
  14685. typedef struct _KMUTANT {
  14686. DISPATCHER_HEADER Header;
  14687. LIST_ENTRY MutantListEntry;
  14688. struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
  14689. BOOLEAN Abandoned;
  14690. UCHAR ApcDisable;
  14691. } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
  14692. // end_ntddk end_wdm end_ntosp
  14693. //
  14694. // Queue object
  14695. //
  14696. #define ASSERT_QUEUE(Q) ASSERT(((Q)->Header.Type & ~KOBJECT_LOCK_BIT) == QueueObject);
  14697. // begin_ntosp
  14698. typedef struct _KQUEUE {
  14699. DISPATCHER_HEADER Header;
  14700. LIST_ENTRY EntryListHead;
  14701. ULONG CurrentCount;
  14702. ULONG MaximumCount;
  14703. LIST_ENTRY ThreadListHead;
  14704. } KQUEUE, *PKQUEUE, *RESTRICTED_POINTER PRKQUEUE;
  14705. // end_ntosp
  14706. // begin_ntddk begin_wdm begin_ntosp
  14707. //
  14708. //
  14709. // Semaphore object
  14710. //
  14711. typedef struct _KSEMAPHORE {
  14712. DISPATCHER_HEADER Header;
  14713. LONG Limit;
  14714. } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
  14715. //
  14716. // DPC object
  14717. //
  14718. NTKERNELAPI
  14719. VOID
  14720. KeInitializeDpc (
  14721. IN PRKDPC Dpc,
  14722. IN PKDEFERRED_ROUTINE DeferredRoutine,
  14723. IN PVOID DeferredContext
  14724. );
  14725. NTKERNELAPI
  14726. BOOLEAN
  14727. KeInsertQueueDpc (
  14728. IN PRKDPC Dpc,
  14729. IN PVOID SystemArgument1,
  14730. IN PVOID SystemArgument2
  14731. );
  14732. NTKERNELAPI
  14733. BOOLEAN
  14734. KeRemoveQueueDpc (
  14735. IN PRKDPC Dpc
  14736. );
  14737. // end_wdm
  14738. NTKERNELAPI
  14739. VOID
  14740. KeSetImportanceDpc (
  14741. IN PRKDPC Dpc,
  14742. IN KDPC_IMPORTANCE Importance
  14743. );
  14744. NTKERNELAPI
  14745. VOID
  14746. KeSetTargetProcessorDpc (
  14747. IN PRKDPC Dpc,
  14748. IN CCHAR Number
  14749. );
  14750. // begin_wdm
  14751. NTKERNELAPI
  14752. VOID
  14753. KeFlushQueuedDpcs (
  14754. VOID
  14755. );
  14756. //
  14757. // Device queue object
  14758. //
  14759. NTKERNELAPI
  14760. VOID
  14761. KeInitializeDeviceQueue (
  14762. IN PKDEVICE_QUEUE DeviceQueue
  14763. );
  14764. NTKERNELAPI
  14765. BOOLEAN
  14766. KeInsertDeviceQueue (
  14767. IN PKDEVICE_QUEUE DeviceQueue,
  14768. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  14769. );
  14770. NTKERNELAPI
  14771. BOOLEAN
  14772. KeInsertByKeyDeviceQueue (
  14773. IN PKDEVICE_QUEUE DeviceQueue,
  14774. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
  14775. IN ULONG SortKey
  14776. );
  14777. NTKERNELAPI
  14778. PKDEVICE_QUEUE_ENTRY
  14779. KeRemoveDeviceQueue (
  14780. IN PKDEVICE_QUEUE DeviceQueue
  14781. );
  14782. NTKERNELAPI
  14783. PKDEVICE_QUEUE_ENTRY
  14784. KeRemoveByKeyDeviceQueue (
  14785. IN PKDEVICE_QUEUE DeviceQueue,
  14786. IN ULONG SortKey
  14787. );
  14788. NTKERNELAPI
  14789. PKDEVICE_QUEUE_ENTRY
  14790. KeRemoveByKeyDeviceQueueIfBusy (
  14791. IN PKDEVICE_QUEUE DeviceQueue,
  14792. IN ULONG SortKey
  14793. );
  14794. NTKERNELAPI
  14795. BOOLEAN
  14796. KeRemoveEntryDeviceQueue (
  14797. IN PKDEVICE_QUEUE DeviceQueue,
  14798. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  14799. );
  14800. //
  14801. // Kernel dispatcher object functions
  14802. //
  14803. // Event Object
  14804. //
  14805. NTKERNELAPI
  14806. VOID
  14807. KeInitializeEvent (
  14808. IN PRKEVENT Event,
  14809. IN EVENT_TYPE Type,
  14810. IN BOOLEAN State
  14811. );
  14812. NTKERNELAPI
  14813. VOID
  14814. KeClearEvent (
  14815. IN PRKEVENT Event
  14816. );
  14817. NTKERNELAPI
  14818. LONG
  14819. KePulseEvent (
  14820. IN PRKEVENT Event,
  14821. IN KPRIORITY Increment,
  14822. IN BOOLEAN Wait
  14823. );
  14824. NTKERNELAPI
  14825. LONG
  14826. KeReadStateEvent (
  14827. IN PRKEVENT Event
  14828. );
  14829. NTKERNELAPI
  14830. LONG
  14831. KeResetEvent (
  14832. IN PRKEVENT Event
  14833. );
  14834. NTKERNELAPI
  14835. LONG
  14836. KeSetEvent (
  14837. IN PRKEVENT Event,
  14838. IN KPRIORITY Increment,
  14839. IN BOOLEAN Wait
  14840. );
  14841. NTKERNELAPI
  14842. VOID
  14843. KeInitializeMutant (
  14844. IN PRKMUTANT Mutant,
  14845. IN BOOLEAN InitialOwner
  14846. );
  14847. LONG
  14848. KeReadStateMutant (
  14849. IN PRKMUTANT Mutant
  14850. );
  14851. NTKERNELAPI
  14852. LONG
  14853. KeReleaseMutant (
  14854. IN PRKMUTANT Mutant,
  14855. IN KPRIORITY Increment,
  14856. IN BOOLEAN Abandoned,
  14857. IN BOOLEAN Wait
  14858. );
  14859. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  14860. //
  14861. // Mutex object
  14862. //
  14863. NTKERNELAPI
  14864. VOID
  14865. KeInitializeMutex (
  14866. IN PRKMUTEX Mutex,
  14867. IN ULONG Level
  14868. );
  14869. NTKERNELAPI
  14870. LONG
  14871. KeReadStateMutex (
  14872. IN PRKMUTEX Mutex
  14873. );
  14874. NTKERNELAPI
  14875. LONG
  14876. KeReleaseMutex (
  14877. IN PRKMUTEX Mutex,
  14878. IN BOOLEAN Wait
  14879. );
  14880. // end_ntddk end_wdm
  14881. //
  14882. // Queue Object.
  14883. //
  14884. NTKERNELAPI
  14885. VOID
  14886. KeInitializeQueue (
  14887. IN PRKQUEUE Queue,
  14888. IN ULONG Count OPTIONAL
  14889. );
  14890. NTKERNELAPI
  14891. LONG
  14892. KeReadStateQueue (
  14893. IN PRKQUEUE Queue
  14894. );
  14895. NTKERNELAPI
  14896. LONG
  14897. KeInsertQueue (
  14898. IN PRKQUEUE Queue,
  14899. IN PLIST_ENTRY Entry
  14900. );
  14901. NTKERNELAPI
  14902. LONG
  14903. KeInsertHeadQueue (
  14904. IN PRKQUEUE Queue,
  14905. IN PLIST_ENTRY Entry
  14906. );
  14907. NTKERNELAPI
  14908. PLIST_ENTRY
  14909. KeRemoveQueue (
  14910. IN PRKQUEUE Queue,
  14911. IN KPROCESSOR_MODE WaitMode,
  14912. IN PLARGE_INTEGER Timeout OPTIONAL
  14913. );
  14914. PLIST_ENTRY
  14915. KeRundownQueue (
  14916. IN PRKQUEUE Queue
  14917. );
  14918. // begin_ntddk begin_wdm
  14919. //
  14920. // Semaphore object
  14921. //
  14922. NTKERNELAPI
  14923. VOID
  14924. KeInitializeSemaphore (
  14925. IN PRKSEMAPHORE Semaphore,
  14926. IN LONG Count,
  14927. IN LONG Limit
  14928. );
  14929. NTKERNELAPI
  14930. LONG
  14931. KeReadStateSemaphore (
  14932. IN PRKSEMAPHORE Semaphore
  14933. );
  14934. NTKERNELAPI
  14935. LONG
  14936. KeReleaseSemaphore (
  14937. IN PRKSEMAPHORE Semaphore,
  14938. IN KPRIORITY Increment,
  14939. IN LONG Adjustment,
  14940. IN BOOLEAN Wait
  14941. );
  14942. NTKERNELAPI
  14943. VOID
  14944. KeAttachProcess (
  14945. IN PRKPROCESS Process
  14946. );
  14947. NTKERNELAPI
  14948. VOID
  14949. KeDetachProcess (
  14950. VOID
  14951. );
  14952. NTKERNELAPI
  14953. VOID
  14954. KeStackAttachProcess (
  14955. IN PRKPROCESS PROCESS,
  14956. OUT PRKAPC_STATE ApcState
  14957. );
  14958. NTKERNELAPI
  14959. VOID
  14960. KeUnstackDetachProcess (
  14961. IN PRKAPC_STATE ApcState
  14962. );
  14963. NTKERNELAPI
  14964. NTSTATUS
  14965. KeDelayExecutionThread (
  14966. IN KPROCESSOR_MODE WaitMode,
  14967. IN BOOLEAN Alertable,
  14968. IN PLARGE_INTEGER Interval
  14969. );
  14970. NTKERNELAPI
  14971. KPRIORITY
  14972. KeQueryPriorityThread (
  14973. IN PKTHREAD Thread
  14974. );
  14975. NTKERNELAPI
  14976. ULONG
  14977. KeQueryRuntimeThread (
  14978. IN PKTHREAD Thread,
  14979. OUT PULONG UserTime
  14980. );
  14981. NTKERNELAPI
  14982. LONG
  14983. KeSetBasePriorityThread (
  14984. IN PKTHREAD Thread,
  14985. IN LONG Increment
  14986. );
  14987. NTKERNELAPI
  14988. UCHAR
  14989. KeSetIdealProcessorThread (
  14990. IN PKTHREAD Thread,
  14991. IN UCHAR Processor
  14992. );
  14993. // begin_ntosp
  14994. NTKERNELAPI
  14995. BOOLEAN
  14996. KeSetKernelStackSwapEnable (
  14997. IN BOOLEAN Enable
  14998. );
  14999. NTKERNELAPI
  15000. KPRIORITY
  15001. KeSetPriorityThread (
  15002. IN PKTHREAD Thread,
  15003. IN KPRIORITY Priority
  15004. );
  15005. #if ((defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) ||defined(_NTHAL_)) && !defined(_NTSYSTEM_DRIVER_) || defined(_NTOSP_))
  15006. // begin_wdm
  15007. NTKERNELAPI
  15008. VOID
  15009. KeEnterCriticalRegion (
  15010. VOID
  15011. );
  15012. NTKERNELAPI
  15013. VOID
  15014. KeLeaveCriticalRegion (
  15015. VOID
  15016. );
  15017. NTKERNELAPI
  15018. BOOLEAN
  15019. KeAreApcsDisabled (
  15020. VOID
  15021. );
  15022. // end_wdm
  15023. #endif
  15024. // begin_wdm
  15025. //
  15026. // Timer object
  15027. //
  15028. NTKERNELAPI
  15029. VOID
  15030. KeInitializeTimer (
  15031. IN PKTIMER Timer
  15032. );
  15033. NTKERNELAPI
  15034. VOID
  15035. KeInitializeTimerEx (
  15036. IN PKTIMER Timer,
  15037. IN TIMER_TYPE Type
  15038. );
  15039. NTKERNELAPI
  15040. BOOLEAN
  15041. KeCancelTimer (
  15042. IN PKTIMER
  15043. );
  15044. NTKERNELAPI
  15045. BOOLEAN
  15046. KeReadStateTimer (
  15047. PKTIMER Timer
  15048. );
  15049. NTKERNELAPI
  15050. BOOLEAN
  15051. KeSetTimer (
  15052. IN PKTIMER Timer,
  15053. IN LARGE_INTEGER DueTime,
  15054. IN PKDPC Dpc OPTIONAL
  15055. );
  15056. NTKERNELAPI
  15057. BOOLEAN
  15058. KeSetTimerEx (
  15059. IN PKTIMER Timer,
  15060. IN LARGE_INTEGER DueTime,
  15061. IN LONG Period OPTIONAL,
  15062. IN PKDPC Dpc OPTIONAL
  15063. );
  15064. #define KeWaitForMutexObject KeWaitForSingleObject
  15065. NTKERNELAPI
  15066. NTSTATUS
  15067. KeWaitForMultipleObjects (
  15068. IN ULONG Count,
  15069. IN PVOID Object[],
  15070. IN WAIT_TYPE WaitType,
  15071. IN KWAIT_REASON WaitReason,
  15072. IN KPROCESSOR_MODE WaitMode,
  15073. IN BOOLEAN Alertable,
  15074. IN PLARGE_INTEGER Timeout OPTIONAL,
  15075. IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
  15076. );
  15077. NTKERNELAPI
  15078. NTSTATUS
  15079. KeWaitForSingleObject (
  15080. IN PVOID Object,
  15081. IN KWAIT_REASON WaitReason,
  15082. IN KPROCESSOR_MODE WaitMode,
  15083. IN BOOLEAN Alertable,
  15084. IN PLARGE_INTEGER Timeout OPTIONAL
  15085. );
  15086. //
  15087. // Define interprocess interrupt generic call types.
  15088. //
  15089. typedef
  15090. ULONG_PTR
  15091. (*PKIPI_BROADCAST_WORKER)(
  15092. IN ULONG_PTR Argument
  15093. );
  15094. ULONG_PTR
  15095. KeIpiGenericCall (
  15096. IN PKIPI_BROADCAST_WORKER BroadcastFunction,
  15097. IN ULONG_PTR Context
  15098. );
  15099. //
  15100. // On X86 the following routines are defined in the HAL and imported by
  15101. // all other modules.
  15102. //
  15103. #if defined(_X86_) && !defined(_NTHAL_)
  15104. #define _DECL_HAL_KE_IMPORT __declspec(dllimport)
  15105. #else
  15106. #define _DECL_HAL_KE_IMPORT
  15107. #endif
  15108. _DECL_HAL_KE_IMPORT
  15109. KIRQL
  15110. FASTCALL
  15111. KeAcquireQueuedSpinLock (
  15112. IN KSPIN_LOCK_QUEUE_NUMBER Number
  15113. );
  15114. _DECL_HAL_KE_IMPORT
  15115. VOID
  15116. FASTCALL
  15117. KeReleaseQueuedSpinLock (
  15118. IN KSPIN_LOCK_QUEUE_NUMBER Number,
  15119. IN KIRQL OldIrql
  15120. );
  15121. _DECL_HAL_KE_IMPORT
  15122. LOGICAL
  15123. FASTCALL
  15124. KeTryToAcquireQueuedSpinLock(
  15125. IN KSPIN_LOCK_QUEUE_NUMBER Number,
  15126. IN PKIRQL OldIrql
  15127. );
  15128. //
  15129. // spin lock functions
  15130. //
  15131. #if defined(_X86_) && (defined(_WDMDDK_) || defined(WIN9X_COMPAT_SPINLOCK))
  15132. NTKERNELAPI
  15133. VOID
  15134. NTAPI
  15135. KeInitializeSpinLock (
  15136. IN PKSPIN_LOCK SpinLock
  15137. );
  15138. #else
  15139. __inline
  15140. VOID
  15141. NTAPI
  15142. KeInitializeSpinLock (
  15143. IN PKSPIN_LOCK SpinLock
  15144. )
  15145. {
  15146. *SpinLock = 0;
  15147. }
  15148. #endif
  15149. #if defined(_X86_)
  15150. NTKERNELAPI
  15151. VOID
  15152. FASTCALL
  15153. KefAcquireSpinLockAtDpcLevel (
  15154. IN PKSPIN_LOCK SpinLock
  15155. );
  15156. NTKERNELAPI
  15157. VOID
  15158. FASTCALL
  15159. KefReleaseSpinLockFromDpcLevel (
  15160. IN PKSPIN_LOCK SpinLock
  15161. );
  15162. #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
  15163. #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
  15164. _DECL_HAL_KE_IMPORT
  15165. KIRQL
  15166. FASTCALL
  15167. KfAcquireSpinLock (
  15168. IN PKSPIN_LOCK SpinLock
  15169. );
  15170. _DECL_HAL_KE_IMPORT
  15171. VOID
  15172. FASTCALL
  15173. KfReleaseSpinLock (
  15174. IN PKSPIN_LOCK SpinLock,
  15175. IN KIRQL NewIrql
  15176. );
  15177. // end_wdm end_ntddk
  15178. _DECL_HAL_KE_IMPORT
  15179. KIRQL
  15180. FASTCALL
  15181. KeAcquireSpinLockRaiseToSynch (
  15182. IN PKSPIN_LOCK SpinLock
  15183. );
  15184. // begin_wdm begin_ntddk
  15185. #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
  15186. #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
  15187. NTKERNELAPI
  15188. BOOLEAN
  15189. FASTCALL
  15190. KeTestSpinLock (
  15191. IN PKSPIN_LOCK SpinLock
  15192. );
  15193. NTKERNELAPI
  15194. BOOLEAN
  15195. FASTCALL
  15196. KeTryToAcquireSpinLockAtDpcLevel (
  15197. IN PKSPIN_LOCK SpinLock
  15198. );
  15199. #else
  15200. //
  15201. // These functions are imported for IA64, ntddk, ntifs, nthal, ntosp, and wdm.
  15202. // They can be inlined for the system on AMD64.
  15203. //
  15204. #define KeAcquireSpinLock(SpinLock, OldIrql) \
  15205. *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
  15206. #if defined(_IA64_) || defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_) || defined(_WDMDDK_)
  15207. // end_wdm end_ntddk
  15208. NTKERNELAPI
  15209. KIRQL
  15210. FASTCALL
  15211. KeAcquireSpinLockRaiseToSynch (
  15212. IN PKSPIN_LOCK SpinLock
  15213. );
  15214. // begin_wdm begin_ntddk
  15215. NTKERNELAPI
  15216. VOID
  15217. KeAcquireSpinLockAtDpcLevel (
  15218. IN PKSPIN_LOCK SpinLock
  15219. );
  15220. NTKERNELAPI
  15221. KIRQL
  15222. KeAcquireSpinLockRaiseToDpc (
  15223. IN PKSPIN_LOCK SpinLock
  15224. );
  15225. NTKERNELAPI
  15226. VOID
  15227. KeReleaseSpinLock (
  15228. IN PKSPIN_LOCK SpinLock,
  15229. IN KIRQL NewIrql
  15230. );
  15231. NTKERNELAPI
  15232. VOID
  15233. KeReleaseSpinLockFromDpcLevel (
  15234. IN PKSPIN_LOCK SpinLock
  15235. );
  15236. NTKERNELAPI
  15237. BOOLEAN
  15238. FASTCALL
  15239. KeTestSpinLock (
  15240. IN PKSPIN_LOCK SpinLock
  15241. );
  15242. NTKERNELAPI
  15243. BOOLEAN
  15244. FASTCALL
  15245. KeTryToAcquireSpinLockAtDpcLevel (
  15246. IN PKSPIN_LOCK SpinLock
  15247. );
  15248. #else
  15249. #if defined(_AMD64_)
  15250. //
  15251. // The system version of these functions are defined in amd64.h for AMD64.
  15252. //
  15253. #endif
  15254. #endif
  15255. #endif
  15256. #if defined(_X86_)
  15257. _DECL_HAL_KE_IMPORT
  15258. VOID
  15259. FASTCALL
  15260. KfLowerIrql (
  15261. IN KIRQL NewIrql
  15262. );
  15263. _DECL_HAL_KE_IMPORT
  15264. KIRQL
  15265. FASTCALL
  15266. KfRaiseIrql (
  15267. IN KIRQL NewIrql
  15268. );
  15269. // end_wdm
  15270. _DECL_HAL_KE_IMPORT
  15271. KIRQL
  15272. KeRaiseIrqlToDpcLevel(
  15273. VOID
  15274. );
  15275. // end_ntddk
  15276. _DECL_HAL_KE_IMPORT
  15277. KIRQL
  15278. KeRaiseIrqlToSynchLevel(
  15279. VOID
  15280. );
  15281. // begin_wdm begin_ntddk
  15282. #define KeLowerIrql(a) KfLowerIrql(a)
  15283. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  15284. // end_wdm
  15285. // begin_wdm
  15286. #elif defined(_IA64_)
  15287. //
  15288. // These function are defined in IA64.h for the IA64 platform.
  15289. //
  15290. #elif defined(_AMD64_)
  15291. //
  15292. // These function are defined in amd64.h for the AMD64 platform.
  15293. //
  15294. #else
  15295. #error "no target architecture"
  15296. #endif
  15297. //
  15298. // Queued spin lock functions for "in stack" lock handles.
  15299. //
  15300. // The following three functions RAISE and LOWER IRQL when a queued
  15301. // in stack spin lock is acquired or released using these routines.
  15302. //
  15303. _DECL_HAL_KE_IMPORT
  15304. VOID
  15305. FASTCALL
  15306. KeAcquireInStackQueuedSpinLock (
  15307. IN PKSPIN_LOCK SpinLock,
  15308. IN PKLOCK_QUEUE_HANDLE LockHandle
  15309. );
  15310. _DECL_HAL_KE_IMPORT
  15311. VOID
  15312. FASTCALL
  15313. KeReleaseInStackQueuedSpinLock (
  15314. IN PKLOCK_QUEUE_HANDLE LockHandle
  15315. );
  15316. //
  15317. // The following two functions do NOT raise or lower IRQL when a queued
  15318. // in stack spin lock is acquired or released using these functions.
  15319. //
  15320. NTKERNELAPI
  15321. VOID
  15322. FASTCALL
  15323. KeAcquireInStackQueuedSpinLockAtDpcLevel (
  15324. IN PKSPIN_LOCK SpinLock,
  15325. IN PKLOCK_QUEUE_HANDLE LockHandle
  15326. );
  15327. NTKERNELAPI
  15328. VOID
  15329. FASTCALL
  15330. KeReleaseInStackQueuedSpinLockFromDpcLevel (
  15331. IN PKLOCK_QUEUE_HANDLE LockHandle
  15332. );
  15333. //
  15334. // Miscellaneous kernel functions
  15335. //
  15336. typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
  15337. BufferEmpty,
  15338. BufferInserted,
  15339. BufferStarted,
  15340. BufferFinished,
  15341. BufferIncomplete
  15342. } KBUGCHECK_BUFFER_DUMP_STATE;
  15343. typedef
  15344. VOID
  15345. (*PKBUGCHECK_CALLBACK_ROUTINE) (
  15346. IN PVOID Buffer,
  15347. IN ULONG Length
  15348. );
  15349. typedef struct _KBUGCHECK_CALLBACK_RECORD {
  15350. LIST_ENTRY Entry;
  15351. PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
  15352. PVOID Buffer;
  15353. ULONG Length;
  15354. PUCHAR Component;
  15355. ULONG_PTR Checksum;
  15356. UCHAR State;
  15357. } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
  15358. #define KeInitializeCallbackRecord(CallbackRecord) \
  15359. (CallbackRecord)->State = BufferEmpty
  15360. NTKERNELAPI
  15361. BOOLEAN
  15362. KeDeregisterBugCheckCallback (
  15363. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord
  15364. );
  15365. NTKERNELAPI
  15366. BOOLEAN
  15367. KeRegisterBugCheckCallback (
  15368. IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
  15369. IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
  15370. IN PVOID Buffer,
  15371. IN ULONG Length,
  15372. IN PUCHAR Component
  15373. );
  15374. typedef enum _KBUGCHECK_CALLBACK_REASON {
  15375. KbCallbackInvalid,
  15376. KbCallbackReserved1,
  15377. KbCallbackSecondaryDumpData,
  15378. KbCallbackDumpIo,
  15379. } KBUGCHECK_CALLBACK_REASON;
  15380. typedef
  15381. VOID
  15382. (*PKBUGCHECK_REASON_CALLBACK_ROUTINE) (
  15383. IN KBUGCHECK_CALLBACK_REASON Reason,
  15384. IN struct _KBUGCHECK_REASON_CALLBACK_RECORD* Record,
  15385. IN OUT PVOID ReasonSpecificData,
  15386. IN ULONG ReasonSpecificDataLength
  15387. );
  15388. typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
  15389. LIST_ENTRY Entry;
  15390. PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
  15391. PUCHAR Component;
  15392. ULONG_PTR Checksum;
  15393. KBUGCHECK_CALLBACK_REASON Reason;
  15394. UCHAR State;
  15395. } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
  15396. typedef struct _KBUGCHECK_SECONDARY_DUMP_DATA {
  15397. IN PVOID InBuffer;
  15398. IN ULONG InBufferLength;
  15399. IN ULONG MaximumAllowed;
  15400. OUT GUID Guid;
  15401. OUT PVOID OutBuffer;
  15402. OUT ULONG OutBufferLength;
  15403. } KBUGCHECK_SECONDARY_DUMP_DATA, *PKBUGCHECK_SECONDARY_DUMP_DATA;
  15404. typedef enum _KBUGCHECK_DUMP_IO_TYPE
  15405. {
  15406. KbDumpIoInvalid,
  15407. KbDumpIoHeader,
  15408. KbDumpIoBody,
  15409. KbDumpIoSecondaryData,
  15410. KbDumpIoComplete
  15411. } KBUGCHECK_DUMP_IO_TYPE;
  15412. typedef struct _KBUGCHECK_DUMP_IO {
  15413. IN ULONG64 Offset;
  15414. IN PVOID Buffer;
  15415. IN ULONG BufferLength;
  15416. IN KBUGCHECK_DUMP_IO_TYPE Type;
  15417. } KBUGCHECK_DUMP_IO, *PKBUGCHECK_DUMP_IO;
  15418. NTKERNELAPI
  15419. BOOLEAN
  15420. KeDeregisterBugCheckReasonCallback (
  15421. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
  15422. );
  15423. NTKERNELAPI
  15424. BOOLEAN
  15425. KeRegisterBugCheckReasonCallback (
  15426. IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord,
  15427. IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine,
  15428. IN KBUGCHECK_CALLBACK_REASON Reason,
  15429. IN PUCHAR Component
  15430. );
  15431. typedef
  15432. BOOLEAN
  15433. (*PNMI_CALLBACK)(
  15434. IN PVOID Context,
  15435. IN BOOLEAN Handled
  15436. );
  15437. NTKERNELAPI
  15438. PVOID
  15439. KeRegisterNmiCallback(
  15440. PNMI_CALLBACK CallbackRoutine,
  15441. PVOID Context
  15442. );
  15443. NTSTATUS
  15444. KeDeregisterNmiCallback(
  15445. PVOID Handle
  15446. );
  15447. // end_wdm
  15448. NTKERNELAPI
  15449. DECLSPEC_NORETURN
  15450. VOID
  15451. NTAPI
  15452. KeBugCheck (
  15453. IN ULONG BugCheckCode
  15454. );
  15455. NTKERNELAPI
  15456. DECLSPEC_NORETURN
  15457. VOID
  15458. KeBugCheckEx(
  15459. IN ULONG BugCheckCode,
  15460. IN ULONG_PTR BugCheckParameter1,
  15461. IN ULONG_PTR BugCheckParameter2,
  15462. IN ULONG_PTR BugCheckParameter3,
  15463. IN ULONG_PTR BugCheckParameter4
  15464. );
  15465. #if !defined(_AMD64_)
  15466. NTKERNELAPI
  15467. ULONGLONG
  15468. KeQueryInterruptTime (
  15469. VOID
  15470. );
  15471. NTKERNELAPI
  15472. VOID
  15473. KeQuerySystemTime (
  15474. OUT PLARGE_INTEGER CurrentTime
  15475. );
  15476. #endif
  15477. NTKERNELAPI
  15478. ULONG
  15479. KeQueryTimeIncrement (
  15480. VOID
  15481. );
  15482. NTKERNELAPI
  15483. ULONG
  15484. KeGetRecommendedSharedDataAlignment (
  15485. VOID
  15486. );
  15487. // end_wdm
  15488. NTKERNELAPI
  15489. KAFFINITY
  15490. KeQueryActiveProcessors (
  15491. VOID
  15492. );
  15493. #if defined(_IA64_)
  15494. extern volatile LARGE_INTEGER KeTickCount;
  15495. #elif defined(_X86_)
  15496. extern volatile KSYSTEM_TIME KeTickCount;
  15497. #endif
  15498. typedef enum _MEMORY_CACHING_TYPE_ORIG {
  15499. MmFrameBufferCached = 2
  15500. } MEMORY_CACHING_TYPE_ORIG;
  15501. typedef enum _MEMORY_CACHING_TYPE {
  15502. MmNonCached = FALSE,
  15503. MmCached = TRUE,
  15504. MmWriteCombined = MmFrameBufferCached,
  15505. MmHardwareCoherentCached,
  15506. MmNonCachedUnordered, // IA64
  15507. MmUSWCCached,
  15508. MmMaximumCacheType
  15509. } MEMORY_CACHING_TYPE;
  15510. //
  15511. // Pool Allocation routines (in pool.c)
  15512. //
  15513. typedef enum _POOL_TYPE {
  15514. NonPagedPool,
  15515. PagedPool,
  15516. NonPagedPoolMustSucceed,
  15517. DontUseThisType,
  15518. NonPagedPoolCacheAligned,
  15519. PagedPoolCacheAligned,
  15520. NonPagedPoolCacheAlignedMustS,
  15521. MaxPoolType
  15522. // end_wdm
  15523. ,
  15524. //
  15525. // Note these per session types are carefully chosen so that the appropriate
  15526. // masking still applies as well as MaxPoolType above.
  15527. //
  15528. NonPagedPoolSession = 32,
  15529. PagedPoolSession = NonPagedPoolSession + 1,
  15530. NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
  15531. DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
  15532. NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
  15533. PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
  15534. NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1,
  15535. // begin_wdm
  15536. } POOL_TYPE;
  15537. #define POOL_COLD_ALLOCATION 256 // Note this cannot encode into the header.
  15538. #define POOL_RAISE_IF_ALLOCATION_FAILURE 16
  15539. DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithTag
  15540. NTKERNELAPI
  15541. PVOID
  15542. ExAllocatePool(
  15543. IN POOL_TYPE PoolType,
  15544. IN SIZE_T NumberOfBytes
  15545. );
  15546. DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithQuotaTag
  15547. NTKERNELAPI
  15548. PVOID
  15549. ExAllocatePoolWithQuota(
  15550. IN POOL_TYPE PoolType,
  15551. IN SIZE_T NumberOfBytes
  15552. );
  15553. NTKERNELAPI
  15554. PVOID
  15555. NTAPI
  15556. ExAllocatePoolWithTag(
  15557. IN POOL_TYPE PoolType,
  15558. IN SIZE_T NumberOfBytes,
  15559. IN ULONG Tag
  15560. );
  15561. //
  15562. // _EX_POOL_PRIORITY_ provides a method for the system to handle requests
  15563. // intelligently in low resource conditions.
  15564. //
  15565. // LowPoolPriority should be used when it is acceptable to the driver for the
  15566. // mapping request to fail if the system is low on resources. An example of
  15567. // this could be for a non-critical network connection where the driver can
  15568. // handle the failure case when system resources are close to being depleted.
  15569. //
  15570. // NormalPoolPriority should be used when it is acceptable to the driver for the
  15571. // mapping request to fail if the system is very low on resources. An example
  15572. // of this could be for a non-critical local filesystem request.
  15573. //
  15574. // HighPoolPriority should be used when it is unacceptable to the driver for the
  15575. // mapping request to fail unless the system is completely out of resources.
  15576. // An example of this would be the paging file path in a driver.
  15577. //
  15578. // SpecialPool can be specified to bound the allocation at a page end (or
  15579. // beginning). This should only be done on systems being debugged as the
  15580. // memory cost is expensive.
  15581. //
  15582. // N.B. These values are very carefully chosen so that the pool allocation
  15583. // code can quickly crack the priority request.
  15584. //
  15585. typedef enum _EX_POOL_PRIORITY {
  15586. LowPoolPriority,
  15587. LowPoolPrioritySpecialPoolOverrun = 8,
  15588. LowPoolPrioritySpecialPoolUnderrun = 9,
  15589. NormalPoolPriority = 16,
  15590. NormalPoolPrioritySpecialPoolOverrun = 24,
  15591. NormalPoolPrioritySpecialPoolUnderrun = 25,
  15592. HighPoolPriority = 32,
  15593. HighPoolPrioritySpecialPoolOverrun = 40,
  15594. HighPoolPrioritySpecialPoolUnderrun = 41
  15595. } EX_POOL_PRIORITY;
  15596. NTKERNELAPI
  15597. PVOID
  15598. NTAPI
  15599. ExAllocatePoolWithTagPriority(
  15600. IN POOL_TYPE PoolType,
  15601. IN SIZE_T NumberOfBytes,
  15602. IN ULONG Tag,
  15603. IN EX_POOL_PRIORITY Priority
  15604. );
  15605. #ifndef POOL_TAGGING
  15606. #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
  15607. #endif //POOL_TAGGING
  15608. NTKERNELAPI
  15609. PVOID
  15610. ExAllocatePoolWithQuotaTag(
  15611. IN POOL_TYPE PoolType,
  15612. IN SIZE_T NumberOfBytes,
  15613. IN ULONG Tag
  15614. );
  15615. #ifndef POOL_TAGGING
  15616. #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
  15617. #endif //POOL_TAGGING
  15618. NTKERNELAPI
  15619. VOID
  15620. NTAPI
  15621. ExFreePool(
  15622. IN PVOID P
  15623. );
  15624. // end_wdm
  15625. #if defined(POOL_TAGGING)
  15626. #define ExFreePool(a) ExFreePoolWithTag(a,0)
  15627. #endif
  15628. //
  15629. // If high order bit in Pool tag is set, then must use ExFreePoolWithTag to free
  15630. //
  15631. #define PROTECTED_POOL 0x80000000
  15632. // begin_wdm
  15633. NTKERNELAPI
  15634. VOID
  15635. ExFreePoolWithTag(
  15636. IN PVOID P,
  15637. IN ULONG Tag
  15638. );
  15639. NTKERNELAPI
  15640. SIZE_T
  15641. ExQueryPoolBlockSize (
  15642. IN PVOID PoolBlock,
  15643. OUT PBOOLEAN QuotaCharged
  15644. );
  15645. //
  15646. // Routines to support fast mutexes.
  15647. //
  15648. typedef struct _FAST_MUTEX {
  15649. LONG Count;
  15650. PKTHREAD Owner;
  15651. ULONG Contention;
  15652. KEVENT Event;
  15653. ULONG OldIrql;
  15654. } FAST_MUTEX, *PFAST_MUTEX;
  15655. #define ExInitializeFastMutex(_FastMutex) \
  15656. (_FastMutex)->Count = 1; \
  15657. (_FastMutex)->Owner = NULL; \
  15658. (_FastMutex)->Contention = 0; \
  15659. KeInitializeEvent(&(_FastMutex)->Event, \
  15660. SynchronizationEvent, \
  15661. FALSE);
  15662. NTKERNELAPI
  15663. VOID
  15664. FASTCALL
  15665. ExAcquireFastMutexUnsafe (
  15666. IN PFAST_MUTEX FastMutex
  15667. );
  15668. NTKERNELAPI
  15669. VOID
  15670. FASTCALL
  15671. ExReleaseFastMutexUnsafe (
  15672. IN PFAST_MUTEX FastMutex
  15673. );
  15674. #if defined(_IA64_) || defined(_AMD64_)
  15675. NTKERNELAPI
  15676. VOID
  15677. FASTCALL
  15678. ExAcquireFastMutex (
  15679. IN PFAST_MUTEX FastMutex
  15680. );
  15681. NTKERNELAPI
  15682. VOID
  15683. FASTCALL
  15684. ExReleaseFastMutex (
  15685. IN PFAST_MUTEX FastMutex
  15686. );
  15687. NTKERNELAPI
  15688. BOOLEAN
  15689. FASTCALL
  15690. ExTryToAcquireFastMutex (
  15691. IN PFAST_MUTEX FastMutex
  15692. );
  15693. #elif defined(_X86_)
  15694. NTHALAPI
  15695. VOID
  15696. FASTCALL
  15697. ExAcquireFastMutex (
  15698. IN PFAST_MUTEX FastMutex
  15699. );
  15700. NTHALAPI
  15701. VOID
  15702. FASTCALL
  15703. ExReleaseFastMutex (
  15704. IN PFAST_MUTEX FastMutex
  15705. );
  15706. NTHALAPI
  15707. BOOLEAN
  15708. FASTCALL
  15709. ExTryToAcquireFastMutex (
  15710. IN PFAST_MUTEX FastMutex
  15711. );
  15712. #else
  15713. #error "Target architecture not defined"
  15714. #endif
  15715. //
  15716. #if defined(_WIN64)
  15717. #define ExInterlockedAddLargeStatistic(Addend, Increment) \
  15718. (VOID) InterlockedAdd64(&(Addend)->QuadPart, Increment)
  15719. #else
  15720. #ifdef __cplusplus
  15721. extern "C" {
  15722. #endif
  15723. LONG
  15724. _InterlockedAddLargeStatistic (
  15725. IN PLONGLONG Addend,
  15726. IN ULONG Increment
  15727. );
  15728. #ifdef __cplusplus
  15729. }
  15730. #endif
  15731. #pragma intrinsic (_InterlockedAddLargeStatistic)
  15732. #define ExInterlockedAddLargeStatistic(Addend,Increment) \
  15733. (VOID) _InterlockedAddLargeStatistic ((PLONGLONG)&(Addend)->QuadPart, Increment)
  15734. #endif
  15735. // end_ntndis
  15736. NTKERNELAPI
  15737. LARGE_INTEGER
  15738. ExInterlockedAddLargeInteger (
  15739. IN PLARGE_INTEGER Addend,
  15740. IN LARGE_INTEGER Increment,
  15741. IN PKSPIN_LOCK Lock
  15742. );
  15743. NTKERNELAPI
  15744. ULONG
  15745. FASTCALL
  15746. ExInterlockedAddUlong (
  15747. IN PULONG Addend,
  15748. IN ULONG Increment,
  15749. IN PKSPIN_LOCK Lock
  15750. );
  15751. #if defined(_AMD64_) || defined(_AXP64_) || defined(_IA64_)
  15752. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  15753. InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
  15754. #elif defined(_ALPHA_)
  15755. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  15756. ExpInterlockedCompareExchange64(Destination, Exchange, Comperand)
  15757. #else
  15758. #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
  15759. ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
  15760. #endif
  15761. NTKERNELAPI
  15762. PLIST_ENTRY
  15763. FASTCALL
  15764. ExInterlockedInsertHeadList (
  15765. IN PLIST_ENTRY ListHead,
  15766. IN PLIST_ENTRY ListEntry,
  15767. IN PKSPIN_LOCK Lock
  15768. );
  15769. NTKERNELAPI
  15770. PLIST_ENTRY
  15771. FASTCALL
  15772. ExInterlockedInsertTailList (
  15773. IN PLIST_ENTRY ListHead,
  15774. IN PLIST_ENTRY ListEntry,
  15775. IN PKSPIN_LOCK Lock
  15776. );
  15777. NTKERNELAPI
  15778. PLIST_ENTRY
  15779. FASTCALL
  15780. ExInterlockedRemoveHeadList (
  15781. IN PLIST_ENTRY ListHead,
  15782. IN PKSPIN_LOCK Lock
  15783. );
  15784. NTKERNELAPI
  15785. PSINGLE_LIST_ENTRY
  15786. FASTCALL
  15787. ExInterlockedPopEntryList (
  15788. IN PSINGLE_LIST_ENTRY ListHead,
  15789. IN PKSPIN_LOCK Lock
  15790. );
  15791. NTKERNELAPI
  15792. PSINGLE_LIST_ENTRY
  15793. FASTCALL
  15794. ExInterlockedPushEntryList (
  15795. IN PSINGLE_LIST_ENTRY ListHead,
  15796. IN PSINGLE_LIST_ENTRY ListEntry,
  15797. IN PKSPIN_LOCK Lock
  15798. );
  15799. //
  15800. // Define interlocked sequenced listhead functions.
  15801. //
  15802. // A sequenced interlocked list is a singly linked list with a header that
  15803. // contains the current depth and a sequence number. Each time an entry is
  15804. // inserted or removed from the list the depth is updated and the sequence
  15805. // number is incremented. This enables AMD64, IA64, and Pentium and later
  15806. // machines to insert and remove from the list without the use of spinlocks.
  15807. //
  15808. #if !defined(_WINBASE_)
  15809. /*++
  15810. Routine Description:
  15811. This function initializes a sequenced singly linked listhead.
  15812. Arguments:
  15813. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  15814. Return Value:
  15815. None.
  15816. --*/
  15817. #if defined(_WIN64) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  15818. NTKERNELAPI
  15819. VOID
  15820. InitializeSListHead (
  15821. IN PSLIST_HEADER SListHead
  15822. );
  15823. #else
  15824. __inline
  15825. VOID
  15826. InitializeSListHead (
  15827. IN PSLIST_HEADER SListHead
  15828. )
  15829. {
  15830. #ifdef _WIN64
  15831. //
  15832. // Slist headers must be 16 byte aligned.
  15833. //
  15834. if ((ULONG_PTR) SListHead & 0x0f) {
  15835. DbgPrint( "InitializeSListHead unaligned Slist header. Address = %p, Caller = %p\n", SListHead, _ReturnAddress());
  15836. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  15837. }
  15838. #endif
  15839. SListHead->Alignment = 0;
  15840. //
  15841. // For IA-64 we save the region number of the elements of the list in a
  15842. // separate field. This imposes the requirement that all elements stored
  15843. // in the list are from the same region.
  15844. #if defined(_IA64_)
  15845. SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
  15846. #elif defined(_AMD64_)
  15847. SListHead->Region = 0;
  15848. #endif
  15849. return;
  15850. }
  15851. #endif
  15852. #endif // !defined(_WINBASE_)
  15853. #define ExInitializeSListHead InitializeSListHead
  15854. PSLIST_ENTRY
  15855. FirstEntrySList (
  15856. IN const SLIST_HEADER *SListHead
  15857. );
  15858. /*++
  15859. Routine Description:
  15860. This function queries the current number of entries contained in a
  15861. sequenced single linked list.
  15862. Arguments:
  15863. SListHead - Supplies a pointer to the sequenced listhead which is
  15864. be queried.
  15865. Return Value:
  15866. The current number of entries in the sequenced singly linked list is
  15867. returned as the function value.
  15868. --*/
  15869. #if defined(_WIN64)
  15870. #if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  15871. NTKERNELAPI
  15872. USHORT
  15873. ExQueryDepthSList (
  15874. IN PSLIST_HEADER SListHead
  15875. );
  15876. #else
  15877. __inline
  15878. USHORT
  15879. ExQueryDepthSList (
  15880. IN PSLIST_HEADER SListHead
  15881. )
  15882. {
  15883. return (USHORT)(SListHead->Alignment & 0xffff);
  15884. }
  15885. #endif
  15886. #else
  15887. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  15888. #endif
  15889. #if defined(_WIN64)
  15890. #define ExInterlockedPopEntrySList(Head, Lock) \
  15891. ExpInterlockedPopEntrySList(Head)
  15892. #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
  15893. ExpInterlockedPushEntrySList(Head, Entry)
  15894. #define ExInterlockedFlushSList(Head) \
  15895. ExpInterlockedFlushSList(Head)
  15896. #if !defined(_WINBASE_)
  15897. #define InterlockedPopEntrySList(Head) \
  15898. ExpInterlockedPopEntrySList(Head)
  15899. #define InterlockedPushEntrySList(Head, Entry) \
  15900. ExpInterlockedPushEntrySList(Head, Entry)
  15901. #define InterlockedFlushSList(Head) \
  15902. ExpInterlockedFlushSList(Head)
  15903. #define QueryDepthSList(Head) \
  15904. ExQueryDepthSList(Head)
  15905. #endif // !defined(_WINBASE_)
  15906. NTKERNELAPI
  15907. PSLIST_ENTRY
  15908. ExpInterlockedPopEntrySList (
  15909. IN PSLIST_HEADER ListHead
  15910. );
  15911. NTKERNELAPI
  15912. PSLIST_ENTRY
  15913. ExpInterlockedPushEntrySList (
  15914. IN PSLIST_HEADER ListHead,
  15915. IN PSLIST_ENTRY ListEntry
  15916. );
  15917. NTKERNELAPI
  15918. PSLIST_ENTRY
  15919. ExpInterlockedFlushSList (
  15920. IN PSLIST_HEADER ListHead
  15921. );
  15922. #else
  15923. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  15924. NTKERNELAPI
  15925. PSLIST_ENTRY
  15926. FASTCALL
  15927. ExInterlockedPopEntrySList (
  15928. IN PSLIST_HEADER ListHead,
  15929. IN PKSPIN_LOCK Lock
  15930. );
  15931. NTKERNELAPI
  15932. PSLIST_ENTRY
  15933. FASTCALL
  15934. ExInterlockedPushEntrySList (
  15935. IN PSLIST_HEADER ListHead,
  15936. IN PSLIST_ENTRY ListEntry,
  15937. IN PKSPIN_LOCK Lock
  15938. );
  15939. #else
  15940. #define ExInterlockedPopEntrySList(ListHead, Lock) \
  15941. InterlockedPopEntrySList(ListHead)
  15942. #define ExInterlockedPushEntrySList(ListHead, ListEntry, Lock) \
  15943. InterlockedPushEntrySList(ListHead, ListEntry)
  15944. #endif
  15945. NTKERNELAPI
  15946. PSLIST_ENTRY
  15947. FASTCALL
  15948. ExInterlockedFlushSList (
  15949. IN PSLIST_HEADER ListHead
  15950. );
  15951. #if !defined(_WINBASE_)
  15952. NTKERNELAPI
  15953. PSLIST_ENTRY
  15954. FASTCALL
  15955. InterlockedPopEntrySList (
  15956. IN PSLIST_HEADER ListHead
  15957. );
  15958. NTKERNELAPI
  15959. PSLIST_ENTRY
  15960. FASTCALL
  15961. InterlockedPushEntrySList (
  15962. IN PSLIST_HEADER ListHead,
  15963. IN PSLIST_ENTRY ListEntry
  15964. );
  15965. #define InterlockedFlushSList(Head) \
  15966. ExInterlockedFlushSList(Head)
  15967. #define QueryDepthSList(Head) \
  15968. ExQueryDepthSList(Head)
  15969. #endif // !defined(_WINBASE_)
  15970. #endif // defined(_WIN64)
  15971. // end_ntddk end_wdm end_ntosp
  15972. PSLIST_ENTRY
  15973. FASTCALL
  15974. InterlockedPushListSList (
  15975. IN PSLIST_HEADER ListHead,
  15976. IN PSLIST_ENTRY List,
  15977. IN PSLIST_ENTRY ListEnd,
  15978. IN ULONG Count
  15979. );
  15980. //
  15981. // Define interlocked lookaside list structure and allocation functions.
  15982. //
  15983. VOID
  15984. ExAdjustLookasideDepth (
  15985. VOID
  15986. );
  15987. // begin_ntddk begin_wdm begin_ntosp
  15988. typedef
  15989. PVOID
  15990. (*PALLOCATE_FUNCTION) (
  15991. IN POOL_TYPE PoolType,
  15992. IN SIZE_T NumberOfBytes,
  15993. IN ULONG Tag
  15994. );
  15995. typedef
  15996. VOID
  15997. (*PFREE_FUNCTION) (
  15998. IN PVOID Buffer
  15999. );
  16000. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  16001. typedef struct _GENERAL_LOOKASIDE {
  16002. #else
  16003. typedef struct DECLSPEC_CACHEALIGN _GENERAL_LOOKASIDE {
  16004. #endif
  16005. SLIST_HEADER ListHead;
  16006. USHORT Depth;
  16007. USHORT MaximumDepth;
  16008. ULONG TotalAllocates;
  16009. union {
  16010. ULONG AllocateMisses;
  16011. ULONG AllocateHits;
  16012. };
  16013. ULONG TotalFrees;
  16014. union {
  16015. ULONG FreeMisses;
  16016. ULONG FreeHits;
  16017. };
  16018. POOL_TYPE Type;
  16019. ULONG Tag;
  16020. ULONG Size;
  16021. PALLOCATE_FUNCTION Allocate;
  16022. PFREE_FUNCTION Free;
  16023. LIST_ENTRY ListEntry;
  16024. ULONG LastTotalAllocates;
  16025. union {
  16026. ULONG LastAllocateMisses;
  16027. ULONG LastAllocateHits;
  16028. };
  16029. ULONG Future[2];
  16030. } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
  16031. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  16032. typedef struct _NPAGED_LOOKASIDE_LIST {
  16033. #else
  16034. typedef struct DECLSPEC_CACHEALIGN _NPAGED_LOOKASIDE_LIST {
  16035. #endif
  16036. GENERAL_LOOKASIDE L;
  16037. #if !defined(_AMD64_) && !defined(_IA64_)
  16038. KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
  16039. #endif
  16040. } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
  16041. NTKERNELAPI
  16042. VOID
  16043. ExInitializeNPagedLookasideList (
  16044. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  16045. IN PALLOCATE_FUNCTION Allocate,
  16046. IN PFREE_FUNCTION Free,
  16047. IN ULONG Flags,
  16048. IN SIZE_T Size,
  16049. IN ULONG Tag,
  16050. IN USHORT Depth
  16051. );
  16052. NTKERNELAPI
  16053. VOID
  16054. ExDeleteNPagedLookasideList (
  16055. IN PNPAGED_LOOKASIDE_LIST Lookaside
  16056. );
  16057. __inline
  16058. PVOID
  16059. ExAllocateFromNPagedLookasideList(
  16060. IN PNPAGED_LOOKASIDE_LIST Lookaside
  16061. )
  16062. /*++
  16063. Routine Description:
  16064. This function removes (pops) the first entry from the specified
  16065. nonpaged lookaside list.
  16066. Arguments:
  16067. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  16068. Return Value:
  16069. If an entry is removed from the specified lookaside list, then the
  16070. address of the entry is returned as the function value. Otherwise,
  16071. NULL is returned.
  16072. --*/
  16073. {
  16074. PVOID Entry;
  16075. Lookaside->L.TotalAllocates += 1;
  16076. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  16077. Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
  16078. &Lookaside->Lock__ObsoleteButDoNotDelete);
  16079. #else
  16080. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  16081. #endif
  16082. if (Entry == NULL) {
  16083. Lookaside->L.AllocateMisses += 1;
  16084. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  16085. Lookaside->L.Size,
  16086. Lookaside->L.Tag);
  16087. }
  16088. return Entry;
  16089. }
  16090. __inline
  16091. VOID
  16092. ExFreeToNPagedLookasideList(
  16093. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  16094. IN PVOID Entry
  16095. )
  16096. /*++
  16097. Routine Description:
  16098. This function inserts (pushes) the specified entry into the specified
  16099. nonpaged lookaside list.
  16100. Arguments:
  16101. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  16102. Entry - Supples a pointer to the entry that is inserted in the
  16103. lookaside list.
  16104. Return Value:
  16105. None.
  16106. --*/
  16107. {
  16108. Lookaside->L.TotalFrees += 1;
  16109. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  16110. Lookaside->L.FreeMisses += 1;
  16111. (Lookaside->L.Free)(Entry);
  16112. } else {
  16113. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  16114. ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
  16115. (PSLIST_ENTRY)Entry,
  16116. &Lookaside->Lock__ObsoleteButDoNotDelete);
  16117. #else
  16118. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  16119. (PSLIST_ENTRY)Entry);
  16120. #endif
  16121. }
  16122. return;
  16123. }
  16124. // end_ntndis
  16125. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  16126. typedef struct _PAGED_LOOKASIDE_LIST {
  16127. #else
  16128. typedef struct DECLSPEC_CACHEALIGN _PAGED_LOOKASIDE_LIST {
  16129. #endif
  16130. GENERAL_LOOKASIDE L;
  16131. #if !defined(_AMD64_) && !defined(_IA64_)
  16132. FAST_MUTEX Lock__ObsoleteButDoNotDelete;
  16133. #endif
  16134. } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
  16135. NTKERNELAPI
  16136. VOID
  16137. ExInitializePagedLookasideList (
  16138. IN PPAGED_LOOKASIDE_LIST Lookaside,
  16139. IN PALLOCATE_FUNCTION Allocate,
  16140. IN PFREE_FUNCTION Free,
  16141. IN ULONG Flags,
  16142. IN SIZE_T Size,
  16143. IN ULONG Tag,
  16144. IN USHORT Depth
  16145. );
  16146. NTKERNELAPI
  16147. VOID
  16148. ExDeletePagedLookasideList (
  16149. IN PPAGED_LOOKASIDE_LIST Lookaside
  16150. );
  16151. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  16152. NTKERNELAPI
  16153. PVOID
  16154. ExAllocateFromPagedLookasideList(
  16155. IN PPAGED_LOOKASIDE_LIST Lookaside
  16156. );
  16157. #else
  16158. __inline
  16159. PVOID
  16160. ExAllocateFromPagedLookasideList(
  16161. IN PPAGED_LOOKASIDE_LIST Lookaside
  16162. )
  16163. /*++
  16164. Routine Description:
  16165. This function removes (pops) the first entry from the specified
  16166. paged lookaside list.
  16167. Arguments:
  16168. Lookaside - Supplies a pointer to a paged lookaside list structure.
  16169. Return Value:
  16170. If an entry is removed from the specified lookaside list, then the
  16171. address of the entry is returned as the function value. Otherwise,
  16172. NULL is returned.
  16173. --*/
  16174. {
  16175. PVOID Entry;
  16176. Lookaside->L.TotalAllocates += 1;
  16177. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  16178. if (Entry == NULL) {
  16179. Lookaside->L.AllocateMisses += 1;
  16180. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  16181. Lookaside->L.Size,
  16182. Lookaside->L.Tag);
  16183. }
  16184. return Entry;
  16185. }
  16186. #endif
  16187. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  16188. NTKERNELAPI
  16189. VOID
  16190. ExFreeToPagedLookasideList(
  16191. IN PPAGED_LOOKASIDE_LIST Lookaside,
  16192. IN PVOID Entry
  16193. );
  16194. #else
  16195. __inline
  16196. VOID
  16197. ExFreeToPagedLookasideList(
  16198. IN PPAGED_LOOKASIDE_LIST Lookaside,
  16199. IN PVOID Entry
  16200. )
  16201. /*++
  16202. Routine Description:
  16203. This function inserts (pushes) the specified entry into the specified
  16204. paged lookaside list.
  16205. Arguments:
  16206. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  16207. Entry - Supples a pointer to the entry that is inserted in the
  16208. lookaside list.
  16209. Return Value:
  16210. None.
  16211. --*/
  16212. {
  16213. Lookaside->L.TotalFrees += 1;
  16214. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  16215. Lookaside->L.FreeMisses += 1;
  16216. (Lookaside->L.Free)(Entry);
  16217. } else {
  16218. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  16219. (PSLIST_ENTRY)Entry);
  16220. }
  16221. return;
  16222. }
  16223. #endif
  16224. NTKERNELAPI
  16225. VOID
  16226. NTAPI
  16227. ProbeForRead(
  16228. IN CONST VOID *Address,
  16229. IN SIZE_T Length,
  16230. IN ULONG Alignment
  16231. );
  16232. //
  16233. // Common probe for write functions.
  16234. //
  16235. NTKERNELAPI
  16236. VOID
  16237. NTAPI
  16238. ProbeForWrite (
  16239. IN PVOID Address,
  16240. IN SIZE_T Length,
  16241. IN ULONG Alignment
  16242. );
  16243. //
  16244. // Worker Thread
  16245. //
  16246. typedef enum _WORK_QUEUE_TYPE {
  16247. CriticalWorkQueue,
  16248. DelayedWorkQueue,
  16249. HyperCriticalWorkQueue,
  16250. MaximumWorkQueue
  16251. } WORK_QUEUE_TYPE;
  16252. typedef
  16253. VOID
  16254. (*PWORKER_THREAD_ROUTINE)(
  16255. IN PVOID Parameter
  16256. );
  16257. typedef struct _WORK_QUEUE_ITEM {
  16258. LIST_ENTRY List;
  16259. PWORKER_THREAD_ROUTINE WorkerRoutine;
  16260. PVOID Parameter;
  16261. } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
  16262. #if PRAGMA_DEPRECATED_DDK
  16263. #pragma deprecated(ExInitializeWorkItem) // Use IoAllocateWorkItem
  16264. #endif
  16265. #define ExInitializeWorkItem(Item, Routine, Context) \
  16266. (Item)->WorkerRoutine = (Routine); \
  16267. (Item)->Parameter = (Context); \
  16268. (Item)->List.Flink = NULL;
  16269. DECLSPEC_DEPRECATED_DDK // Use IoQueueWorkItem
  16270. NTKERNELAPI
  16271. VOID
  16272. ExQueueWorkItem(
  16273. IN PWORK_QUEUE_ITEM WorkItem,
  16274. IN WORK_QUEUE_TYPE QueueType
  16275. );
  16276. NTKERNELAPI
  16277. BOOLEAN
  16278. ExIsProcessorFeaturePresent(
  16279. ULONG ProcessorFeature
  16280. );
  16281. //
  16282. // Zone Allocation
  16283. //
  16284. typedef struct _ZONE_SEGMENT_HEADER {
  16285. SINGLE_LIST_ENTRY SegmentList;
  16286. PVOID Reserved;
  16287. } ZONE_SEGMENT_HEADER, *PZONE_SEGMENT_HEADER;
  16288. typedef struct _ZONE_HEADER {
  16289. SINGLE_LIST_ENTRY FreeList;
  16290. SINGLE_LIST_ENTRY SegmentList;
  16291. ULONG BlockSize;
  16292. ULONG TotalSegmentSize;
  16293. } ZONE_HEADER, *PZONE_HEADER;
  16294. DECLSPEC_DEPRECATED_DDK
  16295. NTKERNELAPI
  16296. NTSTATUS
  16297. ExInitializeZone(
  16298. IN PZONE_HEADER Zone,
  16299. IN ULONG BlockSize,
  16300. IN PVOID InitialSegment,
  16301. IN ULONG InitialSegmentSize
  16302. );
  16303. DECLSPEC_DEPRECATED_DDK
  16304. NTKERNELAPI
  16305. NTSTATUS
  16306. ExExtendZone(
  16307. IN PZONE_HEADER Zone,
  16308. IN PVOID Segment,
  16309. IN ULONG SegmentSize
  16310. );
  16311. DECLSPEC_DEPRECATED_DDK
  16312. NTKERNELAPI
  16313. NTSTATUS
  16314. ExInterlockedExtendZone(
  16315. IN PZONE_HEADER Zone,
  16316. IN PVOID Segment,
  16317. IN ULONG SegmentSize,
  16318. IN PKSPIN_LOCK Lock
  16319. );
  16320. //++
  16321. //
  16322. // PVOID
  16323. // ExAllocateFromZone(
  16324. // IN PZONE_HEADER Zone
  16325. // )
  16326. //
  16327. // Routine Description:
  16328. //
  16329. // This routine removes an entry from the zone and returns a pointer to it.
  16330. //
  16331. // Arguments:
  16332. //
  16333. // Zone - Pointer to the zone header controlling the storage from which the
  16334. // entry is to be allocated.
  16335. //
  16336. // Return Value:
  16337. //
  16338. // The function value is a pointer to the storage allocated from the zone.
  16339. //
  16340. //--
  16341. #if PRAGMA_DEPRECATED_DDK
  16342. #pragma deprecated(ExAllocateFromZone)
  16343. #endif
  16344. #define ExAllocateFromZone(Zone) \
  16345. (PVOID)((Zone)->FreeList.Next); \
  16346. if ( (Zone)->FreeList.Next ) (Zone)->FreeList.Next = (Zone)->FreeList.Next->Next
  16347. //++
  16348. //
  16349. // PVOID
  16350. // ExFreeToZone(
  16351. // IN PZONE_HEADER Zone,
  16352. // IN PVOID Block
  16353. // )
  16354. //
  16355. // Routine Description:
  16356. //
  16357. // This routine places the specified block of storage back onto the free
  16358. // list in the specified zone.
  16359. //
  16360. // Arguments:
  16361. //
  16362. // Zone - Pointer to the zone header controlling the storage to which the
  16363. // entry is to be inserted.
  16364. //
  16365. // Block - Pointer to the block of storage to be freed back to the zone.
  16366. //
  16367. // Return Value:
  16368. //
  16369. // Pointer to previous block of storage that was at the head of the free
  16370. // list. NULL implies the zone went from no available free blocks to
  16371. // at least one free block.
  16372. //
  16373. //--
  16374. #if PRAGMA_DEPRECATED_DDK
  16375. #pragma deprecated(ExFreeToZone)
  16376. #endif
  16377. #define ExFreeToZone(Zone,Block) \
  16378. ( ((PSINGLE_LIST_ENTRY)(Block))->Next = (Zone)->FreeList.Next, \
  16379. (Zone)->FreeList.Next = ((PSINGLE_LIST_ENTRY)(Block)), \
  16380. ((PSINGLE_LIST_ENTRY)(Block))->Next \
  16381. )
  16382. //++
  16383. //
  16384. // BOOLEAN
  16385. // ExIsFullZone(
  16386. // IN PZONE_HEADER Zone
  16387. // )
  16388. //
  16389. // Routine Description:
  16390. //
  16391. // This routine determines if the specified zone is full or not. A zone
  16392. // is considered full if the free list is empty.
  16393. //
  16394. // Arguments:
  16395. //
  16396. // Zone - Pointer to the zone header to be tested.
  16397. //
  16398. // Return Value:
  16399. //
  16400. // TRUE if the zone is full and FALSE otherwise.
  16401. //
  16402. //--
  16403. #if PRAGMA_DEPRECATED_DDK
  16404. #pragma deprecated(ExIsFullZone)
  16405. #endif
  16406. #define ExIsFullZone(Zone) \
  16407. ( (Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY)NULL )
  16408. //++
  16409. //
  16410. // PVOID
  16411. // ExInterlockedAllocateFromZone(
  16412. // IN PZONE_HEADER Zone,
  16413. // IN PKSPIN_LOCK Lock
  16414. // )
  16415. //
  16416. // Routine Description:
  16417. //
  16418. // This routine removes an entry from the zone and returns a pointer to it.
  16419. // The removal is performed with the specified lock owned for the sequence
  16420. // to make it MP-safe.
  16421. //
  16422. // Arguments:
  16423. //
  16424. // Zone - Pointer to the zone header controlling the storage from which the
  16425. // entry is to be allocated.
  16426. //
  16427. // Lock - Pointer to the spin lock which should be obtained before removing
  16428. // the entry from the allocation list. The lock is released before
  16429. // returning to the caller.
  16430. //
  16431. // Return Value:
  16432. //
  16433. // The function value is a pointer to the storage allocated from the zone.
  16434. //
  16435. //--
  16436. #if PRAGMA_DEPRECATED_DDK
  16437. #pragma deprecated(ExInterlockedAllocateFromZone)
  16438. #endif
  16439. #define ExInterlockedAllocateFromZone(Zone,Lock) \
  16440. (PVOID) ExInterlockedPopEntryList( &(Zone)->FreeList, Lock )
  16441. //++
  16442. //
  16443. // PVOID
  16444. // ExInterlockedFreeToZone(
  16445. // IN PZONE_HEADER Zone,
  16446. // IN PVOID Block,
  16447. // IN PKSPIN_LOCK Lock
  16448. // )
  16449. //
  16450. // Routine Description:
  16451. //
  16452. // This routine places the specified block of storage back onto the free
  16453. // list in the specified zone. The insertion is performed with the lock
  16454. // owned for the sequence to make it MP-safe.
  16455. //
  16456. // Arguments:
  16457. //
  16458. // Zone - Pointer to the zone header controlling the storage to which the
  16459. // entry is to be inserted.
  16460. //
  16461. // Block - Pointer to the block of storage to be freed back to the zone.
  16462. //
  16463. // Lock - Pointer to the spin lock which should be obtained before inserting
  16464. // the entry onto the free list. The lock is released before returning
  16465. // to the caller.
  16466. //
  16467. // Return Value:
  16468. //
  16469. // Pointer to previous block of storage that was at the head of the free
  16470. // list. NULL implies the zone went from no available free blocks to
  16471. // at least one free block.
  16472. //
  16473. //--
  16474. #if PRAGMA_DEPRECATED_DDK
  16475. #pragma deprecated(ExInterlockedFreeToZone)
  16476. #endif
  16477. #define ExInterlockedFreeToZone(Zone,Block,Lock) \
  16478. ExInterlockedPushEntryList( &(Zone)->FreeList, ((PSINGLE_LIST_ENTRY) (Block)), Lock )
  16479. //++
  16480. //
  16481. // BOOLEAN
  16482. // ExIsObjectInFirstZoneSegment(
  16483. // IN PZONE_HEADER Zone,
  16484. // IN PVOID Object
  16485. // )
  16486. //
  16487. // Routine Description:
  16488. //
  16489. // This routine determines if the specified pointer lives in the zone.
  16490. //
  16491. // Arguments:
  16492. //
  16493. // Zone - Pointer to the zone header controlling the storage to which the
  16494. // object may belong.
  16495. //
  16496. // Object - Pointer to the object in question.
  16497. //
  16498. // Return Value:
  16499. //
  16500. // TRUE if the Object came from the first segment of zone.
  16501. //
  16502. //--
  16503. #if PRAGMA_DEPRECATED_DDK
  16504. #pragma deprecated(ExIsObjectInFirstZoneSegment)
  16505. #endif
  16506. #define ExIsObjectInFirstZoneSegment(Zone,Object) ((BOOLEAN) \
  16507. (((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
  16508. ((PUCHAR)(Object) < (PUCHAR)(Zone)->SegmentList.Next + \
  16509. (Zone)->TotalSegmentSize)) \
  16510. )
  16511. //
  16512. // Define executive resource data structures.
  16513. //
  16514. typedef ULONG_PTR ERESOURCE_THREAD;
  16515. typedef ERESOURCE_THREAD *PERESOURCE_THREAD;
  16516. typedef struct _OWNER_ENTRY {
  16517. ERESOURCE_THREAD OwnerThread;
  16518. union {
  16519. LONG OwnerCount;
  16520. ULONG TableSize;
  16521. };
  16522. } OWNER_ENTRY, *POWNER_ENTRY;
  16523. typedef struct _ERESOURCE {
  16524. LIST_ENTRY SystemResourcesList;
  16525. POWNER_ENTRY OwnerTable;
  16526. SHORT ActiveCount;
  16527. USHORT Flag;
  16528. PKSEMAPHORE SharedWaiters;
  16529. PKEVENT ExclusiveWaiters;
  16530. OWNER_ENTRY OwnerThreads[2];
  16531. ULONG ContentionCount;
  16532. USHORT NumberOfSharedWaiters;
  16533. USHORT NumberOfExclusiveWaiters;
  16534. union {
  16535. PVOID Address;
  16536. ULONG_PTR CreatorBackTraceIndex;
  16537. };
  16538. KSPIN_LOCK SpinLock;
  16539. } ERESOURCE, *PERESOURCE;
  16540. //
  16541. // Values for ERESOURCE.Flag
  16542. //
  16543. #define ResourceNeverExclusive 0x10
  16544. #define ResourceReleaseByOtherThread 0x20
  16545. #define ResourceOwnedExclusive 0x80
  16546. #define RESOURCE_HASH_TABLE_SIZE 64
  16547. typedef struct _RESOURCE_HASH_ENTRY {
  16548. LIST_ENTRY ListEntry;
  16549. PVOID Address;
  16550. ULONG ContentionCount;
  16551. ULONG Number;
  16552. } RESOURCE_HASH_ENTRY, *PRESOURCE_HASH_ENTRY;
  16553. typedef struct _RESOURCE_PERFORMANCE_DATA {
  16554. ULONG ActiveResourceCount;
  16555. ULONG TotalResourceCount;
  16556. ULONG ExclusiveAcquire;
  16557. ULONG SharedFirstLevel;
  16558. ULONG SharedSecondLevel;
  16559. ULONG StarveFirstLevel;
  16560. ULONG StarveSecondLevel;
  16561. ULONG WaitForExclusive;
  16562. ULONG OwnerTableExpands;
  16563. ULONG MaximumTableExpand;
  16564. LIST_ENTRY HashTable[RESOURCE_HASH_TABLE_SIZE];
  16565. } RESOURCE_PERFORMANCE_DATA, *PRESOURCE_PERFORMANCE_DATA;
  16566. //
  16567. // Define executive resource function prototypes.
  16568. //
  16569. NTKERNELAPI
  16570. NTSTATUS
  16571. ExInitializeResourceLite(
  16572. IN PERESOURCE Resource
  16573. );
  16574. NTKERNELAPI
  16575. NTSTATUS
  16576. ExReinitializeResourceLite(
  16577. IN PERESOURCE Resource
  16578. );
  16579. NTKERNELAPI
  16580. BOOLEAN
  16581. ExAcquireResourceSharedLite(
  16582. IN PERESOURCE Resource,
  16583. IN BOOLEAN Wait
  16584. );
  16585. NTKERNELAPI
  16586. BOOLEAN
  16587. ExAcquireResourceExclusiveLite(
  16588. IN PERESOURCE Resource,
  16589. IN BOOLEAN Wait
  16590. );
  16591. NTKERNELAPI
  16592. BOOLEAN
  16593. ExAcquireSharedStarveExclusive(
  16594. IN PERESOURCE Resource,
  16595. IN BOOLEAN Wait
  16596. );
  16597. NTKERNELAPI
  16598. BOOLEAN
  16599. ExAcquireSharedWaitForExclusive(
  16600. IN PERESOURCE Resource,
  16601. IN BOOLEAN Wait
  16602. );
  16603. NTKERNELAPI
  16604. BOOLEAN
  16605. ExTryToAcquireResourceExclusiveLite(
  16606. IN PERESOURCE Resource
  16607. );
  16608. //
  16609. // VOID
  16610. // ExReleaseResource(
  16611. // IN PERESOURCE Resource
  16612. // );
  16613. //
  16614. #if PRAGMA_DEPRECATED_DDK
  16615. #pragma deprecated(ExReleaseResource) // Use ExReleaseResourceLite
  16616. #endif
  16617. #define ExReleaseResource(R) (ExReleaseResourceLite(R))
  16618. NTKERNELAPI
  16619. VOID
  16620. FASTCALL
  16621. ExReleaseResourceLite(
  16622. IN PERESOURCE Resource
  16623. );
  16624. NTKERNELAPI
  16625. VOID
  16626. ExReleaseResourceForThreadLite(
  16627. IN PERESOURCE Resource,
  16628. IN ERESOURCE_THREAD ResourceThreadId
  16629. );
  16630. NTKERNELAPI
  16631. VOID
  16632. ExSetResourceOwnerPointer(
  16633. IN PERESOURCE Resource,
  16634. IN PVOID OwnerPointer
  16635. );
  16636. NTKERNELAPI
  16637. VOID
  16638. ExConvertExclusiveToSharedLite(
  16639. IN PERESOURCE Resource
  16640. );
  16641. NTKERNELAPI
  16642. NTSTATUS
  16643. ExDeleteResourceLite (
  16644. IN PERESOURCE Resource
  16645. );
  16646. NTKERNELAPI
  16647. ULONG
  16648. ExGetExclusiveWaiterCount (
  16649. IN PERESOURCE Resource
  16650. );
  16651. NTKERNELAPI
  16652. ULONG
  16653. ExGetSharedWaiterCount (
  16654. IN PERESOURCE Resource
  16655. );
  16656. // end_ntddk end_wdm end_ntosp
  16657. NTKERNELAPI
  16658. VOID
  16659. ExDisableResourceBoostLite (
  16660. IN PERESOURCE Resource
  16661. );
  16662. #if DBG
  16663. VOID
  16664. ExCheckIfResourceOwned (
  16665. VOID
  16666. );
  16667. #endif
  16668. // begin_ntddk begin_wdm begin_ntosp
  16669. //
  16670. // ERESOURCE_THREAD
  16671. // ExGetCurrentResourceThread(
  16672. // );
  16673. //
  16674. #define ExGetCurrentResourceThread() ((ULONG_PTR)PsGetCurrentThread())
  16675. NTKERNELAPI
  16676. BOOLEAN
  16677. ExIsResourceAcquiredExclusiveLite (
  16678. IN PERESOURCE Resource
  16679. );
  16680. NTKERNELAPI
  16681. ULONG
  16682. ExIsResourceAcquiredSharedLite (
  16683. IN PERESOURCE Resource
  16684. );
  16685. //
  16686. // An acquired resource is always owned shared, as shared ownership is a subset
  16687. // of exclusive ownership.
  16688. //
  16689. #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
  16690. // end_wdm
  16691. //
  16692. // ntddk.h stole the entrypoints we wanted so fix them up here.
  16693. //
  16694. #if PRAGMA_DEPRECATED_DDK
  16695. #pragma deprecated(ExInitializeResource) // use ExInitializeResourceLite
  16696. #pragma deprecated(ExAcquireResourceShared) // use ExAcquireResourceSharedLite
  16697. #pragma deprecated(ExAcquireResourceExclusive) // use ExAcquireResourceExclusiveLite
  16698. #pragma deprecated(ExReleaseResourceForThread) // use ExReleaseResourceForThreadLite
  16699. #pragma deprecated(ExConvertExclusiveToShared) // use ExConvertExclusiveToSharedLite
  16700. #pragma deprecated(ExDeleteResource) // use ExDeleteResourceLite
  16701. #pragma deprecated(ExIsResourceAcquiredExclusive) // use ExIsResourceAcquiredExclusiveLite
  16702. #pragma deprecated(ExIsResourceAcquiredShared) // use ExIsResourceAcquiredSharedLite
  16703. #pragma deprecated(ExIsResourceAcquired) // use ExIsResourceAcquiredSharedLite
  16704. #endif
  16705. #define ExInitializeResource ExInitializeResourceLite
  16706. #define ExAcquireResourceShared ExAcquireResourceSharedLite
  16707. #define ExAcquireResourceExclusive ExAcquireResourceExclusiveLite
  16708. #define ExReleaseResourceForThread ExReleaseResourceForThreadLite
  16709. #define ExConvertExclusiveToShared ExConvertExclusiveToSharedLite
  16710. #define ExDeleteResource ExDeleteResourceLite
  16711. #define ExIsResourceAcquiredExclusive ExIsResourceAcquiredExclusiveLite
  16712. #define ExIsResourceAcquiredShared ExIsResourceAcquiredSharedLite
  16713. #define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
  16714. // end_ntddk end_ntosp
  16715. #define ExDisableResourceBoost ExDisableResourceBoostLite
  16716. //
  16717. // Rundown protection structure
  16718. //
  16719. typedef struct _EX_RUNDOWN_REF {
  16720. #define EX_RUNDOWN_ACTIVE 0x1
  16721. #define EX_RUNDOWN_COUNT_SHIFT 0x1
  16722. #define EX_RUNDOWN_COUNT_INC (1<<EX_RUNDOWN_COUNT_SHIFT)
  16723. union {
  16724. ULONG_PTR Count;
  16725. PVOID Ptr;
  16726. };
  16727. } EX_RUNDOWN_REF, *PEX_RUNDOWN_REF;
  16728. //
  16729. // Get previous mode
  16730. //
  16731. NTKERNELAPI
  16732. KPROCESSOR_MODE
  16733. ExGetPreviousMode(
  16734. VOID
  16735. );
  16736. //
  16737. // Raise status from kernel mode.
  16738. //
  16739. NTKERNELAPI
  16740. VOID
  16741. NTAPI
  16742. ExRaiseStatus (
  16743. IN NTSTATUS Status
  16744. );
  16745. // end_wdm
  16746. NTKERNELAPI
  16747. VOID
  16748. ExRaiseDatatypeMisalignment (
  16749. VOID
  16750. );
  16751. NTKERNELAPI
  16752. VOID
  16753. ExRaiseAccessViolation (
  16754. VOID
  16755. );
  16756. //
  16757. // Set timer resolution.
  16758. //
  16759. NTKERNELAPI
  16760. ULONG
  16761. ExSetTimerResolution (
  16762. IN ULONG DesiredTime,
  16763. IN BOOLEAN SetResolution
  16764. );
  16765. //
  16766. // Subtract time zone bias from system time to get local time.
  16767. //
  16768. NTKERNELAPI
  16769. VOID
  16770. ExSystemTimeToLocalTime (
  16771. IN PLARGE_INTEGER SystemTime,
  16772. OUT PLARGE_INTEGER LocalTime
  16773. );
  16774. //
  16775. // Add time zone bias to local time to get system time.
  16776. //
  16777. NTKERNELAPI
  16778. VOID
  16779. ExLocalTimeToSystemTime (
  16780. IN PLARGE_INTEGER LocalTime,
  16781. OUT PLARGE_INTEGER SystemTime
  16782. );
  16783. //
  16784. // Define the type for Callback function.
  16785. //
  16786. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  16787. typedef VOID (*PCALLBACK_FUNCTION ) (
  16788. IN PVOID CallbackContext,
  16789. IN PVOID Argument1,
  16790. IN PVOID Argument2
  16791. );
  16792. NTKERNELAPI
  16793. NTSTATUS
  16794. ExCreateCallback (
  16795. OUT PCALLBACK_OBJECT *CallbackObject,
  16796. IN POBJECT_ATTRIBUTES ObjectAttributes,
  16797. IN BOOLEAN Create,
  16798. IN BOOLEAN AllowMultipleCallbacks
  16799. );
  16800. NTKERNELAPI
  16801. PVOID
  16802. ExRegisterCallback (
  16803. IN PCALLBACK_OBJECT CallbackObject,
  16804. IN PCALLBACK_FUNCTION CallbackFunction,
  16805. IN PVOID CallbackContext
  16806. );
  16807. NTKERNELAPI
  16808. VOID
  16809. ExUnregisterCallback (
  16810. IN PVOID CallbackRegistration
  16811. );
  16812. NTKERNELAPI
  16813. VOID
  16814. ExNotifyCallback (
  16815. IN PVOID CallbackObject,
  16816. IN PVOID Argument1,
  16817. IN PVOID Argument2
  16818. );
  16819. //
  16820. // UUID Generation
  16821. //
  16822. typedef GUID UUID;
  16823. NTKERNELAPI
  16824. NTSTATUS
  16825. ExUuidCreate(
  16826. OUT UUID *Uuid
  16827. );
  16828. //
  16829. // suite support
  16830. //
  16831. NTKERNELAPI
  16832. BOOLEAN
  16833. ExVerifySuite(
  16834. SUITE_TYPE SuiteType
  16835. );
  16836. //
  16837. // Rundown Locks
  16838. //
  16839. NTKERNELAPI
  16840. VOID
  16841. FASTCALL
  16842. ExInitializeRundownProtection (
  16843. IN PEX_RUNDOWN_REF RunRef
  16844. );
  16845. NTKERNELAPI
  16846. VOID
  16847. FASTCALL
  16848. ExReInitializeRundownProtection (
  16849. IN PEX_RUNDOWN_REF RunRef
  16850. );
  16851. NTKERNELAPI
  16852. BOOLEAN
  16853. FASTCALL
  16854. ExAcquireRundownProtection (
  16855. IN PEX_RUNDOWN_REF RunRef
  16856. );
  16857. NTKERNELAPI
  16858. BOOLEAN
  16859. FASTCALL
  16860. ExAcquireRundownProtectionEx (
  16861. IN PEX_RUNDOWN_REF RunRef,
  16862. IN ULONG Count
  16863. );
  16864. NTKERNELAPI
  16865. VOID
  16866. FASTCALL
  16867. ExReleaseRundownProtection (
  16868. IN PEX_RUNDOWN_REF RunRef
  16869. );
  16870. NTKERNELAPI
  16871. VOID
  16872. FASTCALL
  16873. ExReleaseRundownProtectionEx (
  16874. IN PEX_RUNDOWN_REF RunRef,
  16875. IN ULONG Count
  16876. );
  16877. NTKERNELAPI
  16878. VOID
  16879. FASTCALL
  16880. ExRundownCompleted (
  16881. IN PEX_RUNDOWN_REF RunRef
  16882. );
  16883. NTKERNELAPI
  16884. VOID
  16885. FASTCALL
  16886. ExWaitForRundownProtectionRelease (
  16887. IN PEX_RUNDOWN_REF RunRef
  16888. );
  16889. //
  16890. // Security operation codes
  16891. //
  16892. typedef enum _SECURITY_OPERATION_CODE {
  16893. SetSecurityDescriptor,
  16894. QuerySecurityDescriptor,
  16895. DeleteSecurityDescriptor,
  16896. AssignSecurityDescriptor
  16897. } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
  16898. //
  16899. // Token Flags
  16900. //
  16901. // Flags that may be defined in the TokenFlags field of the token object,
  16902. // or in an ACCESS_STATE structure
  16903. //
  16904. #define TOKEN_HAS_TRAVERSE_PRIVILEGE 0x01
  16905. #define TOKEN_HAS_BACKUP_PRIVILEGE 0x02
  16906. #define TOKEN_HAS_RESTORE_PRIVILEGE 0x04
  16907. #define TOKEN_HAS_ADMIN_GROUP 0x08
  16908. #define TOKEN_IS_RESTRICTED 0x10
  16909. #define TOKEN_SESSION_NOT_REFERENCED 0x20
  16910. #define TOKEN_SANDBOX_INERT 0x40
  16911. #define TOKEN_HAS_IMPERSONATE_PRIVILEGE 0x80
  16912. //
  16913. // Data structure used to capture subject security context
  16914. // for access validations and auditing.
  16915. //
  16916. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  16917. // BY ALL EXCEPT THE SECURITY ROUTINES.
  16918. //
  16919. typedef struct _SECURITY_SUBJECT_CONTEXT {
  16920. PACCESS_TOKEN ClientToken;
  16921. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  16922. PACCESS_TOKEN PrimaryToken;
  16923. PVOID ProcessAuditId;
  16924. } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
  16925. ///////////////////////////////////////////////////////////////////////////////
  16926. // //
  16927. // ACCESS_STATE and related structures //
  16928. // //
  16929. ///////////////////////////////////////////////////////////////////////////////
  16930. //
  16931. // Initial Privilege Set - Room for three privileges, which should
  16932. // be enough for most applications. This structure exists so that
  16933. // it can be imbedded in an ACCESS_STATE structure. Use PRIVILEGE_SET
  16934. // for all other references to Privilege sets.
  16935. //
  16936. #define INITIAL_PRIVILEGE_COUNT 3
  16937. typedef struct _INITIAL_PRIVILEGE_SET {
  16938. ULONG PrivilegeCount;
  16939. ULONG Control;
  16940. LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
  16941. } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
  16942. //
  16943. // Combine the information that describes the state
  16944. // of an access-in-progress into a single structure
  16945. //
  16946. typedef struct _ACCESS_STATE {
  16947. LUID OperationID;
  16948. BOOLEAN SecurityEvaluated;
  16949. BOOLEAN GenerateAudit;
  16950. BOOLEAN GenerateOnClose;
  16951. BOOLEAN PrivilegesAllocated;
  16952. ULONG Flags;
  16953. ACCESS_MASK RemainingDesiredAccess;
  16954. ACCESS_MASK PreviouslyGrantedAccess;
  16955. ACCESS_MASK OriginalDesiredAccess;
  16956. SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
  16957. PSECURITY_DESCRIPTOR SecurityDescriptor;
  16958. PVOID AuxData;
  16959. union {
  16960. INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
  16961. PRIVILEGE_SET PrivilegeSet;
  16962. } Privileges;
  16963. BOOLEAN AuditPrivileges;
  16964. UNICODE_STRING ObjectName;
  16965. UNICODE_STRING ObjectTypeName;
  16966. } ACCESS_STATE, *PACCESS_STATE;
  16967. typedef struct _SE_EXPORTS {
  16968. //
  16969. // Privilege values
  16970. //
  16971. LUID SeCreateTokenPrivilege;
  16972. LUID SeAssignPrimaryTokenPrivilege;
  16973. LUID SeLockMemoryPrivilege;
  16974. LUID SeIncreaseQuotaPrivilege;
  16975. LUID SeUnsolicitedInputPrivilege;
  16976. LUID SeTcbPrivilege;
  16977. LUID SeSecurityPrivilege;
  16978. LUID SeTakeOwnershipPrivilege;
  16979. LUID SeLoadDriverPrivilege;
  16980. LUID SeCreatePagefilePrivilege;
  16981. LUID SeIncreaseBasePriorityPrivilege;
  16982. LUID SeSystemProfilePrivilege;
  16983. LUID SeSystemtimePrivilege;
  16984. LUID SeProfileSingleProcessPrivilege;
  16985. LUID SeCreatePermanentPrivilege;
  16986. LUID SeBackupPrivilege;
  16987. LUID SeRestorePrivilege;
  16988. LUID SeShutdownPrivilege;
  16989. LUID SeDebugPrivilege;
  16990. LUID SeAuditPrivilege;
  16991. LUID SeSystemEnvironmentPrivilege;
  16992. LUID SeChangeNotifyPrivilege;
  16993. LUID SeRemoteShutdownPrivilege;
  16994. //
  16995. // Universally defined Sids
  16996. //
  16997. PSID SeNullSid;
  16998. PSID SeWorldSid;
  16999. PSID SeLocalSid;
  17000. PSID SeCreatorOwnerSid;
  17001. PSID SeCreatorGroupSid;
  17002. //
  17003. // Nt defined Sids
  17004. //
  17005. PSID SeNtAuthoritySid;
  17006. PSID SeDialupSid;
  17007. PSID SeNetworkSid;
  17008. PSID SeBatchSid;
  17009. PSID SeInteractiveSid;
  17010. PSID SeLocalSystemSid;
  17011. PSID SeAliasAdminsSid;
  17012. PSID SeAliasUsersSid;
  17013. PSID SeAliasGuestsSid;
  17014. PSID SeAliasPowerUsersSid;
  17015. PSID SeAliasAccountOpsSid;
  17016. PSID SeAliasSystemOpsSid;
  17017. PSID SeAliasPrintOpsSid;
  17018. PSID SeAliasBackupOpsSid;
  17019. //
  17020. // New Sids defined for NT5
  17021. //
  17022. PSID SeAuthenticatedUsersSid;
  17023. PSID SeRestrictedSid;
  17024. PSID SeAnonymousLogonSid;
  17025. //
  17026. // New Privileges defined for NT5
  17027. //
  17028. LUID SeUndockPrivilege;
  17029. LUID SeSyncAgentPrivilege;
  17030. LUID SeEnableDelegationPrivilege;
  17031. //
  17032. // New Sids defined for post-Windows 2000
  17033. PSID SeLocalServiceSid;
  17034. PSID SeNetworkServiceSid;
  17035. //
  17036. // New Privileges defined for post-Windows 2000
  17037. //
  17038. LUID SeManageVolumePrivilege;
  17039. LUID SeImpersonatePrivilege;
  17040. LUID SeCreateGlobalPrivilege;
  17041. } SE_EXPORTS, *PSE_EXPORTS;
  17042. ///////////////////////////////////////////////////////////////////////////////
  17043. // //
  17044. // Logon session notification callback routines //
  17045. // //
  17046. ///////////////////////////////////////////////////////////////////////////////
  17047. //
  17048. // These callback routines are used to notify file systems that have
  17049. // registered of logon sessions being terminated, so they can cleanup state
  17050. // associated with this logon session
  17051. //
  17052. typedef NTSTATUS
  17053. (*PSE_LOGON_SESSION_TERMINATED_ROUTINE)(
  17054. IN PLUID LogonId);
  17055. //++
  17056. //
  17057. // ULONG
  17058. // SeLengthSid(
  17059. // IN PSID Sid
  17060. // );
  17061. //
  17062. // Routine Description:
  17063. //
  17064. // This routine computes the length of a SID.
  17065. //
  17066. // Arguments:
  17067. //
  17068. // Sid - Points to the SID whose length is to be returned.
  17069. //
  17070. // Return Value:
  17071. //
  17072. // The length, in bytes of the SID.
  17073. //
  17074. //--
  17075. #define SeLengthSid( Sid ) \
  17076. (8 + (4 * ((SID *)Sid)->SubAuthorityCount))
  17077. //
  17078. //VOID
  17079. //SeDeleteClientSecurity(
  17080. // IN PSECURITY_CLIENT_CONTEXT ClientContext
  17081. // )
  17082. //
  17083. ///*++
  17084. //
  17085. //Routine Description:
  17086. //
  17087. // This service deletes a client security context block,
  17088. // performing whatever cleanup might be necessary to do so. In
  17089. // particular, reference to any client token is removed.
  17090. //
  17091. //Arguments:
  17092. //
  17093. // ClientContext - Points to the client security context block to be
  17094. // deleted.
  17095. //
  17096. //
  17097. //Return Value:
  17098. //
  17099. //
  17100. //
  17101. //--*/
  17102. //--
  17103. // begin_ntosp
  17104. #define SeDeleteClientSecurity(C) { \
  17105. if (SeTokenType((C)->ClientToken) == TokenPrimary) { \
  17106. PsDereferencePrimaryToken( (C)->ClientToken ); \
  17107. } else { \
  17108. PsDereferenceImpersonationToken( (C)->ClientToken ); \
  17109. } \
  17110. }
  17111. //++
  17112. //VOID
  17113. //SeStopImpersonatingClient()
  17114. //
  17115. ///*++
  17116. //
  17117. //Routine Description:
  17118. //
  17119. // This service is used to stop impersonating a client using an
  17120. // impersonation token. This service must be called in the context
  17121. // of the server thread which wishes to stop impersonating its
  17122. // client.
  17123. //
  17124. //
  17125. //Arguments:
  17126. //
  17127. // None.
  17128. //
  17129. //Return Value:
  17130. //
  17131. // None.
  17132. //
  17133. //--*/
  17134. //--
  17135. #define SeStopImpersonatingClient() PsRevertToSelf()
  17136. //++
  17137. //
  17138. // PACCESS_TOKEN
  17139. // SeQuerySubjectContextToken(
  17140. // IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  17141. // );
  17142. //
  17143. // Routine Description:
  17144. //
  17145. // This routine returns the effective token from the subject context,
  17146. // either the client token, if present, or the process token.
  17147. //
  17148. // Arguments:
  17149. //
  17150. // SubjectContext - Context to query
  17151. //
  17152. // Return Value:
  17153. //
  17154. // This routine returns the PACCESS_TOKEN for the effective token.
  17155. // The pointer may be passed to SeQueryInformationToken. This routine
  17156. // does not affect the lock status of the token, i.e. the token is not
  17157. // locked. If the SubjectContext has been locked, the token remains locked,
  17158. // if not, the token remains unlocked.
  17159. //
  17160. //--
  17161. #define SeQuerySubjectContextToken( SubjectContext ) \
  17162. ( ARGUMENT_PRESENT( ((PSECURITY_SUBJECT_CONTEXT) SubjectContext)->ClientToken) ? \
  17163. ((PSECURITY_SUBJECT_CONTEXT) SubjectContext)->ClientToken : \
  17164. ((PSECURITY_SUBJECT_CONTEXT) SubjectContext)->PrimaryToken )
  17165. NTKERNELAPI
  17166. VOID
  17167. SeCaptureSubjectContext (
  17168. OUT PSECURITY_SUBJECT_CONTEXT SubjectContext
  17169. );
  17170. NTKERNELAPI
  17171. VOID
  17172. SeLockSubjectContext(
  17173. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  17174. );
  17175. NTKERNELAPI
  17176. VOID
  17177. SeUnlockSubjectContext(
  17178. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  17179. );
  17180. NTKERNELAPI
  17181. VOID
  17182. SeReleaseSubjectContext (
  17183. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  17184. );
  17185. NTSTATUS
  17186. SeCaptureAuditPolicy(
  17187. IN PTOKEN_AUDIT_POLICY Policy,
  17188. IN KPROCESSOR_MODE RequestorMode,
  17189. IN PVOID CaptureBuffer OPTIONAL,
  17190. IN ULONG CaptureBufferLength,
  17191. IN POOL_TYPE PoolType,
  17192. IN BOOLEAN ForceCapture,
  17193. OUT PTOKEN_AUDIT_POLICY *CapturedPolicy
  17194. );
  17195. VOID
  17196. SeReleaseAuditPolicy (
  17197. IN PTOKEN_AUDIT_POLICY CapturedPolicy,
  17198. IN KPROCESSOR_MODE RequestorMode,
  17199. IN BOOLEAN ForceCapture
  17200. );
  17201. NTKERNELAPI
  17202. NTSTATUS
  17203. SeAssignSecurity (
  17204. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  17205. IN PSECURITY_DESCRIPTOR ExplicitDescriptor,
  17206. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  17207. IN BOOLEAN IsDirectoryObject,
  17208. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  17209. IN PGENERIC_MAPPING GenericMapping,
  17210. IN POOL_TYPE PoolType
  17211. );
  17212. NTKERNELAPI
  17213. NTSTATUS
  17214. SeAssignSecurityEx (
  17215. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  17216. IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL,
  17217. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  17218. IN GUID *ObjectType OPTIONAL,
  17219. IN BOOLEAN IsDirectoryObject,
  17220. IN ULONG AutoInheritFlags,
  17221. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  17222. IN PGENERIC_MAPPING GenericMapping,
  17223. IN POOL_TYPE PoolType
  17224. );
  17225. NTKERNELAPI
  17226. NTSTATUS
  17227. SeDeassignSecurity (
  17228. IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
  17229. );
  17230. NTKERNELAPI
  17231. BOOLEAN
  17232. SeAccessCheck (
  17233. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  17234. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  17235. IN BOOLEAN SubjectContextLocked,
  17236. IN ACCESS_MASK DesiredAccess,
  17237. IN ACCESS_MASK PreviouslyGrantedAccess,
  17238. OUT PPRIVILEGE_SET *Privileges OPTIONAL,
  17239. IN PGENERIC_MAPPING GenericMapping,
  17240. IN KPROCESSOR_MODE AccessMode,
  17241. OUT PACCESS_MASK GrantedAccess,
  17242. OUT PNTSTATUS AccessStatus
  17243. );
  17244. #ifdef SE_NTFS_WORLD_CACHE
  17245. VOID
  17246. SeGetWorldRights (
  17247. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  17248. IN PGENERIC_MAPPING GenericMapping,
  17249. OUT PACCESS_MASK GrantedAccess
  17250. );
  17251. #endif
  17252. NTKERNELAPI
  17253. BOOLEAN
  17254. SePrivilegeCheck(
  17255. IN OUT PPRIVILEGE_SET RequiredPrivileges,
  17256. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
  17257. IN KPROCESSOR_MODE AccessMode
  17258. );
  17259. NTKERNELAPI
  17260. VOID
  17261. SeFreePrivileges(
  17262. IN PPRIVILEGE_SET Privileges
  17263. );
  17264. NTKERNELAPI
  17265. VOID
  17266. SeOpenObjectAuditAlarm (
  17267. IN PUNICODE_STRING ObjectTypeName,
  17268. IN PVOID Object OPTIONAL,
  17269. IN PUNICODE_STRING AbsoluteObjectName OPTIONAL,
  17270. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  17271. IN PACCESS_STATE AccessState,
  17272. IN BOOLEAN ObjectCreated,
  17273. IN BOOLEAN AccessGranted,
  17274. IN KPROCESSOR_MODE AccessMode,
  17275. OUT PBOOLEAN GenerateOnClose
  17276. );
  17277. NTKERNELAPI
  17278. VOID
  17279. SeOpenObjectForDeleteAuditAlarm (
  17280. IN PUNICODE_STRING ObjectTypeName,
  17281. IN PVOID Object OPTIONAL,
  17282. IN PUNICODE_STRING AbsoluteObjectName OPTIONAL,
  17283. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  17284. IN PACCESS_STATE AccessState,
  17285. IN BOOLEAN ObjectCreated,
  17286. IN BOOLEAN AccessGranted,
  17287. IN KPROCESSOR_MODE AccessMode,
  17288. OUT PBOOLEAN GenerateOnClose
  17289. );
  17290. VOID
  17291. SeDeleteObjectAuditAlarm(
  17292. IN PVOID Object,
  17293. IN HANDLE Handle
  17294. );
  17295. NTKERNELAPI
  17296. BOOLEAN
  17297. SeValidSecurityDescriptor(
  17298. IN ULONG Length,
  17299. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  17300. );
  17301. NTKERNELAPI
  17302. TOKEN_TYPE
  17303. SeTokenType(
  17304. IN PACCESS_TOKEN Token
  17305. );
  17306. NTKERNELAPI
  17307. BOOLEAN
  17308. SeTokenIsAdmin(
  17309. IN PACCESS_TOKEN Token
  17310. );
  17311. NTKERNELAPI
  17312. BOOLEAN
  17313. SeTokenIsRestricted(
  17314. IN PACCESS_TOKEN Token
  17315. );
  17316. NTSTATUS
  17317. SeFilterToken (
  17318. IN PACCESS_TOKEN ExistingToken,
  17319. IN ULONG Flags,
  17320. IN PTOKEN_GROUPS SidsToDisable OPTIONAL,
  17321. IN PTOKEN_PRIVILEGES PrivilegesToDelete OPTIONAL,
  17322. IN PTOKEN_GROUPS RestrictedSids OPTIONAL,
  17323. OUT PACCESS_TOKEN * FilteredToken
  17324. );
  17325. // begin_ntosp
  17326. NTKERNELAPI
  17327. NTSTATUS
  17328. SeQueryAuthenticationIdToken(
  17329. IN PACCESS_TOKEN Token,
  17330. OUT PLUID AuthenticationId
  17331. );
  17332. // end_ntosp
  17333. NTKERNELAPI
  17334. NTSTATUS
  17335. SeQuerySessionIdToken(
  17336. IN PACCESS_TOKEN,
  17337. IN PULONG pSessionId
  17338. );
  17339. NTKERNELAPI
  17340. NTSTATUS
  17341. SeSetSessionIdToken(
  17342. IN PACCESS_TOKEN,
  17343. IN ULONG SessionId
  17344. );
  17345. // begin_ntosp
  17346. NTKERNELAPI
  17347. NTSTATUS
  17348. SeCreateClientSecurity (
  17349. IN PETHREAD ClientThread,
  17350. IN PSECURITY_QUALITY_OF_SERVICE ClientSecurityQos,
  17351. IN BOOLEAN RemoteSession,
  17352. OUT PSECURITY_CLIENT_CONTEXT ClientContext
  17353. );
  17354. // end_ntosp
  17355. NTKERNELAPI
  17356. VOID
  17357. SeImpersonateClient(
  17358. IN PSECURITY_CLIENT_CONTEXT ClientContext,
  17359. IN PETHREAD ServerThread OPTIONAL
  17360. );
  17361. // begin_ntosp
  17362. NTKERNELAPI
  17363. NTSTATUS
  17364. SeImpersonateClientEx(
  17365. IN PSECURITY_CLIENT_CONTEXT ClientContext,
  17366. IN PETHREAD ServerThread OPTIONAL
  17367. );
  17368. // end_ntosp
  17369. NTKERNELAPI
  17370. NTSTATUS
  17371. SeCreateClientSecurityFromSubjectContext (
  17372. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  17373. IN PSECURITY_QUALITY_OF_SERVICE ClientSecurityQos,
  17374. IN BOOLEAN ServerIsRemote,
  17375. OUT PSECURITY_CLIENT_CONTEXT ClientContext
  17376. );
  17377. NTKERNELAPI
  17378. NTSTATUS
  17379. SeQuerySecurityDescriptorInfo (
  17380. IN PSECURITY_INFORMATION SecurityInformation,
  17381. OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  17382. IN OUT PULONG Length,
  17383. IN PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor
  17384. );
  17385. NTKERNELAPI
  17386. NTSTATUS
  17387. SeSetSecurityDescriptorInfo (
  17388. IN PVOID Object OPTIONAL,
  17389. IN PSECURITY_INFORMATION SecurityInformation,
  17390. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  17391. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  17392. IN POOL_TYPE PoolType,
  17393. IN PGENERIC_MAPPING GenericMapping
  17394. );
  17395. NTKERNELAPI
  17396. NTSTATUS
  17397. SeSetSecurityDescriptorInfoEx (
  17398. IN PVOID Object OPTIONAL,
  17399. IN PSECURITY_INFORMATION SecurityInformation,
  17400. IN PSECURITY_DESCRIPTOR ModificationDescriptor,
  17401. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  17402. IN ULONG AutoInheritFlags,
  17403. IN POOL_TYPE PoolType,
  17404. IN PGENERIC_MAPPING GenericMapping
  17405. );
  17406. NTKERNELAPI
  17407. NTSTATUS
  17408. SeAppendPrivileges(
  17409. PACCESS_STATE AccessState,
  17410. PPRIVILEGE_SET Privileges
  17411. );
  17412. NTKERNELAPI
  17413. BOOLEAN
  17414. SeSinglePrivilegeCheck(
  17415. LUID PrivilegeValue,
  17416. KPROCESSOR_MODE PreviousMode
  17417. );
  17418. NTKERNELAPI
  17419. BOOLEAN
  17420. SeAuditingFileEvents(
  17421. IN BOOLEAN AccessGranted,
  17422. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  17423. );
  17424. NTKERNELAPI
  17425. BOOLEAN
  17426. SeAuditingFileEventsWithContext(
  17427. IN BOOLEAN AccessGranted,
  17428. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  17429. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext OPTIONAL
  17430. );
  17431. NTKERNELAPI
  17432. BOOLEAN
  17433. SeAuditingHardLinkEvents(
  17434. IN BOOLEAN AccessGranted,
  17435. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  17436. );
  17437. NTKERNELAPI
  17438. BOOLEAN
  17439. SeAuditingHardLinkEventsWithContext(
  17440. IN BOOLEAN AccessGranted,
  17441. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  17442. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext OPTIONAL
  17443. );
  17444. NTKERNELAPI
  17445. BOOLEAN
  17446. SeAuditingFileOrGlobalEvents(
  17447. IN BOOLEAN AccessGranted,
  17448. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  17449. IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext
  17450. );
  17451. NTKERNELAPI
  17452. BOOLEAN
  17453. FASTCALL
  17454. SeDetailedAuditingWithToken(
  17455. IN PACCESS_TOKEN AccessToken OPTIONAL
  17456. );
  17457. VOID
  17458. SeAuditHardLinkCreation(
  17459. IN PUNICODE_STRING FileName,
  17460. IN PUNICODE_STRING LinkName,
  17461. IN BOOLEAN bSuccess
  17462. );
  17463. VOID
  17464. SeSetAccessStateGenericMapping (
  17465. PACCESS_STATE AccessState,
  17466. PGENERIC_MAPPING GenericMapping
  17467. );
  17468. NTKERNELAPI
  17469. NTSTATUS
  17470. SeRegisterLogonSessionTerminatedRoutine(
  17471. IN PSE_LOGON_SESSION_TERMINATED_ROUTINE CallbackRoutine
  17472. );
  17473. NTKERNELAPI
  17474. NTSTATUS
  17475. SeUnregisterLogonSessionTerminatedRoutine(
  17476. IN PSE_LOGON_SESSION_TERMINATED_ROUTINE CallbackRoutine
  17477. );
  17478. NTKERNELAPI
  17479. NTSTATUS
  17480. SeMarkLogonSessionForTerminationNotification(
  17481. IN PLUID LogonId
  17482. );
  17483. // begin_ntosp
  17484. NTKERNELAPI
  17485. NTSTATUS
  17486. SeQueryInformationToken (
  17487. IN PACCESS_TOKEN Token,
  17488. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  17489. OUT PVOID *TokenInformation
  17490. );
  17491. //
  17492. // Grants access to SeExports structure
  17493. //
  17494. extern NTKERNELAPI PSE_EXPORTS SeExports;
  17495. //
  17496. // System Thread and Process Creation and Termination
  17497. //
  17498. NTKERNELAPI
  17499. NTSTATUS
  17500. PsCreateSystemThread(
  17501. OUT PHANDLE ThreadHandle,
  17502. IN ULONG DesiredAccess,
  17503. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  17504. IN HANDLE ProcessHandle OPTIONAL,
  17505. OUT PCLIENT_ID ClientId OPTIONAL,
  17506. IN PKSTART_ROUTINE StartRoutine,
  17507. IN PVOID StartContext
  17508. );
  17509. NTKERNELAPI
  17510. NTSTATUS
  17511. PsTerminateSystemThread(
  17512. IN NTSTATUS ExitStatus
  17513. );
  17514. typedef
  17515. VOID
  17516. (*PCREATE_PROCESS_NOTIFY_ROUTINE)(
  17517. IN HANDLE ParentId,
  17518. IN HANDLE ProcessId,
  17519. IN BOOLEAN Create
  17520. );
  17521. NTSTATUS
  17522. PsSetCreateProcessNotifyRoutine(
  17523. IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
  17524. IN BOOLEAN Remove
  17525. );
  17526. typedef
  17527. VOID
  17528. (*PCREATE_THREAD_NOTIFY_ROUTINE)(
  17529. IN HANDLE ProcessId,
  17530. IN HANDLE ThreadId,
  17531. IN BOOLEAN Create
  17532. );
  17533. NTSTATUS
  17534. PsSetCreateThreadNotifyRoutine(
  17535. IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
  17536. );
  17537. NTSTATUS
  17538. PsRemoveCreateThreadNotifyRoutine (
  17539. IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
  17540. );
  17541. //
  17542. // Structures for Load Image Notify
  17543. //
  17544. typedef struct _IMAGE_INFO {
  17545. union {
  17546. ULONG Properties;
  17547. struct {
  17548. ULONG ImageAddressingMode : 8; // code addressing mode
  17549. ULONG SystemModeImage : 1; // system mode image
  17550. ULONG ImageMappedToAllPids : 1; // image mapped into all processes
  17551. ULONG Reserved : 22;
  17552. };
  17553. };
  17554. PVOID ImageBase;
  17555. ULONG ImageSelector;
  17556. SIZE_T ImageSize;
  17557. ULONG ImageSectionNumber;
  17558. } IMAGE_INFO, *PIMAGE_INFO;
  17559. #define IMAGE_ADDRESSING_MODE_32BIT 3
  17560. typedef
  17561. VOID
  17562. (*PLOAD_IMAGE_NOTIFY_ROUTINE)(
  17563. IN PUNICODE_STRING FullImageName,
  17564. IN HANDLE ProcessId, // pid into which image is being mapped
  17565. IN PIMAGE_INFO ImageInfo
  17566. );
  17567. NTSTATUS
  17568. PsSetLoadImageNotifyRoutine(
  17569. IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
  17570. );
  17571. NTSTATUS
  17572. PsRemoveLoadImageNotifyRoutine(
  17573. IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
  17574. );
  17575. // end_ntddk
  17576. //
  17577. // Security Support
  17578. //
  17579. NTSTATUS
  17580. PsAssignImpersonationToken(
  17581. IN PETHREAD Thread,
  17582. IN HANDLE Token
  17583. );
  17584. // begin_ntosp
  17585. NTKERNELAPI
  17586. PACCESS_TOKEN
  17587. PsReferencePrimaryToken(
  17588. IN PEPROCESS Process
  17589. );
  17590. VOID
  17591. PsDereferencePrimaryToken(
  17592. IN PACCESS_TOKEN PrimaryToken
  17593. );
  17594. VOID
  17595. PsDereferenceImpersonationToken(
  17596. IN PACCESS_TOKEN ImpersonationToken
  17597. );
  17598. NTKERNELAPI
  17599. PACCESS_TOKEN
  17600. PsReferenceImpersonationToken(
  17601. IN PETHREAD Thread,
  17602. OUT PBOOLEAN CopyOnOpen,
  17603. OUT PBOOLEAN EffectiveOnly,
  17604. OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  17605. );
  17606. LARGE_INTEGER
  17607. PsGetProcessExitTime(
  17608. VOID
  17609. );
  17610. BOOLEAN
  17611. PsIsThreadTerminating(
  17612. IN PETHREAD Thread
  17613. );
  17614. // begin_ntosp
  17615. NTSTATUS
  17616. PsImpersonateClient(
  17617. IN PETHREAD Thread,
  17618. IN PACCESS_TOKEN Token,
  17619. IN BOOLEAN CopyOnOpen,
  17620. IN BOOLEAN EffectiveOnly,
  17621. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  17622. );
  17623. // end_ntosp
  17624. BOOLEAN
  17625. PsDisableImpersonation(
  17626. IN PETHREAD Thread,
  17627. IN PSE_IMPERSONATION_STATE ImpersonationState
  17628. );
  17629. VOID
  17630. PsRestoreImpersonation(
  17631. IN PETHREAD Thread,
  17632. IN PSE_IMPERSONATION_STATE ImpersonationState
  17633. );
  17634. NTKERNELAPI
  17635. VOID
  17636. PsRevertToSelf(
  17637. VOID
  17638. );
  17639. //
  17640. // Quota Operations
  17641. //
  17642. VOID
  17643. PsChargePoolQuota(
  17644. IN PEPROCESS Process,
  17645. IN POOL_TYPE PoolType,
  17646. IN ULONG_PTR Amount
  17647. );
  17648. NTSTATUS
  17649. PsChargeProcessPoolQuota(
  17650. IN PEPROCESS Process,
  17651. IN POOL_TYPE PoolType,
  17652. IN ULONG_PTR Amount
  17653. );
  17654. VOID
  17655. PsReturnPoolQuota(
  17656. IN PEPROCESS Process,
  17657. IN POOL_TYPE PoolType,
  17658. IN ULONG_PTR Amount
  17659. );
  17660. HANDLE
  17661. PsGetCurrentProcessId( VOID );
  17662. HANDLE
  17663. PsGetCurrentThreadId( VOID );
  17664. // end_ntosp
  17665. BOOLEAN
  17666. PsGetVersion(
  17667. PULONG MajorVersion OPTIONAL,
  17668. PULONG MinorVersion OPTIONAL,
  17669. PULONG BuildNumber OPTIONAL,
  17670. PUNICODE_STRING CSDVersion OPTIONAL
  17671. );
  17672. NTKERNELAPI
  17673. BOOLEAN
  17674. PsIsSystemThread(
  17675. PETHREAD Thread
  17676. );
  17677. //
  17678. // Define I/O system data structure type codes. Each major data structure in
  17679. // the I/O system has a type code The type field in each structure is at the
  17680. // same offset. The following values can be used to determine which type of
  17681. // data structure a pointer refers to.
  17682. //
  17683. #define IO_TYPE_ADAPTER 0x00000001
  17684. #define IO_TYPE_CONTROLLER 0x00000002
  17685. #define IO_TYPE_DEVICE 0x00000003
  17686. #define IO_TYPE_DRIVER 0x00000004
  17687. #define IO_TYPE_FILE 0x00000005
  17688. #define IO_TYPE_IRP 0x00000006
  17689. #define IO_TYPE_MASTER_ADAPTER 0x00000007
  17690. #define IO_TYPE_OPEN_PACKET 0x00000008
  17691. #define IO_TYPE_TIMER 0x00000009
  17692. #define IO_TYPE_VPB 0x0000000a
  17693. #define IO_TYPE_ERROR_LOG 0x0000000b
  17694. #define IO_TYPE_ERROR_MESSAGE 0x0000000c
  17695. #define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
  17696. //
  17697. // Define the major function codes for IRPs.
  17698. //
  17699. #define IRP_MJ_CREATE 0x00
  17700. #define IRP_MJ_CREATE_NAMED_PIPE 0x01
  17701. #define IRP_MJ_CLOSE 0x02
  17702. #define IRP_MJ_READ 0x03
  17703. #define IRP_MJ_WRITE 0x04
  17704. #define IRP_MJ_QUERY_INFORMATION 0x05
  17705. #define IRP_MJ_SET_INFORMATION 0x06
  17706. #define IRP_MJ_QUERY_EA 0x07
  17707. #define IRP_MJ_SET_EA 0x08
  17708. #define IRP_MJ_FLUSH_BUFFERS 0x09
  17709. #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  17710. #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  17711. #define IRP_MJ_DIRECTORY_CONTROL 0x0c
  17712. #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  17713. #define IRP_MJ_DEVICE_CONTROL 0x0e
  17714. #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  17715. #define IRP_MJ_SHUTDOWN 0x10
  17716. #define IRP_MJ_LOCK_CONTROL 0x11
  17717. #define IRP_MJ_CLEANUP 0x12
  17718. #define IRP_MJ_CREATE_MAILSLOT 0x13
  17719. #define IRP_MJ_QUERY_SECURITY 0x14
  17720. #define IRP_MJ_SET_SECURITY 0x15
  17721. #define IRP_MJ_POWER 0x16
  17722. #define IRP_MJ_SYSTEM_CONTROL 0x17
  17723. #define IRP_MJ_DEVICE_CHANGE 0x18
  17724. #define IRP_MJ_QUERY_QUOTA 0x19
  17725. #define IRP_MJ_SET_QUOTA 0x1a
  17726. #define IRP_MJ_PNP 0x1b
  17727. #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
  17728. #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  17729. //
  17730. // Make the Scsi major code the same as internal device control.
  17731. //
  17732. #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
  17733. //
  17734. // Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
  17735. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  17736. // reserved to customers of Microsoft.
  17737. //
  17738. // end_wdm end_ntndis
  17739. //
  17740. // Directory control minor function codes
  17741. //
  17742. #define IRP_MN_QUERY_DIRECTORY 0x01
  17743. #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
  17744. //
  17745. // File system control minor function codes. Note that "user request" is
  17746. // assumed to be zero by both the I/O system and file systems. Do not change
  17747. // this value.
  17748. //
  17749. #define IRP_MN_USER_FS_REQUEST 0x00
  17750. #define IRP_MN_MOUNT_VOLUME 0x01
  17751. #define IRP_MN_VERIFY_VOLUME 0x02
  17752. #define IRP_MN_LOAD_FILE_SYSTEM 0x03
  17753. #define IRP_MN_TRACK_LINK 0x04 // To be obsoleted soon
  17754. #define IRP_MN_KERNEL_CALL 0x04
  17755. //
  17756. // Lock control minor function codes
  17757. //
  17758. #define IRP_MN_LOCK 0x01
  17759. #define IRP_MN_UNLOCK_SINGLE 0x02
  17760. #define IRP_MN_UNLOCK_ALL 0x03
  17761. #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
  17762. //
  17763. // Read and Write minor function codes for file systems supporting Lan Manager
  17764. // software. All of these subfunction codes are invalid if the file has been
  17765. // opened with FO_NO_INTERMEDIATE_BUFFERING. They are also invalid in combi-
  17766. // nation with synchronous calls (Irp Flag or file open option).
  17767. //
  17768. // Note that "normal" is assumed to be zero by both the I/O system and file
  17769. // systems. Do not change this value.
  17770. //
  17771. #define IRP_MN_NORMAL 0x00
  17772. #define IRP_MN_DPC 0x01
  17773. #define IRP_MN_MDL 0x02
  17774. #define IRP_MN_COMPLETE 0x04
  17775. #define IRP_MN_COMPRESSED 0x08
  17776. #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
  17777. #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
  17778. #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
  17779. // begin_wdm
  17780. //
  17781. // Device Control Request minor function codes for SCSI support. Note that
  17782. // user requests are assumed to be zero.
  17783. //
  17784. #define IRP_MN_SCSI_CLASS 0x01
  17785. //
  17786. // PNP minor function codes.
  17787. //
  17788. #define IRP_MN_START_DEVICE 0x00
  17789. #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
  17790. #define IRP_MN_REMOVE_DEVICE 0x02
  17791. #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  17792. #define IRP_MN_STOP_DEVICE 0x04
  17793. #define IRP_MN_QUERY_STOP_DEVICE 0x05
  17794. #define IRP_MN_CANCEL_STOP_DEVICE 0x06
  17795. #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  17796. #define IRP_MN_QUERY_INTERFACE 0x08
  17797. #define IRP_MN_QUERY_CAPABILITIES 0x09
  17798. #define IRP_MN_QUERY_RESOURCES 0x0A
  17799. #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  17800. #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
  17801. #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
  17802. #define IRP_MN_READ_CONFIG 0x0F
  17803. #define IRP_MN_WRITE_CONFIG 0x10
  17804. #define IRP_MN_EJECT 0x11
  17805. #define IRP_MN_SET_LOCK 0x12
  17806. #define IRP_MN_QUERY_ID 0x13
  17807. #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
  17808. #define IRP_MN_QUERY_BUS_INFORMATION 0x15
  17809. #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
  17810. #define IRP_MN_SURPRISE_REMOVAL 0x17
  17811. // end_wdm
  17812. #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
  17813. // begin_wdm
  17814. //
  17815. // POWER minor function codes
  17816. //
  17817. #define IRP_MN_WAIT_WAKE 0x00
  17818. #define IRP_MN_POWER_SEQUENCE 0x01
  17819. #define IRP_MN_SET_POWER 0x02
  17820. #define IRP_MN_QUERY_POWER 0x03
  17821. // begin_ntminiport
  17822. //
  17823. // WMI minor function codes under IRP_MJ_SYSTEM_CONTROL
  17824. //
  17825. #define IRP_MN_QUERY_ALL_DATA 0x00
  17826. #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
  17827. #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
  17828. #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
  17829. #define IRP_MN_ENABLE_EVENTS 0x04
  17830. #define IRP_MN_DISABLE_EVENTS 0x05
  17831. #define IRP_MN_ENABLE_COLLECTION 0x06
  17832. #define IRP_MN_DISABLE_COLLECTION 0x07
  17833. #define IRP_MN_REGINFO 0x08
  17834. #define IRP_MN_EXECUTE_METHOD 0x09
  17835. // Minor code 0x0a is reserved
  17836. #define IRP_MN_REGINFO_EX 0x0b
  17837. // end_ntminiport
  17838. //
  17839. // Define option flags for IoCreateFile. Note that these values must be
  17840. // exactly the same as the SL_... flags for a create function. Note also
  17841. // that there are flags that may be passed to IoCreateFile that are not
  17842. // placed in the stack location for the create IRP. These flags start in
  17843. // the next byte.
  17844. //
  17845. #define IO_FORCE_ACCESS_CHECK 0x0001
  17846. // end_ntddk end_wdm end_nthal end_ntosp
  17847. #define IO_OPEN_PAGING_FILE 0x0002
  17848. #define IO_OPEN_TARGET_DIRECTORY 0x0004
  17849. //
  17850. // Flags not passed to driver
  17851. //
  17852. // begin_ntddk begin_wdm begin_ntosp
  17853. #define IO_NO_PARAMETER_CHECKING 0x0100
  17854. //
  17855. // Define Information fields for whether or not a REPARSE or a REMOUNT has
  17856. // occurred in the file system.
  17857. //
  17858. #define IO_REPARSE 0x0
  17859. #define IO_REMOUNT 0x1
  17860. // end_ntddk end_wdm
  17861. #define IO_CHECK_CREATE_PARAMETERS 0x0200
  17862. #define IO_ATTACH_DEVICE 0x0400
  17863. // end_ntosp
  17864. // begin_ntifs begin_ntosp
  17865. //
  17866. // This flag is only meaning full to IoCreateFileSpecifyDeviceObjectHint.
  17867. // FileHandles created using IoCreateFileSpecifyDeviceObjectHint with this
  17868. // flag set will bypass ShareAccess checks on this file.
  17869. //
  17870. #define IO_IGNORE_SHARE_ACCESS_CHECK 0x0800 // Ignores share access checks on opens.
  17871. //
  17872. // Define the objects that can be created by IoCreateFile.
  17873. //
  17874. typedef enum _CREATE_FILE_TYPE {
  17875. CreateFileTypeNone,
  17876. CreateFileTypeNamedPipe,
  17877. CreateFileTypeMailslot
  17878. } CREATE_FILE_TYPE;
  17879. //
  17880. // Define the structures used by the I/O system
  17881. //
  17882. //
  17883. // Define empty typedefs for the _IRP, _DEVICE_OBJECT, and _DRIVER_OBJECT
  17884. // structures so they may be referenced by function types before they are
  17885. // actually defined.
  17886. //
  17887. struct _DEVICE_DESCRIPTION;
  17888. struct _DEVICE_OBJECT;
  17889. struct _DMA_ADAPTER;
  17890. struct _DRIVER_OBJECT;
  17891. struct _DRIVE_LAYOUT_INFORMATION;
  17892. struct _DISK_PARTITION;
  17893. struct _FILE_OBJECT;
  17894. struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP;
  17895. struct _SCSI_REQUEST_BLOCK;
  17896. struct _SCATTER_GATHER_LIST;
  17897. //
  17898. // Define the I/O version of a DPC routine.
  17899. //
  17900. typedef
  17901. VOID
  17902. (*PIO_DPC_ROUTINE) (
  17903. IN PKDPC Dpc,
  17904. IN struct _DEVICE_OBJECT *DeviceObject,
  17905. IN struct _IRP *Irp,
  17906. IN PVOID Context
  17907. );
  17908. //
  17909. // Define driver timer routine type.
  17910. //
  17911. typedef
  17912. VOID
  17913. (*PIO_TIMER_ROUTINE) (
  17914. IN struct _DEVICE_OBJECT *DeviceObject,
  17915. IN PVOID Context
  17916. );
  17917. //
  17918. // Define driver initialization routine type.
  17919. //
  17920. typedef
  17921. NTSTATUS
  17922. (*PDRIVER_INITIALIZE) (
  17923. IN struct _DRIVER_OBJECT *DriverObject,
  17924. IN PUNICODE_STRING RegistryPath
  17925. );
  17926. // end_wdm
  17927. //
  17928. // Define driver reinitialization routine type.
  17929. //
  17930. typedef
  17931. VOID
  17932. (*PDRIVER_REINITIALIZE) (
  17933. IN struct _DRIVER_OBJECT *DriverObject,
  17934. IN PVOID Context,
  17935. IN ULONG Count
  17936. );
  17937. // begin_wdm begin_ntndis
  17938. //
  17939. // Define driver cancel routine type.
  17940. //
  17941. typedef
  17942. VOID
  17943. (*PDRIVER_CANCEL) (
  17944. IN struct _DEVICE_OBJECT *DeviceObject,
  17945. IN struct _IRP *Irp
  17946. );
  17947. //
  17948. // Define driver dispatch routine type.
  17949. //
  17950. typedef
  17951. NTSTATUS
  17952. (*PDRIVER_DISPATCH) (
  17953. IN struct _DEVICE_OBJECT *DeviceObject,
  17954. IN struct _IRP *Irp
  17955. );
  17956. //
  17957. // Define driver start I/O routine type.
  17958. //
  17959. typedef
  17960. VOID
  17961. (*PDRIVER_STARTIO) (
  17962. IN struct _DEVICE_OBJECT *DeviceObject,
  17963. IN struct _IRP *Irp
  17964. );
  17965. //
  17966. // Define driver unload routine type.
  17967. //
  17968. typedef
  17969. VOID
  17970. (*PDRIVER_UNLOAD) (
  17971. IN struct _DRIVER_OBJECT *DriverObject
  17972. );
  17973. //
  17974. // Define driver AddDevice routine type.
  17975. //
  17976. typedef
  17977. NTSTATUS
  17978. (*PDRIVER_ADD_DEVICE) (
  17979. IN struct _DRIVER_OBJECT *DriverObject,
  17980. IN struct _DEVICE_OBJECT *PhysicalDeviceObject
  17981. );
  17982. // end_ntddk end_wdm end_nthal end_ntndis end_ntosp
  17983. //
  17984. // Define driver FS notification change routine type.
  17985. //
  17986. typedef
  17987. VOID
  17988. (*PDRIVER_FS_NOTIFICATION) (
  17989. IN struct _DEVICE_OBJECT *DeviceObject,
  17990. IN BOOLEAN FsActive
  17991. );
  17992. // begin_ntddk begin_wdm begin_ntosp
  17993. //
  17994. // Define fast I/O procedure prototypes.
  17995. //
  17996. // Fast I/O read and write procedures.
  17997. //
  17998. typedef
  17999. BOOLEAN
  18000. (*PFAST_IO_CHECK_IF_POSSIBLE) (
  18001. IN struct _FILE_OBJECT *FileObject,
  18002. IN PLARGE_INTEGER FileOffset,
  18003. IN ULONG Length,
  18004. IN BOOLEAN Wait,
  18005. IN ULONG LockKey,
  18006. IN BOOLEAN CheckForReadOperation,
  18007. OUT PIO_STATUS_BLOCK IoStatus,
  18008. IN struct _DEVICE_OBJECT *DeviceObject
  18009. );
  18010. typedef
  18011. BOOLEAN
  18012. (*PFAST_IO_READ) (
  18013. IN struct _FILE_OBJECT *FileObject,
  18014. IN PLARGE_INTEGER FileOffset,
  18015. IN ULONG Length,
  18016. IN BOOLEAN Wait,
  18017. IN ULONG LockKey,
  18018. OUT PVOID Buffer,
  18019. OUT PIO_STATUS_BLOCK IoStatus,
  18020. IN struct _DEVICE_OBJECT *DeviceObject
  18021. );
  18022. typedef
  18023. BOOLEAN
  18024. (*PFAST_IO_WRITE) (
  18025. IN struct _FILE_OBJECT *FileObject,
  18026. IN PLARGE_INTEGER FileOffset,
  18027. IN ULONG Length,
  18028. IN BOOLEAN Wait,
  18029. IN ULONG LockKey,
  18030. IN PVOID Buffer,
  18031. OUT PIO_STATUS_BLOCK IoStatus,
  18032. IN struct _DEVICE_OBJECT *DeviceObject
  18033. );
  18034. //
  18035. // Fast I/O query basic and standard information procedures.
  18036. //
  18037. typedef
  18038. BOOLEAN
  18039. (*PFAST_IO_QUERY_BASIC_INFO) (
  18040. IN struct _FILE_OBJECT *FileObject,
  18041. IN BOOLEAN Wait,
  18042. OUT PFILE_BASIC_INFORMATION Buffer,
  18043. OUT PIO_STATUS_BLOCK IoStatus,
  18044. IN struct _DEVICE_OBJECT *DeviceObject
  18045. );
  18046. typedef
  18047. BOOLEAN
  18048. (*PFAST_IO_QUERY_STANDARD_INFO) (
  18049. IN struct _FILE_OBJECT *FileObject,
  18050. IN BOOLEAN Wait,
  18051. OUT PFILE_STANDARD_INFORMATION Buffer,
  18052. OUT PIO_STATUS_BLOCK IoStatus,
  18053. IN struct _DEVICE_OBJECT *DeviceObject
  18054. );
  18055. //
  18056. // Fast I/O lock and unlock procedures.
  18057. //
  18058. typedef
  18059. BOOLEAN
  18060. (*PFAST_IO_LOCK) (
  18061. IN struct _FILE_OBJECT *FileObject,
  18062. IN PLARGE_INTEGER FileOffset,
  18063. IN PLARGE_INTEGER Length,
  18064. PEPROCESS ProcessId,
  18065. ULONG Key,
  18066. BOOLEAN FailImmediately,
  18067. BOOLEAN ExclusiveLock,
  18068. OUT PIO_STATUS_BLOCK IoStatus,
  18069. IN struct _DEVICE_OBJECT *DeviceObject
  18070. );
  18071. typedef
  18072. BOOLEAN
  18073. (*PFAST_IO_UNLOCK_SINGLE) (
  18074. IN struct _FILE_OBJECT *FileObject,
  18075. IN PLARGE_INTEGER FileOffset,
  18076. IN PLARGE_INTEGER Length,
  18077. PEPROCESS ProcessId,
  18078. ULONG Key,
  18079. OUT PIO_STATUS_BLOCK IoStatus,
  18080. IN struct _DEVICE_OBJECT *DeviceObject
  18081. );
  18082. typedef
  18083. BOOLEAN
  18084. (*PFAST_IO_UNLOCK_ALL) (
  18085. IN struct _FILE_OBJECT *FileObject,
  18086. PEPROCESS ProcessId,
  18087. OUT PIO_STATUS_BLOCK IoStatus,
  18088. IN struct _DEVICE_OBJECT *DeviceObject
  18089. );
  18090. typedef
  18091. BOOLEAN
  18092. (*PFAST_IO_UNLOCK_ALL_BY_KEY) (
  18093. IN struct _FILE_OBJECT *FileObject,
  18094. PVOID ProcessId,
  18095. ULONG Key,
  18096. OUT PIO_STATUS_BLOCK IoStatus,
  18097. IN struct _DEVICE_OBJECT *DeviceObject
  18098. );
  18099. //
  18100. // Fast I/O device control procedure.
  18101. //
  18102. typedef
  18103. BOOLEAN
  18104. (*PFAST_IO_DEVICE_CONTROL) (
  18105. IN struct _FILE_OBJECT *FileObject,
  18106. IN BOOLEAN Wait,
  18107. IN PVOID InputBuffer OPTIONAL,
  18108. IN ULONG InputBufferLength,
  18109. OUT PVOID OutputBuffer OPTIONAL,
  18110. IN ULONG OutputBufferLength,
  18111. IN ULONG IoControlCode,
  18112. OUT PIO_STATUS_BLOCK IoStatus,
  18113. IN struct _DEVICE_OBJECT *DeviceObject
  18114. );
  18115. //
  18116. // Define callbacks for NtCreateSection to synchronize correctly with
  18117. // the file system. It pre-acquires the resources that will be needed
  18118. // when calling to query and set file/allocation size in the file system.
  18119. //
  18120. typedef
  18121. VOID
  18122. (*PFAST_IO_ACQUIRE_FILE) (
  18123. IN struct _FILE_OBJECT *FileObject
  18124. );
  18125. typedef
  18126. VOID
  18127. (*PFAST_IO_RELEASE_FILE) (
  18128. IN struct _FILE_OBJECT *FileObject
  18129. );
  18130. //
  18131. // Define callback for drivers that have device objects attached to lower-
  18132. // level drivers' device objects. This callback is made when the lower-level
  18133. // driver is deleting its device object.
  18134. //
  18135. typedef
  18136. VOID
  18137. (*PFAST_IO_DETACH_DEVICE) (
  18138. IN struct _DEVICE_OBJECT *SourceDevice,
  18139. IN struct _DEVICE_OBJECT *TargetDevice
  18140. );
  18141. //
  18142. // This structure is used by the server to quickly get the information needed
  18143. // to service a server open call. It is takes what would be two fast io calls
  18144. // one for basic information and the other for standard information and makes
  18145. // it into one call.
  18146. //
  18147. typedef
  18148. BOOLEAN
  18149. (*PFAST_IO_QUERY_NETWORK_OPEN_INFO) (
  18150. IN struct _FILE_OBJECT *FileObject,
  18151. IN BOOLEAN Wait,
  18152. OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
  18153. OUT struct _IO_STATUS_BLOCK *IoStatus,
  18154. IN struct _DEVICE_OBJECT *DeviceObject
  18155. );
  18156. //
  18157. // Define Mdl-based routines for the server to call
  18158. //
  18159. typedef
  18160. BOOLEAN
  18161. (*PFAST_IO_MDL_READ) (
  18162. IN struct _FILE_OBJECT *FileObject,
  18163. IN PLARGE_INTEGER FileOffset,
  18164. IN ULONG Length,
  18165. IN ULONG LockKey,
  18166. OUT PMDL *MdlChain,
  18167. OUT PIO_STATUS_BLOCK IoStatus,
  18168. IN struct _DEVICE_OBJECT *DeviceObject
  18169. );
  18170. typedef
  18171. BOOLEAN
  18172. (*PFAST_IO_MDL_READ_COMPLETE) (
  18173. IN struct _FILE_OBJECT *FileObject,
  18174. IN PMDL MdlChain,
  18175. IN struct _DEVICE_OBJECT *DeviceObject
  18176. );
  18177. typedef
  18178. BOOLEAN
  18179. (*PFAST_IO_PREPARE_MDL_WRITE) (
  18180. IN struct _FILE_OBJECT *FileObject,
  18181. IN PLARGE_INTEGER FileOffset,
  18182. IN ULONG Length,
  18183. IN ULONG LockKey,
  18184. OUT PMDL *MdlChain,
  18185. OUT PIO_STATUS_BLOCK IoStatus,
  18186. IN struct _DEVICE_OBJECT *DeviceObject
  18187. );
  18188. typedef
  18189. BOOLEAN
  18190. (*PFAST_IO_MDL_WRITE_COMPLETE) (
  18191. IN struct _FILE_OBJECT *FileObject,
  18192. IN PLARGE_INTEGER FileOffset,
  18193. IN PMDL MdlChain,
  18194. IN struct _DEVICE_OBJECT *DeviceObject
  18195. );
  18196. //
  18197. // If this routine is present, it will be called by FsRtl
  18198. // to acquire the file for the mapped page writer.
  18199. //
  18200. typedef
  18201. NTSTATUS
  18202. (*PFAST_IO_ACQUIRE_FOR_MOD_WRITE) (
  18203. IN struct _FILE_OBJECT *FileObject,
  18204. IN PLARGE_INTEGER EndingOffset,
  18205. OUT struct _ERESOURCE **ResourceToRelease,
  18206. IN struct _DEVICE_OBJECT *DeviceObject
  18207. );
  18208. typedef
  18209. NTSTATUS
  18210. (*PFAST_IO_RELEASE_FOR_MOD_WRITE) (
  18211. IN struct _FILE_OBJECT *FileObject,
  18212. IN struct _ERESOURCE *ResourceToRelease,
  18213. IN struct _DEVICE_OBJECT *DeviceObject
  18214. );
  18215. //
  18216. // If this routine is present, it will be called by FsRtl
  18217. // to acquire the file for the mapped page writer.
  18218. //
  18219. typedef
  18220. NTSTATUS
  18221. (*PFAST_IO_ACQUIRE_FOR_CCFLUSH) (
  18222. IN struct _FILE_OBJECT *FileObject,
  18223. IN struct _DEVICE_OBJECT *DeviceObject
  18224. );
  18225. typedef
  18226. NTSTATUS
  18227. (*PFAST_IO_RELEASE_FOR_CCFLUSH) (
  18228. IN struct _FILE_OBJECT *FileObject,
  18229. IN struct _DEVICE_OBJECT *DeviceObject
  18230. );
  18231. typedef
  18232. BOOLEAN
  18233. (*PFAST_IO_READ_COMPRESSED) (
  18234. IN struct _FILE_OBJECT *FileObject,
  18235. IN PLARGE_INTEGER FileOffset,
  18236. IN ULONG Length,
  18237. IN ULONG LockKey,
  18238. OUT PVOID Buffer,
  18239. OUT PMDL *MdlChain,
  18240. OUT PIO_STATUS_BLOCK IoStatus,
  18241. OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  18242. IN ULONG CompressedDataInfoLength,
  18243. IN struct _DEVICE_OBJECT *DeviceObject
  18244. );
  18245. typedef
  18246. BOOLEAN
  18247. (*PFAST_IO_WRITE_COMPRESSED) (
  18248. IN struct _FILE_OBJECT *FileObject,
  18249. IN PLARGE_INTEGER FileOffset,
  18250. IN ULONG Length,
  18251. IN ULONG LockKey,
  18252. IN PVOID Buffer,
  18253. OUT PMDL *MdlChain,
  18254. OUT PIO_STATUS_BLOCK IoStatus,
  18255. IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  18256. IN ULONG CompressedDataInfoLength,
  18257. IN struct _DEVICE_OBJECT *DeviceObject
  18258. );
  18259. typedef
  18260. BOOLEAN
  18261. (*PFAST_IO_MDL_READ_COMPLETE_COMPRESSED) (
  18262. IN struct _FILE_OBJECT *FileObject,
  18263. IN PMDL MdlChain,
  18264. IN struct _DEVICE_OBJECT *DeviceObject
  18265. );
  18266. typedef
  18267. BOOLEAN
  18268. (*PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED) (
  18269. IN struct _FILE_OBJECT *FileObject,
  18270. IN PLARGE_INTEGER FileOffset,
  18271. IN PMDL MdlChain,
  18272. IN struct _DEVICE_OBJECT *DeviceObject
  18273. );
  18274. typedef
  18275. BOOLEAN
  18276. (*PFAST_IO_QUERY_OPEN) (
  18277. IN struct _IRP *Irp,
  18278. OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
  18279. IN struct _DEVICE_OBJECT *DeviceObject
  18280. );
  18281. //
  18282. // Define the structure to describe the Fast I/O dispatch routines. Any
  18283. // additions made to this structure MUST be added monotonically to the end
  18284. // of the structure, and fields CANNOT be removed from the middle.
  18285. //
  18286. typedef struct _FAST_IO_DISPATCH {
  18287. ULONG SizeOfFastIoDispatch;
  18288. PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
  18289. PFAST_IO_READ FastIoRead;
  18290. PFAST_IO_WRITE FastIoWrite;
  18291. PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
  18292. PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
  18293. PFAST_IO_LOCK FastIoLock;
  18294. PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
  18295. PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
  18296. PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
  18297. PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
  18298. PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
  18299. PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
  18300. PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
  18301. PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
  18302. PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
  18303. PFAST_IO_MDL_READ MdlRead;
  18304. PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
  18305. PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
  18306. PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
  18307. PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
  18308. PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
  18309. PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
  18310. PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
  18311. PFAST_IO_QUERY_OPEN FastIoQueryOpen;
  18312. PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
  18313. PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
  18314. PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
  18315. } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
  18316. // end_ntddk end_wdm end_ntosp
  18317. //
  18318. // Valid values for FS_FILTER_PARAMETERS.AcquireForSectionSynchronization.SyncType
  18319. //
  18320. typedef enum _FS_FILTER_SECTION_SYNC_TYPE {
  18321. SyncTypeOther = 0,
  18322. SyncTypeCreateSection
  18323. } FS_FILTER_SECTION_SYNC_TYPE, *PFS_FILTER_SECTION_SYNC_TYPE;
  18324. //
  18325. // Parameters union for the operations that
  18326. // are exposed to the filters through the
  18327. // FsFilterCallbacks registration mechanism.
  18328. //
  18329. typedef union _FS_FILTER_PARAMETERS {
  18330. //
  18331. // AcquireForModifiedPageWriter
  18332. //
  18333. struct {
  18334. PLARGE_INTEGER EndingOffset;
  18335. PERESOURCE *ResourceToRelease;
  18336. } AcquireForModifiedPageWriter;
  18337. //
  18338. // ReleaseForModifiedPageWriter
  18339. //
  18340. struct {
  18341. PERESOURCE ResourceToRelease;
  18342. } ReleaseForModifiedPageWriter;
  18343. //
  18344. // AcquireForSectionSynchronization
  18345. //
  18346. struct {
  18347. FS_FILTER_SECTION_SYNC_TYPE SyncType;
  18348. ULONG PageProtection;
  18349. } AcquireForSectionSynchronization;
  18350. //
  18351. // Other
  18352. //
  18353. struct {
  18354. PVOID Argument1;
  18355. PVOID Argument2;
  18356. PVOID Argument3;
  18357. PVOID Argument4;
  18358. PVOID Argument5;
  18359. } Others;
  18360. } FS_FILTER_PARAMETERS, *PFS_FILTER_PARAMETERS;
  18361. //
  18362. // These are the valid values for the Operation field
  18363. // of the FS_FILTER_CALLBACK_DATA structure.
  18364. //
  18365. #define FS_FILTER_ACQUIRE_FOR_SECTION_SYNCHRONIZATION (UCHAR)-1
  18366. #define FS_FILTER_RELEASE_FOR_SECTION_SYNCHRONIZATION (UCHAR)-2
  18367. #define FS_FILTER_ACQUIRE_FOR_MOD_WRITE (UCHAR)-3
  18368. #define FS_FILTER_RELEASE_FOR_MOD_WRITE (UCHAR)-4
  18369. #define FS_FILTER_ACQUIRE_FOR_CC_FLUSH (UCHAR)-5
  18370. #define FS_FILTER_RELEASE_FOR_CC_FLUSH (UCHAR)-6
  18371. typedef struct _FS_FILTER_CALLBACK_DATA {
  18372. ULONG SizeOfFsFilterCallbackData;
  18373. UCHAR Operation;
  18374. UCHAR Reserved;
  18375. struct _DEVICE_OBJECT *DeviceObject;
  18376. struct _FILE_OBJECT *FileObject;
  18377. FS_FILTER_PARAMETERS Parameters;
  18378. } FS_FILTER_CALLBACK_DATA, *PFS_FILTER_CALLBACK_DATA;
  18379. //
  18380. // Prototype for the callbacks received before an operation
  18381. // is passed to the base file system.
  18382. //
  18383. // A filter can fail this operation, but consistant failure
  18384. // will halt system progress.
  18385. //
  18386. typedef
  18387. NTSTATUS
  18388. (*PFS_FILTER_CALLBACK) (
  18389. IN PFS_FILTER_CALLBACK_DATA Data,
  18390. OUT PVOID *CompletionContext
  18391. );
  18392. //
  18393. // Prototype for the completion callback received after an
  18394. // operation is completed.
  18395. //
  18396. typedef
  18397. VOID
  18398. (*PFS_FILTER_COMPLETION_CALLBACK) (
  18399. IN PFS_FILTER_CALLBACK_DATA Data,
  18400. IN NTSTATUS OperationStatus,
  18401. IN PVOID CompletionContext
  18402. );
  18403. //
  18404. // This is the structure that the file system filter fills in to
  18405. // receive notifications for these locking operations.
  18406. //
  18407. // A filter should set the field to NULL for any notification callback
  18408. // it doesn't wish to receive.
  18409. //
  18410. typedef struct _FS_FILTER_CALLBACKS {
  18411. ULONG SizeOfFsFilterCallbacks;
  18412. ULONG Reserved; // For alignment
  18413. PFS_FILTER_CALLBACK PreAcquireForSectionSynchronization;
  18414. PFS_FILTER_COMPLETION_CALLBACK PostAcquireForSectionSynchronization;
  18415. PFS_FILTER_CALLBACK PreReleaseForSectionSynchronization;
  18416. PFS_FILTER_COMPLETION_CALLBACK PostReleaseForSectionSynchronization;
  18417. PFS_FILTER_CALLBACK PreAcquireForCcFlush;
  18418. PFS_FILTER_COMPLETION_CALLBACK PostAcquireForCcFlush;
  18419. PFS_FILTER_CALLBACK PreReleaseForCcFlush;
  18420. PFS_FILTER_COMPLETION_CALLBACK PostReleaseForCcFlush;
  18421. PFS_FILTER_CALLBACK PreAcquireForModifiedPageWriter;
  18422. PFS_FILTER_COMPLETION_CALLBACK PostAcquireForModifiedPageWriter;
  18423. PFS_FILTER_CALLBACK PreReleaseForModifiedPageWriter;
  18424. PFS_FILTER_COMPLETION_CALLBACK PostReleaseForModifiedPageWriter;
  18425. } FS_FILTER_CALLBACKS, *PFS_FILTER_CALLBACKS;
  18426. NTKERNELAPI
  18427. NTSTATUS
  18428. FsRtlRegisterFileSystemFilterCallbacks (
  18429. IN struct _DRIVER_OBJECT *FilterDriverObject,
  18430. IN PFS_FILTER_CALLBACKS Callbacks
  18431. );
  18432. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  18433. //
  18434. // Define the actions that a driver execution routine may request of the
  18435. // adapter/controller allocation routines upon return.
  18436. //
  18437. typedef enum _IO_ALLOCATION_ACTION {
  18438. KeepObject = 1,
  18439. DeallocateObject,
  18440. DeallocateObjectKeepRegisters
  18441. } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
  18442. //
  18443. // Define device driver adapter/controller execution routine.
  18444. //
  18445. typedef
  18446. IO_ALLOCATION_ACTION
  18447. (*PDRIVER_CONTROL) (
  18448. IN struct _DEVICE_OBJECT *DeviceObject,
  18449. IN struct _IRP *Irp,
  18450. IN PVOID MapRegisterBase,
  18451. IN PVOID Context
  18452. );
  18453. //
  18454. // Define the I/O system's security context type for use by file system's
  18455. // when checking access to volumes, files, and directories.
  18456. //
  18457. typedef struct _IO_SECURITY_CONTEXT {
  18458. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  18459. PACCESS_STATE AccessState;
  18460. ACCESS_MASK DesiredAccess;
  18461. ULONG FullCreateOptions;
  18462. } IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
  18463. //
  18464. // Define Volume Parameter Block (VPB) flags.
  18465. //
  18466. #define VPB_MOUNTED 0x00000001
  18467. #define VPB_LOCKED 0x00000002
  18468. #define VPB_PERSISTENT 0x00000004
  18469. #define VPB_REMOVE_PENDING 0x00000008
  18470. #define VPB_RAW_MOUNT 0x00000010
  18471. //
  18472. // Volume Parameter Block (VPB)
  18473. //
  18474. #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR)) // 32 characters
  18475. typedef struct _VPB {
  18476. CSHORT Type;
  18477. CSHORT Size;
  18478. USHORT Flags;
  18479. USHORT VolumeLabelLength; // in bytes
  18480. struct _DEVICE_OBJECT *DeviceObject;
  18481. struct _DEVICE_OBJECT *RealDevice;
  18482. ULONG SerialNumber;
  18483. ULONG ReferenceCount;
  18484. WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
  18485. } VPB, *PVPB;
  18486. #if defined(_WIN64)
  18487. //
  18488. // Use __inline DMA macros (hal.h)
  18489. //
  18490. #ifndef USE_DMA_MACROS
  18491. #define USE_DMA_MACROS
  18492. #endif
  18493. //
  18494. // Only PnP drivers!
  18495. //
  18496. #ifndef NO_LEGACY_DRIVERS
  18497. #define NO_LEGACY_DRIVERS
  18498. #endif
  18499. #endif // _WIN64
  18500. #if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_) || defined(_NTOSP_))
  18501. // begin_wdm
  18502. //
  18503. // Define object type specific fields of various objects used by the I/O system
  18504. //
  18505. typedef struct _DMA_ADAPTER *PADAPTER_OBJECT;
  18506. // end_wdm
  18507. #else
  18508. //
  18509. // Define object type specific fields of various objects used by the I/O system
  18510. //
  18511. typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT; // ntndis
  18512. #endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_ || _NTOSP_)
  18513. // begin_wdm
  18514. //
  18515. // Define Wait Context Block (WCB)
  18516. //
  18517. typedef struct _WAIT_CONTEXT_BLOCK {
  18518. KDEVICE_QUEUE_ENTRY WaitQueueEntry;
  18519. PDRIVER_CONTROL DeviceRoutine;
  18520. PVOID DeviceContext;
  18521. ULONG NumberOfMapRegisters;
  18522. PVOID DeviceObject;
  18523. PVOID CurrentIrp;
  18524. PKDPC BufferChainingDpc;
  18525. } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
  18526. // end_wdm
  18527. typedef struct _CONTROLLER_OBJECT {
  18528. CSHORT Type;
  18529. CSHORT Size;
  18530. PVOID ControllerExtension;
  18531. KDEVICE_QUEUE DeviceWaitQueue;
  18532. ULONG Spare1;
  18533. LARGE_INTEGER Spare2;
  18534. } CONTROLLER_OBJECT, *PCONTROLLER_OBJECT;
  18535. // begin_wdm
  18536. //
  18537. // Define Device Object (DO) flags
  18538. //
  18539. #define DO_VERIFY_VOLUME 0x00000002
  18540. #define DO_BUFFERED_IO 0x00000004
  18541. #define DO_EXCLUSIVE 0x00000008
  18542. #define DO_DIRECT_IO 0x00000010
  18543. #define DO_MAP_IO_BUFFER 0x00000020
  18544. #define DO_DEVICE_HAS_NAME 0x00000040
  18545. #define DO_DEVICE_INITIALIZING 0x00000080
  18546. #define DO_SYSTEM_BOOT_PARTITION 0x00000100
  18547. #define DO_LONG_TERM_REQUESTS 0x00000200
  18548. #define DO_NEVER_LAST_DEVICE 0x00000400
  18549. #define DO_SHUTDOWN_REGISTERED 0x00000800
  18550. #define DO_BUS_ENUMERATED_DEVICE 0x00001000
  18551. #define DO_POWER_PAGABLE 0x00002000
  18552. #define DO_POWER_INRUSH 0x00004000
  18553. #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000
  18554. //
  18555. // Device Object structure definition
  18556. //
  18557. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {
  18558. CSHORT Type;
  18559. USHORT Size;
  18560. LONG ReferenceCount;
  18561. struct _DRIVER_OBJECT *DriverObject;
  18562. struct _DEVICE_OBJECT *NextDevice;
  18563. struct _DEVICE_OBJECT *AttachedDevice;
  18564. struct _IRP *CurrentIrp;
  18565. PIO_TIMER Timer;
  18566. ULONG Flags; // See above: DO_...
  18567. ULONG Characteristics; // See ntioapi: FILE_...
  18568. PVPB Vpb;
  18569. PVOID DeviceExtension;
  18570. DEVICE_TYPE DeviceType;
  18571. CCHAR StackSize;
  18572. union {
  18573. LIST_ENTRY ListEntry;
  18574. WAIT_CONTEXT_BLOCK Wcb;
  18575. } Queue;
  18576. ULONG AlignmentRequirement;
  18577. KDEVICE_QUEUE DeviceQueue;
  18578. KDPC Dpc;
  18579. //
  18580. // The following field is for exclusive use by the filesystem to keep
  18581. // track of the number of Fsp threads currently using the device
  18582. //
  18583. ULONG ActiveThreadCount;
  18584. PSECURITY_DESCRIPTOR SecurityDescriptor;
  18585. KEVENT DeviceLock;
  18586. USHORT SectorSize;
  18587. USHORT Spare1;
  18588. struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
  18589. PVOID Reserved;
  18590. } DEVICE_OBJECT;
  18591. typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT; // ntndis
  18592. struct _DEVICE_OBJECT_POWER_EXTENSION;
  18593. typedef struct _DEVOBJ_EXTENSION {
  18594. CSHORT Type;
  18595. USHORT Size;
  18596. //
  18597. // Public part of the DeviceObjectExtension structure
  18598. //
  18599. PDEVICE_OBJECT DeviceObject; // owning device object
  18600. } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
  18601. //
  18602. // Define Driver Object (DRVO) flags
  18603. //
  18604. #define DRVO_UNLOAD_INVOKED 0x00000001
  18605. #define DRVO_LEGACY_DRIVER 0x00000002
  18606. #define DRVO_BUILTIN_DRIVER 0x00000004 // Driver objects for Hal, PnP Mgr
  18607. // end_wdm
  18608. #define DRVO_REINIT_REGISTERED 0x00000008
  18609. #define DRVO_INITIALIZED 0x00000010
  18610. #define DRVO_BOOTREINIT_REGISTERED 0x00000020
  18611. #define DRVO_LEGACY_RESOURCES 0x00000040
  18612. // begin_wdm
  18613. typedef struct _DRIVER_EXTENSION {
  18614. //
  18615. // Back pointer to Driver Object
  18616. //
  18617. struct _DRIVER_OBJECT *DriverObject;
  18618. //
  18619. // The AddDevice entry point is called by the Plug & Play manager
  18620. // to inform the driver when a new device instance arrives that this
  18621. // driver must control.
  18622. //
  18623. PDRIVER_ADD_DEVICE AddDevice;
  18624. //
  18625. // The count field is used to count the number of times the driver has
  18626. // had its registered reinitialization routine invoked.
  18627. //
  18628. ULONG Count;
  18629. //
  18630. // The service name field is used by the pnp manager to determine
  18631. // where the driver related info is stored in the registry.
  18632. //
  18633. UNICODE_STRING ServiceKeyName;
  18634. //
  18635. // Note: any new shared fields get added here.
  18636. //
  18637. } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
  18638. typedef struct _DRIVER_OBJECT {
  18639. CSHORT Type;
  18640. CSHORT Size;
  18641. //
  18642. // The following links all of the devices created by a single driver
  18643. // together on a list, and the Flags word provides an extensible flag
  18644. // location for driver objects.
  18645. //
  18646. PDEVICE_OBJECT DeviceObject;
  18647. ULONG Flags;
  18648. //
  18649. // The following section describes where the driver is loaded. The count
  18650. // field is used to count the number of times the driver has had its
  18651. // registered reinitialization routine invoked.
  18652. //
  18653. PVOID DriverStart;
  18654. ULONG DriverSize;
  18655. PVOID DriverSection;
  18656. PDRIVER_EXTENSION DriverExtension;
  18657. //
  18658. // The driver name field is used by the error log thread
  18659. // determine the name of the driver that an I/O request is/was bound.
  18660. //
  18661. UNICODE_STRING DriverName;
  18662. //
  18663. // The following section is for registry support. Thise is a pointer
  18664. // to the path to the hardware information in the registry
  18665. //
  18666. PUNICODE_STRING HardwareDatabase;
  18667. //
  18668. // The following section contains the optional pointer to an array of
  18669. // alternate entry points to a driver for "fast I/O" support. Fast I/O
  18670. // is performed by invoking the driver routine directly with separate
  18671. // parameters, rather than using the standard IRP call mechanism. Note
  18672. // that these functions may only be used for synchronous I/O, and when
  18673. // the file is cached.
  18674. //
  18675. PFAST_IO_DISPATCH FastIoDispatch;
  18676. //
  18677. // The following section describes the entry points to this particular
  18678. // driver. Note that the major function dispatch table must be the last
  18679. // field in the object so that it remains extensible.
  18680. //
  18681. PDRIVER_INITIALIZE DriverInit;
  18682. PDRIVER_STARTIO DriverStartIo;
  18683. PDRIVER_UNLOAD DriverUnload;
  18684. PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
  18685. } DRIVER_OBJECT;
  18686. typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT; // ntndis
  18687. //
  18688. // The following structure is pointed to by the SectionObject pointer field
  18689. // of a file object, and is allocated by the various NT file systems.
  18690. //
  18691. typedef struct _SECTION_OBJECT_POINTERS {
  18692. PVOID DataSectionObject;
  18693. PVOID SharedCacheMap;
  18694. PVOID ImageSectionObject;
  18695. } SECTION_OBJECT_POINTERS;
  18696. typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
  18697. //
  18698. // Define the format of a completion message.
  18699. //
  18700. typedef struct _IO_COMPLETION_CONTEXT {
  18701. PVOID Port;
  18702. PVOID Key;
  18703. } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
  18704. //
  18705. // Define File Object (FO) flags
  18706. //
  18707. #define FO_FILE_OPEN 0x00000001
  18708. #define FO_SYNCHRONOUS_IO 0x00000002
  18709. #define FO_ALERTABLE_IO 0x00000004
  18710. #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
  18711. #define FO_WRITE_THROUGH 0x00000010
  18712. #define FO_SEQUENTIAL_ONLY 0x00000020
  18713. #define FO_CACHE_SUPPORTED 0x00000040
  18714. #define FO_NAMED_PIPE 0x00000080
  18715. #define FO_STREAM_FILE 0x00000100
  18716. #define FO_MAILSLOT 0x00000200
  18717. #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
  18718. #define FO_DIRECT_DEVICE_OPEN 0x00000800
  18719. #define FO_FILE_MODIFIED 0x00001000
  18720. #define FO_FILE_SIZE_CHANGED 0x00002000
  18721. #define FO_CLEANUP_COMPLETE 0x00004000
  18722. #define FO_TEMPORARY_FILE 0x00008000
  18723. #define FO_DELETE_ON_CLOSE 0x00010000
  18724. #define FO_OPENED_CASE_SENSITIVE 0x00020000
  18725. #define FO_HANDLE_CREATED 0x00040000
  18726. #define FO_FILE_FAST_IO_READ 0x00080000
  18727. #define FO_RANDOM_ACCESS 0x00100000
  18728. #define FO_FILE_OPEN_CANCELLED 0x00200000
  18729. #define FO_VOLUME_OPEN 0x00400000
  18730. #define FO_FILE_OBJECT_HAS_EXTENSION 0x00800000
  18731. #define FO_REMOTE_ORIGIN 0x01000000
  18732. typedef struct _FILE_OBJECT {
  18733. CSHORT Type;
  18734. CSHORT Size;
  18735. PDEVICE_OBJECT DeviceObject;
  18736. PVPB Vpb;
  18737. PVOID FsContext;
  18738. PVOID FsContext2;
  18739. PSECTION_OBJECT_POINTERS SectionObjectPointer;
  18740. PVOID PrivateCacheMap;
  18741. NTSTATUS FinalStatus;
  18742. struct _FILE_OBJECT *RelatedFileObject;
  18743. BOOLEAN LockOperation;
  18744. BOOLEAN DeletePending;
  18745. BOOLEAN ReadAccess;
  18746. BOOLEAN WriteAccess;
  18747. BOOLEAN DeleteAccess;
  18748. BOOLEAN SharedRead;
  18749. BOOLEAN SharedWrite;
  18750. BOOLEAN SharedDelete;
  18751. ULONG Flags;
  18752. UNICODE_STRING FileName;
  18753. LARGE_INTEGER CurrentByteOffset;
  18754. ULONG Waiters;
  18755. ULONG Busy;
  18756. PVOID LastLock;
  18757. KEVENT Lock;
  18758. KEVENT Event;
  18759. PIO_COMPLETION_CONTEXT CompletionContext;
  18760. } FILE_OBJECT;
  18761. typedef struct _FILE_OBJECT *PFILE_OBJECT; // ntndis
  18762. //
  18763. // Define I/O Request Packet (IRP) flags
  18764. //
  18765. #define IRP_NOCACHE 0x00000001
  18766. #define IRP_PAGING_IO 0x00000002
  18767. #define IRP_MOUNT_COMPLETION 0x00000002
  18768. #define IRP_SYNCHRONOUS_API 0x00000004
  18769. #define IRP_ASSOCIATED_IRP 0x00000008
  18770. #define IRP_BUFFERED_IO 0x00000010
  18771. #define IRP_DEALLOCATE_BUFFER 0x00000020
  18772. #define IRP_INPUT_OPERATION 0x00000040
  18773. #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
  18774. #define IRP_CREATE_OPERATION 0x00000080
  18775. #define IRP_READ_OPERATION 0x00000100
  18776. #define IRP_WRITE_OPERATION 0x00000200
  18777. #define IRP_CLOSE_OPERATION 0x00000400
  18778. // end_wdm
  18779. #define IRP_DEFER_IO_COMPLETION 0x00000800
  18780. #define IRP_OB_QUERY_NAME 0x00001000
  18781. #define IRP_HOLD_DEVICE_QUEUE 0x00002000
  18782. // begin_wdm
  18783. //
  18784. // Define I/O request packet (IRP) alternate flags for allocation control.
  18785. //
  18786. #define IRP_QUOTA_CHARGED 0x01
  18787. #define IRP_ALLOCATED_MUST_SUCCEED 0x02
  18788. #define IRP_ALLOCATED_FIXED_SIZE 0x04
  18789. #define IRP_LOOKASIDE_ALLOCATION 0x08
  18790. //
  18791. // I/O Request Packet (IRP) definition
  18792. //
  18793. typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP {
  18794. CSHORT Type;
  18795. USHORT Size;
  18796. //
  18797. // Define the common fields used to control the IRP.
  18798. //
  18799. //
  18800. // Define a pointer to the Memory Descriptor List (MDL) for this I/O
  18801. // request. This field is only used if the I/O is "direct I/O".
  18802. //
  18803. PMDL MdlAddress;
  18804. //
  18805. // Flags word - used to remember various flags.
  18806. //
  18807. ULONG Flags;
  18808. //
  18809. // The following union is used for one of three purposes:
  18810. //
  18811. // 1. This IRP is an associated IRP. The field is a pointer to a master
  18812. // IRP.
  18813. //
  18814. // 2. This is the master IRP. The field is the count of the number of
  18815. // IRPs which must complete (associated IRPs) before the master can
  18816. // complete.
  18817. //
  18818. // 3. This operation is being buffered and the field is the address of
  18819. // the system space buffer.
  18820. //
  18821. union {
  18822. struct _IRP *MasterIrp;
  18823. LONG IrpCount;
  18824. PVOID SystemBuffer;
  18825. } AssociatedIrp;
  18826. //
  18827. // Thread list entry - allows queueing the IRP to the thread pending I/O
  18828. // request packet list.
  18829. //
  18830. LIST_ENTRY ThreadListEntry;
  18831. //
  18832. // I/O status - final status of operation.
  18833. //
  18834. IO_STATUS_BLOCK IoStatus;
  18835. //
  18836. // Requestor mode - mode of the original requestor of this operation.
  18837. //
  18838. KPROCESSOR_MODE RequestorMode;
  18839. //
  18840. // Pending returned - TRUE if pending was initially returned as the
  18841. // status for this packet.
  18842. //
  18843. BOOLEAN PendingReturned;
  18844. //
  18845. // Stack state information.
  18846. //
  18847. CHAR StackCount;
  18848. CHAR CurrentLocation;
  18849. //
  18850. // Cancel - packet has been canceled.
  18851. //
  18852. BOOLEAN Cancel;
  18853. //
  18854. // Cancel Irql - Irql at which the cancel spinlock was acquired.
  18855. //
  18856. KIRQL CancelIrql;
  18857. //
  18858. // ApcEnvironment - Used to save the APC environment at the time that the
  18859. // packet was initialized.
  18860. //
  18861. CCHAR ApcEnvironment;
  18862. //
  18863. // Allocation control flags.
  18864. //
  18865. UCHAR AllocationFlags;
  18866. //
  18867. // User parameters.
  18868. //
  18869. PIO_STATUS_BLOCK UserIosb;
  18870. PKEVENT UserEvent;
  18871. union {
  18872. struct {
  18873. PIO_APC_ROUTINE UserApcRoutine;
  18874. PVOID UserApcContext;
  18875. } AsynchronousParameters;
  18876. LARGE_INTEGER AllocationSize;
  18877. } Overlay;
  18878. //
  18879. // CancelRoutine - Used to contain the address of a cancel routine supplied
  18880. // by a device driver when the IRP is in a cancelable state.
  18881. //
  18882. PDRIVER_CANCEL CancelRoutine;
  18883. //
  18884. // Note that the UserBuffer parameter is outside of the stack so that I/O
  18885. // completion can copy data back into the user's address space without
  18886. // having to know exactly which service was being invoked. The length
  18887. // of the copy is stored in the second half of the I/O status block. If
  18888. // the UserBuffer field is NULL, then no copy is performed.
  18889. //
  18890. PVOID UserBuffer;
  18891. //
  18892. // Kernel structures
  18893. //
  18894. // The following section contains kernel structures which the IRP needs
  18895. // in order to place various work information in kernel controller system
  18896. // queues. Because the size and alignment cannot be controlled, they are
  18897. // placed here at the end so they just hang off and do not affect the
  18898. // alignment of other fields in the IRP.
  18899. //
  18900. union {
  18901. struct {
  18902. union {
  18903. //
  18904. // DeviceQueueEntry - The device queue entry field is used to
  18905. // queue the IRP to the device driver device queue.
  18906. //
  18907. KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
  18908. struct {
  18909. //
  18910. // The following are available to the driver to use in
  18911. // whatever manner is desired, while the driver owns the
  18912. // packet.
  18913. //
  18914. PVOID DriverContext[4];
  18915. } ;
  18916. } ;
  18917. //
  18918. // Thread - pointer to caller's Thread Control Block.
  18919. //
  18920. PETHREAD Thread;
  18921. //
  18922. // Auxiliary buffer - pointer to any auxiliary buffer that is
  18923. // required to pass information to a driver that is not contained
  18924. // in a normal buffer.
  18925. //
  18926. PCHAR AuxiliaryBuffer;
  18927. //
  18928. // The following unnamed structure must be exactly identical
  18929. // to the unnamed structure used in the minipacket header used
  18930. // for completion queue entries.
  18931. //
  18932. struct {
  18933. //
  18934. // List entry - used to queue the packet to completion queue, among
  18935. // others.
  18936. //
  18937. LIST_ENTRY ListEntry;
  18938. union {
  18939. //
  18940. // Current stack location - contains a pointer to the current
  18941. // IO_STACK_LOCATION structure in the IRP stack. This field
  18942. // should never be directly accessed by drivers. They should
  18943. // use the standard functions.
  18944. //
  18945. struct _IO_STACK_LOCATION *CurrentStackLocation;
  18946. //
  18947. // Minipacket type.
  18948. //
  18949. ULONG PacketType;
  18950. };
  18951. };
  18952. //
  18953. // Original file object - pointer to the original file object
  18954. // that was used to open the file. This field is owned by the
  18955. // I/O system and should not be used by any other drivers.
  18956. //
  18957. PFILE_OBJECT OriginalFileObject;
  18958. } Overlay;
  18959. //
  18960. // APC - This APC control block is used for the special kernel APC as
  18961. // well as for the caller's APC, if one was specified in the original
  18962. // argument list. If so, then the APC is reused for the normal APC for
  18963. // whatever mode the caller was in and the "special" routine that is
  18964. // invoked before the APC gets control simply deallocates the IRP.
  18965. //
  18966. KAPC Apc;
  18967. //
  18968. // CompletionKey - This is the key that is used to distinguish
  18969. // individual I/O operations initiated on a single file handle.
  18970. //
  18971. PVOID CompletionKey;
  18972. } Tail;
  18973. } IRP, *PIRP;
  18974. //
  18975. // Define completion routine types for use in stack locations in an IRP
  18976. //
  18977. typedef
  18978. NTSTATUS
  18979. (*PIO_COMPLETION_ROUTINE) (
  18980. IN PDEVICE_OBJECT DeviceObject,
  18981. IN PIRP Irp,
  18982. IN PVOID Context
  18983. );
  18984. //
  18985. // Define stack location control flags
  18986. //
  18987. #define SL_PENDING_RETURNED 0x01
  18988. #define SL_INVOKE_ON_CANCEL 0x20
  18989. #define SL_INVOKE_ON_SUCCESS 0x40
  18990. #define SL_INVOKE_ON_ERROR 0x80
  18991. //
  18992. // Define flags for various functions
  18993. //
  18994. //
  18995. // Create / Create Named Pipe
  18996. //
  18997. // The following flags must exactly match those in the IoCreateFile call's
  18998. // options. The case sensitive flag is added in later, by the parse routine,
  18999. // and is not an actual option to open. Rather, it is part of the object
  19000. // manager's attributes structure.
  19001. //
  19002. #define SL_FORCE_ACCESS_CHECK 0x01
  19003. #define SL_OPEN_PAGING_FILE 0x02
  19004. #define SL_OPEN_TARGET_DIRECTORY 0x04
  19005. #define SL_CASE_SENSITIVE 0x80
  19006. //
  19007. // Read / Write
  19008. //
  19009. #define SL_KEY_SPECIFIED 0x01
  19010. #define SL_OVERRIDE_VERIFY_VOLUME 0x02
  19011. #define SL_WRITE_THROUGH 0x04
  19012. #define SL_FT_SEQUENTIAL_WRITE 0x08
  19013. //
  19014. // Device I/O Control
  19015. //
  19016. //
  19017. // Same SL_OVERRIDE_VERIFY_VOLUME as for read/write above.
  19018. //
  19019. #define SL_READ_ACCESS_GRANTED 0x01
  19020. #define SL_WRITE_ACCESS_GRANTED 0x04 // Gap for SL_OVERRIDE_VERIFY_VOLUME
  19021. //
  19022. // Lock
  19023. //
  19024. #define SL_FAIL_IMMEDIATELY 0x01
  19025. #define SL_EXCLUSIVE_LOCK 0x02
  19026. //
  19027. // QueryDirectory / QueryEa / QueryQuota
  19028. //
  19029. #define SL_RESTART_SCAN 0x01
  19030. #define SL_RETURN_SINGLE_ENTRY 0x02
  19031. #define SL_INDEX_SPECIFIED 0x04
  19032. //
  19033. // NotifyDirectory
  19034. //
  19035. #define SL_WATCH_TREE 0x01
  19036. //
  19037. // FileSystemControl
  19038. //
  19039. // minor: mount/verify volume
  19040. //
  19041. #define SL_ALLOW_RAW_MOUNT 0x01
  19042. //
  19043. // Define PNP/POWER types required by IRP_MJ_PNP/IRP_MJ_POWER.
  19044. //
  19045. typedef enum _DEVICE_RELATION_TYPE {
  19046. BusRelations,
  19047. EjectionRelations,
  19048. PowerRelations,
  19049. RemovalRelations,
  19050. TargetDeviceRelation,
  19051. SingleBusRelations
  19052. } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
  19053. typedef struct _DEVICE_RELATIONS {
  19054. ULONG Count;
  19055. PDEVICE_OBJECT Objects[1]; // variable length
  19056. } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
  19057. typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
  19058. DeviceUsageTypeUndefined,
  19059. DeviceUsageTypePaging,
  19060. DeviceUsageTypeHibernation,
  19061. DeviceUsageTypeDumpFile
  19062. } DEVICE_USAGE_NOTIFICATION_TYPE;
  19063. // begin_ntminiport
  19064. // workaround overloaded definition (rpc generated headers all define INTERFACE
  19065. // to match the class name).
  19066. #undef INTERFACE
  19067. typedef struct _INTERFACE {
  19068. USHORT Size;
  19069. USHORT Version;
  19070. PVOID Context;
  19071. PINTERFACE_REFERENCE InterfaceReference;
  19072. PINTERFACE_DEREFERENCE InterfaceDereference;
  19073. // interface specific entries go here
  19074. } INTERFACE, *PINTERFACE;
  19075. // end_ntminiport
  19076. typedef struct _DEVICE_CAPABILITIES {
  19077. USHORT Size;
  19078. USHORT Version; // the version documented here is version 1
  19079. ULONG DeviceD1:1;
  19080. ULONG DeviceD2:1;
  19081. ULONG LockSupported:1;
  19082. ULONG EjectSupported:1; // Ejectable in S0
  19083. ULONG Removable:1;
  19084. ULONG DockDevice:1;
  19085. ULONG UniqueID:1;
  19086. ULONG SilentInstall:1;
  19087. ULONG RawDeviceOK:1;
  19088. ULONG SurpriseRemovalOK:1;
  19089. ULONG WakeFromD0:1;
  19090. ULONG WakeFromD1:1;
  19091. ULONG WakeFromD2:1;
  19092. ULONG WakeFromD3:1;
  19093. ULONG HardwareDisabled:1;
  19094. ULONG NonDynamic:1;
  19095. ULONG WarmEjectSupported:1;
  19096. ULONG NoDisplayInUI:1;
  19097. ULONG Reserved:14;
  19098. ULONG Address;
  19099. ULONG UINumber;
  19100. DEVICE_POWER_STATE DeviceState[POWER_SYSTEM_MAXIMUM];
  19101. SYSTEM_POWER_STATE SystemWake;
  19102. DEVICE_POWER_STATE DeviceWake;
  19103. ULONG D1Latency;
  19104. ULONG D2Latency;
  19105. ULONG D3Latency;
  19106. } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
  19107. typedef struct _POWER_SEQUENCE {
  19108. ULONG SequenceD1;
  19109. ULONG SequenceD2;
  19110. ULONG SequenceD3;
  19111. } POWER_SEQUENCE, *PPOWER_SEQUENCE;
  19112. typedef enum {
  19113. BusQueryDeviceID = 0, // <Enumerator>\<Enumerator-specific device id>
  19114. BusQueryHardwareIDs = 1, // Hardware ids
  19115. BusQueryCompatibleIDs = 2, // compatible device ids
  19116. BusQueryInstanceID = 3, // persistent id for this instance of the device
  19117. BusQueryDeviceSerialNumber = 4 // serial number for this device
  19118. } BUS_QUERY_ID_TYPE, *PBUS_QUERY_ID_TYPE;
  19119. typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
  19120. #define PNP_DEVICE_DISABLED 0x00000001
  19121. #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
  19122. #define PNP_DEVICE_FAILED 0x00000004
  19123. #define PNP_DEVICE_REMOVED 0x00000008
  19124. #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
  19125. #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
  19126. typedef enum {
  19127. DeviceTextDescription = 0, // DeviceDesc property
  19128. DeviceTextLocationInformation = 1 // DeviceLocation property
  19129. } DEVICE_TEXT_TYPE, *PDEVICE_TEXT_TYPE;
  19130. //
  19131. // Define I/O Request Packet (IRP) stack locations
  19132. //
  19133. #if !defined(_AMD64_) && !defined(_IA64_)
  19134. #include "pshpack4.h"
  19135. #endif
  19136. // begin_ntndis
  19137. #if defined(_WIN64)
  19138. #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
  19139. #else
  19140. #define POINTER_ALIGNMENT
  19141. #endif
  19142. // end_ntndis
  19143. typedef struct _IO_STACK_LOCATION {
  19144. UCHAR MajorFunction;
  19145. UCHAR MinorFunction;
  19146. UCHAR Flags;
  19147. UCHAR Control;
  19148. //
  19149. // The following user parameters are based on the service that is being
  19150. // invoked. Drivers and file systems can determine which set to use based
  19151. // on the above major and minor function codes.
  19152. //
  19153. union {
  19154. //
  19155. // System service parameters for: NtCreateFile
  19156. //
  19157. struct {
  19158. PIO_SECURITY_CONTEXT SecurityContext;
  19159. ULONG Options;
  19160. USHORT POINTER_ALIGNMENT FileAttributes;
  19161. USHORT ShareAccess;
  19162. ULONG POINTER_ALIGNMENT EaLength;
  19163. } Create;
  19164. //
  19165. // System service parameters for: NtReadFile
  19166. //
  19167. struct {
  19168. ULONG Length;
  19169. ULONG POINTER_ALIGNMENT Key;
  19170. LARGE_INTEGER ByteOffset;
  19171. } Read;
  19172. //
  19173. // System service parameters for: NtWriteFile
  19174. //
  19175. struct {
  19176. ULONG Length;
  19177. ULONG POINTER_ALIGNMENT Key;
  19178. LARGE_INTEGER ByteOffset;
  19179. } Write;
  19180. // end_ntddk end_wdm end_nthal
  19181. //
  19182. // System service parameters for: NtQueryDirectoryFile
  19183. //
  19184. struct {
  19185. ULONG Length;
  19186. PUNICODE_STRING FileName;
  19187. FILE_INFORMATION_CLASS FileInformationClass;
  19188. ULONG POINTER_ALIGNMENT FileIndex;
  19189. } QueryDirectory;
  19190. //
  19191. // System service parameters for: NtNotifyChangeDirectoryFile
  19192. //
  19193. struct {
  19194. ULONG Length;
  19195. ULONG POINTER_ALIGNMENT CompletionFilter;
  19196. } NotifyDirectory;
  19197. // begin_ntddk begin_wdm begin_nthal
  19198. //
  19199. // System service parameters for: NtQueryInformationFile
  19200. //
  19201. struct {
  19202. ULONG Length;
  19203. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  19204. } QueryFile;
  19205. //
  19206. // System service parameters for: NtSetInformationFile
  19207. //
  19208. struct {
  19209. ULONG Length;
  19210. FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
  19211. PFILE_OBJECT FileObject;
  19212. union {
  19213. struct {
  19214. BOOLEAN ReplaceIfExists;
  19215. BOOLEAN AdvanceOnly;
  19216. };
  19217. ULONG ClusterCount;
  19218. HANDLE DeleteHandle;
  19219. };
  19220. } SetFile;
  19221. // end_ntddk end_wdm end_nthal end_ntosp
  19222. //
  19223. // System service parameters for: NtQueryEaFile
  19224. //
  19225. struct {
  19226. ULONG Length;
  19227. PVOID EaList;
  19228. ULONG EaListLength;
  19229. ULONG POINTER_ALIGNMENT EaIndex;
  19230. } QueryEa;
  19231. //
  19232. // System service parameters for: NtSetEaFile
  19233. //
  19234. struct {
  19235. ULONG Length;
  19236. } SetEa;
  19237. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  19238. //
  19239. // System service parameters for: NtQueryVolumeInformationFile
  19240. //
  19241. struct {
  19242. ULONG Length;
  19243. FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
  19244. } QueryVolume;
  19245. // end_ntddk end_wdm end_nthal end_ntosp
  19246. //
  19247. // System service parameters for: NtSetVolumeInformationFile
  19248. //
  19249. struct {
  19250. ULONG Length;
  19251. FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
  19252. } SetVolume;
  19253. // begin_ntosp
  19254. //
  19255. // System service parameters for: NtFsControlFile
  19256. //
  19257. // Note that the user's output buffer is stored in the UserBuffer field
  19258. // and the user's input buffer is stored in the SystemBuffer field.
  19259. //
  19260. struct {
  19261. ULONG OutputBufferLength;
  19262. ULONG POINTER_ALIGNMENT InputBufferLength;
  19263. ULONG POINTER_ALIGNMENT FsControlCode;
  19264. PVOID Type3InputBuffer;
  19265. } FileSystemControl;
  19266. //
  19267. // System service parameters for: NtLockFile/NtUnlockFile
  19268. //
  19269. struct {
  19270. PLARGE_INTEGER Length;
  19271. ULONG POINTER_ALIGNMENT Key;
  19272. LARGE_INTEGER ByteOffset;
  19273. } LockControl;
  19274. // begin_ntddk begin_wdm begin_nthal
  19275. //
  19276. // System service parameters for: NtFlushBuffersFile
  19277. //
  19278. // No extra user-supplied parameters.
  19279. //
  19280. // end_ntddk end_wdm end_nthal
  19281. // end_ntosp
  19282. //
  19283. // System service parameters for: NtCancelIoFile
  19284. //
  19285. // No extra user-supplied parameters.
  19286. //
  19287. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  19288. //
  19289. // System service parameters for: NtDeviceIoControlFile
  19290. //
  19291. // Note that the user's output buffer is stored in the UserBuffer field
  19292. // and the user's input buffer is stored in the SystemBuffer field.
  19293. //
  19294. struct {
  19295. ULONG OutputBufferLength;
  19296. ULONG POINTER_ALIGNMENT InputBufferLength;
  19297. ULONG POINTER_ALIGNMENT IoControlCode;
  19298. PVOID Type3InputBuffer;
  19299. } DeviceIoControl;
  19300. // end_wdm
  19301. //
  19302. // System service parameters for: NtQuerySecurityObject
  19303. //
  19304. struct {
  19305. SECURITY_INFORMATION SecurityInformation;
  19306. ULONG POINTER_ALIGNMENT Length;
  19307. } QuerySecurity;
  19308. //
  19309. // System service parameters for: NtSetSecurityObject
  19310. //
  19311. struct {
  19312. SECURITY_INFORMATION SecurityInformation;
  19313. PSECURITY_DESCRIPTOR SecurityDescriptor;
  19314. } SetSecurity;
  19315. // begin_wdm
  19316. //
  19317. // Non-system service parameters.
  19318. //
  19319. // Parameters for MountVolume
  19320. //
  19321. struct {
  19322. PVPB Vpb;
  19323. PDEVICE_OBJECT DeviceObject;
  19324. } MountVolume;
  19325. //
  19326. // Parameters for VerifyVolume
  19327. //
  19328. struct {
  19329. PVPB Vpb;
  19330. PDEVICE_OBJECT DeviceObject;
  19331. } VerifyVolume;
  19332. //
  19333. // Parameters for Scsi with internal device contorl.
  19334. //
  19335. struct {
  19336. struct _SCSI_REQUEST_BLOCK *Srb;
  19337. } Scsi;
  19338. // end_ntddk end_wdm end_nthal end_ntosp
  19339. //
  19340. // System service parameters for: NtQueryQuotaInformationFile
  19341. //
  19342. struct {
  19343. ULONG Length;
  19344. PSID StartSid;
  19345. PFILE_GET_QUOTA_INFORMATION SidList;
  19346. ULONG SidListLength;
  19347. } QueryQuota;
  19348. //
  19349. // System service parameters for: NtSetQuotaInformationFile
  19350. //
  19351. struct {
  19352. ULONG Length;
  19353. } SetQuota;
  19354. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  19355. //
  19356. // Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
  19357. //
  19358. struct {
  19359. DEVICE_RELATION_TYPE Type;
  19360. } QueryDeviceRelations;
  19361. //
  19362. // Parameters for IRP_MN_QUERY_INTERFACE
  19363. //
  19364. struct {
  19365. CONST GUID *InterfaceType;
  19366. USHORT Size;
  19367. USHORT Version;
  19368. PINTERFACE Interface;
  19369. PVOID InterfaceSpecificData;
  19370. } QueryInterface;
  19371. //
  19372. // Parameters for Cleanup
  19373. //
  19374. // No extra parameters supplied
  19375. //
  19376. //
  19377. // WMI Irps
  19378. //
  19379. struct {
  19380. ULONG_PTR ProviderId;
  19381. PVOID DataPath;
  19382. ULONG BufferSize;
  19383. PVOID Buffer;
  19384. } WMI;
  19385. //
  19386. // Others - driver-specific
  19387. //
  19388. struct {
  19389. PVOID Argument1;
  19390. PVOID Argument2;
  19391. PVOID Argument3;
  19392. PVOID Argument4;
  19393. } Others;
  19394. } Parameters;
  19395. //
  19396. // Save a pointer to this device driver's device object for this request
  19397. // so it can be passed to the completion routine if needed.
  19398. //
  19399. PDEVICE_OBJECT DeviceObject;
  19400. //
  19401. // The following location contains a pointer to the file object for this
  19402. //
  19403. PFILE_OBJECT FileObject;
  19404. //
  19405. // The following routine is invoked depending on the flags in the above
  19406. // flags field.
  19407. //
  19408. PIO_COMPLETION_ROUTINE CompletionRoutine;
  19409. //
  19410. // The following is used to store the address of the context parameter
  19411. // that should be passed to the CompletionRoutine.
  19412. //
  19413. PVOID Context;
  19414. } IO_STACK_LOCATION, *PIO_STACK_LOCATION;
  19415. #if !defined(_AMD64_) && !defined(_IA64_)
  19416. #include "poppack.h"
  19417. #endif
  19418. //
  19419. // Define the share access structure used by file systems to determine
  19420. // whether or not another accessor may open the file.
  19421. //
  19422. typedef struct _SHARE_ACCESS {
  19423. ULONG OpenCount;
  19424. ULONG Readers;
  19425. ULONG Writers;
  19426. ULONG Deleters;
  19427. ULONG SharedRead;
  19428. ULONG SharedWrite;
  19429. ULONG SharedDelete;
  19430. } SHARE_ACCESS, *PSHARE_ACCESS;
  19431. // end_wdm
  19432. //
  19433. // The following structure is used by drivers that are initializing to
  19434. // determine the number of devices of a particular type that have already
  19435. // been initialized. It is also used to track whether or not the AtDisk
  19436. // address range has already been claimed. Finally, it is used by the
  19437. // NtQuerySystemInformation system service to return device type counts.
  19438. //
  19439. typedef struct _CONFIGURATION_INFORMATION {
  19440. //
  19441. // This field indicates the total number of disks in the system. This
  19442. // number should be used by the driver to determine the name of new
  19443. // disks. This field should be updated by the driver as it finds new
  19444. // disks.
  19445. //
  19446. ULONG DiskCount; // Count of hard disks thus far
  19447. ULONG FloppyCount; // Count of floppy disks thus far
  19448. ULONG CdRomCount; // Count of CD-ROM drives thus far
  19449. ULONG TapeCount; // Count of tape drives thus far
  19450. ULONG ScsiPortCount; // Count of SCSI port adapters thus far
  19451. ULONG SerialCount; // Count of serial devices thus far
  19452. ULONG ParallelCount; // Count of parallel devices thus far
  19453. //
  19454. // These next two fields indicate ownership of one of the two IO address
  19455. // spaces that are used by WD1003-compatable disk controllers.
  19456. //
  19457. BOOLEAN AtDiskPrimaryAddressClaimed; // 0x1F0 - 0x1FF
  19458. BOOLEAN AtDiskSecondaryAddressClaimed; // 0x170 - 0x17F
  19459. //
  19460. // Indicates the structure version, as anything value belong this will have been added.
  19461. // Use the structure size as the version.
  19462. //
  19463. ULONG Version;
  19464. //
  19465. // Indicates the total number of medium changer devices in the system.
  19466. // This field will be updated by the drivers as it determines that
  19467. // new devices have been found and will be supported.
  19468. //
  19469. ULONG MediumChangerCount;
  19470. } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
  19471. // end_ntddk end_nthal end_ntosp
  19472. //
  19473. // The following are global counters used by the I/O system to indicate the
  19474. // amount of I/O being performed in the system. The first three counters
  19475. // are just that, counts of operations that have been requested, while the
  19476. // last three counters track the amount of data transferred for each type
  19477. // of I/O request.
  19478. //
  19479. extern KSPIN_LOCK IoStatisticsLock;
  19480. extern ULONG IoReadOperationCount;
  19481. extern ULONG IoWriteOperationCount;
  19482. extern ULONG IoOtherOperationCount;
  19483. extern LARGE_INTEGER IoReadTransferCount;
  19484. extern LARGE_INTEGER IoWriteTransferCount;
  19485. extern LARGE_INTEGER IoOtherTransferCount;
  19486. //
  19487. // It is difficult for cached file systems to properly charge quota
  19488. // for the storage that they allocate on behalf of user file handles,
  19489. // so the following amount of additional quota is charged against each
  19490. // handle as a "best guess" as to the amount of quota the file system
  19491. // will allocate on behalf of this handle.
  19492. //
  19493. //
  19494. // These numbers are totally arbitrary, and can be changed if it turns out
  19495. // that the file systems actually allocate more (or less) on behalf of
  19496. // their file objects. The non-paged pool charge constant is added to the
  19497. // size of a FILE_OBJECT to get the actual charge amount.
  19498. //
  19499. #define IO_FILE_OBJECT_NON_PAGED_POOL_CHARGE 64
  19500. #define IO_FILE_OBJECT_PAGED_POOL_CHARGE 1024
  19501. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  19502. //
  19503. // Public I/O routine definitions
  19504. //
  19505. NTKERNELAPI
  19506. VOID
  19507. IoAcquireCancelSpinLock(
  19508. OUT PKIRQL Irql
  19509. );
  19510. // end_ntddk end_wdm end_nthal end_ntosp
  19511. NTKERNELAPI
  19512. VOID
  19513. IoAcquireVpbSpinLock(
  19514. OUT PKIRQL Irql
  19515. );
  19516. NTKERNELAPI
  19517. PVOID
  19518. IoAllocateErrorLogEntry(
  19519. IN PVOID IoObject,
  19520. IN UCHAR EntrySize
  19521. );
  19522. NTKERNELAPI
  19523. PIRP
  19524. IoAllocateIrp(
  19525. IN CCHAR StackSize,
  19526. IN BOOLEAN ChargeQuota
  19527. );
  19528. NTKERNELAPI
  19529. PMDL
  19530. IoAllocateMdl(
  19531. IN PVOID VirtualAddress,
  19532. IN ULONG Length,
  19533. IN BOOLEAN SecondaryBuffer,
  19534. IN BOOLEAN ChargeQuota,
  19535. IN OUT PIRP Irp OPTIONAL
  19536. );
  19537. typedef enum _IO_PAGING_PRIORITY {
  19538. IoPagingPriorityInvalid, // Returned if a non-paging IO IRP is passed.
  19539. IoPagingPriorityNormal, // For regular paging IO
  19540. IoPagingPriorityHigh, // For high priority paging IO
  19541. IoPagingPriorityReserved1, // Reserved for future use.
  19542. IoPagingPriorityReserved2 // Reserved for future use.
  19543. } IO_PAGING_PRIORITY;
  19544. NTKERNELAPI
  19545. NTSTATUS
  19546. IoAttachDevice(
  19547. IN PDEVICE_OBJECT SourceDevice,
  19548. IN PUNICODE_STRING TargetDevice,
  19549. OUT PDEVICE_OBJECT *AttachedDevice
  19550. );
  19551. // end_wdm
  19552. DECLSPEC_DEPRECATED_DDK // Use IoAttachDeviceToDeviceStack
  19553. NTKERNELAPI
  19554. NTSTATUS
  19555. IoAttachDeviceByPointer(
  19556. IN PDEVICE_OBJECT SourceDevice,
  19557. IN PDEVICE_OBJECT TargetDevice
  19558. );
  19559. // begin_wdm
  19560. NTKERNELAPI
  19561. PDEVICE_OBJECT
  19562. IoAttachDeviceToDeviceStack(
  19563. IN PDEVICE_OBJECT SourceDevice,
  19564. IN PDEVICE_OBJECT TargetDevice
  19565. );
  19566. NTKERNELAPI
  19567. PIRP
  19568. IoBuildAsynchronousFsdRequest(
  19569. IN ULONG MajorFunction,
  19570. IN PDEVICE_OBJECT DeviceObject,
  19571. IN OUT PVOID Buffer OPTIONAL,
  19572. IN ULONG Length OPTIONAL,
  19573. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  19574. IN PIO_STATUS_BLOCK IoStatusBlock OPTIONAL
  19575. );
  19576. NTKERNELAPI
  19577. PIRP
  19578. IoBuildDeviceIoControlRequest(
  19579. IN ULONG IoControlCode,
  19580. IN PDEVICE_OBJECT DeviceObject,
  19581. IN PVOID InputBuffer OPTIONAL,
  19582. IN ULONG InputBufferLength,
  19583. OUT PVOID OutputBuffer OPTIONAL,
  19584. IN ULONG OutputBufferLength,
  19585. IN BOOLEAN InternalDeviceIoControl,
  19586. IN PKEVENT Event,
  19587. OUT PIO_STATUS_BLOCK IoStatusBlock
  19588. );
  19589. NTKERNELAPI
  19590. VOID
  19591. IoBuildPartialMdl(
  19592. IN PMDL SourceMdl,
  19593. IN OUT PMDL TargetMdl,
  19594. IN PVOID VirtualAddress,
  19595. IN ULONG Length
  19596. );
  19597. typedef struct _BOOTDISK_INFORMATION {
  19598. LONGLONG BootPartitionOffset;
  19599. LONGLONG SystemPartitionOffset;
  19600. ULONG BootDeviceSignature;
  19601. ULONG SystemDeviceSignature;
  19602. } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
  19603. //
  19604. // This structure should follow the previous structure field for field.
  19605. //
  19606. typedef struct _BOOTDISK_INFORMATION_EX {
  19607. LONGLONG BootPartitionOffset;
  19608. LONGLONG SystemPartitionOffset;
  19609. ULONG BootDeviceSignature;
  19610. ULONG SystemDeviceSignature;
  19611. GUID BootDeviceGuid;
  19612. GUID SystemDeviceGuid;
  19613. BOOLEAN BootDeviceIsGpt;
  19614. BOOLEAN SystemDeviceIsGpt;
  19615. } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
  19616. NTKERNELAPI
  19617. NTSTATUS
  19618. IoGetBootDiskInformation(
  19619. IN OUT PBOOTDISK_INFORMATION BootDiskInformation,
  19620. IN ULONG Size
  19621. );
  19622. NTKERNELAPI
  19623. PIRP
  19624. IoBuildSynchronousFsdRequest(
  19625. IN ULONG MajorFunction,
  19626. IN PDEVICE_OBJECT DeviceObject,
  19627. IN OUT PVOID Buffer OPTIONAL,
  19628. IN ULONG Length OPTIONAL,
  19629. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  19630. IN PKEVENT Event,
  19631. OUT PIO_STATUS_BLOCK IoStatusBlock
  19632. );
  19633. NTKERNELAPI
  19634. NTSTATUS
  19635. FASTCALL
  19636. IofCallDriver(
  19637. IN PDEVICE_OBJECT DeviceObject,
  19638. IN OUT PIRP Irp
  19639. );
  19640. #define IoCallDriver(a,b) \
  19641. IofCallDriver(a,b)
  19642. NTKERNELAPI
  19643. BOOLEAN
  19644. IoCancelIrp(
  19645. IN PIRP Irp
  19646. );
  19647. NTKERNELAPI
  19648. NTSTATUS
  19649. IoCheckDesiredAccess(
  19650. IN OUT PACCESS_MASK DesiredAccess,
  19651. IN ACCESS_MASK GrantedAccess
  19652. );
  19653. NTKERNELAPI
  19654. NTSTATUS
  19655. IoCheckEaBufferValidity(
  19656. IN PFILE_FULL_EA_INFORMATION EaBuffer,
  19657. IN ULONG EaLength,
  19658. OUT PULONG ErrorOffset
  19659. );
  19660. NTKERNELAPI
  19661. NTSTATUS
  19662. IoCheckFunctionAccess(
  19663. IN ACCESS_MASK GrantedAccess,
  19664. IN UCHAR MajorFunction,
  19665. IN UCHAR MinorFunction,
  19666. IN ULONG IoControlCode,
  19667. IN PVOID Arg1 OPTIONAL,
  19668. IN PVOID Arg2 OPTIONAL
  19669. );
  19670. NTKERNELAPI
  19671. NTSTATUS
  19672. IoCheckQuerySetFileInformation(
  19673. IN FILE_INFORMATION_CLASS FileInformationClass,
  19674. IN ULONG Length,
  19675. IN BOOLEAN SetOperation
  19676. );
  19677. NTKERNELAPI
  19678. NTSTATUS
  19679. IoCheckQuerySetVolumeInformation(
  19680. IN FS_INFORMATION_CLASS FsInformationClass,
  19681. IN ULONG Length,
  19682. IN BOOLEAN SetOperation
  19683. );
  19684. NTKERNELAPI
  19685. NTSTATUS
  19686. IoCheckQuotaBufferValidity(
  19687. IN PFILE_QUOTA_INFORMATION QuotaBuffer,
  19688. IN ULONG QuotaLength,
  19689. OUT PULONG ErrorOffset
  19690. );
  19691. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  19692. NTKERNELAPI
  19693. NTSTATUS
  19694. IoCheckShareAccess(
  19695. IN ACCESS_MASK DesiredAccess,
  19696. IN ULONG DesiredShareAccess,
  19697. IN OUT PFILE_OBJECT FileObject,
  19698. IN OUT PSHARE_ACCESS ShareAccess,
  19699. IN BOOLEAN Update
  19700. );
  19701. //
  19702. // This value should be returned from completion routines to continue
  19703. // completing the IRP upwards. Otherwise, STATUS_MORE_PROCESSING_REQUIRED
  19704. // should be returned.
  19705. //
  19706. #define STATUS_CONTINUE_COMPLETION STATUS_SUCCESS
  19707. //
  19708. // Completion routines can also use this enumeration in place of status codes.
  19709. //
  19710. typedef enum _IO_COMPLETION_ROUTINE_RESULT {
  19711. ContinueCompletion = STATUS_CONTINUE_COMPLETION,
  19712. StopCompletion = STATUS_MORE_PROCESSING_REQUIRED
  19713. } IO_COMPLETION_ROUTINE_RESULT, *PIO_COMPLETION_ROUTINE_RESULT;
  19714. NTKERNELAPI
  19715. VOID
  19716. FASTCALL
  19717. IofCompleteRequest(
  19718. IN PIRP Irp,
  19719. IN CCHAR PriorityBoost
  19720. );
  19721. #define IoCompleteRequest(a,b) \
  19722. IofCompleteRequest(a,b)
  19723. NTKERNELAPI
  19724. NTSTATUS
  19725. IoCreateDevice(
  19726. IN PDRIVER_OBJECT DriverObject,
  19727. IN ULONG DeviceExtensionSize,
  19728. IN PUNICODE_STRING DeviceName OPTIONAL,
  19729. IN DEVICE_TYPE DeviceType,
  19730. IN ULONG DeviceCharacteristics,
  19731. IN BOOLEAN Exclusive,
  19732. OUT PDEVICE_OBJECT *DeviceObject
  19733. );
  19734. #define WDM_MAJORVERSION 0x01
  19735. #define WDM_MINORVERSION 0x30
  19736. NTKERNELAPI
  19737. BOOLEAN
  19738. IoIsWdmVersionAvailable(
  19739. IN UCHAR MajorVersion,
  19740. IN UCHAR MinorVersion
  19741. );
  19742. // end_nthal
  19743. NTKERNELAPI
  19744. NTSTATUS
  19745. IoCreateFile(
  19746. OUT PHANDLE FileHandle,
  19747. IN ACCESS_MASK DesiredAccess,
  19748. IN POBJECT_ATTRIBUTES ObjectAttributes,
  19749. OUT PIO_STATUS_BLOCK IoStatusBlock,
  19750. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  19751. IN ULONG FileAttributes,
  19752. IN ULONG ShareAccess,
  19753. IN ULONG Disposition,
  19754. IN ULONG CreateOptions,
  19755. IN PVOID EaBuffer OPTIONAL,
  19756. IN ULONG EaLength,
  19757. IN CREATE_FILE_TYPE CreateFileType,
  19758. IN PVOID ExtraCreateParameters OPTIONAL,
  19759. IN ULONG Options
  19760. );
  19761. // end_ntddk end_wdm end_ntosp
  19762. NTKERNELAPI
  19763. PFILE_OBJECT
  19764. IoCreateStreamFileObject(
  19765. IN PFILE_OBJECT FileObject OPTIONAL,
  19766. IN PDEVICE_OBJECT DeviceObject OPTIONAL
  19767. );
  19768. NTKERNELAPI
  19769. PFILE_OBJECT
  19770. IoCreateStreamFileObjectEx(
  19771. IN PFILE_OBJECT FileObject OPTIONAL,
  19772. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  19773. OUT PHANDLE FileObjectHandle OPTIONAL
  19774. );
  19775. NTKERNELAPI
  19776. PFILE_OBJECT
  19777. IoCreateStreamFileObjectLite(
  19778. IN PFILE_OBJECT FileObject OPTIONAL,
  19779. IN PDEVICE_OBJECT DeviceObject OPTIONAL
  19780. );
  19781. // begin_nthal begin_ntddk begin_wdm begin_ntosp
  19782. NTKERNELAPI
  19783. PKEVENT
  19784. IoCreateNotificationEvent(
  19785. IN PUNICODE_STRING EventName,
  19786. OUT PHANDLE EventHandle
  19787. );
  19788. NTKERNELAPI
  19789. NTSTATUS
  19790. IoCreateSymbolicLink(
  19791. IN PUNICODE_STRING SymbolicLinkName,
  19792. IN PUNICODE_STRING DeviceName
  19793. );
  19794. NTKERNELAPI
  19795. PKEVENT
  19796. IoCreateSynchronizationEvent(
  19797. IN PUNICODE_STRING EventName,
  19798. OUT PHANDLE EventHandle
  19799. );
  19800. NTKERNELAPI
  19801. NTSTATUS
  19802. IoCreateUnprotectedSymbolicLink(
  19803. IN PUNICODE_STRING SymbolicLinkName,
  19804. IN PUNICODE_STRING DeviceName
  19805. );
  19806. // end_wdm
  19807. //++
  19808. //
  19809. // VOID
  19810. // IoDeassignArcName(
  19811. // IN PUNICODE_STRING ArcName
  19812. // )
  19813. //
  19814. // Routine Description:
  19815. //
  19816. // This routine is invoked by drivers to deassign an ARC name that they
  19817. // created to a device. This is generally only called if the driver is
  19818. // deleting the device object, which means that the driver is probably
  19819. // unloading.
  19820. //
  19821. // Arguments:
  19822. //
  19823. // ArcName - Supplies the ARC name to be removed.
  19824. //
  19825. // Return Value:
  19826. //
  19827. // None.
  19828. //
  19829. //--
  19830. #define IoDeassignArcName( ArcName ) ( \
  19831. IoDeleteSymbolicLink( (ArcName) ) )
  19832. NTKERNELAPI
  19833. VOID
  19834. IoDeleteDevice(
  19835. IN PDEVICE_OBJECT DeviceObject
  19836. );
  19837. NTKERNELAPI
  19838. NTSTATUS
  19839. IoDeleteSymbolicLink(
  19840. IN PUNICODE_STRING SymbolicLinkName
  19841. );
  19842. NTKERNELAPI
  19843. VOID
  19844. IoDetachDevice(
  19845. IN OUT PDEVICE_OBJECT TargetDevice
  19846. );
  19847. NTKERNELAPI
  19848. BOOLEAN
  19849. IoFastQueryNetworkAttributes(
  19850. IN POBJECT_ATTRIBUTES ObjectAttributes,
  19851. IN ACCESS_MASK DesiredAccess,
  19852. IN ULONG OpenOptions,
  19853. OUT PIO_STATUS_BLOCK IoStatus,
  19854. OUT PFILE_NETWORK_OPEN_INFORMATION Buffer
  19855. );
  19856. NTKERNELAPI
  19857. VOID
  19858. IoFreeIrp(
  19859. IN PIRP Irp
  19860. );
  19861. NTKERNELAPI
  19862. VOID
  19863. IoFreeMdl(
  19864. IN PMDL Mdl
  19865. );
  19866. NTKERNELAPI
  19867. PDEVICE_OBJECT
  19868. IoGetAttachedDevice(
  19869. IN PDEVICE_OBJECT DeviceObject
  19870. );
  19871. NTKERNELAPI // ntddk wdm nthal
  19872. PDEVICE_OBJECT // ntddk wdm nthal
  19873. IoGetAttachedDeviceReference( // ntddk wdm nthal
  19874. IN PDEVICE_OBJECT DeviceObject // ntddk wdm nthal
  19875. ); // ntddk wdm nthal
  19876. // ntddk wdm nthal
  19877. NTKERNELAPI
  19878. PDEVICE_OBJECT
  19879. IoGetBaseFileSystemDeviceObject(
  19880. IN PFILE_OBJECT FileObject
  19881. );
  19882. NTKERNELAPI // ntddk nthal ntosp
  19883. PCONFIGURATION_INFORMATION // ntddk nthal ntosp
  19884. IoGetConfigurationInformation( VOID ); // ntddk nthal ntosp
  19885. // begin_ntddk begin_wdm begin_nthal
  19886. //++
  19887. //
  19888. // PIO_STACK_LOCATION
  19889. // IoGetCurrentIrpStackLocation(
  19890. // IN PIRP Irp
  19891. // )
  19892. //
  19893. // Routine Description:
  19894. //
  19895. // This routine is invoked to return a pointer to the current stack location
  19896. // in an I/O Request Packet (IRP).
  19897. //
  19898. // Arguments:
  19899. //
  19900. // Irp - Pointer to the I/O Request Packet.
  19901. //
  19902. // Return Value:
  19903. //
  19904. // The function value is a pointer to the current stack location in the
  19905. // packet.
  19906. //
  19907. //--
  19908. #define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
  19909. // end_nthal end_wdm
  19910. NTKERNELAPI
  19911. PDEVICE_OBJECT
  19912. IoGetDeviceToVerify(
  19913. IN PETHREAD Thread
  19914. );
  19915. // begin_wdm
  19916. NTKERNELAPI
  19917. PVOID
  19918. IoGetDriverObjectExtension(
  19919. IN PDRIVER_OBJECT DriverObject,
  19920. IN PVOID ClientIdentificationAddress
  19921. );
  19922. NTKERNELAPI
  19923. PEPROCESS
  19924. IoGetCurrentProcess(
  19925. VOID
  19926. );
  19927. // begin_nthal
  19928. NTKERNELAPI
  19929. NTSTATUS
  19930. IoGetDeviceObjectPointer(
  19931. IN PUNICODE_STRING ObjectName,
  19932. IN ACCESS_MASK DesiredAccess,
  19933. OUT PFILE_OBJECT *FileObject,
  19934. OUT PDEVICE_OBJECT *DeviceObject
  19935. );
  19936. NTKERNELAPI
  19937. struct _DMA_ADAPTER *
  19938. IoGetDmaAdapter(
  19939. IN PDEVICE_OBJECT PhysicalDeviceObject, OPTIONAL // required for PnP drivers
  19940. IN struct _DEVICE_DESCRIPTION *DeviceDescription,
  19941. IN OUT PULONG NumberOfMapRegisters
  19942. );
  19943. NTKERNELAPI
  19944. BOOLEAN
  19945. IoForwardIrpSynchronously(
  19946. IN PDEVICE_OBJECT DeviceObject,
  19947. IN PIRP Irp
  19948. );
  19949. #define IoForwardAndCatchIrp IoForwardIrpSynchronously
  19950. // end_wdm
  19951. NTKERNELAPI
  19952. PGENERIC_MAPPING
  19953. IoGetFileObjectGenericMapping(
  19954. VOID
  19955. );
  19956. // end_nthal
  19957. // begin_wdm
  19958. //++
  19959. //
  19960. // ULONG
  19961. // IoGetFunctionCodeFromCtlCode(
  19962. // IN ULONG ControlCode
  19963. // )
  19964. //
  19965. // Routine Description:
  19966. //
  19967. // This routine extracts the function code from IOCTL and FSCTL function
  19968. // control codes.
  19969. // This routine should only be used by kernel mode code.
  19970. //
  19971. // Arguments:
  19972. //
  19973. // ControlCode - A function control code (IOCTL or FSCTL) from which the
  19974. // function code must be extracted.
  19975. //
  19976. // Return Value:
  19977. //
  19978. // The extracted function code.
  19979. //
  19980. // Note:
  19981. //
  19982. // The CTL_CODE macro, used to create IOCTL and FSCTL function control
  19983. // codes, is defined in ntioapi.h
  19984. //
  19985. //--
  19986. #define IoGetFunctionCodeFromCtlCode( ControlCode ) (\
  19987. ( ControlCode >> 2) & 0x00000FFF )
  19988. // begin_nthal
  19989. NTKERNELAPI
  19990. PVOID
  19991. IoGetInitialStack(
  19992. VOID
  19993. );
  19994. NTKERNELAPI
  19995. VOID
  19996. IoGetStackLimits (
  19997. OUT PULONG_PTR LowLimit,
  19998. OUT PULONG_PTR HighLimit
  19999. );
  20000. //
  20001. // The following function is used to tell the caller how much stack is available
  20002. //
  20003. FORCEINLINE
  20004. ULONG_PTR
  20005. IoGetRemainingStackSize (
  20006. VOID
  20007. )
  20008. {
  20009. ULONG_PTR Top;
  20010. ULONG_PTR Bottom;
  20011. IoGetStackLimits( &Bottom, &Top );
  20012. return((ULONG_PTR)(&Top) - Bottom );
  20013. }
  20014. //++
  20015. //
  20016. // PIO_STACK_LOCATION
  20017. // IoGetNextIrpStackLocation(
  20018. // IN PIRP Irp
  20019. // )
  20020. //
  20021. // Routine Description:
  20022. //
  20023. // This routine is invoked to return a pointer to the next stack location
  20024. // in an I/O Request Packet (IRP).
  20025. //
  20026. // Arguments:
  20027. //
  20028. // Irp - Pointer to the I/O Request Packet.
  20029. //
  20030. // Return Value:
  20031. //
  20032. // The function value is a pointer to the next stack location in the packet.
  20033. //
  20034. //--
  20035. #define IoGetNextIrpStackLocation( Irp ) (\
  20036. (Irp)->Tail.Overlay.CurrentStackLocation - 1 )
  20037. NTKERNELAPI
  20038. PDEVICE_OBJECT
  20039. IoGetRelatedDeviceObject(
  20040. IN PFILE_OBJECT FileObject
  20041. );
  20042. // end_ntddk end_wdm end_nthal
  20043. NTKERNELAPI
  20044. ULONG
  20045. IoGetRequestorProcessId(
  20046. IN PIRP Irp
  20047. );
  20048. NTKERNELAPI
  20049. PEPROCESS
  20050. IoGetRequestorProcess(
  20051. IN PIRP Irp
  20052. );
  20053. // end_ntosp
  20054. NTKERNELAPI
  20055. PIRP
  20056. IoGetTopLevelIrp(
  20057. VOID
  20058. );
  20059. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  20060. //++
  20061. //
  20062. // VOID
  20063. // IoInitializeDpcRequest(
  20064. // IN PDEVICE_OBJECT DeviceObject,
  20065. // IN PIO_DPC_ROUTINE DpcRoutine
  20066. // )
  20067. //
  20068. // end_ntddk end_wdm end_nthal
  20069. // VOID
  20070. // IoInitializeTheadedDpcRequest(
  20071. // IN PDEVICE_OBJECT DeviceObject,
  20072. // IN PIO_DPC_ROUTINE DpcRoutine
  20073. // )
  20074. //
  20075. // begin_ntddk begin_wdm begin_nthal
  20076. // Routine Description:
  20077. //
  20078. // This routine is invoked to initialize the DPC in a device object for a
  20079. // device driver during its initialization routine. The DPC is used later
  20080. // when the driver interrupt service routine requests that a DPC routine
  20081. // be queued for later execution.
  20082. //
  20083. // Arguments:
  20084. //
  20085. // DeviceObject - Pointer to the device object that the request is for.
  20086. //
  20087. // DpcRoutine - Address of the driver's DPC routine to be executed when
  20088. // the DPC is dequeued for processing.
  20089. //
  20090. // Return Value:
  20091. //
  20092. // None.
  20093. //
  20094. //--
  20095. #define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\
  20096. KeInitializeDpc( &(DeviceObject)->Dpc, \
  20097. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  20098. (DeviceObject) ) )
  20099. // end_ntddk end_wdm end_nthal
  20100. #define IoInitializeThreadedDpcRequest( DeviceObject, DpcRoutine ) (\
  20101. KeInitializeThreadedDpc( &(DeviceObject)->Dpc, \
  20102. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  20103. (DeviceObject) ) )
  20104. // begin_ntddk begin_wdm begin_nthal
  20105. NTKERNELAPI
  20106. VOID
  20107. IoInitializeIrp(
  20108. IN OUT PIRP Irp,
  20109. IN USHORT PacketSize,
  20110. IN CCHAR StackSize
  20111. );
  20112. NTKERNELAPI
  20113. NTSTATUS
  20114. IoInitializeTimer(
  20115. IN PDEVICE_OBJECT DeviceObject,
  20116. IN PIO_TIMER_ROUTINE TimerRoutine,
  20117. IN PVOID Context
  20118. );
  20119. NTKERNELAPI
  20120. VOID
  20121. IoReuseIrp(
  20122. IN OUT PIRP Irp,
  20123. IN NTSTATUS Iostatus
  20124. );
  20125. // end_wdm
  20126. NTKERNELAPI
  20127. VOID
  20128. IoCancelFileOpen(
  20129. IN PDEVICE_OBJECT DeviceObject,
  20130. IN PFILE_OBJECT FileObject
  20131. );
  20132. //++
  20133. //
  20134. // BOOLEAN
  20135. // IoIsErrorUserInduced(
  20136. // IN NTSTATUS Status
  20137. // )
  20138. //
  20139. // Routine Description:
  20140. //
  20141. // This routine is invoked to determine if an error was as a
  20142. // result of user actions. Typically these error are related
  20143. // to removable media and will result in a pop-up.
  20144. //
  20145. // Arguments:
  20146. //
  20147. // Status - The status value to check.
  20148. //
  20149. // Return Value:
  20150. // The function value is TRUE if the user induced the error,
  20151. // otherwise FALSE is returned.
  20152. //
  20153. //--
  20154. #define IoIsErrorUserInduced( Status ) ((BOOLEAN) \
  20155. (((Status) == STATUS_DEVICE_NOT_READY) || \
  20156. ((Status) == STATUS_IO_TIMEOUT) || \
  20157. ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
  20158. ((Status) == STATUS_NO_MEDIA_IN_DEVICE) || \
  20159. ((Status) == STATUS_VERIFY_REQUIRED) || \
  20160. ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
  20161. ((Status) == STATUS_WRONG_VOLUME)))
  20162. // end_ntddk end_wdm end_nthal end_ntosp
  20163. //++
  20164. //
  20165. // BOOLEAN
  20166. // IoIsFileOpenedExclusively(
  20167. // IN PFILE_OBJECT FileObject
  20168. // )
  20169. //
  20170. // Routine Description:
  20171. //
  20172. // This routine is invoked to determine whether the file open represented
  20173. // by the specified file object is opened exclusively.
  20174. //
  20175. // Arguments:
  20176. //
  20177. // FileObject - Pointer to the file object that represents the open instance
  20178. // of the target file to be tested for exclusive access.
  20179. //
  20180. // Return Value:
  20181. //
  20182. // The function value is TRUE if the open instance of the file is exclusive;
  20183. // otherwise FALSE is returned.
  20184. //
  20185. //--
  20186. #define IoIsFileOpenedExclusively( FileObject ) (\
  20187. (BOOLEAN) !((FileObject)->SharedRead || (FileObject)->SharedWrite || (FileObject)->SharedDelete))
  20188. NTKERNELAPI
  20189. BOOLEAN
  20190. IoIsOperationSynchronous(
  20191. IN PIRP Irp
  20192. );
  20193. NTKERNELAPI
  20194. BOOLEAN
  20195. IoIsSystemThread(
  20196. IN PETHREAD Thread
  20197. );
  20198. NTKERNELAPI
  20199. BOOLEAN
  20200. IoIsValidNameGraftingBuffer(
  20201. IN PIRP Irp,
  20202. IN PREPARSE_DATA_BUFFER ReparseBuffer
  20203. );
  20204. // begin_ntddk begin_nthal begin_ntosp
  20205. NTKERNELAPI
  20206. PIRP
  20207. IoMakeAssociatedIrp(
  20208. IN PIRP Irp,
  20209. IN CCHAR StackSize
  20210. );
  20211. // begin_wdm
  20212. //++
  20213. //
  20214. // VOID
  20215. // IoMarkIrpPending(
  20216. // IN OUT PIRP Irp
  20217. // )
  20218. //
  20219. // Routine Description:
  20220. //
  20221. // This routine marks the specified I/O Request Packet (IRP) to indicate
  20222. // that an initial status of STATUS_PENDING was returned to the caller.
  20223. // This is used so that I/O completion can determine whether or not to
  20224. // fully complete the I/O operation requested by the packet.
  20225. //
  20226. // Arguments:
  20227. //
  20228. // Irp - Pointer to the I/O Request Packet to be marked pending.
  20229. //
  20230. // Return Value:
  20231. //
  20232. // None.
  20233. //
  20234. //--
  20235. #define IoMarkIrpPending( Irp ) ( \
  20236. IoGetCurrentIrpStackLocation( (Irp) )->Control |= SL_PENDING_RETURNED )
  20237. NTKERNELAPI
  20238. NTSTATUS
  20239. IoPageRead(
  20240. IN PFILE_OBJECT FileObject,
  20241. IN PMDL MemoryDescriptorList,
  20242. IN PLARGE_INTEGER StartingOffset,
  20243. IN PKEVENT Event,
  20244. OUT PIO_STATUS_BLOCK IoStatusBlock
  20245. );
  20246. NTSTATUS
  20247. IoQueryFileDosDeviceName(
  20248. IN PFILE_OBJECT FileObject,
  20249. OUT POBJECT_NAME_INFORMATION *ObjectNameInformation
  20250. );
  20251. NTKERNELAPI
  20252. NTSTATUS
  20253. IoQueryFileInformation(
  20254. IN PFILE_OBJECT FileObject,
  20255. IN FILE_INFORMATION_CLASS FileInformationClass,
  20256. IN ULONG Length,
  20257. OUT PVOID FileInformation,
  20258. OUT PULONG ReturnedLength
  20259. );
  20260. NTKERNELAPI
  20261. NTSTATUS
  20262. IoQueryVolumeInformation(
  20263. IN PFILE_OBJECT FileObject,
  20264. IN FS_INFORMATION_CLASS FsInformationClass,
  20265. IN ULONG Length,
  20266. OUT PVOID FsInformation,
  20267. OUT PULONG ReturnedLength
  20268. );
  20269. // begin_ntosp
  20270. NTKERNELAPI
  20271. VOID
  20272. IoQueueThreadIrp(
  20273. IN PIRP Irp
  20274. );
  20275. // end_ntosp
  20276. // begin_ntddk begin_nthal begin_ntosp
  20277. NTKERNELAPI
  20278. VOID
  20279. IoRaiseHardError(
  20280. IN PIRP Irp,
  20281. IN PVPB Vpb OPTIONAL,
  20282. IN PDEVICE_OBJECT RealDeviceObject
  20283. );
  20284. NTKERNELAPI
  20285. BOOLEAN
  20286. IoRaiseInformationalHardError(
  20287. IN NTSTATUS ErrorStatus,
  20288. IN PUNICODE_STRING String OPTIONAL,
  20289. IN PKTHREAD Thread OPTIONAL
  20290. );
  20291. NTKERNELAPI
  20292. BOOLEAN
  20293. IoSetThreadHardErrorMode(
  20294. IN BOOLEAN EnableHardErrors
  20295. );
  20296. NTKERNELAPI
  20297. VOID
  20298. IoRegisterBootDriverReinitialization(
  20299. IN PDRIVER_OBJECT DriverObject,
  20300. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  20301. IN PVOID Context
  20302. );
  20303. NTKERNELAPI
  20304. VOID
  20305. IoRegisterDriverReinitialization(
  20306. IN PDRIVER_OBJECT DriverObject,
  20307. IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
  20308. IN PVOID Context
  20309. );
  20310. // end_ntddk end_nthal end_ntosp
  20311. NTKERNELAPI
  20312. VOID
  20313. IoRegisterFileSystem(
  20314. IN OUT PDEVICE_OBJECT DeviceObject
  20315. );
  20316. NTKERNELAPI
  20317. NTSTATUS
  20318. IoRegisterFsRegistrationChange(
  20319. IN PDRIVER_OBJECT DriverObject,
  20320. IN PDRIVER_FS_NOTIFICATION DriverNotificationRoutine
  20321. );
  20322. // begin_ntddk begin_nthal begin_ntosp
  20323. NTKERNELAPI
  20324. NTSTATUS
  20325. IoRegisterShutdownNotification(
  20326. IN PDEVICE_OBJECT DeviceObject
  20327. );
  20328. NTKERNELAPI
  20329. NTSTATUS
  20330. IoRegisterLastChanceShutdownNotification(
  20331. IN PDEVICE_OBJECT DeviceObject
  20332. );
  20333. // begin_wdm
  20334. NTKERNELAPI
  20335. VOID
  20336. IoReleaseCancelSpinLock(
  20337. IN KIRQL Irql
  20338. );
  20339. // end_ntddk end_nthal end_wdm end_ntosp
  20340. NTKERNELAPI
  20341. VOID
  20342. IoReleaseVpbSpinLock(
  20343. IN KIRQL Irql
  20344. );
  20345. // begin_ntddk begin_nthal begin_ntosp
  20346. NTKERNELAPI
  20347. VOID
  20348. IoRemoveShareAccess(
  20349. IN PFILE_OBJECT FileObject,
  20350. IN OUT PSHARE_ACCESS ShareAccess
  20351. );
  20352. DECLSPEC_DEPRECATED_DDK // Use IoReportResourceForDetection
  20353. NTKERNELAPI
  20354. NTSTATUS
  20355. IoReportResourceUsage(
  20356. IN PUNICODE_STRING DriverClassName OPTIONAL,
  20357. IN PDRIVER_OBJECT DriverObject,
  20358. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  20359. IN ULONG DriverListSize OPTIONAL,
  20360. IN PDEVICE_OBJECT DeviceObject,
  20361. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  20362. IN ULONG DeviceListSize OPTIONAL,
  20363. IN BOOLEAN OverrideConflict,
  20364. OUT PBOOLEAN ConflictDetected
  20365. );
  20366. // begin_wdm
  20367. //++
  20368. //
  20369. // VOID
  20370. // IoRequestDpc(
  20371. // IN PDEVICE_OBJECT DeviceObject,
  20372. // IN PIRP Irp,
  20373. // IN PVOID Context
  20374. // )
  20375. //
  20376. // Routine Description:
  20377. //
  20378. // This routine is invoked by the device driver's interrupt service routine
  20379. // to request that a DPC routine be queued for later execution at a lower
  20380. // IRQL.
  20381. //
  20382. // Arguments:
  20383. //
  20384. // DeviceObject - Device object for which the request is being processed.
  20385. //
  20386. // Irp - Pointer to the current I/O Request Packet (IRP) for the specified
  20387. // device.
  20388. //
  20389. // Context - Provides a general context parameter to be passed to the
  20390. // DPC routine.
  20391. //
  20392. // Return Value:
  20393. //
  20394. // None.
  20395. //
  20396. //--
  20397. #define IoRequestDpc( DeviceObject, Irp, Context ) ( \
  20398. KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )
  20399. //++
  20400. //
  20401. // PDRIVER_CANCEL
  20402. // IoSetCancelRoutine(
  20403. // IN PIRP Irp,
  20404. // IN PDRIVER_CANCEL CancelRoutine
  20405. // )
  20406. //
  20407. // Routine Description:
  20408. //
  20409. // This routine is invoked to set the address of a cancel routine which
  20410. // is to be invoked when an I/O packet has been canceled.
  20411. //
  20412. // Arguments:
  20413. //
  20414. // Irp - Pointer to the I/O Request Packet itself.
  20415. //
  20416. // CancelRoutine - Address of the cancel routine that is to be invoked
  20417. // if the IRP is cancelled.
  20418. //
  20419. // Return Value:
  20420. //
  20421. // Previous value of CancelRoutine field in the IRP.
  20422. //
  20423. //--
  20424. #define IoSetCancelRoutine( Irp, NewCancelRoutine ) ( \
  20425. (PDRIVER_CANCEL) (ULONG_PTR) InterlockedExchangePointer( (PVOID *) &(Irp)->CancelRoutine, (PVOID) (ULONG_PTR)(NewCancelRoutine) ) )
  20426. //++
  20427. //
  20428. // VOID
  20429. // IoSetCompletionRoutine(
  20430. // IN PIRP Irp,
  20431. // IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  20432. // IN PVOID Context,
  20433. // IN BOOLEAN InvokeOnSuccess,
  20434. // IN BOOLEAN InvokeOnError,
  20435. // IN BOOLEAN InvokeOnCancel
  20436. // )
  20437. //
  20438. // Routine Description:
  20439. //
  20440. // This routine is invoked to set the address of a completion routine which
  20441. // is to be invoked when an I/O packet has been completed by a lower-level
  20442. // driver.
  20443. //
  20444. // Arguments:
  20445. //
  20446. // Irp - Pointer to the I/O Request Packet itself.
  20447. //
  20448. // CompletionRoutine - Address of the completion routine that is to be
  20449. // invoked once the next level driver completes the packet.
  20450. //
  20451. // Context - Specifies a context parameter to be passed to the completion
  20452. // routine.
  20453. //
  20454. // InvokeOnSuccess - Specifies that the completion routine is invoked when the
  20455. // operation is successfully completed.
  20456. //
  20457. // InvokeOnError - Specifies that the completion routine is invoked when the
  20458. // operation completes with an error status.
  20459. //
  20460. // InvokeOnCancel - Specifies that the completion routine is invoked when the
  20461. // operation is being canceled.
  20462. //
  20463. // Return Value:
  20464. //
  20465. // None.
  20466. //
  20467. //--
  20468. #define IoSetCompletionRoutine( Irp, Routine, CompletionContext, Success, Error, Cancel ) { \
  20469. PIO_STACK_LOCATION __irpSp; \
  20470. ASSERT( (Success) | (Error) | (Cancel) ? (Routine) != NULL : TRUE ); \
  20471. __irpSp = IoGetNextIrpStackLocation( (Irp) ); \
  20472. __irpSp->CompletionRoutine = (Routine); \
  20473. __irpSp->Context = (CompletionContext); \
  20474. __irpSp->Control = 0; \
  20475. if ((Success)) { __irpSp->Control = SL_INVOKE_ON_SUCCESS; } \
  20476. if ((Error)) { __irpSp->Control |= SL_INVOKE_ON_ERROR; } \
  20477. if ((Cancel)) { __irpSp->Control |= SL_INVOKE_ON_CANCEL; } }
  20478. NTSTATUS
  20479. IoSetCompletionRoutineEx(
  20480. IN PDEVICE_OBJECT DeviceObject,
  20481. IN PIRP Irp,
  20482. IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  20483. IN PVOID Context,
  20484. IN BOOLEAN InvokeOnSuccess,
  20485. IN BOOLEAN InvokeOnError,
  20486. IN BOOLEAN InvokeOnCancel
  20487. );
  20488. // end_ntddk end_wdm end_nthal end_ntosp
  20489. NTKERNELAPI
  20490. VOID
  20491. IoSetDeviceToVerify(
  20492. IN PETHREAD Thread,
  20493. IN PDEVICE_OBJECT DeviceObject
  20494. );
  20495. // begin_ntddk begin_nthal begin_ntosp
  20496. NTKERNELAPI
  20497. VOID
  20498. IoSetHardErrorOrVerifyDevice(
  20499. IN PIRP Irp,
  20500. IN PDEVICE_OBJECT DeviceObject
  20501. );
  20502. // end_ntddk end_nthal
  20503. NTKERNELAPI
  20504. NTSTATUS
  20505. IoSetInformation(
  20506. IN PFILE_OBJECT FileObject,
  20507. IN FILE_INFORMATION_CLASS FileInformationClass,
  20508. IN ULONG Length,
  20509. IN PVOID FileInformation
  20510. );
  20511. // end_ntosp
  20512. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  20513. //++
  20514. //
  20515. // VOID
  20516. // IoSetNextIrpStackLocation (
  20517. // IN OUT PIRP Irp
  20518. // )
  20519. //
  20520. // Routine Description:
  20521. //
  20522. // This routine is invoked to set the current IRP stack location to
  20523. // the next stack location, i.e. it "pushes" the stack.
  20524. //
  20525. // Arguments:
  20526. //
  20527. // Irp - Pointer to the I/O Request Packet (IRP).
  20528. //
  20529. // Return Value:
  20530. //
  20531. // None.
  20532. //
  20533. //--
  20534. #define IoSetNextIrpStackLocation( Irp ) { \
  20535. (Irp)->CurrentLocation--; \
  20536. (Irp)->Tail.Overlay.CurrentStackLocation--; }
  20537. //++
  20538. //
  20539. // VOID
  20540. // IoCopyCurrentIrpStackLocationToNext(
  20541. // IN PIRP Irp
  20542. // )
  20543. //
  20544. // Routine Description:
  20545. //
  20546. // This routine is invoked to copy the IRP stack arguments and file
  20547. // pointer from the current IrpStackLocation to the next
  20548. // in an I/O Request Packet (IRP).
  20549. //
  20550. // If the caller wants to call IoCallDriver with a completion routine
  20551. // but does not wish to change the arguments otherwise,
  20552. // the caller first calls IoCopyCurrentIrpStackLocationToNext,
  20553. // then IoSetCompletionRoutine, then IoCallDriver.
  20554. //
  20555. // Arguments:
  20556. //
  20557. // Irp - Pointer to the I/O Request Packet.
  20558. //
  20559. // Return Value:
  20560. //
  20561. // None.
  20562. //
  20563. //--
  20564. #define IoCopyCurrentIrpStackLocationToNext( Irp ) { \
  20565. PIO_STACK_LOCATION __irpSp; \
  20566. PIO_STACK_LOCATION __nextIrpSp; \
  20567. __irpSp = IoGetCurrentIrpStackLocation( (Irp) ); \
  20568. __nextIrpSp = IoGetNextIrpStackLocation( (Irp) ); \
  20569. RtlCopyMemory( __nextIrpSp, __irpSp, FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
  20570. __nextIrpSp->Control = 0; }
  20571. //++
  20572. //
  20573. // VOID
  20574. // IoSkipCurrentIrpStackLocation (
  20575. // IN PIRP Irp
  20576. // )
  20577. //
  20578. // Routine Description:
  20579. //
  20580. // This routine is invoked to increment the current stack location of
  20581. // a given IRP.
  20582. //
  20583. // If the caller wishes to call the next driver in a stack, and does not
  20584. // wish to change the arguments, nor does he wish to set a completion
  20585. // routine, then the caller first calls IoSkipCurrentIrpStackLocation
  20586. // and the calls IoCallDriver.
  20587. //
  20588. // Arguments:
  20589. //
  20590. // Irp - Pointer to the I/O Request Packet.
  20591. //
  20592. // Return Value:
  20593. //
  20594. // None
  20595. //
  20596. //--
  20597. #define IoSkipCurrentIrpStackLocation( Irp ) { \
  20598. (Irp)->CurrentLocation++; \
  20599. (Irp)->Tail.Overlay.CurrentStackLocation++; }
  20600. NTKERNELAPI
  20601. VOID
  20602. IoSetShareAccess(
  20603. IN ACCESS_MASK DesiredAccess,
  20604. IN ULONG DesiredShareAccess,
  20605. IN OUT PFILE_OBJECT FileObject,
  20606. OUT PSHARE_ACCESS ShareAccess
  20607. );
  20608. // end_ntddk end_wdm end_nthal end_ntosp
  20609. NTKERNELAPI
  20610. VOID
  20611. IoSetTopLevelIrp(
  20612. IN PIRP Irp
  20613. );
  20614. //++
  20615. //
  20616. // USHORT
  20617. // IoSizeOfIrp(
  20618. // IN CCHAR StackSize
  20619. // )
  20620. //
  20621. // Routine Description:
  20622. //
  20623. // Determines the size of an IRP given the number of stack locations
  20624. // the IRP will have.
  20625. //
  20626. // Arguments:
  20627. //
  20628. // StackSize - Number of stack locations for the IRP.
  20629. //
  20630. // Return Value:
  20631. //
  20632. // Size in bytes of the IRP.
  20633. //
  20634. //--
  20635. #define IoSizeOfIrp( StackSize ) \
  20636. ((USHORT) (sizeof( IRP ) + ((StackSize) * (sizeof( IO_STACK_LOCATION )))))
  20637. NTKERNELAPI
  20638. VOID
  20639. IoStartTimer(
  20640. IN PDEVICE_OBJECT DeviceObject
  20641. );
  20642. NTKERNELAPI
  20643. VOID
  20644. IoStopTimer(
  20645. IN PDEVICE_OBJECT DeviceObject
  20646. );
  20647. // end_ntddk end_wdm end_nthal end_ntosp
  20648. NTKERNELAPI
  20649. NTSTATUS
  20650. IoSynchronousPageWrite(
  20651. IN PFILE_OBJECT FileObject,
  20652. IN PMDL MemoryDescriptorList,
  20653. IN PLARGE_INTEGER StartingOffset,
  20654. IN PKEVENT Event,
  20655. OUT PIO_STATUS_BLOCK IoStatusBlock
  20656. );
  20657. // begin_ntosp
  20658. NTKERNELAPI
  20659. PEPROCESS
  20660. IoThreadToProcess(
  20661. IN PETHREAD Thread
  20662. );
  20663. // end_ntosp
  20664. NTKERNELAPI
  20665. VOID
  20666. IoUnregisterFileSystem(
  20667. IN OUT PDEVICE_OBJECT DeviceObject
  20668. );
  20669. NTKERNELAPI
  20670. VOID
  20671. IoUnregisterFsRegistrationChange(
  20672. IN PDRIVER_OBJECT DriverObject,
  20673. IN PDRIVER_FS_NOTIFICATION DriverNotificationRoutine
  20674. );
  20675. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  20676. NTKERNELAPI
  20677. VOID
  20678. IoUnregisterShutdownNotification(
  20679. IN PDEVICE_OBJECT DeviceObject
  20680. );
  20681. // end_wdm
  20682. NTKERNELAPI
  20683. VOID
  20684. IoUpdateShareAccess(
  20685. IN PFILE_OBJECT FileObject,
  20686. IN OUT PSHARE_ACCESS ShareAccess
  20687. );
  20688. // end_ntddk end_nthal
  20689. NTKERNELAPI
  20690. NTSTATUS
  20691. IoVerifyVolume(
  20692. IN PDEVICE_OBJECT DeviceObject,
  20693. IN BOOLEAN AllowRawMount
  20694. );
  20695. NTKERNELAPI // ntddk wdm nthal
  20696. VOID // ntddk wdm nthal
  20697. IoWriteErrorLogEntry( // ntddk wdm nthal
  20698. IN PVOID ElEntry // ntddk wdm nthal
  20699. ); // ntddk wdm nthal
  20700. typedef struct _IO_WORKITEM *PIO_WORKITEM;
  20701. typedef
  20702. VOID
  20703. (*PIO_WORKITEM_ROUTINE) (
  20704. IN PDEVICE_OBJECT DeviceObject,
  20705. IN PVOID Context
  20706. );
  20707. PIO_WORKITEM
  20708. IoAllocateWorkItem(
  20709. PDEVICE_OBJECT DeviceObject
  20710. );
  20711. VOID
  20712. IoFreeWorkItem(
  20713. PIO_WORKITEM IoWorkItem
  20714. );
  20715. VOID
  20716. IoQueueWorkItem(
  20717. IN PIO_WORKITEM IoWorkItem,
  20718. IN PIO_WORKITEM_ROUTINE WorkerRoutine,
  20719. IN WORK_QUEUE_TYPE QueueType,
  20720. IN PVOID Context
  20721. );
  20722. NTKERNELAPI
  20723. NTSTATUS
  20724. IoWMIRegistrationControl(
  20725. IN PDEVICE_OBJECT DeviceObject,
  20726. IN ULONG Action
  20727. );
  20728. //
  20729. // Action code for IoWMIRegistrationControl api
  20730. //
  20731. #define WMIREG_ACTION_REGISTER 1
  20732. #define WMIREG_ACTION_DEREGISTER 2
  20733. #define WMIREG_ACTION_REREGISTER 3
  20734. #define WMIREG_ACTION_UPDATE_GUIDS 4
  20735. #define WMIREG_ACTION_BLOCK_IRPS 5
  20736. //
  20737. // Code passed in IRP_MN_REGINFO WMI irp
  20738. //
  20739. #define WMIREGISTER 0
  20740. #define WMIUPDATE 1
  20741. NTKERNELAPI
  20742. NTSTATUS
  20743. IoWMIAllocateInstanceIds(
  20744. IN GUID *Guid,
  20745. IN ULONG InstanceCount,
  20746. OUT ULONG *FirstInstanceId
  20747. );
  20748. NTKERNELAPI
  20749. NTSTATUS
  20750. IoWMISuggestInstanceName(
  20751. IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
  20752. IN PUNICODE_STRING SymbolicLinkName OPTIONAL,
  20753. IN BOOLEAN CombineNames,
  20754. OUT PUNICODE_STRING SuggestedInstanceName
  20755. );
  20756. NTKERNELAPI
  20757. NTSTATUS
  20758. IoWMIWriteEvent(
  20759. IN PVOID WnodeEventItem
  20760. );
  20761. #if defined(_WIN64)
  20762. NTKERNELAPI
  20763. ULONG IoWMIDeviceObjectToProviderId(
  20764. PDEVICE_OBJECT DeviceObject
  20765. );
  20766. #else
  20767. #define IoWMIDeviceObjectToProviderId(DeviceObject) ((ULONG)(DeviceObject))
  20768. #endif
  20769. NTKERNELAPI
  20770. NTSTATUS IoWMIOpenBlock(
  20771. IN GUID *DataBlockGuid,
  20772. IN ULONG DesiredAccess,
  20773. OUT PVOID *DataBlockObject
  20774. );
  20775. NTKERNELAPI
  20776. NTSTATUS IoWMIQueryAllData(
  20777. IN PVOID DataBlockObject,
  20778. IN OUT ULONG *InOutBufferSize,
  20779. OUT /* non paged */ PVOID OutBuffer
  20780. );
  20781. NTKERNELAPI
  20782. NTSTATUS
  20783. IoWMIQueryAllDataMultiple(
  20784. IN PVOID *DataBlockObjectList,
  20785. IN ULONG ObjectCount,
  20786. IN OUT ULONG *InOutBufferSize,
  20787. OUT /* non paged */ PVOID OutBuffer
  20788. );
  20789. NTKERNELAPI
  20790. NTSTATUS
  20791. IoWMIQuerySingleInstance(
  20792. IN PVOID DataBlockObject,
  20793. IN PUNICODE_STRING InstanceName,
  20794. IN OUT ULONG *InOutBufferSize,
  20795. OUT /* non paged */ PVOID OutBuffer
  20796. );
  20797. NTKERNELAPI
  20798. NTSTATUS
  20799. IoWMIQuerySingleInstanceMultiple(
  20800. IN PVOID *DataBlockObjectList,
  20801. IN PUNICODE_STRING InstanceNames,
  20802. IN ULONG ObjectCount,
  20803. IN OUT ULONG *InOutBufferSize,
  20804. OUT /* non paged */ PVOID OutBuffer
  20805. );
  20806. NTKERNELAPI
  20807. NTSTATUS
  20808. IoWMISetSingleInstance(
  20809. IN PVOID DataBlockObject,
  20810. IN PUNICODE_STRING InstanceName,
  20811. IN ULONG Version,
  20812. IN ULONG ValueBufferSize,
  20813. IN PVOID ValueBuffer
  20814. );
  20815. NTKERNELAPI
  20816. NTSTATUS
  20817. IoWMISetSingleItem(
  20818. IN PVOID DataBlockObject,
  20819. IN PUNICODE_STRING InstanceName,
  20820. IN ULONG DataItemId,
  20821. IN ULONG Version,
  20822. IN ULONG ValueBufferSize,
  20823. IN PVOID ValueBuffer
  20824. );
  20825. NTKERNELAPI
  20826. NTSTATUS
  20827. IoWMIExecuteMethod(
  20828. IN PVOID DataBlockObject,
  20829. IN PUNICODE_STRING InstanceName,
  20830. IN ULONG MethodId,
  20831. IN ULONG InBufferSize,
  20832. IN OUT PULONG OutBufferSize,
  20833. IN OUT PUCHAR InOutBuffer
  20834. );
  20835. typedef VOID (*WMI_NOTIFICATION_CALLBACK)(
  20836. PVOID Wnode,
  20837. PVOID Context
  20838. );
  20839. NTKERNELAPI
  20840. NTSTATUS
  20841. IoWMISetNotificationCallback(
  20842. IN PVOID Object,
  20843. IN WMI_NOTIFICATION_CALLBACK Callback,
  20844. IN PVOID Context
  20845. );
  20846. NTKERNELAPI
  20847. NTSTATUS
  20848. IoWMIHandleToInstanceName(
  20849. IN PVOID DataBlockObject,
  20850. IN HANDLE FileHandle,
  20851. OUT PUNICODE_STRING InstanceName
  20852. );
  20853. NTKERNELAPI
  20854. NTSTATUS
  20855. IoWMIDeviceObjectToInstanceName(
  20856. IN PVOID DataBlockObject,
  20857. IN PDEVICE_OBJECT DeviceObject,
  20858. OUT PUNICODE_STRING InstanceName
  20859. );
  20860. #if defined(_WIN64)
  20861. BOOLEAN
  20862. IoIs32bitProcess(
  20863. IN PIRP Irp
  20864. );
  20865. #endif
  20866. NTSTATUS
  20867. IoVolumeDeviceToDosName(
  20868. IN PVOID VolumeDeviceObject,
  20869. OUT PUNICODE_STRING DosName
  20870. );
  20871. NTSTATUS
  20872. IoEnumerateDeviceObjectList(
  20873. IN PDRIVER_OBJECT DriverObject,
  20874. IN PDEVICE_OBJECT *DeviceObjectList,
  20875. IN ULONG DeviceObjectListSize,
  20876. OUT PULONG ActualNumberDeviceObjects
  20877. );
  20878. PDEVICE_OBJECT
  20879. IoGetLowerDeviceObject(
  20880. IN PDEVICE_OBJECT DeviceObject
  20881. );
  20882. PDEVICE_OBJECT
  20883. IoGetDeviceAttachmentBaseRef(
  20884. IN PDEVICE_OBJECT DeviceObject
  20885. );
  20886. NTSTATUS
  20887. IoGetDiskDeviceObject(
  20888. IN PDEVICE_OBJECT FileSystemDeviceObject,
  20889. OUT PDEVICE_OBJECT *DiskDeviceObject
  20890. );
  20891. NTSTATUS
  20892. IoSetSystemPartition(
  20893. PUNICODE_STRING VolumeNameString
  20894. );
  20895. // begin_wdm
  20896. VOID
  20897. IoFreeErrorLogEntry(
  20898. PVOID ElEntry
  20899. );
  20900. // Cancel SAFE API set start
  20901. //
  20902. // The following APIs are to help ease the pain of writing queue packages that
  20903. // handle the cancellation race well. The idea of this set of APIs is to not
  20904. // force a single queue data structure but allow the cancel logic to be hidden
  20905. // from the drivers. A driver implements a queue and as part of its header
  20906. // includes the IO_CSQ structure. In its initialization routine it calls
  20907. // IoInitializeCsq. Then in the dispatch routine when the driver wants to
  20908. // insert an IRP into the queue it calls IoCsqInsertIrp. When the driver wants
  20909. // to remove something from the queue it calls IoCsqRemoveIrp. Note that Insert
  20910. // can fail if the IRP was cancelled in the meantime. Remove can also fail if
  20911. // the IRP was already cancelled.
  20912. //
  20913. // There are typically two modes where drivers queue IRPs. These two modes are
  20914. // covered by the cancel safe queue API set.
  20915. //
  20916. // Mode 1:
  20917. // One is where the driver queues the IRP and at some later
  20918. // point in time dequeues an IRP and issues the IO request.
  20919. // For this mode the driver should use IoCsqInsertIrp and IoCsqRemoveNextIrp.
  20920. // The driver in this case is expected to pass NULL to the irp context
  20921. // parameter in IoInsertIrp.
  20922. //
  20923. // Mode 2:
  20924. // In this the driver queues theIRP, issues the IO request (like issuing a DMA
  20925. // request or writing to a register) and when the IO request completes (either
  20926. // using a DPC or timer) the driver dequeues the IRP and completes it. For this
  20927. // mode the driver should use IoCsqInsertIrp and IoCsqRemoveIrp. In this case
  20928. // the driver should allocate an IRP context and pass it in to IoCsqInsertIrp.
  20929. // The cancel API code creates an association between the IRP and the context
  20930. // and thus ensures that when the time comes to remove the IRP it can ascertain
  20931. // correctly.
  20932. //
  20933. // Note that the cancel API set assumes that the field DriverContext[3] is
  20934. // always available for use and that the driver does not use it.
  20935. //
  20936. //
  20937. // Bookkeeping structure. This should be opaque to drivers.
  20938. // Drivers typically include this as part of their queue headers.
  20939. // Given a CSQ pointer the driver should be able to get its
  20940. // queue header using CONTAINING_RECORD macro
  20941. //
  20942. typedef struct _IO_CSQ IO_CSQ, *PIO_CSQ;
  20943. #define IO_TYPE_CSQ_IRP_CONTEXT 1
  20944. #define IO_TYPE_CSQ 2
  20945. #define IO_TYPE_CSQ_EX 3
  20946. //
  20947. // IRP context structure. This structure is necessary if the driver is using
  20948. // the second mode.
  20949. //
  20950. typedef struct _IO_CSQ_IRP_CONTEXT {
  20951. ULONG Type;
  20952. PIRP Irp;
  20953. PIO_CSQ Csq;
  20954. } IO_CSQ_IRP_CONTEXT, *PIO_CSQ_IRP_CONTEXT;
  20955. //
  20956. // Routines that insert/remove IRP
  20957. //
  20958. typedef VOID
  20959. (*PIO_CSQ_INSERT_IRP)(
  20960. IN struct _IO_CSQ *Csq,
  20961. IN PIRP Irp
  20962. );
  20963. typedef NTSTATUS
  20964. (*PIO_CSQ_INSERT_IRP_EX)(
  20965. IN struct _IO_CSQ *Csq,
  20966. IN PIRP Irp,
  20967. IN OUT PVOID InsertContext
  20968. );
  20969. typedef VOID
  20970. (*PIO_CSQ_REMOVE_IRP)(
  20971. IN PIO_CSQ Csq,
  20972. IN PIRP Irp
  20973. );
  20974. //
  20975. // Retrieves next entry after Irp from the queue.
  20976. // Returns NULL if there are no entries in the queue.
  20977. // If Irp is NUL, returns the entry in the head of the queue.
  20978. // This routine does not remove the IRP from the queue.
  20979. //
  20980. typedef PIRP
  20981. (*PIO_CSQ_PEEK_NEXT_IRP)(
  20982. IN PIO_CSQ Csq,
  20983. IN PIRP Irp,
  20984. IN PVOID PeekContext
  20985. );
  20986. //
  20987. // Lock routine that protects the cancel safe queue.
  20988. //
  20989. typedef VOID
  20990. (*PIO_CSQ_ACQUIRE_LOCK)(
  20991. IN PIO_CSQ Csq,
  20992. OUT PKIRQL Irql
  20993. );
  20994. typedef VOID
  20995. (*PIO_CSQ_RELEASE_LOCK)(
  20996. IN PIO_CSQ Csq,
  20997. IN KIRQL Irql
  20998. );
  20999. //
  21000. // Completes the IRP with STATUS_CANCELLED. IRP is guaranteed to be valid
  21001. // In most cases this routine just calls IoCompleteRequest(Irp, STATUS_CANCELLED);
  21002. //
  21003. typedef VOID
  21004. (*PIO_CSQ_COMPLETE_CANCELED_IRP)(
  21005. IN PIO_CSQ Csq,
  21006. IN PIRP Irp
  21007. );
  21008. //
  21009. // Bookkeeping structure. This should be opaque to drivers.
  21010. // Drivers typically include this as part of their queue headers.
  21011. // Given a CSQ pointer the driver should be able to get its
  21012. // queue header using CONTAINING_RECORD macro
  21013. //
  21014. typedef struct _IO_CSQ {
  21015. ULONG Type;
  21016. PIO_CSQ_INSERT_IRP CsqInsertIrp;
  21017. PIO_CSQ_REMOVE_IRP CsqRemoveIrp;
  21018. PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp;
  21019. PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock;
  21020. PIO_CSQ_RELEASE_LOCK CsqReleaseLock;
  21021. PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp;
  21022. PVOID ReservePointer; // Future expansion
  21023. } IO_CSQ, *PIO_CSQ;
  21024. //
  21025. // Initializes the cancel queue structure.
  21026. //
  21027. NTSTATUS
  21028. IoCsqInitialize(
  21029. IN PIO_CSQ Csq,
  21030. IN PIO_CSQ_INSERT_IRP CsqInsertIrp,
  21031. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  21032. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  21033. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  21034. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  21035. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  21036. );
  21037. NTSTATUS
  21038. IoCsqInitializeEx(
  21039. IN PIO_CSQ Csq,
  21040. IN PIO_CSQ_INSERT_IRP_EX CsqInsertIrp,
  21041. IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
  21042. IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
  21043. IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
  21044. IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
  21045. IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
  21046. );
  21047. //
  21048. // The caller calls this routine to insert the IRP and return STATUS_PENDING.
  21049. //
  21050. VOID
  21051. IoCsqInsertIrp(
  21052. IN PIO_CSQ Csq,
  21053. IN PIRP Irp,
  21054. IN PIO_CSQ_IRP_CONTEXT Context
  21055. );
  21056. NTSTATUS
  21057. IoCsqInsertIrpEx(
  21058. IN PIO_CSQ Csq,
  21059. IN PIRP Irp,
  21060. IN PIO_CSQ_IRP_CONTEXT Context,
  21061. IN PVOID InsertContext
  21062. );
  21063. //
  21064. // Returns an IRP if one can be found. NULL otherwise.
  21065. //
  21066. PIRP
  21067. IoCsqRemoveNextIrp(
  21068. IN PIO_CSQ Csq,
  21069. IN PVOID PeekContext
  21070. );
  21071. //
  21072. // This routine is called from timeout or DPCs.
  21073. // The context is presumably part of the DPC or timer context.
  21074. // If succesfull returns the IRP associated with context.
  21075. //
  21076. PIRP
  21077. IoCsqRemoveIrp(
  21078. IN PIO_CSQ Csq,
  21079. IN PIO_CSQ_IRP_CONTEXT Context
  21080. );
  21081. // Cancel SAFE API set end
  21082. NTSTATUS
  21083. IoCreateFileSpecifyDeviceObjectHint(
  21084. OUT PHANDLE FileHandle,
  21085. IN ACCESS_MASK DesiredAccess,
  21086. IN POBJECT_ATTRIBUTES ObjectAttributes,
  21087. OUT PIO_STATUS_BLOCK IoStatusBlock,
  21088. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  21089. IN ULONG FileAttributes,
  21090. IN ULONG ShareAccess,
  21091. IN ULONG Disposition,
  21092. IN ULONG CreateOptions,
  21093. IN PVOID EaBuffer OPTIONAL,
  21094. IN ULONG EaLength,
  21095. IN CREATE_FILE_TYPE CreateFileType,
  21096. IN PVOID ExtraCreateParameters OPTIONAL,
  21097. IN ULONG Options,
  21098. IN PVOID DeviceObject
  21099. );
  21100. NTSTATUS
  21101. IoAttachDeviceToDeviceStackSafe(
  21102. IN PDEVICE_OBJECT SourceDevice,
  21103. IN PDEVICE_OBJECT TargetDevice,
  21104. OUT PDEVICE_OBJECT *AttachedToDeviceObject
  21105. );
  21106. // end_ntosp
  21107. NTKERNELAPI
  21108. BOOLEAN
  21109. IoIsFileOriginRemote(
  21110. IN PFILE_OBJECT FileObject
  21111. );
  21112. NTKERNELAPI
  21113. NTSTATUS
  21114. IoSetFileOrigin(
  21115. IN PFILE_OBJECT FileObject,
  21116. IN BOOLEAN Remote
  21117. );
  21118. NTSTATUS
  21119. IoValidateDeviceIoControlAccess(
  21120. IN PIRP Irp,
  21121. IN ULONG RequiredAccess
  21122. );
  21123. IO_PAGING_PRIORITY
  21124. FASTCALL
  21125. IoGetPagingIoPriority(
  21126. IN PIRP IRP
  21127. );
  21128. NTKERNELAPI
  21129. PVOID
  21130. PoRegisterSystemState (
  21131. IN PVOID StateHandle,
  21132. IN EXECUTION_STATE Flags
  21133. );
  21134. NTKERNELAPI
  21135. VOID
  21136. PoUnregisterSystemState (
  21137. IN PVOID StateHandle
  21138. );
  21139. // begin_nthal
  21140. NTKERNELAPI
  21141. POWER_STATE
  21142. PoSetPowerState (
  21143. IN PDEVICE_OBJECT DeviceObject,
  21144. IN POWER_STATE_TYPE Type,
  21145. IN POWER_STATE State
  21146. );
  21147. NTKERNELAPI
  21148. NTSTATUS
  21149. PoCallDriver (
  21150. IN PDEVICE_OBJECT DeviceObject,
  21151. IN OUT PIRP Irp
  21152. );
  21153. NTKERNELAPI
  21154. VOID
  21155. PoStartNextPowerIrp(
  21156. IN PIRP Irp
  21157. );
  21158. NTKERNELAPI
  21159. PULONG
  21160. PoRegisterDeviceForIdleDetection (
  21161. IN PDEVICE_OBJECT DeviceObject,
  21162. IN ULONG ConservationIdleTime,
  21163. IN ULONG PerformanceIdleTime,
  21164. IN DEVICE_POWER_STATE State
  21165. );
  21166. #define PoSetDeviceBusy(IdlePointer) \
  21167. *IdlePointer = 0
  21168. //
  21169. // \Callback\PowerState values
  21170. //
  21171. #define PO_CB_SYSTEM_POWER_POLICY 0
  21172. #define PO_CB_AC_STATUS 1
  21173. #define PO_CB_BUTTON_COLLISION 2
  21174. #define PO_CB_SYSTEM_STATE_LOCK 3
  21175. #define PO_CB_LID_SWITCH_STATE 4
  21176. #define PO_CB_PROCESSOR_POWER_POLICY 5
  21177. // end_ntddk end_wdm end_nthal
  21178. // Used for queuing work items to be performed at shutdown time. Same
  21179. // rules apply as per Ex work queues.
  21180. NTKERNELAPI
  21181. NTSTATUS
  21182. PoQueueShutdownWorkItem(
  21183. IN PWORK_QUEUE_ITEM WorkItem
  21184. );
  21185. #if defined(_IA64_)
  21186. DECLSPEC_DEPRECATED_DDK // Use GetDmaRequirement
  21187. NTHALAPI
  21188. ULONG
  21189. HalGetDmaAlignmentRequirement (
  21190. VOID
  21191. );
  21192. #endif
  21193. #if defined(_M_IX86) || defined(_M_AMD64)
  21194. #define HalGetDmaAlignmentRequirement() 1L
  21195. #endif
  21196. NTHALAPI
  21197. VOID
  21198. KeFlushWriteBuffer (
  21199. VOID
  21200. );
  21201. //
  21202. // Performance counter function.
  21203. //
  21204. NTHALAPI
  21205. LARGE_INTEGER
  21206. KeQueryPerformanceCounter (
  21207. OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL
  21208. );
  21209. // begin_ntndis
  21210. //
  21211. // Stall processor execution function.
  21212. //
  21213. NTHALAPI
  21214. VOID
  21215. KeStallExecutionProcessor (
  21216. IN ULONG MicroSeconds
  21217. );
  21218. //
  21219. // Indicates the system may do I/O to physical addresses above 4 GB.
  21220. //
  21221. extern PBOOLEAN Mm64BitPhysicalAddress;
  21222. //
  21223. // Define maximum disk transfer size to be used by MM and Cache Manager,
  21224. // so that packet-oriented disk drivers can optimize their packet allocation
  21225. // to this size.
  21226. //
  21227. #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
  21228. //++
  21229. //
  21230. // ULONG_PTR
  21231. // ROUND_TO_PAGES (
  21232. // IN ULONG_PTR Size
  21233. // )
  21234. //
  21235. // Routine Description:
  21236. //
  21237. // The ROUND_TO_PAGES macro takes a size in bytes and rounds it up to a
  21238. // multiple of the page size.
  21239. //
  21240. // NOTE: This macro fails for values 0xFFFFFFFF - (PAGE_SIZE - 1).
  21241. //
  21242. // Arguments:
  21243. //
  21244. // Size - Size in bytes to round up to a page multiple.
  21245. //
  21246. // Return Value:
  21247. //
  21248. // Returns the size rounded up to a multiple of the page size.
  21249. //
  21250. //--
  21251. #define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  21252. //++
  21253. //
  21254. // ULONG
  21255. // BYTES_TO_PAGES (
  21256. // IN ULONG Size
  21257. // )
  21258. //
  21259. // Routine Description:
  21260. //
  21261. // The BYTES_TO_PAGES macro takes the size in bytes and calculates the
  21262. // number of pages required to contain the bytes.
  21263. //
  21264. // Arguments:
  21265. //
  21266. // Size - Size in bytes.
  21267. //
  21268. // Return Value:
  21269. //
  21270. // Returns the number of pages required to contain the specified size.
  21271. //
  21272. //--
  21273. #define BYTES_TO_PAGES(Size) (((Size) >> PAGE_SHIFT) + \
  21274. (((Size) & (PAGE_SIZE - 1)) != 0))
  21275. //++
  21276. //
  21277. // ULONG
  21278. // BYTE_OFFSET (
  21279. // IN PVOID Va
  21280. // )
  21281. //
  21282. // Routine Description:
  21283. //
  21284. // The BYTE_OFFSET macro takes a virtual address and returns the byte offset
  21285. // of that address within the page.
  21286. //
  21287. // Arguments:
  21288. //
  21289. // Va - Virtual address.
  21290. //
  21291. // Return Value:
  21292. //
  21293. // Returns the byte offset portion of the virtual address.
  21294. //
  21295. //--
  21296. #define BYTE_OFFSET(Va) ((ULONG)((LONG_PTR)(Va) & (PAGE_SIZE - 1)))
  21297. //++
  21298. //
  21299. // PVOID
  21300. // PAGE_ALIGN (
  21301. // IN PVOID Va
  21302. // )
  21303. //
  21304. // Routine Description:
  21305. //
  21306. // The PAGE_ALIGN macro takes a virtual address and returns a page-aligned
  21307. // virtual address for that page.
  21308. //
  21309. // Arguments:
  21310. //
  21311. // Va - Virtual address.
  21312. //
  21313. // Return Value:
  21314. //
  21315. // Returns the page aligned virtual address.
  21316. //
  21317. //--
  21318. #define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
  21319. //++
  21320. //
  21321. // ULONG
  21322. // ADDRESS_AND_SIZE_TO_SPAN_PAGES (
  21323. // IN PVOID Va,
  21324. // IN ULONG Size
  21325. // )
  21326. //
  21327. // Routine Description:
  21328. //
  21329. // The ADDRESS_AND_SIZE_TO_SPAN_PAGES macro takes a virtual address and
  21330. // size and returns the number of pages spanned by the size.
  21331. //
  21332. // Arguments:
  21333. //
  21334. // Va - Virtual address.
  21335. //
  21336. // Size - Size in bytes.
  21337. //
  21338. // Return Value:
  21339. //
  21340. // Returns the number of pages spanned by the size.
  21341. //
  21342. //--
  21343. #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) \
  21344. ((ULONG)((((ULONG_PTR)(Va) & (PAGE_SIZE -1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  21345. #if PRAGMA_DEPRECATED_DDK
  21346. #pragma deprecated(COMPUTE_PAGES_SPANNED) // Use ADDRESS_AND_SIZE_TO_SPAN_PAGES
  21347. #endif
  21348. #define COMPUTE_PAGES_SPANNED(Va, Size) ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
  21349. //++
  21350. // PPFN_NUMBER
  21351. // MmGetMdlPfnArray (
  21352. // IN PMDL Mdl
  21353. // )
  21354. //
  21355. // Routine Description:
  21356. //
  21357. // The MmGetMdlPfnArray routine returns the virtual address of the
  21358. // first element of the array of physical page numbers associated with
  21359. // the MDL.
  21360. //
  21361. // Arguments:
  21362. //
  21363. // Mdl - Pointer to an MDL.
  21364. //
  21365. // Return Value:
  21366. //
  21367. // Returns the virtual address of the first element of the array of
  21368. // physical page numbers associated with the MDL.
  21369. //
  21370. //--
  21371. #define MmGetMdlPfnArray(Mdl) ((PPFN_NUMBER)(Mdl + 1))
  21372. //++
  21373. //
  21374. // PVOID
  21375. // MmGetMdlVirtualAddress (
  21376. // IN PMDL Mdl
  21377. // )
  21378. //
  21379. // Routine Description:
  21380. //
  21381. // The MmGetMdlVirtualAddress returns the virtual address of the buffer
  21382. // described by the Mdl.
  21383. //
  21384. // Arguments:
  21385. //
  21386. // Mdl - Pointer to an MDL.
  21387. //
  21388. // Return Value:
  21389. //
  21390. // Returns the virtual address of the buffer described by the Mdl
  21391. //
  21392. //--
  21393. #define MmGetMdlVirtualAddress(Mdl) \
  21394. ((PVOID) ((PCHAR) ((Mdl)->StartVa) + (Mdl)->ByteOffset))
  21395. //++
  21396. //
  21397. // ULONG
  21398. // MmGetMdlByteCount (
  21399. // IN PMDL Mdl
  21400. // )
  21401. //
  21402. // Routine Description:
  21403. //
  21404. // The MmGetMdlByteCount returns the length in bytes of the buffer
  21405. // described by the Mdl.
  21406. //
  21407. // Arguments:
  21408. //
  21409. // Mdl - Pointer to an MDL.
  21410. //
  21411. // Return Value:
  21412. //
  21413. // Returns the byte count of the buffer described by the Mdl
  21414. //
  21415. //--
  21416. #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
  21417. //++
  21418. //
  21419. // ULONG
  21420. // MmGetMdlByteOffset (
  21421. // IN PMDL Mdl
  21422. // )
  21423. //
  21424. // Routine Description:
  21425. //
  21426. // The MmGetMdlByteOffset returns the byte offset within the page
  21427. // of the buffer described by the Mdl.
  21428. //
  21429. // Arguments:
  21430. //
  21431. // Mdl - Pointer to an MDL.
  21432. //
  21433. // Return Value:
  21434. //
  21435. // Returns the byte offset within the page of the buffer described by the Mdl
  21436. //
  21437. //--
  21438. #define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset)
  21439. //++
  21440. //
  21441. // PVOID
  21442. // MmGetMdlStartVa (
  21443. // IN PMDL Mdl
  21444. // )
  21445. //
  21446. // Routine Description:
  21447. //
  21448. // The MmGetMdlBaseVa returns the virtual address of the buffer
  21449. // described by the Mdl rounded down to the nearest page.
  21450. //
  21451. // Arguments:
  21452. //
  21453. // Mdl - Pointer to an MDL.
  21454. //
  21455. // Return Value:
  21456. //
  21457. // Returns the returns the starting virtual address of the MDL.
  21458. //
  21459. //
  21460. //--
  21461. #define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
  21462. typedef enum _MM_SYSTEM_SIZE {
  21463. MmSmallSystem,
  21464. MmMediumSystem,
  21465. MmLargeSystem
  21466. } MM_SYSTEMSIZE;
  21467. NTKERNELAPI
  21468. MM_SYSTEMSIZE
  21469. MmQuerySystemSize (
  21470. VOID
  21471. );
  21472. // end_wdm
  21473. NTKERNELAPI
  21474. BOOLEAN
  21475. MmIsThisAnNtAsSystem (
  21476. VOID
  21477. );
  21478. NTKERNELAPI
  21479. BOOLEAN
  21480. MmIsRecursiveIoFault(
  21481. VOID
  21482. );
  21483. BOOLEAN
  21484. MmForceSectionClosed (
  21485. IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
  21486. IN BOOLEAN DelayClose
  21487. );
  21488. NTSTATUS
  21489. MmIsVerifierEnabled (
  21490. OUT PULONG VerifierFlags
  21491. );
  21492. NTSTATUS
  21493. MmAddVerifierThunks (
  21494. IN PVOID ThunkBuffer,
  21495. IN ULONG ThunkBufferSize
  21496. );
  21497. typedef enum _MMFLUSH_TYPE {
  21498. MmFlushForDelete,
  21499. MmFlushForWrite
  21500. } MMFLUSH_TYPE;
  21501. BOOLEAN
  21502. MmFlushImageSection (
  21503. IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
  21504. IN MMFLUSH_TYPE FlushType
  21505. );
  21506. BOOLEAN
  21507. MmCanFileBeTruncated (
  21508. IN PSECTION_OBJECT_POINTERS SectionPointer,
  21509. IN PLARGE_INTEGER NewFileSize
  21510. );
  21511. BOOLEAN
  21512. MmSetAddressRangeModified (
  21513. IN PVOID Address,
  21514. IN SIZE_T Length
  21515. );
  21516. NTKERNELAPI
  21517. VOID
  21518. MmProbeAndLockProcessPages (
  21519. IN OUT PMDL MemoryDescriptorList,
  21520. IN PEPROCESS Process,
  21521. IN KPROCESSOR_MODE AccessMode,
  21522. IN LOCK_OPERATION Operation
  21523. );
  21524. // begin_nthal
  21525. //
  21526. // I/O support routines.
  21527. //
  21528. NTKERNELAPI
  21529. VOID
  21530. MmProbeAndLockPages (
  21531. IN OUT PMDL MemoryDescriptorList,
  21532. IN KPROCESSOR_MODE AccessMode,
  21533. IN LOCK_OPERATION Operation
  21534. );
  21535. NTKERNELAPI
  21536. VOID
  21537. MmUnlockPages (
  21538. IN PMDL MemoryDescriptorList
  21539. );
  21540. NTKERNELAPI
  21541. VOID
  21542. MmBuildMdlForNonPagedPool (
  21543. IN OUT PMDL MemoryDescriptorList
  21544. );
  21545. NTKERNELAPI
  21546. PVOID
  21547. MmMapLockedPages (
  21548. IN PMDL MemoryDescriptorList,
  21549. IN KPROCESSOR_MODE AccessMode
  21550. );
  21551. LOGICAL
  21552. MmIsIoSpaceActive (
  21553. IN PHYSICAL_ADDRESS StartAddress,
  21554. IN SIZE_T NumberOfBytes
  21555. );
  21556. NTKERNELAPI
  21557. PVOID
  21558. MmGetSystemRoutineAddress (
  21559. IN PUNICODE_STRING SystemRoutineName
  21560. );
  21561. NTKERNELAPI
  21562. NTSTATUS
  21563. MmAdvanceMdl (
  21564. IN PMDL Mdl,
  21565. IN ULONG NumberOfBytes
  21566. );
  21567. // end_wdm
  21568. NTKERNELAPI
  21569. NTSTATUS
  21570. MmMapUserAddressesToPage (
  21571. IN PVOID BaseAddress,
  21572. IN SIZE_T NumberOfBytes,
  21573. IN PVOID PageAddress
  21574. );
  21575. // begin_wdm
  21576. NTKERNELAPI
  21577. NTSTATUS
  21578. MmProtectMdlSystemAddress (
  21579. IN PMDL MemoryDescriptorList,
  21580. IN ULONG NewProtect
  21581. );
  21582. //
  21583. // _MM_PAGE_PRIORITY_ provides a method for the system to handle requests
  21584. // intelligently in low resource conditions.
  21585. //
  21586. // LowPagePriority should be used when it is acceptable to the driver for the
  21587. // mapping request to fail if the system is low on resources. An example of
  21588. // this could be for a non-critical network connection where the driver can
  21589. // handle the failure case when system resources are close to being depleted.
  21590. //
  21591. // NormalPagePriority should be used when it is acceptable to the driver for the
  21592. // mapping request to fail if the system is very low on resources. An example
  21593. // of this could be for a non-critical local filesystem request.
  21594. //
  21595. // HighPagePriority should be used when it is unacceptable to the driver for the
  21596. // mapping request to fail unless the system is completely out of resources.
  21597. // An example of this would be the paging file path in a driver.
  21598. //
  21599. // begin_ntndis
  21600. typedef enum _MM_PAGE_PRIORITY {
  21601. LowPagePriority,
  21602. NormalPagePriority = 16,
  21603. HighPagePriority = 32
  21604. } MM_PAGE_PRIORITY;
  21605. // end_ntndis
  21606. //
  21607. // Note: This function is not available in WDM 1.0
  21608. //
  21609. NTKERNELAPI
  21610. PVOID
  21611. MmMapLockedPagesSpecifyCache (
  21612. IN PMDL MemoryDescriptorList,
  21613. IN KPROCESSOR_MODE AccessMode,
  21614. IN MEMORY_CACHING_TYPE CacheType,
  21615. IN PVOID BaseAddress,
  21616. IN ULONG BugCheckOnFailure,
  21617. IN MM_PAGE_PRIORITY Priority
  21618. );
  21619. NTKERNELAPI
  21620. VOID
  21621. MmUnmapLockedPages (
  21622. IN PVOID BaseAddress,
  21623. IN PMDL MemoryDescriptorList
  21624. );
  21625. PVOID
  21626. MmAllocateMappingAddress (
  21627. IN SIZE_T NumberOfBytes,
  21628. IN ULONG PoolTag
  21629. );
  21630. VOID
  21631. MmFreeMappingAddress (
  21632. IN PVOID BaseAddress,
  21633. IN ULONG PoolTag
  21634. );
  21635. PVOID
  21636. MmMapLockedPagesWithReservedMapping (
  21637. IN PVOID MappingAddress,
  21638. IN ULONG PoolTag,
  21639. IN PMDL MemoryDescriptorList,
  21640. IN MEMORY_CACHING_TYPE CacheType
  21641. );
  21642. VOID
  21643. MmUnmapReservedMapping (
  21644. IN PVOID BaseAddress,
  21645. IN ULONG PoolTag,
  21646. IN PMDL MemoryDescriptorList
  21647. );
  21648. // end_wdm
  21649. typedef struct _PHYSICAL_MEMORY_RANGE {
  21650. PHYSICAL_ADDRESS BaseAddress;
  21651. LARGE_INTEGER NumberOfBytes;
  21652. } PHYSICAL_MEMORY_RANGE, *PPHYSICAL_MEMORY_RANGE;
  21653. NTKERNELAPI
  21654. NTSTATUS
  21655. MmAddPhysicalMemory (
  21656. IN PPHYSICAL_ADDRESS StartAddress,
  21657. IN OUT PLARGE_INTEGER NumberOfBytes
  21658. );
  21659. NTKERNELAPI
  21660. NTSTATUS
  21661. MmRemovePhysicalMemory (
  21662. IN PPHYSICAL_ADDRESS StartAddress,
  21663. IN OUT PLARGE_INTEGER NumberOfBytes
  21664. );
  21665. NTKERNELAPI
  21666. PPHYSICAL_MEMORY_RANGE
  21667. MmGetPhysicalMemoryRanges (
  21668. VOID
  21669. );
  21670. NTKERNELAPI
  21671. PMDL
  21672. MmAllocatePagesForMdl (
  21673. IN PHYSICAL_ADDRESS LowAddress,
  21674. IN PHYSICAL_ADDRESS HighAddress,
  21675. IN PHYSICAL_ADDRESS SkipBytes,
  21676. IN SIZE_T TotalBytes
  21677. );
  21678. NTKERNELAPI
  21679. VOID
  21680. MmFreePagesFromMdl (
  21681. IN PMDL MemoryDescriptorList
  21682. );
  21683. NTKERNELAPI
  21684. PVOID
  21685. MmMapIoSpace (
  21686. IN PHYSICAL_ADDRESS PhysicalAddress,
  21687. IN SIZE_T NumberOfBytes,
  21688. IN MEMORY_CACHING_TYPE CacheType
  21689. );
  21690. NTKERNELAPI
  21691. VOID
  21692. MmUnmapIoSpace (
  21693. IN PVOID BaseAddress,
  21694. IN SIZE_T NumberOfBytes
  21695. );
  21696. NTKERNELAPI
  21697. PVOID
  21698. MmMapVideoDisplay (
  21699. IN PHYSICAL_ADDRESS PhysicalAddress,
  21700. IN SIZE_T NumberOfBytes,
  21701. IN MEMORY_CACHING_TYPE CacheType
  21702. );
  21703. NTKERNELAPI
  21704. VOID
  21705. MmUnmapVideoDisplay (
  21706. IN PVOID BaseAddress,
  21707. IN SIZE_T NumberOfBytes
  21708. );
  21709. NTKERNELAPI
  21710. PHYSICAL_ADDRESS
  21711. MmGetPhysicalAddress (
  21712. IN PVOID BaseAddress
  21713. );
  21714. NTKERNELAPI
  21715. PVOID
  21716. MmGetVirtualForPhysical (
  21717. IN PHYSICAL_ADDRESS PhysicalAddress
  21718. );
  21719. NTKERNELAPI
  21720. PVOID
  21721. MmAllocateContiguousMemory (
  21722. IN SIZE_T NumberOfBytes,
  21723. IN PHYSICAL_ADDRESS HighestAcceptableAddress
  21724. );
  21725. NTKERNELAPI
  21726. PVOID
  21727. MmAllocateContiguousMemorySpecifyCache (
  21728. IN SIZE_T NumberOfBytes,
  21729. IN PHYSICAL_ADDRESS LowestAcceptableAddress,
  21730. IN PHYSICAL_ADDRESS HighestAcceptableAddress,
  21731. IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
  21732. IN MEMORY_CACHING_TYPE CacheType
  21733. );
  21734. NTKERNELAPI
  21735. VOID
  21736. MmFreeContiguousMemory (
  21737. IN PVOID BaseAddress
  21738. );
  21739. NTKERNELAPI
  21740. VOID
  21741. MmFreeContiguousMemorySpecifyCache (
  21742. IN PVOID BaseAddress,
  21743. IN SIZE_T NumberOfBytes,
  21744. IN MEMORY_CACHING_TYPE CacheType
  21745. );
  21746. NTKERNELAPI
  21747. PVOID
  21748. MmAllocateNonCachedMemory (
  21749. IN SIZE_T NumberOfBytes
  21750. );
  21751. NTKERNELAPI
  21752. VOID
  21753. MmFreeNonCachedMemory (
  21754. IN PVOID BaseAddress,
  21755. IN SIZE_T NumberOfBytes
  21756. );
  21757. NTKERNELAPI
  21758. BOOLEAN
  21759. MmIsAddressValid (
  21760. IN PVOID VirtualAddress
  21761. );
  21762. DECLSPEC_DEPRECATED_DDK
  21763. NTKERNELAPI
  21764. BOOLEAN
  21765. MmIsNonPagedSystemAddressValid (
  21766. IN PVOID VirtualAddress
  21767. );
  21768. // begin_wdm
  21769. NTKERNELAPI
  21770. SIZE_T
  21771. MmSizeOfMdl (
  21772. IN PVOID Base,
  21773. IN SIZE_T Length
  21774. );
  21775. DECLSPEC_DEPRECATED_DDK // Use IoAllocateMdl
  21776. NTKERNELAPI
  21777. PMDL
  21778. MmCreateMdl (
  21779. IN PMDL MemoryDescriptorList OPTIONAL,
  21780. IN PVOID Base,
  21781. IN SIZE_T Length
  21782. );
  21783. NTKERNELAPI
  21784. PVOID
  21785. MmLockPagableDataSection (
  21786. IN PVOID AddressWithinSection
  21787. );
  21788. // end_wdm
  21789. NTKERNELAPI
  21790. VOID
  21791. MmLockPagableSectionByHandle (
  21792. IN PVOID ImageSectionHandle
  21793. );
  21794. NTKERNELAPI
  21795. VOID
  21796. MmResetDriverPaging (
  21797. IN PVOID AddressWithinSection
  21798. );
  21799. NTKERNELAPI
  21800. PVOID
  21801. MmPageEntireDriver (
  21802. IN PVOID AddressWithinSection
  21803. );
  21804. NTKERNELAPI
  21805. VOID
  21806. MmUnlockPagableImageSection(
  21807. IN PVOID ImageSectionHandle
  21808. );
  21809. // end_wdm end_ntosp
  21810. // begin_ntosp
  21811. //
  21812. // Note that even though this function prototype
  21813. // says "HANDLE", MmSecureVirtualMemory does NOT return
  21814. // anything resembling a Win32-style handle. The return
  21815. // value from this function can ONLY be used with MmUnsecureVirtualMemory.
  21816. //
  21817. NTKERNELAPI
  21818. HANDLE
  21819. MmSecureVirtualMemory (
  21820. IN PVOID Address,
  21821. IN SIZE_T Size,
  21822. IN ULONG ProbeMode
  21823. );
  21824. NTKERNELAPI
  21825. VOID
  21826. MmUnsecureVirtualMemory (
  21827. IN HANDLE SecureHandle
  21828. );
  21829. // end_ntosp
  21830. NTKERNELAPI
  21831. NTSTATUS
  21832. MmMapViewInSystemSpace (
  21833. IN PVOID Section,
  21834. OUT PVOID *MappedBase,
  21835. IN PSIZE_T ViewSize
  21836. );
  21837. NTKERNELAPI
  21838. NTSTATUS
  21839. MmUnmapViewInSystemSpace (
  21840. IN PVOID MappedBase
  21841. );
  21842. // begin_ntosp
  21843. NTKERNELAPI
  21844. NTSTATUS
  21845. MmMapViewInSessionSpace (
  21846. IN PVOID Section,
  21847. OUT PVOID *MappedBase,
  21848. IN OUT PSIZE_T ViewSize
  21849. );
  21850. NTKERNELAPI
  21851. NTSTATUS
  21852. MmUnmapViewInSessionSpace (
  21853. IN PVOID MappedBase
  21854. );
  21855. // end_ntosp
  21856. // begin_wdm begin_ntosp
  21857. //++
  21858. //
  21859. // VOID
  21860. // MmInitializeMdl (
  21861. // IN PMDL MemoryDescriptorList,
  21862. // IN PVOID BaseVa,
  21863. // IN SIZE_T Length
  21864. // )
  21865. //
  21866. // Routine Description:
  21867. //
  21868. // This routine initializes the header of a Memory Descriptor List (MDL).
  21869. //
  21870. // Arguments:
  21871. //
  21872. // MemoryDescriptorList - Pointer to the MDL to initialize.
  21873. //
  21874. // BaseVa - Base virtual address mapped by the MDL.
  21875. //
  21876. // Length - Length, in bytes, of the buffer mapped by the MDL.
  21877. //
  21878. // Return Value:
  21879. //
  21880. // None.
  21881. //
  21882. //--
  21883. #define MmInitializeMdl(MemoryDescriptorList, BaseVa, Length) { \
  21884. (MemoryDescriptorList)->Next = (PMDL) NULL; \
  21885. (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
  21886. (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa), (Length)))); \
  21887. (MemoryDescriptorList)->MdlFlags = 0; \
  21888. (MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN((BaseVa)); \
  21889. (MemoryDescriptorList)->ByteOffset = BYTE_OFFSET((BaseVa)); \
  21890. (MemoryDescriptorList)->ByteCount = (ULONG)(Length); \
  21891. }
  21892. //++
  21893. //
  21894. // PVOID
  21895. // MmGetSystemAddressForMdlSafe (
  21896. // IN PMDL MDL,
  21897. // IN MM_PAGE_PRIORITY PRIORITY
  21898. // )
  21899. //
  21900. // Routine Description:
  21901. //
  21902. // This routine returns the mapped address of an MDL. If the
  21903. // Mdl is not already mapped or a system address, it is mapped.
  21904. //
  21905. // Arguments:
  21906. //
  21907. // MemoryDescriptorList - Pointer to the MDL to map.
  21908. //
  21909. // Priority - Supplies an indication as to how important it is that this
  21910. // request succeed under low available PTE conditions.
  21911. //
  21912. // Return Value:
  21913. //
  21914. // Returns the base address where the pages are mapped. The base address
  21915. // has the same offset as the virtual address in the MDL.
  21916. //
  21917. // Unlike MmGetSystemAddressForMdl, Safe guarantees that it will always
  21918. // return NULL on failure instead of bugchecking the system.
  21919. //
  21920. // This macro is not usable by WDM 1.0 drivers as 1.0 did not include
  21921. // MmMapLockedPagesSpecifyCache. The solution for WDM 1.0 drivers is to
  21922. // provide synchronization and set/reset the MDL_MAPPING_CAN_FAIL bit.
  21923. //
  21924. //--
  21925. #define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \
  21926. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  21927. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  21928. ((MDL)->MappedSystemVa) : \
  21929. (MmMapLockedPagesSpecifyCache((MDL), \
  21930. KernelMode, \
  21931. MmCached, \
  21932. NULL, \
  21933. FALSE, \
  21934. (PRIORITY))))
  21935. //++
  21936. //
  21937. // PVOID
  21938. // MmGetSystemAddressForMdl (
  21939. // IN PMDL MDL
  21940. // )
  21941. //
  21942. // Routine Description:
  21943. //
  21944. // This routine returns the mapped address of an MDL, if the
  21945. // Mdl is not already mapped or a system address, it is mapped.
  21946. //
  21947. // Arguments:
  21948. //
  21949. // MemoryDescriptorList - Pointer to the MDL to map.
  21950. //
  21951. // Return Value:
  21952. //
  21953. // Returns the base address where the pages are mapped. The base address
  21954. // has the same offset as the virtual address in the MDL.
  21955. //
  21956. //--
  21957. //#define MmGetSystemAddressForMdl(MDL)
  21958. // (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA)) ?
  21959. // ((MDL)->MappedSystemVa) :
  21960. // ((((MDL)->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL)) ?
  21961. // ((PVOID)((ULONG)(MDL)->StartVa | (MDL)->ByteOffset)) :
  21962. // (MmMapLockedPages((MDL),KernelMode)))))
  21963. #if PRAGMA_DEPRECATED_DDK
  21964. #pragma deprecated(MmGetSystemAddressForMdl) // Use MmGetSystemAddressForMdlSafe
  21965. #endif
  21966. #define MmGetSystemAddressForMdl(MDL) \
  21967. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  21968. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  21969. ((MDL)->MappedSystemVa) : \
  21970. (MmMapLockedPages((MDL),KernelMode)))
  21971. //++
  21972. //
  21973. // VOID
  21974. // MmPrepareMdlForReuse (
  21975. // IN PMDL MDL
  21976. // )
  21977. //
  21978. // Routine Description:
  21979. //
  21980. // This routine will take all of the steps necessary to allow an MDL to be
  21981. // re-used.
  21982. //
  21983. // Arguments:
  21984. //
  21985. // MemoryDescriptorList - Pointer to the MDL that will be re-used.
  21986. //
  21987. // Return Value:
  21988. //
  21989. // None.
  21990. //
  21991. //--
  21992. #define MmPrepareMdlForReuse(MDL) \
  21993. if (((MDL)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
  21994. ASSERT(((MDL)->MdlFlags & MDL_PARTIAL) != 0); \
  21995. MmUnmapLockedPages( (MDL)->MappedSystemVa, (MDL) ); \
  21996. } else if (((MDL)->MdlFlags & MDL_PARTIAL) == 0) { \
  21997. ASSERT(((MDL)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
  21998. }
  21999. typedef NTSTATUS (*PMM_DLL_INITIALIZE)(
  22000. IN PUNICODE_STRING RegistryPath
  22001. );
  22002. typedef NTSTATUS (*PMM_DLL_UNLOAD)(
  22003. VOID
  22004. );
  22005. //
  22006. // Prefetch public interface.
  22007. //
  22008. typedef struct _READ_LIST {
  22009. PFILE_OBJECT FileObject;
  22010. ULONG NumberOfEntries;
  22011. LOGICAL IsImage;
  22012. FILE_SEGMENT_ELEMENT List[ANYSIZE_ARRAY];
  22013. } READ_LIST, *PREAD_LIST;
  22014. NTSTATUS
  22015. MmPrefetchPages (
  22016. IN ULONG NumberOfLists,
  22017. IN PREAD_LIST *ReadLists
  22018. );
  22019. //
  22020. // Object Manager types
  22021. //
  22022. typedef struct _OBJECT_HANDLE_INFORMATION {
  22023. ULONG HandleAttributes;
  22024. ACCESS_MASK GrantedAccess;
  22025. } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
  22026. NTKERNELAPI
  22027. NTSTATUS
  22028. ObReferenceObjectByHandle(
  22029. IN HANDLE Handle,
  22030. IN ACCESS_MASK DesiredAccess,
  22031. IN POBJECT_TYPE ObjectType OPTIONAL,
  22032. IN KPROCESSOR_MODE AccessMode,
  22033. OUT PVOID *Object,
  22034. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL
  22035. );
  22036. NTKERNELAPI
  22037. NTSTATUS
  22038. ObOpenObjectByPointer(
  22039. IN PVOID Object,
  22040. IN ULONG HandleAttributes,
  22041. IN PACCESS_STATE PassedAccessState OPTIONAL,
  22042. IN ACCESS_MASK DesiredAccess OPTIONAL,
  22043. IN POBJECT_TYPE ObjectType OPTIONAL,
  22044. IN KPROCESSOR_MODE AccessMode,
  22045. OUT PHANDLE Handle
  22046. );
  22047. NTKERNELAPI
  22048. VOID
  22049. ObMakeTemporaryObject(
  22050. IN PVOID Object
  22051. );
  22052. #define ObDereferenceObject(a) \
  22053. ObfDereferenceObject(a)
  22054. #define ObReferenceObject(Object) ObfReferenceObject(Object)
  22055. NTKERNELAPI
  22056. LONG_PTR
  22057. FASTCALL
  22058. ObfReferenceObject(
  22059. IN PVOID Object
  22060. );
  22061. NTKERNELAPI
  22062. NTSTATUS
  22063. ObReferenceObjectByPointer(
  22064. IN PVOID Object,
  22065. IN ACCESS_MASK DesiredAccess,
  22066. IN POBJECT_TYPE ObjectType,
  22067. IN KPROCESSOR_MODE AccessMode
  22068. );
  22069. NTKERNELAPI
  22070. LONG_PTR
  22071. FASTCALL
  22072. ObfDereferenceObject(
  22073. IN PVOID Object
  22074. );
  22075. NTKERNELAPI
  22076. NTSTATUS
  22077. ObQueryNameString(
  22078. IN PVOID Object,
  22079. OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
  22080. IN ULONG Length,
  22081. OUT PULONG ReturnLength
  22082. );
  22083. NTSTATUS
  22084. ObGetObjectSecurity(
  22085. IN PVOID Object,
  22086. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
  22087. OUT PBOOLEAN MemoryAllocated
  22088. );
  22089. VOID
  22090. ObReleaseObjectSecurity(
  22091. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  22092. IN BOOLEAN MemoryAllocated
  22093. );
  22094. NTSTATUS
  22095. ObQueryObjectAuditingByHandle(
  22096. IN HANDLE Handle,
  22097. OUT PBOOLEAN GenerateOnClose
  22098. );
  22099. //
  22100. // The following are globally used definitions for an LBN and a VBN
  22101. //
  22102. typedef ULONG LBN;
  22103. typedef LBN *PLBN;
  22104. typedef ULONG VBN;
  22105. typedef VBN *PVBN;
  22106. //
  22107. // Every file system that uses the cache manager must have FsContext
  22108. // of the file object point to a common fcb header structure.
  22109. //
  22110. typedef enum _FAST_IO_POSSIBLE {
  22111. FastIoIsNotPossible = 0,
  22112. FastIoIsPossible,
  22113. FastIoIsQuestionable
  22114. } FAST_IO_POSSIBLE;
  22115. typedef struct _FSRTL_COMMON_FCB_HEADER {
  22116. CSHORT NodeTypeCode;
  22117. CSHORT NodeByteSize;
  22118. //
  22119. // General flags available to FsRtl.
  22120. //
  22121. UCHAR Flags;
  22122. //
  22123. // Indicates if fast I/O is possible or if we should be calling
  22124. // the check for fast I/O routine which is found via the driver
  22125. // object.
  22126. //
  22127. UCHAR IsFastIoPossible; // really type FAST_IO_POSSIBLE
  22128. //
  22129. // Second Flags Field
  22130. //
  22131. UCHAR Flags2;
  22132. //
  22133. // The following reserved field should always be 0
  22134. //
  22135. UCHAR Reserved;
  22136. PERESOURCE Resource;
  22137. PERESOURCE PagingIoResource;
  22138. LARGE_INTEGER AllocationSize;
  22139. LARGE_INTEGER FileSize;
  22140. LARGE_INTEGER ValidDataLength;
  22141. } FSRTL_COMMON_FCB_HEADER;
  22142. typedef FSRTL_COMMON_FCB_HEADER *PFSRTL_COMMON_FCB_HEADER;
  22143. //
  22144. // This Fcb header is used for files which support caching
  22145. // of compressed data, and related new support.
  22146. //
  22147. // We start out by prefixing this structure with the normal
  22148. // FsRtl header from above, which we have to do two different
  22149. // ways for c++ or c.
  22150. //
  22151. #ifdef __cplusplus
  22152. typedef struct _FSRTL_ADVANCED_FCB_HEADER:FSRTL_COMMON_FCB_HEADER {
  22153. #else // __cplusplus
  22154. typedef struct _FSRTL_ADVANCED_FCB_HEADER {
  22155. //
  22156. // Put in the standard FsRtl header fields
  22157. //
  22158. FSRTL_COMMON_FCB_HEADER ;
  22159. #endif // __cplusplus
  22160. //
  22161. // The following two fields are supported only if
  22162. // Flags2 contains FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS
  22163. //
  22164. //
  22165. // This is a pointer to a Fast Mutex which may be used to
  22166. // properly synchronize access to the FsRtl header. The
  22167. // Fast Mutex must be nonpaged.
  22168. //
  22169. PFAST_MUTEX FastMutex;
  22170. //
  22171. // This is a pointer to a list of context structures belonging to
  22172. // filesystem filter drivers that are linked above the filesystem.
  22173. // Each structure is headed by FSRTL_FILTER_CONTEXT.
  22174. //
  22175. LIST_ENTRY FilterContexts;
  22176. } FSRTL_ADVANCED_FCB_HEADER;
  22177. typedef FSRTL_ADVANCED_FCB_HEADER *PFSRTL_ADVANCED_FCB_HEADER;
  22178. //
  22179. // Define FsRtl common header flags
  22180. //
  22181. #define FSRTL_FLAG_FILE_MODIFIED (0x01)
  22182. #define FSRTL_FLAG_FILE_LENGTH_CHANGED (0x02)
  22183. #define FSRTL_FLAG_LIMIT_MODIFIED_PAGES (0x04)
  22184. //
  22185. // Following flags determine how the modified page writer should
  22186. // acquire the file. These flags can't change while either resource
  22187. // is acquired. If neither of these flags is set then the
  22188. // modified/mapped page writer will attempt to acquire the paging io
  22189. // resource shared.
  22190. //
  22191. #define FSRTL_FLAG_ACQUIRE_MAIN_RSRC_EX (0x08)
  22192. #define FSRTL_FLAG_ACQUIRE_MAIN_RSRC_SH (0x10)
  22193. //
  22194. // This flag will be set by the Cache Manager if a view is mapped
  22195. // to a file.
  22196. //
  22197. #define FSRTL_FLAG_USER_MAPPED_FILE (0x20)
  22198. // This flag indicates that the file system is using the
  22199. // FSRTL_ADVANCED_FCB_HEADER structure instead of the FSRTL_COMMON_FCB_HEADER
  22200. // structure.
  22201. //
  22202. #define FSRTL_FLAG_ADVANCED_HEADER (0x40)
  22203. // This flag determines whether there currently is an Eof advance
  22204. // in progress. All such advances must be serialized.
  22205. //
  22206. #define FSRTL_FLAG_EOF_ADVANCE_ACTIVE (0x80)
  22207. //
  22208. // Flag values for Flags2
  22209. //
  22210. // All unused bits are reserved and should NOT be modified.
  22211. //
  22212. //
  22213. // If this flag is set, the Cache Manager will allow modified writing
  22214. // in spite of the value of FsContext2.
  22215. //
  22216. #define FSRTL_FLAG2_DO_MODIFIED_WRITE (0x01)
  22217. //
  22218. // If this flag is set, the additional fields FilterContexts and FastMutex
  22219. // are supported in FSRTL_COMMON_HEADER, and can be used to associate
  22220. // context for filesystem filters with streams.
  22221. //
  22222. #define FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS (0x02)
  22223. //
  22224. // If this flag is set, the cache manager will flush and purge the cache map when
  22225. // a user first maps a file
  22226. //
  22227. #define FSRTL_FLAG2_PURGE_WHEN_MAPPED (0x04)
  22228. //
  22229. // The following constants are used to block top level Irp processing when
  22230. // (in either the fast io or cc case) file system resources have been
  22231. // acquired above the file system, or we are in an Fsp thread.
  22232. //
  22233. #define FSRTL_FSP_TOP_LEVEL_IRP 0x01
  22234. #define FSRTL_CACHE_TOP_LEVEL_IRP 0x02
  22235. #define FSRTL_MOD_WRITE_TOP_LEVEL_IRP 0x03
  22236. #define FSRTL_FAST_IO_TOP_LEVEL_IRP 0x04
  22237. #define FSRTL_MAX_TOP_LEVEL_IRP_FLAG 0xFFFF
  22238. //
  22239. // The following structure is used to synchronize Eof extends.
  22240. //
  22241. typedef struct _EOF_WAIT_BLOCK {
  22242. LIST_ENTRY EofWaitLinks;
  22243. KEVENT Event;
  22244. } EOF_WAIT_BLOCK;
  22245. typedef EOF_WAIT_BLOCK *PEOF_WAIT_BLOCK;
  22246. // begin_ntosp
  22247. //
  22248. // Normal uncompressed Copy and Mdl Apis
  22249. //
  22250. NTKERNELAPI
  22251. BOOLEAN
  22252. FsRtlCopyRead (
  22253. IN PFILE_OBJECT FileObject,
  22254. IN PLARGE_INTEGER FileOffset,
  22255. IN ULONG Length,
  22256. IN BOOLEAN Wait,
  22257. IN ULONG LockKey,
  22258. OUT PVOID Buffer,
  22259. OUT PIO_STATUS_BLOCK IoStatus,
  22260. IN PDEVICE_OBJECT DeviceObject
  22261. );
  22262. NTKERNELAPI
  22263. BOOLEAN
  22264. FsRtlCopyWrite (
  22265. IN PFILE_OBJECT FileObject,
  22266. IN PLARGE_INTEGER FileOffset,
  22267. IN ULONG Length,
  22268. IN BOOLEAN Wait,
  22269. IN ULONG LockKey,
  22270. IN PVOID Buffer,
  22271. OUT PIO_STATUS_BLOCK IoStatus,
  22272. IN PDEVICE_OBJECT DeviceObject
  22273. );
  22274. NTKERNELAPI
  22275. BOOLEAN
  22276. FsRtlMdlReadDev (
  22277. IN PFILE_OBJECT FileObject,
  22278. IN PLARGE_INTEGER FileOffset,
  22279. IN ULONG Length,
  22280. IN ULONG LockKey,
  22281. OUT PMDL *MdlChain,
  22282. OUT PIO_STATUS_BLOCK IoStatus,
  22283. IN PDEVICE_OBJECT DeviceObject
  22284. );
  22285. NTKERNELAPI
  22286. BOOLEAN
  22287. FsRtlMdlReadCompleteDev (
  22288. IN PFILE_OBJECT FileObject,
  22289. IN PMDL MdlChain,
  22290. IN PDEVICE_OBJECT DeviceObject
  22291. );
  22292. NTKERNELAPI
  22293. BOOLEAN
  22294. FsRtlPrepareMdlWriteDev (
  22295. IN PFILE_OBJECT FileObject,
  22296. IN PLARGE_INTEGER FileOffset,
  22297. IN ULONG Length,
  22298. IN ULONG LockKey,
  22299. OUT PMDL *MdlChain,
  22300. OUT PIO_STATUS_BLOCK IoStatus,
  22301. IN PDEVICE_OBJECT DeviceObject
  22302. );
  22303. NTKERNELAPI
  22304. BOOLEAN
  22305. FsRtlMdlWriteCompleteDev (
  22306. IN PFILE_OBJECT FileObject,
  22307. IN PLARGE_INTEGER FileOffset,
  22308. IN PMDL MdlChain,
  22309. IN PDEVICE_OBJECT DeviceObject
  22310. );
  22311. //
  22312. // In Irps, compressed reads and writes are designated by the
  22313. // subfunction IRP_MN_COMPRESSED must be set and the Compressed
  22314. // Data Info buffer must be described by the following structure
  22315. // pointed to by Irp->Tail.Overlay.AuxiliaryBuffer.
  22316. //
  22317. typedef struct _FSRTL_AUXILIARY_BUFFER {
  22318. //
  22319. // Buffer description with length.
  22320. //
  22321. PVOID Buffer;
  22322. ULONG Length;
  22323. //
  22324. // Flags
  22325. //
  22326. ULONG Flags;
  22327. //
  22328. // Pointer to optional Mdl mapping buffer for file system use
  22329. //
  22330. PMDL Mdl;
  22331. } FSRTL_AUXILIARY_BUFFER;
  22332. typedef FSRTL_AUXILIARY_BUFFER *PFSRTL_AUXILIARY_BUFFER;
  22333. //
  22334. // If this flag is set, the auxiliary buffer structure is
  22335. // deallocated on Irp completion. The caller has the
  22336. // option in this case of appending this structure to the
  22337. // structure being described, causing it all to be
  22338. // deallocated at once. If this flag is clear, no deallocate
  22339. // occurs.
  22340. //
  22341. #define FSRTL_AUXILIARY_FLAG_DEALLOCATE 0x00000001
  22342. //
  22343. // The following two routines are called from NtCreateSection to avoid
  22344. // deadlocks with the file systems.
  22345. //
  22346. NTKERNELAPI
  22347. VOID
  22348. FsRtlAcquireFileExclusive (
  22349. IN PFILE_OBJECT FileObject
  22350. );
  22351. NTKERNELAPI
  22352. VOID
  22353. FsRtlReleaseFile (
  22354. IN PFILE_OBJECT FileObject
  22355. );
  22356. //
  22357. // These routines provide a simple interface for the common operations
  22358. // of query/set file size.
  22359. //
  22360. NTSTATUS
  22361. FsRtlGetFileSize(
  22362. IN PFILE_OBJECT FileObject,
  22363. IN OUT PLARGE_INTEGER FileSize
  22364. );
  22365. //
  22366. // Determine if there is a complete device failure on an error.
  22367. //
  22368. NTKERNELAPI
  22369. BOOLEAN
  22370. FsRtlIsTotalDeviceFailure(
  22371. IN NTSTATUS Status
  22372. );
  22373. // end_ntddk
  22374. //
  22375. // Byte range file lock routines, implemented in FileLock.c
  22376. //
  22377. // The file lock info record is used to return enumerated information
  22378. // about a file lock
  22379. //
  22380. typedef struct _FILE_LOCK_INFO {
  22381. //
  22382. // A description of the current locked range, and if the lock
  22383. // is exclusive or shared
  22384. //
  22385. LARGE_INTEGER StartingByte;
  22386. LARGE_INTEGER Length;
  22387. BOOLEAN ExclusiveLock;
  22388. //
  22389. // The following fields describe the owner of the lock.
  22390. //
  22391. ULONG Key;
  22392. PFILE_OBJECT FileObject;
  22393. PVOID ProcessId;
  22394. //
  22395. // The following field is used internally by FsRtl
  22396. //
  22397. LARGE_INTEGER EndingByte;
  22398. } FILE_LOCK_INFO;
  22399. typedef FILE_LOCK_INFO *PFILE_LOCK_INFO;
  22400. //
  22401. // The following two procedure prototypes are used by the caller of the
  22402. // file lock package to supply an alternate routine to call when
  22403. // completing an IRP and when unlocking a byte range. Note that the only
  22404. // utility to us this interface is currently the redirector, all other file
  22405. // system will probably let the IRP complete normally with IoCompleteRequest.
  22406. // The user supplied routine returns any value other than success then the
  22407. // lock package will remove any lock that we just inserted.
  22408. //
  22409. typedef NTSTATUS (*PCOMPLETE_LOCK_IRP_ROUTINE) (
  22410. IN PVOID Context,
  22411. IN PIRP Irp
  22412. );
  22413. typedef VOID (*PUNLOCK_ROUTINE) (
  22414. IN PVOID Context,
  22415. IN PFILE_LOCK_INFO FileLockInfo
  22416. );
  22417. //
  22418. // A FILE_LOCK is an opaque structure but we need to declare the size of
  22419. // it here so that users can allocate space for one.
  22420. //
  22421. typedef struct _FILE_LOCK {
  22422. //
  22423. // The optional procedure to call to complete a request
  22424. //
  22425. PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine;
  22426. //
  22427. // The optional procedure to call when unlocking a byte range
  22428. //
  22429. PUNLOCK_ROUTINE UnlockRoutine;
  22430. //
  22431. // FastIoIsQuestionable is set to true whenever the filesystem require
  22432. // additional checking about whether the fast path can be taken. As an
  22433. // example Ntfs requires checking for disk space before the writes can
  22434. // occur.
  22435. //
  22436. BOOLEAN FastIoIsQuestionable;
  22437. BOOLEAN SpareC[3];
  22438. //
  22439. // FsRtl lock information
  22440. //
  22441. PVOID LockInformation;
  22442. //
  22443. // Contains continuation information for FsRtlGetNextFileLock
  22444. //
  22445. FILE_LOCK_INFO LastReturnedLockInfo;
  22446. PVOID LastReturnedLock;
  22447. } FILE_LOCK;
  22448. typedef FILE_LOCK *PFILE_LOCK;
  22449. PFILE_LOCK
  22450. FsRtlAllocateFileLock (
  22451. IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL,
  22452. IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL
  22453. );
  22454. VOID
  22455. FsRtlFreeFileLock (
  22456. IN PFILE_LOCK FileLock
  22457. );
  22458. NTKERNELAPI
  22459. VOID
  22460. FsRtlInitializeFileLock (
  22461. IN PFILE_LOCK FileLock,
  22462. IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL,
  22463. IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL
  22464. );
  22465. NTKERNELAPI
  22466. VOID
  22467. FsRtlUninitializeFileLock (
  22468. IN PFILE_LOCK FileLock
  22469. );
  22470. NTKERNELAPI
  22471. NTSTATUS
  22472. FsRtlProcessFileLock (
  22473. IN PFILE_LOCK FileLock,
  22474. IN PIRP Irp,
  22475. IN PVOID Context OPTIONAL
  22476. );
  22477. NTKERNELAPI
  22478. BOOLEAN
  22479. FsRtlCheckLockForReadAccess (
  22480. IN PFILE_LOCK FileLock,
  22481. IN PIRP Irp
  22482. );
  22483. NTKERNELAPI
  22484. BOOLEAN
  22485. FsRtlCheckLockForWriteAccess (
  22486. IN PFILE_LOCK FileLock,
  22487. IN PIRP Irp
  22488. );
  22489. NTKERNELAPI
  22490. BOOLEAN
  22491. FsRtlFastCheckLockForRead (
  22492. IN PFILE_LOCK FileLock,
  22493. IN PLARGE_INTEGER StartingByte,
  22494. IN PLARGE_INTEGER Length,
  22495. IN ULONG Key,
  22496. IN PFILE_OBJECT FileObject,
  22497. IN PVOID ProcessId
  22498. );
  22499. NTKERNELAPI
  22500. BOOLEAN
  22501. FsRtlFastCheckLockForWrite (
  22502. IN PFILE_LOCK FileLock,
  22503. IN PLARGE_INTEGER StartingByte,
  22504. IN PLARGE_INTEGER Length,
  22505. IN ULONG Key,
  22506. IN PVOID FileObject,
  22507. IN PVOID ProcessId
  22508. );
  22509. NTKERNELAPI
  22510. PFILE_LOCK_INFO
  22511. FsRtlGetNextFileLock (
  22512. IN PFILE_LOCK FileLock,
  22513. IN BOOLEAN Restart
  22514. );
  22515. NTKERNELAPI
  22516. NTSTATUS
  22517. FsRtlFastUnlockSingle (
  22518. IN PFILE_LOCK FileLock,
  22519. IN PFILE_OBJECT FileObject,
  22520. IN LARGE_INTEGER UNALIGNED *FileOffset,
  22521. IN PLARGE_INTEGER Length,
  22522. IN PEPROCESS ProcessId,
  22523. IN ULONG Key,
  22524. IN PVOID Context OPTIONAL,
  22525. IN BOOLEAN AlreadySynchronized
  22526. );
  22527. NTKERNELAPI
  22528. NTSTATUS
  22529. FsRtlFastUnlockAll (
  22530. IN PFILE_LOCK FileLock,
  22531. IN PFILE_OBJECT FileObject,
  22532. IN PEPROCESS ProcessId,
  22533. IN PVOID Context OPTIONAL
  22534. );
  22535. NTKERNELAPI
  22536. NTSTATUS
  22537. FsRtlFastUnlockAllByKey (
  22538. IN PFILE_LOCK FileLock,
  22539. IN PFILE_OBJECT FileObject,
  22540. IN PEPROCESS ProcessId,
  22541. IN ULONG Key,
  22542. IN PVOID Context OPTIONAL
  22543. );
  22544. NTKERNELAPI
  22545. BOOLEAN
  22546. FsRtlPrivateLock (
  22547. IN PFILE_LOCK FileLock,
  22548. IN PFILE_OBJECT FileObject,
  22549. IN PLARGE_INTEGER FileOffset,
  22550. IN PLARGE_INTEGER Length,
  22551. IN PEPROCESS ProcessId,
  22552. IN ULONG Key,
  22553. IN BOOLEAN FailImmediately,
  22554. IN BOOLEAN ExclusiveLock,
  22555. OUT PIO_STATUS_BLOCK Iosb,
  22556. IN PIRP Irp,
  22557. IN PVOID Context,
  22558. IN BOOLEAN AlreadySynchronized
  22559. );
  22560. //
  22561. // BOOLEAN
  22562. // FsRtlFastLock (
  22563. // IN PFILE_LOCK FileLock,
  22564. // IN PFILE_OBJECT FileObject,
  22565. // IN PLARGE_INTEGER FileOffset,
  22566. // IN PLARGE_INTEGER Length,
  22567. // IN PEPROCESS ProcessId,
  22568. // IN ULONG Key,
  22569. // IN BOOLEAN FailImmediately,
  22570. // IN BOOLEAN ExclusiveLock,
  22571. // OUT PIO_STATUS_BLOCK Iosb,
  22572. // IN PVOID Context OPTIONAL,
  22573. // IN BOOLEAN AlreadySynchronized
  22574. // );
  22575. //
  22576. #define FsRtlFastLock(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11) ( \
  22577. FsRtlPrivateLock( A1, /* FileLock */ \
  22578. A2, /* FileObject */ \
  22579. A3, /* FileOffset */ \
  22580. A4, /* Length */ \
  22581. A5, /* ProcessId */ \
  22582. A6, /* Key */ \
  22583. A7, /* FailImmediately */ \
  22584. A8, /* ExclusiveLock */ \
  22585. A9, /* Iosb */ \
  22586. NULL, /* Irp */ \
  22587. A10, /* Context */ \
  22588. A11 /* AlreadySynchronized */ ) \
  22589. )
  22590. //
  22591. // BOOLEAN
  22592. // FsRtlAreThereCurrentFileLocks (
  22593. // IN PFILE_LOCK FileLock
  22594. // );
  22595. //
  22596. #define FsRtlAreThereCurrentFileLocks(FL) ( \
  22597. ((FL)->FastIoIsQuestionable))
  22598. //
  22599. // Filesystem property tunneling, implemented in tunnel.c
  22600. //
  22601. //
  22602. // Tunnel cache structure
  22603. //
  22604. typedef struct {
  22605. //
  22606. // Mutex for cache manipulation
  22607. //
  22608. FAST_MUTEX Mutex;
  22609. //
  22610. // Splay Tree of tunneled information keyed by
  22611. // DirKey ## Name
  22612. //
  22613. PRTL_SPLAY_LINKS Cache;
  22614. //
  22615. // Timer queue used to age entries out of the main cache
  22616. //
  22617. LIST_ENTRY TimerQueue;
  22618. //
  22619. // Keep track of the number of entries in the cache to prevent
  22620. // excessive use of memory
  22621. //
  22622. USHORT NumEntries;
  22623. } TUNNEL, *PTUNNEL;
  22624. NTKERNELAPI
  22625. VOID
  22626. FsRtlInitializeTunnelCache (
  22627. IN TUNNEL *Cache);
  22628. NTKERNELAPI
  22629. VOID
  22630. FsRtlAddToTunnelCache (
  22631. IN TUNNEL *Cache,
  22632. IN ULONGLONG DirectoryKey,
  22633. IN UNICODE_STRING *ShortName,
  22634. IN UNICODE_STRING *LongName,
  22635. IN BOOLEAN KeyByShortName,
  22636. IN ULONG DataLength,
  22637. IN VOID *Data);
  22638. NTKERNELAPI
  22639. BOOLEAN
  22640. FsRtlFindInTunnelCache (
  22641. IN TUNNEL *Cache,
  22642. IN ULONGLONG DirectoryKey,
  22643. IN UNICODE_STRING *Name,
  22644. OUT UNICODE_STRING *ShortName,
  22645. OUT UNICODE_STRING *LongName,
  22646. IN OUT ULONG *DataLength,
  22647. OUT VOID *Data);
  22648. NTKERNELAPI
  22649. VOID
  22650. FsRtlDeleteKeyFromTunnelCache (
  22651. IN TUNNEL *Cache,
  22652. IN ULONGLONG DirectoryKey);
  22653. NTKERNELAPI
  22654. VOID
  22655. FsRtlDeleteTunnelCache (
  22656. IN TUNNEL *Cache);
  22657. //
  22658. // Dbcs name support routines, implemented in DbcsName.c
  22659. //
  22660. //
  22661. // The following enumerated type is used to denote the result of name
  22662. // comparisons
  22663. //
  22664. typedef enum _FSRTL_COMPARISON_RESULT {
  22665. LessThan = -1,
  22666. EqualTo = 0,
  22667. GreaterThan = 1
  22668. } FSRTL_COMPARISON_RESULT;
  22669. #ifdef NLS_MB_CODE_PAGE_TAG
  22670. #undef NLS_MB_CODE_PAGE_TAG
  22671. #endif // NLS_MB_CODE_PAGE_TAG
  22672. #define LEGAL_ANSI_CHARACTER_ARRAY (*FsRtlLegalAnsiCharacterArray) // ntosp
  22673. #define NLS_MB_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  22674. #define NLS_OEM_LEAD_BYTE_INFO (*NlsOemLeadByteInfo) // ntosp
  22675. extern UCHAR const* const LEGAL_ANSI_CHARACTER_ARRAY;
  22676. extern PUSHORT NLS_OEM_LEAD_BYTE_INFO; // Lead byte info. for ACP
  22677. //
  22678. // These following bit values are set in the FsRtlLegalDbcsCharacterArray
  22679. //
  22680. #define FSRTL_FAT_LEGAL 0x01
  22681. #define FSRTL_HPFS_LEGAL 0x02
  22682. #define FSRTL_NTFS_LEGAL 0x04
  22683. #define FSRTL_WILD_CHARACTER 0x08
  22684. #define FSRTL_OLE_LEGAL 0x10
  22685. #define FSRTL_NTFS_STREAM_LEGAL (FSRTL_NTFS_LEGAL | FSRTL_OLE_LEGAL)
  22686. //
  22687. // The following macro is used to determine if an Ansi character is wild.
  22688. //
  22689. #define FsRtlIsAnsiCharacterWild(C) ( \
  22690. FsRtlTestAnsiCharacter((C), FALSE, FALSE, FSRTL_WILD_CHARACTER) \
  22691. )
  22692. //
  22693. // The following macro is used to determine if an Ansi character is Fat legal.
  22694. //
  22695. #define FsRtlIsAnsiCharacterLegalFat(C,WILD_OK) ( \
  22696. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_FAT_LEGAL) \
  22697. )
  22698. //
  22699. // The following macro is used to determine if an Ansi character is Hpfs legal.
  22700. //
  22701. #define FsRtlIsAnsiCharacterLegalHpfs(C,WILD_OK) ( \
  22702. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_HPFS_LEGAL) \
  22703. )
  22704. //
  22705. // The following macro is used to determine if an Ansi character is Ntfs legal.
  22706. //
  22707. #define FsRtlIsAnsiCharacterLegalNtfs(C,WILD_OK) ( \
  22708. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_NTFS_LEGAL) \
  22709. )
  22710. //
  22711. // The following macro is used to determine if an Ansi character is
  22712. // legal in an Ntfs stream name
  22713. //
  22714. #define FsRtlIsAnsiCharacterLegalNtfsStream(C,WILD_OK) ( \
  22715. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_NTFS_STREAM_LEGAL) \
  22716. )
  22717. //
  22718. // The following macro is used to determine if an Ansi character is legal,
  22719. // according to the caller's specification.
  22720. //
  22721. #define FsRtlIsAnsiCharacterLegal(C,FLAGS) ( \
  22722. FsRtlTestAnsiCharacter((C), TRUE, FALSE, (FLAGS)) \
  22723. )
  22724. //
  22725. // The following macro is used to test attributes of an Ansi character,
  22726. // according to the caller's specified flags.
  22727. //
  22728. #define FsRtlTestAnsiCharacter(C, DEFAULT_RET, WILD_OK, FLAGS) ( \
  22729. ((SCHAR)(C) < 0) ? DEFAULT_RET : \
  22730. FlagOn( LEGAL_ANSI_CHARACTER_ARRAY[(C)], \
  22731. (FLAGS) | \
  22732. ((WILD_OK) ? FSRTL_WILD_CHARACTER : 0) ) \
  22733. )
  22734. //
  22735. // The following two macros use global data defined in ntos\rtl\nlsdata.c
  22736. //
  22737. // BOOLEAN
  22738. // FsRtlIsLeadDbcsCharacter (
  22739. // IN UCHAR DbcsCharacter
  22740. // );
  22741. //
  22742. // /*++
  22743. //
  22744. // Routine Description:
  22745. //
  22746. // This routine takes the first bytes of a Dbcs character and
  22747. // returns whether it is a lead byte in the system code page.
  22748. //
  22749. // Arguments:
  22750. //
  22751. // DbcsCharacter - Supplies the input character being examined
  22752. //
  22753. // Return Value:
  22754. //
  22755. // BOOLEAN - TRUE if the input character is a dbcs lead and
  22756. // FALSE otherwise
  22757. //
  22758. // --*/
  22759. //
  22760. //
  22761. #define FsRtlIsLeadDbcsCharacter(DBCS_CHAR) ( \
  22762. (BOOLEAN)((UCHAR)(DBCS_CHAR) < 0x80 ? FALSE : \
  22763. (NLS_MB_CODE_PAGE_TAG && \
  22764. (NLS_OEM_LEAD_BYTE_INFO[(UCHAR)(DBCS_CHAR)] != 0))) \
  22765. )
  22766. NTKERNELAPI
  22767. VOID
  22768. FsRtlDissectDbcs (
  22769. IN ANSI_STRING InputName,
  22770. OUT PANSI_STRING FirstPart,
  22771. OUT PANSI_STRING RemainingPart
  22772. );
  22773. NTKERNELAPI
  22774. BOOLEAN
  22775. FsRtlDoesDbcsContainWildCards (
  22776. IN PANSI_STRING Name
  22777. );
  22778. NTKERNELAPI
  22779. BOOLEAN
  22780. FsRtlIsDbcsInExpression (
  22781. IN PANSI_STRING Expression,
  22782. IN PANSI_STRING Name
  22783. );
  22784. NTKERNELAPI
  22785. BOOLEAN
  22786. FsRtlIsFatDbcsLegal (
  22787. IN ANSI_STRING DbcsName,
  22788. IN BOOLEAN WildCardsPermissible,
  22789. IN BOOLEAN PathNamePermissible,
  22790. IN BOOLEAN LeadingBackslashPermissible
  22791. );
  22792. // end_ntosp
  22793. NTKERNELAPI
  22794. BOOLEAN
  22795. FsRtlIsHpfsDbcsLegal (
  22796. IN ANSI_STRING DbcsName,
  22797. IN BOOLEAN WildCardsPermissible,
  22798. IN BOOLEAN PathNamePermissible,
  22799. IN BOOLEAN LeadingBackslashPermissible
  22800. );
  22801. //
  22802. // Exception filter routines, implemented in Filter.c
  22803. //
  22804. NTKERNELAPI
  22805. NTSTATUS
  22806. FsRtlNormalizeNtstatus (
  22807. IN NTSTATUS Exception,
  22808. IN NTSTATUS GenericException
  22809. );
  22810. NTKERNELAPI
  22811. BOOLEAN
  22812. FsRtlIsNtstatusExpected (
  22813. IN NTSTATUS Exception
  22814. );
  22815. //
  22816. // The following procedures are used to allocate executive pool and raise
  22817. // insufficient resource status if pool isn't currently available.
  22818. //
  22819. #define FsRtlAllocatePoolWithTag(PoolType, NumberOfBytes, Tag) \
  22820. ExAllocatePoolWithTag((POOL_TYPE)((PoolType) | POOL_RAISE_IF_ALLOCATION_FAILURE), \
  22821. NumberOfBytes, \
  22822. Tag)
  22823. #define FsRtlAllocatePoolWithQuotaTag(PoolType, NumberOfBytes, Tag) \
  22824. ExAllocatePoolWithQuotaTag((POOL_TYPE)((PoolType) | POOL_RAISE_IF_ALLOCATION_FAILURE), \
  22825. NumberOfBytes, \
  22826. Tag)
  22827. //
  22828. // The following function allocates a resource from the FsRtl pool.
  22829. //
  22830. NTKERNELAPI
  22831. PERESOURCE
  22832. FsRtlAllocateResource (
  22833. );
  22834. //
  22835. // Large Integer Mapped Control Blocks routines, implemented in LargeMcb.c
  22836. //
  22837. // Originally this structure was truly opaque and code outside largemcb was
  22838. // never allowed to examine or alter the structures. However, for performance
  22839. // reasons we want to allow ntfs the ability to quickly truncate down the
  22840. // mcb without the overhead of an actual call to largemcb.c. So to do that we
  22841. // need to export the structure. This structure is not exact. The Mapping field
  22842. // is declared here as a pvoid but largemcb.c it is a pointer to mapping pairs.
  22843. //
  22844. typedef struct _BASE_MCB {
  22845. ULONG MaximumPairCount;
  22846. ULONG PairCount;
  22847. POOL_TYPE PoolType;
  22848. PVOID Mapping;
  22849. } BASE_MCB;
  22850. typedef BASE_MCB *PBASE_MCB;
  22851. typedef struct _LARGE_MCB {
  22852. PFAST_MUTEX FastMutex;
  22853. BASE_MCB BaseMcb;
  22854. } LARGE_MCB;
  22855. typedef LARGE_MCB *PLARGE_MCB;
  22856. NTKERNELAPI
  22857. VOID
  22858. FsRtlInitializeLargeMcb (
  22859. IN PLARGE_MCB Mcb,
  22860. IN POOL_TYPE PoolType
  22861. );
  22862. NTKERNELAPI
  22863. VOID
  22864. FsRtlUninitializeLargeMcb (
  22865. IN PLARGE_MCB Mcb
  22866. );
  22867. NTKERNELAPI
  22868. VOID
  22869. FsRtlResetLargeMcb (
  22870. IN PLARGE_MCB Mcb,
  22871. IN BOOLEAN SelfSynchronized
  22872. );
  22873. NTKERNELAPI
  22874. VOID
  22875. FsRtlTruncateLargeMcb (
  22876. IN PLARGE_MCB Mcb,
  22877. IN LONGLONG Vbn
  22878. );
  22879. NTKERNELAPI
  22880. BOOLEAN
  22881. FsRtlAddLargeMcbEntry (
  22882. IN PLARGE_MCB Mcb,
  22883. IN LONGLONG Vbn,
  22884. IN LONGLONG Lbn,
  22885. IN LONGLONG SectorCount
  22886. );
  22887. NTKERNELAPI
  22888. VOID
  22889. FsRtlRemoveLargeMcbEntry (
  22890. IN PLARGE_MCB Mcb,
  22891. IN LONGLONG Vbn,
  22892. IN LONGLONG SectorCount
  22893. );
  22894. NTKERNELAPI
  22895. BOOLEAN
  22896. FsRtlLookupLargeMcbEntry (
  22897. IN PLARGE_MCB Mcb,
  22898. IN LONGLONG Vbn,
  22899. OUT PLONGLONG Lbn OPTIONAL,
  22900. OUT PLONGLONG SectorCountFromLbn OPTIONAL,
  22901. OUT PLONGLONG StartingLbn OPTIONAL,
  22902. OUT PLONGLONG SectorCountFromStartingLbn OPTIONAL,
  22903. OUT PULONG Index OPTIONAL
  22904. );
  22905. NTKERNELAPI
  22906. BOOLEAN
  22907. FsRtlLookupLastLargeMcbEntry (
  22908. IN PLARGE_MCB Mcb,
  22909. OUT PLONGLONG Vbn,
  22910. OUT PLONGLONG Lbn
  22911. );
  22912. NTKERNELAPI
  22913. BOOLEAN
  22914. FsRtlLookupLastLargeMcbEntryAndIndex (
  22915. IN PLARGE_MCB OpaqueMcb,
  22916. OUT PLONGLONG LargeVbn,
  22917. OUT PLONGLONG LargeLbn,
  22918. OUT PULONG Index
  22919. );
  22920. NTKERNELAPI
  22921. ULONG
  22922. FsRtlNumberOfRunsInLargeMcb (
  22923. IN PLARGE_MCB Mcb
  22924. );
  22925. NTKERNELAPI
  22926. BOOLEAN
  22927. FsRtlGetNextLargeMcbEntry (
  22928. IN PLARGE_MCB Mcb,
  22929. IN ULONG RunIndex,
  22930. OUT PLONGLONG Vbn,
  22931. OUT PLONGLONG Lbn,
  22932. OUT PLONGLONG SectorCount
  22933. );
  22934. NTKERNELAPI
  22935. BOOLEAN
  22936. FsRtlSplitLargeMcb (
  22937. IN PLARGE_MCB Mcb,
  22938. IN LONGLONG Vbn,
  22939. IN LONGLONG Amount
  22940. );
  22941. //
  22942. // Unsynchronzied base mcb functions. There is one of these for every
  22943. // large mcb equivalent function - they are identical other than lack of
  22944. // synchronization
  22945. //
  22946. NTKERNELAPI
  22947. VOID
  22948. FsRtlInitializeBaseMcb (
  22949. IN PBASE_MCB Mcb,
  22950. IN POOL_TYPE PoolType
  22951. );
  22952. NTKERNELAPI
  22953. VOID
  22954. FsRtlUninitializeBaseMcb (
  22955. IN PBASE_MCB Mcb
  22956. );
  22957. NTKERNELAPI
  22958. VOID
  22959. FsRtlResetBaseMcb (
  22960. IN PBASE_MCB Mcb
  22961. );
  22962. NTKERNELAPI
  22963. VOID
  22964. FsRtlTruncateBaseMcb (
  22965. IN PBASE_MCB Mcb,
  22966. IN LONGLONG Vbn
  22967. );
  22968. NTKERNELAPI
  22969. BOOLEAN
  22970. FsRtlAddBaseMcbEntry (
  22971. IN PBASE_MCB Mcb,
  22972. IN LONGLONG Vbn,
  22973. IN LONGLONG Lbn,
  22974. IN LONGLONG SectorCount
  22975. );
  22976. NTKERNELAPI
  22977. VOID
  22978. FsRtlRemoveBaseMcbEntry (
  22979. IN PBASE_MCB Mcb,
  22980. IN LONGLONG Vbn,
  22981. IN LONGLONG SectorCount
  22982. );
  22983. NTKERNELAPI
  22984. BOOLEAN
  22985. FsRtlLookupBaseMcbEntry (
  22986. IN PBASE_MCB Mcb,
  22987. IN LONGLONG Vbn,
  22988. OUT PLONGLONG Lbn OPTIONAL,
  22989. OUT PLONGLONG SectorCountFromLbn OPTIONAL,
  22990. OUT PLONGLONG StartingLbn OPTIONAL,
  22991. OUT PLONGLONG SectorCountFromStartingLbn OPTIONAL,
  22992. OUT PULONG Index OPTIONAL
  22993. );
  22994. NTKERNELAPI
  22995. BOOLEAN
  22996. FsRtlLookupLastBaseMcbEntry (
  22997. IN PBASE_MCB Mcb,
  22998. OUT PLONGLONG Vbn,
  22999. OUT PLONGLONG Lbn
  23000. );
  23001. NTKERNELAPI
  23002. BOOLEAN
  23003. FsRtlLookupLastBaseMcbEntryAndIndex (
  23004. IN PBASE_MCB OpaqueMcb,
  23005. OUT PLONGLONG LargeVbn,
  23006. OUT PLONGLONG LargeLbn,
  23007. OUT PULONG Index
  23008. );
  23009. NTKERNELAPI
  23010. ULONG
  23011. FsRtlNumberOfRunsInBaseMcb (
  23012. IN PBASE_MCB Mcb
  23013. );
  23014. NTKERNELAPI
  23015. BOOLEAN
  23016. FsRtlGetNextBaseMcbEntry (
  23017. IN PBASE_MCB Mcb,
  23018. IN ULONG RunIndex,
  23019. OUT PLONGLONG Vbn,
  23020. OUT PLONGLONG Lbn,
  23021. OUT PLONGLONG SectorCount
  23022. );
  23023. NTKERNELAPI
  23024. BOOLEAN
  23025. FsRtlSplitBaseMcb (
  23026. IN PBASE_MCB Mcb,
  23027. IN LONGLONG Vbn,
  23028. IN LONGLONG Amount
  23029. );
  23030. //
  23031. // Mapped Control Blocks routines, implemented in Mcb.c
  23032. //
  23033. // An MCB is an opaque structure but we need to declare the size of
  23034. // it here so that users can allocate space for one. Consequently the
  23035. // size computation here must be updated by hand if the MCB changes.
  23036. //
  23037. typedef struct _MCB {
  23038. LARGE_MCB DummyFieldThatSizesThisStructureCorrectly;
  23039. } MCB;
  23040. typedef MCB *PMCB;
  23041. NTKERNELAPI
  23042. VOID
  23043. FsRtlInitializeMcb (
  23044. IN PMCB Mcb,
  23045. IN POOL_TYPE PoolType
  23046. );
  23047. NTKERNELAPI
  23048. VOID
  23049. FsRtlUninitializeMcb (
  23050. IN PMCB Mcb
  23051. );
  23052. NTKERNELAPI
  23053. VOID
  23054. FsRtlTruncateMcb (
  23055. IN PMCB Mcb,
  23056. IN VBN Vbn
  23057. );
  23058. NTKERNELAPI
  23059. BOOLEAN
  23060. FsRtlAddMcbEntry (
  23061. IN PMCB Mcb,
  23062. IN VBN Vbn,
  23063. IN LBN Lbn,
  23064. IN ULONG SectorCount
  23065. );
  23066. NTKERNELAPI
  23067. VOID
  23068. FsRtlRemoveMcbEntry (
  23069. IN PMCB Mcb,
  23070. IN VBN Vbn,
  23071. IN ULONG SectorCount
  23072. );
  23073. NTKERNELAPI
  23074. BOOLEAN
  23075. FsRtlLookupMcbEntry (
  23076. IN PMCB Mcb,
  23077. IN VBN Vbn,
  23078. OUT PLBN Lbn,
  23079. OUT PULONG SectorCount OPTIONAL,
  23080. OUT PULONG Index
  23081. );
  23082. NTKERNELAPI
  23083. BOOLEAN
  23084. FsRtlLookupLastMcbEntry (
  23085. IN PMCB Mcb,
  23086. OUT PVBN Vbn,
  23087. OUT PLBN Lbn
  23088. );
  23089. NTKERNELAPI
  23090. ULONG
  23091. FsRtlNumberOfRunsInMcb (
  23092. IN PMCB Mcb
  23093. );
  23094. NTKERNELAPI
  23095. BOOLEAN
  23096. FsRtlGetNextMcbEntry (
  23097. IN PMCB Mcb,
  23098. IN ULONG RunIndex,
  23099. OUT PVBN Vbn,
  23100. OUT PLBN Lbn,
  23101. OUT PULONG SectorCount
  23102. );
  23103. //
  23104. // Fault Tolerance routines, implemented in FaultTol.c
  23105. //
  23106. // The routines in this package implement routines that help file
  23107. // systems interact with the FT device drivers.
  23108. //
  23109. NTKERNELAPI
  23110. NTSTATUS
  23111. FsRtlBalanceReads (
  23112. IN PDEVICE_OBJECT TargetDevice
  23113. );
  23114. //
  23115. // Oplock routines, implemented in Oplock.c
  23116. //
  23117. // An OPLOCK is an opaque structure, we declare it as a PVOID and
  23118. // allocate the actual memory only when needed.
  23119. //
  23120. typedef PVOID OPLOCK, *POPLOCK;
  23121. typedef
  23122. VOID
  23123. (*POPLOCK_WAIT_COMPLETE_ROUTINE) (
  23124. IN PVOID Context,
  23125. IN PIRP Irp
  23126. );
  23127. typedef
  23128. VOID
  23129. (*POPLOCK_FS_PREPOST_IRP) (
  23130. IN PVOID Context,
  23131. IN PIRP Irp
  23132. );
  23133. NTKERNELAPI
  23134. VOID
  23135. FsRtlInitializeOplock (
  23136. IN OUT POPLOCK Oplock
  23137. );
  23138. NTKERNELAPI
  23139. VOID
  23140. FsRtlUninitializeOplock (
  23141. IN OUT POPLOCK Oplock
  23142. );
  23143. NTKERNELAPI
  23144. NTSTATUS
  23145. FsRtlOplockFsctrl (
  23146. IN POPLOCK Oplock,
  23147. IN PIRP Irp,
  23148. IN ULONG OpenCount
  23149. );
  23150. NTKERNELAPI
  23151. NTSTATUS
  23152. FsRtlCheckOplock (
  23153. IN POPLOCK Oplock,
  23154. IN PIRP Irp,
  23155. IN PVOID Context,
  23156. IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL,
  23157. IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL
  23158. );
  23159. NTKERNELAPI
  23160. BOOLEAN
  23161. FsRtlOplockIsFastIoPossible (
  23162. IN POPLOCK Oplock
  23163. );
  23164. NTKERNELAPI
  23165. BOOLEAN
  23166. FsRtlCurrentBatchOplock (
  23167. IN POPLOCK Oplock
  23168. );
  23169. //
  23170. // Volume lock/unlock notification routines, implemented in PnP.c
  23171. //
  23172. // These routines provide PnP volume lock notification support
  23173. // for all filesystems.
  23174. //
  23175. #define FSRTL_VOLUME_DISMOUNT 1
  23176. #define FSRTL_VOLUME_DISMOUNT_FAILED 2
  23177. #define FSRTL_VOLUME_LOCK 3
  23178. #define FSRTL_VOLUME_LOCK_FAILED 4
  23179. #define FSRTL_VOLUME_UNLOCK 5
  23180. #define FSRTL_VOLUME_MOUNT 6
  23181. NTKERNELAPI
  23182. NTSTATUS
  23183. FsRtlNotifyVolumeEvent (
  23184. IN PFILE_OBJECT FileObject,
  23185. IN ULONG EventCode
  23186. );
  23187. //
  23188. // Notify Change routines, implemented in Notify.c
  23189. //
  23190. // These routines provide Notify Change support for all filesystems.
  23191. // Any of the 'Full' notify routines will support returning the
  23192. // change information into the user's buffer.
  23193. //
  23194. typedef PVOID PNOTIFY_SYNC;
  23195. typedef
  23196. BOOLEAN (*PCHECK_FOR_TRAVERSE_ACCESS) (
  23197. IN PVOID NotifyContext,
  23198. IN PVOID TargetContext,
  23199. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  23200. );
  23201. typedef
  23202. BOOLEAN (*PFILTER_REPORT_CHANGE) (
  23203. IN PVOID NotifyContext,
  23204. IN PVOID FilterContext
  23205. );
  23206. NTKERNELAPI
  23207. VOID
  23208. FsRtlNotifyInitializeSync (
  23209. IN PNOTIFY_SYNC *NotifySync
  23210. );
  23211. NTKERNELAPI
  23212. VOID
  23213. FsRtlNotifyUninitializeSync (
  23214. IN PNOTIFY_SYNC *NotifySync
  23215. );
  23216. NTKERNELAPI
  23217. VOID
  23218. FsRtlNotifyFullChangeDirectory (
  23219. IN PNOTIFY_SYNC NotifySync,
  23220. IN PLIST_ENTRY NotifyList,
  23221. IN PVOID FsContext,
  23222. IN PSTRING FullDirectoryName,
  23223. IN BOOLEAN WatchTree,
  23224. IN BOOLEAN IgnoreBuffer,
  23225. IN ULONG CompletionFilter,
  23226. IN PIRP NotifyIrp,
  23227. IN PCHECK_FOR_TRAVERSE_ACCESS TraverseCallback OPTIONAL,
  23228. IN PSECURITY_SUBJECT_CONTEXT SubjectContext OPTIONAL
  23229. );
  23230. NTKERNELAPI
  23231. VOID
  23232. FsRtlNotifyFilterChangeDirectory (
  23233. IN PNOTIFY_SYNC NotifySync,
  23234. IN PLIST_ENTRY NotifyList,
  23235. IN PVOID FsContext,
  23236. IN PSTRING FullDirectoryName,
  23237. IN BOOLEAN WatchTree,
  23238. IN BOOLEAN IgnoreBuffer,
  23239. IN ULONG CompletionFilter,
  23240. IN PIRP NotifyIrp,
  23241. IN PCHECK_FOR_TRAVERSE_ACCESS TraverseCallback OPTIONAL,
  23242. IN PSECURITY_SUBJECT_CONTEXT SubjectContext OPTIONAL,
  23243. IN PFILTER_REPORT_CHANGE FilterCallback OPTIONAL
  23244. );
  23245. NTKERNELAPI
  23246. VOID
  23247. FsRtlNotifyFilterReportChange (
  23248. IN PNOTIFY_SYNC NotifySync,
  23249. IN PLIST_ENTRY NotifyList,
  23250. IN PSTRING FullTargetName,
  23251. IN USHORT TargetNameOffset,
  23252. IN PSTRING StreamName OPTIONAL,
  23253. IN PSTRING NormalizedParentName OPTIONAL,
  23254. IN ULONG FilterMatch,
  23255. IN ULONG Action,
  23256. IN PVOID TargetContext,
  23257. IN PVOID FilterContext
  23258. );
  23259. NTKERNELAPI
  23260. VOID
  23261. FsRtlNotifyFullReportChange (
  23262. IN PNOTIFY_SYNC NotifySync,
  23263. IN PLIST_ENTRY NotifyList,
  23264. IN PSTRING FullTargetName,
  23265. IN USHORT TargetNameOffset,
  23266. IN PSTRING StreamName OPTIONAL,
  23267. IN PSTRING NormalizedParentName OPTIONAL,
  23268. IN ULONG FilterMatch,
  23269. IN ULONG Action,
  23270. IN PVOID TargetContext
  23271. );
  23272. NTKERNELAPI
  23273. VOID
  23274. FsRtlNotifyCleanup (
  23275. IN PNOTIFY_SYNC NotifySync,
  23276. IN PLIST_ENTRY NotifyList,
  23277. IN PVOID FsContext
  23278. );
  23279. //
  23280. // Unicode Name support routines, implemented in Name.c
  23281. //
  23282. // The routines here are used to manipulate unicode names
  23283. //
  23284. //
  23285. // The following macro is used to determine if a character is wild.
  23286. //
  23287. #define FsRtlIsUnicodeCharacterWild(C) ( \
  23288. (((C) >= 0x40) ? FALSE : FlagOn( LEGAL_ANSI_CHARACTER_ARRAY[(C)], \
  23289. FSRTL_WILD_CHARACTER ) ) \
  23290. )
  23291. NTKERNELAPI
  23292. VOID
  23293. FsRtlDissectName (
  23294. IN UNICODE_STRING Path,
  23295. OUT PUNICODE_STRING FirstName,
  23296. OUT PUNICODE_STRING RemainingName
  23297. );
  23298. NTKERNELAPI
  23299. BOOLEAN
  23300. FsRtlDoesNameContainWildCards (
  23301. IN PUNICODE_STRING Name
  23302. );
  23303. NTKERNELAPI
  23304. BOOLEAN
  23305. FsRtlAreNamesEqual (
  23306. PCUNICODE_STRING ConstantNameA,
  23307. PCUNICODE_STRING ConstantNameB,
  23308. IN BOOLEAN IgnoreCase,
  23309. IN PCWCH UpcaseTable OPTIONAL
  23310. );
  23311. NTKERNELAPI
  23312. BOOLEAN
  23313. FsRtlIsNameInExpression (
  23314. IN PUNICODE_STRING Expression,
  23315. IN PUNICODE_STRING Name,
  23316. IN BOOLEAN IgnoreCase,
  23317. IN PWCH UpcaseTable OPTIONAL
  23318. );
  23319. //
  23320. // Stack Overflow support routine, implemented in StackOvf.c
  23321. //
  23322. typedef
  23323. VOID
  23324. (*PFSRTL_STACK_OVERFLOW_ROUTINE) (
  23325. IN PVOID Context,
  23326. IN PKEVENT Event
  23327. );
  23328. NTKERNELAPI
  23329. VOID
  23330. FsRtlPostStackOverflow (
  23331. IN PVOID Context,
  23332. IN PKEVENT Event,
  23333. IN PFSRTL_STACK_OVERFLOW_ROUTINE StackOverflowRoutine
  23334. );
  23335. NTKERNELAPI
  23336. VOID
  23337. FsRtlPostPagingFileStackOverflow (
  23338. IN PVOID Context,
  23339. IN PKEVENT Event,
  23340. IN PFSRTL_STACK_OVERFLOW_ROUTINE StackOverflowRoutine
  23341. );
  23342. //
  23343. // UNC Provider support
  23344. //
  23345. NTKERNELAPI
  23346. NTSTATUS
  23347. FsRtlRegisterUncProvider(
  23348. IN OUT PHANDLE MupHandle,
  23349. IN PUNICODE_STRING RedirectorDeviceName,
  23350. IN BOOLEAN MailslotsSupported
  23351. );
  23352. NTKERNELAPI
  23353. VOID
  23354. FsRtlDeregisterUncProvider(
  23355. IN HANDLE Handle
  23356. );
  23357. //
  23358. // File System Filter PerStream Context Support
  23359. //
  23360. //
  23361. // Filesystem filter drivers use these APIs to associate context
  23362. // with open streams (for filesystems that support this).
  23363. //
  23364. //
  23365. // OwnerId should uniquely identify a particular filter driver
  23366. // (e.g. the address of the driver's device object).
  23367. // InstanceId can be used to distinguish distinct contexts associated
  23368. // by a filter driver with a single stream (e.g. the address of the
  23369. // PerStream Context structure).
  23370. //
  23371. //
  23372. // This structure needs to be embedded within the users context that
  23373. // they want to associate with a given stream
  23374. //
  23375. typedef struct _FSRTL_PER_STREAM_CONTEXT {
  23376. //
  23377. // This is linked into the StreamContext list inside the
  23378. // FSRTL_ADVANCED_FCB_HEADER structure.
  23379. //
  23380. LIST_ENTRY Links;
  23381. //
  23382. // A Unique ID for this filter (ex: address of Driver Object, Device
  23383. // Object, or Device Extension)
  23384. //
  23385. PVOID OwnerId;
  23386. //
  23387. // An optional ID to differentiate different contexts for the same
  23388. // filter.
  23389. //
  23390. PVOID InstanceId;
  23391. //
  23392. // A callback routine which is called by the underlying file system
  23393. // when the stream is being torn down. When this routine is called
  23394. // the given context has already been removed from the context linked
  23395. // list. The callback routine cannot recursively call down into the
  23396. // filesystem or acquire any of their resources which they might hold
  23397. // when calling the filesystem outside of the callback. This must
  23398. // be defined.
  23399. //
  23400. PFREE_FUNCTION FreeCallback;
  23401. } FSRTL_PER_STREAM_CONTEXT, *PFSRTL_PER_STREAM_CONTEXT;
  23402. //
  23403. // This will initialize the given FSRTL_PER_STREAM_CONTEXT structure. This
  23404. // should be used before calling "FsRtlInsertPerStreamContext".
  23405. //
  23406. #define FsRtlInitPerStreamContext( _fc, _owner, _inst, _cb) \
  23407. ((_fc)->OwnerId = (_owner), \
  23408. (_fc)->InstanceId = (_inst), \
  23409. (_fc)->FreeCallback = (_cb))
  23410. //
  23411. // Given a FileObject this will return the StreamContext pointer that
  23412. // needs to be passed into the other FsRtl PerStream Context routines.
  23413. //
  23414. #define FsRtlGetPerStreamContextPointer(_fo) \
  23415. ((PFSRTL_ADVANCED_FCB_HEADER)((_fo)->FsContext))
  23416. //
  23417. // This will test to see if PerStream contexts are supported for the given
  23418. // FileObject
  23419. //
  23420. #define FsRtlSupportsPerStreamContexts(_fo) \
  23421. ((NULL != FsRtlGetPerStreamContextPointer(_fo)) && \
  23422. FlagOn(FsRtlGetPerStreamContextPointer(_fo)->Flags2, \
  23423. FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS))
  23424. //
  23425. // Associate the context at Ptr with the given stream. The Ptr structure
  23426. // should be filled in by the caller before calling this routine (see
  23427. // FsRtlInitPerStreamContext). If the underlying filesystem does not support
  23428. // filter contexts, STATUS_INVALID_DEVICE_REQUEST will be returned.
  23429. //
  23430. NTKERNELAPI
  23431. NTSTATUS
  23432. FsRtlInsertPerStreamContext (
  23433. IN PFSRTL_ADVANCED_FCB_HEADER PerStreamContext,
  23434. IN PFSRTL_PER_STREAM_CONTEXT Ptr
  23435. );
  23436. //
  23437. // Lookup a filter context associated with the stream specified. The first
  23438. // context matching OwnerId (and InstanceId, if present) is returned. By not
  23439. // specifying InstanceId, a filter driver can search for any context that it
  23440. // has previously associated with a stream. If no matching context is found,
  23441. // NULL is returned. If the file system does not support filter contexts,
  23442. // NULL is returned.
  23443. //
  23444. NTKERNELAPI
  23445. PFSRTL_PER_STREAM_CONTEXT
  23446. FsRtlLookupPerStreamContextInternal (
  23447. IN PFSRTL_ADVANCED_FCB_HEADER StreamContext,
  23448. IN PVOID OwnerId OPTIONAL,
  23449. IN PVOID InstanceId OPTIONAL
  23450. );
  23451. #define FsRtlLookupPerStreamContext(_sc, _oid, _iid) \
  23452. (((NULL != (_sc)) && \
  23453. FlagOn((_sc)->Flags2,FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS) && \
  23454. !IsListEmpty(&(_sc)->FilterContexts)) ? \
  23455. FsRtlLookupPerStreamContextInternal((_sc), (_oid), (_iid)) : \
  23456. NULL)
  23457. //
  23458. // Normally, contexts should be deleted when the file system notifies the
  23459. // filter that the stream is being closed. There are cases when a filter
  23460. // may want to remove all existing contexts for a specific volume. This
  23461. // routine should be called at those times. This routine should NOT be
  23462. // called for the following cases:
  23463. // - Inside your FreeCallback handler - The underlying file system has
  23464. // already removed it from the linked list).
  23465. // - Inside your IRP_CLOSE handler - If you do this then you will not
  23466. // be notified when the stream is torn down.
  23467. //
  23468. // This functions identically to FsRtlLookupPerStreamContext, except that the
  23469. // returned context has been removed from the list.
  23470. //
  23471. NTKERNELAPI
  23472. PFSRTL_PER_STREAM_CONTEXT
  23473. FsRtlRemovePerStreamContext (
  23474. IN PFSRTL_ADVANCED_FCB_HEADER StreamContext,
  23475. IN PVOID OwnerId OPTIONAL,
  23476. IN PVOID InstanceId OPTIONAL
  23477. );
  23478. //
  23479. // APIs for file systems to use for initializing and cleaning up
  23480. // the Advaned FCB Header fields for PerStreamContext support
  23481. //
  23482. //
  23483. // This will properly initialize the advanced header so that it can be
  23484. // used with PerStream contexts.
  23485. // Note: A fast mutex must be placed in an advanced header. It is the
  23486. // caller's responsibility to properly create and initialize this
  23487. // mutex before calling this macro. The mutex field is only set
  23488. // if a non-NULL value is passed in.
  23489. //
  23490. #define FsRtlSetupAdvancedHeader( _advhdr, _fmutx ) \
  23491. { \
  23492. SetFlag( (_advhdr)->Flags, FSRTL_FLAG_ADVANCED_HEADER ); \
  23493. SetFlag( (_advhdr)->Flags2, FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS ); \
  23494. InitializeListHead( &(_advhdr)->FilterContexts ); \
  23495. if ((_fmutx) != NULL) { \
  23496. (_advhdr)->FastMutex = (_fmutx); \
  23497. } \
  23498. }
  23499. //
  23500. // File systems call this API to free any filter contexts still associated
  23501. // with an FSRTL_COMMON_FCB_HEADER that they are tearing down.
  23502. // The FreeCallback routine for each filter context will be called.
  23503. //
  23504. NTKERNELAPI
  23505. VOID
  23506. FsRtlTeardownPerStreamContexts (
  23507. IN PFSRTL_ADVANCED_FCB_HEADER AdvancedHeader
  23508. );
  23509. //++
  23510. //
  23511. // VOID
  23512. // FsRtlCompleteRequest (
  23513. // IN PIRP Irp,
  23514. // IN NTSTATUS Status
  23515. // );
  23516. //
  23517. // Routine Description:
  23518. //
  23519. // This routine is used to complete an IRP with the indicated
  23520. // status. It does the necessary raise and lower of IRQL.
  23521. //
  23522. // Arguments:
  23523. //
  23524. // Irp - Supplies a pointer to the Irp to complete
  23525. //
  23526. // Status - Supplies the completion status for the Irp
  23527. //
  23528. // Return Value:
  23529. //
  23530. // None.
  23531. //
  23532. //--
  23533. #define FsRtlCompleteRequest(IRP,STATUS) { \
  23534. (IRP)->IoStatus.Status = (STATUS); \
  23535. IoCompleteRequest( (IRP), IO_DISK_INCREMENT ); \
  23536. }
  23537. //++
  23538. //
  23539. // VOID
  23540. // FsRtlEnterFileSystem (
  23541. // );
  23542. //
  23543. // Routine Description:
  23544. //
  23545. // This routine is used when entering a file system (e.g., through its
  23546. // Fsd entry point). It ensures that the file system cannot be suspended
  23547. // while running and thus block other file I/O requests. Upon exit
  23548. // the file system must call FsRtlExitFileSystem.
  23549. //
  23550. // Arguments:
  23551. //
  23552. // Return Value:
  23553. //
  23554. // None.
  23555. //
  23556. //--
  23557. #define FsRtlEnterFileSystem() { \
  23558. KeEnterCriticalRegion(); \
  23559. }
  23560. //++
  23561. //
  23562. // VOID
  23563. // FsRtlExitFileSystem (
  23564. // );
  23565. //
  23566. // Routine Description:
  23567. //
  23568. // This routine is used when exiting a file system (e.g., through its
  23569. // Fsd entry point).
  23570. //
  23571. // Arguments:
  23572. //
  23573. // Return Value:
  23574. //
  23575. // None.
  23576. //
  23577. //--
  23578. #define FsRtlExitFileSystem() { \
  23579. KeLeaveCriticalRegion(); \
  23580. }
  23581. VOID
  23582. FsRtlIncrementCcFastReadNotPossible( VOID );
  23583. VOID
  23584. FsRtlIncrementCcFastReadWait( VOID );
  23585. VOID
  23586. FsRtlIncrementCcFastReadNoWait( VOID );
  23587. VOID
  23588. FsRtlIncrementCcFastReadResourceMiss( VOID );
  23589. //
  23590. // Returns TRUE if the given fileObject represents a paging file, returns
  23591. // FALSE otherwise.
  23592. //
  23593. LOGICAL
  23594. FsRtlIsPagingFile (
  23595. IN PFILE_OBJECT FileObject
  23596. );
  23597. //
  23598. // Define two constants describing the view size (and alignment)
  23599. // that the Cache Manager uses to map files.
  23600. //
  23601. #define VACB_MAPPING_GRANULARITY (0x40000)
  23602. #define VACB_OFFSET_SHIFT (18)
  23603. //
  23604. // Public portion of BCB
  23605. //
  23606. typedef struct _PUBLIC_BCB {
  23607. //
  23608. // Type and size of this record
  23609. //
  23610. // NOTE: The first four fields must be the same as the BCB in cc.h.
  23611. //
  23612. CSHORT NodeTypeCode;
  23613. CSHORT NodeByteSize;
  23614. //
  23615. // Description of range of file which is currently mapped.
  23616. //
  23617. ULONG MappedLength;
  23618. LARGE_INTEGER MappedFileOffset;
  23619. } PUBLIC_BCB, *PPUBLIC_BCB;
  23620. //
  23621. // File Sizes structure.
  23622. //
  23623. typedef struct _CC_FILE_SIZES {
  23624. LARGE_INTEGER AllocationSize;
  23625. LARGE_INTEGER FileSize;
  23626. LARGE_INTEGER ValidDataLength;
  23627. } CC_FILE_SIZES, *PCC_FILE_SIZES;
  23628. //
  23629. // Define a Cache Manager callback structure. These routines are required
  23630. // by the Lazy Writer, so that it can acquire resources in the right order
  23631. // to avoid deadlocks. Note that otherwise you would have most FS requests
  23632. // acquiring FS resources first and caching structures second, while the
  23633. // Lazy Writer needs to acquire its own resources first, and then FS
  23634. // structures later as it calls the file system.
  23635. //
  23636. //
  23637. // First define the procedure pointer typedefs
  23638. //
  23639. //
  23640. // This routine is called by the Lazy Writer prior to doing a write,
  23641. // since this will require some file system resources associated with
  23642. // this cached file. The context parameter supplied is whatever the FS
  23643. // passed as the LazyWriteContext parameter when is called
  23644. // CcInitializeCacheMap.
  23645. //
  23646. typedef
  23647. BOOLEAN (*PACQUIRE_FOR_LAZY_WRITE) (
  23648. IN PVOID Context,
  23649. IN BOOLEAN Wait
  23650. );
  23651. //
  23652. // This routine releases the Context acquired above.
  23653. //
  23654. typedef
  23655. VOID (*PRELEASE_FROM_LAZY_WRITE) (
  23656. IN PVOID Context
  23657. );
  23658. //
  23659. // This routine is called by the Lazy Writer prior to doing a readahead.
  23660. //
  23661. typedef
  23662. BOOLEAN (*PACQUIRE_FOR_READ_AHEAD) (
  23663. IN PVOID Context,
  23664. IN BOOLEAN Wait
  23665. );
  23666. //
  23667. // This routine releases the Context acquired above.
  23668. //
  23669. typedef
  23670. VOID (*PRELEASE_FROM_READ_AHEAD) (
  23671. IN PVOID Context
  23672. );
  23673. typedef struct _CACHE_MANAGER_CALLBACKS {
  23674. PACQUIRE_FOR_LAZY_WRITE AcquireForLazyWrite;
  23675. PRELEASE_FROM_LAZY_WRITE ReleaseFromLazyWrite;
  23676. PACQUIRE_FOR_READ_AHEAD AcquireForReadAhead;
  23677. PRELEASE_FROM_READ_AHEAD ReleaseFromReadAhead;
  23678. } CACHE_MANAGER_CALLBACKS, *PCACHE_MANAGER_CALLBACKS;
  23679. //
  23680. // This structure is passed into CcUninitializeCacheMap
  23681. // if the caller wants to know when the cache map is deleted.
  23682. //
  23683. typedef struct _CACHE_UNINITIALIZE_EVENT {
  23684. struct _CACHE_UNINITIALIZE_EVENT *Next;
  23685. KEVENT Event;
  23686. } CACHE_UNINITIALIZE_EVENT, *PCACHE_UNINITIALIZE_EVENT;
  23687. //
  23688. // Callback routine for retrieving dirty pages from Cache Manager.
  23689. //
  23690. typedef
  23691. VOID (*PDIRTY_PAGE_ROUTINE) (
  23692. IN PFILE_OBJECT FileObject,
  23693. IN PLARGE_INTEGER FileOffset,
  23694. IN ULONG Length,
  23695. IN PLARGE_INTEGER OldestLsn,
  23696. IN PLARGE_INTEGER NewestLsn,
  23697. IN PVOID Context1,
  23698. IN PVOID Context2
  23699. );
  23700. //
  23701. // Callback routine for doing log file flushes to Lsn.
  23702. //
  23703. typedef
  23704. VOID (*PFLUSH_TO_LSN) (
  23705. IN PVOID LogHandle,
  23706. IN LARGE_INTEGER Lsn
  23707. );
  23708. //
  23709. // Macro to test whether a file is cached or not.
  23710. //
  23711. #define CcIsFileCached(FO) ( \
  23712. ((FO)->SectionObjectPointer != NULL) && \
  23713. (((PSECTION_OBJECT_POINTERS)(FO)->SectionObjectPointer)->SharedCacheMap != NULL) \
  23714. )
  23715. extern ULONG CcFastMdlReadWait;
  23716. //
  23717. // The following routines are intended for use by File Systems Only.
  23718. //
  23719. NTKERNELAPI
  23720. VOID
  23721. CcInitializeCacheMap (
  23722. IN PFILE_OBJECT FileObject,
  23723. IN PCC_FILE_SIZES FileSizes,
  23724. IN BOOLEAN PinAccess,
  23725. IN PCACHE_MANAGER_CALLBACKS Callbacks,
  23726. IN PVOID LazyWriteContext
  23727. );
  23728. NTKERNELAPI
  23729. BOOLEAN
  23730. CcUninitializeCacheMap (
  23731. IN PFILE_OBJECT FileObject,
  23732. IN PLARGE_INTEGER TruncateSize OPTIONAL,
  23733. IN PCACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent OPTIONAL
  23734. );
  23735. NTKERNELAPI
  23736. VOID
  23737. CcSetFileSizes (
  23738. IN PFILE_OBJECT FileObject,
  23739. IN PCC_FILE_SIZES FileSizes
  23740. );
  23741. //
  23742. // VOID
  23743. // CcFastIoSetFileSizes (
  23744. // IN PFILE_OBJECT FileObject,
  23745. // IN PCC_FILE_SIZES FileSizes
  23746. // );
  23747. //
  23748. #define CcGetFileSizePointer(FO) ( \
  23749. ((PLARGE_INTEGER)((FO)->SectionObjectPointer->SharedCacheMap) + 1) \
  23750. )
  23751. NTKERNELAPI
  23752. BOOLEAN
  23753. CcPurgeCacheSection (
  23754. IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
  23755. IN PLARGE_INTEGER FileOffset OPTIONAL,
  23756. IN ULONG Length,
  23757. IN BOOLEAN UninitializeCacheMaps
  23758. );
  23759. NTKERNELAPI
  23760. VOID
  23761. CcSetDirtyPageThreshold (
  23762. IN PFILE_OBJECT FileObject,
  23763. IN ULONG DirtyPageThreshold
  23764. );
  23765. NTKERNELAPI
  23766. VOID
  23767. CcFlushCache (
  23768. IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
  23769. IN PLARGE_INTEGER FileOffset OPTIONAL,
  23770. IN ULONG Length,
  23771. OUT PIO_STATUS_BLOCK IoStatus OPTIONAL
  23772. );
  23773. NTKERNELAPI
  23774. LARGE_INTEGER
  23775. CcGetFlushedValidData (
  23776. IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
  23777. IN BOOLEAN BcbListHeld
  23778. );
  23779. NTKERNELAPI
  23780. BOOLEAN
  23781. CcZeroData (
  23782. IN PFILE_OBJECT FileObject,
  23783. IN PLARGE_INTEGER StartOffset,
  23784. IN PLARGE_INTEGER EndOffset,
  23785. IN BOOLEAN Wait
  23786. );
  23787. NTKERNELAPI
  23788. PVOID
  23789. CcRemapBcb (
  23790. IN PVOID Bcb
  23791. );
  23792. NTKERNELAPI
  23793. VOID
  23794. CcRepinBcb (
  23795. IN PVOID Bcb
  23796. );
  23797. NTKERNELAPI
  23798. VOID
  23799. CcUnpinRepinnedBcb (
  23800. IN PVOID Bcb,
  23801. IN BOOLEAN WriteThrough,
  23802. OUT PIO_STATUS_BLOCK IoStatus
  23803. );
  23804. NTKERNELAPI
  23805. PFILE_OBJECT
  23806. CcGetFileObjectFromSectionPtrs (
  23807. IN PSECTION_OBJECT_POINTERS SectionObjectPointer
  23808. );
  23809. NTKERNELAPI
  23810. PFILE_OBJECT
  23811. CcGetFileObjectFromBcb (
  23812. IN PVOID Bcb
  23813. );
  23814. //
  23815. // These routines are implemented to support write throttling.
  23816. //
  23817. //
  23818. // BOOLEAN
  23819. // CcCopyWriteWontFlush (
  23820. // IN PFILE_OBJECT FileObject,
  23821. // IN PLARGE_INTEGER FileOffset,
  23822. // IN ULONG Length
  23823. // );
  23824. //
  23825. #define CcCopyWriteWontFlush(FO,FOFF,LEN) ((LEN) <= 0X10000)
  23826. NTKERNELAPI
  23827. BOOLEAN
  23828. CcCanIWrite (
  23829. IN PFILE_OBJECT FileObject,
  23830. IN ULONG BytesToWrite,
  23831. IN BOOLEAN Wait,
  23832. IN BOOLEAN Retrying
  23833. );
  23834. typedef
  23835. VOID (*PCC_POST_DEFERRED_WRITE) (
  23836. IN PVOID Context1,
  23837. IN PVOID Context2
  23838. );
  23839. NTKERNELAPI
  23840. VOID
  23841. CcDeferWrite (
  23842. IN PFILE_OBJECT FileObject,
  23843. IN PCC_POST_DEFERRED_WRITE PostRoutine,
  23844. IN PVOID Context1,
  23845. IN PVOID Context2,
  23846. IN ULONG BytesToWrite,
  23847. IN BOOLEAN Retrying
  23848. );
  23849. //
  23850. // The following routines provide a data copy interface to the cache, and
  23851. // are intended for use by File Servers and File Systems.
  23852. //
  23853. NTKERNELAPI
  23854. BOOLEAN
  23855. CcCopyRead (
  23856. IN PFILE_OBJECT FileObject,
  23857. IN PLARGE_INTEGER FileOffset,
  23858. IN ULONG Length,
  23859. IN BOOLEAN Wait,
  23860. OUT PVOID Buffer,
  23861. OUT PIO_STATUS_BLOCK IoStatus
  23862. );
  23863. NTKERNELAPI
  23864. VOID
  23865. CcFastCopyRead (
  23866. IN PFILE_OBJECT FileObject,
  23867. IN ULONG FileOffset,
  23868. IN ULONG Length,
  23869. IN ULONG PageCount,
  23870. OUT PVOID Buffer,
  23871. OUT PIO_STATUS_BLOCK IoStatus
  23872. );
  23873. NTKERNELAPI
  23874. BOOLEAN
  23875. CcCopyWrite (
  23876. IN PFILE_OBJECT FileObject,
  23877. IN PLARGE_INTEGER FileOffset,
  23878. IN ULONG Length,
  23879. IN BOOLEAN Wait,
  23880. IN PVOID Buffer
  23881. );
  23882. NTKERNELAPI
  23883. VOID
  23884. CcFastCopyWrite (
  23885. IN PFILE_OBJECT FileObject,
  23886. IN ULONG FileOffset,
  23887. IN ULONG Length,
  23888. IN PVOID Buffer
  23889. );
  23890. //
  23891. // The following routines provide an Mdl interface for transfers to and
  23892. // from the cache, and are primarily intended for File Servers.
  23893. //
  23894. // NOBODY SHOULD BE CALLING THESE MDL ROUTINES DIRECTLY, USE FSRTL AND
  23895. // FASTIO INTERFACES.
  23896. //
  23897. NTKERNELAPI
  23898. VOID
  23899. CcMdlRead (
  23900. IN PFILE_OBJECT FileObject,
  23901. IN PLARGE_INTEGER FileOffset,
  23902. IN ULONG Length,
  23903. OUT PMDL *MdlChain,
  23904. OUT PIO_STATUS_BLOCK IoStatus
  23905. );
  23906. //
  23907. // This routine is now a wrapper for FastIo if present or CcMdlReadComplete2
  23908. //
  23909. NTKERNELAPI
  23910. VOID
  23911. CcMdlReadComplete (
  23912. IN PFILE_OBJECT FileObject,
  23913. IN PMDL MdlChain
  23914. );
  23915. NTKERNELAPI
  23916. VOID
  23917. CcPrepareMdlWrite (
  23918. IN PFILE_OBJECT FileObject,
  23919. IN PLARGE_INTEGER FileOffset,
  23920. IN ULONG Length,
  23921. OUT PMDL *MdlChain,
  23922. OUT PIO_STATUS_BLOCK IoStatus
  23923. );
  23924. //
  23925. // This routine is now a wrapper for FastIo if present or CcMdlWriteComplete2
  23926. //
  23927. NTKERNELAPI
  23928. VOID
  23929. CcMdlWriteComplete (
  23930. IN PFILE_OBJECT FileObject,
  23931. IN PLARGE_INTEGER FileOffset,
  23932. IN PMDL MdlChain
  23933. );
  23934. VOID
  23935. CcMdlWriteAbort (
  23936. IN PFILE_OBJECT FileObject,
  23937. IN PMDL MdlChain
  23938. );
  23939. //
  23940. // Common ReadAhead call for Copy Read and Mdl Read.
  23941. //
  23942. // ReadAhead should always be invoked by calling the CcReadAhead macro,
  23943. // which tests first to see if the read is large enough to warrant read
  23944. // ahead. Measurements have shown that, calling the read ahead routine
  23945. // actually decreases performance for small reads, such as issued by
  23946. // many compilers and linkers. Compilers simply want all of the include
  23947. // files to stay in memory after being read the first time.
  23948. //
  23949. #define CcReadAhead(FO,FOFF,LEN) { \
  23950. if ((LEN) >= 256) { \
  23951. CcScheduleReadAhead((FO),(FOFF),(LEN)); \
  23952. } \
  23953. }
  23954. NTKERNELAPI
  23955. VOID
  23956. CcScheduleReadAhead (
  23957. IN PFILE_OBJECT FileObject,
  23958. IN PLARGE_INTEGER FileOffset,
  23959. IN ULONG Length
  23960. );
  23961. //
  23962. // The following routine allows a caller to wait for the next batch
  23963. // of lazy writer work to complete. In particular, this provides a
  23964. // mechanism for a caller to be sure that all avaliable lazy closes
  23965. // at the time of this call have issued.
  23966. //
  23967. NTSTATUS
  23968. CcWaitForCurrentLazyWriterActivity (
  23969. VOID
  23970. );
  23971. //
  23972. // This routine changes the read ahead granularity for a file, which is
  23973. // PAGE_SIZE by default.
  23974. //
  23975. NTKERNELAPI
  23976. VOID
  23977. CcSetReadAheadGranularity (
  23978. IN PFILE_OBJECT FileObject,
  23979. IN ULONG Granularity
  23980. );
  23981. //
  23982. // The following routines provide direct access data which is pinned in the
  23983. // cache, and is primarily intended for use by File Systems. In particular,
  23984. // this mode of access is ideal for dealing with volume structures.
  23985. //
  23986. //
  23987. // Flags for pinning
  23988. //
  23989. //
  23990. // Synchronous Wait - normally specified. This pattern may be specified as TRUE.
  23991. //
  23992. #define PIN_WAIT (1)
  23993. //
  23994. // Acquire metadata Bcb exclusive (default is shared, Lazy Writer uses exclusive).
  23995. //
  23996. // Must be set with PIN_WAIT.
  23997. //
  23998. #define PIN_EXCLUSIVE (2)
  23999. //
  24000. // Acquire metadata Bcb but do not fault data in. Default is to fault the data in.
  24001. // This unusual flag is only used by Ntfs for cache coherency synchronization between
  24002. // compressed and uncompressed streams for the same compressed file.
  24003. //
  24004. // Must be set with PIN_WAIT.
  24005. //
  24006. #define PIN_NO_READ (4)
  24007. //
  24008. // This option may be used to pin data only if the Bcb already exists. If the Bcb
  24009. // does not already exist - the pin is unsuccessful and no Bcb is returned. This routine
  24010. // provides a way to see if data is already pinned (and possibly dirty) in the cache,
  24011. // without forcing a fault if the data is not there.
  24012. //
  24013. #define PIN_IF_BCB (8)
  24014. //
  24015. // Flags for mapping
  24016. //
  24017. //
  24018. // Synchronous Wait - normally specified. This pattern may be specified as TRUE.
  24019. //
  24020. #define MAP_WAIT (1)
  24021. //
  24022. // Acquire metadata Bcb but do not fault data in. Default is to fault the data in.
  24023. // This should not overlap with any of the PIN_ flags so they can be passed down to
  24024. // CcPinFileData
  24025. //
  24026. #define MAP_NO_READ (16)
  24027. NTKERNELAPI
  24028. BOOLEAN
  24029. CcPinRead (
  24030. IN PFILE_OBJECT FileObject,
  24031. IN PLARGE_INTEGER FileOffset,
  24032. IN ULONG Length,
  24033. IN ULONG Flags,
  24034. OUT PVOID *Bcb,
  24035. OUT PVOID *Buffer
  24036. );
  24037. NTKERNELAPI
  24038. BOOLEAN
  24039. CcMapData (
  24040. IN PFILE_OBJECT FileObject,
  24041. IN PLARGE_INTEGER FileOffset,
  24042. IN ULONG Length,
  24043. IN ULONG Flags,
  24044. OUT PVOID *Bcb,
  24045. OUT PVOID *Buffer
  24046. );
  24047. NTKERNELAPI
  24048. BOOLEAN
  24049. CcPinMappedData (
  24050. IN PFILE_OBJECT FileObject,
  24051. IN PLARGE_INTEGER FileOffset,
  24052. IN ULONG Length,
  24053. IN ULONG Flags,
  24054. IN OUT PVOID *Bcb
  24055. );
  24056. NTKERNELAPI
  24057. BOOLEAN
  24058. CcPreparePinWrite (
  24059. IN PFILE_OBJECT FileObject,
  24060. IN PLARGE_INTEGER FileOffset,
  24061. IN ULONG Length,
  24062. IN BOOLEAN Zero,
  24063. IN ULONG Flags,
  24064. OUT PVOID *Bcb,
  24065. OUT PVOID *Buffer
  24066. );
  24067. NTKERNELAPI
  24068. VOID
  24069. CcSetDirtyPinnedData (
  24070. IN PVOID BcbVoid,
  24071. IN PLARGE_INTEGER Lsn OPTIONAL
  24072. );
  24073. NTKERNELAPI
  24074. VOID
  24075. CcUnpinData (
  24076. IN PVOID Bcb
  24077. );
  24078. NTKERNELAPI
  24079. VOID
  24080. CcSetBcbOwnerPointer (
  24081. IN PVOID Bcb,
  24082. IN PVOID OwnerPointer
  24083. );
  24084. NTKERNELAPI
  24085. VOID
  24086. CcUnpinDataForThread (
  24087. IN PVOID Bcb,
  24088. IN ERESOURCE_THREAD ResourceThreadId
  24089. );
  24090. NTKERNELAPI
  24091. VOID
  24092. CcSetAdditionalCacheAttributes (
  24093. IN PFILE_OBJECT FileObject,
  24094. IN BOOLEAN DisableReadAhead,
  24095. IN BOOLEAN DisableWriteBehind
  24096. );
  24097. NTKERNELAPI
  24098. VOID
  24099. CcSetLogHandleForFile (
  24100. IN PFILE_OBJECT FileObject,
  24101. IN PVOID LogHandle,
  24102. IN PFLUSH_TO_LSN FlushToLsnRoutine
  24103. );
  24104. NTKERNELAPI
  24105. LARGE_INTEGER
  24106. CcGetDirtyPages (
  24107. IN PVOID LogHandle,
  24108. IN PDIRTY_PAGE_ROUTINE DirtyPageRoutine,
  24109. IN PVOID Context1,
  24110. IN PVOID Context2
  24111. );
  24112. NTKERNELAPI
  24113. BOOLEAN
  24114. CcIsThereDirtyData (
  24115. IN PVPB Vpb
  24116. );
  24117. #ifdef RUN_WPP
  24118. #include <evntrace.h>
  24119. #include <stdarg.h>
  24120. #endif // #ifdef RUN_WPP
  24121. #ifdef RUN_WPP
  24122. NTKERNELAPI
  24123. NTSTATUS
  24124. WmiTraceMessage(
  24125. IN TRACEHANDLE LoggerHandle,
  24126. IN ULONG MessageFlags,
  24127. IN LPGUID MessageGuid,
  24128. IN USHORT MessageNumber,
  24129. IN ...
  24130. );
  24131. NTKERNELAPI
  24132. NTSTATUS
  24133. WmiTraceMessageVa(
  24134. IN TRACEHANDLE LoggerHandle,
  24135. IN ULONG MessageFlags,
  24136. IN LPGUID MessageGuid,
  24137. IN USHORT MessageNumber,
  24138. IN va_list MessageArgList
  24139. );
  24140. #endif // #ifdef RUN_WPP
  24141. #ifndef TRACE_INFORMATION_CLASS_DEFINE
  24142. typedef enum _TRACE_INFORMATION_CLASS {
  24143. TraceIdClass,
  24144. TraceHandleClass,
  24145. TraceEnableFlagsClass,
  24146. TraceEnableLevelClass,
  24147. GlobalLoggerHandleClass,
  24148. EventLoggerHandleClass,
  24149. AllLoggerHandlesClass,
  24150. TraceHandleByNameClass
  24151. } TRACE_INFORMATION_CLASS;
  24152. NTKERNELAPI
  24153. NTSTATUS
  24154. WmiQueryTraceInformation(
  24155. IN TRACE_INFORMATION_CLASS TraceInformationClass,
  24156. OUT PVOID TraceInformation,
  24157. IN ULONG TraceInformationLength,
  24158. OUT PULONG RequiredLength OPTIONAL,
  24159. IN PVOID Buffer OPTIONAL
  24160. );
  24161. #define TRACE_INFORMATION_CLASS_DEFINE
  24162. #endif // TRACE_INFOPRMATION_CLASS_DEFINE
  24163. #ifndef __SSPI_H__
  24164. #define __SSPI_H__
  24165. #define ISSP_LEVEL 32
  24166. #define ISSP_MODE 0
  24167. typedef WCHAR SEC_WCHAR;
  24168. typedef CHAR SEC_CHAR;
  24169. #ifndef __SECSTATUS_DEFINED__
  24170. typedef LONG SECURITY_STATUS;
  24171. #define __SECSTATUS_DEFINED__
  24172. #endif
  24173. #define SEC_TEXT TEXT
  24174. #define SEC_FAR
  24175. #define SEC_ENTRY __stdcall
  24176. #ifndef __SECHANDLE_DEFINED__
  24177. typedef struct _SecHandle
  24178. {
  24179. ULONG_PTR dwLower ;
  24180. ULONG_PTR dwUpper ;
  24181. } SecHandle, * PSecHandle ;
  24182. #define __SECHANDLE_DEFINED__
  24183. #endif // __SECHANDLE_DEFINED__
  24184. #define SecInvalidateHandle( x ) \
  24185. ((PSecHandle) x)->dwLower = ((ULONG_PTR) ((INT_PTR)-1)) ; \
  24186. ((PSecHandle) x)->dwUpper = ((ULONG_PTR) ((INT_PTR)-1)) ; \
  24187. #define SecIsValidHandle( x ) \
  24188. ( ( ((PSecHandle) x)->dwLower != ((ULONG_PTR) ((INT_PTR) -1 ))) && \
  24189. ( ((PSecHandle) x)->dwUpper != ((ULONG_PTR) ((INT_PTR) -1 ))) )
  24190. typedef SecHandle CredHandle;
  24191. typedef PSecHandle PCredHandle;
  24192. typedef SecHandle CtxtHandle;
  24193. typedef PSecHandle PCtxtHandle;
  24194. typedef LARGE_INTEGER _SECURITY_INTEGER, SECURITY_INTEGER, *PSECURITY_INTEGER;
  24195. typedef SECURITY_INTEGER TimeStamp;
  24196. typedef SECURITY_INTEGER SEC_FAR * PTimeStamp;
  24197. typedef UNICODE_STRING SECURITY_STRING, *PSECURITY_STRING;
  24198. //
  24199. // SecPkgInfo structure
  24200. //
  24201. // Provides general information about a security provider
  24202. //
  24203. typedef struct _SecPkgInfoW
  24204. {
  24205. unsigned long fCapabilities; // Capability bitmask
  24206. unsigned short wVersion; // Version of driver
  24207. unsigned short wRPCID; // ID for RPC Runtime
  24208. unsigned long cbMaxToken; // Size of authentication token (max)
  24209. #ifdef MIDL_PASS
  24210. [string]
  24211. #endif
  24212. SEC_WCHAR SEC_FAR * Name; // Text name
  24213. #ifdef MIDL_PASS
  24214. [string]
  24215. #endif
  24216. SEC_WCHAR SEC_FAR * Comment; // Comment
  24217. } SecPkgInfoW, SEC_FAR * PSecPkgInfoW;
  24218. # define SecPkgInfo SecPkgInfoW
  24219. # define PSecPkgInfo PSecPkgInfoW
  24220. //
  24221. // Security Package Capabilities
  24222. //
  24223. #define SECPKG_FLAG_INTEGRITY 0x00000001 // Supports integrity on messages
  24224. #define SECPKG_FLAG_PRIVACY 0x00000002 // Supports privacy (confidentiality)
  24225. #define SECPKG_FLAG_TOKEN_ONLY 0x00000004 // Only security token needed
  24226. #define SECPKG_FLAG_DATAGRAM 0x00000008 // Datagram RPC support
  24227. #define SECPKG_FLAG_CONNECTION 0x00000010 // Connection oriented RPC support
  24228. #define SECPKG_FLAG_MULTI_REQUIRED 0x00000020 // Full 3-leg required for re-auth.
  24229. #define SECPKG_FLAG_CLIENT_ONLY 0x00000040 // Server side functionality not available
  24230. #define SECPKG_FLAG_EXTENDED_ERROR 0x00000080 // Supports extended error msgs
  24231. #define SECPKG_FLAG_IMPERSONATION 0x00000100 // Supports impersonation
  24232. #define SECPKG_FLAG_ACCEPT_WIN32_NAME 0x00000200 // Accepts Win32 names
  24233. #define SECPKG_FLAG_STREAM 0x00000400 // Supports stream semantics
  24234. #define SECPKG_FLAG_NEGOTIABLE 0x00000800 // Can be used by the negotiate package
  24235. #define SECPKG_FLAG_GSS_COMPATIBLE 0x00001000 // GSS Compatibility Available
  24236. #define SECPKG_FLAG_LOGON 0x00002000 // Supports common LsaLogonUser
  24237. #define SECPKG_FLAG_ASCII_BUFFERS 0x00004000 // Token Buffers are in ASCII
  24238. #define SECPKG_FLAG_FRAGMENT 0x00008000 // Package can fragment to fit
  24239. #define SECPKG_FLAG_MUTUAL_AUTH 0x00010000 // Package can perform mutual authentication
  24240. #define SECPKG_FLAG_DELEGATION 0x00020000 // Package can delegate
  24241. #define SECPKG_FLAG_READONLY_WITH_CHECKSUM 0x00040000 // Package can delegate
  24242. #define SECPKG_ID_NONE 0xFFFF
  24243. //
  24244. // SecBuffer
  24245. //
  24246. // Generic memory descriptors for buffers passed in to the security
  24247. // API
  24248. //
  24249. typedef struct _SecBuffer {
  24250. unsigned long cbBuffer; // Size of the buffer, in bytes
  24251. unsigned long BufferType; // Type of the buffer (below)
  24252. void SEC_FAR * pvBuffer; // Pointer to the buffer
  24253. } SecBuffer, SEC_FAR * PSecBuffer;
  24254. typedef struct _SecBufferDesc {
  24255. unsigned long ulVersion; // Version number
  24256. unsigned long cBuffers; // Number of buffers
  24257. #ifdef MIDL_PASS
  24258. [size_is(cBuffers)]
  24259. #endif
  24260. PSecBuffer pBuffers; // Pointer to array of buffers
  24261. } SecBufferDesc, SEC_FAR * PSecBufferDesc;
  24262. #define SECBUFFER_VERSION 0
  24263. #define SECBUFFER_EMPTY 0 // Undefined, replaced by provider
  24264. #define SECBUFFER_DATA 1 // Packet data
  24265. #define SECBUFFER_TOKEN 2 // Security token
  24266. #define SECBUFFER_PKG_PARAMS 3 // Package specific parameters
  24267. #define SECBUFFER_MISSING 4 // Missing Data indicator
  24268. #define SECBUFFER_EXTRA 5 // Extra data
  24269. #define SECBUFFER_STREAM_TRAILER 6 // Security Trailer
  24270. #define SECBUFFER_STREAM_HEADER 7 // Security Header
  24271. #define SECBUFFER_NEGOTIATION_INFO 8 // Hints from the negotiation pkg
  24272. #define SECBUFFER_PADDING 9 // non-data padding
  24273. #define SECBUFFER_STREAM 10 // whole encrypted message
  24274. #define SECBUFFER_MECHLIST 11
  24275. #define SECBUFFER_MECHLIST_SIGNATURE 12
  24276. #define SECBUFFER_TARGET 13
  24277. #define SECBUFFER_CHANNEL_BINDINGS 14
  24278. #define SECBUFFER_ATTRMASK 0xF0000000
  24279. #define SECBUFFER_READONLY 0x80000000 // Buffer is read-only, no checksum
  24280. #define SECBUFFER_READONLY_WITH_CHECKSUM 0x10000000 // Buffer is read-only, and checksummed
  24281. #define SECBUFFER_RESERVED 0x60000000 // Flags reserved to security system
  24282. typedef struct _SEC_NEGOTIATION_INFO {
  24283. unsigned long Size; // Size of this structure
  24284. unsigned long NameLength; // Length of name hint
  24285. SEC_WCHAR SEC_FAR * Name; // Name hint
  24286. void SEC_FAR * Reserved; // Reserved
  24287. } SEC_NEGOTIATION_INFO, SEC_FAR * PSEC_NEGOTIATION_INFO ;
  24288. typedef struct _SEC_CHANNEL_BINDINGS {
  24289. unsigned long dwInitiatorAddrType;
  24290. unsigned long cbInitiatorLength;
  24291. unsigned long dwInitiatorOffset;
  24292. unsigned long dwAcceptorAddrType;
  24293. unsigned long cbAcceptorLength;
  24294. unsigned long dwAcceptorOffset;
  24295. unsigned long cbApplicationDataLength;
  24296. unsigned long dwApplicationDataOffset;
  24297. } SEC_CHANNEL_BINDINGS, SEC_FAR * PSEC_CHANNEL_BINDINGS ;
  24298. //
  24299. // Data Representation Constant:
  24300. //
  24301. #define SECURITY_NATIVE_DREP 0x00000010
  24302. #define SECURITY_NETWORK_DREP 0x00000000
  24303. //
  24304. // Credential Use Flags
  24305. //
  24306. #define SECPKG_CRED_INBOUND 0x00000001
  24307. #define SECPKG_CRED_OUTBOUND 0x00000002
  24308. #define SECPKG_CRED_BOTH 0x00000003
  24309. #define SECPKG_CRED_DEFAULT 0x00000004
  24310. #define SECPKG_CRED_RESERVED 0xF0000000
  24311. //
  24312. // InitializeSecurityContext Requirement and return flags:
  24313. //
  24314. #define ISC_REQ_DELEGATE 0x00000001
  24315. #define ISC_REQ_MUTUAL_AUTH 0x00000002
  24316. #define ISC_REQ_REPLAY_DETECT 0x00000004
  24317. #define ISC_REQ_SEQUENCE_DETECT 0x00000008
  24318. #define ISC_REQ_CONFIDENTIALITY 0x00000010
  24319. #define ISC_REQ_USE_SESSION_KEY 0x00000020
  24320. #define ISC_REQ_PROMPT_FOR_CREDS 0x00000040
  24321. #define ISC_REQ_USE_SUPPLIED_CREDS 0x00000080
  24322. #define ISC_REQ_ALLOCATE_MEMORY 0x00000100
  24323. #define ISC_REQ_USE_DCE_STYLE 0x00000200
  24324. #define ISC_REQ_DATAGRAM 0x00000400
  24325. #define ISC_REQ_CONNECTION 0x00000800
  24326. #define ISC_REQ_CALL_LEVEL 0x00001000
  24327. #define ISC_REQ_FRAGMENT_SUPPLIED 0x00002000
  24328. #define ISC_REQ_EXTENDED_ERROR 0x00004000
  24329. #define ISC_REQ_STREAM 0x00008000
  24330. #define ISC_REQ_INTEGRITY 0x00010000
  24331. #define ISC_REQ_IDENTIFY 0x00020000
  24332. #define ISC_REQ_NULL_SESSION 0x00040000
  24333. #define ISC_REQ_MANUAL_CRED_VALIDATION 0x00080000
  24334. #define ISC_REQ_RESERVED1 0x00100000
  24335. #define ISC_REQ_FRAGMENT_TO_FIT 0x00200000
  24336. #define ISC_RET_DELEGATE 0x00000001
  24337. #define ISC_RET_MUTUAL_AUTH 0x00000002
  24338. #define ISC_RET_REPLAY_DETECT 0x00000004
  24339. #define ISC_RET_SEQUENCE_DETECT 0x00000008
  24340. #define ISC_RET_CONFIDENTIALITY 0x00000010
  24341. #define ISC_RET_USE_SESSION_KEY 0x00000020
  24342. #define ISC_RET_USED_COLLECTED_CREDS 0x00000040
  24343. #define ISC_RET_USED_SUPPLIED_CREDS 0x00000080
  24344. #define ISC_RET_ALLOCATED_MEMORY 0x00000100
  24345. #define ISC_RET_USED_DCE_STYLE 0x00000200
  24346. #define ISC_RET_DATAGRAM 0x00000400
  24347. #define ISC_RET_CONNECTION 0x00000800
  24348. #define ISC_RET_INTERMEDIATE_RETURN 0x00001000
  24349. #define ISC_RET_CALL_LEVEL 0x00002000
  24350. #define ISC_RET_EXTENDED_ERROR 0x00004000
  24351. #define ISC_RET_STREAM 0x00008000
  24352. #define ISC_RET_INTEGRITY 0x00010000
  24353. #define ISC_RET_IDENTIFY 0x00020000
  24354. #define ISC_RET_NULL_SESSION 0x00040000
  24355. #define ISC_RET_MANUAL_CRED_VALIDATION 0x00080000
  24356. #define ISC_RET_RESERVED1 0x00100000
  24357. #define ISC_RET_FRAGMENT_ONLY 0x00200000
  24358. #define ASC_REQ_DELEGATE 0x00000001
  24359. #define ASC_REQ_MUTUAL_AUTH 0x00000002
  24360. #define ASC_REQ_REPLAY_DETECT 0x00000004
  24361. #define ASC_REQ_SEQUENCE_DETECT 0x00000008
  24362. #define ASC_REQ_CONFIDENTIALITY 0x00000010
  24363. #define ASC_REQ_USE_SESSION_KEY 0x00000020
  24364. #define ASC_REQ_ALLOCATE_MEMORY 0x00000100
  24365. #define ASC_REQ_USE_DCE_STYLE 0x00000200
  24366. #define ASC_REQ_DATAGRAM 0x00000400
  24367. #define ASC_REQ_CONNECTION 0x00000800
  24368. #define ASC_REQ_CALL_LEVEL 0x00001000
  24369. #define ASC_REQ_EXTENDED_ERROR 0x00008000
  24370. #define ASC_REQ_STREAM 0x00010000
  24371. #define ASC_REQ_INTEGRITY 0x00020000
  24372. #define ASC_REQ_LICENSING 0x00040000
  24373. #define ASC_REQ_IDENTIFY 0x00080000
  24374. #define ASC_REQ_ALLOW_NULL_SESSION 0x00100000
  24375. #define ASC_REQ_ALLOW_NON_USER_LOGONS 0x00200000
  24376. #define ASC_REQ_ALLOW_CONTEXT_REPLAY 0x00400000
  24377. #define ASC_REQ_FRAGMENT_TO_FIT 0x00800000
  24378. #define ASC_REQ_FRAGMENT_SUPPLIED 0x00002000
  24379. #define ASC_REQ_NO_TOKEN 0x01000000
  24380. #define ASC_RET_DELEGATE 0x00000001
  24381. #define ASC_RET_MUTUAL_AUTH 0x00000002
  24382. #define ASC_RET_REPLAY_DETECT 0x00000004
  24383. #define ASC_RET_SEQUENCE_DETECT 0x00000008
  24384. #define ASC_RET_CONFIDENTIALITY 0x00000010
  24385. #define ASC_RET_USE_SESSION_KEY 0x00000020
  24386. #define ASC_RET_ALLOCATED_MEMORY 0x00000100
  24387. #define ASC_RET_USED_DCE_STYLE 0x00000200
  24388. #define ASC_RET_DATAGRAM 0x00000400
  24389. #define ASC_RET_CONNECTION 0x00000800
  24390. #define ASC_RET_CALL_LEVEL 0x00002000 // skipped 1000 to be like ISC_
  24391. #define ASC_RET_THIRD_LEG_FAILED 0x00004000
  24392. #define ASC_RET_EXTENDED_ERROR 0x00008000
  24393. #define ASC_RET_STREAM 0x00010000
  24394. #define ASC_RET_INTEGRITY 0x00020000
  24395. #define ASC_RET_LICENSING 0x00040000
  24396. #define ASC_RET_IDENTIFY 0x00080000
  24397. #define ASC_RET_NULL_SESSION 0x00100000
  24398. #define ASC_RET_ALLOW_NON_USER_LOGONS 0x00200000
  24399. #define ASC_RET_ALLOW_CONTEXT_REPLAY 0x00400000
  24400. #define ASC_RET_FRAGMENT_ONLY 0x00800000
  24401. #define ASC_RET_NO_TOKEN 0x01000000
  24402. //
  24403. // Security Credentials Attributes:
  24404. //
  24405. #define SECPKG_CRED_ATTR_NAMES 1
  24406. typedef struct _SecPkgCredentials_NamesW
  24407. {
  24408. SEC_WCHAR SEC_FAR * sUserName;
  24409. } SecPkgCredentials_NamesW, SEC_FAR * PSecPkgCredentials_NamesW;
  24410. # define SecPkgCredentials_Names SecPkgCredentials_NamesW
  24411. # define PSecPkgCredentials_Names PSecPkgCredentials_NamesW
  24412. //
  24413. // Security Context Attributes:
  24414. //
  24415. #define SECPKG_ATTR_SIZES 0
  24416. #define SECPKG_ATTR_NAMES 1
  24417. #define SECPKG_ATTR_LIFESPAN 2
  24418. #define SECPKG_ATTR_DCE_INFO 3
  24419. #define SECPKG_ATTR_STREAM_SIZES 4
  24420. #define SECPKG_ATTR_KEY_INFO 5
  24421. #define SECPKG_ATTR_AUTHORITY 6
  24422. #define SECPKG_ATTR_PROTO_INFO 7
  24423. #define SECPKG_ATTR_PASSWORD_EXPIRY 8
  24424. #define SECPKG_ATTR_SESSION_KEY 9
  24425. #define SECPKG_ATTR_PACKAGE_INFO 10
  24426. #define SECPKG_ATTR_USER_FLAGS 11
  24427. #define SECPKG_ATTR_NEGOTIATION_INFO 12
  24428. #define SECPKG_ATTR_NATIVE_NAMES 13
  24429. #define SECPKG_ATTR_FLAGS 14
  24430. #define SECPKG_ATTR_USE_VALIDATED 15
  24431. #define SECPKG_ATTR_CREDENTIAL_NAME 16
  24432. #define SECPKG_ATTR_TARGET_INFORMATION 17
  24433. #define SECPKG_ATTR_ACCESS_TOKEN 18
  24434. #define SECPKG_ATTR_TARGET 19
  24435. #define SECPKG_ATTR_AUTHENTICATION_ID 20
  24436. typedef struct _SecPkgContext_Sizes
  24437. {
  24438. unsigned long cbMaxToken;
  24439. unsigned long cbMaxSignature;
  24440. unsigned long cbBlockSize;
  24441. unsigned long cbSecurityTrailer;
  24442. } SecPkgContext_Sizes, SEC_FAR * PSecPkgContext_Sizes;
  24443. typedef struct _SecPkgContext_StreamSizes
  24444. {
  24445. unsigned long cbHeader;
  24446. unsigned long cbTrailer;
  24447. unsigned long cbMaximumMessage;
  24448. unsigned long cBuffers;
  24449. unsigned long cbBlockSize;
  24450. } SecPkgContext_StreamSizes, * PSecPkgContext_StreamSizes;
  24451. typedef struct _SecPkgContext_NamesW
  24452. {
  24453. SEC_WCHAR SEC_FAR * sUserName;
  24454. } SecPkgContext_NamesW, SEC_FAR * PSecPkgContext_NamesW;
  24455. # define SecPkgContext_Names SecPkgContext_NamesW
  24456. # define PSecPkgContext_Names PSecPkgContext_NamesW
  24457. typedef struct _SecPkgContext_Lifespan
  24458. {
  24459. TimeStamp tsStart;
  24460. TimeStamp tsExpiry;
  24461. } SecPkgContext_Lifespan, SEC_FAR * PSecPkgContext_Lifespan;
  24462. typedef struct _SecPkgContext_DceInfo
  24463. {
  24464. unsigned long AuthzSvc;
  24465. void SEC_FAR * pPac;
  24466. } SecPkgContext_DceInfo, SEC_FAR * PSecPkgContext_DceInfo;
  24467. typedef struct _SecPkgContext_KeyInfoW
  24468. {
  24469. SEC_WCHAR SEC_FAR * sSignatureAlgorithmName;
  24470. SEC_WCHAR SEC_FAR * sEncryptAlgorithmName;
  24471. unsigned long KeySize;
  24472. unsigned long SignatureAlgorithm;
  24473. unsigned long EncryptAlgorithm;
  24474. } SecPkgContext_KeyInfoW, SEC_FAR * PSecPkgContext_KeyInfoW;
  24475. #define SecPkgContext_KeyInfo SecPkgContext_KeyInfoW
  24476. #define PSecPkgContext_KeyInfo PSecPkgContext_KeyInfoW
  24477. typedef struct _SecPkgContext_AuthorityW
  24478. {
  24479. SEC_WCHAR SEC_FAR * sAuthorityName;
  24480. } SecPkgContext_AuthorityW, * PSecPkgContext_AuthorityW;
  24481. #define SecPkgContext_Authority SecPkgContext_AuthorityW
  24482. #define PSecPkgContext_Authority PSecPkgContext_AuthorityW
  24483. typedef struct _SecPkgContext_ProtoInfoW
  24484. {
  24485. SEC_WCHAR SEC_FAR * sProtocolName;
  24486. unsigned long majorVersion;
  24487. unsigned long minorVersion;
  24488. } SecPkgContext_ProtoInfoW, SEC_FAR * PSecPkgContext_ProtoInfoW;
  24489. #define SecPkgContext_ProtoInfo SecPkgContext_ProtoInfoW
  24490. #define PSecPkgContext_ProtoInfo PSecPkgContext_ProtoInfoW
  24491. typedef struct _SecPkgContext_PasswordExpiry
  24492. {
  24493. TimeStamp tsPasswordExpires;
  24494. } SecPkgContext_PasswordExpiry, SEC_FAR * PSecPkgContext_PasswordExpiry;
  24495. typedef struct _SecPkgContext_SessionKey
  24496. {
  24497. unsigned long SessionKeyLength;
  24498. unsigned char SEC_FAR * SessionKey;
  24499. } SecPkgContext_SessionKey, *PSecPkgContext_SessionKey;
  24500. typedef struct _SecPkgContext_PackageInfoW
  24501. {
  24502. PSecPkgInfoW PackageInfo;
  24503. } SecPkgContext_PackageInfoW, SEC_FAR * PSecPkgContext_PackageInfoW;
  24504. typedef struct _SecPkgContext_UserFlags
  24505. {
  24506. unsigned long UserFlags;
  24507. } SecPkgContext_UserFlags, SEC_FAR * PSecPkgContext_UserFlags;
  24508. typedef struct _SecPkgContext_Flags
  24509. {
  24510. unsigned long Flags;
  24511. } SecPkgContext_Flags, SEC_FAR * PSecPkgContext_Flags;
  24512. #define SecPkgContext_PackageInfo SecPkgContext_PackageInfoW
  24513. #define PSecPkgContext_PackageInfo PSecPkgContext_PackageInfoW
  24514. typedef struct _SecPkgContext_NegotiationInfoW
  24515. {
  24516. PSecPkgInfoW PackageInfo ;
  24517. unsigned long NegotiationState ;
  24518. } SecPkgContext_NegotiationInfoW, SEC_FAR * PSecPkgContext_NegotiationInfoW ;
  24519. # define SecPkgContext_NativeNames SecPkgContext_NativeNamesW
  24520. # define PSecPkgContext_NativeNames PSecPkgContext_NativeNamesW
  24521. typedef struct _SecPkgContext_CredentialNameW
  24522. {
  24523. unsigned long CredentialType;
  24524. SEC_WCHAR SEC_FAR *sCredentialName;
  24525. } SecPkgContext_CredentialNameW, SEC_FAR * PSecPkgContext_CredentialNameW;
  24526. # define SecPkgContext_CredentialName SecPkgContext_CredentialNameW
  24527. # define PSecPkgContext_CredentialName PSecPkgContext_CredentialNameW
  24528. typedef void
  24529. (SEC_ENTRY SEC_FAR * SEC_GET_KEY_FN) (
  24530. void SEC_FAR * Arg, // Argument passed in
  24531. void SEC_FAR * Principal, // Principal ID
  24532. unsigned long KeyVer, // Key Version
  24533. void SEC_FAR * SEC_FAR * Key, // Returned ptr to key
  24534. SECURITY_STATUS SEC_FAR * Status // returned status
  24535. );
  24536. //
  24537. // Flags for ExportSecurityContext
  24538. //
  24539. #define SECPKG_CONTEXT_EXPORT_RESET_NEW 0x00000001 // New context is reset to initial state
  24540. #define SECPKG_CONTEXT_EXPORT_DELETE_OLD 0x00000002 // Old context is deleted during export
  24541. SECURITY_STATUS SEC_ENTRY
  24542. AcquireCredentialsHandleW(
  24543. #if ISSP_MODE == 0 // For Kernel mode
  24544. PSECURITY_STRING pPrincipal,
  24545. PSECURITY_STRING pPackage,
  24546. #else
  24547. SEC_WCHAR SEC_FAR * pszPrincipal, // Name of principal
  24548. SEC_WCHAR SEC_FAR * pszPackage, // Name of package
  24549. #endif
  24550. unsigned long fCredentialUse, // Flags indicating use
  24551. void SEC_FAR * pvLogonId, // Pointer to logon ID
  24552. void SEC_FAR * pAuthData, // Package specific data
  24553. SEC_GET_KEY_FN pGetKeyFn, // Pointer to GetKey() func
  24554. void SEC_FAR * pvGetKeyArgument, // Value to pass to GetKey()
  24555. PCredHandle phCredential, // (out) Cred Handle
  24556. PTimeStamp ptsExpiry // (out) Lifetime (optional)
  24557. );
  24558. typedef SECURITY_STATUS
  24559. (SEC_ENTRY * ACQUIRE_CREDENTIALS_HANDLE_FN_W)(
  24560. #if ISSP_MODE == 0
  24561. PSECURITY_STRING,
  24562. PSECURITY_STRING,
  24563. #else
  24564. SEC_WCHAR SEC_FAR *,
  24565. SEC_WCHAR SEC_FAR *,
  24566. #endif
  24567. unsigned long,
  24568. void SEC_FAR *,
  24569. void SEC_FAR *,
  24570. SEC_GET_KEY_FN,
  24571. void SEC_FAR *,
  24572. PCredHandle,
  24573. PTimeStamp);
  24574. # define AcquireCredentialsHandle AcquireCredentialsHandleW
  24575. # define ACQUIRE_CREDENTIALS_HANDLE_FN ACQUIRE_CREDENTIALS_HANDLE_FN_W
  24576. SECURITY_STATUS SEC_ENTRY
  24577. FreeCredentialsHandle(
  24578. PCredHandle phCredential // Handle to free
  24579. );
  24580. typedef SECURITY_STATUS
  24581. (SEC_ENTRY * FREE_CREDENTIALS_HANDLE_FN)(
  24582. PCredHandle );
  24583. SECURITY_STATUS SEC_ENTRY
  24584. AddCredentialsW(
  24585. PCredHandle hCredentials,
  24586. #if ISSP_MODE == 0 // For Kernel mode
  24587. PSECURITY_STRING pPrincipal,
  24588. PSECURITY_STRING pPackage,
  24589. #else
  24590. SEC_WCHAR SEC_FAR * pszPrincipal, // Name of principal
  24591. SEC_WCHAR SEC_FAR * pszPackage, // Name of package
  24592. #endif
  24593. unsigned long fCredentialUse, // Flags indicating use
  24594. void SEC_FAR * pAuthData, // Package specific data
  24595. SEC_GET_KEY_FN pGetKeyFn, // Pointer to GetKey() func
  24596. void SEC_FAR * pvGetKeyArgument, // Value to pass to GetKey()
  24597. PTimeStamp ptsExpiry // (out) Lifetime (optional)
  24598. );
  24599. typedef SECURITY_STATUS
  24600. (SEC_ENTRY * ADD_CREDENTIALS_FN_W)(
  24601. PCredHandle,
  24602. #if ISSP_MODE == 0
  24603. PSECURITY_STRING,
  24604. PSECURITY_STRING,
  24605. #else
  24606. SEC_WCHAR SEC_FAR *,
  24607. SEC_WCHAR SEC_FAR *,
  24608. #endif
  24609. unsigned long,
  24610. void SEC_FAR *,
  24611. SEC_GET_KEY_FN,
  24612. void SEC_FAR *,
  24613. PTimeStamp);
  24614. SECURITY_STATUS SEC_ENTRY
  24615. AddCredentialsA(
  24616. PCredHandle hCredentials,
  24617. SEC_CHAR SEC_FAR * pszPrincipal, // Name of principal
  24618. SEC_CHAR SEC_FAR * pszPackage, // Name of package
  24619. unsigned long fCredentialUse, // Flags indicating use
  24620. void SEC_FAR * pAuthData, // Package specific data
  24621. SEC_GET_KEY_FN pGetKeyFn, // Pointer to GetKey() func
  24622. void SEC_FAR * pvGetKeyArgument, // Value to pass to GetKey()
  24623. PTimeStamp ptsExpiry // (out) Lifetime (optional)
  24624. );
  24625. typedef SECURITY_STATUS
  24626. (SEC_ENTRY * ADD_CREDENTIALS_FN_A)(
  24627. PCredHandle,
  24628. SEC_CHAR SEC_FAR *,
  24629. SEC_CHAR SEC_FAR *,
  24630. unsigned long,
  24631. void SEC_FAR *,
  24632. SEC_GET_KEY_FN,
  24633. void SEC_FAR *,
  24634. PTimeStamp);
  24635. #ifdef UNICODE
  24636. #define AddCredentials AddCredentialsW
  24637. #define ADD_CREDENTIALS_FN ADD_CREDENTIALS_FN_W
  24638. #else
  24639. #define AddCredentials AddCredentialsA
  24640. #define ADD_CREDENTIALS_FN ADD_CREDENTIALS_FN_A
  24641. #endif
  24642. ////////////////////////////////////////////////////////////////////////
  24643. ///
  24644. /// Context Management Functions
  24645. ///
  24646. ////////////////////////////////////////////////////////////////////////
  24647. SECURITY_STATUS SEC_ENTRY
  24648. InitializeSecurityContextW(
  24649. PCredHandle phCredential, // Cred to base context
  24650. PCtxtHandle phContext, // Existing context (OPT)
  24651. #if ISSP_MODE == 0
  24652. PSECURITY_STRING pTargetName,
  24653. #else
  24654. SEC_WCHAR SEC_FAR * pszTargetName, // Name of target
  24655. #endif
  24656. unsigned long fContextReq, // Context Requirements
  24657. unsigned long Reserved1, // Reserved, MBZ
  24658. unsigned long TargetDataRep, // Data rep of target
  24659. PSecBufferDesc pInput, // Input Buffers
  24660. unsigned long Reserved2, // Reserved, MBZ
  24661. PCtxtHandle phNewContext, // (out) New Context handle
  24662. PSecBufferDesc pOutput, // (inout) Output Buffers
  24663. unsigned long SEC_FAR * pfContextAttr, // (out) Context attrs
  24664. PTimeStamp ptsExpiry // (out) Life span (OPT)
  24665. );
  24666. typedef SECURITY_STATUS
  24667. (SEC_ENTRY * INITIALIZE_SECURITY_CONTEXT_FN_W)(
  24668. PCredHandle,
  24669. PCtxtHandle,
  24670. #if ISSP_MODE == 0
  24671. PSECURITY_STRING,
  24672. #else
  24673. SEC_WCHAR SEC_FAR *,
  24674. #endif
  24675. unsigned long,
  24676. unsigned long,
  24677. unsigned long,
  24678. PSecBufferDesc,
  24679. unsigned long,
  24680. PCtxtHandle,
  24681. PSecBufferDesc,
  24682. unsigned long SEC_FAR *,
  24683. PTimeStamp);
  24684. # define InitializeSecurityContext InitializeSecurityContextW
  24685. # define INITIALIZE_SECURITY_CONTEXT_FN INITIALIZE_SECURITY_CONTEXT_FN_W
  24686. SECURITY_STATUS SEC_ENTRY
  24687. AcceptSecurityContext(
  24688. PCredHandle phCredential, // Cred to base context
  24689. PCtxtHandle phContext, // Existing context (OPT)
  24690. PSecBufferDesc pInput, // Input buffer
  24691. unsigned long fContextReq, // Context Requirements
  24692. unsigned long TargetDataRep, // Target Data Rep
  24693. PCtxtHandle phNewContext, // (out) New context handle
  24694. PSecBufferDesc pOutput, // (inout) Output buffers
  24695. unsigned long SEC_FAR * pfContextAttr, // (out) Context attributes
  24696. PTimeStamp ptsExpiry // (out) Life span (OPT)
  24697. );
  24698. typedef SECURITY_STATUS
  24699. (SEC_ENTRY * ACCEPT_SECURITY_CONTEXT_FN)(
  24700. PCredHandle,
  24701. PCtxtHandle,
  24702. PSecBufferDesc,
  24703. unsigned long,
  24704. unsigned long,
  24705. PCtxtHandle,
  24706. PSecBufferDesc,
  24707. unsigned long SEC_FAR *,
  24708. PTimeStamp);
  24709. SECURITY_STATUS SEC_ENTRY
  24710. CompleteAuthToken(
  24711. PCtxtHandle phContext, // Context to complete
  24712. PSecBufferDesc pToken // Token to complete
  24713. );
  24714. typedef SECURITY_STATUS
  24715. (SEC_ENTRY * COMPLETE_AUTH_TOKEN_FN)(
  24716. PCtxtHandle,
  24717. PSecBufferDesc);
  24718. SECURITY_STATUS SEC_ENTRY
  24719. ImpersonateSecurityContext(
  24720. PCtxtHandle phContext // Context to impersonate
  24721. );
  24722. typedef SECURITY_STATUS
  24723. (SEC_ENTRY * IMPERSONATE_SECURITY_CONTEXT_FN)(
  24724. PCtxtHandle);
  24725. SECURITY_STATUS SEC_ENTRY
  24726. RevertSecurityContext(
  24727. PCtxtHandle phContext // Context from which to re
  24728. );
  24729. typedef SECURITY_STATUS
  24730. (SEC_ENTRY * REVERT_SECURITY_CONTEXT_FN)(
  24731. PCtxtHandle);
  24732. SECURITY_STATUS SEC_ENTRY
  24733. QuerySecurityContextToken(
  24734. PCtxtHandle phContext,
  24735. void SEC_FAR * SEC_FAR * Token
  24736. );
  24737. typedef SECURITY_STATUS
  24738. (SEC_ENTRY * QUERY_SECURITY_CONTEXT_TOKEN_FN)(
  24739. PCtxtHandle, void SEC_FAR * SEC_FAR *);
  24740. SECURITY_STATUS SEC_ENTRY
  24741. DeleteSecurityContext(
  24742. PCtxtHandle phContext // Context to delete
  24743. );
  24744. typedef SECURITY_STATUS
  24745. (SEC_ENTRY * DELETE_SECURITY_CONTEXT_FN)(
  24746. PCtxtHandle);
  24747. SECURITY_STATUS SEC_ENTRY
  24748. ApplyControlToken(
  24749. PCtxtHandle phContext, // Context to modify
  24750. PSecBufferDesc pInput // Input token to apply
  24751. );
  24752. typedef SECURITY_STATUS
  24753. (SEC_ENTRY * APPLY_CONTROL_TOKEN_FN)(
  24754. PCtxtHandle, PSecBufferDesc);
  24755. SECURITY_STATUS SEC_ENTRY
  24756. QueryContextAttributesW(
  24757. PCtxtHandle phContext, // Context to query
  24758. unsigned long ulAttribute, // Attribute to query
  24759. void SEC_FAR * pBuffer // Buffer for attributes
  24760. );
  24761. typedef SECURITY_STATUS
  24762. (SEC_ENTRY * QUERY_CONTEXT_ATTRIBUTES_FN_W)(
  24763. PCtxtHandle,
  24764. unsigned long,
  24765. void SEC_FAR *);
  24766. # define QueryContextAttributes QueryContextAttributesW
  24767. # define QUERY_CONTEXT_ATTRIBUTES_FN QUERY_CONTEXT_ATTRIBUTES_FN_W
  24768. SECURITY_STATUS SEC_ENTRY
  24769. SetContextAttributesW(
  24770. PCtxtHandle phContext, // Context to Set
  24771. unsigned long ulAttribute, // Attribute to Set
  24772. void SEC_FAR * pBuffer, // Buffer for attributes
  24773. unsigned long cbBuffer // Size (in bytes) of Buffer
  24774. );
  24775. typedef SECURITY_STATUS
  24776. (SEC_ENTRY * SET_CONTEXT_ATTRIBUTES_FN_W)(
  24777. PCtxtHandle,
  24778. unsigned long,
  24779. void SEC_FAR *,
  24780. unsigned long );
  24781. # define SetContextAttributes SetContextAttributesW
  24782. # define SET_CONTEXT_ATTRIBUTES_FN SET_CONTEXT_ATTRIBUTES_FN_W
  24783. SECURITY_STATUS SEC_ENTRY
  24784. QueryCredentialsAttributesW(
  24785. PCredHandle phCredential, // Credential to query
  24786. unsigned long ulAttribute, // Attribute to query
  24787. void SEC_FAR * pBuffer // Buffer for attributes
  24788. );
  24789. typedef SECURITY_STATUS
  24790. (SEC_ENTRY * QUERY_CREDENTIALS_ATTRIBUTES_FN_W)(
  24791. PCredHandle,
  24792. unsigned long,
  24793. void SEC_FAR *);
  24794. # define QueryCredentialsAttributes QueryCredentialsAttributesW
  24795. # define QUERY_CREDENTIALS_ATTRIBUTES_FN QUERY_CREDENTIALS_ATTRIBUTES_FN_W
  24796. SECURITY_STATUS SEC_ENTRY
  24797. FreeContextBuffer(
  24798. void SEC_FAR * pvContextBuffer // buffer to free
  24799. );
  24800. typedef SECURITY_STATUS
  24801. (SEC_ENTRY * FREE_CONTEXT_BUFFER_FN)(
  24802. void SEC_FAR *);
  24803. ///////////////////////////////////////////////////////////////////
  24804. ////
  24805. //// Message Support API
  24806. ////
  24807. //////////////////////////////////////////////////////////////////
  24808. SECURITY_STATUS SEC_ENTRY
  24809. MakeSignature(
  24810. PCtxtHandle phContext, // Context to use
  24811. unsigned long fQOP, // Quality of Protection
  24812. PSecBufferDesc pMessage, // Message to sign
  24813. unsigned long MessageSeqNo // Message Sequence Num.
  24814. );
  24815. typedef SECURITY_STATUS
  24816. (SEC_ENTRY * MAKE_SIGNATURE_FN)(
  24817. PCtxtHandle,
  24818. unsigned long,
  24819. PSecBufferDesc,
  24820. unsigned long);
  24821. SECURITY_STATUS SEC_ENTRY
  24822. VerifySignature(
  24823. PCtxtHandle phContext, // Context to use
  24824. PSecBufferDesc pMessage, // Message to verify
  24825. unsigned long MessageSeqNo, // Sequence Num.
  24826. unsigned long SEC_FAR * pfQOP // QOP used
  24827. );
  24828. typedef SECURITY_STATUS
  24829. (SEC_ENTRY * VERIFY_SIGNATURE_FN)(
  24830. PCtxtHandle,
  24831. PSecBufferDesc,
  24832. unsigned long,
  24833. unsigned long SEC_FAR *);
  24834. #define SECQOP_WRAP_NO_ENCRYPT 0x80000001
  24835. SECURITY_STATUS SEC_ENTRY
  24836. EncryptMessage( PCtxtHandle phContext,
  24837. unsigned long fQOP,
  24838. PSecBufferDesc pMessage,
  24839. unsigned long MessageSeqNo);
  24840. typedef SECURITY_STATUS
  24841. (SEC_ENTRY * ENCRYPT_MESSAGE_FN)(
  24842. PCtxtHandle, unsigned long, PSecBufferDesc, unsigned long);
  24843. SECURITY_STATUS SEC_ENTRY
  24844. DecryptMessage( PCtxtHandle phContext,
  24845. PSecBufferDesc pMessage,
  24846. unsigned long MessageSeqNo,
  24847. unsigned long * pfQOP);
  24848. typedef SECURITY_STATUS
  24849. (SEC_ENTRY * DECRYPT_MESSAGE_FN)(
  24850. PCtxtHandle, PSecBufferDesc, unsigned long,
  24851. unsigned long SEC_FAR *);
  24852. ///////////////////////////////////////////////////////////////////////////
  24853. ////
  24854. //// Misc.
  24855. ////
  24856. ///////////////////////////////////////////////////////////////////////////
  24857. SECURITY_STATUS SEC_ENTRY
  24858. EnumerateSecurityPackagesW(
  24859. unsigned long SEC_FAR * pcPackages, // Receives num. packages
  24860. PSecPkgInfoW SEC_FAR * ppPackageInfo // Receives array of info
  24861. );
  24862. typedef SECURITY_STATUS
  24863. (SEC_ENTRY * ENUMERATE_SECURITY_PACKAGES_FN_W)(
  24864. unsigned long SEC_FAR *,
  24865. PSecPkgInfoW SEC_FAR *);
  24866. # define EnumerateSecurityPackages EnumerateSecurityPackagesW
  24867. # define ENUMERATE_SECURITY_PACKAGES_FN ENUMERATE_SECURITY_PACKAGES_FN_W
  24868. SECURITY_STATUS SEC_ENTRY
  24869. QuerySecurityPackageInfoW(
  24870. #if ISSP_MODE == 0
  24871. PSECURITY_STRING pPackageName,
  24872. #else
  24873. SEC_WCHAR SEC_FAR * pszPackageName, // Name of package
  24874. #endif
  24875. PSecPkgInfoW SEC_FAR *ppPackageInfo // Receives package info
  24876. );
  24877. typedef SECURITY_STATUS
  24878. (SEC_ENTRY * QUERY_SECURITY_PACKAGE_INFO_FN_W)(
  24879. #if ISSP_MODE == 0
  24880. PSECURITY_STRING,
  24881. #else
  24882. SEC_WCHAR SEC_FAR *,
  24883. #endif
  24884. PSecPkgInfoW SEC_FAR *);
  24885. # define QuerySecurityPackageInfo QuerySecurityPackageInfoW
  24886. # define QUERY_SECURITY_PACKAGE_INFO_FN QUERY_SECURITY_PACKAGE_INFO_FN_W
  24887. ///////////////////////////////////////////////////////////////////////////
  24888. ////
  24889. //// Context export/import
  24890. ////
  24891. ///////////////////////////////////////////////////////////////////////////
  24892. SECURITY_STATUS SEC_ENTRY
  24893. ExportSecurityContext(
  24894. PCtxtHandle phContext, // (in) context to export
  24895. ULONG fFlags, // (in) option flags
  24896. PSecBuffer pPackedContext, // (out) marshalled context
  24897. void SEC_FAR * SEC_FAR * pToken // (out, optional) token handle for impersonation
  24898. );
  24899. typedef SECURITY_STATUS
  24900. (SEC_ENTRY * EXPORT_SECURITY_CONTEXT_FN)(
  24901. PCtxtHandle,
  24902. ULONG,
  24903. PSecBuffer,
  24904. void SEC_FAR * SEC_FAR *
  24905. );
  24906. SECURITY_STATUS SEC_ENTRY
  24907. ImportSecurityContextW(
  24908. #if ISSP_MODE == 0
  24909. PSECURITY_STRING pszPackage,
  24910. #else
  24911. SEC_WCHAR SEC_FAR * pszPackage,
  24912. #endif
  24913. PSecBuffer pPackedContext, // (in) marshalled context
  24914. void SEC_FAR * Token, // (in, optional) handle to token for context
  24915. PCtxtHandle phContext // (out) new context handle
  24916. );
  24917. typedef SECURITY_STATUS
  24918. (SEC_ENTRY * IMPORT_SECURITY_CONTEXT_FN_W)(
  24919. #if ISSP_MODE == 0
  24920. PSECURITY_STRING,
  24921. #else
  24922. SEC_WCHAR SEC_FAR *,
  24923. #endif
  24924. PSecBuffer,
  24925. VOID SEC_FAR *,
  24926. PCtxtHandle
  24927. );
  24928. # define ImportSecurityContext ImportSecurityContextW
  24929. # define IMPORT_SECURITY_CONTEXT_FN IMPORT_SECURITY_CONTEXT_FN_W
  24930. #if ISSP_MODE == 0
  24931. NTSTATUS
  24932. NTAPI
  24933. SecMakeSPN(
  24934. IN PUNICODE_STRING ServiceClass,
  24935. IN PUNICODE_STRING ServiceName,
  24936. IN PUNICODE_STRING InstanceName OPTIONAL,
  24937. IN USHORT InstancePort OPTIONAL,
  24938. IN PUNICODE_STRING Referrer OPTIONAL,
  24939. IN OUT PUNICODE_STRING Spn,
  24940. OUT PULONG Length OPTIONAL,
  24941. IN BOOLEAN Allocate
  24942. );
  24943. NTSTATUS
  24944. NTAPI
  24945. SecMakeSPNEx(
  24946. IN PUNICODE_STRING ServiceClass,
  24947. IN PUNICODE_STRING ServiceName,
  24948. IN PUNICODE_STRING InstanceName OPTIONAL,
  24949. IN USHORT InstancePort OPTIONAL,
  24950. IN PUNICODE_STRING Referrer OPTIONAL,
  24951. IN PUNICODE_STRING TargetInfo OPTIONAL,
  24952. IN OUT PUNICODE_STRING Spn,
  24953. OUT PULONG Length OPTIONAL,
  24954. IN BOOLEAN Allocate
  24955. );
  24956. NTSTATUS
  24957. SEC_ENTRY
  24958. SecLookupAccountSid(
  24959. IN PSID Sid,
  24960. IN OUT PULONG NameSize,
  24961. OUT PUNICODE_STRING NameBuffer,
  24962. IN OUT PULONG DomainSize OPTIONAL,
  24963. OUT PUNICODE_STRING DomainBuffer OPTIONAL,
  24964. OUT PSID_NAME_USE NameUse
  24965. );
  24966. NTSTATUS
  24967. SEC_ENTRY
  24968. SecLookupAccountName(
  24969. IN PUNICODE_STRING Name,
  24970. IN OUT PULONG SidSize,
  24971. OUT PSID Sid,
  24972. OUT PSID_NAME_USE NameUse,
  24973. IN OUT PULONG DomainSize OPTIONAL,
  24974. OUT PUNICODE_STRING ReferencedDomain OPTIONAL
  24975. );
  24976. NTSTATUS
  24977. SEC_ENTRY
  24978. SecLookupWellKnownSid(
  24979. IN WELL_KNOWN_SID_TYPE SidType,
  24980. OUT PSID Sid,
  24981. ULONG SidBufferSize,
  24982. OUT PULONG SidSize OPTIONAL
  24983. );
  24984. #endif
  24985. #define SECURITY_ENTRYPOINTW SEC_TEXT("InitSecurityInterfaceW")
  24986. # define SECURITY_ENTRYPOINT SECURITY_ENTRYPOINTW
  24987. #define FreeCredentialHandle FreeCredentialsHandle
  24988. typedef struct _SECURITY_FUNCTION_TABLE_W {
  24989. unsigned long dwVersion;
  24990. ENUMERATE_SECURITY_PACKAGES_FN_W EnumerateSecurityPackagesW;
  24991. QUERY_CREDENTIALS_ATTRIBUTES_FN_W QueryCredentialsAttributesW;
  24992. ACQUIRE_CREDENTIALS_HANDLE_FN_W AcquireCredentialsHandleW;
  24993. FREE_CREDENTIALS_HANDLE_FN FreeCredentialsHandle;
  24994. void SEC_FAR * Reserved2;
  24995. INITIALIZE_SECURITY_CONTEXT_FN_W InitializeSecurityContextW;
  24996. ACCEPT_SECURITY_CONTEXT_FN AcceptSecurityContext;
  24997. COMPLETE_AUTH_TOKEN_FN CompleteAuthToken;
  24998. DELETE_SECURITY_CONTEXT_FN DeleteSecurityContext;
  24999. APPLY_CONTROL_TOKEN_FN ApplyControlToken;
  25000. QUERY_CONTEXT_ATTRIBUTES_FN_W QueryContextAttributesW;
  25001. IMPERSONATE_SECURITY_CONTEXT_FN ImpersonateSecurityContext;
  25002. REVERT_SECURITY_CONTEXT_FN RevertSecurityContext;
  25003. MAKE_SIGNATURE_FN MakeSignature;
  25004. VERIFY_SIGNATURE_FN VerifySignature;
  25005. FREE_CONTEXT_BUFFER_FN FreeContextBuffer;
  25006. QUERY_SECURITY_PACKAGE_INFO_FN_W QuerySecurityPackageInfoW;
  25007. void SEC_FAR * Reserved3;
  25008. void SEC_FAR * Reserved4;
  25009. EXPORT_SECURITY_CONTEXT_FN ExportSecurityContext;
  25010. IMPORT_SECURITY_CONTEXT_FN_W ImportSecurityContextW;
  25011. ADD_CREDENTIALS_FN_W AddCredentialsW ;
  25012. void SEC_FAR * Reserved8;
  25013. QUERY_SECURITY_CONTEXT_TOKEN_FN QuerySecurityContextToken;
  25014. ENCRYPT_MESSAGE_FN EncryptMessage;
  25015. DECRYPT_MESSAGE_FN DecryptMessage;
  25016. SET_CONTEXT_ATTRIBUTES_FN_W SetContextAttributesW;
  25017. } SecurityFunctionTableW, SEC_FAR * PSecurityFunctionTableW;
  25018. # define SecurityFunctionTable SecurityFunctionTableW
  25019. # define PSecurityFunctionTable PSecurityFunctionTableW
  25020. #define SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION 1
  25021. #define SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_2 2
  25022. PSecurityFunctionTableW SEC_ENTRY
  25023. InitSecurityInterfaceW(
  25024. void
  25025. );
  25026. typedef PSecurityFunctionTableW
  25027. (SEC_ENTRY * INIT_SECURITY_INTERFACE_W)(void);
  25028. # define InitSecurityInterface InitSecurityInterfaceW
  25029. # define INIT_SECURITY_INTERFACE INIT_SECURITY_INTERFACE_W
  25030. #ifndef _AUTH_IDENTITY_DEFINED
  25031. #define _AUTH_IDENTITY_DEFINED
  25032. #define SEC_WINNT_AUTH_IDENTITY_ANSI 0x1
  25033. #define SEC_WINNT_AUTH_IDENTITY_UNICODE 0x2
  25034. typedef struct _SEC_WINNT_AUTH_IDENTITY_W {
  25035. unsigned short *User;
  25036. unsigned long UserLength;
  25037. unsigned short *Domain;
  25038. unsigned long DomainLength;
  25039. unsigned short *Password;
  25040. unsigned long PasswordLength;
  25041. unsigned long Flags;
  25042. } SEC_WINNT_AUTH_IDENTITY_W, *PSEC_WINNT_AUTH_IDENTITY_W;
  25043. #define SEC_WINNT_AUTH_IDENTITY SEC_WINNT_AUTH_IDENTITY_W
  25044. #define PSEC_WINNT_AUTH_IDENTITY PSEC_WINNT_AUTH_IDENTITY_W
  25045. #define _SEC_WINNT_AUTH_IDENTITY _SEC_WINNT_AUTH_IDENTITY_W
  25046. #endif
  25047. //
  25048. // This is the combined authentication identity structure that may be
  25049. // used with the negotiate package, NTLM, Kerberos, or SCHANNEL
  25050. //
  25051. #ifndef SEC_WINNT_AUTH_IDENTITY_VERSION
  25052. #define SEC_WINNT_AUTH_IDENTITY_VERSION 0x200
  25053. typedef struct _SEC_WINNT_AUTH_IDENTITY_EXW {
  25054. unsigned long Version;
  25055. unsigned long Length;
  25056. unsigned short SEC_FAR *User;
  25057. unsigned long UserLength;
  25058. unsigned short SEC_FAR *Domain;
  25059. unsigned long DomainLength;
  25060. unsigned short SEC_FAR *Password;
  25061. unsigned long PasswordLength;
  25062. unsigned long Flags;
  25063. unsigned short SEC_FAR * PackageList;
  25064. unsigned long PackageListLength;
  25065. } SEC_WINNT_AUTH_IDENTITY_EXW, *PSEC_WINNT_AUTH_IDENTITY_EXW;
  25066. #define SEC_WINNT_AUTH_IDENTITY_EX SEC_WINNT_AUTH_IDENTITY_EXW
  25067. #define PSEC_WINNT_AUTH_IDENTITY_EX PSEC_WINNT_AUTH_IDENTITY_EXW
  25068. #endif // SEC_WINNT_AUTH_IDENTITY_VERSION
  25069. //
  25070. // Common types used by negotiable security packages
  25071. //
  25072. #define SEC_WINNT_AUTH_IDENTITY_MARSHALLED 0x4 // all data is in one buffer
  25073. #define SEC_WINNT_AUTH_IDENTITY_ONLY 0x8 // these credentials are for identity only - no PAC needed
  25074. #endif // __SSPI_H__
  25075. #ifndef SECURITY_USER_DATA_DEFINED
  25076. #define SECURITY_USER_DATA_DEFINED
  25077. typedef struct _SECURITY_USER_DATA {
  25078. SECURITY_STRING UserName; // User name
  25079. SECURITY_STRING LogonDomainName; // Domain the user logged on to
  25080. SECURITY_STRING LogonServer; // Server that logged the user on
  25081. PSID pSid; // SID of user
  25082. } SECURITY_USER_DATA, *PSECURITY_USER_DATA;
  25083. typedef SECURITY_USER_DATA SecurityUserData, * PSecurityUserData;
  25084. #define UNDERSTANDS_LONG_NAMES 1
  25085. #define NO_LONG_NAMES 2
  25086. #endif // SECURITY_USER_DATA_DEFINED
  25087. HRESULT SEC_ENTRY
  25088. GetSecurityUserInfo(
  25089. IN PLUID LogonId,
  25090. IN ULONG Flags,
  25091. OUT PSecurityUserData * UserInformation
  25092. );
  25093. SECURITY_STATUS SEC_ENTRY
  25094. MapSecurityError( SECURITY_STATUS SecStatus );
  25095. #define DD_MUP_DEVICE_NAME L"\\Device\\Mup"
  25096. #define IOCTL_REDIR_QUERY_PATH CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM, 99, METHOD_NEITHER, FILE_ANY_ACCESS)
  25097. typedef struct _QUERY_PATH_REQUEST {
  25098. ULONG PathNameLength;
  25099. PIO_SECURITY_CONTEXT SecurityContext;
  25100. WCHAR FilePathName[1];
  25101. } QUERY_PATH_REQUEST, *PQUERY_PATH_REQUEST;
  25102. typedef struct _QUERY_PATH_RESPONSE {
  25103. ULONG LengthAccepted;
  25104. } QUERY_PATH_RESPONSE, *PQUERY_PATH_RESPONSE;
  25105. //
  25106. // Define external data.
  25107. // because of indirection for all drivers external to ntoskrnl these are actually ptrs
  25108. //
  25109. #if defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
  25110. extern PBOOLEAN KdDebuggerNotPresent;
  25111. extern PBOOLEAN KdDebuggerEnabled;
  25112. #define KD_DEBUGGER_ENABLED *KdDebuggerEnabled
  25113. #define KD_DEBUGGER_NOT_PRESENT *KdDebuggerNotPresent
  25114. #else
  25115. extern BOOLEAN KdDebuggerNotPresent;
  25116. extern BOOLEAN KdDebuggerEnabled;
  25117. #define KD_DEBUGGER_ENABLED KdDebuggerEnabled
  25118. #define KD_DEBUGGER_NOT_PRESENT KdDebuggerNotPresent
  25119. #endif
  25120. NTSTATUS
  25121. KdDisableDebugger(
  25122. VOID
  25123. );
  25124. NTSTATUS
  25125. KdEnableDebugger(
  25126. VOID
  25127. );
  25128. //
  25129. // KdRefreshDebuggerPresent attempts to communicate with
  25130. // the debugger host machine to refresh the state of
  25131. // KdDebuggerNotPresent. It returns the state of
  25132. // KdDebuggerNotPresent while the kd locks are held.
  25133. // KdDebuggerNotPresent may immediately change state
  25134. // after the kd locks are released so it may not
  25135. // match the return value.
  25136. //
  25137. BOOLEAN
  25138. KdRefreshDebuggerNotPresent(
  25139. VOID
  25140. );
  25141. #define VOLSNAPCONTROLTYPE ((ULONG) 'S')
  25142. #define IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES CTL_CODE(VOLSNAPCONTROLTYPE, 0, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  25143. //
  25144. // Runtime Library function prototypes.
  25145. //
  25146. NTSYSAPI
  25147. VOID
  25148. NTAPI
  25149. RtlCaptureContext (
  25150. OUT PCONTEXT ContextRecord
  25151. );
  25152. NTSYSAPI
  25153. USHORT
  25154. NTAPI
  25155. RtlCaptureStackBackTrace (
  25156. IN ULONG FramesToSkip,
  25157. IN ULONG FramesToCapture,
  25158. OUT PVOID *BackTrace,
  25159. OUT PULONG BackTraceHash OPTIONAL
  25160. );
  25161. #ifdef POOL_TAGGING
  25162. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,' sfI')
  25163. #define ExAllocatePoolWithQuota(a,b) ExAllocatePoolWithQuotaTag(a,b,' sfI')
  25164. #endif
  25165. extern POBJECT_TYPE *PsThreadType;
  25166. extern POBJECT_TYPE *IoFileObjectType;
  25167. extern POBJECT_TYPE *ExEventObjectType;
  25168. extern POBJECT_TYPE *ExSemaphoreObjectType;
  25169. //
  25170. // Define exported ZwXxx routines to device drivers.
  25171. //
  25172. NTSYSAPI
  25173. NTSTATUS
  25174. NTAPI
  25175. ZwCreateEvent (
  25176. OUT PHANDLE EventHandle,
  25177. IN ACCESS_MASK DesiredAccess,
  25178. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  25179. IN EVENT_TYPE EventType,
  25180. IN BOOLEAN InitialState
  25181. );
  25182. NTSYSAPI
  25183. NTSTATUS
  25184. NTAPI
  25185. ZwCreateFile(
  25186. OUT PHANDLE FileHandle,
  25187. IN ACCESS_MASK DesiredAccess,
  25188. IN POBJECT_ATTRIBUTES ObjectAttributes,
  25189. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25190. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  25191. IN ULONG FileAttributes,
  25192. IN ULONG ShareAccess,
  25193. IN ULONG CreateDisposition,
  25194. IN ULONG CreateOptions,
  25195. IN PVOID EaBuffer OPTIONAL,
  25196. IN ULONG EaLength
  25197. );
  25198. NTSYSAPI
  25199. NTSTATUS
  25200. NTAPI
  25201. ZwDeleteFile(
  25202. IN POBJECT_ATTRIBUTES ObjectAttributes
  25203. );
  25204. NTSYSAPI
  25205. NTSTATUS
  25206. NTAPI
  25207. ZwDeviceIoControlFile(
  25208. IN HANDLE FileHandle,
  25209. IN HANDLE Event OPTIONAL,
  25210. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  25211. IN PVOID ApcContext OPTIONAL,
  25212. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25213. IN ULONG IoControlCode,
  25214. IN PVOID InputBuffer OPTIONAL,
  25215. IN ULONG InputBufferLength,
  25216. OUT PVOID OutputBuffer OPTIONAL,
  25217. IN ULONG OutputBufferLength
  25218. );
  25219. NTSYSAPI
  25220. NTSTATUS
  25221. NTAPI
  25222. ZwOpenFile(
  25223. OUT PHANDLE FileHandle,
  25224. IN ACCESS_MASK DesiredAccess,
  25225. IN POBJECT_ATTRIBUTES ObjectAttributes,
  25226. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25227. IN ULONG ShareAccess,
  25228. IN ULONG OpenOptions
  25229. );
  25230. NTSYSAPI
  25231. NTSTATUS
  25232. NTAPI
  25233. ZwQueryDirectoryFile(
  25234. IN HANDLE FileHandle,
  25235. IN HANDLE Event OPTIONAL,
  25236. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  25237. IN PVOID ApcContext OPTIONAL,
  25238. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25239. OUT PVOID FileInformation,
  25240. IN ULONG Length,
  25241. IN FILE_INFORMATION_CLASS FileInformationClass,
  25242. IN BOOLEAN ReturnSingleEntry,
  25243. IN PUNICODE_STRING FileName OPTIONAL,
  25244. IN BOOLEAN RestartScan
  25245. );
  25246. NTSYSAPI
  25247. NTSTATUS
  25248. NTAPI
  25249. ZwQueryInformationFile(
  25250. IN HANDLE FileHandle,
  25251. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25252. OUT PVOID FileInformation,
  25253. IN ULONG Length,
  25254. IN FILE_INFORMATION_CLASS FileInformationClass
  25255. );
  25256. NTSYSAPI
  25257. NTSTATUS
  25258. NTAPI
  25259. ZwSetInformationFile(
  25260. IN HANDLE FileHandle,
  25261. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25262. IN PVOID FileInformation,
  25263. IN ULONG Length,
  25264. IN FILE_INFORMATION_CLASS FileInformationClass
  25265. );
  25266. NTSYSAPI
  25267. NTSTATUS
  25268. NTAPI
  25269. ZwQueryVolumeInformationFile(
  25270. IN HANDLE FileHandle,
  25271. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25272. OUT PVOID FsInformation,
  25273. IN ULONG Length,
  25274. IN FS_INFORMATION_CLASS FsInformationClass
  25275. );
  25276. NTSYSAPI
  25277. NTSTATUS
  25278. NTAPI
  25279. ZwSetVolumeInformationFile(
  25280. IN HANDLE FileHandle,
  25281. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25282. IN PVOID FsInformation,
  25283. IN ULONG Length,
  25284. IN FS_INFORMATION_CLASS FsInformationClass
  25285. );
  25286. NTSYSAPI
  25287. NTSTATUS
  25288. NTAPI
  25289. ZwReadFile(
  25290. IN HANDLE FileHandle,
  25291. IN HANDLE Event OPTIONAL,
  25292. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  25293. IN PVOID ApcContext OPTIONAL,
  25294. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25295. OUT PVOID Buffer,
  25296. IN ULONG Length,
  25297. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  25298. IN PULONG Key OPTIONAL
  25299. );
  25300. NTSYSAPI
  25301. NTSTATUS
  25302. NTAPI
  25303. ZwWriteFile(
  25304. IN HANDLE FileHandle,
  25305. IN HANDLE Event OPTIONAL,
  25306. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  25307. IN PVOID ApcContext OPTIONAL,
  25308. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25309. IN PVOID Buffer,
  25310. IN ULONG Length,
  25311. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  25312. IN PULONG Key OPTIONAL
  25313. );
  25314. NTSYSAPI
  25315. NTSTATUS
  25316. NTAPI
  25317. ZwFsControlFile(
  25318. IN HANDLE FileHandle,
  25319. IN HANDLE Event OPTIONAL,
  25320. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  25321. IN PVOID ApcContext OPTIONAL,
  25322. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25323. IN ULONG FsControlCode,
  25324. IN PVOID InputBuffer OPTIONAL,
  25325. IN ULONG InputBufferLength,
  25326. OUT PVOID OutputBuffer OPTIONAL,
  25327. IN ULONG OutputBufferLength
  25328. );
  25329. NTSYSAPI
  25330. NTSTATUS
  25331. NTAPI
  25332. ZwClose(
  25333. IN HANDLE Handle
  25334. );
  25335. NTSYSAPI
  25336. NTSTATUS
  25337. NTAPI
  25338. ZwDuplicateObject(
  25339. IN HANDLE SourceProcessHandle,
  25340. IN HANDLE SourceHandle,
  25341. IN HANDLE TargetProcessHandle OPTIONAL,
  25342. OUT PHANDLE TargetHandle OPTIONAL,
  25343. IN ACCESS_MASK DesiredAccess,
  25344. IN ULONG HandleAttributes,
  25345. IN ULONG Options
  25346. );
  25347. NTSYSAPI
  25348. NTSTATUS
  25349. NTAPI
  25350. ZwCreateDirectoryObject(
  25351. OUT PHANDLE DirectoryHandle,
  25352. IN ACCESS_MASK DesiredAccess,
  25353. IN POBJECT_ATTRIBUTES ObjectAttributes
  25354. );
  25355. NTSYSAPI
  25356. NTSTATUS
  25357. NTAPI
  25358. ZwOpenDirectoryObject(
  25359. OUT PHANDLE DirectoryHandle,
  25360. IN ACCESS_MASK DesiredAccess,
  25361. IN POBJECT_ATTRIBUTES ObjectAttributes
  25362. );
  25363. NTSYSAPI
  25364. NTSTATUS
  25365. NTAPI
  25366. ZwOpenSymbolicLinkObject(
  25367. OUT PHANDLE LinkHandle,
  25368. IN ACCESS_MASK DesiredAccess,
  25369. IN POBJECT_ATTRIBUTES ObjectAttributes
  25370. );
  25371. NTSYSAPI
  25372. NTSTATUS
  25373. NTAPI
  25374. ZwQuerySymbolicLinkObject(
  25375. IN HANDLE LinkHandle,
  25376. IN OUT PUNICODE_STRING LinkTarget,
  25377. OUT PULONG ReturnedLength OPTIONAL
  25378. );
  25379. NTSYSAPI
  25380. NTSTATUS
  25381. NTAPI
  25382. ZwMakeTemporaryObject(
  25383. IN HANDLE Handle
  25384. );
  25385. NTSYSAPI
  25386. NTSTATUS
  25387. NTAPI
  25388. ZwCreateKey(
  25389. OUT PHANDLE KeyHandle,
  25390. IN ACCESS_MASK DesiredAccess,
  25391. IN POBJECT_ATTRIBUTES ObjectAttributes,
  25392. IN ULONG TitleIndex,
  25393. IN PUNICODE_STRING Class OPTIONAL,
  25394. IN ULONG CreateOptions,
  25395. OUT PULONG Disposition OPTIONAL
  25396. );
  25397. NTSYSAPI
  25398. NTSTATUS
  25399. NTAPI
  25400. ZwOpenKey(
  25401. OUT PHANDLE KeyHandle,
  25402. IN ACCESS_MASK DesiredAccess,
  25403. IN POBJECT_ATTRIBUTES ObjectAttributes
  25404. );
  25405. NTSYSAPI
  25406. NTSTATUS
  25407. NTAPI
  25408. ZwDeleteKey(
  25409. IN HANDLE KeyHandle
  25410. );
  25411. NTSYSAPI
  25412. NTSTATUS
  25413. NTAPI
  25414. ZwDeleteValueKey(
  25415. IN HANDLE KeyHandle,
  25416. IN PUNICODE_STRING ValueName
  25417. );
  25418. NTSYSAPI
  25419. NTSTATUS
  25420. NTAPI
  25421. ZwEnumerateKey(
  25422. IN HANDLE KeyHandle,
  25423. IN ULONG Index,
  25424. IN KEY_INFORMATION_CLASS KeyInformationClass,
  25425. OUT PVOID KeyInformation,
  25426. IN ULONG Length,
  25427. OUT PULONG ResultLength
  25428. );
  25429. NTSYSAPI
  25430. NTSTATUS
  25431. NTAPI
  25432. ZwEnumerateValueKey(
  25433. IN HANDLE KeyHandle,
  25434. IN ULONG Index,
  25435. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  25436. OUT PVOID KeyValueInformation,
  25437. IN ULONG Length,
  25438. OUT PULONG ResultLength
  25439. );
  25440. NTSYSAPI
  25441. NTSTATUS
  25442. NTAPI
  25443. ZwFlushKey(
  25444. IN HANDLE KeyHandle
  25445. );
  25446. NTSYSAPI
  25447. NTSTATUS
  25448. NTAPI
  25449. ZwQueryKey(
  25450. IN HANDLE KeyHandle,
  25451. IN KEY_INFORMATION_CLASS KeyInformationClass,
  25452. OUT PVOID KeyInformation,
  25453. IN ULONG Length,
  25454. OUT PULONG ResultLength
  25455. );
  25456. NTSYSAPI
  25457. NTSTATUS
  25458. NTAPI
  25459. ZwQueryValueKey(
  25460. IN HANDLE KeyHandle,
  25461. IN PUNICODE_STRING ValueName,
  25462. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  25463. OUT PVOID KeyValueInformation,
  25464. IN ULONG Length,
  25465. OUT PULONG ResultLength
  25466. );
  25467. NTSYSAPI
  25468. NTSTATUS
  25469. NTAPI
  25470. ZwSetValueKey(
  25471. IN HANDLE KeyHandle,
  25472. IN PUNICODE_STRING ValueName,
  25473. IN ULONG TitleIndex OPTIONAL,
  25474. IN ULONG Type,
  25475. IN PVOID Data,
  25476. IN ULONG DataSize
  25477. );
  25478. NTSYSAPI
  25479. NTSTATUS
  25480. NTAPI
  25481. ZwOpenSection(
  25482. OUT PHANDLE SectionHandle,
  25483. IN ACCESS_MASK DesiredAccess,
  25484. IN POBJECT_ATTRIBUTES ObjectAttributes
  25485. );
  25486. NTSYSAPI
  25487. NTSTATUS
  25488. NTAPI
  25489. ZwMapViewOfSection(
  25490. IN HANDLE SectionHandle,
  25491. IN HANDLE ProcessHandle,
  25492. IN OUT PVOID *BaseAddress,
  25493. IN ULONG ZeroBits,
  25494. IN SIZE_T CommitSize,
  25495. IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
  25496. IN OUT PSIZE_T ViewSize,
  25497. IN SECTION_INHERIT InheritDisposition,
  25498. IN ULONG AllocationType,
  25499. IN ULONG Protect
  25500. );
  25501. NTSYSAPI
  25502. NTSTATUS
  25503. NTAPI
  25504. ZwUnmapViewOfSection(
  25505. IN HANDLE ProcessHandle,
  25506. IN PVOID BaseAddress
  25507. );
  25508. NTSYSAPI
  25509. NTSTATUS
  25510. NTAPI
  25511. ZwSetInformationThread(
  25512. IN HANDLE ThreadHandle,
  25513. IN THREADINFOCLASS ThreadInformationClass,
  25514. IN PVOID ThreadInformation,
  25515. IN ULONG ThreadInformationLength
  25516. );
  25517. NTSYSAPI
  25518. NTSTATUS
  25519. NTAPI
  25520. ZwCreateSection (
  25521. OUT PHANDLE SectionHandle,
  25522. IN ACCESS_MASK DesiredAccess,
  25523. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  25524. IN PLARGE_INTEGER MaximumSize OPTIONAL,
  25525. IN ULONG SectionPageProtection,
  25526. IN ULONG AllocationAttributes,
  25527. IN HANDLE FileHandle OPTIONAL
  25528. );
  25529. NTSYSAPI
  25530. NTSTATUS
  25531. NTAPI
  25532. ZwAllocateVirtualMemory(
  25533. IN HANDLE ProcessHandle,
  25534. IN OUT PVOID *BaseAddress,
  25535. IN ULONG ZeroBits,
  25536. IN OUT PSIZE_T RegionSize,
  25537. IN ULONG AllocationType,
  25538. IN ULONG Protect
  25539. );
  25540. NTSYSAPI
  25541. NTSTATUS
  25542. NTAPI
  25543. ZwFreeVirtualMemory(
  25544. IN HANDLE ProcessHandle,
  25545. IN OUT PVOID *BaseAddress,
  25546. IN OUT PSIZE_T RegionSize,
  25547. IN ULONG FreeType
  25548. );
  25549. NTSYSAPI
  25550. NTSTATUS
  25551. NTAPI
  25552. ZwWaitForSingleObject(
  25553. IN HANDLE Handle,
  25554. IN BOOLEAN Alertable,
  25555. IN PLARGE_INTEGER Timeout OPTIONAL
  25556. );
  25557. NTSYSAPI
  25558. NTSTATUS
  25559. NTAPI
  25560. ZwSetEvent (
  25561. IN HANDLE Handle,
  25562. OUT PLONG PreviousState OPTIONAL
  25563. );
  25564. NTSYSAPI
  25565. NTSTATUS
  25566. NTAPI
  25567. ZwFlushVirtualMemory(
  25568. IN HANDLE ProcessHandle,
  25569. IN OUT PVOID *BaseAddress,
  25570. IN OUT PSIZE_T RegionSize,
  25571. OUT PIO_STATUS_BLOCK IoStatus
  25572. );
  25573. NTSYSAPI
  25574. NTSTATUS
  25575. NTAPI
  25576. ZwOpenProcessTokenEx(
  25577. IN HANDLE ProcessHandle,
  25578. IN ACCESS_MASK DesiredAccess,
  25579. IN ULONG HandleAttributes,
  25580. OUT PHANDLE TokenHandle
  25581. );
  25582. NTSYSAPI
  25583. NTSTATUS
  25584. NTAPI
  25585. ZwOpenThreadTokenEx(
  25586. IN HANDLE ThreadHandle,
  25587. IN ACCESS_MASK DesiredAccess,
  25588. IN BOOLEAN OpenAsSelf,
  25589. IN ULONG HandleAttributes,
  25590. OUT PHANDLE TokenHandle
  25591. );
  25592. NTSYSAPI
  25593. NTSTATUS
  25594. NTAPI
  25595. ZwSetInformationToken (
  25596. IN HANDLE TokenHandle,
  25597. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  25598. IN PVOID TokenInformation,
  25599. IN ULONG TokenInformationLength
  25600. );
  25601. NTSYSAPI
  25602. NTSTATUS
  25603. NTAPI
  25604. ZwQueryInformationToken (
  25605. IN HANDLE TokenHandle,
  25606. IN TOKEN_INFORMATION_CLASS TokenInformationClass,
  25607. OUT PVOID TokenInformation,
  25608. IN ULONG TokenInformationLength,
  25609. OUT PULONG ReturnLength
  25610. );
  25611. NTSYSAPI
  25612. NTSTATUS
  25613. NTAPI
  25614. ZwSetSecurityObject(
  25615. IN HANDLE Handle,
  25616. IN SECURITY_INFORMATION SecurityInformation,
  25617. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  25618. );
  25619. NTSYSAPI
  25620. NTSTATUS
  25621. NTAPI
  25622. ZwQuerySecurityObject(
  25623. IN HANDLE Handle,
  25624. IN SECURITY_INFORMATION SecurityInformation,
  25625. OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  25626. IN ULONG Length,
  25627. OUT PULONG LengthNeeded
  25628. );
  25629. NTSYSAPI
  25630. NTSTATUS
  25631. NTAPI
  25632. ZwLoadDriver(
  25633. IN PUNICODE_STRING DriverServiceName
  25634. );
  25635. NTSYSAPI
  25636. NTSTATUS
  25637. NTAPI
  25638. ZwUnloadDriver(
  25639. IN PUNICODE_STRING DriverServiceName
  25640. );
  25641. NTSYSAPI
  25642. NTSTATUS
  25643. NTAPI
  25644. ZwLockFile(
  25645. IN HANDLE FileHandle,
  25646. IN HANDLE Event OPTIONAL,
  25647. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  25648. IN PVOID ApcContext OPTIONAL,
  25649. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25650. IN PLARGE_INTEGER ByteOffset,
  25651. IN PLARGE_INTEGER Length,
  25652. IN ULONG Key,
  25653. IN BOOLEAN FailImmediately,
  25654. IN BOOLEAN ExclusiveLock
  25655. );
  25656. NTSYSAPI
  25657. NTSTATUS
  25658. NTAPI
  25659. ZwUnlockFile(
  25660. IN HANDLE FileHandle,
  25661. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25662. IN PLARGE_INTEGER ByteOffset,
  25663. IN PLARGE_INTEGER Length,
  25664. IN ULONG Key
  25665. );
  25666. NTSYSAPI
  25667. NTSTATUS
  25668. NTAPI
  25669. ZwQueryQuotaInformationFile(
  25670. IN HANDLE FileHandle,
  25671. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25672. OUT PVOID Buffer,
  25673. IN ULONG Length,
  25674. IN BOOLEAN ReturnSingleEntry,
  25675. IN PVOID SidList OPTIONAL,
  25676. IN ULONG SidListLength,
  25677. IN PSID StartSid OPTIONAL,
  25678. IN BOOLEAN RestartScan
  25679. );
  25680. NTSYSAPI
  25681. NTSTATUS
  25682. NTAPI
  25683. ZwSetQuotaInformationFile(
  25684. IN HANDLE FileHandle,
  25685. OUT PIO_STATUS_BLOCK IoStatusBlock,
  25686. IN PVOID Buffer,
  25687. IN ULONG Length
  25688. );
  25689. NTSYSAPI
  25690. NTSTATUS
  25691. NTAPI
  25692. ZwConnectPort(
  25693. OUT PHANDLE PortHandle,
  25694. IN PUNICODE_STRING PortName,
  25695. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
  25696. IN OUT PPORT_VIEW ClientView OPTIONAL,
  25697. IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL,
  25698. OUT PULONG MaxMessageLength OPTIONAL,
  25699. IN OUT PVOID ConnectionInformation OPTIONAL,
  25700. IN OUT PULONG ConnectionInformationLength OPTIONAL
  25701. );
  25702. NTSYSAPI
  25703. NTSTATUS
  25704. NTAPI
  25705. ZwSecureConnectPort(
  25706. OUT PHANDLE PortHandle,
  25707. IN PUNICODE_STRING PortName,
  25708. IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
  25709. IN OUT PPORT_VIEW ClientView OPTIONAL,
  25710. IN PSID RequiredServerSid,
  25711. IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL,
  25712. OUT PULONG MaxMessageLength OPTIONAL,
  25713. IN OUT PVOID ConnectionInformation OPTIONAL,
  25714. IN OUT PULONG ConnectionInformationLength OPTIONAL
  25715. );
  25716. NTSYSAPI
  25717. NTSTATUS
  25718. NTAPI
  25719. ZwRequestWaitReplyPort(
  25720. IN HANDLE PortHandle,
  25721. IN PPORT_MESSAGE RequestMessage,
  25722. OUT PPORT_MESSAGE ReplyMessage
  25723. );
  25724. #endif // _NTIFS_